2013-12-18 23:44:54 +00:00
|
|
|
<?php
|
2014-02-05 02:35:48 +00:00
|
|
|
/**
|
|
|
|
|
* Benchmark script for parse operations
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Tim Starling <tstarling@wikimedia.org>
|
|
|
|
|
* @ingroup Benchmark
|
|
|
|
|
*/
|
2013-12-18 23:44:54 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2021-01-08 02:16:02 +00:00
|
|
|
require_once __DIR__ . '/../Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2013-12-18 23:44:54 +00:00
|
|
|
|
2024-02-08 19:09:50 +00:00
|
|
|
use MediaWiki\Cache\LinkCache;
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2024-10-16 00:39:55 +00:00
|
|
|
use MediaWiki\Maintenance\Maintenance;
|
2020-04-15 21:50:29 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-07-25 13:37:41 +00:00
|
|
|
use Wikimedia\Rdbms\SelectQueryBuilder;
|
2016-09-15 06:55:35 +00:00
|
|
|
|
2014-02-05 02:35:48 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to benchmark how long it takes to parse a given title at an optionally
|
|
|
|
|
* specified timestamp
|
|
|
|
|
*
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
2013-12-18 23:44:54 +00:00
|
|
|
class BenchmarkParse extends Maintenance {
|
|
|
|
|
/** @var string MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS) */
|
2014-02-05 02:35:48 +00:00
|
|
|
private $templateTimestamp = null;
|
2013-12-18 23:44:54 +00:00
|
|
|
|
2024-09-12 19:59:28 +00:00
|
|
|
/** @var bool */
|
2016-09-15 06:55:35 +00:00
|
|
|
private $clearLinkCache = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var LinkCache
|
|
|
|
|
*/
|
|
|
|
|
private $linkCache;
|
|
|
|
|
|
2014-02-05 02:35:48 +00:00
|
|
|
/** @var array Cache that maps a Title DB key to revision ID for the requested timestamp */
|
2016-02-17 09:09:32 +00:00
|
|
|
private $idCache = [];
|
2013-12-18 23:44:54 +00:00
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct() {
|
2013-12-18 23:44:54 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
$this->addDescription( 'Benchmark parse operation' );
|
|
|
|
|
$this->addArg( 'title', 'The name of the page to parse' );
|
2014-07-16 00:23:27 +00:00
|
|
|
$this->addOption( 'warmup', 'Repeat the parse operation this number of times to warm the cache',
|
|
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'loops', 'Number of times to repeat parse operation post-warmup',
|
|
|
|
|
false, true );
|
2013-12-18 23:44:54 +00:00
|
|
|
$this->addOption( 'page-time',
|
|
|
|
|
'Use the version of the page which was current at the given time',
|
|
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'tpl-time',
|
2014-02-05 02:35:48 +00:00
|
|
|
'Use templates which were current at the given time (except that moves and ' .
|
2014-04-23 18:08:42 +00:00
|
|
|
'deletes are not handled properly)',
|
2013-12-18 23:44:54 +00:00
|
|
|
false, true );
|
2016-09-15 06:55:35 +00:00
|
|
|
$this->addOption( 'reset-linkcache', 'Reset the LinkCache after every parse.',
|
|
|
|
|
false, false );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function execute() {
|
2013-12-18 23:44:54 +00:00
|
|
|
if ( $this->hasOption( 'tpl-time' ) ) {
|
|
|
|
|
$this->templateTimestamp = wfTimestamp( TS_MW, strtotime( $this->getOption( 'tpl-time' ) ) );
|
2023-05-18 15:21:26 +00:00
|
|
|
$hookContainer = $this->getHookContainer();
|
|
|
|
|
$hookContainer->register( 'BeforeParserFetchTemplateRevisionRecord', [ $this, 'onFetchTemplate' ] );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2016-09-15 06:55:35 +00:00
|
|
|
$this->clearLinkCache = $this->hasOption( 'reset-linkcache' );
|
|
|
|
|
// Set as a member variable to avoid function calls when we're timing the parse
|
2023-08-31 09:21:12 +00:00
|
|
|
$this->linkCache = $this->getServiceContainer()->getLinkCache();
|
2016-09-15 06:55:35 +00:00
|
|
|
|
2019-02-28 11:13:49 +00:00
|
|
|
$title = Title::newFromText( $this->getArg( 0 ) );
|
2013-12-18 23:44:54 +00:00
|
|
|
if ( !$title ) {
|
2021-08-30 18:54:47 +00:00
|
|
|
$this->fatalError( "Invalid title" );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$revLookup = $this->getServiceContainer()->getRevisionLookup();
|
2013-12-18 23:44:54 +00:00
|
|
|
if ( $this->hasOption( 'page-time' ) ) {
|
|
|
|
|
$pageTimestamp = wfTimestamp( TS_MW, strtotime( $this->getOption( 'page-time' ) ) );
|
|
|
|
|
$id = $this->getRevIdForTime( $title, $pageTimestamp );
|
|
|
|
|
if ( !$id ) {
|
2021-08-30 18:54:47 +00:00
|
|
|
$this->fatalError( "The page did not exist at that time" );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-05 20:05:01 +00:00
|
|
|
$revision = $revLookup->getRevisionById( (int)$id );
|
2013-12-18 23:44:54 +00:00
|
|
|
} else {
|
2020-04-15 21:50:29 +00:00
|
|
|
$revision = $revLookup->getRevisionByTitle( $title );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2013-12-18 23:44:54 +00:00
|
|
|
if ( !$revision ) {
|
2021-08-30 18:54:47 +00:00
|
|
|
$this->fatalError( "Unable to load revision, incorrect title?" );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2014-07-16 00:23:27 +00:00
|
|
|
$warmup = $this->getOption( 'warmup', 1 );
|
|
|
|
|
for ( $i = 0; $i < $warmup; $i++ ) {
|
2013-12-18 23:44:54 +00:00
|
|
|
$this->runParser( $revision );
|
|
|
|
|
}
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2014-07-16 00:23:27 +00:00
|
|
|
$loops = $this->getOption( 'loops', 1 );
|
|
|
|
|
if ( $loops < 1 ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( 'Invalid number of loops specified' );
|
2014-07-16 00:23:27 +00:00
|
|
|
}
|
2013-12-18 23:44:54 +00:00
|
|
|
$startUsage = getrusage();
|
|
|
|
|
$startTime = microtime( true );
|
2014-07-16 00:23:27 +00:00
|
|
|
for ( $i = 0; $i < $loops; $i++ ) {
|
|
|
|
|
$this->runParser( $revision );
|
|
|
|
|
}
|
2013-12-18 23:44:54 +00:00
|
|
|
$endUsage = getrusage();
|
|
|
|
|
$endTime = microtime( true );
|
|
|
|
|
|
|
|
|
|
printf( "CPU time = %.3f s, wall clock time = %.3f s\n",
|
2014-02-05 02:35:48 +00:00
|
|
|
// CPU time
|
2014-07-16 00:23:27 +00:00
|
|
|
( $endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1e-6
|
|
|
|
|
- $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6 ) / $loops,
|
2014-02-05 02:35:48 +00:00
|
|
|
// Wall clock time
|
2014-07-16 00:23:27 +00:00
|
|
|
( $endTime - $startTime ) / $loops
|
|
|
|
|
);
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-05 02:35:48 +00:00
|
|
|
* Fetch the ID of the revision of a Title that occurred
|
|
|
|
|
*
|
2013-12-18 23:44:54 +00:00
|
|
|
* @param Title $title
|
|
|
|
|
* @param string $timestamp
|
2014-02-05 02:35:48 +00:00
|
|
|
* @return bool|string Revision ID, or false if not found or error
|
2013-12-18 23:44:54 +00:00
|
|
|
*/
|
2019-10-11 19:07:32 +00:00
|
|
|
private function getRevIdForTime( Title $title, $timestamp ) {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2014-02-05 02:35:48 +00:00
|
|
|
|
2023-07-25 13:37:41 +00:00
|
|
|
$id = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( 'rev_id' )
|
|
|
|
|
->from( 'revision' )
|
|
|
|
|
->join( 'page', null, 'rev_page=page_id' )
|
|
|
|
|
->where( [ 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() ] )
|
2024-01-17 17:48:40 +00:00
|
|
|
->andWhere( $dbr->expr( 'rev_timestamp', '<=', $timestamp ) )
|
2023-07-25 13:37:41 +00:00
|
|
|
->orderBy( 'rev_timestamp', SelectQueryBuilder::SORT_DESC )
|
|
|
|
|
->caller( __METHOD__ )->fetchField();
|
2013-12-18 23:44:54 +00:00
|
|
|
|
|
|
|
|
return $id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-02 23:55:07 +00:00
|
|
|
* Parse the text from a given RevisionRecord
|
2014-02-05 02:35:48 +00:00
|
|
|
*
|
2020-04-15 21:50:29 +00:00
|
|
|
* @param RevisionRecord $revision
|
2013-12-18 23:44:54 +00:00
|
|
|
*/
|
2020-04-15 21:50:29 +00:00
|
|
|
private function runParser( RevisionRecord $revision ) {
|
|
|
|
|
$content = $revision->getContent( SlotRecord::MAIN );
|
2023-08-31 09:21:12 +00:00
|
|
|
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
2021-10-25 19:15:52 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable getId does not return null here
|
2021-10-14 14:01:58 +00:00
|
|
|
$contentRenderer->getParserOutput( $content, $revision->getPage(), $revision->getId() );
|
2016-09-15 06:55:35 +00:00
|
|
|
if ( $this->clearLinkCache ) {
|
|
|
|
|
$this->linkCache->clear();
|
|
|
|
|
}
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-05 02:35:48 +00:00
|
|
|
* Hook into the parser's revision ID fetcher. Make sure that the parser only
|
|
|
|
|
* uses revisions around the specified timestamp.
|
|
|
|
|
*
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
* @param ?LinkTarget $contextTitle
|
|
|
|
|
* @param LinkTarget $titleTarget
|
2014-02-05 02:35:48 +00:00
|
|
|
* @param bool &$skip
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
* @param ?RevisionRecord &$revRecord
|
2013-12-18 23:44:54 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
private function onFetchTemplate(
|
|
|
|
|
?LinkTarget $contextTitle,
|
|
|
|
|
LinkTarget $titleTarget,
|
|
|
|
|
bool &$skip,
|
|
|
|
|
?RevisionRecord &$revRecord
|
|
|
|
|
): bool {
|
2023-04-22 13:57:00 +00:00
|
|
|
$title = Title::newFromLinkTarget( $titleTarget );
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
|
2013-12-18 23:44:54 +00:00
|
|
|
$pdbk = $title->getPrefixedDBkey();
|
|
|
|
|
if ( !isset( $this->idCache[$pdbk] ) ) {
|
|
|
|
|
$proposedId = $this->getRevIdForTime( $title, $this->templateTimestamp );
|
|
|
|
|
$this->idCache[$pdbk] = $proposedId;
|
|
|
|
|
}
|
|
|
|
|
if ( $this->idCache[$pdbk] !== false ) {
|
2023-08-31 09:21:12 +00:00
|
|
|
$revLookup = $this->getServiceContainer()->getRevisionLookup();
|
parser: new BeforeParserFetchTemplateRevisionRecord hook
This new hook provides for the use case in T47096 (allowing the
Translate extension to transclude a page from another language) by
adding a new hook which would let us deprecate and replace two awkward
legacy hooks (one with an embarrassing capitalization issue). The new
hook is a little more tightly scoped in terms of what it allows and
gives access to, and it uses the new RevisionRecord API.
In addition, the new hook uses LinkTarget instead of Title per
current best practices. (PageIdentity is not appropriate for
reasons documented at the hook invocation site.)
The original BeforeParserFetchTemplateAndtitle (sic) hook allowed
redirecting the revision id of a template inclusion, but not the
title. The only known current use is Extension:ApprovedRevs; the
FlaggedRevs extension replaces the entire function using
ParserOptions::setCurrentRevisionRecordCallback().
Extension:Translate would like to redirect the title as well, possibly
recursively (for a limited number of hops) to handle fallback
languages. That is, when invoked on Foo/fr, including Template:Bar
would redirect to Template:Bar/fr -- and, if that doesn't exist, then
Template:Bar/fr would redirect to its fallback language, say
Template:Bar/en. It uses the top-level page title as context to set
the desired page language. This would require 2 invocations of the
hook; we've set the recursion limit to 3 to provide a little bit
of future-proofing.
The hook added in this patch uses RevisionRecord instead of int
$rev_id, and thus can handle the case where the redirect is to a page
which doesn't exist (by setting the RevisionRecord to a
MutableRevisionRecord with the correct title and no main slot content)
in the fallback language case above.
The new hook deprecates BeforeParserFetchTemplateAndtitle and replaces
ParserFetchTemplate as well (deprecated in 1.35). Code search:
https://codesearch.wmcloud.org/search/?q=BeforeParserFetchTemplateAndtitle&i=nope&files=&repos=
Bug: T47096
Change-Id: Ia5b5d339706ce4084c16948300e0e3418b11792e
2020-07-29 23:32:45 +00:00
|
|
|
$revRecord = $revLookup->getRevisionById( $this->idCache[$pdbk] );
|
2013-12-18 23:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = BenchmarkParse::class;
|
2021-01-08 02:16:02 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|