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