RevisionDeleter::getChanges() documentation cleanup
[lhc/web/wiklou.git] / includes / revisiondelete / RevisionDeleter.php
1 <?php
2 /**
3 * Revision/log/file deletion backend
4 *
5 * @file
6 */
7
8 /**
9 * Temporary b/c interface, collection of static functions.
10 * @ingroup SpecialPage
11 */
12 class RevisionDeleter {
13 /**
14 * Checks for a change in the bitfield for a certain option and updates the
15 * provided array accordingly.
16 *
17 * @param $desc String: description to add to the array if the option was
18 * enabled / disabled.
19 * @param $field Integer: the bitmask describing the single option.
20 * @param $diff Integer: the xor of the old and new bitfields.
21 * @param $new Integer: the new bitfield
22 * @param $arr Array: the array to update.
23 */
24 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
25 if( $diff & $field ) {
26 $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc;
27 }
28 }
29
30 /**
31 * Gets an array of message keys describing the changes made to the
32 * visibility of the revision.
33 *
34 * If the resulting array is $arr, then $arr[0] will contain an array of
35 * message keys describing the items that were hidden, $arr[1] will contain
36 * an array of message keys describing the items that were unhidden, and $arr[2]
37 * will contain an array with a single message key, which can be one of
38 * "revdelete-restricted", "revdelete-unrestricted", or null, indicating (un)suppression.
39 *
40 * @param $n Integer: the new bitfield.
41 * @param $o Integer: the old bitfield.
42 * @return An array as described above.
43 * @since 1.19 public
44 */
45 public static function getChanges( $n, $o ) {
46 $diff = $n ^ $o;
47 $ret = array( 0 => array(), 1 => array(), 2 => array() );
48 // Build bitfield changes in language
49 self::checkItem( 'revdelete-content',
50 Revision::DELETED_TEXT, $diff, $n, $ret );
51 self::checkItem( 'revdelete-summary',
52 Revision::DELETED_COMMENT, $diff, $n, $ret );
53 self::checkItem( 'revdelete-uname',
54 Revision::DELETED_USER, $diff, $n, $ret );
55 // Restriction application to sysops
56 if( $diff & Revision::DELETED_RESTRICTED ) {
57 if( $n & Revision::DELETED_RESTRICTED )
58 $ret[2][] = 'revdelete-restricted';
59 else
60 $ret[2][] = 'revdelete-unrestricted';
61 }
62 return $ret;
63 }
64
65 // Get DB field name for URL param...
66 // Future code for other things may also track
67 // other types of revision-specific changes.
68 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
69 public static function getRelationType( $typeName ) {
70 if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
71 $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
72 }
73 if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
74 $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
75 return call_user_func( array( $class, 'getRelationType' ) );
76 } else {
77 return null;
78 }
79 }
80
81 /**
82 * Checks if a revision still exists in the revision table.
83 * If it doesn't, returns the corresponding ar_timestamp field
84 * so that this key can be used instead.
85 *
86 * @param $title Title
87 * @param $revid
88 * @return bool|mixed
89 */
90 public static function checkRevisionExistence( $title, $revid ) {
91 $dbr = wfGetDB( DB_SLAVE );
92 $exists = $dbr->selectField( 'revision', '1',
93 array( 'rev_id' => $revid ), __METHOD__ );
94
95 if ( $exists ) {
96 return true;
97 }
98
99 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
100 array( 'ar_namespace' => $title->getNamespace(),
101 'ar_title' => $title->getDBkey(),
102 'ar_rev_id' => $revid ), __METHOD__ );
103
104 return $timestamp;
105 }
106
107 /**
108 * Creates utility links for log entries.
109 *
110 * @param $title Title
111 * @param $paramArray Array
112 * @param $skin Skin
113 * @param $messages
114 * @return String
115 */
116 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
117 global $wgLang;
118
119 if ( count( $paramArray ) >= 2 ) {
120 // Different revision types use different URL params...
121 $originalKey = $key = $paramArray[0];
122 // $paramArray[1] is a CSV of the IDs
123 $Ids = explode( ',', $paramArray[1] );
124
125 $revert = array();
126
127 // Diff link for single rev deletions
128 if ( count( $Ids ) == 1 ) {
129 // Live revision diffs...
130 if ( in_array( $key, array( 'oldid', 'revision' ) ) ) {
131 $revert[] = $skin->link(
132 $title,
133 $messages['diff'],
134 array(),
135 array(
136 'diff' => intval( $Ids[0] ),
137 'unhide' => 1
138 ),
139 array( 'known', 'noclasses' )
140 );
141 // Deleted revision diffs...
142 } elseif ( in_array( $key, array( 'artimestamp','archive' ) ) ) {
143 $revert[] = $skin->link(
144 SpecialPage::getTitleFor( 'Undelete' ),
145 $messages['diff'],
146 array(),
147 array(
148 'target' => $title->getPrefixedDBKey(),
149 'diff' => 'prev',
150 'timestamp' => $Ids[0]
151 ),
152 array( 'known', 'noclasses' )
153 );
154 }
155 }
156
157 // View/modify link...
158 $revert[] = $skin->link(
159 SpecialPage::getTitleFor( 'Revisiondelete' ),
160 $messages['revdel-restore'],
161 array(),
162 array(
163 'target' => $title->getPrefixedText(),
164 'type' => $key,
165 'ids' => implode(',', $Ids),
166 ),
167 array( 'known', 'noclasses' )
168 );
169
170 // Pipe links
171 return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
172 }
173 return '';
174 }
175 }