r22124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22123‎ | r22124 | r22125 >
Date:17:25, 12 May 2007
Author:aaron
Status:old
Tags:
Comment:
*Fix some link update quirks
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -76,9 +76,10 @@
7777 # How long to cache stable versions? (seconds)
7878 $wgFlaggedRevsExpire = 7 * 24 * 3600;
7979 # MW can try to dynamically parse text from a timeframe, however
80 -# it does have limitations. Using expanded text cache will avoid
81 -# this issues with regard to transcluded page moves/deletes. However
82 -# messages like {{CURRENTDATE}} will not remain dynamic.
 80+# it does have limitations when thins such as special:import are used.
 81+# However messages like {{CURRENTDATE}} will not remain dynamic if
 82+# $wgUseExpandedCache is true. Conditional template inclusions will
 83+# also no longer be updated.
8384 $wgUseExpandedCache = false;
8485
8586 # When setting up new dimensions or levels, you will need to add some
@@ -252,9 +253,9 @@
253254 public static function getReviewedRevs( $page ) {
254255 wfProfileIn( __METHOD__ );
255256
256 - $db = wfGetDB( DB_SLAVE );
 257+ $db = wfGetDB( DB_SLAVE );
257258 $rows = array();
258 - // Skip deleted revisions
 259+
259260 $result = $db->select(
260261 array('flaggedrevs'),
261262 array('fr_rev_id','fr_quality'),
@@ -276,8 +277,7 @@
277278 wfProfileIn( __METHOD__ );
278279
279280 $db = wfGetDB( DB_SLAVE );
280 - $count = $db->selectField('revision',
281 - 'COUNT(*)',
 281+ $count = $db->selectField('revision', 'COUNT(*)',
282282 array('rev_page' => $page_id, "rev_id > $from_rev"),
283283 __METHOD__ );
284284
@@ -299,7 +299,7 @@
300300 array('flaggedrevs', 'revision'),
301301 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
302302 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
303 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 303+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
304304 __METHOD__,
305305 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
306306 // Do we have one?
@@ -308,7 +308,7 @@
309309 array('flaggedrevs', 'revision'),
310310 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
311311 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
312 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 312+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
313313 __METHOD__,
314314 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
315315 if( !$row = $dbr->fetchObject($result) )
@@ -464,6 +464,7 @@
465465 }
466466
467467 wfProfileOut( $fname );
 468+
468469 return $value;
469470 }
470471
@@ -475,13 +476,13 @@
476477 public static function updatePageCache( $article, $parserOutput=NULL ) {
477478 global $wgUser, $parserMemc, $wgFlaggedRevsExpire;
478479 // Make sure it is valid
479 - if ( is_null($parserOutput) || !$article )
480 - return false;
 480+ if ( is_null($parserOutput) || !$article ) return false;
 481+
481482 // Update the cache...
482483 $article->mTitle->invalidateCache();
483484
484485 $key = 'sv-' . ParserCache::getKey( $article, $wgUser );
485 - // Add cache mark to HTML
 486+ // Add cache mark to HTML
486487 $now = wfTimestampNow();
487488 $parserOutput->setCacheTime( $now );
488489
@@ -511,17 +512,23 @@
512513 __METHOD__ );
513514 }
514515
515 - public static function extraLinksUpdate( &$article ) {
 516+ public static function extraLinksUpdate( &$title ) {
516517 $fname = 'FlaggedRevs::extraLinksUpdate';
517518 wfProfileIn( $fname );
 519+
 520+ $article = new Article( $title );
 521+ if( !$article ) return;
518522 # Check if this page has a stable version
519523 $sv = self::getOverridingPageRev( $article );
520 - if ( !$sv ) return;
 524+ if( !$sv ) return;
521525 # Retrieve the text
522526 $text = self::getFlaggedRevText( $sv->fr_rev_id );
523527 # Parse the revision
524 - $options = ParserOptions::newFromUser($wgUser);
 528+ $options = new ParserOptions;
525529 $poutput = self::parseStableText( $article->mTitle, $text, $sv->fr_rev_id, $options, $sv->fr_timestamp );
 530+
 531+ # Might as well update the cache while we're at it
 532+ FlaggedRevs::updatePageCache( $article, $poutput );
526533
527534 # Update the links tables to include these
528535 # We want the UNION of links between the current
@@ -916,16 +923,18 @@
917924 }
918925
919926 function addToDiff( &$diff, &$oldrev, &$newrev ) {
920 - $id = $newrev->getId();
921 - // We cannot review deleted edits
922 - if( $newrev->mDeleted ) return;
923 - $this->addQuickReview( $id );
 927+ $id = $newrev->getId();
 928+ // We cannot review deleted edits
 929+ if( !$newrev->mDeleted )
 930+ $this->addQuickReview( $id );
924931 }
925932
926933 function addToPageHist( &$article ) {
927934 $this->pageFlaggedRevs = array();
928935 $rows = $this->getReviewedRevs( $article->getTitle() );
 936+
929937 if( !$rows ) return;
 938+
930939 foreach( $rows as $rev => $quality ) {
931940 $this->pageFlaggedRevs[$rev] = $quality;
932941 }
@@ -989,7 +998,7 @@
990999 array('flaggedrevs', 'revision'),
9911000 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
9921001 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
993 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 1002+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
9941003 __METHOD__,
9951004 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
9961005 // Do we have one?
@@ -1030,7 +1039,7 @@
10311040 array('flaggedrevs', 'revision'),
10321041 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
10331042 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
1034 - 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted=0'),
 1043+ 'fr_rev_id = rev_id', 'rev_page' => $article->getId(), 'rev_deleted = 0'),
10351044 __METHOD__,
10361045 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
10371046 // Do we have one?
@@ -1093,7 +1102,7 @@
10941103
10951104 $wgHooks['ArticleSaveComplete'][] = array($flaggedrevs, 'autoPromoteUser');
10961105
1097 -$wgHooks['ArticleEditUpdatesDeleteFromRecentchanges'][] = array($flaggedrevs, 'extraLinksUpdate');
 1106+$wgHooks['TitleLinkUpdatesAfterCompletion'][] = array($flaggedrevs, 'extraLinksUpdate');
10981107 $wgHooks['ArticleRevisionVisiblityUpdates'][] = array($flaggedrevs, 'extraLinksUpdate');
10991108 $wgHooks['SpecialMovepageAfterMove'][] = array($flaggedrevs, 'updateFromMove');
11001109 ?>
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.body.php
@@ -289,10 +289,21 @@
290290 // Update the article review log
291291 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, true );
292292
293 - # Update our links if needed
294293 $article = new Article( $this->page );
295 - FlaggedRevs::extraLinksUpdate( $article );
 294+ // Update the links tables as a new stable version
 295+ // may now be the default page.
 296+ $parserCache =& ParserCache::singleton();
 297+ $poutput = $parserCache->get( $article, $wgUser );
 298+ if ( $poutput==false ) {
 299+ $text = $article->getContent();
 300+ $poutput = $wgParser->parse($text, $article->mTitle, ParserOptions::newFromUser($wgUser));
 301+ }
 302+ $u = new LinksUpdate( $this->page, $poutput );
 303+ $u->doUpdate();
