120 protected function addItem( $type, $marker, $value, ?
string $extra =
null ) {
121 if ( !preg_match( $this->regex, $marker, $m ) ) {
122 throw new InvalidArgumentException(
"Invalid marker: $marker" );
125 $this->data[$type][$m[1]] = $value;
127 $this->extra[$type][$m[1]] =
$extra;
155 if ( !count( $this->data[
'nowiki'] ) ) {
159 $callback =
function ( $m ) use ( $callback ) {
161 if ( isset( $this->data[
'nowiki'][$marker] ) ) {
162 $value = $this->data[
'nowiki'][$marker];
163 if ( $value instanceof Closure ) {
167 $this->expandSize += strlen( $value );
168 if ( $this->expandSize > $this->sizeLimit ) {
169 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
172 return $callback( $value );
178 return preg_replace_callback( $this->regex, $callback, $text );
189 public function split(
string $text ): array {
191 $pieces = preg_split( $this->regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
192 for ( $i = 0; $i < count( $pieces ); $i++ ) {
193 if ( $i % 2 === 0 ) {
196 'content' => $pieces[$i],
200 $marker = $pieces[$i];
201 foreach ( $this->data as $type => $items ) {
202 if ( isset( $items[$marker] ) ) {
203 $value = $items[$marker];
204 $extra = $this->extra[$type][$marker] ??
null;
205 if ( $value instanceof Closure ) {
209 if ( $type ===
'exttag' ) {
212 if ( isset( $this->circularRefGuard[$marker] ) ) {
215 'content' => $this->getWarning(
'parser-unstrip-loop-warning' )
220 if ( $this->depth > $this->highestDepth ) {
221 $this->highestDepth = $this->depth;
223 if ( $this->depth >= $this->depthLimit ) {
226 'content' => $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit )
235 $this->expandSize += strlen( $value );
236 if ( $this->expandSize > $this->sizeLimit ) {
239 'content' => $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit )
244 $this->circularRefGuard[$marker] =
true;
246 $result = array_merge( $result, $this->split( $value ) );
248 unset( $this->circularRefGuard[$marker] );
286 if ( !count( $this->data[$type] ) ) {
290 $callback =
function ( $m ) use ( $type ) {
292 if ( isset( $this->data[$type][$marker] ) ) {
293 if ( isset( $this->circularRefGuard[$marker] ) ) {
294 return $this->getWarning(
'parser-unstrip-loop-warning' );
297 if ( $this->depth > $this->highestDepth ) {
298 $this->highestDepth = $this->depth;
300 if ( $this->depth >= $this->depthLimit ) {
301 return $this->getLimitationWarning(
'unstrip-depth', $this->depthLimit );
304 $value = $this->data[$type][$marker];
305 if ( $value instanceof Closure ) {
309 $this->expandSize += strlen( $value );
310 if ( $this->expandSize > $this->sizeLimit ) {
311 return $this->getLimitationWarning(
'unstrip-size', $this->sizeLimit );
314 $this->circularRefGuard[$marker] =
true;
316 $ret = $this->unstripType( $type, $value );
318 unset( $this->circularRefGuard[$marker] );
326 $text = preg_replace_callback( $this->regex, $callback, $text );