r77695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77694‎ | r77695 | r77696 >
Date:00:13, 4 December 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Followup r77679, 1 more for bug 23332
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDelete.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDeleter.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/revisiondelete/RevisionDelete.php
@@ -1,275 +1,5 @@
22 <?php
33 /**
4 - * Revision/log/file deletion backend
5 - *
6 - * @file
7 - */
8 -
9 -/**
10 - * Temporary b/c interface, collection of static functions.
11 - * @ingroup SpecialPage
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 visibility
33 - * of the revision. If the resulting array is $arr, then $arr[0] will contain an
34 - * array of strings describing the items that were hidden, $arr[2] will contain
35 - * an array of strings describing the items that were unhidden, and $arr[3] will
36 - * contain an array with a single string, which can be one of "applied
37 - * restrictions to sysops", "removed restrictions from sysops", or null.
38 - *
39 - * @param $n Integer: the new bitfield.
40 - * @param $o Integer: the old bitfield.
41 - * @return An array as described above.
42 - */
43 - protected static function getChanges( $n, $o ) {
44 - $diff = $n ^ $o;
45 - $ret = array( 0 => array(), 1 => array(), 2 => array() );
46 - // Build bitfield changes in language
47 - self::checkItem( 'revdelete-content',
48 - Revision::DELETED_TEXT, $diff, $n, $ret );
49 - self::checkItem( 'revdelete-summary',
50 - Revision::DELETED_COMMENT, $diff, $n, $ret );
51 - self::checkItem( 'revdelete-uname',
52 - Revision::DELETED_USER, $diff, $n, $ret );
53 - // Restriction application to sysops
54 - if( $diff & Revision::DELETED_RESTRICTED ) {
55 - if( $n & Revision::DELETED_RESTRICTED )
56 - $ret[2][] = 'revdelete-restricted';
57 - else
58 - $ret[2][] = 'revdelete-unrestricted';
59 - }
60 - return $ret;
61 - }
62 -
63 - /**
64 - * Gets a log message to describe the given revision visibility change. This
65 - * message will be of the form "[hid {content, edit summary, username}];
66 - * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
67 - *
68 - * @param $count Integer: The number of effected revisions.
69 - * @param $nbitfield Integer: The new bitfield for the revision.
70 - * @param $obitfield Integer: The old bitfield for the revision.
71 - * @param $isForLog Boolean
72 - * @param $forContent Boolean
73 - */
74 - public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
75 - global $wgLang, $wgContLang;
76 -
77 - $lang = $forContent ? $wgContLang : $wgLang;
78 - $msgFunc = $forContent ? "wfMsgForContent" : "wfMsg";
79 -
80 - $changes = self::getChanges( $nbitfield, $obitfield );
81 - array_walk($changes, 'RevisionDeleter::expandMessageArray', $forContent);
82 -
83 - $changesText = array();
84 -
85 - if( count( $changes[0] ) ) {
86 - $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
87 - }
88 - if( count( $changes[1] ) ) {
89 - $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
90 - }
91 -
92 - $s = $lang->semicolonList( $changesText );
93 - if( count( $changes[2] ) ) {
94 - $s .= $s ? ' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
95 - }
96 -
97 - $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
98 - return wfMsgExt( $msg, $forContent ? array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
99 - }
100 -
101 - private static function expandMessageArray(& $msg, $key, $forContent) {
102 - if ( is_array ($msg) ) {
103 - array_walk($msg, 'RevisionDeleter::expandMessageArray', $forContent);
104 - } else {
105 - if ( $forContent ) {
106 - $msg = wfMsgForContent($msg);
107 - } else {
108 - $msg = wfMsg($msg);
109 - }
110 - }
111 - }
112 -
113 - // Get DB field name for URL param...
114 - // Future code for other things may also track
115 - // other types of revision-specific changes.
116 - // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
117 - public static function getRelationType( $typeName ) {
118 - if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
119 - $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
120 - }
121 - if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
122 - $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
123 - $list = new $class( null, null, null );
124 - return $list->getIdField();
125 - } else {
126 - return null;
127 - }
128 - }
129 -
130 - // Checks if a revision still exists in the revision table.
131 - // If it doesn't, returns the corresponding ar_timestamp field
132 - // so that this key can be used instead.
133 - public static function checkRevisionExistence( $title, $revid ) {
134 - $dbr = wfGetDB( DB_SLAVE );
135 - $exists = $dbr->selectField( 'revision', '1',
136 - array( 'rev_id' => $revid ), __METHOD__ );
137 -
138 - if ( $exists ) {
139 - return true;
140 - }
141 -
142 - $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
143 - array( 'ar_namespace' => $title->getNamespace(),
144 - 'ar_title' => $title->getDBkey(),
145 - 'ar_rev_id' => $revid ), __METHOD__ );
146 -
147 - return $timestamp;
148 - }
149 -
150 - // Creates utility links for log entries.
151 - public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
152 - global $wgLang;
153 -
154 - if( count($paramArray) >= 2 ) {
155 - // Different revision types use different URL params...
156 - $originalKey = $key = $paramArray[0];
157 - // $paramArray[1] is a CSV of the IDs
158 - $Ids = explode( ',', $paramArray[1] );
159 -
160 - $revert = array();
161 -
162 - // For if undeleted revisions are found amidst deleted ones.
163 - $undeletedRevisions = array();
164 -
165 - // This is not going to work if some revs are deleted and some
166 - // aren't.
167 - if ($key == 'revision') {
168 - foreach( $Ids as $k => $id ) {
169 - $existResult =
170 - self::checkRevisionExistence( $title, $id );
171 -
172 - if ($existResult !== true) {
173 - $key = 'archive';
174 - $Ids[$k] = $existResult;
175 - } else {
176 - // Undeleted revision amidst deleted ones
177 - unset($Ids[$k]);
178 - $undeletedRevisions[] = $id;
179 - }
180 - }
181 -
182 - if ( $key == $originalKey ) {
183 - $Ids = $undeletedRevisions;
184 - $undeletedRevisions = array();
185 - }
186 - }
187 -
188 - // Diff link for single rev deletions
189 - if( count($Ids) == 1 && !count($undeletedRevisions) ) {
190 - // Live revision diffs...
191 - if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
192 - $revert[] = $skin->link(
193 - $title,
194 - $messages['diff'],
195 - array(),
196 - array(
197 - 'diff' => intval( $Ids[0] ),
198 - 'unhide' => 1
199 - ),
200 - array( 'known', 'noclasses' )
201 - );
202 - // Deleted revision diffs...
203 - } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
204 - $revert[] = $skin->link(
205 - SpecialPage::getTitleFor( 'Undelete' ),
206 - $messages['diff'],
207 - array(),
208 - array(
209 - 'target' => $title->getPrefixedDBKey(),
210 - 'diff' => 'prev',
211 - 'timestamp' => $Ids[0]
212 - ),
213 - array( 'known', 'noclasses' )
214 - );
215 - }
216 - }
217 -
218 - // View/modify link...
219 - if ( count($undeletedRevisions) ) {
220 - // FIXME THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
221 - // It's not possible to pass a list of both deleted and
222 - // undeleted revisions to SpecialRevisionDelete, so we're
223 - // stuck with two links. See bug 23363.
224 - $restoreLinks = array();
225 -
226 - $restoreLinks[] = $skin->link(
227 - SpecialPage::getTitleFor( 'Revisiondelete' ),
228 - $messages['revdel-restore-visible'],
229 - array(),
230 - array(
231 - 'target' => $title->getPrefixedText(),
232 - 'type' => $originalKey,
233 - 'ids' => implode(',', $undeletedRevisions),
234 - ),
235 - array( 'known', 'noclasses' )
236 - );
237 -
238 - $restoreLinks[] = $skin->link(
239 - SpecialPage::getTitleFor( 'Revisiondelete' ),
240 - $messages['revdel-restore-deleted'],
241 - array(),
242 - array(
243 - 'target' => $title->getPrefixedText(),
244 - 'type' => $key,
245 - 'ids' => implode(',', $Ids),
246 - ),
247 - array( 'known', 'noclasses' )
248 - );
249 -
250 - $revert[] = $messages['revdel-restore'] . ' [' .
251 - $wgLang->pipeList( $restoreLinks ) . ']';
252 - } else {
253 - $revert[] = $skin->link(
254 - SpecialPage::getTitleFor( 'Revisiondelete' ),
255 - $messages['revdel-restore'],
256 - array(),
257 - array(
258 - 'target' => $title->getPrefixedText(),
259 - 'type' => $key,
260 - 'ids' => implode(',', $Ids),
261 - ),
262 - array( 'known', 'noclasses' )
263 - );
264 - }
265 -
266 - // Pipe links
267 - return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
268 - }
269 - return '';
270 - }
271 -}
272 -
273 -/**
2744 * List for revision table items
2755 */
2766 class RevDel_RevisionList extends RevDel_List {
Index: trunk/phase3/includes/revisiondelete/RevisionDeleter.php
@@ -0,0 +1,270 @@
 2+<?php
 3+/**
 4+ * Revision/log/file deletion backend
 5+ *
 6+ * @file
 7+ */
 8+
 9+/**
 10+ * Temporary b/c interface, collection of static functions.
 11+ * @ingroup SpecialPage
 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 visibility
 33+ * of the revision. If the resulting array is $arr, then $arr[0] will contain an
 34+ * array of strings describing the items that were hidden, $arr[2] will contain
 35+ * an array of strings describing the items that were unhidden, and $arr[3] will
 36+ * contain an array with a single string, which can be one of "applied
 37+ * restrictions to sysops", "removed restrictions from sysops", or null.
 38+ *
 39+ * @param $n Integer: the new bitfield.
 40+ * @param $o Integer: the old bitfield.
 41+ * @return An array as described above.
 42+ */
 43+ protected static function getChanges( $n, $o ) {
 44+ $diff = $n ^ $o;
 45+ $ret = array( 0 => array(), 1 => array(), 2 => array() );
 46+ // Build bitfield changes in language
 47+ self::checkItem( 'revdelete-content',
 48+ Revision::DELETED_TEXT, $diff, $n, $ret );
 49+ self::checkItem( 'revdelete-summary',
 50+ Revision::DELETED_COMMENT, $diff, $n, $ret );
 51+ self::checkItem( 'revdelete-uname',
 52+ Revision::DELETED_USER, $diff, $n, $ret );
 53+ // Restriction application to sysops
 54+ if( $diff & Revision::DELETED_RESTRICTED ) {
 55+ if( $n & Revision::DELETED_RESTRICTED )
 56+ $ret[2][] = 'revdelete-restricted';
 57+ else
 58+ $ret[2][] = 'revdelete-unrestricted';
 59+ }
 60+ return $ret;
 61+ }
 62+
 63+ /**
 64+ * Gets a log message to describe the given revision visibility change. This
 65+ * message will be of the form "[hid {content, edit summary, username}];
 66+ * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
 67+ *
 68+ * @param $count Integer: The number of effected revisions.
 69+ * @param $nbitfield Integer: The new bitfield for the revision.
 70+ * @param $obitfield Integer: The old bitfield for the revision.
 71+ * @param $isForLog Boolean
 72+ * @param $forContent Boolean
 73+ */
 74+ public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
 75+ global $wgLang, $wgContLang;
 76+
 77+ $lang = $forContent ? $wgContLang : $wgLang;
 78+ $msgFunc = $forContent ? "wfMsgForContent" : "wfMsg";
 79+
 80+ $changes = self::getChanges( $nbitfield, $obitfield );
 81+ array_walk($changes, 'RevisionDeleter::expandMessageArray', $forContent);
 82+
 83+ $changesText = array();
 84+
 85+ if( count( $changes[0] ) ) {
 86+ $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
 87+ }
 88+ if( count( $changes[1] ) ) {
 89+ $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
 90+ }
 91+
 92+ $s = $lang->semicolonList( $changesText );
 93+ if( count( $changes[2] ) ) {
 94+ $s .= $s ? ' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
 95+ }
 96+
 97+ $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
 98+ return wfMsgExt( $msg, $forContent ? array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
 99+ }
 100+
 101+ private static function expandMessageArray(& $msg, $key, $forContent) {
 102+ if ( is_array ($msg) ) {
 103+ array_walk($msg, 'RevisionDeleter::expandMessageArray', $forContent);
 104+ } else {
 105+ if ( $forContent ) {
 106+ $msg = wfMsgForContent($msg);
 107+ } else {
 108+ $msg = wfMsg($msg);
 109+ }
 110+ }
 111+ }
 112+
 113+ // Get DB field name for URL param...
 114+ // Future code for other things may also track
 115+ // other types of revision-specific changes.
 116+ // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
 117+ public static function getRelationType( $typeName ) {
 118+ if ( isset( SpecialRevisionDelete::$deprecatedTypeMap[$typeName] ) ) {
 119+ $typeName = SpecialRevisionDelete::$deprecatedTypeMap[$typeName];
 120+ }
 121+ if ( isset( SpecialRevisionDelete::$allowedTypes[$typeName] ) ) {
 122+ $class = SpecialRevisionDelete::$allowedTypes[$typeName]['list-class'];
 123+ $list = new $class( null, null, null );
 124+ return $list->getIdField();
 125+ } else {
 126+ return null;
 127+ }
 128+ }
 129+
 130+ // Checks if a revision still exists in the revision table.
 131+ // If it doesn't, returns the corresponding ar_timestamp field
 132+ // so that this key can be used instead.
 133+ public static function checkRevisionExistence( $title, $revid ) {
 134+ $dbr = wfGetDB( DB_SLAVE );
 135+ $exists = $dbr->selectField( 'revision', '1',
 136+ array( 'rev_id' => $revid ), __METHOD__ );
 137+
 138+ if ( $exists ) {
 139+ return true;
 140+ }
 141+
 142+ $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
 143+ array( 'ar_namespace' => $title->getNamespace(),
 144+ 'ar_title' => $title->getDBkey(),
 145+ 'ar_rev_id' => $revid ), __METHOD__ );
 146+
 147+ return $timestamp;
 148+ }
 149+
 150+ // Creates utility links for log entries.
 151+ public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
 152+ global $wgLang;
 153+
 154+ if( count($paramArray) >= 2 ) {
 155+ // Different revision types use different URL params...
 156+ $originalKey = $key = $paramArray[0];
 157+ // $paramArray[1] is a CSV of the IDs
 158+ $Ids = explode( ',', $paramArray[1] );
 159+
 160+ $revert = array();
 161+
 162+ // For if undeleted revisions are found amidst deleted ones.
 163+ $undeletedRevisions = array();
 164+
 165+ // This is not going to work if some revs are deleted and some
 166+ // aren't.
 167+ if ($key == 'revision') {
 168+ foreach( $Ids as $k => $id ) {
 169+ $existResult =
 170+ self::checkRevisionExistence( $title, $id );
 171+
 172+ if ($existResult !== true) {
 173+ $key = 'archive';
 174+ $Ids[$k] = $existResult;
 175+ } else {
 176+ // Undeleted revision amidst deleted ones
 177+ unset($Ids[$k]);
 178+ $undeletedRevisions[] = $id;
 179+ }
 180+ }
 181+
 182+ if ( $key == $originalKey ) {
 183+ $Ids = $undeletedRevisions;
 184+ $undeletedRevisions = array();
 185+ }
 186+ }
 187+
 188+ // Diff link for single rev deletions
 189+ if( count($Ids) == 1 && !count($undeletedRevisions) ) {
 190+ // Live revision diffs...
 191+ if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
 192+ $revert[] = $skin->link(
 193+ $title,
 194+ $messages['diff'],
 195+ array(),
 196+ array(
 197+ 'diff' => intval( $Ids[0] ),
 198+ 'unhide' => 1
 199+ ),
 200+ array( 'known', 'noclasses' )
 201+ );
 202+ // Deleted revision diffs...
 203+ } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
 204+ $revert[] = $skin->link(
 205+ SpecialPage::getTitleFor( 'Undelete' ),
 206+ $messages['diff'],
 207+ array(),
 208+ array(
 209+ 'target' => $title->getPrefixedDBKey(),
 210+ 'diff' => 'prev',
 211+ 'timestamp' => $Ids[0]
 212+ ),
 213+ array( 'known', 'noclasses' )
 214+ );
 215+ }
 216+ }
 217+
 218+ // View/modify link...
 219+ if ( count($undeletedRevisions) ) {
 220+ // FIXME THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
 221+ // It's not possible to pass a list of both deleted and
 222+ // undeleted revisions to SpecialRevisionDelete, so we're
 223+ // stuck with two links. See bug 23363.
 224+ $restoreLinks = array();
 225+
 226+ $restoreLinks[] = $skin->link(
 227+ SpecialPage::getTitleFor( 'Revisiondelete' ),
 228+ $messages['revdel-restore-visible'],
 229+ array(),
 230+ array(
 231+ 'target' => $title->getPrefixedText(),
 232+ 'type' => $originalKey,
 233+ 'ids' => implode(',', $undeletedRevisions),
 234+ ),
 235+ array( 'known', 'noclasses' )
 236+ );
 237+
 238+ $restoreLinks[] = $skin->link(
 239+ SpecialPage::getTitleFor( 'Revisiondelete' ),
 240+ $messages['revdel-restore-deleted'],
 241+ array(),
 242+ array(
 243+ 'target' => $title->getPrefixedText(),
 244+ 'type' => $key,
 245+ 'ids' => implode(',', $Ids),
 246+ ),
 247+ array( 'known', 'noclasses' )
 248+ );
 249+
 250+ $revert[] = $messages['revdel-restore'] . ' [' .
 251+ $wgLang->pipeList( $restoreLinks ) . ']';
 252+ } else {
 253+ $revert[] = $skin->link(
 254+ SpecialPage::getTitleFor( 'Revisiondelete' ),
 255+ $messages['revdel-restore'],
 256+ array(),
 257+ array(
 258+ 'target' => $title->getPrefixedText(),
 259+ 'type' => $key,
 260+ 'ids' => implode(',', $Ids),
 261+ ),
 262+ array( 'known', 'noclasses' )
 263+ );
 264+ }
 265+
 266+ // Pipe links
 267+ return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
 268+ }
 269+ return '';
 270+ }
 271+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/revisiondelete/RevisionDeleter.php
