Add ParserFetchTemplate hook
authorGlaisher <glaisher.wiki@gmail.com>
Sat, 27 Aug 2016 16:44:51 +0000 (21:44 +0500)
committerGlaisher <glaisher.wiki@gmail.com>
Sat, 27 Aug 2016 16:56:47 +0000 (21:56 +0500)
This allows extensions to add custom content for transclusion
text if they want.

Bug: T47096
Change-Id: I0de1c96bb968a99a2c81a9977655780a78988a20

docs/hooks.txt
includes/parser/Parser.php

index a0ee8bd..5c0d15b 100644 (file)
@@ -2404,6 +2404,13 @@ $revId: ID of the revision that was parsed to create $parserOutput
 'ParserCloned': Called when the parser is cloned.
 $parser: Newly-cloned Parser object
 
+'ParserFetchTemplate': Called when the parser fetches a template
+$parser: Parser Parser object or false
+$title: Title object of the template to be fetched
+$rev: Revision object of the template
+&$text: Transclusion text of the template or false or null
+&$deps: Array of template dependencies with 'title', 'page_id', 'rev_id' keys
+
 'ParserFirstCallInit': Called when the parser initialises for the first time.
 &$parser: Parser object being cleared
 
index b116bd4..8c7c590 100644 (file)
@@ -3556,6 +3556,9 @@ class Parser {
                                $content = $rev->getContent();
                                $text = $content ? $content->getWikitextForTransclusion() : null;
 
+                               Hooks::run( 'ParserFetchTemplate',
+                                       [ $parser, $title, $rev, &$text, &$deps ] );
+
                                if ( $text === false || $text === null ) {
                                        $text = false;
                                        break;