Manual:Hooks/ParserFetchTemplateData
From Linux Web Expert
<translate> Tracked in [[<tvar name=1>phabricator:</tvar>|Phabricator]]</translate>
<translate> Task <tvar name=1>T213228</tvar></translate>
<translate> Task <tvar name=1>T213228</tvar></translate>
ParserFetchTemplateData | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar (Gerrit change 494817)</tvar></translate> Fetches template data for an array of template titles | |
<translate> Define function:</translate> | public static function onParserFetchTemplateData( array $titles, array &$ret ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"ParserFetchTemplateData": "MediaWiki\\Extension\\MyExtension\\Hooks::onParserFetchTemplateData"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> includes/parser/Parsoid/Config/DataAccess.php <translate> Function(s):</translate> fetchTemplateData |
<translate> Interface:</translate> | ParserFetchTemplateDataHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ParserFetchTemplateData extensions</tvar>.</translate>
Parameters
$titles
: 1-dimensional array of strings, representing template titles&$templateData
: array map (contains key-value pairs) passed by reference, which can be modified by extensions to send their own template data
Use cases
Currently, TemplateData uses this extension. TemplateData adds each template title to the $templateData
map, and will assign one of the following values:
- If a title is invalid title or is an invalid redirect title, gives a
null
value - If a title doesn't exist, will assign it a
'missing'
key assigned withtrue
- If a title has invalid data from the database, or does not have a
'templatedata'
property in the page_props table, assign it as:(object)[ "notemplatedata" => true ]
Notes
- This hook originally lived inside the PHP Parsoid service.
- This hook was originally named "ParsoidFetchTemplateData" in Gerrit change 494817, and renamed to "ParserFetchTemplateData" in Gerrit change 552666.
- This hook was moved from Parsoid to core in Gerrit change 774532.
- See also <translate> task <tvar name=1>T304899</tvar></translate> for future improvements to this hook.