r57283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57282‎ | r57283 | r57284 >
Date:09:46, 2 October 2009
Author:daniel
Status:ok (Comments)
Tags:todo 
Comment:
follow-up to r57278: cache all variables untill the next clearState()
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -2340,173 +2340,235 @@
23412341
23422342 switch ( $index ) {
23432343 case 'currentmonth':
2344 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'm', $ts ) );
 2344+ $value = $wgContLang->formatNum( gmdate( 'm', $ts ) );
 2345+ break;
23452346 case 'currentmonth1':
2346 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'n', $ts ) );
 2347+ $value = $wgContLang->formatNum( gmdate( 'n', $ts ) );
 2348+ break;
23472349 case 'currentmonthname':
2348 - return $this->mVarCache[$index] = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
 2350+ $value = $wgContLang->getMonthName( gmdate( 'n', $ts ) );
 2351+ break;
23492352 case 'currentmonthnamegen':
2350 - return $this->mVarCache[$index] = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
 2353+ $value = $wgContLang->getMonthNameGen( gmdate( 'n', $ts ) );
 2354+ break;
23512355 case 'currentmonthabbrev':
2352 - return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
 2356+ $value = $wgContLang->getMonthAbbreviation( gmdate( 'n', $ts ) );
 2357+ break;
23532358 case 'currentday':
2354 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'j', $ts ) );
 2359+ $value = $wgContLang->formatNum( gmdate( 'j', $ts ) );
 2360+ break;
23552361 case 'currentday2':
2356 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'd', $ts ) );
 2362+ $value = $wgContLang->formatNum( gmdate( 'd', $ts ) );
 2363+ break;
23572364 case 'localmonth':
2358 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localMonth );
 2365+ $value = $wgContLang->formatNum( $localMonth );
 2366+ break;
23592367 case 'localmonth1':
2360 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localMonth1 );
 2368+ $value = $wgContLang->formatNum( $localMonth1 );
 2369+ break;
23612370 case 'localmonthname':
2362 - return $this->mVarCache[$index] = $wgContLang->getMonthName( $localMonthName );
 2371+ $value = $wgContLang->getMonthName( $localMonthName );
 2372+ break;
23632373 case 'localmonthnamegen':
2364 - return $this->mVarCache[$index] = $wgContLang->getMonthNameGen( $localMonthName );
 2374+ $value = $wgContLang->getMonthNameGen( $localMonthName );
 2375+ break;
23652376 case 'localmonthabbrev':
2366 - return $this->mVarCache[$index] = $wgContLang->getMonthAbbreviation( $localMonthName );
 2377+ $value = $wgContLang->getMonthAbbreviation( $localMonthName );
 2378+ break;
23672379 case 'localday':
2368 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localDay );
 2380+ $value = $wgContLang->formatNum( $localDay );
 2381+ break;
23692382 case 'localday2':
2370 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localDay2 );
 2383+ $value = $wgContLang->formatNum( $localDay2 );
 2384+ break;
23712385 case 'pagename':
2372 - return wfEscapeWikiText( $this->mTitle->getText() );
 2386+ $value = wfEscapeWikiText( $this->mTitle->getText() );
 2387+ break;
23732388 case 'pagenamee':
2374 - return $this->mTitle->getPartialURL();
 2389+ $value = $this->mTitle->getPartialURL();
 2390+ break;
23752391 case 'fullpagename':
2376 - return wfEscapeWikiText( $this->mTitle->getPrefixedText() );
 2392+ $value = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
 2393+ break;
23772394 case 'fullpagenamee':
2378 - return $this->mTitle->getPrefixedURL();
 2395+ $value = $this->mTitle->getPrefixedURL();
 2396+ break;
23792397 case 'subpagename':
2380 - return wfEscapeWikiText( $this->mTitle->getSubpageText() );
 2398+ $value = wfEscapeWikiText( $this->mTitle->getSubpageText() );
 2399+ break;
23812400 case 'subpagenamee':
2382 - return $this->mTitle->getSubpageUrlForm();
 2401+ $value = $this->mTitle->getSubpageUrlForm();
 2402+ break;
23832403 case 'basepagename':
2384 - return wfEscapeWikiText( $this->mTitle->getBaseText() );
 2404+ $value = wfEscapeWikiText( $this->mTitle->getBaseText() );
 2405+ break;
23852406 case 'basepagenamee':
2386 - return wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
 2407+ $value = wfUrlEncode( str_replace( ' ', '_', $this->mTitle->getBaseText() ) );
 2408+ break;
23872409 case 'talkpagename':
23882410 if( $this->mTitle->canTalk() ) {
23892411 $talkPage = $this->mTitle->getTalkPage();
2390 - return wfEscapeWikiText( $talkPage->getPrefixedText() );
 2412+ $value = wfEscapeWikiText( $talkPage->getPrefixedText() );
23912413 } else {
2392 - return '';
 2414+ $value = '';
23932415 }
 2416+ break;
