r34615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34614‎ | r34615 | r34616 >
Date:14:42, 11 May 2008
Author:aaron
Status:old
Tags:
Comment:
* Revert back to r34539 (temporary)
* Add tweak to avoid index miss
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.042',
 18+ 'version' => '1.041',
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 = null;
 227+ $wgFlaggedArticle = new FlaggedArticle();
228228
229229 wfLoadExtensionMessages( 'FlaggedRevsPage' );
230230
@@ -238,8 +238,28 @@
239239 define( 'FLAGGED_JS', $wgScriptPath . '/extensions/FlaggedRevs/flaggedrevs.js?' . $wgFlaggedRevStyleVersion );
240240
241241 ######### Hook attachments #########
242 - # Set $wgFlaggedArticle
243 - $wgHooks['ArticleFromTitle'][] = 'wfInitFlaggedArticle';
 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' );
244264 # Autopromote Editors
245265 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoPromoteUser';
246266 # Adds table link references to include ones from the stable version
@@ -261,10 +281,17 @@
262282 # Additional parser versioning
263283 $wgHooks['ParserAfterTidy'][] = 'FlaggedRevs::parserInjectTimestamps';
264284 $wgHooks['OutputPageParserOutput'][] = 'FlaggedRevs::outputInjectTimestamps';
265 - # Auto-reviewing
 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' );
266294 $wgHooks['ArticleSaveComplete'][] = 'FlaggedRevs::autoMarkPatrolled';
267 - $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeEditReviewed';
268 - $wgHooks['ArticleRollbackComplete'][] = 'FlaggedRevs::maybeMakeRollbackReviewed';
 295+ $wgHooks['RevisionInsertComplete'][] = 'FlaggedRevs::maybeMakeNullEditReviewed';
269296 # Disallow moves of stable pages
270297 $wgHooks['userCan'][] = 'FlaggedRevs::userCanMove';
271298 $wgHooks['userCan'][] = 'FlaggedRevs::userCanView';
@@ -280,44 +307,6 @@
281308 #########
282309 }
283310
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 -
322311 # Add review log and such
323312 $wgLogTypes[] = 'review';
324313 $wgLogNames['review'] = 'review-logpage';
@@ -337,6 +326,25 @@
338327
339328 $wgHooks['LoadExtensionSchemaUpdates'][] = 'efFlaggedRevsSchemaUpdates';
340329
 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+