___________________________________________________________________
Added: svn:eol-style
1272 + native
Added: svn:keywords
2273 + Author Date Id Revision
Index: trunk/phase3/includes/AutoLoader.php
@@ -605,7 +605,7 @@
606606 'PreferencesForm' => 'includes/Preferences.php',
607607 'RandomPage' => 'includes/specials/SpecialRandompage.php',
608608 'SpecialRevisionDelete' => 'includes/specials/SpecialRevisiondelete.php',
609 - 'RevisionDeleter' => 'includes/revisiondelete/RevisionDelete.php',
 609+ 'RevisionDeleter' => 'includes/revisiondelete/RevisionDeleter.php',
610610 'RevDel_List' => 'includes/revisiondelete/RevisionDeleteAbstracts.php',
611611 'RevDel_Item' => 'includes/revisiondelete/RevisionDeleteAbstracts.php',
612612 'RevDel_RevisionList' => 'includes/revisiondelete/RevisionDelete.php',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66856bug 18608 done in a fashion much closer to how I should've done it originally....reedy23:24, 24 May 2010
r66858Try r66856 again - Less fail this time...reedy23:32, 24 May 2010
r77679Fixup 1 more autoloader from r77677...reedy20:30, 3 December 2010

Comments

#Comment by Catrope (talk | contribs)   00:24, 4 December 2010

This is a test comment for the code comments mailing list

#Comment by Catrope (talk | contribs)   00:31, 4 December 2010

And another test comment

#Comment by Catrope (talk | contribs)   00:41, 4 December 2010

Should really work now

#Comment by Catrope (talk | contribs)   00:50, 4 December 2010

Testing again

#Comment by Trevor Parscal (WMF) (talk | contribs)   00:51, 4 December 2010

Mailing list? I want to join!

Status & tagging log