r34632 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34631‎ | r34632 | r34633 >
Date:21:31, 11 May 2008
Author:aaron
Status:old
Tags:
Comment:
Scap done already - bring back commits reverted in r34615
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsXML.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/README.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -14,7 +14,7 @@
1515 $wgExtensionCredits['specialpage'][] = array(
1616 'name' => 'Flagged Revisions',
1717 'author' => array( 'Aaron Schulz', 'Joerg Baach' ),
18 - 'version' => '1.041',
 18+ 'version' => '1.042',
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:FlaggedRevs',
2020 'descriptionmsg' => 'flaggedrevs-desc',
2121 );
@@ -223,7 +223,7 @@
224224 global $wgOut, $wgHooks, $wgLang, $wgFlaggedArticle, $wgUseRCPatrol;
225225 # Initialize
226226 FlaggedRevs::load();
227 - $wgFlaggedArticle = new FlaggedArticle();
 227+ $wgFlaggedArticle = null;
228228
229229 wfLoadExtensionMessages( 'FlaggedRevsPage' );
230230
@@ -238,28 +238,8 @@
239239 define( 'FLAGGED_JS', $wgScriptPath . '/extensions/FlaggedRevs/flaggedrevs.js?' . $wgFlaggedRevStyleVersion );
240240
241241 ######### Hook attachments #########
242 - $wgHooks['OutputPageParserOutput'][] = 'FlaggedRevs::InjectStyleAndJS';
243 - $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevs::InjectStyleAndJS';
244 - $wgHooks['PageHistoryBeforeList'][] = 'FlaggedRevs::InjectStyleAndJS';
245 - # Main hooks, overrides pages content, adds tags, sets tabs and permalink
246 - $wgHooks['SkinTemplateTabs'][] = array( $wgFlaggedArticle, 'setActionTabs' );
247 - # Change last-modified footer
248 - $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( $wgFlaggedArticle, 'setLastModified' );
249 - # Update older, incomplete, page caches (ones that lack template Ids/image timestamps)
250 - $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'maybeUpdateMainCache' );
251 - $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'setPageContent' );
252 - $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'addPatrolLink' );
253 - # Set image version
254 - $wgHooks['ArticleFromTitle'][] = array( $wgFlaggedArticle, 'setImageVersion' );
255 - # Add page notice
256 - $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array( $wgFlaggedArticle, 'setPermaLink' );
257 - # Add tags do edit view
258 - $wgHooks['EditPage::showEditForm:initial'][] = array( $wgFlaggedArticle, 'addToEditView' );
259 - # Add review form
260 - $wgHooks['BeforePageDisplay'][] = array( $wgFlaggedArticle, 'addReviewForm' );
261 - $wgHooks['BeforePageDisplay'][] = array( $wgFlaggedArticle, 'addVisibilityLink' );
262 - # Mark of items in page history
263 - $wgHooks['PageHistoryLineEnding'][] = array( $wgFlaggedArticle, 'addToHistLine' );
 242+ # Set $wgFlaggedArticle
 243+ $wgHooks['ArticleFromTitle'][] = 'wfInitFlaggedArticle';
264244 # Autopromote Editors
265245 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoPromoteUser';
266246 # Adds table link references to include ones from the stable version
@@ -281,17 +261,10 @@
282262 # Additional parser versioning
283263 $wgHooks['ParserAfterTidy'][] = 'FlaggedRevs::parserInjectTimestamps';
284264 $wgHooks['OutputPageParserOutput'][] = 'FlaggedRevs::outputInjectTimestamps';
285 - # Page review on edit
286 - $wgHooks['ArticleUpdateBeforeRedirect'][] = array( $wgFlaggedArticle, 'injectReviewDiffURLParams' );
287 - $wgHooks['DiffViewHeader'][] = array( $wgFlaggedArticle, 'addPatrolAndDiffLink' );
288 - $wgHooks['DiffViewHeader'][] = array( $wgFlaggedArticle, 'addDiffNoticeAndIncludes' );
289 - # Autoreview stuff
290 - $wgHooks['EditPage::showEditForm:fields'][] = array( $wgFlaggedArticle, 'addRevisionIDField' );
291 - $wgHooks['ArticleInsertComplete'][] = array( $wgFlaggedArticle, 'maybeMakeNewPageReviewed' );
292 - $wgHooks['ArticleSaveComplete'][] = array( $wgFlaggedArticle, 'maybeMakeEditReviewed' );
293 - $wgHooks['ArticleRollbackComplete'][] = array( $wgFlaggedArticle, 'maybeMakeRollbackReviewed' );
 265+ # Auto-reviewing
294266 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoMarkPatrolled';
295 - $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeNullEditReviewed';
 267+ $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
 268+ $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevs::maybeMakeRollbackReviewed';
296269 # Disallow moves of stable pages
297270 $wgHooks['userCan'][] = 'FlaggedRevs::userCanMove';
298271 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
@@ -307,6 +280,44 @@
308281 #########
309282 }
310283
 284+function wfInitFlaggedArticle( $title, $article ) {
 285+ global $wgFlaggedArticle, $wgHooks;
 286+ if( !FlaggedRevs::isPageReviewable( $title ) )
 287+ return true;
 288+ # Initialize and set article hooks
 289+ $wgFlaggedArticle = new FlaggedArticle( $title );
 290+ # Main hooks, overrides pages content, adds tags, sets tabs and permalink
 291+ $wgHooks['SkinTemplateTabs'][] = array( $wgFlaggedArticle, 'setActionTabs' );
 292+ # Change last-modified footer
 293+ $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array( $wgFlaggedArticle, 'setLastModified' );
 294+ # Update older, incomplete, page caches (ones that lack template Ids/image timestamps)
 295+ $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'maybeUpdateMainCache' );
 296+ $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'setPageContent' );
 297+ $wgHooks['ArticleViewHeader'][] = array( $wgFlaggedArticle, 'addPatrolLink' );
 298+ # Set image version
 299+ $wgHooks['ArticleFromTitle'][] = array( $wgFlaggedArticle, 'setImageVersion' );
 300+ # Add page notice
 301+ $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = array( $wgFlaggedArticle, 'setPermaLink' );
 302+ # Add tags do edit view
 303+ $wgHooks['EditPage::showEditForm:initial'][] = array( $wgFlaggedArticle, 'addToEditView' );
 304+ # Add review form
 305+ $wgHooks['BeforePageDisplay'][] = array( $wgFlaggedArticle, 'addReviewForm' );
 306+ $wgHooks['BeforePageDisplay'][] = array( $wgFlaggedArticle, 'addVisibilityLink' );
 307+ # Mark of items in page history
 308+ $wgHooks['PageHistoryLineEnding'][] = array( $wgFlaggedArticle, 'addToHistLine' );
 309+ # Page review on edit
 310+ $wgHooks['ArticleUpdateBeforeRedirect'][] = array( $wgFlaggedArticle, 'injectReviewDiffURLParams' );
 311+ $wgHooks['DiffViewHeader'][] = array( $wgFlaggedArticle, 'addPatrolAndDiffLink' );
 312+ $wgHooks['DiffViewHeader'][] = array( $wgFlaggedArticle, 'addDiffNoticeAndIncludes' );
 313+ # Autoreview stuff
 314+ $wgHooks['EditPage::showEditForm:fields'][] = array( $wgFlaggedArticle, 'addRevisionIDField' );
 315+ # Add CSS/JS
 316+ $wgHooks['OutputPageParserOutput'][] = 'FlaggedRevs::InjectStyleAndJS';
 317+ $wgHooks['EditPage::showEditForm:initial'][] = 'FlaggedRevs::InjectStyleAndJS';
 318+ $wgHooks['PageHistoryBeforeList'][] = 'FlaggedRevs::InjectStyleAndJS';
 319+ return true;
 320+}
 321+
