56 $this->regex =
'/' . Parser::MARKER_PREFIX .
"([^\x7f<>&'\"]+)" . Parser::MARKER_SUFFIX .
'/';
57 $this->circularRefGuard = [];
60 if ( isset( $options[
'depthLimit'] ) ) {
61 $this->depthLimit = $options[
'depthLimit'];
63 if ( isset( $options[
'sizeLimit'] ) ) {
64 $this->sizeLimit = $options[
'sizeLimit'];
93 protected function addItem( $type, $marker, $value ) {
94 if ( !preg_match( $this->regex, $marker, $m ) ) {
95 throw new InvalidArgumentException(
"Invalid marker: $marker" );
98 $this->data[$type][$m[1]] = $value;
124 if ( !count( $this->data[
'nowiki'] ) ) {
128 $callback =
function ( $m ) use ( $callback ) {
130 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
131 $value = $this->data[
'nowiki'][$marker];
132 if ( $value instanceof Closure ) {
136 $this->expandSize += strlen( $value );
137 if ( $this->expandSize > $this->sizeLimit ) {
138 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
141 return call_user_func( $callback, $value );
147 return preg_replace_callback( $this->regex, $callback, $text );
167 if ( !count( $this->data[$type] ) ) {
171 $callback =
function ( $m ) use ( $type ) {
173 if ( isset( $this->data[$type][$marker] ) ) {
174 if ( isset( $this->circularRefGuard[$marker] ) ) {
175 return $this->getWarning(
'parser-unstrip-loop-warning' );
178 if ( $this->depth > $this->highestDepth ) {
179 $this->highestDepth = $this->depth;
181 if ( $this->depth >= $this->depthLimit ) {
182 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
185 $value = $this->data[$type][$marker];
186 if ( $value instanceof Closure ) {
190 $this->expandSize += strlen( $value );
191 if ( $this->expandSize > $this->sizeLimit ) {
192 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
195 $this->circularRefGuard[$marker] =
true;
197 $ret = $this->unstripType( $type, $value );
199 unset( $this->circularRefGuard[$marker] );
207 $text = preg_replace_callback( $this->regex, $callback, $text );