341349 class FlaggedRevs {
342350 public static $dimensions = array();
343351 public static $styleLoaded = false;
@@ -426,14 +434,14 @@
427435 */
428436 public static function parseStableText( $article, $text='', $id, $reparsed = true ) {
429437 global $wgParser;
430 - $title = $article->getTitle(); // avoid pass-by-reference error
431438 # Make our hooks to trigger
432439 $wgParser->fr_isStable = true;
433440 $wgParser->fr_includesMatched = true;
434441 # Don't show section-edit links, they can be old and misleading
435442 $options = self::makeParserOptions();
436 - $options->setEditSection( $id == $title->getLatestRevID(GAID_FOR_UPDATE) );
 443+ $options->setEditSection( $id==$article->getLatest() );
437444 # Parse the new body, wikitext -> html
 445+ $title = $article->getTitle(); // avoid pass-by-reference error
438446 $parserOut = $wgParser->parse( $text, $title, $options, true, true, $id );
439447 $parserOut->fr_includesMatched = $wgParser->fr_includesMatched;
440448 # Done with parser!
@@ -482,14 +490,14 @@
483491 /**
484492 * @param FlaggedRevision $frev
485493 * @param Article $article
486 - * @param ParserOutput $stableOutput, will fetch if not given
 494+ * @param ParserOutput $flaggedOutput, will fetch if not given
487495 * @param ParserOutput $currentOutput, will fetch if not given
488496 * @return bool
489497 * See if a flagged revision is synced with the current
490498 */
491 - public static function flaggedRevIsSynced( $frev, $article, $stableOutput=null, $currentOutput=null ) {
 499+ public static function flaggedRevIsSynced( $frev, $article, $flaggedOutput=null, $currentOutput=null ) {
492500 # Must be the same revision
493 - if( $frev->getRevId() != $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) ) {
 501+ if( $frev->getRevId() != $article->getLatest() ) {
494502 return false;
495503 }
496504 global $wgMemc;
@@ -505,14 +513,20 @@
506514 }
507515 }
508516 # If parseroutputs not given, fetch them...
509 - if( is_null($stableOutput) || !isset($stableOutput->fr_newestTemplateID) ) {
 517+ if( is_null($flaggedOutput) || !isset($flaggedOutput->fr_newestTemplateID) ) {
510518 # Get parsed stable version
511 - $stableOutput = self::getPageCache( $article );
512 - if( $stableOutput==false ) {
513 - $text = $frev->getTextForParse();
514 - $stableOutput = self::parseStableText( $article, $text, $frev->getRevId() );
 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() );
515529 # Update the stable version cache
516 - self::updatePageCache( $article, $stableOutput );
 530+ FlaggedRevs::updatePageCache( $article, $flaggedOutput );
517531 }
518532 }
519533 if( is_null($currentOutput) || !isset($currentOutput->fr_newestTemplateID) ) {
@@ -526,17 +540,15 @@
527541 $options = self::makeParserOptions( $wgUser );
528542 $currentOutput = $wgParser->parse( $text, $title, $options );
529543 # Might as well save the cache while we're at it
530 - global $wgEnableParserCache;
531 - if( $wgEnableParserCache )
532 - $parserCache->save( $currentOutput, $article, $wgUser );
 544+ $parserCache->save( $currentOutput, $article, $wgUser );
533545 }
534546 }
535547 # Only current of revisions of inclusions can be reviewed. Since the stable and current revisions
536548 # have the same text, the only thing that can make them different is updating a template or image.
537549 # If this is the case, the current revision will have a newer template or image version used somewhere.
538 - if( $currentOutput->fr_newestImageTime > $stableOutput->fr_newestImageTime ) {
 550+ if( $currentOutput->fr_newestImageTime > $flaggedOutput->fr_newestImageTime ) {
539551 $synced = false;
540 - } else if( $currentOutput->fr_newestTemplateID > $stableOutput->fr_newestTemplateID ) {
 552+ } else if( $currentOutput->fr_newestTemplateID > $flaggedOutput->fr_newestTemplateID ) {
541553 $synced = false;
542554 } else {
543555 $synced = true;
@@ -546,7 +558,7 @@
547559 global $wgParserCacheExpireTime;
548560 $syncData = $synced ? "true" : "false";
549561 $wgMemc->set( $key, $syncData, $wgParserCacheExpireTime );
550 -
 562+
551563 return $synced;
552564 }
553565
@@ -646,6 +658,7 @@
647659 if( $row ) {
648660 return new FlaggedRevision( $title, $row );
649661 }
 662+
650663 return null;
651664 }
652665
@@ -657,13 +670,11 @@
658671 */
659672 public static function getRevQuality( $title, $rev_id, $db = NULL ) {
660673 $db = $db ? $db : wfGetDB( DB_SLAVE );
661 - $quality = $db->selectField( 'flaggedrevs',
662 - 'fr_quality',
 674+ $quality = $db->selectField( 'flaggedrevs', 'fr_quality',
663675 array( 'fr_page_id' => $title->getArticleID(),
664676 'fr_rev_id' => $rev_id ),
665677 __METHOD__,
666 - array( 'FORCE INDEX' => 'PRIMARY' )
667 - );
 678+ array( 'FORCE INDEX' => 'PRIMARY' ) );
668679 return $quality;
669680 }
670681
@@ -754,7 +765,7 @@
755766 # Check if the count is zero by using $article->getLatest().
756767 # I don't trust using memcache and PHP for values like '0'
757768 # as it may confuse "expired" with "0". -aaron
758 - if( $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE) == $from_rev ) {
 769+ if( $article->getLatest()==$from_rev ) {
759770 return 0;
760771 }
761772 global $wgMemc;
@@ -862,7 +873,7 @@
863874 public static function getRevisionTags( $title, $rev_id ) {
864875 $dbr = wfGetDB( DB_SLAVE );
865876 $tags = $dbr->selectField( 'flaggedrevs', 'fr_tags',
866 - array( 'fr_rev_id' => $rev_id,
 877+ array('fr_rev_id' => $rev_id,
867878 'fr_page_id' => $title->getArticleId() ),
868879 __METHOD__ );
869880 if( !$tags )
@@ -1034,10 +1045,10 @@
10351046 /**
10361047 * Add FlaggedRevs css/js. Attached to two different hooks, neglect inputs.
10371048 */
1038 - public static function InjectStyleAndJS() {
 1049+ public static function InjectStyleAndJS( $a=false, $b=false ) {
10391050 global $wgOut, $wgJsMimeType, $wgFlaggedArticle;
10401051 # Don't double-load
1041 - if( self::$styleLoaded || !$wgFlaggedArticle )
 1052+ if( self::$styleLoaded )
10421053 return true;
10431054 # UI CSS
10441055 $wgOut->addLink( array(
@@ -1093,18 +1104,19 @@
10941105 $quality = self::isPristine($flags) ? 2 : 1;
10951106 }
10961107 $tmpset = $imgset = array();
1097 - $poutput = false;
10981108 # Try the parser cache, should be set on the edit before this is called.
10991109 # If not set or up to date, then parse it. Use master to avoid lag issues.
 1110+ $poutput = false;
11001111 $latestID = $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE);
1101 - if( $poutput == false ) {
 1112+ if( $latestID == $rev->getId() ) {
 1113+ $parserCache = ParserCache::singleton();
 1114+ $poutput = $parserCache->get( $article, $user );
 1115+ }
 1116+ if( $poutput==false ) {
11021117 $options = self::makeParserOptions( $user );
1103 - $title = $article->getTitle(); // avoid pass-by-ref error
1104 - $poutput = $wgParser->parse( $text, $title, $options, true, true, $latestID );
 1118+ $poutput = $wgParser->parse( $text, $article->getTitle(), $options, true, true, $rev->getId() );
11051119 # Might as well save the cache while we're at it
1106 - global $wgEnableParserCache;
1107 - if( $wgEnableParserCache && $latestID == $rev->getId() ) {
1108 - $parserCache = ParserCache::singleton();
 1120+ if( $latestID == $rev->getId() ) {
11091121 $parserCache->save( $poutput, $article, $user );
11101122 }
11111123 }
@@ -1151,7 +1163,7 @@
11521164 $textFlags = self::compressText( $fulltext );
11531165
11541166 # Write to external storage if required
1155 - $storage = self::getExternalStorage();
 1167+ $storage = FlaggedRevs::getExternalStorage();
11561168 if( $storage ) {
11571169 if( is_array($storage) ) {
11581170 # Distribute storage across multiple clusters
@@ -1207,7 +1219,7 @@
12081220 $sv = self::getStablePageRev( $article->getTitle(), false, true );
12091221 if( $sv && $sv->getRevId() == $rev->getId() ) {
12101222 # Update stable cache
1211 - self::updatePageCache( $article, $poutput );
 1223+ FlaggedRevs::updatePageCache( $article, $poutput );
12121224 # Update page fields
12131225 self::updateArticleOn( $article, $rev->getId(), $rev->getId() );
12141226 # Purge squid for this page only
@@ -1341,9 +1353,7 @@
13421354 $options = self::makeParserOptions( $wgUser );
13431355 $poutput = $wgParser->parse($text, $article->getTitle(), $options);
13441356 # Might as well save the cache while we're at it
1345 - global $wgEnableParserCache;
1346 - if( $wgEnableParserCache )
1347 - $parserCache->save( $poutput, $article, $wgUser );
 1357+ $parserCache->save( $poutput, $article, $wgUser );
13481358 }
13491359 $u = new LinksUpdate( $article->getTitle(), $poutput );
13501360 $u->doUpdate(); // this will trigger our hook to add stable links too...
@@ -1380,7 +1390,12 @@
13811391 # Try stable version cache. This should be updated before this is called.
13821392 $parserOut = self::getPageCache( $article );
13831393 if( $parserOut==false ) {
1384 - $text = $sv->getTextForParse();
 1394+ if( $wgUseStableTemplates ) {
 1395+ $rev = Revision::newFromId( $sv->getRevId() );
 1396+ $text = $rev->getText();
 1397+ } else {
 1398+ $text = $sv->getExpandedText();
 1399+ }
13851400 # Parse the text
13861401 $parserOut = self::parseStableText( $article, $text, $sv->getRevId() );
13871402 }
@@ -1699,12 +1714,13 @@
17001715 * Don't let users vandalize pages by moving them.
17011716 */
17021717 public static function userCanMove( $title, $user, $action, $result ) {
1703 - global $wgTitle, $wgFlaggedArticle;
 1718+ global $wgTitle;
17041719
17051720 if( $action != 'move' || !self::isPageReviewable( $title ) )
17061721 return true;
17071722 # See if there is a stable version
1708 - if( $wgFlaggedArticle && $wgTitle && $wgTitle->equals( $title ) ) {
 1723+ if( $wgTitle && $wgTitle->equals( $title ) ) {
 1724+ global $wgFlaggedArticle;
17091725 // Cache stable version while we are at it.
17101726 $frev = $wgFlaggedArticle->getStableRev( true );
17111727 } else {
@@ -1725,7 +1741,7 @@
17261742 * Allow users to view reviewed pages.
17271743 */
17281744 public static function userCanView( $title, $user, $action, $result ) {
1729 - global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle, $wgFlaggedArticle;
 1745+ global $wgFlaggedRevsVisible, $wgFlaggedRevsTalkVisible, $wgTitle;
17301746 # Assume $action may still not be set, in which case, treat it as 'view'...
17311747 if( $action != 'read' )
17321748 return true;
@@ -1741,7 +1757,7 @@
17421758 }
17431759 # See if there is a stable version. Also, see if, given the page
17441760 # config and URL params, the page can be overriden.
1745 - if( $wgFlaggedArticle && $wgTitle && $wgTitle->equals( $title ) ) {
 1761+ if( $wgTitle && $wgTitle->equals( $title ) ) {
17461762 global $wgFlaggedArticle;
17471763 // Cache stable version while we are at it.
17481764 if( $wgFlaggedArticle->pageOverride() && $wgFlaggedArticle->getStableRev( true ) ) {
@@ -1756,89 +1772,42 @@
17571773 }
17581774
17591775 /**
1760 - * When an edit is made by a reviewer, if the current revision is the stable
1761 - * version, try to automatically review it.
 1776+ * When a null edit is made, autoreview if necessary
17621777 */
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;
 1778+ public static function maybeMakeNullEditReviewed( $rev ) {
 1779+ $title = $rev->getTitle();
17691780 # GetTitle() for revisions uses slaves and wants page_id,rev_id to
17701781 # match...this is bad if we *just* added it.
1771 - $title = $rev->getTitle() ? $rev->getTitle() : Title::newFromID( $rev->getPage(), GAID_FOR_UPDATE );
1772 - # Must be in reviewable namespace
 1782+ $title = $title ? $title : Title::newFromID( $rev->getPage() );
17731783 if( !$title || !self::isPageReviewable( $title ) ) {
17741784 return true;
17751785 }
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;
 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+ }
17941803 }
 1804+ $user = User::newFromId( $rev->getUser() );
 1805+ FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags );
17951806 }
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 - }
18051807 }
1806 - if( $wgFlaggedArticle ) {
1807 - $wgFlaggedArticle->skipReviewDiff = true; // Don't jump to diff...
1808 - }
18091808 return true;
18101809 }
18111810
18121811 /**
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 - /**
18431812 * When an edit is made to a page that can't be reviewed, autopatrol if allowed.
18441813 * This is not loggged for perfomance reasons and no one cares if talk pages and such
18451814 * are autopatrolled.
@@ -2145,8 +2114,46 @@
21462115 * Add user preference to form HTML
21472116 */
21482117 public static function injectPreferences( $form, $out ) {
2149 - $prefsHtml = FlaggedRevsXML::stabilityPreferences( $form );
2150 - $out->addHTML( $prefsHtml );
 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+
21512158 return true;
21522159 }
21532160
@@ -2206,21 +2213,4 @@
22072214 }
22082215 }
22092216
2210 -function efFlaggedRevsSchemaUpdates() {
2211 - global $wgDBtype, $wgExtNewFields, $wgExtPGNewFields, $wgExtNewIndexes, $wgExtNewTables;
22122217
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,12 +117,8 @@
118118 $msg = $quality ? 'revreview-quality-old' : 'revreview-basic-old';
119119 $html = wfMsgExt($msg, array('parseinline'), $frev->getRevId(), $time );
120120 } else {
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 - }
 121+ $msg = $stable ? 'revreview-' : 'revreview-newest-';
 122+ $msg .= $quality ? 'quality' : 'basic';
127123 $html = wfMsgExt($msg, array('parseinline'), $frev->getRevId(), $time, $revs_since );
128124 }
129125 # Make fancy box...
@@ -141,45 +137,4 @@
142138
143139 return $box;
144140 }
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 - }
186141 }
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -1,8 +1,9 @@
22 <?php
33
4 -class FlaggedArticle extends Article {
 4+class FlaggedArticle {
55 public $isDiffFromStable = false;
66 public $skipReviewDiff = false;
 7+ public $skipAutoReview = false;
78 public $stableRev = null;
89 public $pageconfig = null;
910 public $flags = null;
@@ -74,7 +75,9 @@
7576 * Is this article reviewable?
7677 */
7778 public function isReviewable() {
78 - return FlaggedRevs::isPageReviewable( $this->getTitle() );
 79+ global $wgTitle;
 80+
 81+ return FlaggedRevs::isPageReviewable( $wgTitle );
7982 }
8083
8184 /**
@@ -82,7 +85,12 @@
8386 */
8487 private function displayTag() {
8588 global $wgOut;
 89+
 90+ if( !$this->reviewNotice ) {
 91+ return false;
 92+ }
8693 $wgOut->appendSubtitle( $this->reviewNotice );
 94+
8795 return true;
8896 }
8997
@@ -168,7 +176,13 @@
169177 // behavior below, since it is the same as ("&stable=1").
170178 if( $old ) {
171179 $revs_since = FlaggedRevs::getRevCountSince( $article, $frev->getRevId() );
172 - $text = $frev->getTextForParse();
 180+ global $wgUseStableTemplates;
 181+ if( $wgUseStableTemplates ) {
 182+ $rev = Revision::newFromId( $frev->getRevId() );
 183+ $text = $rev->getText();
 184+ } else {
 185+ $text = $frev->getExpandedText();
 186+ }
173187 $parserOut = FlaggedRevs::parseStableText( $article, $text, $frev->getRevId() );
174188 # Construct some tagging for non-printable outputs. Note that the pending
175189 # notice has all this info already, so don't do this if we added that already.
@@ -272,7 +286,13 @@
273287 # Get parsed stable version
274288 $parserOut = FlaggedRevs::getPageCache( $article );
275289 if( $parserOut==false ) {
276 - $text = $frev->getTextForParse();
 290+ global $wgUseStableTemplates;
 291+ if( $wgUseStableTemplates ) {
 292+ $rev = Revision::newFromId( $frev->getRevId() );
 293+ $text = $rev->getText();
 294+ } else {
 295+ $text = $frev->getExpandedText();
 296+ }
277297 $parserOut = FlaggedRevs::parseStableText( $article, $text, $frev->getRevId() );
278298 # Update the stable version cache
279299 FlaggedRevs::updatePageCache( $article, $parserOut );
@@ -294,7 +314,6 @@
295315 // Standard UI
296316 } else {
297317 $msg = $quality ? 'revreview-quality' : 'revreview-basic';
298 - $msg .= ($revs_since == 0) ? '-i' : '';
299318 $msg = $synced ? "{$msg}-same" : $msg;
300319
301320 $tag = "<span class='{$css} plainlinks' title=\"{$tooltip}\"></span>" .
@@ -386,7 +405,7 @@
387406 * Adds latest stable version tag to page when editing
388407 */
389408 public function addToEditView( $editform ) {
390 - global $wgRequest, $wgOut;
 409+ global $wgRequest, $wgTitle, $wgOut;
391410 # Talk pages cannot be validated
392411 if( !$editform->mArticle || !$this->isReviewable() )
393412 return false;
@@ -403,7 +422,7 @@
404423 $tag = $warning = '';
405424 # Check the newest stable version
406425 $frev = $this->getStableRev();
407 - if( !is_null($frev) ) {
 426+ if( !is_null($frev) && $frev->getRevId() != $revid ) {
408427 global $wgLang, $wgUser, $wgFlaggedRevsAutoReview;
409428
410429 $time = $wgLang->date( $frev->getTimestamp(), true );
@@ -422,28 +441,26 @@
423442 wfMsgExt($msg,array('parseinline')) . "</div>";
424443 }
425444 }
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>";
 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>';
447463 }
 464+ $tag = "<div id='mw-revisiontag-edit' class='flaggedrevs_editnotice plainlinks'>$tag</div>";
448465 }
449466 $wgOut->addHTML( $tag . $warning );
450467 # Show diff to stable, to make things less confusing
@@ -519,7 +536,7 @@
520537 * Add link to stable version setting to protection form
521538 */
522539 public function addVisibilityLink( $out ) {
523 - global $wgUser, $wgRequest;
 540+ global $wgUser, $wgRequest, $wgTitle;
524541
525542 if( !$this->isReviewable() )
526543 return true;
@@ -889,6 +906,108 @@
890907
891908 return true;
892909 }
 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+ }
8931012
8941013 /**
8951014 * Add a hidden revision ID field to edit form.
@@ -928,7 +1047,8 @@
9291048 return $this->stableRev;
9301049 }
9311050 # Get the content page, skip talk
932 - $title = $this->getTitle()->getSubjectPage();
 1051+ global $wgTitle;
 1052+ $title = $wgTitle->getSubjectPage();
9331053 # Do we have one?
9341054 $srev = FlaggedRevs::getStablePageRev( $title, $getText, $forUpdate );
9351055 if( $srev ) {
@@ -946,12 +1066,13 @@
9471067 * @returns Array (select,override)
9481068 */
9491069 public function getVisibilitySettings( $forUpdate=false ) {
 1070+ global $wgTitle;
9501071 # Cached results available?
9511072 if( !is_null($this->pageconfig) ) {
9521073 return $this->pageconfig;
9531074 }
9541075 # Get the content page, skip talk
955 - $title = $this->getTitle()->getSubjectPage();
 1076+ $title = $wgTitle->getSubjectPage();
9561077
9571078 $config = FlaggedRevs::getPageVisibilitySettings( $title, $forUpdate );
9581079 $this->pageconfig = $config;
@@ -964,12 +1085,12 @@
9651086 * @eturns Array, output of the flags for a given revision
9661087 */
9671088 public function getFlagsForRevision( $rev_id ) {
968 - global $wgFlaggedRevTags;
 1089+ global $wgFlaggedRevTags, $wgTitle;
9691090 # Cached results?
9701091 if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
9711092 return $this->flags[$rev_id];
9721093 # Get the flags
973 - $flags = FlaggedRevs::getRevisionTags( $this->getTitle(), $rev_id );
 1094+ $flags = FlaggedRevs::getRevisionTags( $wgTitle, $rev_id );
9741095 # Try to cache results
9751096 $this->flags[$rev_id] = $flags;
9761097
@@ -983,7 +1104,7 @@
9841105 * @param bool $top, should this form always go on top?
9851106 */
9861107 public function addQuickReview( $out, $top = false ) {
987 - global $wgOut, $wgUser, $wgRequest, $wgFlaggedRevComments, $wgFlaggedRevsOverride;
 1108+ global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgFlaggedRevComments, $wgFlaggedRevsOverride;
9881109 # User must have review rights
9891110 if( !$wgUser->isAllowed( 'review' ) ) {
9901111 return;
@@ -1112,16 +1233,16 @@
11131234 }
11141235 }
11151236 # For image pages, note the current image version
1116 - if( $this->getTitle()->getNamespace() == NS_IMAGE ) {
1117 - $file = wfFindFile( $this->getTitle() );
 1237+ if( $wgTitle->getNamespace() == NS_IMAGE ) {
 1238+ $file = wfFindFile( $wgTitle );
11181239 if( $file ) {
1119 - $imageParams .= $this->getTitle()->getDBkey() . "|" . $file->getTimestamp() . "|" . $file->getSha1() . "#";
 1240+ $imageParams .= $wgTitle->getDBkey() . "|" . $file->getTimestamp() . "|" . $file->getSha1() . "#";
11201241 }
11211242 }
11221243
11231244 # Hidden params
11241245 $form .= Xml::hidden( 'title', $reviewtitle->getPrefixedText() ) . "\n";
1125 - $form .= Xml::hidden( 'target', $this->getTitle()->getPrefixedText() ) . "\n";
 1246+ $form .= Xml::hidden( 'target', $wgTitle->getPrefixedText() ) . "\n";
11261247 $form .= Xml::hidden( 'oldid', $id ) . "\n";
11271248 $form .= Xml::hidden( 'action', 'submit') . "\n";
11281249 $form .= Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n";
@@ -1189,18 +1310,11 @@
11901311 * If viewing a stable version, adjust the last modified header
11911312 */
11921313 public function setLastModified( $sktmp, &$tpl ) {
1193 - global $wgArticle, $wgLang, $wgRequest;
 1314+ global $wgArticle, $wgLang;
11941315 # Non-content pages cannot be validated
1195 - if( !$this->isReviewable() )
 1316+ if( !$this->pageOverride() )
11961317 return true;
1197 - # Old stable versions
1198 - if( $wgRequest->getIntOrNull('stableid') ) {
1199 - $tpl->set('lastmod', false);
1200 - return true;
1201 - }
12021318 # Check for an overridabe revision
1203 - if( !$this->pageOverride() )
1204 - return true;
12051319 $frev = $this->getStableRev( true );
12061320 if( !$frev || $frev->getRevId() == $wgArticle->getLatest() )
12071321 return true;
@@ -1245,3 +1359,5 @@
12461360 return true;
12471361 }
12481362 }
 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 awaits|changes await}}] review.",
 45+The ''draft'' is shown below.''' [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur}} $2 {{plural:$2|change|changes}}] await review.",
4646
4747 'validationpage' => '{{ns:help}}:Article validation',
4848
@@ -66,10 +66,6 @@
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.',
7470 '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>.',
7571 '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>.',
7672 '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.13+
 9+* Upgrade to MediaWiki 1.12+
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,9 +594,7 @@
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 - global $wgEnableParserCache;
599 - if( $wgEnableParserCache )
600 - $parserCache->save( $poutput, $article, $wgUser );
 598+ $parserCache->save( $poutput, $article, $wgUser );
601599 # Purge squid for this page only
602600 $article->getTitle()->purgeSquid();
603601
@@ -648,9 +646,7 @@
649647 # Clear the cache...
650648 $this->page->invalidateCache();
651649 # Might as well save the cache
652 - global $wgEnableParserCache;
653 - if( $wgEnableParserCache )
654 - $parserCache->save( $poutput, $article, $wgUser );
 650+ $parserCache->save( $poutput, $article, $wgUser );
655651 # Purge squid for this page only
656652 $this->page->purgeSquid();
657653
@@ -901,17 +897,15 @@
902898 '&nbsp;&nbsp;' . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
903899 "</fieldset></form>"
904900 );
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 - }
 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') ) );
916910 }
917911 }
918912
@@ -951,22 +945,6 @@
952946 array( 'LIMIT' => 5 ) );
953947 return $res->numRows();
954948 }
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 - }
971949 }
972950
973951 /**
@@ -999,6 +977,7 @@
1000978
1001979 function getQueryInfo() {
1002980 $conds = $this->mConds;
 981+ $tables = array( 'page', 'flaggedpages' );
1003982 $fields = array('page_namespace','page_title','page_len','fp_stable');
1004983 $conds[] = 'fp_reviewed IS NULL';
1005984 # Reviewable pages only
@@ -1007,26 +986,69 @@
1008987 $conds['page_is_redirect'] = 0;
1009988 # Filter by category
1010989 if( $this->category ) {
1011 - $tables = array( 'categorylinks', 'page', 'flaggedpages' );
 990+ $tables[] = 'categorylinks';
1012991 $fields[] = 'cl_sortkey';
1013992 $conds['cl_to'] = $this->category;
1014993 $conds[] = 'cl_from = page_id';
1015994 $this->mIndexField = 'cl_sortkey';
1016 - $useIndex = array( 'categorylinks' => 'cl_sortkey' );
1017995 } else {
1018 - $tables = array( 'page', 'flaggedpages' );
1019996 $fields[] = 'page_id';
1020997 $this->mIndexField = 'page_title';
1021 - $useIndex = array( 'page' => 'name_title' );
1022998 }
1023999 return array(
10241000 'tables' => $tables,
10251001 'fields' => $fields,
10261002 'conds' => $conds,
1027 - 'options' => array( 'USE INDEX' => $useIndex ),
1028 - 'join_conds' => array( 'flaggedpages' => array('LEFT JOIN','fp_page_id=page_id') )
 1003+ 'options' => array()
10291004 );
10301005 }
 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+ }
10311053
10321054 function getIndexField() {
10331055 return $this->mIndexField;
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -101,13 +101,6 @@
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 - }
112105
113106 /**
114107 * @returns Integer revision timestamp in MW format
@@ -130,20 +123,12 @@
131124 $this->loadText(); // load if not loaded
132125 return $this->mText;
133126 }
134 -
 127+
135128 /**
136 - * @returns mixed (string/false) expanded text or revision text.
137 - * Depends on whether $wgUseStableTemplates is on or not.
 129+ * @returns Integer the user ID of the reviewer
138130 */
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;
 131+ public function getUser() {
 132+ return $this->mUser;
148133 }
149134
150135 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r34632Scap done already - bring back commits reverted in r34615aaron21:31, 11 May 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r34539- modular reader/writer support for non-ImageIO handlers...river22:59, 9 May 2008

Status & tagging log