r23763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23762‎ | r23763 | r23764 >
Date:02:02, 6 July 2007
Author:aaron
Status:old
Tags:
Comment:
*Some code cleanup; deal with dynamic transclusion exceptions better (rather than silent failure), don't allow fake timestamps
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -122,8 +122,6 @@
123123 # Set to false to disable this
124124 $wgFlaggedRevsAutopromote = array('days' => 60, 'edits' => 500, 'email' => true);
125125
126 -# What icons to display
127 -
128126 # Settings below this point should probably not be modified
129127 ############
130128
@@ -140,9 +138,9 @@
141139 global $wgFlaggedRevTags, $wgFlaggedRevValues;
142140
143141 $this->dimensions = array();
144 - foreach ( array_keys($wgFlaggedRevTags) as $tag ) {
 142+ foreach( array_keys($wgFlaggedRevTags) as $tag ) {
145143 $this->dimensions[$tag] = array();
146 - for ($i=0; $i <= $wgFlaggedRevValues; $i++) {
 144+ for($i=0; $i <= $wgFlaggedRevValues; $i++) {
147145 $this->dimensions[$tag][$i] = "$tag-$i";
148146 }
149147 }
@@ -150,22 +148,24 @@
151149
152150 /**
153151 * @param string $text
154 - * @returns string
 152+ * @returns array( string, bool )
155153 * All included pages/arguments are expanded out
156154 */
157 - public static function expandText( $text, $title, $id=null ) {
 155+ public static function expandText( $text='', $title, $id=null ) {
158156 global $wgParser;
159 -
160 - $text = $text ? $text : '';
161 - $wgParser->isStable = true; // Causes our hooks to trigger
162 -
 157+ # Causes our hooks to trigger
 158+ $wgParser->isStable = true;
 159+ $wgParser->includesMatched = true;
 160+ # Parse with default options
163161 $options = new ParserOptions;
164 - $options->setRemoveComments( true ); // Less banwidth?
 162+ $options->setRemoveComments( true ); // Save some bandwidth ;)
165163 $outputText = $wgParser->preprocess( $text, $title, $options, $id );
 164+ $expandedText = array( $outputText, $wgParser->includesMatched );
 165+ # Done!
 166+ $wgParser->isStable = false;
 167+ $wgParser->includesMatched = false;
166168
167 - $wgParser->isStable = false; // Done!
168 -
169 - return $outputText;
 169+ return $expandedText;
170170 }
171171
172172 /**
@@ -407,12 +407,13 @@
408408
409409 public static function ReviewNotes( $row ) {
410410 global $wgUser, $wgFlaggedRevComments;
411 - $notes = '';
412 - if( !$row || !$wgFlaggedRevComments) return $notes;
413411
 412+ if( !$row || !$wgFlaggedRevComments )
 413+ return $notes;
 414+
414415 if( $row->fr_comment ) {
415416 $skin = $wgUser->getSkin();
416 - $notes .= '<p><div class="flaggedrevs_notes plainlinks">';
 417+ $notes = '<p><div class="flaggedrevs_notes plainlinks">';
417418 $notes .= wfMsgExt('revreview-note', array('parse'), User::whoIs( $row->fr_user ) );
418419 $notes .= '<i>' . $skin->formatComment( $row->fr_comment ) . '</i></div></p><br/>';
419420 }
@@ -676,21 +677,17 @@
677678 // Trigger for stable version parsing only
678679 if( !isset($parser->isStable) || !$parser->isStable )
679680 return true;
680 -
681 - $dbr = wfGetDB( DB_SLAVE );
682 - $id = $dbr->selectField('flaggedtemplates', 'ft_tmp_rev_id',
683 - array('ft_rev_id' => $parser->mRevisionId,
 681+ // Only called to make fr_text, right after template/image specifiers
 682+ // are added to the DB. It's unlikely for slaves to have it yet
 683+ $dbw = wfGetDB( DB_MASTER );
 684+ $id = $dbw->selectField('flaggedtemplates', 'ft_tmp_rev_id',
 685+ array('ft_rev_id' => $parser->mRevisionId,
684686 'ft_namespace' => $title->getNamespace(), 'ft_title' => $title->getDBkey() ),
685687 __METHOD__ );
686 - // Slave lag maybe? try master...
687 - if( $id===false ) {
688 - $dbw = wfGetDB( DB_MASTER );
689 - $id = $dbw->selectField('flaggedtemplates', 'ft_tmp_rev_id',
690 - array('ft_rev_id' => $parser->mRevisionId,
691 - 'ft_namespace' => $title->getNamespace(), 'ft_title' => $title->getDBkey() ),
692 - __METHOD__ );
693 - }
 688+
694689 if( !$id ) {
 690+ if( $id === false )
 691+ $parser->includesMatched = false; // May want to give an error
695692 $id = 0; // Zero for not found
696693 $skip = true;
697694 }
@@ -702,18 +699,16 @@
703700 if( !isset($parser->isStable) || !$parser->isStable )
704701 return true;
705702
706 - $dbr = wfGetDB( DB_SLAVE );
707 - $time = $dbr->selectField('flaggedimages', 'fi_img_timestamp',
 703+ // Only called to make fr_text, right after template/image specifiers
 704+ // are added to the DB. It's unlikely for slaves to have it yet
 705+ $dbw = wfGetDB( DB_MASTER );
 706+ $time = $dbw->selectField('flaggedimages', 'fi_img_timestamp',
708707 array('fi_rev_id' => $parser->mRevisionId, 'fi_name' => $nt->getDBkey() ),
709708 __METHOD__ );
710 - // Slave lag maybe? try master...
711 - if( $time===false ) {
712 - $dbw = wfGetDB( DB_MASTER );
713 - $time = $dbw->selectField('flaggedimages', 'fi_img_timestamp',
714 - array('fi_rev_id' => $parser->mRevisionId, 'fi_name' => $nt->getDBkey() ),
715 - __METHOD__ );
716 - }
 709+
717710 if( !$time ) {
 711+ if( $time === false )
 712+ $parser->includesMatched = false; // May want to give an error
718713 $time = 0; // Zero for not found
719714 $skip = true;
720715 }
@@ -1214,8 +1209,7 @@
12151210 $form .= wfHidden( 'oldid', $id );
12161211 $form .= wfHidden( 'action', 'submit');
12171212 $form .= wfHidden( 'wpEditToken', $wgUser->editToken() );
1218 - // It takes time to review, make sure that we record what the reviewer had in mind
1219 - $form .= wfHidden( 'wpTimestamp', wfTimestampNow() );
 1213+
12201214 foreach( $this->dimensions as $quality => $levels ) {
12211215 $options = ''; $disabled = '';
12221216 foreach( $levels as $idx => $label ) {
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php
@@ -52,8 +52,6 @@
5353 // Special parameter mapping
5454 $this->templateParams = $wgRequest->getVal( 'templateParams' );
5555 $this->imageParams = $wgRequest->getVal( 'imageParams' );
56 - // Time of page view when viewed
57 - $this->timestamp = $wgRequest->getVal( 'wpTimestamp' );
5856 // Log comment
5957 $this->comment = $wgRequest->getText( 'wpReason' );
6058 // Additional notes
@@ -123,8 +121,8 @@
124122 * @param webrequest $request
125123 */
126124 function showRevision( $request ) {
127 - global $wgOut, $wgUser, $wgTitle,
128 - $wgFlaggedRevComments, $wgFlaggedRevTags, $wgFlaggedRevValues;
 125+ global $wgOut, $wgUser, $wgTitle, $wgFlaggedRevComments, $wgFlaggedRevsOverride,
 126+ $wgFlaggedRevTags, $wgFlaggedRevValues;
129127
130128 if ( !$this->isValid )
131129 $wgOut->addWikiText( '<strong>' . wfMsg( 'revreview-toolow' ) . '</strong>' );
@@ -139,11 +137,14 @@
140138 $wgOut->showErrorPage( 'internalerror', 'notargettitle', 'notargettext' );
141139 return;
142140 }
 141+
143142 $wgOut->addHtml( "<ul>" );
144143 $wgOut->addHtml( $this->historyLine( $rev ) );
145144 $wgOut->addHtml( "</ul>" );
146145
147 - $wgOut->addWikiText( wfMsg('revreview-text') );
 146+ if( $wgFlaggedRevsOverride )
 147+ $wgOut->addWikiText( wfMsg('revreview-text') );
 148+
148149 $formradios = array();
149150 // Dynamically contruct our radio options
150151 foreach ( array_keys($wgFlaggedRevTags) as $tag ) {
@@ -261,7 +262,7 @@
262263 }
263264 $wgOut->redirect( $this->page->escapeLocalUrl() );
264265 } else {
265 - $wgOut->showErrorPage( 'internalerror', 'badarticleerror' );
 266+ $wgOut->showErrorPage( 'internalerror', 'revreview-changed' );
266267 }
267268 }
268269
@@ -272,18 +273,16 @@
273274 function approveRevision( $rev=NULL, $notes='' ) {
274275 global $wgUser, $wgFlaggedRevsWatch, $wgParser;
275276
276 - if( is_null($rev) ) return false;
277 - // No bogus timestamps
278 - if ( $this->timestamp && ($this->timestamp < $rev->getTimestamp() || $this->timestamp > wfTimestampNow()) )
 277+ if( is_null($rev) )
279278 return false;
 279+ // Get the page this corresponds to
 280+ $title = $rev->getTitle();
280281
281282 $quality = 0;
282283 if ( FlaggedRevs::isQuality($this->dims) ) {
283284 $quality = FlaggedRevs::getLCQuality($this->dims);
284285 $quality = ($quality > 1) ? $quality : 1;
285286 }
286 - // Get the page this corresponds to
287 - $title = $rev->getTitle();
288287 // Our flags
289288 $flagset = array();
290289 foreach( $this->dims as $tag => $value ) {
@@ -301,7 +300,7 @@
302301 if( !$template ) continue;
303302
304303 $m = explode('|',$template,2);
305 - if( !isset($m[0]) || !isset($m[1]) || !$m[0] || !$m[1] ) continue;
 304+ if( !isset($m[0]) || !isset($m[1]) || !$m[0] ) continue;
306305
307306 list($prefixed_text,$rev_id) = $m;
308307
@@ -325,7 +324,7 @@
326325 if( !$image ) continue;
327326 $m = explode('|',$image,2);
328327
329 - if( !isset($m[0]) || !isset($m[1]) || !$m[0] || !$m[1] ) continue;
 328+ if( !isset($m[0]) || !isset($m[1]) || !$m[0] ) continue;
330329
331330 list($dbkey,$timestamp) = $m;
332331
@@ -342,8 +341,8 @@
343342 );
344343 }
345344
346 - wfProfileIn( __METHOD__ );
347345 $dbw = wfGetDB( DB_MASTER );
 346+ $dbw->begin();
348347 // Update our versioning pointers
349348 if( !empty( $tmpset ) ) {
350349 $dbw->replace( 'flaggedtemplates', array( array('ft_rev_id','ft_namespace','ft_title') ), $tmpset,
@@ -354,14 +353,18 @@
355354 __METHOD__ );
356355 }
357356 // Get the page text and resolve all templates
358 - $fulltext = FlaggedRevs::expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
 357+ list($fulltext,$complete) = FlaggedRevs::expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
 358+ if( !$complete ) {
 359+ $dbw->rollback(); // All versions must be specified, 0 for none
 360+ return false;
 361+ }
359362 // Our review entry
360363 $revset = array(
361364 'fr_rev_id' => $rev->getId(),
362365 'fr_namespace' => $title->getNamespace(),
363366 'fr_title' => $title->getDBkey(),
364367 'fr_user' => $wgUser->getId(),
365 - 'fr_timestamp' => $this->timestamp,
 368+ 'fr_timestamp' => wfTimestampNow(),
366369 'fr_comment' => $notes,
367370 'fr_text' => $fulltext, // Store expanded text for speed
368371 'fr_quality' => $quality
@@ -370,12 +373,13 @@
371374 $dbw->replace( 'flaggedrevs', array( array('fr_rev_id','fr_namespace','fr_title') ), $revset, __METHOD__ );
372375 // Set all of our flags
373376 $dbw->replace( 'flaggedrevtags', array( array('frt_rev_id','frt_dimension') ), $flagset, __METHOD__ );
374 -
375377 // Mark as patrolled
376378 $dbw->update( 'recentchanges',
377379 array( 'rc_patrolled' => 1 ),
378 - array( 'rc_this_oldid' => $rev->getId() ), __METHOD__
 380+ array( 'rc_this_oldid' => $rev->getId() ),
 381+ __METHOD__
379382 );
 383+ $dbw->commit();
380384
381385 // Update the article review log
382386 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, true );
@@ -389,7 +393,7 @@
390394 $poutput = $wgParser->parse($text, $article->mTitle, ParserOptions::newFromUser($wgUser));
391395 }
392396 $u = new LinksUpdate( $this->page, $poutput );
393 - $u->doUpdate(); // this will trigger our hook to add stable links too...
 397+ $u->doUpdate(); // Will trigger our hook to add stable links too...
394398
395399 # Clear the cache...
396400 $this->page->invalidateCache();
@@ -398,8 +402,6 @@
399403 # Purge squid for this page only
400404 $this->page->purgeSquid();
401405
402 - wfProfileOut( __METHOD__ );
403 -
404406 return true;
405407 }
406408
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -87,7 +87,12 @@
8888 'revreview-style-3' => 'Concise',
8989 'revreview-style-4' => 'Featured',
9090 'revreview-log' => 'Log comment:',
91 - 'revreview-submit' => 'Apply review',
 91+ 'revreview-submit' => 'Submit review',
 92+ 'revreview-changed' => '\'\'\'The requestion action could not be performed on this revision.\'\'\'
 93+
 94+ A template or image may have been requested when no specific version was specified. This can happen if a
 95+ dynamic template transcludes another image or template depending on a variable that changed since you started
 96+ reviewed this page. Refreshing the page and rereviewing can solve this problem.',
9297
9398 'stableversions' => 'Stable versions',
9499 'stableversions-leg1' => 'List reviewed revisions for a page',

Status & tagging log