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