From 7c9d6c0d10789364b62cacfdbaa37b941bda2872 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 14 Nov 2012 16:05:24 -0800 Subject: [PATCH] (bug 32368) Add ParserCloned hook We store various bits of data as "expando" properties on the Parser object, to pass information from one stage of the parser to another. If the parser is cloned, however, we can run into trouble because two different Parser objects are now manipulating the same extension data structure; this often shows up when ParserClearState is called on one clone and clears the state of the other as well. Since a deep clone might be too expensive and still might be wrong in some cases, it seems most useful to simply provide a ParserCloned hook so extensions can just do The Right Thing. Change-Id: Ieec65c908d71e89b9a66f83b9a626f842aadacbb --- docs/hooks.txt | 3 +++ includes/parser/Parser.php | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index 67b4580b75..32182a2d98 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1629,6 +1629,9 @@ $text: actual text 'ParserClearState': called at the end of Parser::clearState() $parser: Parser object being cleared +'ParserCloned': called when the parser is cloned +$parser: Newly-cloned Parser object + 'ParserFirstCallInit': called when the parser initialises for the first time &$parser: Parser object being cleared diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9dad1e5be9..36b682ee48 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -246,6 +246,13 @@ class Parser { } } + /** + * Allow extensions to clean up when the parser is cloned + */ + function __clone() { + wfRunHooks( 'ParserCloned', array( $this ) ); + } + /** * Do various kinds of initialisation on the first call of the parser */ -- 2.20.1