protected $regex;
protected $tempType, $tempMergePrefix;
+ protected $circularRefGuard;
+ protected $recursionLevel = 0;
+
+ const UNSTRIP_RECURSION_LIMIT = 20;
/**
* @param $prefix string
'general' => array()
);
$this->regex = "/{$this->prefix}([^\x7f]+)" . Parser::MARKER_SUFFIX . '/';
+ $this->circularRefGuard = array();
}
/**
}
wfProfileIn( __METHOD__ );
+ $oldType = $this->tempType;
$this->tempType = $type;
- do {
- $oldText = $text;
- $text = preg_replace_callback( $this->regex, array( $this, 'unstripCallback' ), $text );
- } while ( $text !== $oldText );
- $this->tempType = null;
+ $text = preg_replace_callback( $this->regex, array( $this, 'unstripCallback' ), $text );
+ $this->tempType = $oldType;
wfProfileOut( __METHOD__ );
return $text;
}
* @return array
*/
protected function unstripCallback( $m ) {
- if ( isset( $this->data[$this->tempType][$m[1]] ) ) {
- return $this->data[$this->tempType][$m[1]];
+ $marker = $m[1];
+ if ( isset( $this->data[$this->tempType][$marker] ) ) {
+ if ( isset( $this->circularRefGuard[$marker] ) ) {
+ return '<span class="error">' . wfMsgForContent( 'parser-unstrip-loop-warning' ) . '</span>';
+ }
+ if ( $this->recursionLevel >= self::UNSTRIP_RECURSION_LIMIT ) {
+ return '<span class="error">' .
+ wfMsgForContent( 'parser-unstrip-recursion-limit', self::UNSTRIP_RECURSION_LIMIT ) .
+ '</span>';
+ }
+ $this->circularRefGuard[$marker] = true;
+ $this->recursionLevel++;
+ $ret = $this->unstripType( $this->tempType, $this->data[$this->tempType][$marker] );
+ $this->recursionLevel--;
+ unset( $this->circularRefGuard[$marker] );
+ return $ret;
} else {
return $m[0];
}
'node-count-exceeded-warning' => 'Page exceeded the node-count',
'expansion-depth-exceeded-category' => 'Pages where expansion depth is exceeded',
'expansion-depth-exceeded-warning' => 'Page exceeded the expansion depth',
+'parser-unstrip-loop-warning' => 'Unstrip loop detected',
+'parser-unstrip-recursion-limit' => 'Unstrip recursion limit exceeded ($1)',
# "Undo" feature
'undo-success' => 'The edit can be undone.