r35979 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35978‎ | r35979 | r35980 >
Date:20:28, 6 June 2008
Author:aaron
Status:old
Tags:
Comment:
* Pass in $parser more cleanly
* Show namespace in include error list
* Use getRevisionId() accessor
* Handle bogus article Ids
* Remove unused var
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Parser_OldPP.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -3057,7 +3057,7 @@
30583058 */
30593059 function fetchTemplateAndTitle( $title ) {
30603060 $templateCb = $this->mOptions->getTemplateCallback();
3061 - $stuff = call_user_func( $templateCb, $title );
 3061+ $stuff = call_user_func( $templateCb, $title, $this );
30623062 $text = $stuff['text'];
30633063 $finalTitle = isset( $stuff['finalTitle'] ) ? $stuff['finalTitle'] : $title;
30643064 if ( isset( $stuff['deps'] ) ) {
@@ -3077,7 +3077,7 @@
30783078 * Static function to get a template
30793079 * Can be overridden via ParserOptions::setTemplateCallback().
30803080 */
3081 - static function statelessFetchTemplate( $title ) {
 3081+ static function statelessFetchTemplate( $title, $parser=false ) {
30823082 $text = $skip = false;
30833083 $finalTitle = $title;
30843084 $deps = array();
@@ -3086,7 +3086,7 @@
30873087 for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
30883088 # Give extensions a chance to select the revision instead
30893089 $id = false; // Assume current
3090 - wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( false, &$title, &$skip, &$id ) );
 3090+ wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) );
30913091
30923092 if( $skip ) {
30933093 $text = false;
Index: trunk/phase3/includes/Parser_OldPP.php
@@ -410,6 +410,7 @@
411411
412412 function &getTitle() { return $this->mTitle; }
413413 function getOptions() { return $this->mOptions; }
 414+ function getRevisionId() { return $this->mRevisionId; }
414415
415416 function getFunctionLang() {
416417 global $wgLang, $wgContLang;
@@ -3261,7 +3262,7 @@
32623263 */
32633264 function fetchTemplateAndTitle( $title ) {
32643265 $templateCb = $this->mOptions->getTemplateCallback();
3265 - $stuff = call_user_func( $templateCb, $title );
 3266+ $stuff = call_user_func( $templateCb, $title, $this );
32663267 $text = $stuff['text'];
32673268 $finalTitle = isset( $stuff['finalTitle'] ) ? $stuff['finalTitle'] : $title;
32683269 if ( isset( $stuff['deps'] ) ) {
@@ -3289,7 +3290,7 @@
32903291 * page_id: The page_id of the title
32913292 * rev_id: The revision ID loaded
32923293 */
3293 - static function statelessFetchTemplate( $title ) {
 3294+ static function statelessFetchTemplate( $title, $parser=false ) {
32943295 $text = $skip = false;
32953296 $finalTitle = $title;
32963297 $deps = array();
@@ -3298,7 +3299,7 @@
32993300 for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
33003301 # Give extensions a chance to select the revision instead
33013302 $id = false; // Assume current
3302 - wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( false, &$title, &$skip, &$id ) );
 3303+ wfRunHooks( 'BeforeParserFetchTemplateAndtitle', array( $parser, &$title, &$skip, &$id ) );
33033304
33043305 if( $skip ) {
33053306 $text = false;
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -513,16 +513,17 @@
514514 * Updates the fp_stable and fp_reviewed fields
515515 */
516516 public static function updateArticleOn( $article, $revId, $latest=NULL ) {
517 - global $wgMemc;
518 - wfProfileIn( __METHOD__ );
 517+ if( !$article->getId() )
 518+ return true; // no bogus entries
519519
 520+ wfProfileIn( __METHOD__ );
520521 $lastID = $latest ? $latest : $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE);
521522
522523 $dbw = wfGetDB( DB_MASTER );
523524 # Get the highest quality revision (not necessarily this one).
524525 $maxQuality = $dbw->selectField( array('flaggedrevs','revision'),
525526 'fr_quality',
526 - array( 'fr_page_id' => $article->getTitle()->getArticleID(),
 527+ array( 'fr_page_id' => $article->getId(),
527528 'rev_id = fr_rev_id',
528529 'rev_page = fr_page_id',
529530 'rev_deleted & '.Revision::DELETED_TEXT => 0 ),
@@ -1250,11 +1251,9 @@
12511252 * Select the desired templates based on the selected stable revision IDs
12521253 * NOTE: $p comes in false from this hook ... weird
12531254 */
1254 - public static function parserFetchStableTemplate( $p=false, $title, &$skip, &$id ) {
1255 - global $wgParser;
 1255+ public static function parserFetchStableTemplate( $parser, $title, &$skip, &$id ) {
12561256 # Trigger for stable version parsing only
1257 - $parser =& $wgParser;
1258 - if( !isset($parser->fr_isStable) || !$parser->fr_isStable )
 1257+ if( !$parser || !isset($parser->fr_isStable) || !$parser->fr_isStable )
12591258 return true;
12601259 # Special namespace ... ?
12611260 if( $title->getNamespace() < 0 ) {
@@ -1265,21 +1264,21 @@
12661265 # Should be in reviewable namespace, this saves unneeded DB checks as
12671266 # well as enforce site settings if they are later changed.
12681267 global $wgUseStableTemplates;
1269 - if( $wgUseStableTemplates && self::isPageReviewable( $title ) ) {
 1268+ if( $wgUseStableTemplates && self::isPageReviewable($title) && $title->getArticleId() ) {
12701269 $id = $dbr->selectField( 'flaggedpages', 'fp_stable',
12711270 array( 'fp_page_id' => $title->getArticleId() ),
12721271 __METHOD__ );
12731272 }
12741273 # Check cache before doing another DB hit...
12751274 if( !$id ) {
1276 - $id = self::getTemplateIdFromCache( $parser->mRevisionId, $title->getNamespace(), $title->getDBKey() );
 1275+ $id = self::getTemplateIdFromCache( $parser->getRevisionId(), $title->getNamespace(), $title->getDBKey() );
12771276 $id = is_null($id) ? false : $id;
12781277 }
12791278 # If there is no stable version (or that feature is not enabled), use
12801279 # the template revision during review time.
12811280 if( $id === false ) {
12821281 $id = $dbr->selectField( 'flaggedtemplates', 'ft_tmp_rev_id',
1283 - array( 'ft_rev_id' => $parser->mRevisionId,
 1282+ array( 'ft_rev_id' => $parser->getRevisionId(),
12841283 'ft_namespace' => $title->getNamespace(),
12851284 'ft_title' => $title->getDBkey() ),
12861285 __METHOD__ );
@@ -1288,7 +1287,7 @@
12891288 if( !$id ) {
12901289 global $wgUseCurrentTemplates;
12911290 if( $id === false ) {
1292 - $parser->fr_includeErrors[] = $title->getDBKey(); // May want to give an error
 1291+ $parser->fr_includeErrors[] = $title->getPrefixedDBKey(); // May want to give an error
12931292 if( !$wgUseCurrentTemplates ) {
12941293 $skip = true;
12951294 }
@@ -1335,7 +1334,7 @@
13361335 }
13371336 # Check cache before doing another DB hit...
13381337 if( !$time ) {
1339 - $params = self::getFileVersionFromCache( $parser->mRevisionId, $nt->getDBKey() );
 1338+ $params = self::getFileVersionFromCache( $parser->getRevisionId(), $nt->getDBKey() );
13401339 if( is_array($params) ) {
13411340 list($time,$sha1) = $params;
13421341 }
@@ -1345,7 +1344,7 @@
13461345 if( $time === false ) {
13471346 $row = $dbr->selectRow( 'flaggedimages',
13481347 array( 'fi_img_timestamp', 'fi_img_sha1' ),
1349 - array( 'fi_rev_id' => $parser->mRevisionId,
 1348+ array( 'fi_rev_id' => $parser->getRevisionId(),
13501349 'fi_name' => $nt->getDBkey() ),
13511350 __METHOD__ );
13521351 $time = $row ? $row->fi_img_timestamp : $time;

Status & tagging log