54 $this->regex =
'/' . Parser::MARKER_PREFIX .
"([^\x7f<>&'\"]+)" . Parser::MARKER_SUFFIX .
'/';
55 $this->circularRefGuard = [];
58 if ( isset( $options[
'depthLimit'] ) ) {
59 $this->depthLimit = $options[
'depthLimit'];
61 if ( isset( $options[
'sizeLimit'] ) ) {
62 $this->sizeLimit = $options[
'sizeLimit'];
91 protected function addItem( $type, $marker, $value ) {
92 if ( !preg_match( $this->regex, $marker, $m ) ) {
93 throw new InvalidArgumentException(
"Invalid marker: $marker" );
96 $this->data[$type][$m[1]] = $value;
122 if ( !count( $this->data[
'nowiki'] ) ) {
126 $callback =
function ( $m ) use ( $callback ) {
128 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
129 $value = $this->data[
'nowiki'][$marker];
130 if ( $value instanceof Closure ) {
134 $this->expandSize += strlen( $value );
135 if ( $this->expandSize > $this->sizeLimit ) {
136 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
139 return call_user_func( $callback, $value );
145 return preg_replace_callback( $this->regex, $callback, $text );
165 if ( !count( $this->data[$type] ) ) {
169 $callback =
function ( $m ) use ( $type ) {
171 if ( isset( $this->data[$type][$marker] ) ) {
172 if ( isset( $this->circularRefGuard[$marker] ) ) {
173 return $this->getWarning(
'parser-unstrip-loop-warning' );
176 if ( $this->depth > $this->highestDepth ) {
177 $this->highestDepth = $this->depth;
179 if ( $this->depth >= $this->depthLimit ) {
180 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
183 $value = $this->data[$type][$marker];
184 if ( $value instanceof Closure ) {
188 $this->expandSize += strlen( $value );
189 if ( $this->expandSize > $this->sizeLimit ) {
190 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
193 $this->circularRefGuard[$marker] =
true;
195 $ret = $this->unstripType( $type, $value );
197 unset( $this->circularRefGuard[$marker] );
205 $text = preg_replace_callback( $this->regex, $callback, $text );