311322 # Add review log and such
312323 $wgLogTypes[] = 'review';
313324 $wgLogNames['review'] = 'review-logpage';
@@ -326,25 +337,6 @@
327338
328339 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efFlaggedRevsSchemaUpdates';
329340
330 -function efFlaggedRevsSchemaUpdates() {
331 - global $wgDBtype, $wgExtNewFields, $wgExtPGNewFields, $wgExtNewIndexes, $wgExtNewTables;
332 -
333 - $base = dirname(__FILE__);
334 - if( $wgDBtype == 'mysql' ) {
335 - $wgExtNewFields[] = array( 'flaggedpage_config', 'fpc_expiry', "$base/archives/patch-fpc_expiry.sql" );
336 - $wgExtNewIndexes[] = array('flaggedpage_config', 'fpc_expiry', "$base/archives/patch-expiry-index.sql" );
337 - $wgExtNewTables[] = array( 'flaggedrevs_promote', "$base/archives/patch-flaggedrevs_promote.sql" );
338 - $wgExtNewTables[] = array( 'flaggedpages', "$base/archives/patch-flaggedpages.sql" );
339 - } else if( $wgDBtype == 'postgres' ) {
340 - $wgExtPGNewFields[] = array('flaggedpage_config', 'fpc_expiry', "TIMESTAMPTZ NULL" );
341 - $wgExtNewIndexes[] = array('flaggedpage_config', 'fpc_expiry', "$base/postgres/patch-expiry-index.sql" );
342 - $wgExtNewTables[] = array( 'flaggedrevs_promote', "$base/postgres/patch-flaggedrevs_promote.sql" );
343 - $wgExtNewTables[] = array( 'flaggedpages', "$base/postgres/patch-flaggedpages.sql" );
344 - }
345 -
346 - return true;
347 -}
348 -
349341 class FlaggedRevs {
350342 public static $dimensions = array();
351343 public static $styleLoaded = false;
@@ -434,14 +426,14 @@
435427 */
436428 public static function parseStableText( $article, $text='', $id, $reparsed = true ) {
437429 global $wgParser;
 430+ $title = $article->getTitle(); // avoid pass-by-reference error
438431 # Make our hooks to trigger
439432 $wgParser->fr_isStable = true;
440433 $wgParser->fr_includesMatched = true;
441434 # Don't show section-edit links, they can be old and misleading
442435 $options = self::makeParserOptions();
443 - $options->setEditSection( $id==$article->getLatest() );
 436+ $options->setEditSection( $id == $title->getLatestRevID(GAID_FOR_UPDATE) );
444437 # Parse the new body, wikitext -> html
445 - $title = $article->getTitle(); // avoid pass-by-reference error
446438 $parserOut = $wgParser->parse( $text, $title, $options, true, true, $id );
447439 $parserOut->fr_includesMatched = $wgParser->fr_includesMatched;
448440 # Done with parser!
@@ -490,14 +482,14 @@
491483 /**
492484 * @param FlaggedRevision $frev
493485 * @param Article $article
494 - * @param ParserOutput $flaggedOutput, will fetch if not given
 486+ * @param ParserOutput $stableOutput, will fetch if not given
495487 * @param ParserOutput $currentOutput, will fetch if not given
496488 * @return bool
497489 * See if a flagged revision is synced with the current
498490 */
499 - public static function flaggedRevIsSynced( $frev, $article, $flaggedOutput=null, $currentOutput=null ) {
 491+ public static function flaggedRevIsSynced( $frev, $article, $stableOutput=null, $currentOutput=null ) {
500492 # Must be the same revision
501 - if( $frev->getRevId() != $article->getLatest() ) {
 493+ if( $frev->getRevId() != $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) ) {
502494 return false;
503495 }
504496 global $wgMemc;
@@ -513,20 +505,14 @@
514506 }
515507 }
516508 # If parseroutputs not given, fetch them...
517 - if( is_null($flaggedOutput) || !isset($flaggedOutput->fr_newestTemplateID) ) {
 509+ if( is_null($stableOutput) || !isset($stableOutput->fr_newestTemplateID) ) {
518510 # Get parsed stable version
519 - $flaggedOutput = FlaggedRevs::getPageCache( $article );
520 - if( $flaggedOutput==false ) {
521 - global $wgUseStableTemplates;
522 - if( $wgUseStableTemplates ) {
523 - $rev = Revision::newFromId( $frev->getRevId() );
524 - $text = $rev->getText();
525 - } else {
526 - $text = $frev->getExpandedText();
527 - }
528 - $flaggedOutput = FlaggedRevs::parseStableText( $article, $text, $frev->getRevId() );
 511+ $stableOutput = self::getPageCache( $article );
 512+ if( $stableOutput==false ) {
 513+ $text = $frev->getTextForParse();
 514+ $stableOutput = self::parseStableText( $article, $text, $frev->getRevId() );
529515 # Update the stable version cache
530 - FlaggedRevs::updatePageCache( $article, $flaggedOutput );
 516+ self::updatePageCache( $article, $stableOutput );
531517 }
532518 }
533519 if( is_null($currentOutput) || !isset($currentOutput->fr_newestTemplateID) ) {
@@ -540,15 +526,17 @@
541527 $options = self::makeParserOptions( $wgUser );
542528 $currentOutput = $wgParser->parse( $text, $title, $options );
543529 # Might as well save the cache while we're at it
544 - $parserCache->save( $currentOutput, $article, $wgUser );
 530+ global $wgEnableParserCache;
 531+ if( $wgEnableParserCache )
 532+ $parserCache->save( $currentOutput, $article, $wgUser );
545533 }
546534 }
547535 # Only current of revisions of inclusions can be reviewed. Since the stable and current revisions
548536 # have the same text, the only thing that can make them different is updating a template or image.
549537 # If this is the case, the current revision will have a newer template or image version used somewhere.
550 - if( $currentOutput->fr_newestImageTime > $flaggedOutput->fr_newestImageTime ) {
 538+ if( $currentOutput->fr_newestImageTime > $stableOutput->fr_newestImageTime ) {
551539 $synced = false;
552 - } else if( $currentOutput->fr_newestTemplateID > $flaggedOutput->fr_newestTemplateID ) {
 540+ } else if( $currentOutput->fr_newestTemplateID > $stableOutput->fr_newestTemplateID ) {
553541 $synced = false;
554542 } else {
555543 $synced = true;
@@ -558,7 +546,7 @@
559547 global $wgParserCacheExpireTime;
560548 $syncData = $synced ? "true" : "false";
561549 $wgMemc->set( $key, $syncData, $wgParserCacheExpireTime );
562 -
 550+
563551 return $synced;
564552 }
565553
@@ -658,7 +646,6 @@
659647 if( $row ) {
660648 return new FlaggedRevision( $title, $row );
661649 }
662 -
663650 return null;
664651 }
665652
@@ -670,11 +657,13 @@
671658 */
672659 public static function getRevQuality( $title, $rev_id, $db = NULL ) {
673660 $db = $db ? $db : wfGetDB( DB_SLAVE );
674 - $quality = $db->selectField( 'flaggedrevs', 'fr_quality',
 661+ $quality = $db->selectField( 'flaggedrevs',
 662+ 'fr_quality',
675663 array( 'fr_page_id' => $title->getArticleID(),
676664 'fr_rev_id' => $rev_id ),
677665 __METHOD__,
678 - array( 'FORCE INDEX' => 'PRIMARY' ) );
 666+ array( 'FORCE INDEX' => 'PRIMARY' )
 667+ );
679668 return $quality;
680669 }
681670
@@ -765,7 +754,7 @@
766755 # Check if the count is zero by using $article->getLatest().
767756 # I don't trust using memcache and PHP for values like '0'
768757 # as it may confuse "expired" with "0". -aaron
769 - if( $article->getLatest()==$from_rev ) {
 758+ if( $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) == $from_rev ) {
770759 return 0;
771760 }
772761 global $wgMemc;
@@ -873,7 +862,7 @@
874863 public static function getRevisionTags( $title, $rev_id ) {
875864 $dbr = wfGetDB( DB_SLAVE );
876865 $tags = $dbr->selectField( 'flaggedrevs', 'fr_tags',
877 - array('fr_rev_id' => $rev_id,
 866+ array( 'fr_rev_id' => $rev_id,
878867 'fr_page_id' => $title->getArticleId() ),
879868 __METHOD__ );
880869 if( !$tags )
@@ -1045,10 +1034,10 @@
10461035 /**
10471036 * Add FlaggedRevs css/js. Attached to two different hooks, neglect inputs.
10481037 */
1049 - public static function InjectStyleAndJS( $a=false, $b=false ) {
 1038+ public static function InjectStyleAndJS() {
10501039 global $wgOut, $wgJsMimeType, $wgFlaggedArticle;
10511040 # Don't double-load
1052 - if( self::$styleLoaded )
 1041+ if( self::$styleLoaded || !$wgFlaggedArticle )
10531042 return true;
10541043 # UI CSS
10551044 $wgOut->addLink( array(
@@ -1104,19 +1093,18 @@
11051094 $quality = self::isPristine($flags) ? 2 : 1;
11061095 }
11071096 $tmpset = $imgset = array();
 1097+ $poutput = false;
11081098 # Try the parser cache, should be set on the edit before this is called.
11091099 # If not set or up to date, then parse it. Use master to avoid lag issues.
1110 - $poutput = false;
11111100 $latestID = $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE);
1112 - if( $latestID == $rev->getId() ) {
1113 - $parserCache = ParserCache::singleton();
1114 - $poutput = $parserCache->get( $article, $user );
1115 - }
1116 - if( $poutput==false ) {
 1101+ if( $poutput == false ) {
11171102 $options = self::makeParserOptions( $user );
1118 - $poutput = $wgParser->parse( $text, $article->getTitle(), $options, true, true, $rev->getId() );
 1103+ $title = $article->getTitle(); // avoid pass-by-ref error
 1104+ $poutput = $wgParser->parse( $text, $title, $options, true, true, $latestID );
11191105 # Might as well save the cache while we're at it
1120 - if( $latestID == $rev->getId() ) {
 1106+ global $wgEnableParserCache;
 1107+ if( $wgEnableParserCache && $latestID == $rev->getId() ) {
 1108+ $parserCache = ParserCache::singleton();
11211109 $parserCache->save( $poutput, $article, $user );
11221110 }
11231111 }
@@ -1163,7 +1151,7 @@
11641152 $textFlags = self::compressText( $fulltext );
11651153
11661154 # Write to external storage if required
1167 - $storage = FlaggedRevs::getExternalStorage();
 1155+ $storage = self::getExternalStorage();
11681156 if( $storage ) {
11691157 if( is_array($storage) ) {
11701158 # Distribute storage across multiple clusters
@@ -1219,7 +1207,7 @@
12201208 $sv = self::getStablePageRev( $article->getTitle(), false, true );
12211209 if( $sv && $sv->getRevId() == $rev->getId() ) {
12221210 # Update stable cache
1223 - FlaggedRevs::updatePageCache( $article, $poutput );
 1211+ self::updatePageCache( $article, $poutput );
12241212 # Update page fields
12251213 self::updateArticleOn( $article, $rev->getId(), $rev->getId() );
12261214 # Purge squid for this page only
@@ -1353,7 +1341,9 @@
13541342 $options = self::makeParserOptions( $wgUser );
13551343 $poutput = $wgParser->parse($text, $article->getTitle(), $options);
13561344 # Might as well save the cache while we're at it
1357 - $parserCache->save( $poutput, $article, $wgUser );
 1345+ global $wgEnableParserCache;
 1346+ if( $wgEnableParserCache )
 1347+ $parserCache->save( $poutput, $article, $wgUser );
13581348 }
13591349 $u = new LinksUpdate( $article->getTitle(), $poutput );
13601350 $u->doUpdate(); // this will trigger our hook to add stable links too...
@@ -1390,12 +1380,7 @@
13911381 # Try stable version cache. This should be updated before this is called.
13921382 $parserOut = self::getPageCache( $article );
13931383 if( $parserOut==false ) {
1394 - if( $wgUseStableTemplates ) {
1395 - $rev = Revision::newFromId( $sv->getRevId() );
1396 - $text = $rev->getText();
1397 - } else {
1398 - $text = $sv->getExpandedText();
1399 - }
 1384+ $text = $sv->getTextForParse();
14001385 # Parse the text
14011386 $parserOut = self::parseStableText( $article, $text, $sv->getRevId() );
14021387 }
@@ -1714,13 +1699,12 @@
17151700 * Don't let users vandalize pages by moving them.
17161701 */
17171702 public static function userCanMove( $title, $user, $action, $result ) {
1718 - global $wgTitle;
 1703+ global $wgTitle, $wgFlaggedArticle;
17191704
17201705 if( $action != 'move' || !self::isPageReviewable( $title ) )
17211706 return true;
17221707 # See if there is a stable version
1723 - if( $wgTitle && $wgTitle->equals( $title ) ) {
1724 - global $wgFlaggedArticle;
 1708+ if( $wgFlaggedArticle && $wgTitle && $wgTitle->equals( $title ) ) {
17251709 // Cache stable version while we are at it.
17261710 $frev = $wgFlaggedArticle->getStableRev( true );
17271711 } else {
@@ -1741,7 +1725,7 @@
17421726 * Allow users to view reviewed pages.
17431727 */
17441728 public static function userCanView( $title, $user, $action, $result ) {
1745 - global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle;
 1729+ global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle, $wgFlaggedArticle;
17461730 # Assume $action may still not be set, in which case, treat it as 'view'...
17471731 if( $action != 'read' )
17481732 return true;
@@ -1757,7 +1741,7 @@
17581742 }
17591743 # See if there is a stable version. Also, see if, given the page
17601744 # config and URL params, the page can be overriden.
1761 - if( $wgTitle && $wgTitle->equals( $title ) ) {
 1745+ if( $wgFlaggedArticle && $wgTitle && $wgTitle->equals( $title ) ) {
17621746 global $wgFlaggedArticle;
17631747 // Cache stable version while we are at it.
17641748 if( $wgFlaggedArticle->pageOverride() && $wgFlaggedArticle->getStableRev( true ) ) {
@@ -1772,42 +1756,89 @@
17731757 }
17741758
17751759 /**
1776 - * When a null edit is made, autoreview if necessary
 1760+ * When an edit is made by a reviewer, if the current revision is the stable
 1761+ * version, try to automatically review it.
17771762 */
1778 - public static function maybeMakeNullEditReviewed( $rev ) {
1779 - $title = $rev->getTitle();
 1763+ public static function maybeMakeEditReviewed( $rev ) {
 1764+ global $wgFlaggedRevsAutoReview, $wgFlaggedRevsAutoReviewNew, $wgFlaggedArticle, $wgRequest;
 1765+ # Get the user
 1766+ $user = User::newFromId( $rev->getUser() );
 1767+ if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
 1768+ return true;
17801769 # GetTitle() for revisions uses slaves and wants page_id,rev_id to
17811770 # match...this is bad if we *just* added it.
1782 - $title = $title ? $title : Title::newFromID( $rev->getPage() );
 1771+ $title = $rev->getTitle() ? $rev->getTitle() : Title::newFromID( $rev->getPage(), GAID_FOR_UPDATE );
 1772+ # Must be in reviewable namespace
17831773 if( !$title || !self::isPageReviewable( $title ) ) {
17841774 return true;
17851775 }
1786 - $prevRevID = $title->getPreviousRevisionId( $rev->getId() );
1787 - if( !$prevRevID )
1788 - return true;
1789 - $prevRev = Revision::newFromID( $prevRevID );
1790 - # Check for null edits
1791 - if( $prevRev && $prevRev->getTextId() == $rev->getTextId() ) {
1792 - $frev = FlaggedRevs::getFlaggedRev( $title, $prevRev->getId() );
1793 - if( !is_null($frev) ) {
1794 - $article = new Article( $title );
1795 - $flags = $frev->getTags();
1796 - # Check if user is allowed to renew the stable version.
1797 - if( !RevisionReview::userCanSetFlags( $flags ) ) {
1798 - # Assume basic flagging level
1799 - $flags = array();
1800 - foreach( FlaggedRevs::$dimensions as $tag => $minQL ) {
1801 - $flags[$tag] = 1;
1802 - }
 1776+ $article = new Article( $title );
 1777+ # Revision will be null for null edits
 1778+ if( $rev ) {
 1779+ $frev = null;
 1780+ $reviewableNewPage = false;
 1781+ # Get the revision the incoming one was based off
 1782+ $baseRevID = $wgRequest->getVal('baseRevId');
 1783+ if( $baseRevID ) {
 1784+ $frev = self::getFlaggedRev( $article->getTitle(), $baseRevID );
 1785+ } else {
 1786+ $prevRevID = $article->getTitle()->getPreviousRevisionId( $rev->getId() );
 1787+ $prevRev = $prevRevID ? Revision::newFromID( $prevRevID ) : null;
 1788+ # Check for null edits
 1789+ if( $prevRev && $prevRev->getTextId() == $rev->getTextId() ) {
 1790+ $frev = self::getFlaggedRev( $title, $prevRev->getId() );
 1791+ # Check for new pages
 1792+ } else if( !$prevRev ) {
 1793+ $reviewableNewPage = $wgFlaggedRevsAutoReviewNew;
18031794 }
1804 - $user = User::newFromId( $rev->getUser() );
1805 - FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
18061795 }
 1796+ # Is this an edit directly to the stable version?
 1797+ if( $reviewableNewPage || !is_null($frev) ) {
 1798+ # Assume basic flagging level
 1799+ $flags = array();
 1800+ foreach( self::$dimensions as $tag => $minQL ) {
 1801+ $flags[$tag] = 1;
 1802+ }
 1803+ self::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
 1804+ }
18071805 }
 1806+ if( $wgFlaggedArticle ) {
 1807+ $wgFlaggedArticle->skipReviewDiff = true; // Don't jump to diff...
 1808+ }
18081809 return true;
18091810 }
18101811
18111812 /**
 1813+ * When a rollback is made by a reviwer, try to automatically review it.
 1814+ */
 1815+ public static function maybeMakeRollbackReviewed( $article, $user, $rev ) {
 1816+ global $wgFlaggedRevsAutoReview, $wgFlaggedArticle;
 1817+ if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
 1818+ return true;
 1819+ # Must be in reviewable namespace
 1820+ if( !self::isPageReviewable( $article->getTitle() ) )
 1821+ return true;
 1822+ # Was this revision flagged?
 1823+ $frev = self::getFlaggedRev( $article->getTitle(), $rev->getId() );
 1824+ if( !is_null($frev) ) {
 1825+ # Assume basic flagging level
 1826+ $flags = array();
 1827+ foreach( self::$dimensions as $tag => $minQL ) {
 1828+ $flags[$tag] = 1;
 1829+ }
 1830+ $newRev = Revision::newFromId( $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) );
 1831+ if( $newRev ) {
 1832+ self::autoReviewEdit( $article, $user, $rev->getText(), $newRev, $flags );
 1833+ self::articleLinksUpdate( $article ); // lame...
 1834+ }
 1835+ }
 1836+ if( $wgFlaggedArticle ) {
 1837+ $wgFlaggedArticle->skipReviewDiff = true; // Don't jump to diff...
 1838+ }
 1839+ return true;
 1840+ }
 1841+
 1842+ /**
18121843 * When an edit is made to a page that can't be reviewed, autopatrol if allowed.
18131844 * This is not loggged for perfomance reasons and no one cares if talk pages and such
18141845 * are autopatrolled.
@@ -2114,46 +2145,8 @@
21152146 * Add user preference to form HTML
21162147 */
21172148 public static function injectPreferences( $form, $out ) {
2118 - global $wgUser;
2119 -
2120 - $out->addHTML(
2121 - Xml::openElement( 'fieldset' ) .
2122 - Xml::element( 'legend', null, wfMsgHtml('flaggedrevs-prefs') ) .
2123 - Xml::openElement( 'table' ) .
2124 - Xml::openElement( 'tr' ) .
2125 - '<td>' . wfCheck( 'wpFlaggedRevsStable', $form->mFlaggedRevsStable,
2126 - array('id' => 'wpFlaggedRevsStable') ) . '</td><td> ' .
2127 - wfLabel( wfMsg( 'flaggedrevs-prefs-stable' ), 'wpFlaggedRevsStable' ) . '</td>' .
2128 - Xml::closeElement( 'tr' ) .
2129 - Xml::openElement( 'tr' ) .
2130 - '<td>' .
2131 - Xml::radio( 'wpFlaggedRevsSUI', 0, $form->mFlaggedRevsSUI==0, array('id' => 'standardUI') ) .
2132 - '</td><td> ' .
2133 - Xml::label( wfMsgHtml('flaggedrevs-pref-UI-0'), 'standardUI' ) .
2134 - '</td>' .
2135 - Xml::closeElement( 'tr' ) .
2136 - Xml::openElement( 'tr' ) .
2137 - '<td>' .
2138 - Xml::radio( 'wpFlaggedRevsSUI', 1, $form->mFlaggedRevsSUI==1, array('id' => 'simpleUI') ) .
2139 - '</td><td> ' .
2140 - Xml::label( wfMsgHtml('flaggedrevs-pref-UI-1'), 'simpleUI' ) .
2141 - '</td>'
2142 - );
2143 - if( $wgUser->isAllowed( 'review' ) ) {
2144 - $out->addHTML(
2145 - Xml::closeElement( 'tr' ) .
2146 - Xml::openElement( 'tr' ) . '<td><br/></td>' . Xml::closeElement( 'tr' ) .
2147 - Xml::openElement( 'tr' ) .
2148 - '<td>' . wfCheck( 'wpFlaggedRevsWatch', $form->mFlaggedRevsWatch, array('id' => 'wpFlaggedRevsWatch') ) .
2149 - '</td><td> ' . wfLabel( wfMsg( 'flaggedrevs-prefs-watch' ), 'wpFlaggedRevsWatch' ) . '</td>'
2150 - );
2151 - }
2152 - $out->addHTML(
2153 - Xml::closeElement( 'tr' ) .
2154 - Xml::closeElement( 'table' ) .
2155 - Xml::closeElement( 'fieldset' )
2156 - );
2157 -
 2149+ $prefsHtml = FlaggedRevsXML::stabilityPreferences( $form );
 2150+ $out->addHTML( $prefsHtml );
21582151 return true;
21592152 }
21602153
@@ -2213,4 +2206,21 @@
22142207 }
22152208 }
22162209
 2210+function efFlaggedRevsSchemaUpdates() {
 2211+ global $wgDBtype, $wgExtNewFields, $wgExtPGNewFields, $wgExtNewIndexes, $wgExtNewTables;
22172212
 2213+ $base = dirname(__FILE__);
 2214+ if( $wgDBtype == 'mysql' ) {
 2215+ $wgExtNewFields[] = array( 'flaggedpage_config', 'fpc_expiry', "$base/archives/patch-fpc_expiry.sql" );
 2216+ $wgExtNewIndexes[] = array('flaggedpage_config', 'fpc_expiry', "$base/archives/patch-expiry-index.sql" );
 2217+ $wgExtNewTables[] = array( 'flaggedrevs_promote', "$base/archives/patch-flaggedrevs_promote.sql" );
 2218+ $wgExtNewTables[] = array( 'flaggedpages', "$base/archives/patch-flaggedpages.sql" );
 2219+ } else if( $wgDBtype == 'postgres' ) {
 2220+ $wgExtPGNewFields[] = array('flaggedpage_config', 'fpc_expiry', "TIMESTAMPTZ NULL" );
 2221+ $wgExtNewIndexes[] = array('flaggedpage_config', 'fpc_expiry', "$base/postgres/patch-expiry-index.sql" );
 2222+ $wgExtNewTables[] = array( 'flaggedrevs_promote', "$base/postgres/patch-flaggedrevs_promote.sql" );
 2223+ $wgExtNewTables[] = array( 'flaggedpages', "$base/postgres/patch-flaggedpages.sql" );
 2224+ }
 2225+
 2226+ return true;
 2227+}
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php
@@ -28,7 +28,7 @@
2929
3030 $name = $index !== 0 ? $name : wfMsg('blanknamespace');
3131
32 - if($index === $selected) {
 32+ if( $index === $selected ) {
3333 $s .= "\t" . Xml::element("option", array("value" => $index, "selected" => "selected"), $name) . "\n";
3434 } else {
3535 $s .= "\t" . Xml::element("option", array("value" => $index), $name) . "\n";
@@ -117,8 +117,12 @@
118118 $msg = $quality ? 'revreview-quality-old' : 'revreview-basic-old';
119119 $html = wfMsgExt($msg, array('parseinline'), $frev->getRevId(), $time );
120120 } else {
121 - $msg = $stable ? 'revreview-' : 'revreview-newest-';
122 - $msg .= $quality ? 'quality' : 'basic';
 121+ if( $stable ) {
 122+ $msg = $quality ? 'revreview-quality' : 'revreview-basic';
 123+ $msg .= ($revs_since == 0) ? '-i' : '';
 124+ } else {
 125+ $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
 126+ }
123127 $html = wfMsgExt($msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
124128 }
125129 # Make fancy box...
@@ -137,4 +141,45 @@
138142
139143 return $box;
140144 }
 145+
 146+ /**
 147+ * Add user preference to form HTML
 148+ */
 149+ public static function stabilityPreferences( $form ) {
 150+ global $wgUser;
 151+
 152+ $html = Xml::openElement( 'fieldset' ) .
 153+ Xml::element( 'legend', null, wfMsgHtml('flaggedrevs-prefs') ) .
 154+ Xml::openElement( 'table' ) .
 155+ Xml::openElement( 'tr' ) .
 156+ '<td>' . wfCheck( 'wpFlaggedRevsStable', $form->mFlaggedRevsStable,
 157+ array('id' => 'wpFlaggedRevsStable') ) . '</td><td> ' .
 158+ wfLabel( wfMsg( 'flaggedrevs-prefs-stable' ), 'wpFlaggedRevsStable' ) . '</td>' .
 159+ Xml::closeElement( 'tr' ) .
 160+ Xml::openElement( 'tr' ) .
 161+ '<td>' .
 162+ Xml::radio( 'wpFlaggedRevsSUI', 0, $form->mFlaggedRevsSUI==0, array('id' => 'standardUI') ) .
 163+ '</td><td> ' .
 164+ Xml::label( wfMsgHtml('flaggedrevs-pref-UI-0'), 'standardUI' ) .
 165+ '</td>' .
 166+ Xml::closeElement( 'tr' ) .
 167+ Xml::openElement( 'tr' ) .
 168+ '<td>' .
 169+ Xml::radio( 'wpFlaggedRevsSUI', 1, $form->mFlaggedRevsSUI==1, array('id' => 'simpleUI') ) .
 170+ '</td><td> ' .
 171+ Xml::label( wfMsgHtml('flaggedrevs-pref-UI-1'), 'simpleUI' ) .
 172+ '</td>';
 173+ if( $wgUser->isAllowed( 'review' ) ) {
 174+ $html .= Xml::closeElement( 'tr' ) .
 175+ Xml::openElement( 'tr' ) . '<td><br/></td>' . Xml::closeElement( 'tr' ) .
 176+ Xml::openElement( 'tr' ) .
 177+ '<td>' . wfCheck( 'wpFlaggedRevsWatch', $form->mFlaggedRevsWatch, array('id' => 'wpFlaggedRevsWatch') ) .
 178+ '</td><td> ' . wfLabel( wfMsg( 'flaggedrevs-prefs-watch' ), 'wpFlaggedRevsWatch' ) . '</td>';
 179+ }
 180+ $html .= Xml::closeElement( 'tr' ) .
 181+ Xml::closeElement( 'table' ) .
 182+ Xml::closeElement( 'fieldset' );
 183+
 184+ return $html;
 185+ }
141186 }
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -1,9 +1,8 @@
22 <?php
33
4 -class FlaggedArticle {
 4+class FlaggedArticle extends Article {
55 public $isDiffFromStable = false;
66 public $skipReviewDiff = false;
7 - public $skipAutoReview = false;
87 public $stableRev = null;
98 public $pageconfig = null;
109 public $flags = null;
@@ -75,9 +74,7 @@
7675 * Is this article reviewable?
7776 */
7877 public function isReviewable() {
79 - global $wgTitle;
80 -
81 - return FlaggedRevs::isPageReviewable( $wgTitle );
 78+ return FlaggedRevs::isPageReviewable( $this->getTitle() );
8279 }
8380
8481 /**
@@ -85,12 +82,7 @@
8683 */
8784 private function displayTag() {
8885 global $wgOut;
89 -
90 - if( !$this->reviewNotice ) {
91 - return false;
92 - }
9386 $wgOut->appendSubtitle( $this->reviewNotice );
94 -
9587 return true;
9688 }
9789
@@ -176,13 +168,7 @@
177169 // behavior below, since it is the same as ("&stable=1").
178170 if( $old ) {
179171 $revs_since = FlaggedRevs::getRevCountSince( $article, $frev->getRevId() );
180 - global $wgUseStableTemplates;
181 - if( $wgUseStableTemplates ) {
182 - $rev = Revision::newFromId( $frev->getRevId() );
183 - $text = $rev->getText();
184 - } else {
185 - $text = $frev->getExpandedText();
186 - }
 172+ $text = $frev->getTextForParse();
187173 $parserOut = FlaggedRevs::parseStableText( $article, $text, $frev->getRevId() );
188174 # Construct some tagging for non-printable outputs. Note that the pending
189175 # notice has all this info already, so don't do this if we added that already.
@@ -286,13 +272,7 @@
287273 # Get parsed stable version
288274 $parserOut = FlaggedRevs::getPageCache( $article );
289275 if( $parserOut==false ) {
290 - global $wgUseStableTemplates;
291 - if( $wgUseStableTemplates ) {
292 - $rev = Revision::newFromId( $frev->getRevId() );
293 - $text = $rev->getText();
294 - } else {
295 - $text = $frev->getExpandedText();
296 - }
 276+ $text = $frev->getTextForParse();
297277 $parserOut = FlaggedRevs::parseStableText( $article, $text, $frev->getRevId() );
298278 # Update the stable version cache
299279 FlaggedRevs::updatePageCache( $article, $parserOut );
@@ -314,6 +294,7 @@
315295 // Standard UI
316296 } else {
317297 $msg = $quality ? 'revreview-quality' : 'revreview-basic';
 298+ $msg .= ($revs_since == 0) ? '-i' : '';
318299 $msg = $synced ? "{$msg}-same" : $msg;
319300
320301 $tag = "<span class='{$css} plainlinks' title=\"{$tooltip}\"></span>" .
@@ -405,7 +386,7 @@
406387 * Adds latest stable version tag to page when editing
407388 */
408389 public function addToEditView( $editform ) {
409 - global $wgRequest, $wgTitle, $wgOut;
 390+ global $wgRequest, $wgOut;
410391 # Talk pages cannot be validated
411392 if( !$editform->mArticle || !$this->isReviewable() )
412393 return false;
@@ -422,7 +403,7 @@
423404 $tag = $warning = '';
424405 # Check the newest stable version
425406 $frev = $this->getStableRev();
426 - if( !is_null($frev) && $frev->getRevId() != $revid ) {
 407+ if( !is_null($frev) ) {
427408 global $wgLang, $wgUser, $wgFlaggedRevsAutoReview;
428409
429410 $time = $wgLang->date( $frev->getTimestamp(), true );
@@ -441,26 +422,28 @@
442423 wfMsgExt($msg,array('parseinline')) . "</div>";
443424 }
444425 }
445 - # Streamlined UI
446 - if( FlaggedRevs::useSimpleUI() ) {
447 - $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
448 - $tag = "<span class='fr-checkbox'></span>" .
449 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
450 - $tag = "<div id='mw-revisiontag-edit' class='flaggedrevs_editnotice plainlinks'>$tag</div>";
451 - # Standard UI
452 - } else {
453 - $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
454 - $tag = "<span class='fr-checkbox'></span>" .
455 - wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
456 - # Hide clutter
457 - if( !empty($flags) ) {
458 - $tag .= " <span id='mw-revisiontoggle' class='flaggedrevs_toggle' style='display:none;'" .
459 - " onclick='toggleRevRatings()' title='" . wfMsgHtml('revreview-toggle-title') . "' >" .
460 - wfMsg( 'revreview-toggle' ) . "</span>";
461 - $tag .= '<span id="mw-revisionratings" style="display:block;">' .
462 - wfMsg('revreview-oldrating') . FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
 426+ if( $frev->getRevId() != $revid ) {
 427+ # Streamlined UI
 428+ if( FlaggedRevs::useSimpleUI() ) {
 429+ $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
 430+ $tag = "<span class='fr-checkbox'></span>" .
 431+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
 432+ $tag = "<div id='mw-revisiontag-edit' class='flaggedrevs_editnotice plainlinks'>$tag</div>";
 433+ # Standard UI
 434+ } else {
 435+ $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
 436+ $tag = "<span class='fr-checkbox'></span>" .
 437+ wfMsgExt( $msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
 438+ # Hide clutter
 439+ if( !empty($flags) ) {
 440+ $tag .= " <span id='mw-revisiontoggle' class='flaggedrevs_toggle' style='display:none;'" .
 441+ " onclick='toggleRevRatings()' title='" . wfMsgHtml('revreview-toggle-title') . "' >" .
 442+ wfMsg( 'revreview-toggle' ) . "</span>";
 443+ $tag .= '<span id="mw-revisionratings" style="display:block;">' .
 444+ wfMsg('revreview-oldrating') . FlaggedRevsXML::addTagRatings( $flags ) . '</span>';
 445+ }
 446+ $tag = "<div id='mw-revisiontag-edit' class='flaggedrevs_editnotice plainlinks'>$tag</div>";
463447 }
464 - $tag = "<div id='mw-revisiontag-edit' class='flaggedrevs_editnotice plainlinks'>$tag</div>";
465448 }
466449 $wgOut->addHTML( $tag . $warning );
467450 # Show diff to stable, to make things less confusing
@@ -536,7 +519,7 @@
537520 * Add link to stable version setting to protection form
538521 */
539522 public function addVisibilityLink( $out ) {
540 - global $wgUser, $wgRequest, $wgTitle;
 523+ global $wgUser, $wgRequest;
541524
542525 if( !$this->isReviewable() )
543526 return true;
@@ -906,108 +889,6 @@
907890
908891 return true;
909892 }
910 -
911 - /**
912 - * When a new page is made by a reviwer, try to automatically review it.
913 - */
914 - public function maybeMakeNewPageReviewed( $article, $user, $text, $c, $flags, $a, $b, $flags, $rev ) {
915 - global $wgFlaggedRevsAutoReviewNew;
916 -
917 - if( $this->skipAutoReview || !$wgFlaggedRevsAutoReviewNew || !$user->isAllowed('autoreview') )
918 - return true;
919 - # Must be in reviewable namespace
920 - if( !FlaggedRevs::isPageReviewable( $article->getTitle() ) )
921 - return true;
922 - # Revision will be null for null edits
923 - if( !$rev ) {
924 - $this->skipReviewDiff = true; // Don't jump to diff...
925 - return true;
926 - }
927 - # Assume basic flagging level
928 - $flags = array();
929 - foreach( FlaggedRevs::$dimensions as $tag => $minQL ) {
930 - $flags[$tag] = 1;
931 - }
932 - FlaggedRevs::autoReviewEdit( $article, $user, $text, $rev, $flags );
933 -
934 - $this->skipReviewDiff = true; // Don't jump to diff...
935 - $this->skipAutoReview = true; // Be sure not to do stuff twice
936 -
937 - return true;
938 - }
939 -
940 - /**
941 - * When an edit is made by a reviewer, if the current revision is the stable
942 - * version, try to automatically review it.
943 - */
944 - public function maybeMakeEditReviewed( $article, $user, $text, $c, $m, $a, $b, $flags, $rev ) {
945 - global $wgFlaggedRevsAutoReview, $wgRequest;
946 -
947 - if( $this->skipAutoReview || !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
948 - return true;
949 - # Must be in reviewable namespace
950 - if( !FlaggedRevs::isPageReviewable( $article->getTitle() ) )
951 - return true;
952 - # Revision will be null for null edits
953 - if( !$rev ) {
954 - $this->skipReviewDiff = true; // Don't jump to diff...
955 - return true;
956 - }
957 - # Get the revision the incoming one was based off
958 - $baseRevID = $wgRequest->getVal('baseRevId');
959 - $frev = FlaggedRevs::getFlaggedRev( $article->getTitle(), $baseRevID );
960 - # Is this an edit directly to the stable version?
961 - if( is_null($frev) )
962 - return true;
963 - # Assume basic flagging level
964 - $flags = array();
965 - foreach( FlaggedRevs::$dimensions as $tag => $minQL ) {
966 - $flags[$tag] = 1;
967 - }
968 - FlaggedRevs::autoReviewEdit( $article, $user, $text, $rev, $flags );
969 -
970 - $this->skipReviewDiff = true; // Don't jump to diff...
971 - $this->skipAutoReview = true; // Be sure not to do stuff twice
972 -
973 - return true;
974 - }
975 -
976 - /**
977 - * When a rollback is made by a reviwer, try to automatically review it.
978 - */
979 - public function maybeMakeRollbackReviewed( $article, $user, $rev ) {
980 - global $wgFlaggedRevsAutoReview;
981 -
982 - if( $this->skipAutoReview || !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
983 - return true;
984 - # Must be in reviewable namespace
985 - if( !FlaggedRevs::isPageReviewable( $article->getTitle() ) )
986 - return true;
987 - # Was this revision flagged?
988 - $frev = FlaggedRevs::getFlaggedRev( $article->getTitle(), $rev->getId() );
989 - if( is_null($frev) )
990 - return true;
991 - # Grab the flags for this revision
992 - $flags = FlaggedRevs::getRevisionTags( $article->getTitle(), $rev->getID() );
993 - # Check if user is allowed to renew the stable version.
994 - if( !RevisionReview::userCanSetFlags( $flags ) ) {
995 - # Assume basic flagging level
996 - $flags = array();
997 - foreach( FlaggedRevs::$dimensions as $tag => $minQL ) {
998 - $flags[$tag] = 1;
999 - }
1000 - }
1001 - # Select the version that is now current. Create a new article object
1002 - # to avoid using one with outdated field data.
1003 - $article = new Article( $article->getTitle() );
1004 - $newRev = Revision::newFromId( $article->getLatest() );
1005 - FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $newRev, $flags );
1006 -
1007 - $this->skipReviewDiff = true; // Don't jump to diff...
1008 - $this->skipAutoReview = true; // Be sure not to do stuff twice
1009 -
1010 - return true;
1011 - }
1012893
1013894 /**
1014895 * Add a hidden revision ID field to edit form.
@@ -1047,8 +928,7 @@
1048929 return $this->stableRev;
1049930 }
1050931 # Get the content page, skip talk
1051 - global $wgTitle;
1052 - $title = $wgTitle->getSubjectPage();
 932+ $title = $this->getTitle()->getSubjectPage();
1053933 # Do we have one?
1054934 $srev = FlaggedRevs::getStablePageRev( $title, $getText, $forUpdate );
1055935 if( $srev ) {
@@ -1066,13 +946,12 @@
1067947 * @returns Array (select,override)
1068948 */
1069949 public function getVisibilitySettings( $forUpdate=false ) {
1070 - global $wgTitle;
1071950 # Cached results available?
1072951 if( !is_null($this->pageconfig) ) {
1073952 return $this->pageconfig;
1074953 }
1075954 # Get the content page, skip talk
1076 - $title = $wgTitle->getSubjectPage();
 955+ $title = $this->getTitle()->getSubjectPage();
1077956
1078957 $config = FlaggedRevs::getPageVisibilitySettings( $title, $forUpdate );
1079958 $this->pageconfig = $config;
@@ -1085,12 +964,12 @@
1086965 * @eturns Array, output of the flags for a given revision
1087966 */
1088967 public function getFlagsForRevision( $rev_id ) {
1089 - global $wgFlaggedRevTags, $wgTitle;
 968+ global $wgFlaggedRevTags;
1090969 # Cached results?
1091970 if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
1092971 return $this->flags[$rev_id];
1093972 # Get the flags
1094 - $flags = FlaggedRevs::getRevisionTags( $wgTitle, $rev_id );
 973+ $flags = FlaggedRevs::getRevisionTags( $this->getTitle(), $rev_id );
1095974 # Try to cache results
1096975 $this->flags[$rev_id] = $flags;
1097976
@@ -1104,7 +983,7 @@
1105984 * @param bool $top, should this form always go on top?
1106985 */
1107986 public function addQuickReview( $out, $top = false ) {
1108 - global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgFlaggedRevComments, $wgFlaggedRevsOverride;
 987+ global $wgOut, $wgUser, $wgRequest, $wgFlaggedRevComments, $wgFlaggedRevsOverride;
1109988 # User must have review rights
1110989 if( !$wgUser->isAllowed( 'review' ) ) {
1111990 return;
@@ -1233,16 +1112,16 @@
12341113 }
12351114 }
12361115 # For image pages, note the current image version
1237 - if( $wgTitle->getNamespace() == NS_IMAGE ) {
1238 - $file = wfFindFile( $wgTitle );
 1116+ if( $this->getTitle()->getNamespace() == NS_IMAGE ) {
 1117+ $file = wfFindFile( $this->getTitle() );
12391118 if( $file ) {
1240 - $imageParams .= $wgTitle->getDBkey() . "|" . $file->getTimestamp() . "|" . $file->getSha1() . "#";
 1119+ $imageParams .= $this->getTitle()->getDBkey() . "|" . $file->getTimestamp() . "|" . $file->getSha1() . "#";
12411120 }
12421121 }
12431122
12441123 # Hidden params
12451124 $form .= Xml::hidden( 'title', $reviewtitle->getPrefixedText() ) . "\n";
1246 - $form .= Xml::hidden( 'target', $wgTitle->getPrefixedText() ) . "\n";
 1125+ $form .= Xml::hidden( 'target', $this->getTitle()->getPrefixedText() ) . "\n";
12471126 $form .= Xml::hidden( 'oldid', $id ) . "\n";
12481127 $form .= Xml::hidden( 'action', 'submit') . "\n";
12491128 $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
@@ -1310,11 +1189,18 @@
13111190 * If viewing a stable version, adjust the last modified header
13121191 */
13131192 public function setLastModified( $sktmp, &$tpl ) {
1314 - global $wgArticle, $wgLang;
 1193+ global $wgArticle, $wgLang, $wgRequest;
13151194 # Non-content pages cannot be validated
1316 - if( !$this->pageOverride() )
 1195+ if( !$this->isReviewable() )
13171196 return true;
 1197+ # Old stable versions
 1198+ if( $wgRequest->getIntOrNull('stableid') ) {
 1199+ $tpl->set('lastmod', false);
 1200+ return true;
 1201+ }
13181202 # Check for an overridabe revision
 1203+ if( !$this->pageOverride() )
 1204+ return true;
13191205 $frev = $this->getStableRev( true );
13201206 if( !$frev || $frev->getRevId() == $wgArticle->getLatest() )
13211207 return true;
@@ -1359,5 +1245,3 @@
13601246 return true;
13611247 }
13621248 }
1363 -
1364 -
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -41,7 +41,7 @@
4242 'tooltip-ca-default' => 'Quality assurance settings',
4343
4444 'revreview-edited' => "'''Edits will be incorporated into the [[{{MediaWiki:Validationpage}}|stable version]] once an established user reviews them.
45 -The ''draft'' is shown below.''' [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} $2 {{plural:$2|change|changes}}] await review.",
 45+The ''draft'' is shown below.''' [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} $2 {{plural:$2|change awaits|changes await}}] review.",
4646
4747 'validationpage' => '{{ns:help}}:Article validation',
4848
@@ -66,6 +66,10 @@
6767 The [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} draft] has [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} $3 {{plural:$3|change|changes}}] awaiting review.',
6868 'revreview-quality' => 'This is the latest [[{{MediaWiki:Validationpage}}|quality]] revision, [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.
6969 The [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} draft] has [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} $3 {{plural:$3|change|changes}}] awaiting review.',
 70+ 'revreview-basic-i' => 'This is the latest [[{{MediaWiki:Validationpage}}|sighted]] revision, [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.
 71+The [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} draft] has [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} template/image changes] awaiting review.',
 72+ 'revreview-quality-i' => 'This is the latest [[{{MediaWiki:Validationpage}}|quality]] revision, [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.
 73+The [{{fullurl:{{FULLPAGENAMEE}}|stable=0}} draft] has [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} template/image changes] awaiting review.',
7074 'revreview-basic-same' => 'This is the latest [[{{MediaWiki:Validationpage}}|sighted]] revision ([{{fullurl:Special:Stableversions|page={{FULLPAGENAMEE}}}} list all]), [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.',
7175 'revreview-quality-same' => 'This is the latest [[{{MediaWiki:Validationpage}}|quality]] revision ([{{fullurl:Special:Stableversions|page={{FULLPAGENAMEE}}}} list all]), [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.',
7276 'revreview-basic-old' => 'This is a [[{{MediaWiki:Validationpage}}|sighted]] revision ([{{fullurl:Special:Stableversions|page={{FULLPAGENAMEE}}}} list all]), [{{fullurl:Special:Log|type=review&page={{FULLPAGENAMEE}}}} approved] on <i>$2</i>.
Index: trunk/extensions/FlaggedRevs/README.txt
@@ -5,7 +5,7 @@
66 * Download the extension from SVN
77 * (MySQL) Run the 'FlaggedRevs.sql' query, substituting in your wiki's table prefix.
88 * (PostgreSQL) Use 'FlaggedRevs.pg.sql' instead.
9 -* Upgrade to MediaWiki 1.12+
 9+* Upgrade to MediaWiki 1.13+
1010 * Run 'maintenance/update.php'
1111 * Run 'maintenance/archives/populateSha1.php'.
1212 * Add the following line to 'LocalSettings.php':
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.php
@@ -594,7 +594,9 @@
595595 $u = new LinksUpdate( $this->page, $poutput );
596596 $u->doUpdate(); // Will trigger our hook to add stable links too...
597597 # Might as well save the cache, since it should be the same
598 - $parserCache->save( $poutput, $article, $wgUser );
 598+ global $wgEnableParserCache;
 599+ if( $wgEnableParserCache )
 600+ $parserCache->save( $poutput, $article, $wgUser );
599601 # Purge squid for this page only
600602 $article->getTitle()->purgeSquid();
601603
@@ -646,7 +648,9 @@
647649 # Clear the cache...
648650 $this->page->invalidateCache();
649651 # Might as well save the cache
650 - $parserCache->save( $poutput, $article, $wgUser );
 652+ global $wgEnableParserCache;
 653+ if( $wgEnableParserCache )
 654+ $parserCache->save( $poutput, $article, $wgUser );
651655 # Purge squid for this page only
652656 $this->page->purgeSquid();
653657
@@ -897,15 +901,17 @@
898902 '&nbsp;&nbsp;' . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
899903 "</fieldset></form>"
900904 );
901 -
902 - $pager = new UnreviewedPagesPager( $this, $namespace, $category );
903 - if( $pager->getNumRows() ) {
904 - $wgOut->addHTML( wfMsgExt('unreviewed-list', array('parse') ) );
905 - $wgOut->addHTML( $pager->getNavigationBar() );
906 - $wgOut->addHTML( "<ul>" . $pager->getBody() . "</ul>" );
907 - $wgOut->addHTML( $pager->getNavigationBar() );
908 - } else {
909 - $wgOut->addHTML( wfMsgExt('unreviewed-none', array('parse') ) );
 905+ # This will start to get slower...
 906+ if( $category || self::generalQueryOK() ) {
 907+ $pager = new UnreviewedPagesPager( $this, $namespace, $category );
 908+ if( $pager->getNumRows() ) {
 909+ $wgOut->addHTML( wfMsgExt('unreviewed-list', array('parse') ) );
 910+ $wgOut->addHTML( $pager->getNavigationBar() );
 911+ $wgOut->addHTML( "<ul>" . $pager->getBody() . "</ul>" );
 912+ $wgOut->addHTML( $pager->getNavigationBar() );
 913+ } else {
 914+ $wgOut->addHTML( wfMsgExt('unreviewed-none', array('parse') ) );
 915+ }
910916 }
911917 }
912918
@@ -945,6 +951,22 @@
946952 array( 'LIMIT' => 5 ) );
947953 return $res->numRows();
948954 }
 955+
 956+ /**
 957+ * There may be many pages, most of which are reviewed
 958+ */
 959+ public static function generalQueryOK() {
 960+ global $wgFlaggedRevsNamespaces;
 961+ if( !wfQueriesMustScale() )
 962+ return true;
 963+ # Get est. of fraction of pages that are reviewed
 964+ $dbr = wfGetDB( DB_SLAVE );
 965+ $reviewedpages = $dbr->estimateRowCount( 'flaggedpages', '*', array(), __METHOD__ );
 966+ $pages = $dbr->estimateRowCount( 'page', '*', array('page_namespace' => $wgFlaggedRevsNamespaces), __METHOD__ );
 967+ $ratio = $pages/($pages - $reviewedpages);
 968+ # If dist. is normalized, # of rows scanned = $ratio * LIMIT (or until list runs out)
 969+ return ($ratio <= 100);
 970+ }
949971 }
950972
951973 /**
@@ -977,7 +999,6 @@
9781000
9791001 function getQueryInfo() {
9801002 $conds = $this->mConds;
981 - $tables = array( 'page', 'flaggedpages' );
9821003 $fields = array('page_namespace','page_title','page_len','fp_stable');
9831004 $conds[] = 'fp_reviewed IS NULL';
9841005 # Reviewable pages only
@@ -986,69 +1007,26 @@
9871008 $conds['page_is_redirect'] = 0;
9881009 # Filter by category
9891010 if( $this->category ) {
990 - $tables[] = 'categorylinks';
 1011+ $tables = array( 'categorylinks', 'page', 'flaggedpages' );
9911012 $fields[] = 'cl_sortkey';
9921013 $conds['cl_to'] = $this->category;
9931014 $conds[] = 'cl_from = page_id';
9941015 $this->mIndexField = 'cl_sortkey';
 1016+ $useIndex = array( 'categorylinks' => 'cl_sortkey' );
9951017 } else {
 1018+ $tables = array( 'page', 'flaggedpages' );
9961019 $fields[] = 'page_id';
9971020 $this->mIndexField = 'page_title';
 1021+ $useIndex = array( 'page' => 'name_title' );
9981022 }
9991023 return array(
10001024 'tables' => $tables,
10011025 'fields' => $fields,
10021026 'conds' => $conds,
1003 - 'options' => array()
 1027+ 'options' => array( 'USE INDEX' => $useIndex ),
 1028+ 'join_conds' => array( 'flaggedpages' => array('LEFT JOIN','fp_page_id=page_id') )
10041029 );
10051030 }
1006 -
1007 - /**
1008 - * Do a query with specified parameters, rather than using the object
1009 - * context
1010 - *
1011 - * @param string $offset Index offset, inclusive
1012 - * @param integer $limit Exact query limit
1013 - * @param boolean $descending Query direction, false for ascending, true for descending
1014 - * @return ResultWrapper
1015 - */
1016 - function reallyDoQuery( $offset, $limit, $descending ) {
1017 - $fname = __METHOD__ . ' (' . get_class( $this ) . ')';
1018 - $info = $this->getQueryInfo();
1019 - $tables = $info['tables'];
1020 - $fields = $info['fields'];
1021 - $conds = isset( $info['conds'] ) ? $info['conds'] : array();
1022 - $options = isset( $info['options'] ) ? $info['options'] : array();
1023 - if ( $descending ) {
1024 - $options['ORDER BY'] = $this->mIndexField;
1025 - $operator = '>';
1026 - } else {
1027 - $options['ORDER BY'] = $this->mIndexField . ' DESC';
1028 - $operator = '<';
1029 - }
1030 - if ( $offset != '' ) {
1031 - $conds[] = $this->mIndexField . $operator . $this->mDb->addQuotes( $offset );
1032 - }
1033 - $options['LIMIT'] = intval( $limit );
1034 - # Get table names
1035 - list($flaggedpages,$page,$categorylinks) = $this->mDb->tableNamesN('flaggedpages','page','categorylinks');
1036 - # Are we filtering via category?
1037 - if( in_array('categorylinks',$tables) ) {
1038 - $index = $this->mDb->useIndexClause('cl_sortkey'); // *sigh*...
1039 - $fromClause = "$categorylinks $index, $page";
1040 - } else {
1041 - $index = $this->mDb->useIndexClause('name_title'); // *sigh*...
1042 - $fromClause = "$page $index";
1043 - }
1044 - $sql = "SELECT ".implode(',',$fields).
1045 - " FROM $fromClause".
1046 - " LEFT JOIN $flaggedpages ON (fp_page_id=page_id)".
1047 - " WHERE ".$this->mDb->makeList($conds,LIST_AND).
1048 - " ORDER BY ".$options['ORDER BY']." LIMIT ".$options['LIMIT'];
1049 - # Do query!
1050 - $res = $this->mDb->query( $sql );
1051 - return new ResultWrapper( $this->mDb, $res );
1052 - }
10531031
10541032 function getIndexField() {
10551033 return $this->mIndexField;
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -101,6 +101,13 @@
102102 public function getComment() {
103103 return $this->mComment;
104104 }
 105+
 106+ /**
 107+ * @returns Integer the user ID of the reviewer
 108+ */
 109+ public function getUser() {
 110+ return $this->mUser;
 111+ }
105112
106113 /**
107114 * @returns Integer revision timestamp in MW format
@@ -123,12 +130,20 @@
124131 $this->loadText(); // load if not loaded
125132 return $this->mText;
126133 }
127 -
 134+
128135 /**
129 - * @returns Integer the user ID of the reviewer
 136+ * @returns mixed (string/false) expanded text or revision text.
 137+ * Depends on whether $wgUseStableTemplates is on or not.
130138 */
131 - public function getUser() {
132 - return $this->mUser;
 139+ public function getTextForParse() {
 140+ global $wgUseStableTemplates;
 141+ if( $wgUseStableTemplates ) {
 142+ $rev = Revision::newFromId( $this->getRevId() );
 143+ $text = $rev->getText();
 144+ } else {
 145+ $text = $this->getExpandedText();
 146+ }
 147+ return $text;
133148 }
134149
135150 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34615* Revert back to r34539 (temporary)...aaron14:42, 11 May 2008

Status & tagging log