296304
 305+ # Might as well update the cache while we're at it
 306+ $parserCache->save( $poutput, $article, $wgUser );
 307+
297308 # Clear the cache...
298309 $this->page->invalidateCache();
299310 # Purge squid for this page only
@@ -324,10 +335,21 @@
325336 // Update the article review log
326337 $this->updateLog( $this->page, $this->dims, $this->comment, $this->oldid, false );
327338
328 - # Update our links if needed
329339 $article = new Article( $this->page );
330 - FlaggedRevs::extraLinksUpdate( $article );
 340+ // Update the links tables as a new stable version
 341+ // may now be the default page.
 342+ $parserCache =& ParserCache::singleton();
 343+ $poutput = $parserCache->get( $article, $wgUser );
 344+ if ( $poutput==false ) {
 345+ $text = $article->getContent();
 346+ $poutput = $wgParser->parse($text, $article->mTitle, ParserOptions::newFromUser($wgUser));
 347+ }
 348+ $u = new LinksUpdate( $this->page, $poutput );
 349+ $u->doUpdate();
331350
 351+ # Might as well update the cache while we're at it
 352+ $parserCache->save( $poutput, $article, $wgUser );
 353+
332354 # Clear the cache...
333355 $this->page->invalidateCache();
334356 # Purge squid for this page only
@@ -353,10 +375,14 @@
354376 }
355377 $rating = ($approve) ? ' [' . implode(', ',$ratings). ']' : '';
356378 // Append comment with action
 379+ // FIXME: do this better
357380 $action = wfMsgExt('review-logaction', array('parsemag'), $oldid );
358 - $comment = ($comment) ? "$action: $comment$rating" : "$action $rating";
 381+ if( $approve )
 382+ $comment = ($comment) ? "$action: $comment$rating" : "$action $rating";
 383+ else
 384+ $comment = ($comment) ? "$action: $comment" : "$action";
359385
360 - if ( $approve ) {
 386+ if( $approve ) {
361387 $log->addEntry( 'approve', $title, $comment );
362388 } else {
363389 $log->addEntry( 'unapprove', $title, $comment );