r40722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40721‎ | r40722 | r40723 >
Date:03:12, 11 September 2008
Author:aaron
Status:old
Tags:
Comment:
Revision related code cleanup
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -40,8 +40,10 @@
4141
4242 if( !defined('FR_FOR_UPDATE') )
4343 define('FR_FOR_UPDATE',1);
 44+if( !defined('FR_MASTER') )
 45+ define('FR_MASTER',2);
4446 if( !defined('FR_TEXT') )
45 - define('FR_TEXT',2);
 47+ define('FR_TEXT',3);
4648
4749 if( !defined('READER_FEEDBACK_SIZE') )
4850 define('READER_FEEDBACK_SIZE',30);
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -51,12 +51,19 @@
5252 */
5353 public static function newFromTitle( $title, $revId, $flags = 0 ) {
5454 $columns = self::selectFields();
55 - $options = array();
 55+ # If we want the text, then get the text flags too
5656 if( $flags & FR_TEXT ) {
5757 $columns += self::selectTextFields();
58 - $options[] = 'FOR UPDATE';
5958 }
60 - $db = $flags & FR_FOR_UPDATE ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 59+ $options = array();
 60+ # User master/slave as appropriate
 61+ if( $flags & FR_FOR_UPDATE || $flags & FR_MASTER ) {
 62+ $db = wfGetDB( DB_MASTER );
 63+ if( $flags & FR_FOR_UPDATE )
 64+ $options[] = 'FOR UPDATE';
 65+ } else {
 66+ $db = wfGetDB( DB_SLAVE );
 67+ }
6168 $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? GAID_FOR_UPDATE : 0 );
6269 # Short-circuit query
6370 if( !$pageId ) {
@@ -87,18 +94,18 @@
8895 */
8996 public static function newFromStable( $title, $flags = 0 ) {
9097 $columns = self::selectFields();
91 - $options = array();
 98+ # If we want the text, then get the text flags too
9299 if( $flags & FR_TEXT ) {
93100 $columns += self::selectTextFields();
94 - $options[] = 'FOR UPDATE';
95101 }
 102+ $options = array();
96103 $row = null;
97104 # Short-circuit query
98105 if( !$title->getArticleId() ) {
99106 return $row;
100107 }
101 - # If we want the text, then get the text flags too
102 - if( !($flags & FR_FOR_UPDATE) ) {
 108+ # User master/slave as appropriate
 109+ if( !($flags & FR_FOR_UPDATE) && !($flags & FR_MASTER) ) {
103110 $dbr = wfGetDB( DB_SLAVE );
104111 $row = $dbr->selectRow( array('flaggedpages','flaggedrevs'),
105112 $columns,
@@ -109,10 +116,12 @@
110117 if( !$row )
111118 return null;
112119 } else {
113 - $options['ORDER BY'] = 'fr_rev_id DESC';
 120+ if( $flags & FR_FOR_UPDATE )
 121+ $options[] = 'FOR UPDATE';
114122 # Get visiblity settings...
115 - $config = FlaggedRevs::getPageVisibilitySettings( $title, $flags & FR_FOR_UPDATE );
 123+ $config = FlaggedRevs::getPageVisibilitySettings( $title, true );
116124 $dbw = wfGetDB( DB_MASTER );
 125+ $options['ORDER BY'] = 'fr_rev_id DESC';
117126 # Look for the latest pristine revision...
118127 if( FlaggedRevs::pristineVersions() && $config['select'] != FLAGGED_VIS_LATEST ) {
119128 $prow = $dbw->selectRow( array('flaggedrevs','revision'),
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -630,6 +630,8 @@
631631 $user = User::newFromId( $rev->getUser() );
632632 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
633633 return true;
 634+ # If $baseRevId passed in, this is a null edit
 635+ $isNullEdit = $baseRevId ? true : false;
634636 # Must be in reviewable namespace
635637 $title = $article->getTitle();
636638 if( !FlaggedRevs::isPageReviewable( $title ) ) {
@@ -666,19 +668,23 @@
667669 $reviewableNewPage = (bool)$wgFlaggedRevsAutoReviewNew;
668670 // Edits to existing pages
669671 } else if( $baseRevId ) {
670 - $frev = FlaggedRevision::newFromTitle( $title, $baseRevId, FR_FOR_UPDATE );
 672+ $frev = FlaggedRevision::newFromTitle( $title, $baseRevId, FR_MASTER );
671673 # If the base revision was not reviewed, check if the previous one was.
672674 # This should catch null edits as well as normal ones.
673675 if( !$frev ) {
674 - $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_FOR_UPDATE );
 676+ $frev = FlaggedRevision::newFromTitle( $title, $prevRevId, FR_MASTER );
675677 }
676678 }
677679 # Is this an edit directly to the stable version?
678680 if( $reviewableNewPage || !is_null($frev) ) {
679 - # Assume basic flagging level
680 - $flags = array();
681 - foreach( FlaggedRevs::getDimensions() as $tag => $minQL ) {
682 - $flags[$tag] = 1;
 681+ # Assume basic flagging level unless this is a null edit
 682+ if( $isNullEdit ) {
 683+ $flags = $frev->getTags();
 684+ } else {
 685+ $flags = array();
 686+ foreach( FlaggedRevs::getDimensions() as $tag => $minQL ) {
 687+ $flags[$tag] = 1;
 688+ }
683689 }
684690 # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
685691 FlaggedRevs::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags, false );