From 62c3fe221f4975e7cab4da130ea7ac4784d3eb6a Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Fri, 19 Dec 2014 02:05:44 -0500 Subject: [PATCH] Allow running code during unstrip When adding strip markers, allow closures to be passed in place of text. The closure is then called during unstrip. Also, add a hook that runs after unstripGeneral. This is needed for Extension:Cite's I0e136f952. Change-Id: If83b0623671fd67e5ccc9deaaaab456a6679af8f --- docs/hooks.txt | 4 ++++ includes/parser/Parser.php | 4 ++++ includes/parser/StripState.php | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 99a9d33a32..f03e38d9f2 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2149,6 +2149,10 @@ $stripState: stripState used (object) $parser: Parser object being used $text: text that will be returned +'ParserAfterUnstrip': Called after the first unstripGeneral() in Parser::internalParseHalfParsed() +$parser: Parser object being used +$text: text that will be returned + 'ParserBeforeInternalParse': Called at the beginning of Parser::internalParse(). $parser: Parser object $text: text to parse diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index ace63a09d6..27de03929d 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1279,6 +1279,10 @@ class Parser { $text = $this->mStripState->unstripGeneral( $text ); + if ( $isMain ) { + Hooks::run( 'ParserAfterUnstrip', array( &$this, &$text ) ); + } + # Clean up special characters, only run once, next-to-last before doBlockLevels $fixtags = array( # french spaces, last one Guillemet-left diff --git a/includes/parser/StripState.php b/includes/parser/StripState.php index 51ae42dc73..7e38acc70c 100644 --- a/includes/parser/StripState.php +++ b/includes/parser/StripState.php @@ -144,7 +144,11 @@ class StripState { } $this->circularRefGuard[$marker] = true; $this->recursionLevel++; - $ret = $this->unstripType( $this->tempType, $this->data[$this->tempType][$marker] ); + $value = $this->data[$this->tempType][$marker]; + if ( $value instanceof Closure ) { + $value = $value(); + } + $ret = $this->unstripType( $this->tempType, $value ); $this->recursionLevel--; unset( $this->circularRefGuard[$marker] ); return $ret; -- 2.20.1