95 if (
$args !==
false ) {
98 } elseif ( !is_array(
$args ) ) {
99 throw new MWException( __METHOD__ .
': $args must be array or PPNode_Hash_Array' );
101 foreach (
$args as $arg ) {
102 $bits = $arg->splitArg();
103 if ( $bits[
'index'] !==
'' ) {
105 $index = $bits[
'index'] - $indexOffset;
106 if ( isset( $namedArgs[$index] ) || isset( $numberedArgs[$index] ) ) {
107 $this->parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
111 $this->parser->addTrackingCategory(
'duplicate-args-category' );
113 $numberedArgs[$index] = $bits[
'value'];
114 unset( $namedArgs[$index] );
118 if ( isset( $namedArgs[$name] ) || isset( $numberedArgs[$name] ) ) {
119 $this->parser->getOutput()->addWarning(
wfMessage(
'duplicate-args-warning',
123 $this->parser->addTrackingCategory(
'duplicate-args-category' );
125 $namedArgs[$name] = $bits[
'value'];
126 unset( $numberedArgs[$name] );
151 public function expand( $root, $flags = 0 ) {
152 static $expansionDepth = 0;
153 if ( is_string( $root ) ) {
157 if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
158 $this->parser->limitationWarn(
'node-count-exceeded',
159 $this->parser->mPPNodeCount,
160 $this->parser->mOptions->getMaxPPNodeCount()
162 return '<span class="error">Node-count limit exceeded</span>';
164 if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
165 $this->parser->limitationWarn(
'expansion-depth-exceeded',
167 $this->parser->mOptions->getMaxPPExpandDepth()
169 return '<span class="error">Expansion depth limit exceeded</span>';
172 if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
173 $this->parser->mHighestExpansionDepth = $expansionDepth;
176 $outStack = [
'',
'' ];
177 $iteratorStack = [
false, $root ];
178 $indexStack = [ 0, 0 ];
180 while ( count( $iteratorStack ) > 1 ) {
181 $level = count( $outStack ) - 1;
182 $iteratorNode =& $iteratorStack[$level];
183 $out =& $outStack[$level];
184 $index =& $indexStack[$level];
186 if ( is_array( $iteratorNode ) ) {
187 if ( $index >= count( $iteratorNode ) ) {
189 $iteratorStack[$level] =
false;
190 $contextNode =
false;
192 $contextNode = $iteratorNode[$index];
196 if ( $index >= $iteratorNode->getLength() ) {
198 $iteratorStack[$level] =
false;
199 $contextNode =
false;
201 $contextNode = $iteratorNode->item( $index );
207 $contextNode = $iteratorStack[$level];
208 $iteratorStack[$level] =
false;
211 $newIterator =
false;
212 $contextName =
false;
213 $contextChildren =
false;
215 if ( $contextNode ===
false ) {
217 } elseif ( is_string( $contextNode ) ) {
218 $out .= $contextNode;
220 $newIterator = $contextNode;
224 $out .= $contextNode->value;
226 $contextName = $contextNode->name;
227 $contextChildren = $contextNode->getRawChildren();
228 } elseif ( is_array( $contextNode ) ) {
230 if ( count( $contextNode ) !== 2 ) {
232 ': found an array where a node descriptor should be' );
234 list( $contextName, $contextChildren ) = $contextNode;
236 throw new MWException( __METHOD__ .
': Invalid parameter type' );
240 if ( $contextName ===
false ) {
242 } elseif ( $contextName[0] ===
'@' ) {
244 } elseif ( $contextName ===
'template' ) {
245 # Double-brace expansion
254 $ret = $this->parser->braceSubstitution( $bits, $this );
255 if ( isset( $ret[
'object'] ) ) {
256 $newIterator = $ret[
'object'];
258 $out .= $ret[
'text'];
261 } elseif ( $contextName ===
'tplarg' ) {
262 # Triple-brace expansion
271 $ret = $this->parser->argSubstitution( $bits, $this );
272 if ( isset( $ret[
'object'] ) ) {
273 $newIterator = $ret[
'object'];
275 $out .= $ret[
'text'];
278 } elseif ( $contextName ===
'comment' ) {
280 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
281 # Not in RECOVER_COMMENTS mode (msgnw) though.
282 if ( ( $this->parser->ot[
'html']
283 || ( $this->parser->ot[
'pre'] && $this->parser->mOptions->getRemoveComments() )
289 # Add a strip marker in PST mode so that pstPass2() can
290 # run some old-fashioned regexes on the result.
291 # Not in RECOVER_COMMENTS mode (extractSections) though.
292 $out .= $this->parser->insertStripItem( $contextChildren[0] );
294 # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
295 $out .= $contextChildren[0];
297 } elseif ( $contextName ===
'ignore' ) {
298 # Output suppression used by <includeonly> etc.
299 # OT_WIKI will only respect <ignore> in substed templates.
300 # The other output types respect it unless NO_IGNORE is set.
301 # extractSections() sets NO_IGNORE and so never respects it.
302 if ( ( !isset( $this->parent ) && $this->parser->ot[
'wiki'] )
305 $out .= $contextChildren[0];
309 } elseif ( $contextName ===
'ext' ) {
312 [
'attr' =>
null,
'inner' =>
null,
'close' => null ];
314 $s =
'<' . $bits[
'name']->getFirstChild()->value;
315 if ( $bits[
'attr'] ) {
316 $s .= $bits[
'attr']->getFirstChild()->value;
318 if ( $bits[
'inner'] ) {
319 $s .=
'>' . $bits[
'inner']->getFirstChild()->value;
320 if ( $bits[
'close'] ) {
321 $s .= $bits[
'close']->getFirstChild()->value;
328 $out .= $this->parser->extensionSubstitution( $bits, $this );
330 } elseif ( $contextName ===
'h' ) {
332 if ( $this->parser->ot[
'html'] ) {
333 # Expand immediately and insert heading index marker
334 $s = $this->
expand( $contextChildren, $flags );
336 $titleText = $this->title->getPrefixedDBkey();
337 $this->parser->mHeadings[] = [ $titleText, $bits[
'i'] ];
338 $serial = count( $this->parser->mHeadings ) - 1;
339 $marker = Parser::MARKER_PREFIX .
"-h-$serial-" . Parser::MARKER_SUFFIX;
340 $s = substr(
$s, 0, $bits[
'level'] ) . $marker . substr(
$s, $bits[
'level'] );
341 $this->parser->mStripState->addGeneral( $marker,
'' );
344 # Expand in virtual stack
345 $newIterator = $contextChildren;
348 # Generic recursive expansion
349 $newIterator = $contextChildren;
352 if ( $newIterator !==
false ) {
354 $iteratorStack[] = $newIterator;
356 } elseif ( $iteratorStack[$level] ===
false ) {
359 while ( $iteratorStack[$level] ===
false && $level > 0 ) {
360 $outStack[$level - 1] .= $out;
361 array_pop( $outStack );
362 array_pop( $iteratorStack );
363 array_pop( $indexStack );