- $oldType = $this->tempType;
- $this->tempType = $type;
- $text = preg_replace_callback( $this->regex, [ $this, 'unstripCallback' ], $text );
- $this->tempType = $oldType;
- return $text;
- }
-
- /**
- * @param array $m
- * @return array
- */
- protected function unstripCallback( $m ) {
- $marker = $m[1];
- if ( isset( $this->data[$this->tempType][$marker] ) ) {
- if ( isset( $this->circularRefGuard[$marker] ) ) {
- return '<span class="error">'
- . wfMessage( 'parser-unstrip-loop-warning' )->inContentLanguage()->text()
- . '</span>';
- }
- if ( $this->recursionLevel >= self::UNSTRIP_RECURSION_LIMIT ) {
- return '<span class="error">' .
- wfMessage( 'parser-unstrip-recursion-limit' )
- ->numParams( self::UNSTRIP_RECURSION_LIMIT )->inContentLanguage()->text() .
- '</span>';
+ $callback = function ( $m ) use ( $type ) {
+ $marker = $m[1];
+ if ( isset( $this->data[$type][$marker] ) ) {
+ if ( isset( $this->circularRefGuard[$marker] ) ) {
+ return '<span class="error">'
+ . wfMessage( 'parser-unstrip-loop-warning' )->inContentLanguage()->text()
+ . '</span>';
+ }
+ if ( $this->recursionLevel >= self::UNSTRIP_RECURSION_LIMIT ) {
+ return '<span class="error">' .
+ wfMessage( 'parser-unstrip-recursion-limit' )
+ ->numParams( self::UNSTRIP_RECURSION_LIMIT )->inContentLanguage()->text() .
+ '</span>';
+ }
+ $this->circularRefGuard[$marker] = true;
+ $this->recursionLevel++;
+ $value = $this->data[$type][$marker];
+ if ( $value instanceof Closure ) {
+ $value = $value();
+ }
+ $ret = $this->unstripType( $type, $value );
+ $this->recursionLevel--;
+ unset( $this->circularRefGuard[$marker] );
+ return $ret;
+ } else {
+ return $m[0];