119if ( $args !==
false ) {
121 $args = $args->value;
122 } elseif ( !is_array( $args ) ) {
123thrownew InvalidArgumentException( __METHOD__ .
': $args must be array or PPNode_Hash_Array' );
125foreach ( $args as $arg ) {
126 $bits = $arg->splitArg();
127if ( $bits[
'index'] !==
'' ) {
129 $index = $bits[
'index'] - $indexOffset;
130if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
131 $this->parser->getOutput()->addWarningMsg(
132'duplicate-args-warning',
137 $this->parser->addTrackingCategory(
'duplicate-args-category' );
139 $numberedArgs[$index] = $bits[
'value'];
140 unset( $namedArgs[$index] );
144if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
145 $this->parser->getOutput()->addWarningMsg(
146'duplicate-args-warning',
151 $this->parser->addTrackingCategory(
'duplicate-args-category' );
153 $namedArgs[$name] = $bits[
'value'];
154 unset( $numberedArgs[$name] );
177publicfunctionexpand( $root, $flags = 0 ) {
178static $expansionDepth = 0;
179if ( is_string( $root ) ) {
183if ( ++$this->parser->mPPNodeCount > $this->maxPPNodeCount ) {
184 $this->parser->limitationWarn(
'node-count-exceeded',
185 $this->parser->mPPNodeCount,
186 $this->maxPPNodeCount
188return'<span class="error">Node-count limit exceeded</span>';
190if ( $expansionDepth > $this->maxPPExpandDepth ) {
191 $this->parser->limitationWarn(
'expansion-depth-exceeded',
193 $this->maxPPExpandDepth
195return'<span class="error">Expansion depth limit exceeded</span>';
198if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
199 $this->parser->mHighestExpansionDepth = $expansionDepth;
202 $outStack = [
'',
'' ];
203 $iteratorStack = [
false, $root ];
204 $indexStack = [ 0, 0 ];
206while ( count( $iteratorStack ) > 1 ) {
207 $level = count( $outStack ) - 1;
208 $iteratorNode =& $iteratorStack[$level];
209 $out =& $outStack[$level];
210 $index =& $indexStack[$level];
212if ( is_array( $iteratorNode ) ) {
213if ( $index >= count( $iteratorNode ) ) {
214// All done with this iterator 215 $iteratorStack[$level] =
false;
218 $contextNode = $iteratorNode[$index];
222if ( $index >= $iteratorNode->getLength() ) {
223// All done with this iterator 224 $iteratorStack[$level] =
false;
227 $contextNode = $iteratorNode->item( $index );
231// Copy to $contextNode and then delete from iterator stack, 232// because this is not an iterator but we do have to execute it once 233 $contextNode = $iteratorStack[$level];
234 $iteratorStack[$level] =
false;
239 $contextChildren =
false;
241if ( $contextNode ===
false ) {
243 } elseif ( is_string( $contextNode ) ) {
244 $out .= $contextNode;
246 $newIterator = $contextNode;
250 $out .= $contextNode->value;
252 $contextName = $contextNode->name;
253 $contextChildren = $contextNode->getRawChildren();
254 } elseif ( is_array( $contextNode ) ) {
255// Node descriptor array 256if ( count( $contextNode ) !== 2 ) {
257thrownew RuntimeException( __METHOD__ .
258': found an array where a node descriptor should be' );
260 [ $contextName, $contextChildren ] = $contextNode;
262thrownew RuntimeException( __METHOD__ .
': Invalid parameter type' );
265// Handle node descriptor array or tree object 266if ( $contextName ===
false ) {
267// Not a node, already handled above 268 } elseif ( $contextName[0] ===
'@' ) {
269// Attribute: no output 270 } elseif ( $contextName ===
'template' ) {
271 # Double-brace expansion 280 $ret = $this->parser->braceSubstitution( $bits, $this );
281if ( isset( $ret[
'object'] ) ) {
282 $newIterator = $ret[
'object'];
284 $out .= $ret[
'text'];
287 } elseif ( $contextName ===
'tplarg' ) {
288 # Triple-brace expansion 297 $ret = $this->parser->argSubstitution( $bits, $this );
298if ( isset( $ret[
'object'] ) ) {
299 $newIterator = $ret[
'object'];
301 $out .= $ret[
'text'];
304 } elseif ( $contextName ===
'comment' ) {
306 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes 307 # Not in RECOVER_COMMENTS mode (msgnw) though. 310 $this->parser->getOptions()->getRemoveComments() )
319 # Add a strip marker in PST mode so that pstPass2() can 320 # run some old-fashioned regexes on the result. 321 # Not in RECOVER_COMMENTS mode (extractSections) though. 322 $out .= $this->parser->insertStripItem( $contextChildren[0] );
324 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove 325 $out .= $contextChildren[0];
327 } elseif ( $contextName ===
'ignore' ) {
328 # Output suppression used by <includeonly> etc. 329 # OT_WIKI will only respect <ignore> in substed templates. 330 # The other output types respect it unless NO_IGNORE is set. 331 # extractSections() sets NO_IGNORE and so never respects it. 332if ( ( !isset( $this->parent ) && $this->parser->getOutputType() ===
Parser::OT_WIKI )
335 $out .= $contextChildren[0];
339 } elseif ( $contextName ===
'ext' ) {
342 [
'attr' =>
null,
'inner' =>
null,
'close' => null ];
344 $s =
'<' . $bits[
'name']->getFirstChild()->value;
345// @phan-suppress-next-line PhanTypeArraySuspiciousNullable 346if ( $bits[
'attr'] ) {
347 $s .= $bits[
'attr']->getFirstChild()->value;
349// @phan-suppress-next-line PhanTypeArraySuspiciousNullable 350if ( $bits[
'inner'] ) {
351 $s .=
'>' . $bits[
'inner']->getFirstChild()->value;
352// @phan-suppress-next-line PhanTypeArraySuspiciousNullable 353if ( $bits[
'close'] ) {
354 $s .= $bits[
'close']->getFirstChild()->value;
361 $out .= $this->parser->extensionSubstitution( $bits, $this,
364 } elseif ( $contextName ===
'h' ) {
367 # Expand immediately and insert heading index marker 368 $s = $this->
expand( $contextChildren, $flags );
370 $titleText = $this->title->getPrefixedDBkey();
371 $this->parser->mHeadings[] = [ $titleText, $bits[
'i'] ];
372 $serial = count( $this->parser->mHeadings ) - 1;
374 $s = substr( $s, 0, $bits[
'level'] ) . $marker . substr( $s, $bits[
'level'] );
375 $this->parser->getStripState()->addGeneral( $marker,
'' );
378 # Expand in virtual stack 379 $newIterator = $contextChildren;
382 # Generic recursive expansion 383 $newIterator = $contextChildren;
386if ( $newIterator !==
false ) {
388 $iteratorStack[] = $newIterator;
390 } elseif ( $iteratorStack[$level] ===
false ) {
391// Return accumulated value to parent 392// With tail recursion 393while ( $iteratorStack[$level] ===
false && $level > 0 ) {
394 $outStack[$level - 1] .= $out;
395 array_pop( $outStack );
396 array_pop( $iteratorStack );
397 array_pop( $indexStack );