23942417 case 'talkpagenamee':
23952418 if( $this->mTitle->canTalk() ) {
23962419 $talkPage = $this->mTitle->getTalkPage();
2397 - return $talkPage->getPrefixedUrl();
 2420+ $value = $talkPage->getPrefixedUrl();
23982421 } else {
2399 - return '';
 2422+ $value = '';
24002423 }
 2424+ break;
24012425 case 'subjectpagename':
24022426 $subjPage = $this->mTitle->getSubjectPage();
2403 - return wfEscapeWikiText( $subjPage->getPrefixedText() );
 2427+ $value = wfEscapeWikiText( $subjPage->getPrefixedText() );
 2428+ break;
24042429 case 'subjectpagenamee':
24052430 $subjPage = $this->mTitle->getSubjectPage();
2406 - return $subjPage->getPrefixedUrl();
 2431+ $value = $subjPage->getPrefixedUrl();
 2432+ break;
24072433 case 'revisionid':
24082434 // Let the edit saving system know we should parse the page
24092435 // *after* a revision ID has been assigned.
24102436 $this->mOutput->setFlag( 'vary-revision' );
24112437 wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
2412 - return $this->mRevisionId;
 2438+ $value = $this->mRevisionId;
 2439+ break;
24132440 case 'revisionday':
24142441 // Let the edit saving system know we should parse the page
24152442 // *after* a revision ID has been assigned. This is for null edits.
24162443 $this->mOutput->setFlag( 'vary-revision' );
24172444 wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" );
2418 - return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
 2445+ $value = intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
 2446+ break;
24192447 case 'revisionday2':
24202448 // Let the edit saving system know we should parse the page
24212449 // *after* a revision ID has been assigned. This is for null edits.
24222450 $this->mOutput->setFlag( 'vary-revision' );
24232451 wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" );
2424 - return substr( $this->getRevisionTimestamp(), 6, 2 );
 2452+ $value = substr( $this->getRevisionTimestamp(), 6, 2 );
 2453+ break;
24252454 case 'revisionmonth':
24262455 // Let the edit saving system know we should parse the page
24272456 // *after* a revision ID has been assigned. This is for null edits.
24282457 $this->mOutput->setFlag( 'vary-revision' );
24292458 wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" );
2430 - return intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
 2459+ $value = intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
 2460+ break;
24312461 case 'revisionyear':
24322462 // Let the edit saving system know we should parse the page
24332463 // *after* a revision ID has been assigned. This is for null edits.
24342464 $this->mOutput->setFlag( 'vary-revision' );
24352465 wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" );
2436 - return substr( $this->getRevisionTimestamp(), 0, 4 );
 2466+ $value = substr( $this->getRevisionTimestamp(), 0, 4 );
 2467+ break;
24372468 case 'revisiontimestamp':
24382469 // Let the edit saving system know we should parse the page
24392470 // *after* a revision ID has been assigned. This is for null edits.
24402471 $this->mOutput->setFlag( 'vary-revision' );
24412472 wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n" );
2442 - return $this->getRevisionTimestamp();
 2473+ $value = $this->getRevisionTimestamp();
 2474+ break;
24432475 case 'revisionuser':
24442476 // Let the edit saving system know we should parse the page
24452477 // *after* a revision ID has been assigned. This is for null edits.
24462478 $this->mOutput->setFlag( 'vary-revision' );
24472479 wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" );
2448 - return $this->getRevisionUser();
 2480+ $value = $this->getRevisionUser();
 2481+ break;
24492482 case 'namespace':
2450 - return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
 2483+ $value = str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
 2484+ break;
24512485 case 'namespacee':
2452 - return wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
 2486+ $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
 2487+ break;
24532488 case 'talkspace':
2454 - return $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
 2489+ $value = $this->mTitle->canTalk() ? str_replace('_',' ',$this->mTitle->getTalkNsText()) : '';
 2490+ break;
24552491 case 'talkspacee':
2456 - return $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
 2492+ $value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
 2493+ break;
24572494 case 'subjectspace':
2458 - return $this->mTitle->getSubjectNsText();
 2495+ $value = $this->mTitle->getSubjectNsText();
 2496+ break;
