r25827 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25826‎ | r25827 | r25828 >
Date:13:29, 13 September 2007
Author:aaron
Status:old
Tags:
Comment:
*E_STRICT and OOP stuff. Alter convoluted static function scheme; just use the global.
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -143,12 +143,12 @@
144144
145145 # Define when users get automatically promoted to editors. Set as false to disable.
146146 $wgFlaggedRevsAutopromote = array(
147 - 'days' => 60,
148 - 'edits' => 200,
149 - 'spacing' => 5,
 147+ 'days' => 60,
 148+ 'edits' => 200,
 149+ 'spacing' => 5,
150150 'benchmarks' => 5, // keep this small
151 - 'email' => true,
152 - 'userpage' => true
 151+ 'email' => true,
 152+ 'userpage' => true
153153 );
154154
155155 # Variables below this point should probably not be modified
@@ -200,11 +200,11 @@
201201 /**
202202 * @param string $text
203203 * @param Title $title
204 - * @param Integer $id, revision id
 204+ * @param integer $id, revision id
205205 * @returns array( string, bool )
206206 * All included pages/arguments are expanded out
207207 */
208 - public static function expandText( $text='', $title, $id=null ) {
 208+ public function expandText( $text='', $title, $id=null ) {
209209 global $wgParser, $wgUser;
210210 # Make our hooks to trigger
211211 $wgParser->isStable = true;
@@ -228,7 +228,7 @@
229229 * @returns ParserOutput
230230 * Get the HTML of a revision based on how it was during $timeframe
231231 */
232 - public static function parseStableText( $article, $text, $id=NULL ) {
 232+ public function parseStableText( $article, $text, $id=NULL ) {
233233 global $wgParser, $wgUser;
234234 # Default options for anons if not logged in
235235 $options = ParserOptions::newFromUser($wgUser);
@@ -251,7 +251,7 @@
252252 * @returns string, flags
253253 * Compress pre-processed text, passed by reference
254254 */
255 - public static function compressText( &$text ) {
 255+ public function compressText( &$text ) {
256256 global $wgFlaggedRevsCompression;
257257 # Compress text if $wgFlaggedRevsCompression is set.
258258 $flags = array( 'utf-8' );
@@ -272,7 +272,7 @@
273273 * @returns string
274274 * Uncompress pre-processed text, using flags
275275 */
276 - public static function uncompressText( $text, $flags ) {
 276+ public function uncompressText( $text, $flags ) {
277277 global $wgFlaggedRevsCompression;
278278
279279 if( !is_array($flags) ) {
@@ -294,15 +294,16 @@
295295 * @returns string
296296 * Get the text of a stable version
297297 */
298 - public static function getFlaggedRevText( $rev_id ) {
299 - $db = wfGetDB( DB_SLAVE );
 298+ public function getFlaggedRevText( $rev_id ) {
 299+ $dbr = wfGetDB( DB_SLAVE );
300300 // Get the text from the flagged revisions table
301 - $result = $db->select( array('flaggedrevs','revision'),
 301+ $result = $dbr->select( array('flaggedrevs','revision'),
302302 array('fr_text', 'fr_flags'),
303 - array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
 303+ array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id',
 304+ 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
304305 __METHOD__,
305306 array('LIMIT' => 1) );
306 - if( $row = $db->fetchObject($result) ) {
 307+ if( $row = $dbr->fetchObject($result) ) {
307308 return self::uncompressText( $row->fr_text, $row->fr_flags );
308309 }
309310
@@ -314,15 +315,16 @@
315316 * @returns Revision
316317 * Will not return if deleted
317318 */
318 - public static function getFlaggedRev( $rev_id ) {
319 - $db = wfGetDB( DB_SLAVE );
320 - // Skip deleted revisions
321 - $result = $db->select( array('flaggedrevs','revision'),
 319+ public function getFlaggedRev( $rev_id ) {
 320+ $dbr = wfGetDB( DB_SLAVE );
 321+ # Skip deleted revisions
 322+ $result = $dbr->select( array('flaggedrevs','revision'),
322323 array('fr_namespace', 'fr_title', 'fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
323 - array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
 324+ array('fr_rev_id' => $rev_id, 'fr_rev_id = rev_id',
 325+ 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
324326 __METHOD__ );
325 - // Sorted from highest to lowest, so just take the first one if any
326 - if( $row = $db->fetchObject($result) ) {
 327+ # Sorted from highest to lowest, so just take the first one if any
 328+ if( $row = $dbr->fetchObject($result) ) {
327329 return $row;
328330 }
329331
@@ -335,16 +337,16 @@
336338 * Get rev ids of reviewed revs for a page
337339 * Will include deleted revs here
338340 */
339 - public static function getReviewedRevs( $page ) {
 341+ public function getReviewedRevs( $page ) {
340342 $rows = array();
341343
342 - $db = wfGetDB( DB_SLAVE );
343 - $result = $db->select('flaggedrevs',
 344+ $dbr = wfGetDB( DB_SLAVE );
 345+ $result = $dbr->select('flaggedrevs',
344346 array('fr_rev_id','fr_quality'),
345347 array('fr_namespace' => $page->getNamespace(), 'fr_title' => $page->getDBkey() ),
346348 __METHOD__ ,
347349 array('ORDER BY' => 'fr_rev_id DESC') );
348 - while( $row = $db->fetchObject($result) ) {
 350+ while( $row = $dbr->fetchObject($result) ) {
349351 $rows[$row->fr_rev_id] = $row->fr_quality;
350352 }
351353
@@ -357,7 +359,7 @@
358360 * @returns int
359361 * Get number of revs since a certain revision
360362 */
361 - public static function getRevCountSince( $page_id, $from_rev ) {
 363+ public function getRevCountSince( $page_id, $from_rev ) {
362364 $dbr = wfGetDB( DB_SLAVE );
363365 $count = $dbr->selectField('revision', 'COUNT(*)',
364366 array('rev_page' => $page_id, "rev_id > $from_rev"),
@@ -382,10 +384,9 @@
383385 $selectColumns[] = 'fr_text';
384386 $selectColumns[] = 'fr_flags';
385387 }
386 -
 388+ # If we want the text, then get the text flags too
387389 if( !$forUpdate ) {
388390 $dbr = wfGetDB( DB_SLAVE );
389 - // Skip deleted revisions
390391 $result = $dbr->select( array('page', 'flaggedrevs', 'revision'),
391392 $selectColumns,
392393 array('page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey(),
@@ -403,8 +404,8 @@
404405 // Look for quality revision
405406 $result = $dbw->select( array('flaggedrevs', 'revision'),
406407 $selectColumns,
407 - array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
408 - 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
 408+ array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
 409+ 'fr_quality >= 1', 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
409410 __METHOD__,
410411 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
411412 // Do we have one? If not, try any reviewed revision...
@@ -412,7 +413,7 @@
413414 $result = $dbw->select( array('flaggedrevs', 'revision'),
414415 $selectColumns,
415416 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
416 - 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
 417+ 'fr_rev_id = rev_id', 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
417418 __METHOD__,
418419 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
419420 if( !$row = $dbw->fetchObject($result) )
@@ -427,19 +428,18 @@
428429 * @returns Array
429430 */
430431 public function getFlagsForRevision( $rev_id ) {
431 - // Set all flags to zero
 432+ # Set all flags to zero
432433 $flags = array();
433434 foreach( array_keys($this->dimensions) as $tag ) {
434435 $flags[$tag] = 0;
435436 }
436 -
 437+ # Grab all the tags for this revision
437438 $db = wfGetDB( DB_SLAVE );
438 - // Grab all the tags for this revision
439439 $result = $db->select('flaggedrevtags',
440440 array('frt_dimension', 'frt_value'),
441441 array('frt_rev_id' => $rev_id),
442442 __METHOD__ );
443 - // Iterate through each tag result
 443+ # Iterate through each tag result
444444 while ( $row = $db->fetchObject($result) ) {
445445 $flags[$row->frt_dimension] = $row->frt_value;
446446 }
@@ -451,7 +451,7 @@
452452 * @returns bool
453453 * Is $title the main page?
454454 */
455 - public static function isMainPage( $title ) {
 455+ public function isMainPage( $title ) {
456456 $mp = Title::newMainPage();
457457 return ( $title->getNamespace()==$mp->getNamespace() && $title->getDBKey()==$mp->getDBKey() );
458458 }
@@ -459,7 +459,7 @@
460460 /**
461461 * @param array $flags
462462 * @param bool $prettybox
463 - * @param string $css
 463+ * @param string $css, class to wrap box in
464464 * @returns string
465465 * Generates a review box/tag
466466 */
@@ -512,14 +512,14 @@
513513 $quality = self::isQuality( $flags );
514514 $pristine = self::isPristine( $flags );
515515 $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
516 - // Some checks for which tag CSS to use
 516+ # Some checks for which tag CSS to use
517517 if( $pristine )
518518 $tagClass = 'flaggedrevs_box3';
519519 else if( $quality )
520520 $tagClass = 'flaggedrevs_box2';
521521 else
522522 $tagClass = 'flaggedrevs_box1';
523 - // Construct some tagging
 523+ # Construct some tagging
524524 $msg = $stable ? 'revreview-' : 'revreview-newest-';
525525 $msg .= $quality ? 'quality' : 'basic';
526526 $msg2 = $stable ? '' : ' '.wfMsg('revreview-oldrating');
@@ -540,7 +540,7 @@
541541 * @returns string
542542 * Generates revision review notes
543543 */
544 - public static function ReviewNotes( $row ) {
 544+ public function ReviewNotes( $row ) {
545545 global $wgUser, $wgFlaggedRevComments;
546546
547547 if( !$row || !$wgFlaggedRevComments )
@@ -559,7 +559,7 @@
560560 * @param Array $flags
561561 * @returns bool, is this revision at quality condition?
562562 */
563 - public static function isQuality( $flags ) {
 563+ public function isQuality( $flags ) {
564564 global $wgFlaggedRevTags;
565565
566566 foreach( $wgFlaggedRevTags as $f => $v ) {
@@ -573,7 +573,7 @@
574574 * @param Array $flags
575575 * @returns bool, is this revision at optimal condition?
576576 */
577 - public static function isPristine( $flags ) {
 577+ public function isPristine( $flags ) {
578578 global $wgFlaggedRevTags, $wgFlaggedRevValues;
579579
580580 foreach( $wgFlaggedRevTags as $f => $v ) {
@@ -588,31 +588,28 @@
589589 * @param Title, $title
590590 * @returns bool
591591 */
592 - public static function isReviewable( $title ) {
 592+ public function isReviewable( $title ) {
593593 global $wgFlaggedRevsNamespaces;
594594
595595 return in_array($title->getNamespace(),$wgFlaggedRevsNamespaces);
596596 }
597597
598 - ######### Hooked functions #########
599 -
600598 /**
601599 * @param Article $article
602600 * @returns ParserOutput
603601 * Get the page cache for the top stable revision of an article
604602 */
605 - public static function getPageCache( $article ) {
 603+ public function getPageCache( $article ) {
606604 global $wgUser, $parserMemc, $wgCacheEpoch, $wgFlaggedRevsExpire;
607605
608 - $fname = 'FlaggedRevs::getPageCache';
609 - wfProfileIn( $fname );
610 -
611 - // Make sure it is valid
612 - if( !$article || !$article->getId() ) return NULL;
 606+ wfProfileIn( __METHOD__ );
 607+ # Make sure it is valid
 608+ if( !$article || !$article->getId() )
 609+ return NULL;
613610
614611 $parserCache =& ParserCache::singleton();
615612 $key = 'sv-' . $parserCache->getKey( $article, $wgUser );
616 - // Get the cached HTML
 613+ # Get the cached HTML
617614 wfDebug( "Trying parser cache $key\n" );
618615 $value = $parserMemc->get( $key );
619616 if( is_object( $value ) ) {
@@ -653,38 +650,153 @@
654651 * @param parerOutput $parserOut
655652 * Updates the stable cache of a page with the given $parserOut
656653 */
657 - public static function updatePageCache( $article, $parserOut=NULL ) {
 654+ public function updatePageCache( $article, $parserOut=NULL ) {
658655 global $wgUser, $parserMemc, $wgFlaggedRevsExpire;
659 - // Make sure it is valid
660 - if( is_null($parserOut) || !$article ) return false;
661 -
662 - // Update the cache...
 656+ # Make sure it is valid
 657+ if( is_null($parserOut) || !$article )
 658+ return false;
 659+ # Update the cache...
663660 $article->mTitle->invalidateCache();
664661
665662 $parserCache =& ParserCache::singleton();
666663 $key = 'sv-' . $parserCache->getKey( $article, $wgUser );
667 - // Add cache mark to HTML
 664+ # Add cache mark to HTML
668665 $now = wfTimestampNow();
669666 $parserOut->setCacheTime( $now );
670 -
671 - // Save the timestamp so that we don't have to load the revision row on view
 667+ # Save the timestamp so that we don't have to load the revision row on view
672668 $parserOut->mTimestamp = $article->getTimestamp();
673 -
674669 $parserOut->mText .= "\n<!-- Saved in stable version parser cache with key $key and timestamp $now -->";
675 - // Set expire time
 670+ # Set expire time
676671 if( $parserOut->containsOldMagic() ){
677672 $expire = 3600; # 1 hour
678673 } else {
679674 $expire = $wgFlaggedRevsExpire;
680675 }
681 - // Save to objectcache
 676+ # Save to objectcache
682677 $parserMemc->set( $key, $parserOut, $expire );
683 - // Purge squid for this page only
 678+ # Purge squid for this page only
684679 $article->mTitle->purgeSquid();
685680
686681 return true;
687682 }
688683
 684+ /**
 685+ * Automatically review an edit and add a log entry in the review log.
 686+ * LinksUpdate was already called via edit operations, so the page
 687+ * fields will be up to date. This updates the stable version.
 688+ */
 689+ public function autoReviewEdit( $article, $user, $text, $rev, $flags ) {
 690+ global $wgParser, $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
 691+
 692+ $quality = 0;
 693+ if( $wgFlaggedRevs->isQuality($flags) ) {
 694+ $quality = $wgFlaggedRevs->isPristine($flags) ? 2 : 1;
 695+ }
 696+ $flagset = $tmpset = $imgset = array();
 697+ foreach( $flags as $tag => $value ) {
 698+ $flagset[] = array(
 699+ 'frt_rev_id' => $rev->getId(),
 700+ 'frt_dimension' => $tag,
 701+ 'frt_value' => $value
 702+ );
 703+ }
 704+ # Try the parser cache, should be set on the edit before this is called.
 705+ # If not set or up to date, then parse it...
 706+ $parserCache =& ParserCache::singleton();
 707+ $poutput = $parserCache->get( $article, $user );
 708+ if( $poutput==false ) {
 709+ $options = ParserOptions::newFromUser($user);
 710+ $options->setTidy(true);
 711+ $poutput = $wgParser->parse( $text, $article->mTitle, $options, true, true, $rev->getID() );
 712+ # Might as well save the cache while we're at it
 713+ $parserCache->save( $poutput, $article, $user );
 714+ }
 715+ # NS:title -> rev ID mapping
 716+ foreach( $poutput->mTemplateIds as $namespace => $title ) {
 717+ foreach( $title as $dbkey => $id ) {
 718+ $tmpset[] = array(
 719+ 'ft_rev_id' => $rev->getId(),
 720+ 'ft_namespace' => $namespace,
 721+ 'ft_title' => $dbkey,
 722+ 'ft_tmp_rev_id' => $id
 723+ );
 724+ }
 725+ }
 726+ # Image -> timestamp mapping
 727+ foreach( $poutput->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) {
 728+ foreach( $timeAndSHA1 as $time => $sha1 ) {
 729+ $imgset[] = array(
 730+ 'fi_rev_id' => $rev->getId(),
 731+ 'fi_name' => $dbkey,
 732+ 'fi_img_timestamp' => $time,
 733+ 'fi_img_sha1' => $sha1
 734+ );
 735+ }
 736+ }
 737+
 738+ $dbw = wfGetDB( DB_MASTER );
 739+ $dbw->begin();
 740+ # Update our versioning pointers
 741+ if( !empty( $tmpset ) ) {
 742+ $dbw->replace( 'flaggedtemplates',
 743+ array( array('ft_rev_id','ft_namespace','ft_title') ), $tmpset,
 744+ __METHOD__ );
 745+ }
 746+ if( !empty( $imgset ) ) {
 747+ $dbw->replace( 'flaggedimages',
 748+ array( array('fi_rev_id','fi_name') ), $imgset,
 749+ __METHOD__ );
 750+ }
 751+ # Get the page text and resolve all templates
 752+ list($fulltext,$complete) = $wgFlaggedRevs->expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
 753+ if( !$complete ) {
 754+ $dbw->rollback(); // All versions must be specified, 0 for none
 755+ return false;
 756+ }
 757+ # Compress $fulltext, passed by reference
 758+ $textFlags = self::compressText( $fulltext );
 759+ # Our review entry
 760+ $revisionset = array(
 761+ 'fr_rev_id' => $rev->getId(),
 762+ 'fr_namespace' => $rev->getTitle()->getNamespace(),
 763+ 'fr_title' => $rev->getTitle()->getDBkey(),
 764+ 'fr_user' => $user->getId(),
 765+ 'fr_timestamp' => wfTimestampNow(),
 766+ 'fr_comment' => '',
 767+ 'fr_quality' => $quality,
 768+ 'fr_text' => $fulltext, // Store expanded text for speed
 769+ 'fr_flags' => $textFlags
 770+ );
 771+ # Update flagged revisions table
 772+ $dbw->replace( 'flaggedrevs',
 773+ array( array('fr_rev_id','fr_namespace','fr_title') ), $revisionset,
 774+ __METHOD__ );
 775+ # Set all of our flags
 776+ $dbw->replace( 'flaggedrevtags',
 777+ array( array('frt_rev_id','frt_dimension') ), $flagset,
 778+ __METHOD__ );
 779+ # Mark as patrolled
 780+ $dbw->update( 'recentchanges',
 781+ array( 'rc_patrolled' => 1 ),
 782+ array( 'rc_this_oldid' => $rev->getId() ),
 783+ __METHOD__
 784+ );
 785+ $dbw->commit();
 786+
 787+ # Update the article review log
 788+ Revisionreview::updateLog( $rev->getTitle(), $flags, wfMsg('revreview-auto'),
 789+ $rev->getID(), true, false );
 790+
 791+ # Might as well save the stable version cache
 792+ $wgFlaggedRevs->updatePageCache( $article, $poutput );
 793+ # Update page fields
 794+ $wgFlaggedRevs->updateArticleOn( $article, $rev->getID() );
 795+ # Purge squid for this page only
 796+ $article->mTitle->purgeSquid();
 797+
 798+ return true;
 799+ }
 800+
689801 /**
690802 * @param Article $article
691803 * @param Integer $rev_id, the stable version rev_id
@@ -700,7 +812,7 @@
701813 __METHOD__ );
702814 }
703815
704 - public static function updateFromMove( $movePageForm, $oldtitle, $newtitle ) {
 816+ public function updateFromMove( $movePageForm, $oldtitle, $newtitle ) {
705817 $dbw = wfGetDB( DB_MASTER );
706818 $dbw->update( 'flaggedrevs',
707819 array('fr_namespace' => $newtitle->getNamespace(), 'fr_title' => $newtitle->getDBkey() ),
@@ -711,12 +823,12 @@
712824 }
713825
714826 /**
715 - * Clears cache for a page when delete is used
 827+ * Clears cache for a page when merges are done.
 828+ * We may have lost the stable revision to another page.
716829 */
717 - public static function articleLinksUpdate( $article, $a=null, $b=null ) {
 830+ public function articleLinksUpdate( $article, $a=null, $b=null ) {
718831 global $wgUser, $wgParser;
719 -
720 - // Update the links tables as the stable version may now be the default page...
 832+ # Update the links tables as the stable version may now be the default page...
721833 $parserCache =& ParserCache::singleton();
722834 $poutput = $parserCache->get( $article, $wgUser );
723835 if( $poutput==false ) {
@@ -734,11 +846,11 @@
735847 /**
736848 * Clears cache for a page when revisiondelete/undelete is used
737849 */
738 - public static function articleLinksUpdate2( $title, $a=null, $b=null ) {
 850+ public function articleLinksUpdate2( $title, $a=null, $b=null ) {
739851 global $wgUser, $wgParser;
740852
741853 $article = new Article( $title );
742 - // Update the links tables as the stable version may now be the default page...
 854+ # Update the links tables as the stable version may now be the default page...
743855 $parserCache =& ParserCache::singleton();
744856 $poutput = $parserCache->get( $article, $wgUser );
745857 if( $poutput==false ) {
@@ -756,13 +868,12 @@
757869 /**
758870 * Inject stable links on LinksUpdate
759871 */
760 - public static function extraLinksUpdate( $linksUpdate ) {
 872+ public function extraLinksUpdate( $linksUpdate ) {
761873 global $wgFlaggedRevs;
762 -
763 - $fname = 'FlaggedRevs::extraLinksUpdate';
764 - wfProfileIn( $fname );
 874+
 875+ wfProfileIn( __METHOD__ );
765876
766 - if( !FlaggedRevs::isReviewable( $linksUpdate->mTitle ) )
 877+ if( !$wgFlaggedRevs->isReviewable( $linksUpdate->mTitle ) )
767878 return true;
768879 # Check if this page has a stable version
769880 $sv = $wgFlaggedRevs->getOverridingRev( $linksUpdate->mTitle, true, true );
@@ -773,9 +884,9 @@
774885 $text = self::uncompressText( $sv->fr_text, $sv->fr_flags );
775886 $parserOut = self::parseStableText( $article, $text, $sv->fr_rev_id );
776887 # Might as well update the stable cache while we're at it
777 - FlaggedRevs::updatePageCache( $article, $parserOut );
 888+ $wgFlaggedRevs->updatePageCache( $article, $parserOut );
778889 # Update page fields
779 - FlaggedRevs::updateArticleOn( $article, $sv->fr_rev_id );
 890+ $wgFlaggedRevs->updateArticleOn( $article, $sv->fr_rev_id );
780891 # Update the links tables to include these
781892 # We want the UNION of links between the current
782893 # and stable version. Therefore, we only care about
@@ -800,11 +911,11 @@
801912 * Select the desired templates based on the selected stable revision IDs
802913 */
803914 static function parserFetchStableTemplate( $parser, $title, &$skip, &$id ) {
804 - // Trigger for stable version parsing only
 915+ # Trigger for stable version parsing only
805916 if( !isset($parser->isStable) || !$parser->isStable )
806917 return true;
807 - // Only called to make fr_text, right after template/image specifiers
808 - // are added to the DB. Slaves may not have it yet...
 918+ # Only called to make fr_text, right after template/image specifiers
 919+ # are added to the DB. Slaves may not have it yet...
809920 $dbw = wfGetDB( DB_MASTER );
810921 $id = $dbw->selectField('flaggedtemplates', 'ft_tmp_rev_id',
811922 array('ft_rev_id' => $parser->mRevisionId,
@@ -824,11 +935,11 @@
825936 * Select the desired images based on the selected stable revision times/SHA-1s
826937 */
827938 static function parserMakeStableImageLink( $parser, $nt, &$skip, &$time ) {
828 - // Trigger for stable version parsing only
 939+ # Trigger for stable version parsing only
829940 if( !isset($parser->isStable) || !$parser->isStable )
830941 return true;
831 - // Only called to make fr_text, right after template/image specifiers
832 - // are added to the DB. Slaves may not have it yet...
 942+ # Only called to make fr_text, right after template/image specifiers
 943+ # are added to the DB. Slaves may not have it yet...
833944 $dbw = wfGetDB( DB_MASTER );
834945 $time = $dbw->selectField('flaggedimages', 'fi_img_timestamp',
835946 array('fi_rev_id' => $parser->mRevisionId, 'fi_name' => $nt->getDBkey() ),
@@ -847,10 +958,10 @@
848959 * Select the desired images based on the selected stable revision times/SHA-1s
849960 */
850961 static function galleryFindStableFileTime( $ig, $nt, &$time ) {
851 - // Trigger for stable version parsing only
 962+ # Trigger for stable version parsing only
852963 if( !isset($ig->isStable) || !$ig->isStable )
853964 return true;
854 - // Slaves may not have it yet...
 965+ # Slaves may not have it yet...
855966 $dbr = wfGetDB( DB_MASTER );
856967 $time = $dbr->selectField('flaggedimages', 'fi_img_timestamp',
857968 array('fi_rev_id' => $ig->mRevisionId, 'fi_name' => $nt->getDBkey() ),
@@ -864,7 +975,7 @@
865976 * Flag of an image galley as stable
866977 */
867978 static function parserMakeGalleryStable( $parser, $ig ) {
868 - // Trigger for stable version parsing only
 979+ # Trigger for stable version parsing only
869980 if( !isset($parser->isStable) || !$parser->isStable )
870981 return true;
871982
@@ -906,8 +1017,8 @@
9071018 * Redirect users out to review the changes to the stable version.
9081019 * Only for people who can review and for pages that have a stable version.
9091020 */
910 - public static function injectReviewDiffURLParams( $article, &$sectionanchor, &$extraq ) {
911 - global $wgReviewChangesAfterEdit, $wgFlaggedRevs, $wgUser;
 1021+ public function injectReviewDiffURLParams( $article, &$sectionanchor, &$extraq ) {
 1022+ global $wgUser, $wgReviewChangesAfterEdit, $wgFlaggedRevs;
9121023 # Was this already autoreviewed?
9131024 if( $wgFlaggedRevs->skipReviewDiff )
9141025 return true;
@@ -929,7 +1040,7 @@
9301041 * When comparing the stable revision to the current after editing a page, show
9311042 * a tag with some explaination for the diff.
9321043 */
933 - public static function addDiffNoticeAfterEdit( $diff, $OldRev, $NewRev ) {
 1044+ public function addDiffNoticeAfterEdit( $diff, $OldRev, $NewRev ) {
9341045 global $wgRequest, $wgUser, $wgOut, $wgFlaggedRevs;
9351046
9361047 if( !$wgUser->isAllowed( 'review') || !$wgRequest->getBool('editreview') || !$NewRev->isCurrent() )
@@ -956,8 +1067,8 @@
9571068 * When an edit is made by a reviwer, if the current revision is the stable
9581069 * version, try to automatically review it.
9591070 */
960 - public static function maybeMakeEditReviewed( $article, $user, $text, $c, $m, $a, $b, $flags, $rev ) {
961 - global $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
 1071+ public function maybeMakeEditReviewed( $article, $user, $text, $c, $m, $a, $b, $flags, $rev ) {
 1072+ global $wgFlaggedRevs, $wgFlaggedRevsAutoReview;
9621073
9631074 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed( 'review' ) )
9641075 return true;
@@ -994,8 +1105,8 @@
9951106 /**
9961107 * When a new page is made by a reviwer, try to automatically review it.
9971108 */
998 - public static function maybeMakeNewPageReviewed( $article, $user, $text, $c, $flags, $a, $b, $flags, $rev ) {
999 - global $wgFlaggedRevsAutoReviewNew, $wgFlaggedRevs;
 1109+ public function maybeMakeNewPageReviewed( $article, $user, $text, $c, $flags, $a, $b, $flags, $rev ) {
 1110+ global $wgFlaggedRevs, $wgFlaggedRevsAutoReviewNew;
10001111
10011112 if( !$wgFlaggedRevsAutoReviewNew || !$user->isAllowed( 'review' ) )
10021113 return true;
@@ -1015,122 +1126,12 @@
10161127
10171128 return true;
10181129 }
1019 -
1020 - /**
1021 - * Automatically review an edit and add a log entry in the review log.
1022 - * LinksUpdate was already called via edit operations, so the page
1023 - * fields will be up to date. This updates the stable version.
1024 - */
1025 - public static function autoReviewEdit( $article, $user, $text, $rev, $flags ) {
1026 - global $wgParser, $wgFlaggedRevsAutoReview, $wgFlaggedRevs;
1027 -
1028 - $quality = 0;
1029 - if( FlaggedRevs::isQuality($flags) ) {
1030 - $quality = FlaggedRevs::isPristine($flags) ? 2 : 1;
1031 - }
1032 - $flagset = $tmpset = $imgset = array();
1033 - foreach( $flags as $tag => $value ) {
1034 - $flagset[] = array(
1035 - 'frt_rev_id' => $rev->getId(),
1036 - 'frt_dimension' => $tag,
1037 - 'frt_value' => $value
1038 - );
1039 - }
1040 - # Try the parser cache, should be set on the edit before this is called.
1041 - # If not set or up to date, then parse it...
1042 - $parserCache =& ParserCache::singleton();
1043 - $poutput = $parserCache->get( $article, $user );
1044 - if( $poutput==false ) {
1045 - $options = ParserOptions::newFromUser($user);
1046 - $options->setTidy(true);
1047 - $poutput = $wgParser->parse( $text, $article->mTitle, $options, true, true, $rev->getID() );
1048 - # Might as well save the cache while we're at it
1049 - $parserCache->save( $poutput, $article, $user );
1050 - }
1051 - # NS:title -> rev ID mapping
1052 - foreach( $poutput->mTemplateIds as $namespace => $title ) {
1053 - foreach( $title as $dbkey => $id ) {
1054 - $tmpset[] = array(
1055 - 'ft_rev_id' => $rev->getId(),
1056 - 'ft_namespace' => $namespace,
1057 - 'ft_title' => $dbkey,
1058 - 'ft_tmp_rev_id' => $id
1059 - );
1060 - }
1061 - }
1062 - # Image -> timestamp mapping
1063 - foreach( $poutput->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) {
1064 - foreach( $timeAndSHA1 as $time => $sha1 ) {
1065 - $imgset[] = array(
1066 - 'fi_rev_id' => $rev->getId(),
1067 - 'fi_name' => $dbkey,
1068 - 'fi_img_timestamp' => $time,
1069 - 'fi_img_sha1' => $sha1
1070 - );
1071 - }
1072 - }
1073 -
1074 - $dbw = wfGetDB( DB_MASTER );
1075 - $dbw->begin();
1076 - # Update our versioning pointers
1077 - if( !empty( $tmpset ) ) {
1078 - $dbw->replace( 'flaggedtemplates', array( array('ft_rev_id','ft_namespace','ft_title') ), $tmpset,
1079 - __METHOD__ );
1080 - }
1081 - if( !empty( $imgset ) ) {
1082 - $dbw->replace( 'flaggedimages', array( array('fi_rev_id','fi_name') ), $imgset,
1083 - __METHOD__ );
1084 - }
1085 - # Get the page text and resolve all templates
1086 - list($fulltext,$complete) = FlaggedRevs::expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
1087 - if( !$complete ) {
1088 - $dbw->rollback(); // All versions must be specified, 0 for none
1089 - return false;
1090 - }
1091 - # Compress $fulltext, passed by reference
1092 - $textFlags = self::compressText( $fulltext );
1093 - # Our review entry
1094 - $revset = array(
1095 - 'fr_rev_id' => $rev->getId(),
1096 - 'fr_namespace' => $rev->getTitle()->getNamespace(),
1097 - 'fr_title' => $rev->getTitle()->getDBkey(),
1098 - 'fr_user' => $user->getId(),
1099 - 'fr_timestamp' => wfTimestampNow(),
1100 - 'fr_comment' => '',
1101 - 'fr_quality' => $quality,
1102 - 'fr_text' => $fulltext, // Store expanded text for speed
1103 - 'fr_flags' => $textFlags
1104 - );
1105 - # Update flagged revisions table
1106 - $dbw->replace( 'flaggedrevs', array( array('fr_rev_id','fr_namespace','fr_title') ), $revset, __METHOD__ );
1107 - # Set all of our flags
1108 - $dbw->replace( 'flaggedrevtags', array( array('frt_rev_id','frt_dimension') ), $flagset, __METHOD__ );
1109 - # Mark as patrolled
1110 - $dbw->update( 'recentchanges',
1111 - array( 'rc_patrolled' => 1 ),
1112 - array( 'rc_this_oldid' => $rev->getId() ),
1113 - __METHOD__
1114 - );
1115 - $dbw->commit();
1116 -
1117 - # Update the article review log
1118 - Revisionreview::updateLog( $rev->getTitle(), $flags, wfMsg('revreview-auto'), $rev->getID(), true, false );
1119 -
1120 - # Might as well save the stable cache
1121 - $wgFlaggedRevs->updatePageCache( $article, $poutput );
1122 - # Update page fields
1123 - FlaggedRevs::updateArticleOn( $article, $rev->getID() );
1124 - # Purge squid for this page only
1125 - $article->mTitle->purgeSquid();
1126 -
1127 - return true;
1128 - }
11291130
11301131 /**
11311132 * Callback that autopromotes user according to the setting in
11321133 * $wgFlaggedRevsAutopromote. This is not as efficient as it should be
11331134 */
1134 - public static function autoPromoteUser( $article, $user, &$text, &$summary, &$isminor, &$iswatch, &$section ) {
 1135+ public function autoPromoteUser( $article, $user, &$text, &$summary, &$isminor, &$iswatch, &$section ) {
11351136 global $wgUser, $wgFlaggedRevsAutopromote;
11361137
11371138 if( !$wgFlaggedRevsAutopromote )
@@ -1208,32 +1209,30 @@
12091210 /**
12101211 * Updates parser cache output to included needed versioning params.
12111212 */
1212 - public static function maybeUpdateMainCache( $article, &$outputDone, &$pcache ) {
1213 - global $wgUser, $action;
1214 - // Only trigger on article view for content pages, not for protect/delete/hist
 1213+ public function maybeUpdateMainCache( $article, &$outputDone, &$pcache ) {
 1214+ global $wgUser, $action, $wgFlaggedRevs;
 1215+ # Only trigger on article view for content pages, not for protect/delete/hist
12151216 if( $action !='view' || !$wgUser->isAllowed( 'review' ) )
12161217 return true;
1217 - if( !$article || !$article->exists() || !FlaggedRevs::isReviewable( $article->mTitle ) )
 1218+ if( !$article || !$article->exists() || !$wgFlaggedRevs->isReviewable( $article->mTitle ) )
12181219 return true;
12191220
12201221 $parserCache =& ParserCache::singleton();
12211222 $parserOut = $parserCache->get( $article, $wgUser );
12221223 if( $parserOut ) {
1223 - // Clear older, incomplete, cached versions
1224 - // We need the IDs of templates and timestamps of images used
 1224+ # Clear older, incomplete, cached versions
 1225+ # We need the IDs of templates and timestamps of images used
12251226 if( !isset($parserOut->mTemplateIds) || !isset($parserOut->mImageSHA1Keys) )
12261227 $article->mTitle->invalidateCache();
12271228 }
12281229 return true;
12291230 }
12301231
1231 - #########
1232 -
12331232 ######### Stub functions, overridden by subclass #########
12341233
12351234 static function pageOverride() { return false; }
12361235
1237 - function setPageContent( $article, $outputDone, &$pcache ) {}
 1236+ function setPageContent( $article, &$outputDone, &$pcache ) {}
12381237
12391238 function addToEditView( $editform ) {}
12401239
@@ -1263,9 +1262,10 @@
12641263 * for overriding by stable revisions?
12651264 */
12661265 static function pageOverride() {
1267 - global $wgTitle, $wgFlaggedRevsAnonOnly, $wgFlaggedRevsOverride, $wgUser, $wgRequest, $action;
 1266+ global $wgFlaggedRevsAnonOnly, $wgFlaggedRevsOverride, $wgFlaggedRevs,
 1267+ $wgTitle, $wgUser, $wgRequest, $action;
12681268 # This only applies to viewing content pages
1269 - if( $action !='view' || !FlaggedRevs::isReviewable( $wgTitle ) )
 1269+ if( $action !='view' || !$wgFlaggedRevs->isReviewable( $wgTitle ) )
12701270 return;
12711271 # Does not apply to diffs/old revisions
12721272 if( $wgRequest->getVal('oldid') || $wgRequest->getVal('diff') )
@@ -1289,9 +1289,9 @@
12901290 * Adds a quick review form on the bottom if needed
12911291 */
12921292 function setPageContent( $article, &$outputDone, &$pcache ) {
1293 - global $wgRequest, $wgTitle, $wgOut, $action, $wgUser;
 1293+ global $wgRequest, $wgTitle, $wgOut, $action, $wgUser, $wgFlaggedRevs;
12941294 // Only trigger on article view for content pages, not for protect/delete/hist
1295 - if( $action !='view' || !$article || !$article->exists() || !FlaggedRevs::isReviewable( $article->mTitle ) )
 1295+ if( $action !='view' || !$article || !$article->exists() || !$wgFlaggedRevs->isReviewable( $article->mTitle ) )
12961296 return true;
12971297 // Grab page and rev ids
12981298 $pageid = $article->getId();
@@ -1303,7 +1303,7 @@
13041304
13051305 $vis_id = $revid;
13061306 $tag = ''; $notes = '';
1307 - // Check the newest stable version...
 1307+ # Check the newest stable version...
13081308 $tfrev = $this->getOverridingRev();
13091309 $simpleTag = false;
13101310 if( $wgRequest->getVal('diff') || $wgRequest->getVal('oldid') ) {
@@ -1313,19 +1313,19 @@
13141314 # Get flags and date
13151315 $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
13161316 # Get quality level
1317 - $quality = parent::isQuality( $flags );
1318 - $pristine = parent::isPristine( $flags );
 1317+ $quality = $this->isQuality( $flags );
 1318+ $pristine = $this->isPristine( $flags );
13191319 $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
13201320 # Looking at some specific old rev or if flagged revs override only for anons
13211321 if( !$this->pageOverride() ) {
1322 - $revs_since = parent::getRevCountSince( $pageid, $tfrev->fr_rev_id );
 1322+ $revs_since = $this->getRevCountSince( $pageid, $tfrev->fr_rev_id );
13231323 $simpleTag = true;
13241324 # Construct some tagging
13251325 if( !$wgOut->isPrintable() ) {
13261326 if( $this->useSimpleUI() ) {
13271327 $msg = $quality ? 'revreview-quick-see-quality' : 'revreview-quick-see-basic';
13281328 $tag .= "<span class='fr_tab_current plainlinks'></span>" . wfMsgExt($msg,array('parseinline'));
1329 - $tag .= parent::prettyRatingBox( $tfrev, $flags, $revs_since, false );
 1329+ $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since, false );
13301330 } else {
13311331 $msg = $quality ? 'revreview-newest-quality' : 'revreview-newest-basic';
13321332 $tag .= wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since);
@@ -1333,39 +1333,39 @@
13341334 $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
13351335 wfMsg('revreview-toggle') . '</a>';
13361336 $tag .= '<span id="mw-revisionratings" style="display:block;">' .
1337 - wfMsg('revreview-oldrating') . parent::addTagRatings( $flags ) . '</span>';
 1337+ wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) . '</span>';
13381338 }
13391339 }
1340 - # Viewing the page normally: override the page
 1340+ // Viewing the page normally: override the page
13411341 } else {
13421342 # We will be looking at the reviewed revision...
13431343 $vis_id = $tfrev->fr_rev_id;
1344 - $revs_since = parent::getRevCountSince( $pageid, $vis_id );
1345 - // Construct some tagging
 1344+ $revs_since = $this->getRevCountSince( $pageid, $vis_id );
 1345+ # Construct some tagging
13461346 if( !$wgOut->isPrintable() ) {
13471347 if( $this->useSimpleUI() ) {
13481348 $msg = $quality ? 'revreview-quick-quality' : 'revreview-quick-basic';
13491349 $css = $quality ? 'fr_tab_quality' : 'fr_tab_stable';
13501350 $tag .= "<span class='$css plainlinks'></span>" .
13511351 wfMsgExt($msg,array('parseinline'),$tfrev->fr_rev_id,$revs_since);
1352 - $tag .= parent::prettyRatingBox( $tfrev, $flags, $revs_since );
 1352+ $tag .= $this->prettyRatingBox( $tfrev, $flags, $revs_since );
13531353 } else {
13541354 $msg = $quality ? 'revreview-quality' : 'revreview-basic';
13551355 $tag = wfMsgExt($msg, array('parseinline'), $vis_id, $time, $revs_since);
13561356 $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
13571357 wfMsg('revreview-toggle') . '</a>';
13581358 $tag .= '<span id="mw-revisionratings" style="display:block;">' .
1359 - parent::addTagRatings( $flags ) . '</span>';
 1359+ $this->addTagRatings( $flags ) . '</span>';
13601360 }
13611361 }
13621362 # Try the stable page cache
1363 - $parserOut = parent::getPageCache( $article );
 1363+ $parserOut = $this->getPageCache( $article );
13641364 # If no cache is available, get the text and parse it
13651365 if( $parserOut==false ) {
1366 - $text = parent::getFlaggedRevText( $vis_id );
1367 - $parserOut = parent::parseStableText( $article, $text, $vis_id );
 1366+ $text = $this->getFlaggedRevText( $vis_id );
 1367+ $parserOut = $this->parseStableText( $article, $text, $vis_id );
13681368 # Update the general cache
1369 - parent::updatePageCache( $article, $parserOut );
 1369+ $this->updatePageCache( $article, $parserOut );
13701370 }
13711371 $wgOut->mBodytext = $parserOut->getText();
13721372 # Show stable categories and interwiki links only
@@ -1373,12 +1373,12 @@
13741374 $wgOut->addCategoryLinks( $parserOut->getCategories() );
13751375 $wgOut->mLanguageLinks = array();
13761376 $wgOut->addLanguageLinks( $parserOut->getLanguageLinks() );
1377 - $notes = parent::ReviewNotes( $tfrev );
 1377+ $notes = $this->ReviewNotes( $tfrev );
13781378 # Tell MW that parser output is done
13791379 $outputDone = true;
13801380 $pcache = false;
13811381 }
1382 - // Some checks for which tag CSS to use
 1382+ # Some checks for which tag CSS to use
13831383 if( $this->useSimpleUI() )
13841384 $tagClass = 'flaggedrevs_short';
13851385 else if( $simpleTag )
@@ -1389,13 +1389,13 @@
13901390 $tagClass = 'flaggedrevs_tag2';
13911391 else
13921392 $tagClass = 'flaggedrevs_tag1';
1393 - // Wrap tag contents in a div
 1393+ # Wrap tag contents in a div
13941394 if( $tag !='' )
13951395 $tag = '<div id="mw-revisiontag" class="' . $tagClass . ' plainlinks">'.$tag.'</div>';
1396 - // Set the new body HTML, place a tag on top
 1396+ # Set the new body HTML, place a tag on top
13971397 $wgOut->mBodytext = $tag . $wgOut->mBodytext . $notes;
13981398 // Add "no reviewed version" tag, but not for main page
1399 - } else if( !$wgOut->isPrintable() && !parent::isMainPage( $article->mTitle ) ) {
 1399+ } else if( !$wgOut->isPrintable() && !$this->isMainPage( $article->mTitle ) ) {
14001400 if( $this->useSimpleUI() ) {
14011401 $tag .= "<span class='fr_tab_current plainlinks'></span>" .
14021402 wfMsgExt('revreview-quick-none',array('parseinline'));
@@ -1410,40 +1410,40 @@
14111411 }
14121412
14131413 function addToEditView( $editform ) {
1414 - global $wgRequest, $wgTitle, $wgOut;
1415 - // Talk pages cannot be validated
1416 - if( !$editform->mArticle || !FlaggedRevs::isReviewable( $wgTitle ) )
 1414+ global $wgRequest, $wgTitle, $wgOut, $wgFlaggedRevs;
 1415+ # Talk pages cannot be validated
 1416+ if( !$editform->mArticle || !$wgFlaggedRevs->isReviewable( $wgTitle ) )
14171417 return false;
1418 - // Find out revision id
 1418+ # Find out revision id
14191419 if( $editform->mArticle->mRevision ) {
14201420 $revid = $editform->mArticle->mRevision->mId;
14211421 } else {
14221422 $revid = $editform->mArticle->getLatest();
14231423 }
1424 - // Grab the ratings for this revision if any
 1424+ # Grab the ratings for this revision if any
14251425 if( !$revid )
14261426 return true;
1427 - // Set new body html text as that of now
 1427+ # Set new body html text as that of now
14281428 $tag = '';
1429 - // Check the newest stable version
 1429+ # Check the newest stable version
14301430 $tfrev = $this->getOverridingRev();
14311431 if( is_object($tfrev) ) {
14321432 global $wgLang, $wgUser, $wgFlaggedRevs, $wgFlaggedRevsAutoReview;
14331433
14341434 $time = $wgLang->date( wfTimestamp(TS_MW, $tfrev->fr_timestamp), true );
14351435 $flags = $this->getFlagsForRevision( $tfrev->fr_rev_id );
1436 - $revs_since = parent::getRevCountSince( $editform->mArticle->getID(), $tfrev->fr_rev_id );
 1436+ $revs_since = $this->getRevCountSince( $editform->mArticle->getID(), $tfrev->fr_rev_id );
14371437 # Construct some tagging
1438 - $msg = parent::isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic';
 1438+ $msg = $this->isQuality( $flags ) ? 'revreview-newest-quality' : 'revreview-newest-basic';
14391439 $tag = wfMsgExt($msg, array('parseinline'), $tfrev->fr_rev_id, $time, $revs_since );
14401440 # Hide clutter
14411441 $tag .= ' <a id="mw-revisiontoggle" style="display:none;" href="javascript:toggleRevRatings()">' .
14421442 wfMsg('revreview-toggle') . '</a>';
14431443 $tag .= '<span id="mw-revisionratings" style="display:block;">' .
1444 - wfMsg('revreview-oldrating') . parent::addTagRatings( $flags ) .
 1444+ wfMsg('revreview-oldrating') . $this->addTagRatings( $flags ) .
14451445 '</span>';
14461446 $wgOut->addHTML( '<div id="mw-revisiontag" class="flaggedrevs_notice plainlinks">' . $tag . '</div>' );
1447 - // If this will be autoreviewed, notify the user...
 1447+ # If this will be autoreviewed, notify the user...
14481448 if( !$wgFlaggedRevsAutoReview )
14491449 return true;
14501450 if( $wgUser->isAllowed('review') && $revid==$tfrev->fr_rev_id && $revid==$editform->mArticle->getLatest() ) {
@@ -1464,22 +1464,22 @@
14651465 }
14661466
14671467 function addReviewForm( $out ) {
1468 - global $wgArticle, $wgRequest, $action;
 1468+ global $wgArticle, $wgRequest, $action, $wgFlaggedRevs;
14691469
1470 - if( !$wgArticle || !$wgArticle->exists() || !FlaggedRevs::isReviewable( $wgArticle->mTitle ) )
 1470+ if( !$wgArticle || !$wgArticle->exists() || !$wgFlaggedRevs->isReviewable( $wgArticle->mTitle ) )
14711471 return true;
1472 - // Check if page is protected
 1472+ # Check if page is protected
14731473 if( $action !='view' || !$wgArticle->mTitle->quickUserCan( 'edit' ) ) {
14741474 return true;
14751475 }
1476 - // Get revision ID
 1476+ # Get revision ID
14771477 $revId = $out->mRevisionId ? $out->mRevisionId : $wgArticle->getLatest();
1478 - // We cannot review deleted revisions
 1478+ # We cannot review deleted revisions
14791479 if( is_object($wgArticle->mRevision) && $wgArticle->mRevision->mDeleted )
14801480 return true;
1481 - // Add quick review links IF we did not override, otherwise, they might
1482 - // review a revision that parses out newer templates/images than what they saw.
1483 - // Revisions are always reviewed based on current templates/images.
 1481+ # Add quick review links IF we did not override, otherwise, they might
 1482+ # review a revision that parses out newer templates/images than what they saw.
 1483+ # Revisions are always reviewed based on current templates/images.
14841484 if( $this->pageOverride() ) {
14851485 $tfrev = $this->getOverridingRev();
14861486 if( $tfrev )
@@ -1491,23 +1491,24 @@
14921492 }
14931493
14941494 function setPermaLink( $sktmp, &$nav_urls, &$revid, &$revid ) {
1495 - // Non-content pages cannot be validated
 1495+ global $wgFlaggedRevs;
 1496+ # Non-content pages cannot be validated
14961497 if( !$this->pageOverride() )
14971498 return true;
1498 - // Check for an overridabe revision
 1499+ # Check for an overridabe revision
14991500 $tfrev = $this->getOverridingRev();
15001501 if( !$tfrev )
15011502 return true;
1502 - // Replace "permalink" with an actual permanent link
 1503+ # Replace "permalink" with an actual permanent link
15031504 $nav_urls['permalink'] = array(
15041505 'text' => wfMsg( 'permalink' ),
15051506 'href' => $sktmp->makeSpecialUrl( 'Stableversions', "oldid={$tfrev->fr_rev_id}" )
15061507 );
15071508
15081509 global $wgHooks;
1509 - // Are we using the popular cite extension?
 1510+ # Are we using the popular cite extension?
15101511 if( in_array('wfSpecialCiteNav',$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink']) ) {
1511 - if( FlaggedRevs::isReviewable( $sktmp->mTitle ) && $revid !== 0 ) {
 1512+ if( $wgFlaggedRevs->isReviewable( $sktmp->mTitle ) && $revid !== 0 ) {
15121513 $nav_urls['cite'] = array(
15131514 'text' => wfMsg( 'cite_article_link' ),
15141515 'href' => $sktmp->makeSpecialUrl( 'Cite', "page=" . wfUrlencode( "{$sktmp->thispage}" ) . "&id={$tfrev->fr_rev_id}" )
@@ -1518,20 +1519,20 @@
15191520 }
15201521
15211522 function setCurrentTab( $sktmp, &$content_actions ) {
1522 - global $wgRequest, $wgUser, $action, $wgFlaggedRevsAnonOnly,
 1523+ global $wgRequest, $wgUser, $action, $wgFlaggedRevs, $wgFlaggedRevsAnonOnly,
15231524 $wgFlaggedRevsOverride, $wgFlaggedRevTabs;
1524 - // Get the subject page, not all skins have it :(
 1525+ # Get the subject page, not all skins have it :(
15251526 if( !isset($sktmp->mTitle) )
15261527 return true;
15271528 $title = $sktmp->mTitle->getSubjectPage();
1528 - // Non-content pages cannot be validated
1529 - if( !FlaggedRevs::isReviewable( $title ) || !$title->exists() )
 1529+ # Non-content pages cannot be validated
 1530+ if( !$wgFlaggedRevs->isReviewable( $title ) || !$title->exists() )
15301531 return true;
15311532 $article = new Article( $title );
1532 - // If we are viewing a page normally, and it was overridden,
1533 - // change the edit tab to a "current revision" tab
 1533+ # If we are viewing a page normally, and it was overridden,
 1534+ # change the edit tab to a "current revision" tab
15341535 $tfrev = $this->getOverridingRev();
1535 - // No quality revs? Find the last reviewed one
 1536+ # No quality revs? Find the last reviewed one
15361537 if( !is_object($tfrev) )
15371538 return true;
15381539 /*
@@ -1540,7 +1541,7 @@
15411542 return true;
15421543 }
15431544 */
1544 - // Be clear about what is being edited...
 1545+ # Be clear about what is being edited...
15451546 if( !$sktmp->mTitle->isTalkPage() && !($wgFlaggedRevsAnonOnly && !$wgUser->isAnon()) ) {
15461547 if( isset( $content_actions['edit'] ) )
15471548 $content_actions['edit']['text'] = wfMsg('revreview-edit');
@@ -1551,7 +1552,7 @@
15521553 if( !$wgFlaggedRevTabs ) {
15531554 return true;
15541555 }
1555 - // Note that revisions may not be set to override for users
 1556+ // We are looking at the stable version
15561557 if( $this->pageOverride() ) {
15571558 $new_actions = array(); $counter = 0;
15581559 # Straighten out order
@@ -1646,8 +1647,7 @@
16471648 $rows = $this->getReviewedRevs( $article->getTitle() );
16481649 if( !$rows )
16491650 return true;
1650 - // Try to keep the skin readily accesible,
1651 - // addToHistLine() will use it
 1651+ # Try to keep the skin readily accesible; addToHistLine() will use it
16521652 $this->skin = $wgUser->getSkin();
16531653
16541654 foreach( $rows as $rev => $quality )
@@ -1673,21 +1673,21 @@
16741674 function addQuickReview( $id=NULL, $out, $top=false ) {
16751675 global $wgOut, $wgTitle, $wgUser, $wgRequest,
16761676 $wgFlaggedRevsOverride, $wgFlaggedRevComments, $wgFlaggedRevsWatch;
1677 - // User must have review rights
 1677+ # User must have review rights
16781678 if( !$wgUser->isAllowed( 'review' ) )
16791679 return;
1680 - // Looks ugly when printed
 1680+ # Looks ugly when printed
16811681 if( $out->isPrintable() )
16821682 return;
16831683
16841684 $skin = $wgUser->getSkin();
1685 - // If we are reviewing updates to a page, start off with the stable revision's
1686 - // flags. Otherwise, we just fill them in with the selected revision's flags.
 1685+ # If we are reviewing updates to a page, start off with the stable revision's
 1686+ # flags. Otherwise, we just fill them in with the selected revision's flags.
16871687 if( $this->isDiffFromStable ) {
16881688 $flags = $this->getFlagsForRevision( $wgRequest->getVal('oldid') );
1689 - // Check if user is allowed to renew the stable version.
1690 - // It may perhaps have been reviewed too highly for this user, if so,
1691 - // then get the flags for the new revision itself.
 1689+ # Check if user is allowed to renew the stable version.
 1690+ # It may perhaps have been reviewed too highly for this user, if so,
 1691+ # then get the flags for the new revision itself.
16921692 foreach( $flags as $quality => $level ) {
16931693 if( !Revisionreview::userCan($quality,$level) ) {
16941694 $flags = $this->getFlagsForRevision( $id );
@@ -1716,7 +1716,7 @@
17171717 $options = ''; $disabled = '';
17181718 foreach( $levels as $idx => $label ) {
17191719 $selected = ( $flags[$quality]==$idx || $flags[$quality]==0 && $idx==1 ) ? "selected='selected'" : '';
1720 - // Do not show options user's can't set unless that is the status quo
 1720+ # Do not show options user's can't set unless that is the status quo
17211721 if( !Revisionreview::userCan($quality, $flags[$quality]) ) {
17221722 $disabled = 'disabled = true';
17231723 $options .= "<option value='$idx' $selected>" . wfMsgHtml("revreview-$label") . "</option>\n";
@@ -1738,7 +1738,7 @@
17391739 if( !isset($out->mTemplateIds) || !isset($out->mImageSHA1Keys) ) {
17401740 return; // something went terribly wrong...
17411741 }
1742 - // Hack, add NS:title -> rev ID mapping
 1742+ # Hack, add NS:title -> rev ID mapping
17431743 foreach( $out->mTemplateIds as $namespace => $title ) {
17441744 foreach( $title as $dbkey => $id ) {
17451745 $title = Title::makeTitle( $namespace, $dbkey );
@@ -1746,7 +1746,7 @@
17471747 }
17481748 }
17491749 $form .= Xml::hidden( 'templateParams', $templateParams ) . "\n";
1750 - // Hack, image -> timestamp mapping
 1750+ # Hack, image -> timestamp mapping
17511751 foreach( $out->mImageSHA1Keys as $dbkey => $timeAndSHA1 ) {
17521752 foreach( $timeAndSHA1 as $time => $sha1 ) {
17531753 $imageParams .= $dbkey . "|" . $time . "|" . $sha1 . "#";
@@ -1757,7 +1757,7 @@
17581758 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
17591759 $watchAttribs = array('accesskey' => wfMsg( 'accesskey-watch' ), 'id' => 'wpWatchthis');
17601760 $watchChecked = ( $wgFlaggedRevsWatch && $wgUser->getOption( 'watchdefault' ) || $wgTitle->userIsWatching() );
1761 - // Not much to say unless you are a validator
 1761+ # Not much to say unless you are a validator
17621762 if( $wgUser->isAllowed( 'validate' ) )
17631763 $form .= "<p>".wfInputLabel( wfMsgHtml( 'revreview-log' ), 'wpReason', 'wpReason', 60 )."</p>\n";
17641764
@@ -1781,7 +1781,7 @@
17821782 */
17831783 function getOverridingRev( $title = NULL, $getText=false, $forUpdate=false ) {
17841784 global $wgTitle;
1785 - // Get the content page, skip talk
 1785+ # Get the content page, skip talk
17861786 $title = $wgTitle->getSubjectPage();
17871787
17881788 if( !$forUpdate ) {
@@ -1795,7 +1795,7 @@
17961796 $this->stablerev = $row;
17971797 return $row;
17981798 }
1799 - // Cached results available?
 1799+ # Cached results available?
18001800 if( isset($this->stablefound) ) {
18011801 return ( $this->stablefound ) ? $this->stablerev : null;
18021802 }
@@ -1807,7 +1807,6 @@
18081808 }
18091809
18101810 $dbw = wfGetDB( DB_MASTER );
1811 - // Skip deleted revisions
18121811 $result = $dbw->select( array('page', 'flaggedrevs', 'revision'),
18131812 $selectColumns,
18141813 array('page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey(),
@@ -1815,8 +1814,7 @@
18161815 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
18171816 __METHOD__,
18181817 array('LIMIT' => 1) );
1819 -
1820 - // Do we have one?
 1818+ # Do we have one?
18211819 if( $row = $dbw->fetchObject($result) ) {
18221820 $this->stablefound = true;
18231821 $this->stablerev = $row;
@@ -1838,9 +1836,9 @@
18391837 */
18401838 function getLatestQualityRev( $getText=false ) {
18411839 global $wgTitle;
1842 - // Get the content page, skip talk
 1840+ # Get the content page, skip talk
18431841 $title = $wgTitle->getSubjectPage();
1844 - // Cached results available?
 1842+ # Cached results available?
18451843 if( isset($this->qualityfound) ) {
18461844 return ( $this->qualityfound ) ? $this->qualityrev : null;
18471845 }
@@ -1852,7 +1850,6 @@
18531851 }
18541852
18551853 $dbr = wfGetDB( DB_SLAVE );
1856 - // Skip deleted revisions
18571854 $result = $dbr->select( array('flaggedrevs', 'revision'),
18581855 $selectColumns,
18591856 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(), 'fr_quality >= 1',
@@ -1880,9 +1877,9 @@
18811878 */
18821879 function getLatestStableRev( $getText=false ) {
18831880 global $wgTitle;
1884 - // Get the content page, skip talk
 1881+ # Get the content page, skip talk
18851882 $title = $wgTitle->getSubjectPage();
1886 - // Cached results available?
 1883+ # Cached results available?
18871884 if( isset($this->latestfound) ) {
18881885 return ( $this->latestfound ) ? $this->latestrev : NULL;
18891886 }
@@ -1894,15 +1891,14 @@
18951892 }
18961893
18971894 $dbr = wfGetDB( DB_SLAVE );
1898 - // Skip deleted revisions
18991895 $result = $dbr->select( array('flaggedrevs', 'revision'),
19001896 $selectColumns,
19011897 array('fr_namespace' => $title->getNamespace(), 'fr_title' => $title->getDBkey(),
1902 - 'fr_rev_id = rev_id', 'rev_page' => $title->getArticleID(), 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
 1898+ 'fr_rev_id = rev_id', 'rev_page' => $title->getArticleID(),
 1899+ 'rev_deleted & '.Revision::DELETED_TEXT.' = 0'),
19031900 __METHOD__,
19041901 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
1905 -
1906 - // Do we have one?
 1902+ # Do we have one?
19071903 if( $row = $dbr->fetchObject($result) ) {
19081904 $this->latestfound = true;
19091905 $this->latestrev = $row;
@@ -1919,28 +1915,25 @@
19201916 */
19211917 public function getFlagsForRevision( $rev_id ) {
19221918 global $wgFlaggedRevTags;
1923 -
1924 - // Cached results?
 1919+ # Cached results?
19251920 if( isset($this->flags[$rev_id]) && $this->flags[$rev_id] )
19261921 return $this->revflags[$rev_id];
1927 - // Set all flags to zero
 1922+ # Set all flags to zero
19281923 $flags = array();
19291924 foreach( array_keys($wgFlaggedRevTags) as $tag ) {
19301925 $flags[$tag] = 0;
19311926 }
1932 -
 1927+ # Grab all the tags for this revision
19331928 $dbr = wfGetDB( DB_SLAVE );
1934 - // Grab all the tags for this revision
1935 - $result = $dbr->select('flaggedrevtags',
1936 - array('frt_dimension', 'frt_value'),
1937 - array('frt_rev_id' => $rev_id),
 1929+ $result = $dbr->select( 'flaggedrevtags',
 1930+ array( 'frt_dimension', 'frt_value' ),
 1931+ array( 'frt_rev_id' => $rev_id ),
19381932 __METHOD__ );
1939 -
1940 - // Iterate through each tag result
 1933+ # Iterate through each tag result
19411934 while( $row = $dbr->fetchObject($result) ) {
19421935 $flags[$row->frt_dimension] = $row->frt_value;
19431936 }
1944 - // Try to cache results
 1937+ # Try to cache results
19451938 $this->flags[$rev_id] = true;
19461939 $this->revflags[$rev_id] = $flags;
19471940
@@ -1971,8 +1964,7 @@
19721965 $wgHooks['ArticleSaveComplete'][] = array($wgFlaggedArticle, 'autoPromoteUser');
19731966 # Adds table link references to include ones from the stable version
19741967 $wgHooks['LinksUpdateConstructed'][] = array($wgFlaggedArticle, 'extraLinksUpdate');
1975 -# Check on undelete/delete/revisiondelete for changes to stable version
1976 -$wgHooks['ArticleDeleteComplete'][] = array($wgFlaggedArticle, 'articleLinksUpdate');
 1968+# Check on undelete/merge/revisiondelete for changes to stable version
19771969 $wgHooks['ArticleUndelete'][] = array($wgFlaggedArticle, 'articleLinksUpdate2');
19781970 $wgHooks['ArticleRevisionVisiblitySet'][] = array($wgFlaggedArticle, 'articleLinksUpdate2');
19791971 $wgHooks['ArticleMergeComplete'][] = array($wgFlaggedArticle, 'articleLinksUpdate');
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage_body.php
@@ -41,7 +41,7 @@
4242 $this->oldid = $wgRequest->getIntOrNull( 'oldid' );
4343 // Must be a valid content page
4444 $this->page = Title::newFromUrl( $this->target );
45 - if( !$this->target || !$this->oldid || !FlaggedRevs::isReviewable( $this->page ) ) {
 45+ if( !$this->target || !$this->oldid || !$wgFlaggedRevs->isReviewable( $this->page ) ) {
4646 $wgOut->addHTML( wfMsgExt('revreview-main',array('parse')) );
4747 return;
4848 }
@@ -232,10 +232,9 @@
233233 }
234234
235235 function submit( $request ) {
236 - global $wgOut, $wgUser;
237 -
238 - $approved = false;
 236+ global $wgOut, $wgUser, $wgFlaggedRevs;
239237 # If all values are set to zero, this has been unapproved
 238+ $approved = false;
240239 foreach( $this->dims as $quality => $value ) {
241240 if( $value ) {
242241 $approved = true;
@@ -251,7 +250,7 @@
252251 return;
253252 }
254253 } else {
255 - $frev = FlaggedRevs::getFlaggedRev( $this->oldid );
 254+ $frev = $wgFlaggedRevs->getFlaggedRev( $this->oldid );
256255 // If we can't find this flagged rev, return to page???
257256 if( is_null($frev) ) {
258257 $wgOut->redirect( $this->page->escapeLocalUrl() );
@@ -278,7 +277,7 @@
279278 * Adds or updates the flagged revision table for this page/id set
280279 */
281280 function approveRevision( $rev=NULL, $notes='' ) {
282 - global $wgUser, $wgFlaggedRevsWatch, $wgParser;
 281+ global $wgUser, $wgFlaggedRevsWatch, $wgParser, $wgFlaggedRevs;
283282 // Skip null edits
284283 if( is_null($rev) )
285284 return false;
@@ -286,8 +285,8 @@
287286 $title = $rev->getTitle();
288287
289288 $quality = 0;
290 - if( FlaggedRevs::isQuality($this->dims) ) {
291 - $quality = FlaggedRevs::isPristine($this->dims) ? 2 : 1;
 289+ if( $wgFlaggedRevs->isQuality($this->dims) ) {
 290+ $quality = $wgFlaggedRevs->isPristine($this->dims) ? 2 : 1;
292291 }
293292 // Our flags
294293 $flagset = array();
@@ -361,13 +360,13 @@
362361 __METHOD__ );
363362 }
364363 // Get the page text and resolve all templates
365 - list($fulltext,$complete) = FlaggedRevs::expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
 364+ list($fulltext,$complete) = $wgFlaggedRevs->expandText( $rev->getText(), $rev->getTitle(), $rev->getId() );
366365 if( !$complete ) {
367366 $dbw->rollback(); // All versions must be specified, 0 for none
368367 return false;
369368 }
370369 # Compress $fulltext, passed by reference
371 - $textFlags = FlaggedRevs::compressText( $fulltext );
 370+ $textFlags = $wgFlaggedRevs->compressText( $fulltext );
372371 // Our review entry
373372 $revset = array(
374373 'fr_rev_id' => $rev->getId(),
@@ -559,7 +558,7 @@
560559 function showStableRevision( $frev ) {
561560 global $wgParser, $wgLang, $wgUser, $wgOut, $wgFlaggedRevs;
562561 // Get the revision
563 - $frev = FlaggedRevs::getFlaggedRev( $this->oldid );
 562+ $frev = $wgFlaggedRevs->getFlaggedRev( $this->oldid );
564563 // Revision must exists
565564 if( is_null($frev) ) {
566565 $wgOut->showErrorPage( 'notargettitle', 'revnotfoundtext' );
@@ -592,11 +591,10 @@
593592 }
594593
595594 function showStableList() {
596 - global $wgOut, $wgUser, $wgLang;
597 -
 595+ global $wgOut, $wgUser, $wgLang, $wgFlaggedRevs;
598596 // Must be a valid page/Id
599597 $page = Title::newFromUrl( $this->page );
600 - if( is_null($page) || !FlaggedRevs::isReviewable( $page ) ) {
 598+ if( is_null($page) || !$wgFlaggedRevs->isReviewable( $page ) ) {
601599 $wgOut->showErrorPage('notargettitle', 'allpagesbadtitle' );
602600 return;
603601 }

Status & tagging log