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
31 lines
847 B
PHP
31 lines
847 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Hook;
|
|
|
|
use Parser;
|
|
use Title;
|
|
|
|
/**
|
|
* This is a hook handler interface, see docs/Hooks.md.
|
|
* Use the hook name "BeforeParserFetchTemplateAndtitle" to register handlers implementing this interface.
|
|
*
|
|
* @deprecated since 1.36
|
|
* @ingroup Hooks
|
|
*/
|
|
interface BeforeParserFetchTemplateAndtitleHook {
|
|
/**
|
|
* This hook is called before a template is fetched by Parser.
|
|
*
|
|
* @since 1.35
|
|
* @deprecated since 1.36; use BeforeParserFetchTemplateRevisionRecordHook
|
|
*
|
|
* @param Parser $parser
|
|
* @param Title $title Title of the template
|
|
* @param bool &$skip Skip this template and link it?
|
|
* @param int &$id ID of the revision being parsed
|
|
* @return bool|void True or no return value to continue or false to abort
|
|
*/
|
|
public function onBeforeParserFetchTemplateAndtitle( $parser, $title, &$skip,
|
|
&$id
|
|
);
|
|
}
|