3 * Preprocessor using PHP's dom extension
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 * @deprecated since 1.34, use Preprocessor_Hash
28 // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
29 class Preprocessor_DOM
extends Preprocessor
{
38 const CACHE_PREFIX
= 'preprocess-xml';
41 * @param Parser $parser
43 public function __construct( $parser ) {
44 wfDeprecated( __METHOD__
, '1.34' ); // T204945
45 $this->parser
= $parser;
46 $mem = ini_get( 'memory_limit' );
47 $this->memoryLimit
= false;
48 if ( strval( $mem ) !== '' && $mem != -1 ) {
49 if ( preg_match( '/^\d+$/', $mem ) ) {
50 $this->memoryLimit
= $mem;
51 } elseif ( preg_match( '/^(\d+)M$/i', $mem, $m ) ) {
52 $this->memoryLimit
= $m[1] * 1048576;
60 public function newFrame() {
61 return new PPFrame_DOM( $this );
66 * @return PPCustomFrame_DOM
68 public function newCustomFrame( $args ) {
69 return new PPCustomFrame_DOM( $this, $args );
73 * @param array $values
77 public function newPartNodeArray( $values ) {
78 // NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
81 foreach ( $values as $k => $val ) {
83 $xml .= "<part><name index=\"$k\"/><value>"
84 . htmlspecialchars( $val ) . "</value></part>";
86 $xml .= "<part><name>" . htmlspecialchars( $k )
87 . "</name>=<value>" . htmlspecialchars( $val ) . "</value></part>";
93 $dom = new DOMDocument();
94 Wikimedia\
suppressWarnings();
95 $result = $dom->loadXML( $xml );
96 Wikimedia\restoreWarnings
();
98 // Try running the XML through UtfNormal to get rid of invalid characters
99 $xml = UtfNormal\Validator
::cleanUp( $xml );
100 // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2
101 // don't barf when the XML is >256 levels deep
102 $result = $dom->loadXML( $xml, 1 << 19 );
106 throw new MWException( 'Parameters passed to ' . __METHOD__
. ' result in invalid XML' );
109 $root = $dom->documentElement
;
110 $node = new PPNode_DOM( $root->childNodes
);
115 * @throws MWException
118 public function memCheck() {
119 if ( $this->memoryLimit
=== false ) {
122 $usage = memory_get_usage();
123 if ( $usage > $this->memoryLimit
* 0.9 ) {
124 $limit = intval( $this->memoryLimit
* 0.9 / 1048576 +
0.5 );
125 throw new MWException( "Preprocessor hit 90% memory limit ($limit MB)" );
127 return $usage <= $this->memoryLimit
* 0.8;
131 * Preprocess some wikitext and return the document tree.
132 * This is the ghost of Parser::replace_variables().
134 * @param string $text The text to parse
135 * @param int $flags Bitwise combination of:
136 * Parser::PTD_FOR_INCLUSION Handle "<noinclude>" and "<includeonly>"
137 * as if the text is being included. Default
138 * is to assume a direct page view.
140 * The generated DOM tree must depend only on the input text and the flags.
141 * The DOM tree must be the same in OT_HTML and OT_WIKI mode, to avoid a regression of T6899.
143 * Any flag added to the $flags parameter here, or any other parameter liable to cause a
144 * change in the DOM tree for a given text, must be passed through the section identifier
145 * in the section edit link and thus back to extractSections().
147 * The output of this function is currently only cached in process memory, but a persistent
148 * cache may be implemented at a later date which takes further advantage of these strict
149 * dependency requirements.
151 * @throws MWException
154 public function preprocessToObj( $text, $flags = 0 ) {
155 $xml = $this->cacheGetTree( $text, $flags );
156 if ( $xml === false ) {
157 $xml = $this->preprocessToXml( $text, $flags );
158 $this->cacheSetTree( $text, $flags, $xml );
161 // Fail if the number of elements exceeds acceptable limits
162 // Do not attempt to generate the DOM
163 $this->parser
->mGeneratedPPNodeCount +
= substr_count( $xml, '<' );
164 $max = $this->parser
->mOptions
->getMaxGeneratedPPNodeCount();
165 if ( $this->parser
->mGeneratedPPNodeCount
> $max ) {
166 // if ( $cacheable ) { ... }
167 throw new MWException( __METHOD__
. ': generated node count limit exceeded' );
170 $dom = new DOMDocument
;
171 Wikimedia\
suppressWarnings();
172 $result = $dom->loadXML( $xml );
173 Wikimedia\restoreWarnings
();
175 // Try running the XML through UtfNormal to get rid of invalid characters
176 $xml = UtfNormal\Validator
::cleanUp( $xml );
177 // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2
178 // don't barf when the XML is >256 levels deep.
179 $result = $dom->loadXML( $xml, 1 << 19 );
182 $obj = new PPNode_DOM( $dom->documentElement
);
185 // if ( $cacheable ) { ... }
188 throw new MWException( __METHOD__
. ' generated invalid XML' );
194 * @param string $text
198 public function preprocessToXml( $text, $flags = 0 ) {
199 global $wgDisableLangConversion;
201 $forInclusion = $flags & Parser
::PTD_FOR_INCLUSION
;
203 $xmlishElements = $this->parser
->getStripList();
204 $xmlishAllowMissingEndTag = [ 'includeonly', 'noinclude', 'onlyinclude' ];
205 $enableOnlyinclude = false;
206 if ( $forInclusion ) {
207 $ignoredTags = [ 'includeonly', '/includeonly' ];
208 $ignoredElements = [ 'noinclude' ];
209 $xmlishElements[] = 'noinclude';
210 if ( strpos( $text, '<onlyinclude>' ) !== false
211 && strpos( $text, '</onlyinclude>' ) !== false
213 $enableOnlyinclude = true;
216 $ignoredTags = [ 'noinclude', '/noinclude', 'onlyinclude', '/onlyinclude' ];
217 $ignoredElements = [ 'includeonly' ];
218 $xmlishElements[] = 'includeonly';
220 $xmlishRegex = implode( '|', array_merge( $xmlishElements, $ignoredTags ) );
222 // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset
223 $elementsRegex = "~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
225 $stack = new PPDStack
;
227 $searchBase = "[{<\n"; # }
228 if ( !$wgDisableLangConversion ) {
232 // For fast reverse searches
233 $revText = strrev( $text );
234 $lengthText = strlen( $text );
236 // Input pointer, starts out pointing to a pseudo-newline before the start
238 // Current accumulator
239 $accum =& $stack->getAccum();
241 // True to find equals signs in arguments
243 // True to take notice of pipe characters
246 // True if $i is inside a possible heading
248 // True if there are no more greater-than (>) signs right of $i
250 // Map of tag name => true if there are no more closing tags of given type right of $i
251 $noMoreClosingTag = [];
252 // True to ignore all input up to the next <onlyinclude>
253 $findOnlyinclude = $enableOnlyinclude;
254 // Do a line-start run without outputting an LF character
255 $fakeLineStart = true;
258 // $this->memCheck();
260 if ( $findOnlyinclude ) {
261 // Ignore all input up to the next <onlyinclude>
262 $startPos = strpos( $text, '<onlyinclude>', $i );
263 if ( $startPos === false ) {
264 // Ignored section runs to the end
265 $accum .= '<ignore>' . htmlspecialchars( substr( $text, $i ) ) . '</ignore>';
268 $tagEndPos = $startPos +
strlen( '<onlyinclude>' ); // past-the-end
269 $accum .= '<ignore>' . htmlspecialchars( substr( $text, $i, $tagEndPos - $i ) ) . '</ignore>';
271 $findOnlyinclude = false;
274 if ( $fakeLineStart ) {
275 $found = 'line-start';
278 # Find next opening brace, closing brace or pipe
279 $search = $searchBase;
280 if ( $stack->top
=== false ) {
281 $currentClosing = '';
283 $currentClosing = $stack->top
->close
;
284 $search .= $currentClosing;
290 // First equals will be for the template
294 # Output literal section, advance input counter
295 $literalLength = strcspn( $text, $search, $i );
296 if ( $literalLength > 0 ) {
297 $accum .= htmlspecialchars( substr( $text, $i, $literalLength ) );
298 $i +
= $literalLength;
300 if ( $i >= $lengthText ) {
301 if ( $currentClosing == "\n" ) {
302 // Do a past-the-end run to finish off the heading
310 $curChar = $curTwoChar = $text[$i];
311 if ( ( $i +
1 ) < $lengthText ) {
312 $curTwoChar .= $text[$i +
1];
314 if ( $curChar == '|' ) {
316 } elseif ( $curChar == '=' ) {
318 } elseif ( $curChar == '<' ) {
320 } elseif ( $curChar == "\n" ) {
324 $found = 'line-start';
326 } elseif ( $curTwoChar == $currentClosing ) {
328 $curChar = $curTwoChar;
329 } elseif ( $curChar == $currentClosing ) {
331 } elseif ( isset( $this->rules
[$curTwoChar] ) ) {
332 $curChar = $curTwoChar;
334 $rule = $this->rules
[$curChar];
335 } elseif ( isset( $this->rules
[$curChar] ) ) {
337 $rule = $this->rules
[$curChar];
339 # Some versions of PHP have a strcspn which stops on
340 # null characters; ignore these and continue.
341 # We also may get '-' and '}' characters here which
342 # don't match -{ or $currentClosing. Add these to
343 # output and continue.
344 if ( $curChar == '-' ||
$curChar == '}' ) {
353 if ( $found == 'angle' ) {
355 // Handle </onlyinclude>
356 if ( $enableOnlyinclude
357 && substr( $text, $i, strlen( '</onlyinclude>' ) ) == '</onlyinclude>'
359 $findOnlyinclude = true;
363 // Determine element name
364 if ( !preg_match( $elementsRegex, $text, $matches, 0, $i +
1 ) ) {
365 // Element name missing or not listed
371 if ( isset( $matches[2] ) && $matches[2] == '!--' ) {
372 // To avoid leaving blank lines, when a sequence of
373 // space-separated comments is both preceded and followed by
374 // a newline (ignoring spaces), then
375 // trim leading and trailing spaces and the trailing newline.
378 $endPos = strpos( $text, '-->', $i +
4 );
379 if ( $endPos === false ) {
380 // Unclosed comment in input, runs to end
381 $inner = substr( $text, $i );
382 $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
385 // Search backwards for leading whitespace
386 $wsStart = $i ?
( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0;
388 // Search forwards for trailing whitespace
389 // $wsEnd will be the position of the last space (or the '>' if there's none)
390 $wsEnd = $endPos +
2 +
strspn( $text, " \t", $endPos +
3 );
392 // Keep looking forward as long as we're finding more
394 $comments = [ [ $wsStart, $wsEnd ] ];
395 while ( substr( $text, $wsEnd +
1, 4 ) == '<!--' ) {
396 $c = strpos( $text, '-->', $wsEnd +
4 );
397 if ( $c === false ) {
400 $c = $c +
2 +
strspn( $text, " \t", $c +
3 );
401 $comments[] = [ $wsEnd +
1, $c ];
405 // Eat the line if possible
406 // TODO: This could theoretically be done if $wsStart == 0, i.e. for comments at
407 // the overall start. That's not how Sanitizer::removeHTMLcomments() did it, but
408 // it's a possible beneficial b/c break.
409 if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) == "\n"
410 && substr( $text, $wsEnd +
1, 1 ) == "\n"
412 // Remove leading whitespace from the end of the accumulator
413 // Sanity check first though
414 $wsLength = $i - $wsStart;
416 && strspn( $accum, " \t", -$wsLength ) === $wsLength
418 $accum = substr( $accum, 0, -$wsLength );
421 // Dump all but the last comment to the accumulator
422 foreach ( $comments as $j => $com ) {
424 $endPos = $com[1] +
1;
425 if ( $j == ( count( $comments ) - 1 ) ) {
428 $inner = substr( $text, $startPos, $endPos - $startPos );
429 $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
432 // Do a line-start run next time to look for headings after the comment
433 $fakeLineStart = true;
435 // No line to eat, just take the comment itself
441 $part = $stack->top
->getCurrentPart();
442 if ( !( isset( $part->commentEnd
) && $part->commentEnd
== $wsStart - 1 ) ) {
443 $part->visualEnd
= $wsStart;
445 // Else comments abutting, no change in visual end
446 $part->commentEnd
= $endPos;
449 $inner = substr( $text, $startPos, $endPos - $startPos +
1 );
450 $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
455 $lowerName = strtolower( $name );
456 $attrStart = $i +
strlen( $name ) +
1;
459 $tagEndPos = $noMoreGT ?
false : strpos( $text, '>', $attrStart );
460 if ( $tagEndPos === false ) {
461 // Infinite backtrack
462 // Disable tag search to prevent worst-case O(N^2) performance
469 // Handle ignored tags
470 if ( in_array( $lowerName, $ignoredTags ) ) {
472 . htmlspecialchars( substr( $text, $i, $tagEndPos - $i +
1 ) )
479 if ( $text[$tagEndPos - 1] == '/' ) {
480 $attrEnd = $tagEndPos - 1;
485 $attrEnd = $tagEndPos;
488 !isset( $noMoreClosingTag[$name] ) &&
489 preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
490 $text, $matches, PREG_OFFSET_CAPTURE
, $tagEndPos +
1 )
492 $inner = substr( $text, $tagEndPos +
1, $matches[0][1] - $tagEndPos - 1 );
493 $i = $matches[0][1] +
strlen( $matches[0][0] );
494 $close = '<close>' . htmlspecialchars( $matches[0][0] ) . '</close>';
497 if ( in_array( $name, $xmlishAllowMissingEndTag ) ) {
498 // Let it run out to the end of the text.
499 $inner = substr( $text, $tagEndPos +
1 );
503 // Don't match the tag, treat opening tag as literal and resume parsing.
505 $accum .= htmlspecialchars( substr( $text, $tagStartPos, $tagEndPos +
1 - $tagStartPos ) );
506 // Cache results, otherwise we have O(N^2) performance for input like <foo><foo><foo>...
507 $noMoreClosingTag[$name] = true;
512 // <includeonly> and <noinclude> just become <ignore> tags
513 if ( in_array( $lowerName, $ignoredElements ) ) {
514 $accum .= '<ignore>' . htmlspecialchars( substr( $text, $tagStartPos, $i - $tagStartPos ) )
520 if ( $attrEnd <= $attrStart ) {
523 $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
525 $accum .= '<name>' . htmlspecialchars( $name ) . '</name>' .
526 // Note that the attr element contains the whitespace between name and attribute,
527 // this is necessary for precise reconstruction during pre-save transform.
528 '<attr>' . htmlspecialchars( $attr ) . '</attr>';
529 if ( $inner !== null ) {
530 $accum .= '<inner>' . htmlspecialchars( $inner ) . '</inner>';
532 $accum .= $close . '</ext>';
533 } elseif ( $found == 'line-start' ) {
534 // Is this the start of a heading?
535 // Line break belongs before the heading element in any case
536 if ( $fakeLineStart ) {
537 $fakeLineStart = false;
543 $count = strspn( $text, '=', $i, 6 );
544 if ( $count == 1 && $findEquals ) {
545 // DWIM: This looks kind of like a name/value separator.
546 // Let's let the equals handler have it and break the
547 // potential heading. This is heuristic, but AFAICT the
548 // methods for completely correct disambiguation are very
550 } elseif ( $count > 0 ) {
554 'parts' => [ new PPDPart( str_repeat( '=', $count ) ) ],
557 $stack->push( $piece );
558 $accum =& $stack->getAccum();
559 $stackFlags = $stack->getFlags();
560 if ( isset( $stackFlags['findEquals'] ) ) {
561 $findEquals = $stackFlags['findEquals'];
563 if ( isset( $stackFlags['findPipe'] ) ) {
564 $findPipe = $stackFlags['findPipe'];
566 if ( isset( $stackFlags['inHeading'] ) ) {
567 $inHeading = $stackFlags['inHeading'];
571 } elseif ( $found == 'line-end' ) {
572 $piece = $stack->top
;
573 // A heading must be open, otherwise \n wouldn't have been in the search list
574 // FIXME: Don't use assert()
575 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.assert
576 assert( $piece->open
=== "\n" );
577 $part = $piece->getCurrentPart();
578 // Search back through the input to see if it has a proper close.
579 // Do this using the reversed string since the other solutions
580 // (end anchor, etc.) are inefficient.
581 $wsLength = strspn( $revText, " \t", $lengthText - $i );
582 $searchStart = $i - $wsLength;
583 if ( isset( $part->commentEnd
) && $searchStart - 1 == $part->commentEnd
) {
584 // Comment found at line end
585 // Search for equals signs before the comment
586 $searchStart = $part->visualEnd
;
587 $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart );
589 $count = $piece->count
;
590 $equalsLength = strspn( $revText, '=', $lengthText - $searchStart );
591 if ( $equalsLength > 0 ) {
592 if ( $searchStart - $equalsLength == $piece->startPos
) {
593 // This is just a single string of equals signs on its own line
594 // Replicate the doHeadings behavior /={count}(.+)={count}/
595 // First find out how many equals signs there really are (don't stop at 6)
596 $count = $equalsLength;
600 $count = min( 6, intval( ( $count - 1 ) / 2 ) );
603 $count = min( $equalsLength, $count );
606 // Normal match, output <h>
607 $element = "<h level=\"$count\" i=\"$headingIndex\">$accum</h>";
610 // Single equals sign on its own line, count=0
614 // No match, no <h>, just pass down the inner text
619 $accum =& $stack->getAccum();
620 $stackFlags = $stack->getFlags();
621 if ( isset( $stackFlags['findEquals'] ) ) {
622 $findEquals = $stackFlags['findEquals'];
624 if ( isset( $stackFlags['findPipe'] ) ) {
625 $findPipe = $stackFlags['findPipe'];
627 if ( isset( $stackFlags['inHeading'] ) ) {
628 $inHeading = $stackFlags['inHeading'];
631 // Append the result to the enclosing accumulator
633 // Note that we do NOT increment the input pointer.
634 // This is because the closing linebreak could be the opening linebreak of
635 // another heading. Infinite loops are avoided because the next iteration MUST
636 // hit the heading open case above, which unconditionally increments the
638 } elseif ( $found == 'open' ) {
639 # count opening brace characters
640 $curLen = strlen( $curChar );
641 $count = ( $curLen > 1 ) ?
642 # allow the final character to repeat
643 strspn( $text, $curChar[$curLen - 1], $i +
1 ) +
1 :
644 strspn( $text, $curChar, $i );
647 $lineStart = ( $i > 0 && $text[$i - 1] == "\n" );
649 if ( $curChar === "-{" && $count > $curLen ) {
650 // -{ => {{ transition because rightmost wins
655 $rule = $this->rules
[$curChar];
658 # we need to add to stack only if opening brace count is enough for one of the rules
659 if ( $count >= $rule['min'] ) {
660 # Add it to the stack
663 'close' => $rule['end'],
664 'savedPrefix' => $savedPrefix,
666 'lineStart' => $lineStart,
669 $stack->push( $piece );
670 $accum =& $stack->getAccum();
671 $stackFlags = $stack->getFlags();
672 if ( isset( $stackFlags['findEquals'] ) ) {
673 $findEquals = $stackFlags['findEquals'];
675 if ( isset( $stackFlags['findPipe'] ) ) {
676 $findPipe = $stackFlags['findPipe'];
678 if ( isset( $stackFlags['inHeading'] ) ) {
679 $inHeading = $stackFlags['inHeading'];
682 # Add literal brace(s)
683 $accum .= htmlspecialchars( $savedPrefix . str_repeat( $curChar, $count ) );
686 } elseif ( $found == 'close' ) {
687 $piece = $stack->top
;
688 # lets check if there are enough characters for closing brace
689 $maxCount = $piece->count
;
690 if ( $piece->close
=== '}-' && $curChar === '}' ) {
691 $maxCount--; # don't try to match closing '-' as a '}'
693 $curLen = strlen( $curChar );
694 $count = ( $curLen > 1 ) ?
$curLen :
695 strspn( $text, $curChar, $i, $maxCount );
697 # check for maximum matching characters (if there are 5 closing
698 # characters, we will probably need only 3 - depending on the rules)
699 $rule = $this->rules
[$piece->open
];
700 if ( $count > $rule['max'] ) {
701 # The specified maximum exists in the callback array, unless the caller
703 $matchingCount = $rule['max'];
705 # Count is less than the maximum
706 # Skip any gaps in the callback array to find the true largest match
707 # Need to use array_key_exists not isset because the callback can be null
708 $matchingCount = $count;
709 while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule['names'] ) ) {
714 if ( $matchingCount <= 0 ) {
715 # No matching element found in callback array
716 # Output a literal closing brace and continue
717 $endText = substr( $text, $i, $count );
718 $accum .= htmlspecialchars( $endText );
722 $name = $rule['names'][$matchingCount];
723 if ( $name === null ) {
724 // No element, just literal text
725 $endText = substr( $text, $i, $matchingCount );
726 $element = $piece->breakSyntax( $matchingCount ) . $endText;
729 # Note: $parts is already XML, does not need to be encoded further
730 $parts = $piece->parts
;
731 $title = $parts[0]->out
;
734 # The invocation is at the start of the line if lineStart is set in
735 # the stack, and all opening brackets are used up.
736 if ( $maxCount == $matchingCount &&
737 !empty( $piece->lineStart
) &&
738 strlen( $piece->savedPrefix
) == 0 ) {
739 $attr = ' lineStart="1"';
744 $element = "<$name$attr>";
745 $element .= "<title>$title</title>";
747 foreach ( $parts as $part ) {
748 if ( isset( $part->eqpos
) ) {
749 $argName = substr( $part->out
, 0, $part->eqpos
);
750 $argValue = substr( $part->out
, $part->eqpos +
1 );
751 $element .= "<part><name>$argName</name>=<value>$argValue</value></part>";
753 $element .= "<part><name index=\"$argIndex\" /><value>{$part->out}</value></part>";
757 $element .= "</$name>";
760 # Advance input pointer
761 $i +
= $matchingCount;
765 $accum =& $stack->getAccum();
767 # Re-add the old stack element if it still has unmatched opening characters remaining
768 if ( $matchingCount < $piece->count
) {
769 $piece->parts
= [ new PPDPart
];
770 $piece->count
-= $matchingCount;
771 # do we still qualify for any callback with remaining count?
772 $min = $this->rules
[$piece->open
]['min'];
773 if ( $piece->count
>= $min ) {
774 $stack->push( $piece );
775 $accum =& $stack->getAccum();
776 } elseif ( $piece->count
== 1 && $piece->open
=== '{' && $piece->savedPrefix
=== '-' ) {
777 $piece->savedPrefix
= '';
780 $piece->close
= $this->rules
[$piece->open
]['end'];
781 $stack->push( $piece );
782 $accum =& $stack->getAccum();
784 $s = substr( $piece->open
, 0, -1 );
786 substr( $piece->open
, -1 ),
787 $piece->count
- strlen( $s )
789 $accum .= $piece->savedPrefix
. $s;
791 } elseif ( $piece->savedPrefix
!== '' ) {
792 $accum .= $piece->savedPrefix
;
795 $stackFlags = $stack->getFlags();
796 if ( isset( $stackFlags['findEquals'] ) ) {
797 $findEquals = $stackFlags['findEquals'];
799 if ( isset( $stackFlags['findPipe'] ) ) {
800 $findPipe = $stackFlags['findPipe'];
802 if ( isset( $stackFlags['inHeading'] ) ) {
803 $inHeading = $stackFlags['inHeading'];
806 # Add XML element to the enclosing accumulator
808 } elseif ( $found == 'pipe' ) {
809 $findEquals = true; // shortcut for getFlags()
811 $accum =& $stack->getAccum();
813 } elseif ( $found == 'equals' ) {
814 $findEquals = false; // shortcut for getFlags()
815 $stack->getCurrentPart()->eqpos
= strlen( $accum );
821 # Output any remaining unclosed brackets
822 foreach ( $stack->stack
as $piece ) {
823 $stack->rootAccum
.= $piece->breakSyntax();
825 $stack->rootAccum
.= '</root>';
826 $xml = $stack->rootAccum
;