*/
public $mLangLinkLanguages;
+ /**
+ * @var MapCacheLRU|null
+ * @since 1.24
+ *
+ * A cache of the current revisions of titles. Keys are $title->getPrefixedDbKey()
+ */
+ public $currentRevisionCache;
+
/**
* @var bool Recursive call protection.
* This variable should be treated as if it were private.
$this->mVarCache = array();
$this->mUser = null;
$this->mLangLinkLanguages = array();
+ $this->currentRevisionCache = null;
/**
* Prefix for temporary replacement strings for the multipass parser.
$this->startParse( $title, $options, self::OT_HTML, $clearState );
+ $this->currentRevisionCache = null;
$this->mInputSize = strlen( $text );
if ( $this->mOptions->getEnableLimitReport() ) {
$this->mOutput->resetParseStartTime();
$this->mRevisionUser = $oldRevisionUser;
$this->mRevisionSize = $oldRevisionSize;
$this->mInputSize = false;
+ $this->currentRevisionCache = null;
wfProfileOut( $fname );
wfProfileOut( __METHOD__ );
case 'numberofedits':
$value = $pageLang->formatNum( SiteStats::edits() );
break;
- case 'numberofviews':
- global $wgDisableCounters;
- $value = !$wgDisableCounters ? $pageLang->formatNum( SiteStats::views() ) : '';
- break;
case 'currenttimestamp':
$value = wfTimestamp( TS_MW, $ts );
break;
return array( $dom, $title );
}
+ /**
+ * Fetch the current revision of a given title. Note that the revision
+ * (and even the title) may not exist in the database, so everything
+ * contributing to the output of the parser should use this method
+ * where possible, rather than getting the revisions themselves. This
+ * method also caches its results, so using it benefits performance.
+ *
+ * @since 1.24
+ * @param Title $title
+ * @return Revision
+ */
+ public function fetchCurrentRevisionOfTitle( $title ) {
+ $cacheKey = $title->getPrefixedDBkey();
+ if ( !$this->currentRevisionCache ) {
+ $this->currentRevisionCache = new MapCacheLRU( 100 );
+ }
+ if ( !$this->currentRevisionCache->has( $cacheKey ) ) {
+ $this->currentRevisionCache->set( $cacheKey,
+ // Defaults to Parser::statelessFetchRevision()
+ call_user_func( $this->mOptions->getCurrentRevisionCallback(), $title, $this )
+ );
+ }
+ return $this->currentRevisionCache->get( $cacheKey );
+ }
+
+ /**
+ * Wrapper around Revision::newFromTitle to allow passing additional parameters
+ * without passing them on to it.
+ *
+ * @since 1.24
+ * @param Title $title
+ * @param Parser|bool $parser
+ * @return Revision
+ */
+ public static function statelessFetchRevision( $title, $parser = false ) {
+ return Revision::newFromTitle( $title );
+ }
+
/**
* Fetch the unparsed text of a template and register a reference to it.
* @param Title $title
break;
}
# Get the revision
- $rev = $id
- ? Revision::newFromId( $id )
- : Revision::newFromTitle( $title, false, Revision::READ_NORMAL );
+ if ( $id ) {
+ $rev = Revision::newFromId( $id );
+ } elseif ( $parser ) {
+ $rev = $parser->fetchCurrentRevisionOfTitle( $title );
+ } else {
+ $rev = Revision::newFromTitle( $title );
+ }
$rev_id = $rev ? $rev->getId() : 0;
# If there is no current revision, there is no page
if ( $id === false && !$rev ) {
}
/**
- * Add a tracking category, getting the title from a system message,
- * or print a debug message if the title is invalid.
- *
- * Please add any message that you use with this function to
- * $wgTrackingCategories. That way they will be listed on
- * Special:TrackingCategories.
- *
+ * @see ParserOutput::addTrackingCategory()
* @param string $msg Message key
* @return bool Whether the addition was successful
*/
public function addTrackingCategory( $msg ) {
- if ( $this->mTitle->getNamespace() === NS_SPECIAL ) {
- wfDebug( __METHOD__ . ": Not adding tracking category $msg to special page!\n" );
- return false;
- }
- // Important to parse with correct title (bug 31469)
- $cat = wfMessage( $msg )
- ->title( $this->getTitle() )
- ->inContentLanguage()
- ->text();
-
- # Allow tracking categories to be disabled by setting them to "-"
- if ( $cat === '-' ) {
- return false;
- }
-
- $containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
- if ( $containerCategory ) {
- $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
- return true;
- } else {
- wfDebug( __METHOD__ . ": [[MediaWiki:$msg]] is not a valid title!\n" );
- return false;
- }
+ return $this->mOutput->addTrackingCategory( $msg, $this->mTitle );
}
/**