Allow running code during unstrip
authorJackmcbarn <jackmcbarn@users.noreply.github.com>
Fri, 19 Dec 2014 07:05:44 +0000 (02:05 -0500)
committerTim Starling <tstarling@wikimedia.org>
Wed, 13 May 2015 02:44:20 +0000 (02:44 +0000)
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
includes/parser/Parser.php
includes/parser/StripState.php

index 99a9d33..f03e38d 100644 (file)
@@ -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
index ace63a0..27de039 100644 (file)
@@ -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
index 51ae42d..7e38acc 100644 (file)
@@ -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;