r25422 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25421‎ | r25422 | r25423 >
Date:05:42, 3 September 2007
Author:aaron
Status:old
Tags:
Comment:
*More consitent parsing wrt tidy/user.
*Try cache when autoreviewing, should be up to date and faster.
*Remove aliasing.
*Tweak messages.
*Fix typo in error message.
*Fix '__METHOD__' where it belongs.
*Use $needed, not the array value (it's 1 too high)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -71,7 +71,8 @@
7272 # This will only distinguish "sigted", "quality", and unreviewed
7373 # A small icon will show in the upper right hand corner
7474 $wgSimpleFlaggedRevsUI = false;
75 -# Add stable/current revision tabs. May be redundant due to the tags.
 75+# Add stable/draft revision tabs. May be redundant due to the tags.
 76+# If you have an open wiki, with the simple UI, you may want to enable these.
7677 $wgFlaggedRevTabs = false;
7778
7879 # Allowed namespaces of reviewable pages
@@ -149,8 +150,8 @@
150151 'userpage' => true
151152 );
152153
153 -#
154 -############ Variables below this point should probably not be modified ############
 154+# Variables below this point should probably not be modified
 155+#########
155156
156157 # Add review log
157158 $wgLogTypes[] = 'review';
@@ -203,12 +204,12 @@
204205 * All included pages/arguments are expanded out
205206 */
206207 public static function expandText( $text='', $title, $id=null ) {
207 - global $wgParser;
 208+ global $wgParser, $wgUser;
208209 # Make our hooks to trigger
209210 $wgParser->isStable = true;
210211 $wgParser->includesMatched = true;
211212 # Parse with default options
212 - $options = new ParserOptions;
 213+ $options = new ParserOptions($wgUser);
213214 $options->setRemoveComments( true ); // Save some bandwidth ;)
214215 $outputText = $wgParser->preprocess( $text, $title, $options, $id );
215216 $expandedText = array( $outputText, $wgParser->includesMatched );
@@ -220,23 +221,23 @@
221222 }
222223
223224 /**
224 - * @param Title $title
 225+ * @param Article $article
225226 * @param string $text
226227 * @param int $id
227 - * @param ParserOptions $options
228 - * @param int $timeframe, when the revision was reviewed
229228 * @returns ParserOutput
230229 * Get the HTML of a revision based on how it was during $timeframe
231230 */
232 - public static function parseStableText( $title, $text, $id=NULL, $options ) {
233 - global $wgParser;
 231+ public static function parseStableText( $article, $text, $id=NULL ) {
 232+ global $wgParser, $wgUser;
 233+ # Default options for anons if not logged in
 234+ $options = ParserOptions::newFromUser($wgUser);
234235 # Make our hooks to trigger
235236 $wgParser->isStable = true;
236 - # Don't show section-edit links
237 - # They can be old and misleading
 237+ # Don't show section-edit links, they can be old and misleading
238238 $options->setEditSection(false);
 239+ //$options->setEditSection( $id==$article->getLatest() );
239240 # Parse the new body, wikitext -> html
240 - $parserOut = $wgParser->parse( $text, $title, $options, true, true, $id );
 241+ $parserOut = $wgParser->parse( $text, $article->getTitle(), $options, true, true, $id );
241242 # Reset $wgParser
242243 $wgParser->isStable = false; // Done!
243244
@@ -257,7 +258,7 @@
258259 $text = gzdeflate( $text );
259260 $flags[] = 'gzip';
260261 } else {
261 - wfDebug( "Revision::compressRevisionText() -- no zlib support, not compressing\n" );
 262+ wfDebug( "FlaggedRevs::compressText() -- no zlib support, not compressing\n" );
262263 }
263264 }
264265 return implode( ',', $flags );
@@ -648,13 +649,13 @@
649650
650651 /**
651652 * @param Article $article
652 - * @param parerOutput $parserOutput
653 - * Updates the stable cache of a page with the given $parserOutput
 653+ * @param parerOutput $parserOut
 654+ * Updates the stable cache of a page with the given $parserOut
654655 */
655 - public static function updatePageCache( $article, $parserOutput=NULL ) {
 656+ public static function updatePageCache( $article, $parserOut=NULL ) {
656657 global $wgUser, $parserMemc, $wgFlaggedRevsExpire;
657658 // Make sure it is valid
658 - if( is_null($parserOutput) || !$article ) return false;
 659+ if( is_null($parserOut) || !$article ) return false;
659660
660661 // Update the cache...
661662 $article->mTitle->invalidateCache();
@@ -663,20 +664,20 @@
664665 $key = 'sv-' . $parserCache->getKey( $article, $wgUser );
665666 // Add cache mark to HTML
666667 $now = wfTimestampNow();
667 - $parserOutput->setCacheTime( $now );
 668+ $parserOut->setCacheTime( $now );
668669
669670 // Save the timestamp so that we don't have to load the revision row on view
670 - $parserOutput->mTimestamp = $article->getTimestamp();
 671+ $parserOut->mTimestamp = $article->getTimestamp();
671672
672 - $parserOutput->mText .= "\n<!-- Saved in stable version parser cache with key $key and timestamp $now -->";
 673+ $parserOut->mText .= "\n<!-- Saved in stable version parser cache with key $key and timestamp $now -->";
673674 // Set expire time
674 - if( $parserOutput->containsOldMagic() ){
 675+ if( $parserOut->containsOldMagic() ){
675676 $expire = 3600; # 1 hour
676677 } else {
677678 $expire = $wgFlaggedRevsExpire;
678679 }
679680 // Save to objectcache
680 - $parserMemc->set( $key, $parserOutput, $expire );
 681+ $parserMemc->set( $key, $parserOut, $expire );
681682 // Purge squid for this page only
682683 $article->mTitle->purgeSquid();
683684
@@ -767,25 +768,24 @@
768769 if( !$sv )
769770 return true;
770771 # Parse the revision
771 - $options = new ParserOptions;
 772+ $article = new Article( $linksUpdate->mTitle );
772773 $text = self::uncompressText( $sv->fr_text, $sv->fr_flags );
773 - $parserOutput = self::parseStableText( $linksUpdate->mTitle, $text, $sv->fr_rev_id, $options );
 774+ $parserOut = self::parseStableText( $article, $text, $sv->fr_rev_id );
774775 # Might as well update the stable cache while we're at it
775 - $article = new Article( $linksUpdate->mTitle );
776 - FlaggedRevs::updatePageCache( $article, $parserOutput );
 776+ FlaggedRevs::updatePageCache( $article, $parserOut );
777777 # Update page fields
778778 FlaggedRevs::updateArticleOn( $article, $sv->fr_rev_id );
779779 # Update the links tables to include these
780780 # We want the UNION of links between the current
781781 # and stable version. Therefore, we only care about
782782 # links that are in the stable version and not the regular one.
783 - $linksUpdate->mLinks += $parserOutput->getLinks();
784 - $linksUpdate->mImages += $parserOutput->getImages();
785 - $linksUpdate->mTemplates += $parserOutput->getTemplates();
786 - $linksUpdate->mExternals += $parserOutput->getExternalLinks();
787 - $linksUpdate->mCategories += $parserOutput->getCategories();
 783+ $linksUpdate->mLinks += $parserOut->getLinks();
 784+ $linksUpdate->mImages += $parserOut->getImages();
 785+ $linksUpdate->mTemplates += $parserOut->getTemplates();
 786+ $linksUpdate->mExternals += $parserOut->getExternalLinks();
 787+ $linksUpdate->mCategories += $parserOut->getCategories();
788788 # Interlanguage links
789 - $ill = $parserOutput->getLanguageLinks();
 789+ $ill = $parserOut->getLanguageLinks();
790790 foreach( $ill as $link ) {
791791 list( $key, $title ) = explode( ':', $link, 2 );
792792 $linksUpdate->mInterlangs[$key] = $title;
@@ -895,8 +895,8 @@
896896 /**
897897 * Insert image timestamps/SHA-1s into page output
898898 */
899 - static function outputInjectImageTimestamps( $out, $parserOutput ) {
900 - $out->mImageSHA1Keys = $parserOutput->mImageSHA1Keys;
 899+ static function outputInjectImageTimestamps( $out, $parserOut ) {
 900+ $out->mImageSHA1Keys = $parserOut->mImageSHA1Keys;
901901
902902 return true;
903903 }
@@ -955,15 +955,18 @@
956956 * When an edit is made by a reviwer, if the current revision is the stable
957957 * version, try to automatically review it.
958958 */
959 - public static function maybeMakeEditReviewed( $article, $user, $text, $c, $flags, $a, $b, $flags, $rev ) {
 959+ public static function maybeMakeEditReviewed( $article, $user, $text, $c, $m, $a, $b, $flags, $rev ) {
960960 global $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
961961
962962 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed( 'review' ) )
963963 return true;
 964+ # Revision will be null for null edits
964965 if( !$rev ) {
965966 $wgFlaggedRevs->skipReviewDiff = true; // Don't jump to diff...
966967 return true;
967968 }
 969+ # Check if this new revision is now the current one.
 970+ # ArticleSaveComplete may trigger even though a confict blocked insertion.
968971 $prev_id = $article->mTitle->getPreviousRevisionID( $rev->getID() );
969972 if( !$prev_id )
970973 return true;
@@ -995,6 +998,7 @@
996999
9971000 if( !$wgFlaggedRevsAutoReviewNew || !$user->isAllowed( 'review' ) )
9981001 return true;
 1002+ # Revision will be null for null edits
9991003 if( !$rev ) {
10001004 $wgFlaggedRevs->skipReviewDiff = true; // Don't jump to diff...
10011005 return true;
@@ -1017,7 +1021,7 @@
10181022 * fields will be up to date. This updates the stable version.
10191023 */
10201024 public static function autoReviewEdit( $article, $user, $text, $rev, $flags ) {
1021 - global $wgParser, $parserCache, $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
 1025+ global $wgParser, $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
10221026
10231027 $quality = 0;
10241028 if( FlaggedRevs::isQuality($flags) ) {
@@ -1031,11 +1035,17 @@
10321036 'frt_value' => $value
10331037 );
10341038 }
1035 - # Parse the text, we cannot rely on cache, may be out of date or not used.
1036 - # Also, we need the expanded text anyway.
1037 - $options = new ParserOptions;
1038 - $options->setTidy(true);
1039 - $poutput = $wgParser->parse( $text, $article->mTitle, $options, true, true, $rev->getID() );
 1039+ # Try the parser cache, should be set on the edit before this is called.
 1040+ # If not set or up to date, then parse it...
 1041+ $parserCache =& ParserCache::singleton();
 1042+ $poutput = $parserCache->get( $article, $user );
 1043+ if( $poutput==false ) {
 1044+ $options = ParserOptions::newFromUser($user);
 1045+ $options->setTidy(true);
 1046+ $poutput = $wgParser->parse( $text, $article->mTitle, $options, true, true, $rev->getID() );
 1047+ # Might as well save the cache while we're at it
 1048+ $parserCache->save( $poutput, $article, $user );
 1049+ }
10401050 # NS:title -> rev ID mapping
10411051 foreach( $poutput->mTemplateIds as $namespace => $title ) {
10421052 foreach( $title as $dbkey => $id ) {
@@ -1163,6 +1173,7 @@
11641174 $dbr = wfGetDB( DB_SLAVE );
11651175 $lower = $dbr->selectField( 'revision', 'rev_timestamp',
11661176 array( 'rev_user' => $user->getID() ),
 1177+ __METHOD__,
11671178 array( 'ORDER BY' => 'rev_timestamp ASC',
11681179 'USE INDEX' => 'user_timestamp' ) );
11691180 # Recursevly check for for an edit $spacing days later, until we are done.
@@ -1178,7 +1189,7 @@
11791190 if( $lower !==false )
11801191 $benchmarks++;
11811192 }
1182 - if( $benchmarks < $wgFlaggedRevsAutopromote['benchmarks'] )
 1193+ if( $benchmarks < $needed )
11831194 return true;
11841195 }
11851196 # Add editor rights
@@ -1205,11 +1216,11 @@
12061217 return true;
12071218
12081219 $parserCache =& ParserCache::singleton();
1209 - $parserOutput = $parserCache->get( $article, $wgUser );
1210 - if( $parserOutput ) {
 1220+ $parserOut = $parserCache->get( $article, $wgUser );
 1221+ if( $parserOut ) {
12111222 // Clear older, incomplete, cached versions
12121223 // We need the IDs of templates and timestamps of images used
1213 - if( !isset($parserOutput->mTemplateIds) || !isset($parserOutput->mImageSHA1Keys) )
 1224+ if( !isset($parserOut->mTemplateIds) || !isset($parserOut->mImageSHA1Keys) )
12141225 $article->mTitle->invalidateCache();
12151226 }
12161227 return true;
@@ -1345,21 +1356,20 @@
13461357 }
13471358 }
13481359 # Try the stable page cache
1349 - $parserOutput = parent::getPageCache( $article );
 1360+ $parserOut = parent::getPageCache( $article );
13501361 # If no cache is available, get the text and parse it
1351 - if( $parserOutput==false ) {
 1362+ if( $parserOut==false ) {
13521363 $text = parent::getFlaggedRevText( $vis_id );
1353 - $options = ParserOptions::newFromUser($wgUser);
1354 - $parserOutput = parent::parseStableText( $wgTitle, $text, $vis_id, $options );
 1364+ $parserOut = parent::parseStableText( $article, $text, $vis_id );
13551365 # Update the general cache
1356 - parent::updatePageCache( $article, $parserOutput );
 1366+ parent::updatePageCache( $article, $parserOut );
13571367 }
1358 - $wgOut->mBodytext = $parserOutput->getText();
 1368+ $wgOut->mBodytext = $parserOut->getText();
13591369 # Show stable categories and interwiki links only
13601370 $wgOut->mCategoryLinks = array();
1361 - $wgOut->addCategoryLinks( $parserOutput->getCategories() );
 1371+ $wgOut->addCategoryLinks( $parserOut->getCategories() );
13621372 $wgOut->mLanguageLinks = array();
1363 - $wgOut->addLanguageLinks( $parserOutput->getLanguageLinks() );
 1373+ $wgOut->addLanguageLinks( $parserOut->getLanguageLinks() );
13641374 $notes = parent::ReviewNotes( $tfrev );
13651375 # Tell MW that parser output is done
13661376 $outputDone = true;
@@ -1519,21 +1529,28 @@
15201530 // change the edit tab to a "current revision" tab
15211531 $tfrev = $this->getOverridingRev();
15221532 // No quality revs? Find the last reviewed one
1523 - if( !is_object($tfrev) )
 1533+ if( !is_object($tfrev) )
15241534 return true;
 1535+ /*
 1536+ // If the stable version is the same is the current, move along...
 1537+ if( $article->getLatest() == $tfrev->fr_rev_id ) {
 1538+ return true;
 1539+ }
 1540+ */
15251541 if( !$wgFlaggedRevTabs ) {
15261542 if( $this->pageOverride() ) {
1527 - # Remove edit option altogether
1528 - unset( $content_actions['edit']);
1529 - unset( $content_actions['viewsource']);
 1543+ # Remove edit option altogether, unless it's the current revision
 1544+ unset( $content_actions['edit'] );
 1545+ unset( $content_actions['viewsource'] );
15301546 }
15311547 return true;
15321548 }
15331549 // Note that revisions may not be set to override for users
15341550 if( $this->pageOverride() ) {
15351551 # Remove edit option altogether
1536 - unset( $content_actions['edit']);
1537 - unset( $content_actions['viewsource']);
 1552+ unset( $content_actions['edit'] );
 1553+ unset( $content_actions['viewsource'] );
 1554+
15381555 $new_actions = array(); $counter = 0;
15391556 # Straighten out order
15401557 foreach( $content_actions as $tab_action => $data ) {
@@ -1860,7 +1877,6 @@
18611878 */
18621879 function getLatestStableRev( $getText=false ) {
18631880 global $wgTitle;
1864 -
18651881 // Cached results available?
18661882 if( isset($this->latestfound) ) {
18671883 return ( $this->latestfound ) ? $this->latestrev : NULL;
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php
@@ -401,7 +401,9 @@
402402 $poutput = $parserCache->get( $article, $wgUser );
403403 if( $poutput==false ) {
404404 $text = $article->getContent();
405 - $poutput = $wgParser->parse($text, $article->mTitle, ParserOptions::newFromUser($wgUser));
 405+ $options = ParserOptions::newFromUser($wgUser);
 406+ $options->setTidy(true);
 407+ $poutput = $wgParser->parse( $text, $article->mTitle, $options );
406408 }
407409 $u = new LinksUpdate( $this->page, $poutput );
408410 $u->doUpdate(); // Will trigger our hook to add stable links too...
@@ -555,8 +557,7 @@
556558 }
557559
558560 function showStableRevision( $frev ) {
559 - global $wgParser, $wgLang, $wgUser, $wgOut, $wgTitle, $wgFlaggedRevs;
560 -
 561+ global $wgParser, $wgLang, $wgUser, $wgOut, $wgFlaggedRevs;
561562 // Get the revision
562563 $frev = FlaggedRevs::getFlaggedRev( $this->oldid );
563564 // Revision must exists
@@ -578,8 +579,8 @@
579580 '</span>';
580581 // Parse the text...
581582 $text = $wgFlaggedRevs->getFlaggedRevText( $this->oldid );
582 - $options = ParserOptions::newFromUser($wgUser);
583 - $parserOutput = $wgFlaggedRevs->parseStableText( $page, $text, $this->oldid, $options );
 583+ $article = new Article( $page );
 584+ $parserOutput = $wgFlaggedRevs->parseStableText( $article, $text, $this->oldid );
584585 $notes = $wgFlaggedRevs->ReviewNotes( $frev );
585586 // Set the new body HTML, place a tag on top
586587 $wgOut->addHTML('<div id="mwrevisiontag" class="flaggedrevs_notice plainlinks">'.$tag.'</div>' . $parserOutput->getText() . $notes);
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -14,17 +14,17 @@
1515 'group-reviewer-member' => 'Reviewer',
1616 'grouppage-reviewer' => '{{ns:project}}:Reviewer',
1717
18 - 'revreview-current' => 'Current revision',
 18+ 'revreview-current' => 'Draft (editable)',
1919 'revreview-stable' => 'Stable version',
2020 'revreview-oldrating' => 'It was rated as:',
2121 'revreview-noflagged' => 'There are no reviewed revisions of this page, so it may \'\'\'not\'\'\' have been
2222 [[Help:Article validation|checked]] for quality.',
2323
24 - 'revreview-quick-see-quality' => '\'\'\'Current\'\'\'. [{{fullurl:{{FULLPAGENAMEE}}|stable=1}} See latest quality revision]',
25 - 'revreview-quick-see-basic' => '\'\'\'Current\'\'\'. [{{fullurl:{{FULLPAGENAMEE}}|stable=1}} See latest sighted revision]',
26 - 'revreview-quick-basic' => '\'\'\'Sighted\'\'\'. [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} See current revision]
 24+ 'revreview-quick-see-quality' => '\'\'\'Current\'\'\'. [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} See latest quality revision]]',
 25+ 'revreview-quick-see-basic' => '\'\'\'Current\'\'\'. [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} See latest sighted revision]]',
 26+ 'revreview-quick-basic' => '\'\'\'[[Help:Article validation|Sighted]]\'\'\'. [[{{fullurl:{{FULLPAGENAMEE}}|stable=0}} See current revision]]
2727 ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
28 - 'revreview-quick-quality' => '\'\'\'Quality\'\'\'. [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} See current revision]
 28+ 'revreview-quick-quality' => '\'\'\'[[Help:Article validation|Quality]]\'\'\'. [[{{fullurl:{{FULLPAGENAMEE}}|stable=0}} See current revision]]
2929 ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
3030 'revreview-quick-none' => '\'\'\'Current\'\'\'. No reviewed revisions.',
3131 'revreview-newest-basic' => 'The [{{fullurl:{{FULLPAGENAMEE}}|stable=1}} latest sighted revision]

Status & tagging log