r38233 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38232‎ | r38233 | r38234 >
Date:12:30, 30 July 2008
Author:aaron
Status:old
Tags:
Comment:
Refactor some code to look better
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -37,6 +37,11 @@
3838 # Pristine -> Quality -> Sighted
3939 if( !defined('FLAGGED_VIS_PRISTINE') )
4040 define('FLAGGED_VIS_PRISTINE',2);
 41+
 42+if( !defined('FR_FOR_UPDATE') )
 43+ define('FR_FOR_UPDATE',1);
 44+if( !defined('FR_TEXT') )
 45+ define('FR_TEXT',2);
4146
4247 $wgExtensionCredits['specialpage'][] = array(
4348 'name' => 'Flagged Revisions',
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -207,7 +207,7 @@
208208 $simpleTag = $old = $stable = false;
209209 $tag = $prot = $notes = $pending = '';
210210 # Check the newest stable version.
211 - $srev = $this->getStableRev( true );
 211+ $srev = $this->getStableRev( FR_TEXT );
212212 $frev = $srev;
213213 $stableId = $frev ? $frev->getRevId() : 0;
214214 # Also, check for any explicitly requested old stable version...
@@ -217,7 +217,7 @@
218218 }
219219 if( $stableId && $reqId ) {
220220 if( $reqId != $stableId ) {
221 - $frev = FlaggedRevision::newFromTitle( $this->parent->getTitle(), $reqId, true );
 221+ $frev = FlaggedRevision::newFromTitle( $this->parent->getTitle(), $reqId, FR_TEXT );
222222 $old = true; // old reviewed version requested by ID
223223 if( !$frev ) {
224224 $wgOut->addWikiText( wfMsg('revreview-invalid') );
@@ -460,7 +460,7 @@
461461 if( $reqId = $wgRequest->getVal('stableid') ) {
462462 $frev = FlaggedRevision::newFromTitle( $this->parent->getTitle(), $reqId );
463463 } else if( $this->pageOverride() ) {
464 - $frev = $this->getStableRev( true );
 464+ $frev = $this->getStableRev( FR_TEXT );
465465 }
466466 if( !is_null($frev) ) {
467467 $time = $frev->getFileTimestamp();
@@ -717,7 +717,7 @@
718718 $action = $wgRequest->getVal( 'action', 'view' );
719719 if( $action == 'protect' || $action == 'unprotect' ) {
720720 # Check for an overridabe revision
721 - $frev = $this->getStableRev( true );
 721+ $frev = $this->getStableRev( FR_TEXT );
722722 if( !$frev )
723723 return true;
724724 # Load special page name
@@ -757,7 +757,7 @@
758758 }
759759 # If we are viewing a page normally, and it was overridden,
760760 # change the edit tab to a "current revision" tab
761 - $srev = $this->getStableRev( true );
 761+ $srev = $this->getStableRev( FR_TEXT );
762762 # No quality revs? Find the last reviewed one
763763 if( is_null($srev) ) {
764764 return true;
@@ -1154,7 +1154,7 @@
11551155 if( !$this->isReviewable() || $this->parent->getTitle()->isTalkPage() )
11561156 return true;
11571157 # Get the stable version, from master
1158 - $frev = $this->getStableRev( false, true );
 1158+ $frev = $this->getStableRev( FR_FOR_UPDATE );
11591159 if( !$frev )
11601160 return true;
11611161 $latest = $this->parent->getTitle()->getLatestRevID(GAID_FOR_UPDATE);
@@ -1201,11 +1201,10 @@
12021202
12031203 /**
12041204 * Get latest quality rev, if not, the latest reviewed one
1205 - * @param Bool $getText, get text and params columns?
1206 - * @param Bool $forUpdate, use DB master and avoid page table?
 1205+ * @param int $flags
12071206 * @return Row
12081207 */
1209 - public function getStableRev( $getText = false, $forUpdate = false ) {
 1208+ public function getStableRev( $flags=0 ) {
12101209 if( $this->stableRev === false ) {
12111210 return null; // We already looked and found nothing...
12121211 }
@@ -1216,7 +1215,7 @@
12171216 # Get the content page, skip talk
12181217 $title = $this->parent->getTitle()->getSubjectPage();
12191218 # Do we have one?
1220 - $srev = FlaggedRevision::newFromStable( $title, $getText, $forUpdate );
 1219+ $srev = FlaggedRevision::newFromStable( $title, $flags );
12211220 if( $srev ) {
12221221 $this->stableRev = $srev;
12231222 $this->flags[$srev->getRevId()] = $srev->getTags();
@@ -1287,7 +1286,7 @@
12881287 # If we are reviewing updates to a page, start off with the stable revision's
12891288 # flags. Otherwise, we just fill them in with the selected revision's flags.
12901289 if( $this->isDiffFromStable ) {
1291 - $srev = $this->getStableRev( true );
 1290+ $srev = $this->getStableRev( FR_TEXT );
12921291 $flags = $srev->getTags();
12931292 # Check if user is allowed to renew the stable version.
12941293 # If not, then get the flags for the new revision itself.
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -985,7 +985,7 @@
986986 $title = $article->getTitle();
987987
988988 # Get current stable version ID (for logging)
989 - $oldSv = FlaggedRevision::newFromStable( $title, false, true );
 989+ $oldSv = FlaggedRevision::newFromStable( $title, FR_TEXT | FR_FOR_UPDATE );
990990 $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
991991
992992 # Rev ID is not put into parser on edit, so do the same here.
@@ -1108,7 +1108,7 @@
11091109
11101110 # If we know that this is now the new stable version
11111111 # (which it probably is), save it to the cache...
1112 - $sv = FlaggedRevision::newFromStable( $article->getTitle(), false, true );
 1112+ $sv = FlaggedRevision::newFromStable( $article->getTitle(), FR_FOR_UPDATE );
11131113 if( $sv && $sv->getRevId() == $rev->getId() ) {
11141114 # Update stable cache
11151115 self::updatePageCache( $article, $poutput );
@@ -1156,7 +1156,7 @@
11571157 $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath );
11581158 $rTags = self::getJSTagParams();
11591159 $fTags = self::getJSFeedbackParams();
1160 - $frev = $flaggedArticle->getStableRev( true );
 1160+ $frev = $flaggedArticle->getStableRev( FR_TEXT );
11611161 $stableId = $frev ? $frev->getRevId() : 0;
11621162 $encCssFile = htmlspecialchars( "$stylePath/flaggedrevs.css?$wgFlaggedRevStyleVersion" );
11631163 $encJsFile = htmlspecialchars( "$stylePath/flaggedrevs.js?$wgFlaggedRevStyleVersion" );
@@ -1294,7 +1294,8 @@
12951295 # Check if this page has a stable version by fetching it. Do not
12961296 # get the fr_text field if we are to use the latest stable template revisions.
12971297 global $wgUseStableTemplates;
1298 - $sv = FlaggedRevision::newFromStable( $linksUpdate->mTitle, !$wgUseStableTemplates, true );
 1298+ $flags = $wgUseStableTemplates ? FR_FOR_UPDATE : FR_FOR_UPDATE | FR_TEXT;
 1299+ $sv = FlaggedRevision::newFromStable( $linksUpdate->mTitle, $flags );
12991300 if( !$sv ) {
13001301 $dbw = wfGetDB( DB_MASTER );
13011302 $dbw->delete( 'flaggedpages',
@@ -1445,7 +1446,7 @@
14461447 $sha1 = "";
14471448 global $wgUseStableImages;
14481449 if( $wgUseStableImages && self::isPageReviewable( $title ) ) {
1449 - $srev = FlaggedRevision::newFromStable( $title, false, true );
 1450+ $srev = FlaggedRevision::newFromStable( $title, FR_FOR_UPDATE );
14501451 if( $srev ) {
14511452 $time = $srev->getFileTimestamp();
14521453 $sha1 = $srev->getFileSha1();
@@ -1510,7 +1511,7 @@
15111512 $sha1 = "";
15121513 global $wgUseStableImages;
15131514 if( $wgUseStableImages && self::isPageReviewable( $nt ) ) {
1514 - $srev = FlaggedRevision::newFromStable( $nt, false, true );
 1515+ $srev = FlaggedRevision::newFromStable( $nt, FR_FOR_UPDATE );
15151516 if( $srev ) {
15161517 $time = $srev->getFileTimestamp();
15171518 $sha1 = $srev->getFileSha1();
@@ -1664,7 +1665,7 @@
16651666 $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
16661667 if( $wgTitle && $wgTitle->equals( $title ) ) {
16671668 // Cache stable version while we are at it.
1668 - if( $flaggedArticle->pageOverride() && $flaggedArticle->getStableRev( true ) ) {
 1669+ if( $flaggedArticle->pageOverride() && $flaggedArticle->getStableRev( FR_TEXT ) ) {
16691670 $result = true;
16701671 }
16711672 } else {
@@ -1703,11 +1704,12 @@
17041705 $reviewableNewPage = ( $wgFlaggedRevsAutoReviewNew && $user->isAllowed('review') );
17051706 // Edits to existing pages
17061707 } else if( $baseRevID ) {
1707 - $frev = FlaggedRevision::newFromTitle( $title, $baseRevID, false, true, $rev->getPage() );
 1708+ $title->resetArticleID( $rev->getPage() ); // avoid db hit
 1709+ $frev = FlaggedRevision::newFromTitle( $title, $baseRevID, FR_FOR_UPDATE );
17081710 # If the base revision was not reviewed, check if the previous one was.
17091711 # This should catch null edits as well as normal ones.
17101712 if( !$frev ) {
1711 - $frev = FlaggedRevision::newFromTitle( $title, $prevRevID, false, true, $rev->getPage() );
 1713+ $frev = FlaggedRevision::newFromTitle( $title, $prevRevID, FR_FOR_UPDATE );
17121714 }
17131715 }
17141716 # Is this an edit directly to the stable version?
@@ -2103,7 +2105,7 @@
21042106 } else {
21052107 # Get an instance on the title ($wgTitle) and save to process cache
21062108 $flaggedArticle = FlaggedArticle::getTitleInstance( $title );
2107 - if( $flaggedArticle->pageOverride() && $srev = $flaggedArticle->getStableRev( true ) ) {
 2109+ if( $flaggedArticle->pageOverride() && $srev = $flaggedArticle->getStableRev( FR_TEXT ) ) {
21082110 $text = $srev->getRevText();
21092111 $redirect = $flaggedArticle->followRedirectText( $text );
21102112 if( $redirect ) {
@@ -2228,12 +2230,12 @@
22292231 $fa = FlaggedArticle::getInstance( $article );
22302232 # If the stable is the default, and we are viewing it...cache it!
22312233 if( $fa->showStableByDefault() ) {
2232 - return ( $fa->pageOverride() && $fa->getStableRev( true ) );
 2234+ return ( $fa->pageOverride() && $fa->getStableRev( FR_TEXT ) );
22332235 # If the draft is the default, and we are viewing it...cache it!
22342236 } else {
22352237 global $wgRequest;
22362238 # We don't want to cache the pending edit notice though
2237 - return !( $fa->pageOverride() && $fa->getStableRev( true ) ) && !$wgRequest->getVal('shownotice');
 2239+ return !( $fa->pageOverride() && $fa->getStableRev( FR_TEXT ) ) && !$wgRequest->getVal('shownotice');
22382240 }
22392241 }
22402242
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -45,20 +45,17 @@
4646 /**
4747 * @param Title $title
4848 * @param int $revId
49 - * @param bool $getText, fetch fr_text and fr_flags too?
50 - * @param bool $forUpdate, use master?
51 - * @param int $pageId, optional page ID to use, will defer to $title if not given
 49+ * @param int $flags
5250 * @returns mixed FlaggedRevision (null on failure)
5351 * Will not return a revision if deleted
5452 */
55 - public static function newFromTitle( $title, $revId, $getText=false, $forUpdate=false, $pageId=false ) {
 53+ public static function newFromTitle( $title, $revId, $flags = 0 ) {
5654 $columns = self::selectFields();
57 - if( $getText ) {
 55+ if( $flags & FR_TEXT ) {
5856 $columns += self::selectTextFields();
5957 }
60 - $db = $forUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
61 - $flags = $forUpdate ? GAID_FOR_UPDATE : 0;
62 - $pageId = $pageId ? $pageId : $title->getArticleID( $flags );
 58+ $db = $flags & FR_FOR_UPDATE ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 59+ $pageId = $title->getArticleID( $flags & FR_FOR_UPDATE ? GAID_FOR_UPDATE : 0 );
6360 # Short-circuit query
6461 if( !$pageId ) {
6562 return null;
@@ -82,13 +79,12 @@
8380 /**
8481 * Get latest quality rev, if not, the latest reviewed one.
8582 * @param Title $title, page title
86 - * @param bool $getText, fetch fr_text and fr_flags too?
87 - * @param bool $forUpdate, use master DB and avoid using fp_stable?
 83+ * @param int $flags
8884 * @returns mixed FlaggedRevision (null on failure)
8985 */
90 - public static function newFromStable( $title, $getText=false, $forUpdate=false ) {
 86+ public static function newFromStable( $title, $flags=0 ) {
9187 $columns = self::selectFields();
92 - if( $getText ) {
 88+ if( $flags & FR_TEXT ) {
9389 $columns += self::selectTextFields();
9490 }
9591 $row = null;
@@ -97,7 +93,7 @@
9894 return $row;
9995 }
10096 # If we want the text, then get the text flags too
101 - if( !$forUpdate ) {
 97+ if( !($flags & FR_FOR_UPDATE) ) {
10298 $dbr = wfGetDB( DB_SLAVE );
10399 $row = $dbr->selectRow( array('flaggedpages','flaggedrevs'),
104100 $columns,
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.php
@@ -499,12 +499,12 @@
500500 }
501501
502502 # Get current stable version ID (for logging)
503 - $oldSv = FlaggedRevision::newFromStable( $this->page, false, true );
 503+ $oldSv = FlaggedRevision::newFromStable( $this->page, FR_FOR_UPDATE );
504504 $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
505505
506506 # Is this rev already flagged?
507507 $flaggedOutput = false;
508 - if( $oldfrev = FlaggedRevision::newFromTitle( $this->page, $rev->getId(), true, true ) ) {
 508+ if( $oldfrev = FlaggedRevision::newFromTitle( $this->page, $rev->getId(), FR_TEXT | FR_FOR_UPDATE ) ) {
509509 $flaggedOutput = FlaggedRevs::parseStableText( $article, $oldfrev->getTextForParse(), $oldfrev->getRevId() );
510510 }
511511
@@ -638,7 +638,7 @@
639639 }
640640 # If we know that this is now the new stable version
641641 # (which it probably is), save it to the stable cache...
642 - $sv = FlaggedRevision::newFromStable( $this->page, false, true );
 642+ $sv = FlaggedRevision::newFromStable( $this->page, FR_FOR_UPDATE );
643643 if( $sv && $sv->getRevId() == $rev->getId() ) {
644644 # Clear the cache...
645645 $this->page->invalidateCache();
@@ -685,7 +685,7 @@
686686 $dbw->commit();
687687
688688 # Get current stable version ID (for logging)
689 - $oldSv = FlaggedRevision::newFromStable( $this->page, false, true );
 689+ $oldSv = FlaggedRevision::newFromStable( $this->page, FR_FOR_UPDATE );
690690 $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
691691
692692 # Update the article review log

Status & tagging log