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
36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Hook;
|
|
|
|
use MediaWiki\Linker\LinkTarget;
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
/**
|
|
* @stable to implement
|
|
* @ingroup Hooks
|
|
*/
|
|
interface BeforeParserFetchTemplateRevisionRecordHook {
|
|
/**
|
|
* This hook is called before a template is fetched by Parser.
|
|
* It allows redirection of the title and/or revision id of the
|
|
* template. For example: the template could be redirected to
|
|
* an appropriately localized version of the template; or the
|
|
* template fetch could be redirected to a 'stable revision' of
|
|
* the template. If the returned RevisionRecord does not exist,
|
|
* its title will be added to the page dependencies and then this
|
|
* hook will be invoked again to resolve that title. This allows
|
|
* for fallback chains (of limited length).
|
|
*
|
|
* @since 1.36
|
|
*
|
|
* @param ?LinkTarget $contextTitle The top-level page title, if any
|
|
* @param LinkTarget $title The template link (from the literal wikitext)
|
|
* @param bool &$skip Skip this template and link it?
|
|
* @param ?RevisionRecord &$revRecord The desired revision record
|
|
* @return bool|void True or no return value to continue or false to abort
|
|
*/
|
|
public function onBeforeParserFetchTemplateRevisionRecord(
|
|
?LinkTarget $contextTitle, LinkTarget $title,
|
|
bool &$skip, ?RevisionRecord &$revRecord
|
|
);
|
|
}
|