24592497 case 'subjectspacee':
2460 - return( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
 2498+ $value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
 2499+ break;
24612500 case 'currentdayname':
2462 - return $this->mVarCache[$index] = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
 2501+ $value = $wgContLang->getWeekdayName( gmdate( 'w', $ts ) + 1 );
 2502+ break;
24632503 case 'currentyear':
2464 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
 2504+ $value = $wgContLang->formatNum( gmdate( 'Y', $ts ), true );
 2505+ break;
24652506 case 'currenttime':
2466 - return $this->mVarCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
 2507+ $value = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
 2508+ break;
24672509 case 'currenthour':
2468 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
 2510+ $value = $wgContLang->formatNum( gmdate( 'H', $ts ), true );
 2511+ break;
24692512 case 'currentweek':
24702513 // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
24712514 // int to remove the padding
2472 - return $this->mVarCache[$index] = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
 2515+ $value = $wgContLang->formatNum( (int)gmdate( 'W', $ts ) );
 2516+ break;
24732517 case 'currentdow':
2474 - return $this->mVarCache[$index] = $wgContLang->formatNum( gmdate( 'w', $ts ) );
 2518+ $value = $wgContLang->formatNum( gmdate( 'w', $ts ) );
 2519+ break;
24752520 case 'localdayname':
2476 - return $this->mVarCache[$index] = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
 2521+ $value = $wgContLang->getWeekdayName( $localDayOfWeek + 1 );
 2522+ break;
24772523 case 'localyear':
2478 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localYear, true );
 2524+ $value = $wgContLang->formatNum( $localYear, true );
 2525+ break;
24792526 case 'localtime':
2480 - return $this->mVarCache[$index] = $wgContLang->time( $localTimestamp, false, false );
 2527+ $value = $wgContLang->time( $localTimestamp, false, false );
 2528+ break;
24812529 case 'localhour':
2482 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localHour, true );
 2530+ $value = $wgContLang->formatNum( $localHour, true );
 2531+ break;
24832532 case 'localweek':
24842533 // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
24852534 // int to remove the padding
2486 - return $this->mVarCache[$index] = $wgContLang->formatNum( (int)$localWeek );
 2535+ $value = $wgContLang->formatNum( (int)$localWeek );
 2536+ break;
24872537 case 'localdow':
2488 - return $this->mVarCache[$index] = $wgContLang->formatNum( $localDayOfWeek );
 2538+ $value = $wgContLang->formatNum( $localDayOfWeek );
 2539+ break;
24892540 case 'numberofarticles':
2490 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::articles() );
 2541+ $value = $wgContLang->formatNum( SiteStats::articles() );
 2542+ break;
24912543 case 'numberoffiles':
2492 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::images() );
 2544+ $value = $wgContLang->formatNum( SiteStats::images() );
 2545+ break;
24932546 case 'numberofusers':
2494 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::users() );
 2547+ $value = $wgContLang->formatNum( SiteStats::users() );
 2548+ break;
24952549 case 'numberofactiveusers':
2496 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::activeUsers() );
 2550+ $value = $wgContLang->formatNum( SiteStats::activeUsers() );
 2551+ break;
24972552 case 'numberofpages':
2498 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::pages() );
 2553+ $value = $wgContLang->formatNum( SiteStats::pages() );
 2554+ break;
24992555 case 'numberofadmins':
2500 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
 2556+ $value = $wgContLang->formatNum( SiteStats::numberingroup('sysop') );
 2557+ break;
25012558 case 'numberofedits':
2502 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::edits() );
 2559+ $value = $wgContLang->formatNum( SiteStats::edits() );
 2560+ break;
25032561 case 'numberofviews':
2504 - return $this->mVarCache[$index] = $wgContLang->formatNum( SiteStats::views() );
 2562+ $value = $wgContLang->formatNum( SiteStats::views() );
 2563+ break;
25052564 case 'currenttimestamp':
2506 - return $this->mVarCache[$index] = wfTimestamp( TS_MW, $ts );
 2565+ $value = wfTimestamp( TS_MW, $ts );
 2566+ break;
25072567 case 'localtimestamp':
2508 - return $this->mVarCache[$index] = $localTimestamp;
 2568+ $value = $localTimestamp;
 2569+ break;
25092570 case 'currentversion':
2510 - return $this->mVarCache[$index] = SpecialVersion::getVersion();
 2571+ $value = SpecialVersion::getVersion();
 2572+ break;
25112573 case 'sitename':
25122574 return $wgSitename;
25132575 case 'server':
@@ -2515,8 +2577,6 @@
25162578 return $wgServerName;
25172579 case 'scriptpath':
25182580 return $wgScriptPath;
2519 - case 'stylepath':
2520 - return $wgStylePath;
25212581 case 'directionmark':
25222582 return $wgContLang->getDirMark();
25232583 case 'contentlanguage':
@@ -2529,6 +2589,11 @@
25302590 else
25312591 return null;
25322592 }
 2593+
 2594+ if ( $index )
 2595+ $this->mVarCache[$index] = $value;
 2596+
 2597+ return $value;
25332598 }
25342599
25352600 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r60120Readd case statement for {{STYLEPATH}} that was accidentally removed in r57283catrope12:02, 16 December 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57278clear variable cache in clearState() as suggested by tim. fix odd values for ...daniel09:09, 2 October 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   18:40, 6 October 2009

This might be a little cleaner if we break the caching & lazy-load and the gimme-value-for-this-name bits into separate functions; that avoids the duplication of '$value = ' and 'break' and lets us write nice clean 'return's...

Status & tagging log