parser: apply $wgMiserMode restriction to self-referencial {{REVISIONID|}}

This restricts the parser function similarly to the magic word.

Bug: T235957
Change-Id: Iead8c44c34cb00583473b502089fd3b85d318cb1
This commit is contained in:
Aaron Schulz 2020-02-07 23:08:25 -08:00 committed by Krinkle
parent f2401df6ad
commit d74f29e006

View file

@ -1152,7 +1152,6 @@ class CoreParserFunctions {
$parserRevision = $parser->getRevisionObject(); $parserRevision = $parser->getRevisionObject();
if ( $parserRevision && $parserRevision->isCurrent() ) { if ( $parserRevision && $parserRevision->isCurrent() ) {
$revision = $parserRevision; $revision = $parserRevision;
wfDebug( __METHOD__ . ": used current revision, setting $vary" );
} }
} }
@ -1175,6 +1174,7 @@ class CoreParserFunctions {
} }
if ( $isSelfReferential ) { if ( $isSelfReferential ) {
wfDebug( __METHOD__ . ": used current revision, setting $vary" );
// Upon page save, the result of the parser function using this might change // Upon page save, the result of the parser function using this might change
$parserOutput->setFlag( $vary ); $parserOutput->setFlag( $vary );
if ( $vary === 'vary-revision-sha1' && $revision ) { if ( $vary === 'vary-revision-sha1' && $revision ) {
@ -1247,6 +1247,23 @@ class CoreParserFunctions {
if ( $t === null ) { if ( $t === null ) {
return ''; return '';
} }
$services = MediaWikiServices::getInstance();
$namespace = $t->getNamespace();
if (
$services->getMainConfig()->get( 'MiserMode' ) &&
!$parser->getOptions()->getInterfaceMessage() &&
// @TODO: disallow this word on all namespaces (T235957)
$services->getNamespaceInfo()->isSubject( $namespace )
) {
// Use a stub result instead of the actual revision ID in order to avoid
// double parses on page save but still allow preview detection (T137900)
if ( $parser->getRevisionId() || $parser->getOptions()->getSpeculativeRevId() ) {
return '-';
} else {
$parser->getOutput()->setFlag( 'vary-revision-exists' );
return '';
}
}
// fetch revision from cache/database and return the value // fetch revision from cache/database and return the value
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-id' ); $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-id' );
return $rev ? $rev->getId() : ''; return $rev ? $rev->getId() : '';