if ( !$wgRestrictDisplayTitle ||
( $title instanceof Title
&& !$title->hasFragment()
- && $title->equals( $parser->mTitle ) )
+ && $title->equals( $parser->getTitle() ) )
) {
$old = $parser->mOutput->getProperty( 'displaytitle' );
if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $title );
+ $rev = self::getCachedRevisionObject( $parser, $title, 'vary-revision-sha1' );
$length = $rev ? $rev->getSize() : 0;
if ( $length === null ) {
// We've had bugs where rev_len was not being recorded for empty pages, see T135414
* @return string
*/
public static function protectionlevel( $parser, $type = '', $title = '' ) {
- $titleObject = Title::newFromText( $title );
- if ( !( $titleObject instanceof Title ) ) {
- $titleObject = $parser->mTitle;
- }
+ $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
$restrictions = $titleObject->getRestrictions( strtolower( $type ) );
# Title::getRestrictions returns an array, its possible it may have
* @return string
*/
public static function protectionexpiry( $parser, $type = '', $title = '' ) {
- $titleObject = Title::newFromText( $title );
- if ( !( $titleObject instanceof Title ) ) {
- $titleObject = $parser->mTitle;
- }
+ $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
$expiry = $titleObject->getRestrictionExpiry( strtolower( $type ) );
// getRestrictionExpiry() returns false on invalid type; trying to
*
* @param Parser $parser
* @param Title $title
+ * @param string $vary ParserOuput vary-* flag
* @return Revision
* @since 1.23
*/
- private static function getCachedRevisionObject( $parser, $title = null ) {
- if ( is_null( $title ) ) {
+ private static function getCachedRevisionObject( $parser, $title, $vary ) {
+ if ( !$title ) {
return null;
}
- // Use the revision from the parser itself, when param is the current page
- // and the revision is the current one
- if ( $title->equals( $parser->getTitle() ) ) {
- $parserRev = $parser->getRevisionObject();
- if ( $parserRev && $parserRev->isCurrent() ) {
- // force reparse after edit with vary-revision flag
- $parser->getOutput()->setFlag( 'vary-revision' );
- wfDebug( __METHOD__ . ": use current revision from parser, setting vary-revision...\n" );
- return $parserRev;
+ $revision = null;
+
+ $isSelfReferential = $title->equals( $parser->getTitle() );
+ if ( $isSelfReferential ) {
+ // Revision is for the same title that is currently being parsed. Only use the last
+ // saved revision, regardless of Parser::getRevisionId() or fake revision injection
+ // callbacks against the current title.
+ $parserRevision = $parser->getRevisionObject();
+ if ( $parserRevision && $parserRevision->isCurrent() ) {
+ $revision = $parserRevision;
+ wfDebug( __METHOD__ . ": used current revision, setting $vary" );
}
}
- // Normalize name for cache
- $page = $title->getPrefixedDBkey();
-
- if ( !( $parser->currentRevisionCache && $parser->currentRevisionCache->has( $page ) )
- && !$parser->incrementExpensiveFunctionCount() ) {
- return null;
+ $parserOutput = $parser->getOutput();
+ if ( !$revision ) {
+ if (
+ !$parser->isCurrentRevisionOfTitleCached( $title ) &&
+ !$parser->incrementExpensiveFunctionCount()
+ ) {
+ return null; // not allowed
+ }
+ // Get the current revision, ignoring Parser::getRevisionId() being null/old
+ $revision = $parser->fetchCurrentRevisionOfTitle( $title );
+ // Register dependency in templatelinks
+ $parserOutput->addTemplate(
+ $title,
+ $revision ? $revision->getPage() : 0,
+ $revision ? $revision->getId() : 0
+ );
}
- $rev = $parser->fetchCurrentRevisionOfTitle( $title );
- $pageID = $rev ? $rev->getPage() : 0;
- $revID = $rev ? $rev->getId() : 0;
- // Register dependency in templatelinks
- $parser->getOutput()->addTemplate( $title, $pageID, $revID );
+ if ( $isSelfReferential ) {
+ // Upon page save, the result of the parser function using this might change
+ $parserOutput->setFlag( $vary );
+ if ( $vary === 'vary-revision-sha1' && $revision ) {
+ $parserOutput->setRevisionUsedSha1Base36( $revision->getSha1() );
+ }
+ }
- return $rev;
+ return $revision;
}
/**
*/
public static function pageid( $parser, $title = null ) {
$t = Title::newFromText( $title );
- if ( is_null( $t ) ) {
+ if ( !$t ) {
return '';
+ } elseif ( !$t->canExist() || $t->isExternal() ) {
+ return 0; // e.g. special page or interwiki link
}
- // Use title from parser to have correct pageid after edit
+
+ $parserOutput = $parser->getOutput();
+
if ( $t->equals( $parser->getTitle() ) ) {
- $t = $parser->getTitle();
- return $t->getArticleID();
- }
+ // Revision is for the same title that is currently being parsed.
+ // Use the title from Parser in case a new page ID was injected into it.
+ $parserOutput->setFlag( 'vary-page-id' );
+ $id = $parser->getTitle()->getArticleID();
+ if ( $id ) {
+ $parserOutput->setSpeculativePageIdUsed( $id );
+ }
- // These can't have ids
- if ( !$t->canExist() || $t->isExternal() ) {
- return 0;
+ return $id;
}
- // Check the link cache, maybe something already looked it up.
+ // Check the link cache for the title
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
$pdbk = $t->getPrefixedDBkey();
$id = $linkCache->getGoodLinkID( $pdbk );
- if ( $id != 0 ) {
- $parser->mOutput->addLink( $t, $id );
- return $id;
- }
- if ( $linkCache->isBadLink( $pdbk ) ) {
- $parser->mOutput->addLink( $t, 0 );
+ if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
+ $parserOutput->addLink( $t, $id );
+
return $id;
}
// We need to load it from the DB, so mark expensive
if ( $parser->incrementExpensiveFunctionCount() ) {
$id = $t->getArticleID();
- $parser->mOutput->addLink( $t, $id );
+ $parserOutput->addLink( $t, $id );
+
return $id;
}
+
return null;
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-id' );
return $rev ? $rev->getId() : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'j' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'd' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'm' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'n' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'Y' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'YmdHis' ) : '';
}
return '';
}
// fetch revision from cache/database and return the value
- $rev = self::getCachedRevisionObject( $parser, $t );
+ $rev = self::getCachedRevisionObject( $parser, $t, 'vary-user' );
return $rev ? $rev->getUserText() : '';
}
* @since 1.23
*/
public static function cascadingsources( $parser, $title = '' ) {
- $titleObject = Title::newFromText( $title );
- if ( !( $titleObject instanceof Title ) ) {
- $titleObject = $parser->mTitle;
- }
+ $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
if ( $titleObject->areCascadeProtectionSourcesLoaded()
|| $parser->incrementExpensiveFunctionCount()
) {