r35696 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35695‎ | r35696 | r35697 >
Date:05:01, 2 June 2008
Author:aaron
Status:old
Tags:
Comment:
Be more explicit with object finding for the sake of clarity
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -11,27 +11,31 @@
1212
1313 /**
1414 * Get an instance of FlaggedArticle for a given Article or Title object
 15+ * @param mixed $object (Article/Title)
 16+ * @param bool $tryGlobals, check $wgTitle?
1517 */
16 - static function getInstance( $object ) {
 18+ static function getInstance( $object, $tryGlobals = false ) {
1719 # If instance already cached, return it!
1820 if( isset($object->flaggedRevsArticle) ) {
1921 return $object->flaggedRevsArticle;
2022 }
21 - global $wgTitle;
22 - # Try and keep things to one object to avoid cache misses...
23 - # If $wgTitle has no instance, give it one!
24 - if( !isset($wgTitle->flaggedRevsArticle) ) {
25 - $article = new Article( $wgTitle );
26 - $wgTitle->flaggedRevsArticle = new FlaggedArticle( $article );
 23+ if( $tryGlobals ) {
 24+ global $wgTitle;
 25+ # Try and keep things to one object to avoid cache misses...
 26+ # If $wgTitle has no instance, give it one!
 27+ if( !isset($wgTitle->flaggedRevsArticle) ) {
 28+ $article = new Article( $wgTitle );
 29+ $wgTitle->flaggedRevsArticle = new FlaggedArticle( $article );
 30+ }
 31+ # Use $wgTitle's instance if we are dealing with the same article
 32+ if( $object instanceof Title && $object->equals( $wgTitle ) ) {
 33+ $object->flaggedRevsArticle =& $wgTitle->flaggedRevsArticle;
 34+ return $object->flaggedRevsArticle;
 35+ } else if( $object instanceof Article && $object->getTitle()->equals( $wgTitle ) ) {
 36+ $object->flaggedRevsArticle =& $wgTitle->flaggedRevsArticle;
 37+ return $object->flaggedRevsArticle;
 38+ }
2739 }
28 - # Use $wgTitle's instance if we are dealing with the same article
29 - if( $object instanceof Title && $object->equals( $wgTitle ) ) {
30 - $object->flaggedRevsArticle =& $wgTitle->flaggedRevsArticle;
31 - return $object->flaggedRevsArticle;
32 - } else if( $object instanceof Article && $object->getTitle()->equals( $wgTitle ) ) {
33 - $object->flaggedRevsArticle =& $wgTitle->flaggedRevsArticle;
34 - return $object->flaggedRevsArticle;
35 - }
3640 # For titles, attach instance to the title and give the instance an article parent
3741 if( $object instanceof Title ) {
3842 $article = new Article( $object );
@@ -323,7 +327,7 @@
324328 $revsSince = FlaggedRevs::getRevCountSince( $this->parent, $frev->getRevId() );
325329 # Get parsed stable version
326330 $parserOut = FlaggedRevs::getPageCache( $this->parent );
327 - if( $parserOut==false ) {
 331+ if( $parserOut == false ) {
328332 $text = $frev->getTextForParse();
329333 $parserOut = FlaggedRevs::parseStableText( $this->parent, $text, $frev->getRevId() );
330334 # Update the stable version cache
@@ -1115,7 +1119,7 @@
11161120 * @param Bool $forUpdate, use DB master and avoid page table?
11171121 * @return Row
11181122 */
1119 - public function getStableRev( $getText=false, $forUpdate=false ) {
 1123+ public function getStableRev( $getText = false, $forUpdate = false ) {
11201124 if( $this->stableRev === false ) {
11211125 return null; // We already looked and found nothing...
11221126 }
@@ -1142,7 +1146,7 @@
11431147 * @param Bool $forUpdate, use DB master?
11441148 * @returns Array (select,override)
11451149 */
1146 - public function getVisibilitySettings( $forUpdate=false ) {
 1150+ public function getVisibilitySettings( $forUpdate = false ) {
11471151 # Cached results available?
11481152 if( !is_null($this->pageConfig) ) {
11491153 return $this->pageConfig;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -1111,7 +1111,7 @@
11121112 }
11131113 global $wgScriptPath, $wgJsMimeType, $wgFlaggedRevsStylePath, $wgFlaggedRevStyleVersion;
11141114
1115 - $flaggedArticle = FlaggedArticle::getInstance( $wgArticle );
 1115+ $flaggedArticle = FlaggedArticle::getInstance( $wgArticle, true );
11161116 $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath );
11171117 $JSparams = self::getJSParams();
11181118 $frev = $flaggedArticle->getStableRev( true );
@@ -1595,7 +1595,7 @@
15961596 if( $action != 'move' || !self::isPageReviewable( $title ) )
15971597 return true;
15981598
1599 - $flaggedArticle = FlaggedArticle::getInstance( $title );
 1599+ $flaggedArticle = FlaggedArticle::getInstance( $title, true );
16001600 $frev = $flaggedArticle->getStableRev();
16011601 if( !$frev )
16021602 return true;
@@ -1630,7 +1630,7 @@
16311631 }
16321632 # See if there is a stable version. Also, see if, given the page
16331633 # config and URL params, the page can be overriden.
1634 - $flaggedArticle = FlaggedArticle::getInstance( $title );
 1634+ $flaggedArticle = FlaggedArticle::getInstance( $title, true );
16351635 if( $wgTitle && $wgTitle->equals( $title ) ) {
16361636 // Cache stable version while we are at it.
16371637 if( $flaggedArticle->pageOverride() && $flaggedArticle->getStableRev( true ) ) {
@@ -2047,7 +2047,7 @@
20482048 }
20492049
20502050 public static function imagePageFindFile( $imagePage, &$normalFile, &$displayFile ) {
2051 - $flaggedArticle = FlaggedArticle::getInstance( $imagePage );
 2051+ $flaggedArticle = FlaggedArticle::getInstance( $imagePage, true );
20522052 $flaggedArticle->imagePageFindFile( $normalFile, $displayFile );
20532053 return true;
20542054 }
@@ -2055,7 +2055,7 @@
20562056 static function setActionTabs( $skin, &$contentActions ) {
20572057 global $wgArticle;
20582058 if( $wgArticle ) {
2059 - FlaggedArticle::getInstance( $wgArticle )->setActionTabs( $skin, $contentActions );
 2059+ FlaggedArticle::getInstance( $wgArticle, true )->setActionTabs( $skin, $contentActions );
20602060 }
20612061 return true;
20622062 }
@@ -2063,13 +2063,13 @@
20642064 static function setLastModified( $skin, &$tpl ) {
20652065 global $wgArticle;
20662066 if( $wgArticle ) {
2067 - FlaggedArticle::getInstance( $wgArticle )->setLastModified( $skin, $tpl );
 2067+ FlaggedArticle::getInstance( $wgArticle, true )->setLastModified( $skin, $tpl );
20682068 }
20692069 return true;
20702070 }
20712071
20722072 static function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
2073 - $flaggedArticle = FlaggedArticle::getInstance( $article );
 2073+ $flaggedArticle = FlaggedArticle::getInstance( $article, true );
20742074 $flaggedArticle->maybeUpdateMainCache( $outputDone, $pcache );
20752075 $flaggedArticle->setPageContent( $outputDone, $pcache );
20762076 $flaggedArticle->addPatrolLink( $outputDone, $pcache );
@@ -2079,23 +2079,23 @@
20802080 static function setPermaLink( $skin, &$navUrls, &$revId, &$id ) {
20812081 global $wgArticle;
20822082 if ( $wgArticle ) {
2083 - FlaggedArticle::getInstance( $wgArticle )->setPermaLink( $skin, $navUrls, $revId, $id );
 2083+ FlaggedArticle::getInstance( $wgArticle, true )->setPermaLink( $skin, $navUrls, $revId, $id );
20842084 }
20852085 return true;
20862086 }
20872087
20882088 static function addToEditView( $editPage ) {
2089 - return FlaggedArticle::getInstance( $editPage->mArticle )->addToEditView( $editPage );
 2089+ return FlaggedArticle::getInstance( $editPage->mArticle, true )->addToEditView( $editPage );
20902090 }
20912091
20922092 static function unreviewedPagesLinks( $category ) {
2093 - return FlaggedArticle::getInstance( $category )->addToCategoryView();
 2093+ return FlaggedArticle::getInstance( $category, true )->addToCategoryView();
20942094 }
20952095
20962096 static function addReviewForm( $out ) {
20972097 global $wgArticle;
20982098 if ( $wgArticle && $out->isArticleRelated() ) {
2099 - FlaggedArticle::getInstance( $wgArticle )->addReviewForm( $out );
 2099+ FlaggedArticle::getInstance( $wgArticle, true )->addReviewForm( $out );
21002100 }
21012101 return true;
21022102 }
@@ -2103,13 +2103,13 @@
21042104 static function addVisibilityLink( $out ) {
21052105 global $wgArticle;
21062106 if ( $wgArticle && $out->isArticleRelated() ) {
2107 - FlaggedArticle::getInstance( $wgArticle )->addVisibilityLink( $out );
 2107+ FlaggedArticle::getInstance( $wgArticle, true )->addVisibilityLink( $out );
21082108 }
21092109 return true;
21102110 }
21112111
21122112 static function addToHistQuery( $pager, &$queryInfo ) {
2113 - $flaggedArticle = FlaggedArticle::getInstance( $pager->mPageHistory->getTitle() );
 2113+ $flaggedArticle = FlaggedArticle::getInstance( $pager->mPageHistory->getTitle(), true );
21142114 if( $flaggedArticle->isReviewable() ) {
21152115 $queryInfo['tables'][] = 'flaggedrevs';
21162116 $queryInfo['fields'][] = 'fr_quality';
@@ -2120,26 +2120,26 @@
21212121 }
21222122
21232123 static function addToHistLine( $history, $row, &$s ) {
2124 - return FlaggedArticle::getInstance( $history->getArticle() )->addToHistLine( $history, $row, $s );
 2124+ return FlaggedArticle::getInstance( $history->getArticle(), true )->addToHistLine( $history, $row, $s );
21252125 }
21262126
21272127 static function addToFileHistLine( $hist, $file, &$s, &$rowClass ) {
2128 - return FlaggedArticle::getInstance( $hist->getImagePage() )->addToFileHistLine( $hist, $file, $s, $rowClass );
 2128+ return FlaggedArticle::getInstance( $hist->getImagePage(), true )->addToFileHistLine( $hist, $file, $s, $rowClass );
21292129 }
21302130
21312131 static function injectReviewDiffURLParams( $article, &$sectionAnchor, &$extraQuery ) {
2132 - return FlaggedArticle::getInstance( $article )->injectReviewDiffURLParams( $sectionAnchor, $extraQuery );
 2132+ return FlaggedArticle::getInstance( $article, true )->injectReviewDiffURLParams( $sectionAnchor, $extraQuery );
21332133 }
21342134
21352135 static function onDiffViewHeader( $diff, $oldRev, $newRev ) {
2136 - $flaggedArticle = FlaggedArticle::getInstance( $diff->getTitle() );
 2136+ $flaggedArticle = FlaggedArticle::getInstance( $diff->getTitle(), true );
21372137 $flaggedArticle->addPatrolAndDiffLink( $diff, $oldRev, $newRev );
21382138 $flaggedArticle->addDiffNoticeAndIncludes( $diff, $oldRev, $newRev );
21392139 return true;
21402140 }
21412141
21422142 static function addRevisionIDField( $editPage, $out ) {
2143 - return FlaggedArticle::getInstance( $editPage->mArticle )->addRevisionIDField( $editPage, $out );
 2143+ return FlaggedArticle::getInstance( $editPage->mArticle, true )->addRevisionIDField( $editPage, $out );
21442144 }
21452145
21462146 static function addBacklogNotice( &$notice ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r36159Fix r35696:...tstarling16:13, 10 June 2008

Status & tagging log