MediaWiki  1.23.8
Preprocessor_DOM.php
Go to the documentation of this file.
1 <?php
27 class Preprocessor_DOM implements Preprocessor {
28 
32  var $parser;
33 
34  var $memoryLimit;
35 
36  const CACHE_VERSION = 1;
37 
38  function __construct( $parser ) {
39  $this->parser = $parser;
40  $mem = ini_get( 'memory_limit' );
41  $this->memoryLimit = false;
42  if ( strval( $mem ) !== '' && $mem != -1 ) {
43  if ( preg_match( '/^\d+$/', $mem ) ) {
44  $this->memoryLimit = $mem;
45  } elseif ( preg_match( '/^(\d+)M$/i', $mem, $m ) ) {
46  $this->memoryLimit = $m[1] * 1048576;
47  }
48  }
49  }
50 
54  function newFrame() {
55  return new PPFrame_DOM( $this );
56  }
57 
62  function newCustomFrame( $args ) {
63  return new PPCustomFrame_DOM( $this, $args );
64  }
65 
70  function newPartNodeArray( $values ) {
71  //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
72  $xml = "<list>";
73 
74  foreach ( $values as $k => $val ) {
75  if ( is_int( $k ) ) {
76  $xml .= "<part><name index=\"$k\"/><value>" . htmlspecialchars( $val ) . "</value></part>";
77  } else {
78  $xml .= "<part><name>" . htmlspecialchars( $k ) . "</name>=<value>" . htmlspecialchars( $val ) . "</value></part>";
79  }
80  }
81 
82  $xml .= "</list>";
83 
84  $dom = new DOMDocument();
85  $dom->loadXML( $xml );
86  $root = $dom->documentElement;
87 
88  $node = new PPNode_DOM( $root->childNodes );
89  return $node;
90  }
91 
96  function memCheck() {
97  if ( $this->memoryLimit === false ) {
98  return true;
99  }
100  $usage = memory_get_usage();
101  if ( $usage > $this->memoryLimit * 0.9 ) {
102  $limit = intval( $this->memoryLimit * 0.9 / 1048576 + 0.5 );
103  throw new MWException( "Preprocessor hit 90% memory limit ($limit MB)" );
104  }
105  return $usage <= $this->memoryLimit * 0.8;
106  }
107 
131  function preprocessToObj( $text, $flags = 0 ) {
132  wfProfileIn( __METHOD__ );
133  global $wgMemc, $wgPreprocessorCacheThreshold;
134 
135  $xml = false;
136  $cacheable = ( $wgPreprocessorCacheThreshold !== false
137  && strlen( $text ) > $wgPreprocessorCacheThreshold );
138  if ( $cacheable ) {
139  wfProfileIn( __METHOD__ . '-cacheable' );
140 
141  $cacheKey = wfMemcKey( 'preprocess-xml', md5( $text ), $flags );
142  $cacheValue = $wgMemc->get( $cacheKey );
143  if ( $cacheValue ) {
144  $version = substr( $cacheValue, 0, 8 );
145  if ( intval( $version ) == self::CACHE_VERSION ) {
146  $xml = substr( $cacheValue, 8 );
147  // From the cache
148  wfDebugLog( "Preprocessor", "Loaded preprocessor XML from memcached (key $cacheKey)" );
149  }
150  }
151  if ( $xml === false ) {
152  wfProfileIn( __METHOD__ . '-cache-miss' );
153  $xml = $this->preprocessToXml( $text, $flags );
154  $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . $xml;
155  $wgMemc->set( $cacheKey, $cacheValue, 86400 );
156  wfProfileOut( __METHOD__ . '-cache-miss' );
157  wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" );
158  }
159  } else {
160  $xml = $this->preprocessToXml( $text, $flags );
161  }
162 
163  // Fail if the number of elements exceeds acceptable limits
164  // Do not attempt to generate the DOM
165  $this->parser->mGeneratedPPNodeCount += substr_count( $xml, '<' );
166  $max = $this->parser->mOptions->getMaxGeneratedPPNodeCount();
167  if ( $this->parser->mGeneratedPPNodeCount > $max ) {
168  if ( $cacheable ) {
169  wfProfileOut( __METHOD__ . '-cacheable' );
170  }
171  wfProfileOut( __METHOD__ );
172  throw new MWException( __METHOD__ . ': generated node count limit exceeded' );
173  }
174 
175  wfProfileIn( __METHOD__ . '-loadXML' );
176  $dom = new DOMDocument;
178  $result = $dom->loadXML( $xml );
180  if ( !$result ) {
181  // Try running the XML through UtfNormal to get rid of invalid characters
182  $xml = UtfNormal::cleanUp( $xml );
183  // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
184  $result = $dom->loadXML( $xml, 1 << 19 );
185  }
186  if ( $result ) {
187  $obj = new PPNode_DOM( $dom->documentElement );
188  }
189  wfProfileOut( __METHOD__ . '-loadXML' );
190 
191  if ( $cacheable ) {
192  wfProfileOut( __METHOD__ . '-cacheable' );
193  }
194 
195  wfProfileOut( __METHOD__ );
196 
197  if ( !$result ) {
198  throw new MWException( __METHOD__ . ' generated invalid XML' );
199  }
200  return $obj;
201  }
202 
208  function preprocessToXml( $text, $flags = 0 ) {
209  wfProfileIn( __METHOD__ );
210  $rules = array(
211  '{' => array(
212  'end' => '}',
213  'names' => array(
214  2 => 'template',
215  3 => 'tplarg',
216  ),
217  'min' => 2,
218  'max' => 3,
219  ),
220  '[' => array(
221  'end' => ']',
222  'names' => array( 2 => null ),
223  'min' => 2,
224  'max' => 2,
225  )
226  );
227 
228  $forInclusion = $flags & Parser::PTD_FOR_INCLUSION;
229 
230  $xmlishElements = $this->parser->getStripList();
231  $enableOnlyinclude = false;
232  if ( $forInclusion ) {
233  $ignoredTags = array( 'includeonly', '/includeonly' );
234  $ignoredElements = array( 'noinclude' );
235  $xmlishElements[] = 'noinclude';
236  if ( strpos( $text, '<onlyinclude>' ) !== false && strpos( $text, '</onlyinclude>' ) !== false ) {
237  $enableOnlyinclude = true;
238  }
239  } else {
240  $ignoredTags = array( 'noinclude', '/noinclude', 'onlyinclude', '/onlyinclude' );
241  $ignoredElements = array( 'includeonly' );
242  $xmlishElements[] = 'includeonly';
243  }
244  $xmlishRegex = implode( '|', array_merge( $xmlishElements, $ignoredTags ) );
245 
246  // Use "A" modifier (anchored) instead of "^", because ^ doesn't work with an offset
247  $elementsRegex = "~($xmlishRegex)(?:\s|\/>|>)|(!--)~iA";
248 
249  $stack = new PPDStack;
250 
251  $searchBase = "[{<\n"; #}
252  $revText = strrev( $text ); // For fast reverse searches
253  $lengthText = strlen( $text );
254 
255  $i = 0; # Input pointer, starts out pointing to a pseudo-newline before the start
256  $accum =& $stack->getAccum(); # Current accumulator
257  $accum = '<root>';
258  $findEquals = false; # True to find equals signs in arguments
259  $findPipe = false; # True to take notice of pipe characters
260  $headingIndex = 1;
261  $inHeading = false; # True if $i is inside a possible heading
262  $noMoreGT = false; # True if there are no more greater-than (>) signs right of $i
263  $findOnlyinclude = $enableOnlyinclude; # True to ignore all input up to the next <onlyinclude>
264  $fakeLineStart = true; # Do a line-start run without outputting an LF character
265 
266  while ( true ) {
267  //$this->memCheck();
268 
269  if ( $findOnlyinclude ) {
270  // Ignore all input up to the next <onlyinclude>
271  $startPos = strpos( $text, '<onlyinclude>', $i );
272  if ( $startPos === false ) {
273  // Ignored section runs to the end
274  $accum .= '<ignore>' . htmlspecialchars( substr( $text, $i ) ) . '</ignore>';
275  break;
276  }
277  $tagEndPos = $startPos + strlen( '<onlyinclude>' ); // past-the-end
278  $accum .= '<ignore>' . htmlspecialchars( substr( $text, $i, $tagEndPos - $i ) ) . '</ignore>';
279  $i = $tagEndPos;
280  $findOnlyinclude = false;
281  }
282 
283  if ( $fakeLineStart ) {
284  $found = 'line-start';
285  $curChar = '';
286  } else {
287  # Find next opening brace, closing brace or pipe
288  $search = $searchBase;
289  if ( $stack->top === false ) {
290  $currentClosing = '';
291  } else {
292  $currentClosing = $stack->top->close;
293  $search .= $currentClosing;
294  }
295  if ( $findPipe ) {
296  $search .= '|';
297  }
298  if ( $findEquals ) {
299  // First equals will be for the template
300  $search .= '=';
301  }
302  $rule = null;
303  # Output literal section, advance input counter
304  $literalLength = strcspn( $text, $search, $i );
305  if ( $literalLength > 0 ) {
306  $accum .= htmlspecialchars( substr( $text, $i, $literalLength ) );
307  $i += $literalLength;
308  }
309  if ( $i >= $lengthText ) {
310  if ( $currentClosing == "\n" ) {
311  // Do a past-the-end run to finish off the heading
312  $curChar = '';
313  $found = 'line-end';
314  } else {
315  # All done
316  break;
317  }
318  } else {
319  $curChar = $text[$i];
320  if ( $curChar == '|' ) {
321  $found = 'pipe';
322  } elseif ( $curChar == '=' ) {
323  $found = 'equals';
324  } elseif ( $curChar == '<' ) {
325  $found = 'angle';
326  } elseif ( $curChar == "\n" ) {
327  if ( $inHeading ) {
328  $found = 'line-end';
329  } else {
330  $found = 'line-start';
331  }
332  } elseif ( $curChar == $currentClosing ) {
333  $found = 'close';
334  } elseif ( isset( $rules[$curChar] ) ) {
335  $found = 'open';
336  $rule = $rules[$curChar];
337  } else {
338  # Some versions of PHP have a strcspn which stops on null characters
339  # Ignore and continue
340  ++$i;
341  continue;
342  }
343  }
344  }
345 
346  if ( $found == 'angle' ) {
347  $matches = false;
348  // Handle </onlyinclude>
349  if ( $enableOnlyinclude && substr( $text, $i, strlen( '</onlyinclude>' ) ) == '</onlyinclude>' ) {
350  $findOnlyinclude = true;
351  continue;
352  }
353 
354  // Determine element name
355  if ( !preg_match( $elementsRegex, $text, $matches, 0, $i + 1 ) ) {
356  // Element name missing or not listed
357  $accum .= '&lt;';
358  ++$i;
359  continue;
360  }
361  // Handle comments
362  if ( isset( $matches[2] ) && $matches[2] == '!--' ) {
363 
364  // To avoid leaving blank lines, when a sequence of
365  // space-separated comments is both preceded and followed by
366  // a newline (ignoring spaces), then
367  // trim leading and trailing spaces and the trailing newline.
368 
369  // Find the end
370  $endPos = strpos( $text, '-->', $i + 4 );
371  if ( $endPos === false ) {
372  // Unclosed comment in input, runs to end
373  $inner = substr( $text, $i );
374  $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
375  $i = $lengthText;
376  } else {
377  // Search backwards for leading whitespace
378  $wsStart = $i ? ( $i - strspn( $revText, " \t", $lengthText - $i ) ) : 0;
379 
380  // Search forwards for trailing whitespace
381  // $wsEnd will be the position of the last space (or the '>' if there's none)
382  $wsEnd = $endPos + 2 + strspn( $text, " \t", $endPos + 3 );
383 
384  // Keep looking forward as long as we're finding more
385  // comments.
386  $comments = array( array( $wsStart, $wsEnd ) );
387  while ( substr( $text, $wsEnd + 1, 4 ) == '<!--' ) {
388  $c = strpos( $text, '-->', $wsEnd + 4 );
389  if ( $c === false ) {
390  break;
391  }
392  $c = $c + 2 + strspn( $text, " \t", $c + 3 );
393  $comments[] = array( $wsEnd + 1, $c );
394  $wsEnd = $c;
395  }
396 
397  // Eat the line if possible
398  // TODO: This could theoretically be done if $wsStart == 0, i.e. for comments at
399  // the overall start. That's not how Sanitizer::removeHTMLcomments() did it, but
400  // it's a possible beneficial b/c break.
401  if ( $wsStart > 0 && substr( $text, $wsStart - 1, 1 ) == "\n"
402  && substr( $text, $wsEnd + 1, 1 ) == "\n"
403  ) {
404  // Remove leading whitespace from the end of the accumulator
405  // Sanity check first though
406  $wsLength = $i - $wsStart;
407  if ( $wsLength > 0
408  && strspn( $accum, " \t", -$wsLength ) === $wsLength
409  ) {
410  $accum = substr( $accum, 0, -$wsLength );
411  }
412 
413  // Dump all but the last comment to the accumulator
414  foreach ( $comments as $j => $com ) {
415  $startPos = $com[0];
416  $endPos = $com[1] + 1;
417  if ( $j == ( count( $comments ) - 1 ) ) {
418  break;
419  }
420  $inner = substr( $text, $startPos, $endPos - $startPos );
421  $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
422  }
423 
424  // Do a line-start run next time to look for headings after the comment
425  $fakeLineStart = true;
426  } else {
427  // No line to eat, just take the comment itself
428  $startPos = $i;
429  $endPos += 2;
430  }
431 
432  if ( $stack->top ) {
433  $part = $stack->top->getCurrentPart();
434  if ( !( isset( $part->commentEnd ) && $part->commentEnd == $wsStart - 1 ) ) {
435  $part->visualEnd = $wsStart;
436  }
437  // Else comments abutting, no change in visual end
438  $part->commentEnd = $endPos;
439  }
440  $i = $endPos + 1;
441  $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
442  $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
443  }
444  continue;
445  }
446  $name = $matches[1];
447  $lowerName = strtolower( $name );
448  $attrStart = $i + strlen( $name ) + 1;
449 
450  // Find end of tag
451  $tagEndPos = $noMoreGT ? false : strpos( $text, '>', $attrStart );
452  if ( $tagEndPos === false ) {
453  // Infinite backtrack
454  // Disable tag search to prevent worst-case O(N^2) performance
455  $noMoreGT = true;
456  $accum .= '&lt;';
457  ++$i;
458  continue;
459  }
460 
461  // Handle ignored tags
462  if ( in_array( $lowerName, $ignoredTags ) ) {
463  $accum .= '<ignore>' . htmlspecialchars( substr( $text, $i, $tagEndPos - $i + 1 ) ) . '</ignore>';
464  $i = $tagEndPos + 1;
465  continue;
466  }
467 
468  $tagStartPos = $i;
469  if ( $text[$tagEndPos - 1] == '/' ) {
470  $attrEnd = $tagEndPos - 1;
471  $inner = null;
472  $i = $tagEndPos + 1;
473  $close = '';
474  } else {
475  $attrEnd = $tagEndPos;
476  // Find closing tag
477  if ( preg_match( "/<\/" . preg_quote( $name, '/' ) . "\s*>/i",
478  $text, $matches, PREG_OFFSET_CAPTURE, $tagEndPos + 1 )
479  ) {
480  $inner = substr( $text, $tagEndPos + 1, $matches[0][1] - $tagEndPos - 1 );
481  $i = $matches[0][1] + strlen( $matches[0][0] );
482  $close = '<close>' . htmlspecialchars( $matches[0][0] ) . '</close>';
483  } else {
484  // No end tag -- let it run out to the end of the text.
485  $inner = substr( $text, $tagEndPos + 1 );
486  $i = $lengthText;
487  $close = '';
488  }
489  }
490  // <includeonly> and <noinclude> just become <ignore> tags
491  if ( in_array( $lowerName, $ignoredElements ) ) {
492  $accum .= '<ignore>' . htmlspecialchars( substr( $text, $tagStartPos, $i - $tagStartPos ) )
493  . '</ignore>';
494  continue;
495  }
496 
497  $accum .= '<ext>';
498  if ( $attrEnd <= $attrStart ) {
499  $attr = '';
500  } else {
501  $attr = substr( $text, $attrStart, $attrEnd - $attrStart );
502  }
503  $accum .= '<name>' . htmlspecialchars( $name ) . '</name>' .
504  // Note that the attr element contains the whitespace between name and attribute,
505  // this is necessary for precise reconstruction during pre-save transform.
506  '<attr>' . htmlspecialchars( $attr ) . '</attr>';
507  if ( $inner !== null ) {
508  $accum .= '<inner>' . htmlspecialchars( $inner ) . '</inner>';
509  }
510  $accum .= $close . '</ext>';
511  } elseif ( $found == 'line-start' ) {
512  // Is this the start of a heading?
513  // Line break belongs before the heading element in any case
514  if ( $fakeLineStart ) {
515  $fakeLineStart = false;
516  } else {
517  $accum .= $curChar;
518  $i++;
519  }
520 
521  $count = strspn( $text, '=', $i, 6 );
522  if ( $count == 1 && $findEquals ) {
523  // DWIM: This looks kind of like a name/value separator
524  // Let's let the equals handler have it and break the potential heading
525  // This is heuristic, but AFAICT the methods for completely correct disambiguation are very complex.
526  } elseif ( $count > 0 ) {
527  $piece = array(
528  'open' => "\n",
529  'close' => "\n",
530  'parts' => array( new PPDPart( str_repeat( '=', $count ) ) ),
531  'startPos' => $i,
532  'count' => $count );
533  $stack->push( $piece );
534  $accum =& $stack->getAccum();
535  $flags = $stack->getFlags();
536  extract( $flags );
537  $i += $count;
538  }
539  } elseif ( $found == 'line-end' ) {
540  $piece = $stack->top;
541  // A heading must be open, otherwise \n wouldn't have been in the search list
542  assert( '$piece->open == "\n"' );
543  $part = $piece->getCurrentPart();
544  // Search back through the input to see if it has a proper close
545  // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
546  $wsLength = strspn( $revText, " \t", $lengthText - $i );
547  $searchStart = $i - $wsLength;
548  if ( isset( $part->commentEnd ) && $searchStart - 1 == $part->commentEnd ) {
549  // Comment found at line end
550  // Search for equals signs before the comment
551  $searchStart = $part->visualEnd;
552  $searchStart -= strspn( $revText, " \t", $lengthText - $searchStart );
553  }
554  $count = $piece->count;
555  $equalsLength = strspn( $revText, '=', $lengthText - $searchStart );
556  if ( $equalsLength > 0 ) {
557  if ( $searchStart - $equalsLength == $piece->startPos ) {
558  // This is just a single string of equals signs on its own line
559  // Replicate the doHeadings behavior /={count}(.+)={count}/
560  // First find out how many equals signs there really are (don't stop at 6)
561  $count = $equalsLength;
562  if ( $count < 3 ) {
563  $count = 0;
564  } else {
565  $count = min( 6, intval( ( $count - 1 ) / 2 ) );
566  }
567  } else {
568  $count = min( $equalsLength, $count );
569  }
570  if ( $count > 0 ) {
571  // Normal match, output <h>
572  $element = "<h level=\"$count\" i=\"$headingIndex\">$accum</h>";
573  $headingIndex++;
574  } else {
575  // Single equals sign on its own line, count=0
576  $element = $accum;
577  }
578  } else {
579  // No match, no <h>, just pass down the inner text
580  $element = $accum;
581  }
582  // Unwind the stack
583  $stack->pop();
584  $accum =& $stack->getAccum();
585  $flags = $stack->getFlags();
586  extract( $flags );
587 
588  // Append the result to the enclosing accumulator
589  $accum .= $element;
590  // Note that we do NOT increment the input pointer.
591  // This is because the closing linebreak could be the opening linebreak of
592  // another heading. Infinite loops are avoided because the next iteration MUST
593  // hit the heading open case above, which unconditionally increments the
594  // input pointer.
595  } elseif ( $found == 'open' ) {
596  # count opening brace characters
597  $count = strspn( $text, $curChar, $i );
598 
599  # we need to add to stack only if opening brace count is enough for one of the rules
600  if ( $count >= $rule['min'] ) {
601  # Add it to the stack
602  $piece = array(
603  'open' => $curChar,
604  'close' => $rule['end'],
605  'count' => $count,
606  'lineStart' => ( $i > 0 && $text[$i - 1] == "\n" ),
607  );
608 
609  $stack->push( $piece );
610  $accum =& $stack->getAccum();
611  $flags = $stack->getFlags();
612  extract( $flags );
613  } else {
614  # Add literal brace(s)
615  $accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
616  }
617  $i += $count;
618  } elseif ( $found == 'close' ) {
619  $piece = $stack->top;
620  # lets check if there are enough characters for closing brace
621  $maxCount = $piece->count;
622  $count = strspn( $text, $curChar, $i, $maxCount );
623 
624  # check for maximum matching characters (if there are 5 closing
625  # characters, we will probably need only 3 - depending on the rules)
626  $rule = $rules[$piece->open];
627  if ( $count > $rule['max'] ) {
628  # The specified maximum exists in the callback array, unless the caller
629  # has made an error
630  $matchingCount = $rule['max'];
631  } else {
632  # Count is less than the maximum
633  # Skip any gaps in the callback array to find the true largest match
634  # Need to use array_key_exists not isset because the callback can be null
635  $matchingCount = $count;
636  while ( $matchingCount > 0 && !array_key_exists( $matchingCount, $rule['names'] ) ) {
637  --$matchingCount;
638  }
639  }
640 
641  if ( $matchingCount <= 0 ) {
642  # No matching element found in callback array
643  # Output a literal closing brace and continue
644  $accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
645  $i += $count;
646  continue;
647  }
648  $name = $rule['names'][$matchingCount];
649  if ( $name === null ) {
650  // No element, just literal text
651  $element = $piece->breakSyntax( $matchingCount ) . str_repeat( $rule['end'], $matchingCount );
652  } else {
653  # Create XML element
654  # Note: $parts is already XML, does not need to be encoded further
655  $parts = $piece->parts;
656  $title = $parts[0]->out;
657  unset( $parts[0] );
658 
659  # The invocation is at the start of the line if lineStart is set in
660  # the stack, and all opening brackets are used up.
661  if ( $maxCount == $matchingCount && !empty( $piece->lineStart ) ) {
662  $attr = ' lineStart="1"';
663  } else {
664  $attr = '';
665  }
666 
667  $element = "<$name$attr>";
668  $element .= "<title>$title</title>";
669  $argIndex = 1;
670  foreach ( $parts as $part ) {
671  if ( isset( $part->eqpos ) ) {
672  $argName = substr( $part->out, 0, $part->eqpos );
673  $argValue = substr( $part->out, $part->eqpos + 1 );
674  $element .= "<part><name>$argName</name>=<value>$argValue</value></part>";
675  } else {
676  $element .= "<part><name index=\"$argIndex\" /><value>{$part->out}</value></part>";
677  $argIndex++;
678  }
679  }
680  $element .= "</$name>";
681  }
682 
683  # Advance input pointer
684  $i += $matchingCount;
685 
686  # Unwind the stack
687  $stack->pop();
688  $accum =& $stack->getAccum();
689 
690  # Re-add the old stack element if it still has unmatched opening characters remaining
691  if ( $matchingCount < $piece->count ) {
692  $piece->parts = array( new PPDPart );
693  $piece->count -= $matchingCount;
694  # do we still qualify for any callback with remaining count?
695  $min = $rules[$piece->open]['min'];
696  if ( $piece->count >= $min ) {
697  $stack->push( $piece );
698  $accum =& $stack->getAccum();
699  } else {
700  $accum .= str_repeat( $piece->open, $piece->count );
701  }
702  }
703  $flags = $stack->getFlags();
704  extract( $flags );
705 
706  # Add XML element to the enclosing accumulator
707  $accum .= $element;
708  } elseif ( $found == 'pipe' ) {
709  $findEquals = true; // shortcut for getFlags()
710  $stack->addPart();
711  $accum =& $stack->getAccum();
712  ++$i;
713  } elseif ( $found == 'equals' ) {
714  $findEquals = false; // shortcut for getFlags()
715  $stack->getCurrentPart()->eqpos = strlen( $accum );
716  $accum .= '=';
717  ++$i;
718  }
719  }
720 
721  # Output any remaining unclosed brackets
722  foreach ( $stack->stack as $piece ) {
723  $stack->rootAccum .= $piece->breakSyntax();
724  }
725  $stack->rootAccum .= '</root>';
726  $xml = $stack->rootAccum;
727 
728  wfProfileOut( __METHOD__ );
729 
730  return $xml;
731  }
732 }
733 
738 class PPDStack {
739  var $stack, $rootAccum;
740 
744  var $top;
745  var $out;
746  var $elementClass = 'PPDStackElement';
747 
748  static $false = false;
749 
750  function __construct() {
751  $this->stack = array();
752  $this->top = false;
753  $this->rootAccum = '';
754  $this->accum =& $this->rootAccum;
755  }
756 
760  function count() {
761  return count( $this->stack );
762  }
763 
764  function &getAccum() {
765  return $this->accum;
766  }
767 
768  function getCurrentPart() {
769  if ( $this->top === false ) {
770  return false;
771  } else {
772  return $this->top->getCurrentPart();
773  }
774  }
775 
776  function push( $data ) {
777  if ( $data instanceof $this->elementClass ) {
778  $this->stack[] = $data;
779  } else {
780  $class = $this->elementClass;
781  $this->stack[] = new $class( $data );
782  }
783  $this->top = $this->stack[count( $this->stack ) - 1];
784  $this->accum =& $this->top->getAccum();
785  }
786 
787  function pop() {
788  if ( !count( $this->stack ) ) {
789  throw new MWException( __METHOD__ . ': no elements remaining' );
790  }
791  $temp = array_pop( $this->stack );
792 
793  if ( count( $this->stack ) ) {
794  $this->top = $this->stack[count( $this->stack ) - 1];
795  $this->accum =& $this->top->getAccum();
796  } else {
797  $this->top = self::$false;
798  $this->accum =& $this->rootAccum;
799  }
800  return $temp;
801  }
802 
803  function addPart( $s = '' ) {
804  $this->top->addPart( $s );
805  $this->accum =& $this->top->getAccum();
806  }
807 
811  function getFlags() {
812  if ( !count( $this->stack ) ) {
813  return array(
814  'findEquals' => false,
815  'findPipe' => false,
816  'inHeading' => false,
817  );
818  } else {
819  return $this->top->getFlags();
820  }
821  }
822 }
823 
827 class PPDStackElement {
828  var $open, // Opening character (\n for heading)
829  $close, // Matching closing character
830  $count, // Number of opening characters found (number of "=" for heading)
831  $parts, // Array of PPDPart objects describing pipe-separated parts.
832  $lineStart; // True if the open char appeared at the start of the input line. Not set for headings.
833 
834  var $partClass = 'PPDPart';
835 
836  function __construct( $data = array() ) {
837  $class = $this->partClass;
838  $this->parts = array( new $class );
839 
840  foreach ( $data as $name => $value ) {
841  $this->$name = $value;
842  }
843  }
844 
845  function &getAccum() {
846  return $this->parts[count( $this->parts ) - 1]->out;
847  }
848 
849  function addPart( $s = '' ) {
850  $class = $this->partClass;
851  $this->parts[] = new $class( $s );
852  }
853 
854  function getCurrentPart() {
855  return $this->parts[count( $this->parts ) - 1];
856  }
857 
861  function getFlags() {
862  $partCount = count( $this->parts );
863  $findPipe = $this->open != "\n" && $this->open != '[';
864  return array(
865  'findPipe' => $findPipe,
866  'findEquals' => $findPipe && $partCount > 1 && !isset( $this->parts[$partCount - 1]->eqpos ),
867  'inHeading' => $this->open == "\n",
868  );
869  }
870 
876  function breakSyntax( $openingCount = false ) {
877  if ( $this->open == "\n" ) {
878  $s = $this->parts[0]->out;
879  } else {
880  if ( $openingCount === false ) {
881  $openingCount = $this->count;
882  }
883  $s = str_repeat( $this->open, $openingCount );
884  $first = true;
885  foreach ( $this->parts as $part ) {
886  if ( $first ) {
887  $first = false;
888  } else {
889  $s .= '|';
890  }
891  $s .= $part->out;
892  }
893  }
894  return $s;
895  }
896 }
897 
901 class PPDPart {
902  var $out; // Output accumulator string
903 
904  // Optional member variables:
905  // eqpos Position of equals sign in output accumulator
906  // commentEnd Past-the-end input pointer for the last comment encountered
907  // visualEnd Past-the-end input pointer for the end of the accumulator minus comments
908 
909  function __construct( $out = '' ) {
910  $this->out = $out;
911  }
912 }
913 
918 class PPFrame_DOM implements PPFrame {
919 
923  var $preprocessor;
924 
928  var $parser;
929 
933  var $title;
934  var $titleCache;
935 
940  var $loopCheckHash;
941 
946  var $depth;
947 
952  function __construct( $preprocessor ) {
953  $this->preprocessor = $preprocessor;
954  $this->parser = $preprocessor->parser;
955  $this->title = $this->parser->mTitle;
956  $this->titleCache = array( $this->title ? $this->title->getPrefixedDBkey() : false );
957  $this->loopCheckHash = array();
958  $this->depth = 0;
959  }
960 
967  function newChild( $args = false, $title = false, $indexOffset = 0 ) {
968  $namedArgs = array();
969  $numberedArgs = array();
970  if ( $title === false ) {
972  }
973  if ( $args !== false ) {
974  $xpath = false;
975  if ( $args instanceof PPNode ) {
976  $args = $args->node;
977  }
978  foreach ( $args as $arg ) {
979  if ( $arg instanceof PPNode ) {
980  $arg = $arg->node;
981  }
982  if ( !$xpath ) {
983  $xpath = new DOMXPath( $arg->ownerDocument );
984  }
985 
986  $nameNodes = $xpath->query( 'name', $arg );
987  $value = $xpath->query( 'value', $arg );
988  if ( $nameNodes->item( 0 )->hasAttributes() ) {
989  // Numbered parameter
990  $index = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent;
991  $index = $index - $indexOffset;
992  $numberedArgs[$index] = $value->item( 0 );
993  unset( $namedArgs[$index] );
994  } else {
995  // Named parameter
996  $name = trim( $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS ) );
997  $namedArgs[$name] = $value->item( 0 );
998  unset( $numberedArgs[$name] );
999  }
1000  }
1001  }
1002  return new PPTemplateFrame_DOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
1003  }
1004 
1011  function expand( $root, $flags = 0 ) {
1012  static $expansionDepth = 0;
1013  if ( is_string( $root ) ) {
1014  return $root;
1015  }
1016 
1017  if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
1018  $this->parser->limitationWarn( 'node-count-exceeded',
1019  $this->parser->mPPNodeCount,
1020  $this->parser->mOptions->getMaxPPNodeCount()
1021  );
1022  return '<span class="error">Node-count limit exceeded</span>';
1023  }
1024 
1025  if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
1026  $this->parser->limitationWarn( 'expansion-depth-exceeded',
1027  $expansionDepth,
1028  $this->parser->mOptions->getMaxPPExpandDepth()
1029  );
1030  return '<span class="error">Expansion depth limit exceeded</span>';
1031  }
1032  wfProfileIn( __METHOD__ );
1033  ++$expansionDepth;
1034  if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
1035  $this->parser->mHighestExpansionDepth = $expansionDepth;
1036  }
1037 
1038  if ( $root instanceof PPNode_DOM ) {
1039  $root = $root->node;
1040  }
1041  if ( $root instanceof DOMDocument ) {
1042  $root = $root->documentElement;
1043  }
1044 
1045  $outStack = array( '', '' );
1046  $iteratorStack = array( false, $root );
1047  $indexStack = array( 0, 0 );
1048 
1049  while ( count( $iteratorStack ) > 1 ) {
1050  $level = count( $outStack ) - 1;
1051  $iteratorNode =& $iteratorStack[$level];
1052  $out =& $outStack[$level];
1053  $index =& $indexStack[$level];
1054 
1055  if ( $iteratorNode instanceof PPNode_DOM ) {
1056  $iteratorNode = $iteratorNode->node;
1057  }
1058 
1059  if ( is_array( $iteratorNode ) ) {
1060  if ( $index >= count( $iteratorNode ) ) {
1061  // All done with this iterator
1062  $iteratorStack[$level] = false;
1063  $contextNode = false;
1064  } else {
1065  $contextNode = $iteratorNode[$index];
1066  $index++;
1067  }
1068  } elseif ( $iteratorNode instanceof DOMNodeList ) {
1069  if ( $index >= $iteratorNode->length ) {
1070  // All done with this iterator
1071  $iteratorStack[$level] = false;
1072  $contextNode = false;
1073  } else {
1074  $contextNode = $iteratorNode->item( $index );
1075  $index++;
1076  }
1077  } else {
1078  // Copy to $contextNode and then delete from iterator stack,
1079  // because this is not an iterator but we do have to execute it once
1080  $contextNode = $iteratorStack[$level];
1081  $iteratorStack[$level] = false;
1082  }
1083 
1084  if ( $contextNode instanceof PPNode_DOM ) {
1085  $contextNode = $contextNode->node;
1086  }
1087 
1088  $newIterator = false;
1089 
1090  if ( $contextNode === false ) {
1091  // nothing to do
1092  } elseif ( is_string( $contextNode ) ) {
1093  $out .= $contextNode;
1094  } elseif ( is_array( $contextNode ) || $contextNode instanceof DOMNodeList ) {
1095  $newIterator = $contextNode;
1096  } elseif ( $contextNode instanceof DOMNode ) {
1097  if ( $contextNode->nodeType == XML_TEXT_NODE ) {
1098  $out .= $contextNode->nodeValue;
1099  } elseif ( $contextNode->nodeName == 'template' ) {
1100  # Double-brace expansion
1101  $xpath = new DOMXPath( $contextNode->ownerDocument );
1102  $titles = $xpath->query( 'title', $contextNode );
1103  $title = $titles->item( 0 );
1104  $parts = $xpath->query( 'part', $contextNode );
1105  if ( $flags & PPFrame::NO_TEMPLATES ) {
1106  $newIterator = $this->virtualBracketedImplode( '{{', '|', '}}', $title, $parts );
1107  } else {
1108  $lineStart = $contextNode->getAttribute( 'lineStart' );
1109  $params = array(
1110  'title' => new PPNode_DOM( $title ),
1111  'parts' => new PPNode_DOM( $parts ),
1112  'lineStart' => $lineStart );
1113  $ret = $this->parser->braceSubstitution( $params, $this );
1114  if ( isset( $ret['object'] ) ) {
1115  $newIterator = $ret['object'];
1116  } else {
1117  $out .= $ret['text'];
1118  }
1119  }
1120  } elseif ( $contextNode->nodeName == 'tplarg' ) {
1121  # Triple-brace expansion
1122  $xpath = new DOMXPath( $contextNode->ownerDocument );
1123  $titles = $xpath->query( 'title', $contextNode );
1124  $title = $titles->item( 0 );
1125  $parts = $xpath->query( 'part', $contextNode );
1126  if ( $flags & PPFrame::NO_ARGS ) {
1127  $newIterator = $this->virtualBracketedImplode( '{{{', '|', '}}}', $title, $parts );
1128  } else {
1129  $params = array(
1130  'title' => new PPNode_DOM( $title ),
1131  'parts' => new PPNode_DOM( $parts ) );
1132  $ret = $this->parser->argSubstitution( $params, $this );
1133  if ( isset( $ret['object'] ) ) {
1134  $newIterator = $ret['object'];
1135  } else {
1136  $out .= $ret['text'];
1137  }
1138  }
1139  } elseif ( $contextNode->nodeName == 'comment' ) {
1140  # HTML-style comment
1141  # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
1142  if ( $this->parser->ot['html']
1143  || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() )
1145  ) {
1146  $out .= '';
1147  } elseif ( $this->parser->ot['wiki'] && !( $flags & PPFrame::RECOVER_COMMENTS ) ) {
1148  # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
1149  # Not in RECOVER_COMMENTS mode (extractSections) though
1150  $out .= $this->parser->insertStripItem( $contextNode->textContent );
1151  } else {
1152  # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
1153  $out .= $contextNode->textContent;
1154  }
1155  } elseif ( $contextNode->nodeName == 'ignore' ) {
1156  # Output suppression used by <includeonly> etc.
1157  # OT_WIKI will only respect <ignore> in substed templates.
1158  # The other output types respect it unless NO_IGNORE is set.
1159  # extractSections() sets NO_IGNORE and so never respects it.
1160  if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) || ( $flags & PPFrame::NO_IGNORE ) ) {
1161  $out .= $contextNode->textContent;
1162  } else {
1163  $out .= '';
1164  }
1165  } elseif ( $contextNode->nodeName == 'ext' ) {
1166  # Extension tag
1167  $xpath = new DOMXPath( $contextNode->ownerDocument );
1168  $names = $xpath->query( 'name', $contextNode );
1169  $attrs = $xpath->query( 'attr', $contextNode );
1170  $inners = $xpath->query( 'inner', $contextNode );
1171  $closes = $xpath->query( 'close', $contextNode );
1172  $params = array(
1173  'name' => new PPNode_DOM( $names->item( 0 ) ),
1174  'attr' => $attrs->length > 0 ? new PPNode_DOM( $attrs->item( 0 ) ) : null,
1175  'inner' => $inners->length > 0 ? new PPNode_DOM( $inners->item( 0 ) ) : null,
1176  'close' => $closes->length > 0 ? new PPNode_DOM( $closes->item( 0 ) ) : null,
1177  );
1178  $out .= $this->parser->extensionSubstitution( $params, $this );
1179  } elseif ( $contextNode->nodeName == 'h' ) {
1180  # Heading
1181  $s = $this->expand( $contextNode->childNodes, $flags );
1182 
1183  # Insert a heading marker only for <h> children of <root>
1184  # This is to stop extractSections from going over multiple tree levels
1185  if ( $contextNode->parentNode->nodeName == 'root' && $this->parser->ot['html'] ) {
1186  # Insert heading index marker
1187  $headingIndex = $contextNode->getAttribute( 'i' );
1188  $titleText = $this->title->getPrefixedDBkey();
1189  $this->parser->mHeadings[] = array( $titleText, $headingIndex );
1190  $serial = count( $this->parser->mHeadings ) - 1;
1191  $marker = "{$this->parser->mUniqPrefix}-h-$serial-" . Parser::MARKER_SUFFIX;
1192  $count = $contextNode->getAttribute( 'level' );
1193  $s = substr( $s, 0, $count ) . $marker . substr( $s, $count );
1194  $this->parser->mStripState->addGeneral( $marker, '' );
1195  }
1196  $out .= $s;
1197  } else {
1198  # Generic recursive expansion
1199  $newIterator = $contextNode->childNodes;
1200  }
1201  } else {
1202  wfProfileOut( __METHOD__ );
1203  throw new MWException( __METHOD__ . ': Invalid parameter type' );
1204  }
1205 
1206  if ( $newIterator !== false ) {
1207  if ( $newIterator instanceof PPNode_DOM ) {
1208  $newIterator = $newIterator->node;
1209  }
1210  $outStack[] = '';
1211  $iteratorStack[] = $newIterator;
1212  $indexStack[] = 0;
1213  } elseif ( $iteratorStack[$level] === false ) {
1214  // Return accumulated value to parent
1215  // With tail recursion
1216  while ( $iteratorStack[$level] === false && $level > 0 ) {
1217  $outStack[$level - 1] .= $out;
1218  array_pop( $outStack );
1219  array_pop( $iteratorStack );
1220  array_pop( $indexStack );
1221  $level--;
1222  }
1223  }
1224  }
1225  --$expansionDepth;
1226  wfProfileOut( __METHOD__ );
1227  return $outStack[0];
1228  }
1229 
1235  function implodeWithFlags( $sep, $flags /*, ... */ ) {
1236  $args = array_slice( func_get_args(), 2 );
1237 
1238  $first = true;
1239  $s = '';
1240  foreach ( $args as $root ) {
1241  if ( $root instanceof PPNode_DOM ) {
1242  $root = $root->node;
1243  }
1244  if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1245  $root = array( $root );
1246  }
1247  foreach ( $root as $node ) {
1248  if ( $first ) {
1249  $first = false;
1250  } else {
1251  $s .= $sep;
1252  }
1253  $s .= $this->expand( $node, $flags );
1254  }
1255  }
1256  return $s;
1257  }
1258 
1265  function implode( $sep /*, ... */ ) {
1266  $args = array_slice( func_get_args(), 1 );
1267 
1268  $first = true;
1269  $s = '';
1270  foreach ( $args as $root ) {
1271  if ( $root instanceof PPNode_DOM ) {
1272  $root = $root->node;
1273  }
1274  if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1275  $root = array( $root );
1276  }
1277  foreach ( $root as $node ) {
1278  if ( $first ) {
1279  $first = false;
1280  } else {
1281  $s .= $sep;
1282  }
1283  $s .= $this->expand( $node );
1284  }
1285  }
1286  return $s;
1287  }
1288 
1295  function virtualImplode( $sep /*, ... */ ) {
1296  $args = array_slice( func_get_args(), 1 );
1297  $out = array();
1298  $first = true;
1299 
1300  foreach ( $args as $root ) {
1301  if ( $root instanceof PPNode_DOM ) {
1302  $root = $root->node;
1303  }
1304  if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1305  $root = array( $root );
1306  }
1307  foreach ( $root as $node ) {
1308  if ( $first ) {
1309  $first = false;
1310  } else {
1311  $out[] = $sep;
1312  }
1313  $out[] = $node;
1314  }
1315  }
1316  return $out;
1317  }
1323  function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
1324  $args = array_slice( func_get_args(), 3 );
1325  $out = array( $start );
1326  $first = true;
1327 
1328  foreach ( $args as $root ) {
1329  if ( $root instanceof PPNode_DOM ) {
1330  $root = $root->node;
1331  }
1332  if ( !is_array( $root ) && !( $root instanceof DOMNodeList ) ) {
1333  $root = array( $root );
1334  }
1335  foreach ( $root as $node ) {
1336  if ( $first ) {
1337  $first = false;
1338  } else {
1339  $out[] = $sep;
1340  }
1341  $out[] = $node;
1342  }
1343  }
1344  $out[] = $end;
1345  return $out;
1346  }
1348  function __toString() {
1349  return 'frame{}';
1350  }
1351 
1352  function getPDBK( $level = false ) {
1353  if ( $level === false ) {
1354  return $this->title->getPrefixedDBkey();
1355  } else {
1356  return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] : false;
1357  }
1358  }
1359 
1363  function getArguments() {
1364  return array();
1365  }
1366 
1370  function getNumberedArguments() {
1371  return array();
1372  }
1373 
1377  function getNamedArguments() {
1378  return array();
1379  }
1380 
1386  function isEmpty() {
1387  return true;
1388  }
1389 
1390  function getArgument( $name ) {
1391  return false;
1392  }
1393 
1399  function loopCheck( $title ) {
1400  return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
1401  }
1402 
1408  function isTemplate() {
1409  return false;
1410  }
1411 
1417  function getTitle() {
1418  return $this->title;
1419  }
1420 }
1428 
1432  var $parent;
1434 
1442  function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
1443  parent::__construct( $preprocessor );
1444 
1445  $this->parent = $parent;
1446  $this->numberedArgs = $numberedArgs;
1447  $this->namedArgs = $namedArgs;
1448  $this->title = $title;
1449  $pdbk = $title ? $title->getPrefixedDBkey() : false;
1450  $this->titleCache = $parent->titleCache;
1451  $this->titleCache[] = $pdbk;
1452  $this->loopCheckHash = /*clone*/ $parent->loopCheckHash;
1453  if ( $pdbk !== false ) {
1454  $this->loopCheckHash[$pdbk] = true;
1455  }
1456  $this->depth = $parent->depth + 1;
1457  $this->numberedExpansionCache = $this->namedExpansionCache = array();
1458  }
1459 
1460  function __toString() {
1461  $s = 'tplframe{';
1462  $first = true;
1463  $args = $this->numberedArgs + $this->namedArgs;
1464  foreach ( $args as $name => $value ) {
1465  if ( $first ) {
1466  $first = false;
1467  } else {
1468  $s .= ', ';
1469  }
1470  $s .= "\"$name\":\"" .
1471  str_replace( '"', '\\"', $value->ownerDocument->saveXML( $value ) ) . '"';
1472  }
1473  $s .= '}';
1474  return $s;
1475  }
1482  function isEmpty() {
1483  return !count( $this->numberedArgs ) && !count( $this->namedArgs );
1484  }
1485 
1486  function getArguments() {
1487  $arguments = array();
1488  foreach ( array_merge(
1489  array_keys( $this->numberedArgs ),
1490  array_keys( $this->namedArgs ) ) as $key ) {
1491  $arguments[$key] = $this->getArgument( $key );
1492  }
1493  return $arguments;
1494  }
1495 
1496  function getNumberedArguments() {
1497  $arguments = array();
1498  foreach ( array_keys( $this->numberedArgs ) as $key ) {
1499  $arguments[$key] = $this->getArgument( $key );
1500  }
1501  return $arguments;
1502  }
1503 
1504  function getNamedArguments() {
1505  $arguments = array();
1506  foreach ( array_keys( $this->namedArgs ) as $key ) {
1507  $arguments[$key] = $this->getArgument( $key );
1508  }
1509  return $arguments;
1510  }
1511 
1512  function getNumberedArgument( $index ) {
1513  if ( !isset( $this->numberedArgs[$index] ) ) {
1514  return false;
1515  }
1516  if ( !isset( $this->numberedExpansionCache[$index] ) ) {
1517  # No trimming for unnamed arguments
1518  $this->numberedExpansionCache[$index] = $this->parent->expand( $this->numberedArgs[$index], PPFrame::STRIP_COMMENTS );
1519  }
1520  return $this->numberedExpansionCache[$index];
1521  }
1522 
1523  function getNamedArgument( $name ) {
1524  if ( !isset( $this->namedArgs[$name] ) ) {
1525  return false;
1526  }
1527  if ( !isset( $this->namedExpansionCache[$name] ) ) {
1528  # Trim named arguments post-expand, for backwards compatibility
1529  $this->namedExpansionCache[$name] = trim(
1530  $this->parent->expand( $this->namedArgs[$name], PPFrame::STRIP_COMMENTS ) );
1531  }
1532  return $this->namedExpansionCache[$name];
1533  }
1534 
1535  function getArgument( $name ) {
1536  $text = $this->getNumberedArgument( $name );
1537  if ( $text === false ) {
1538  $text = $this->getNamedArgument( $name );
1539  }
1540  return $text;
1541  }
1548  function isTemplate() {
1549  return true;
1550  }
1557 class PPCustomFrame_DOM extends PPFrame_DOM {
1558  var $args;
1560  function __construct( $preprocessor, $args ) {
1561  parent::__construct( $preprocessor );
1562  $this->args = $args;
1563  }
1564 
1565  function __toString() {
1566  $s = 'cstmframe{';
1567  $first = true;
1568  foreach ( $this->args as $name => $value ) {
1569  if ( $first ) {
1570  $first = false;
1571  } else {
1572  $s .= ', ';
1573  }
1574  $s .= "\"$name\":\"" .
1575  str_replace( '"', '\\"', $value->__toString() ) . '"';
1576  }
1577  $s .= '}';
1578  return $s;
1579  }
1580 
1584  function isEmpty() {
1585  return !count( $this->args );
1586  }
1587 
1588  function getArgument( $index ) {
1589  if ( !isset( $this->args[$index] ) ) {
1590  return false;
1591  }
1592  return $this->args[$index];
1593  }
1594 
1595  function getArguments() {
1596  return $this->args;
1597  }
1598 }
1599 
1603 class PPNode_DOM implements PPNode {
1608  var $node;
1609  var $xpath;
1610 
1611  function __construct( $node, $xpath = false ) {
1612  $this->node = $node;
1613  }
1614 
1618  function getXPath() {
1619  if ( $this->xpath === null ) {
1620  $this->xpath = new DOMXPath( $this->node->ownerDocument );
1621  }
1622  return $this->xpath;
1623  }
1624 
1625  function __toString() {
1626  if ( $this->node instanceof DOMNodeList ) {
1627  $s = '';
1628  foreach ( $this->node as $node ) {
1629  $s .= $node->ownerDocument->saveXML( $node );
1630  }
1631  } else {
1632  $s = $this->node->ownerDocument->saveXML( $this->node );
1633  }
1634  return $s;
1635  }
1636 
1640  function getChildren() {
1641  return $this->node->childNodes ? new self( $this->node->childNodes ) : false;
1642  }
1643 
1647  function getFirstChild() {
1648  return $this->node->firstChild ? new self( $this->node->firstChild ) : false;
1649  }
1650 
1654  function getNextSibling() {
1655  return $this->node->nextSibling ? new self( $this->node->nextSibling ) : false;
1656  }
1657 
1663  function getChildrenOfType( $type ) {
1664  return new self( $this->getXPath()->query( $type, $this->node ) );
1665  }
1666 
1670  function getLength() {
1671  if ( $this->node instanceof DOMNodeList ) {
1672  return $this->node->length;
1673  } else {
1674  return false;
1675  }
1676  }
1677 
1682  function item( $i ) {
1683  $item = $this->node->item( $i );
1684  return $item ? new self( $item ) : false;
1685  }
1686 
1690  function getName() {
1691  if ( $this->node instanceof DOMNodeList ) {
1692  return '#nodelist';
1693  } else {
1694  return $this->node->nodeName;
1695  }
1696  }
1697 
1707  function splitArg() {
1708  $xpath = $this->getXPath();
1709  $names = $xpath->query( 'name', $this->node );
1710  $values = $xpath->query( 'value', $this->node );
1711  if ( !$names->length || !$values->length ) {
1712  throw new MWException( 'Invalid brace node passed to ' . __METHOD__ );
1713  }
1714  $name = $names->item( 0 );
1715  $index = $name->getAttribute( 'index' );
1716  return array(
1717  'name' => new self( $name ),
1718  'index' => $index,
1719  'value' => new self( $values->item( 0 ) ) );
1720  }
1721 
1729  function splitExt() {
1730  $xpath = $this->getXPath();
1731  $names = $xpath->query( 'name', $this->node );
1732  $attrs = $xpath->query( 'attr', $this->node );
1733  $inners = $xpath->query( 'inner', $this->node );
1734  $closes = $xpath->query( 'close', $this->node );
1735  if ( !$names->length || !$attrs->length ) {
1736  throw new MWException( 'Invalid ext node passed to ' . __METHOD__ );
1737  }
1738  $parts = array(
1739  'name' => new self( $names->item( 0 ) ),
1740  'attr' => new self( $attrs->item( 0 ) ) );
1741  if ( $inners->length ) {
1742  $parts['inner'] = new self( $inners->item( 0 ) );
1743  }
1744  if ( $closes->length ) {
1745  $parts['close'] = new self( $closes->item( 0 ) );
1746  }
1747  return $parts;
1748  }
1749 
1755  function splitHeading() {
1756  if ( $this->getName() !== 'h' ) {
1757  throw new MWException( 'Invalid h node passed to ' . __METHOD__ );
1758  }
1759  return array(
1760  'i' => $this->node->getAttribute( 'i' ),
1761  'level' => $this->node->getAttribute( 'level' ),
1762  'contents' => $this->getChildren()
1763  );
1764  }
1765 }
PPFrame_DOM\getPDBK
getPDBK( $level=false)
Definition: Preprocessor_DOM.php:1347
Preprocessor_DOM\preprocessToXml
preprocessToXml( $text, $flags=0)
Definition: Preprocessor_DOM.php:207
PPCustomFrame_DOM\$args
$args
Definition: Preprocessor_DOM.php:1552
PPDStackElement\$lineStart
$lineStart
Definition: Preprocessor_DOM.php:826
PPFrame_DOM\$preprocessor
Preprocessor $preprocessor
Definition: Preprocessor_DOM.php:920
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Preprocessor_DOM
Definition: Preprocessor_DOM.php:27
PPFrame\STRIP_COMMENTS
const STRIP_COMMENTS
Definition: Preprocessor.php:75
Preprocessor_DOM\CACHE_VERSION
const CACHE_VERSION
Definition: Preprocessor_DOM.php:35
PPDPart
Definition: Preprocessor_DOM.php:899
of
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
Definition: globals.txt:10
PPNode_DOM
Definition: Preprocessor_DOM.php:1597
PPNode_DOM\item
item( $i)
Definition: Preprocessor_DOM.php:1675
PPNode_DOM\$xpath
$xpath
Definition: Preprocessor_DOM.php:1602
Preprocessor_DOM\$memoryLimit
$memoryLimit
Definition: Preprocessor_DOM.php:33
Preprocessor_DOM\$parser
Parser $parser
Definition: Preprocessor_DOM.php:31
PPFrame_DOM\implodeWithFlags
implodeWithFlags( $sep, $flags)
Definition: Preprocessor_DOM.php:1230
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
PPNode_DOM\$node
DOMElement $node
Definition: Preprocessor_DOM.php:1601
PPFrame_DOM\implode
implode( $sep)
Implode with no flags specified This previously called implodeWithFlags but has now been inlined to r...
Definition: Preprocessor_DOM.php:1260
is
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
PPDStack\pop
pop()
Definition: Preprocessor_DOM.php:785
PPFrame\NO_ARGS
const NO_ARGS
Definition: Preprocessor.php:73
PPFrame_DOM\$depth
$depth
Recursion depth of this frame, top = 0 Note that this is NOT the same as expansion depth in expand()
Definition: Preprocessor_DOM.php:941
PPTemplateFrame_DOM\$namedExpansionCache
$namedExpansionCache
Definition: Preprocessor_DOM.php:1427
Preprocessor
Definition: Preprocessor.php:27
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1357
UtfNormal\cleanUp
static cleanUp( $string)
The ultimate convenience function! Clean up invalid UTF-8 sequences, and convert to normal form C,...
Definition: UtfNormal.php:79
PPFrame_DOM\getNamedArguments
getNamedArguments()
Definition: Preprocessor_DOM.php:1372
PPFrame\NO_IGNORE
const NO_IGNORE
Definition: Preprocessor.php:76
PPDStack\push
push( $data)
Definition: Preprocessor_DOM.php:774
PPFrame_DOM\$titleCache
$titleCache
Definition: Preprocessor_DOM.php:929
character
</p > ! end ! test Bare pipe character(bug 52363) !! wikitext|!! html< p >|</p > !! end !! test Bare pipe character from a template(bug 52363) !! wikitext
Definition: parserTests.txt:918
PPDStack\$top
PPDStack $top
Definition: Preprocessor_DOM.php:742
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
PPDStackElement\getCurrentPart
getCurrentPart()
Definition: Preprocessor_DOM.php:852
PPFrame_DOM\getArgument
getArgument( $name)
Get an argument to this frame by name.
Definition: Preprocessor_DOM.php:1385
PPDStack\$false
static $false
Definition: Preprocessor_DOM.php:746
$params
$params
Definition: styleTest.css.php:40
$limit
if( $sleep) $limit
Definition: importImages.php:99
PPTemplateFrame_DOM\$numberedExpansionCache
$numberedExpansionCache
Definition: Preprocessor_DOM.php:1427
PPTemplateFrame_DOM\getNumberedArgument
getNumberedArgument( $index)
Definition: Preprocessor_DOM.php:1506
PPDStack\$elementClass
$elementClass
Definition: Preprocessor_DOM.php:744
PPTemplateFrame_DOM\getNumberedArguments
getNumberedArguments()
Definition: Preprocessor_DOM.php:1490
$s
$s
Definition: mergeMessageFileList.php:156
PPDStackElement
Definition: Preprocessor_DOM.php:825
PPNode_DOM\splitHeading
splitHeading()
Split a "<h>" node.
Definition: Preprocessor_DOM.php:1748
Makefile.open
open
Definition: Makefile.py:14
PPFrame_DOM\virtualBracketedImplode
virtualBracketedImplode( $start, $sep, $end)
Virtual implode with brackets.
Definition: Preprocessor_DOM.php:1318
PPNode_DOM\getXPath
getXPath()
Definition: Preprocessor_DOM.php:1611
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
PPDStack\getAccum
& getAccum()
Definition: Preprocessor_DOM.php:762
PPTemplateFrame_DOM\getNamedArguments
getNamedArguments()
Definition: Preprocessor_DOM.php:1498
PPDStackElement\getAccum
& getAccum()
Definition: Preprocessor_DOM.php:843
PPFrame\RECOVER_COMMENTS
const RECOVER_COMMENTS
Definition: Preprocessor.php:77
PPFrame\NO_TEMPLATES
const NO_TEMPLATES
Definition: Preprocessor.php:74
PPDStack\count
count()
Definition: Preprocessor_DOM.php:758
PPCustomFrame_DOM\__toString
__toString()
Definition: Preprocessor_DOM.php:1559
PPNode_DOM\__construct
__construct( $node, $xpath=false)
Definition: Preprocessor_DOM.php:1604
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2703
PPCustomFrame_DOM
Expansion frame with custom arguments.
Definition: Preprocessor_DOM.php:1551
PPNode_DOM\getName
getName()
Definition: Preprocessor_DOM.php:1683
PPFrame_DOM\isEmpty
isEmpty()
Returns true if there are no arguments in this frame.
Definition: Preprocessor_DOM.php:1381
PPCustomFrame_DOM\__construct
__construct( $preprocessor, $args)
Definition: Preprocessor_DOM.php:1554
PPTemplateFrame_DOM\isEmpty
isEmpty()
Returns true if there are no arguments in this frame.
Definition: Preprocessor_DOM.php:1476
MWException
MediaWiki exception.
Definition: MWException.php:26
wfMemcKey
wfMemcKey()
Get a cache key.
Definition: GlobalFunctions.php:3580
$out
$out
Definition: UtfNormalGenerate.php:167
PPDStackElement\$count
$count
Definition: Preprocessor_DOM.php:826
PPNode_DOM\getLength
getLength()
Definition: Preprocessor_DOM.php:1663
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
PPFrame_DOM\loopCheck
loopCheck( $title)
Returns true if the infinite loop check is OK, false if a loop is detected.
Definition: Preprocessor_DOM.php:1394
PPDStackElement\breakSyntax
breakSyntax( $openingCount=false)
Get the output string that would result if the close is not found.
Definition: Preprocessor_DOM.php:874
PPDStack\$rootAccum
$rootAccum
Definition: Preprocessor_DOM.php:738
PPDStackElement\getFlags
getFlags()
Definition: Preprocessor_DOM.php:859
PPDStackElement\addPart
addPart( $s='')
Definition: Preprocessor_DOM.php:847
PPCustomFrame_DOM\getArgument
getArgument( $index)
Get an argument to this frame by name.
Definition: Preprocessor_DOM.php:1582
PPTemplateFrame_DOM\__toString
__toString()
Definition: Preprocessor_DOM.php:1454
there
has been added to your &Future changes to this page and its associated Talk page will be listed there
Definition: All_system_messages.txt:357
PPDStackElement\__construct
__construct( $data=array())
Definition: Preprocessor_DOM.php:834
Preprocessor_DOM\__construct
__construct( $parser)
Create a new preprocessor object based on an initialised Parser object.
Definition: Preprocessor_DOM.php:37
PPNode
There are three types of nodes:
Definition: Preprocessor.php:183
PPDStack\addPart
addPart( $s='')
Definition: Preprocessor_DOM.php:801
PPDStackElement\$partClass
$partClass
Definition: Preprocessor_DOM.php:832
PPNode_DOM\getChildren
getChildren()
Definition: Preprocessor_DOM.php:1633
PPTemplateFrame_DOM\$parent
PPFrame_DOM $parent
Definition: Preprocessor_DOM.php:1426
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
Preprocessor_DOM\newCustomFrame
newCustomFrame( $args)
Definition: Preprocessor_DOM.php:61
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
PPDStack\__construct
__construct()
Definition: Preprocessor_DOM.php:748
PPDStack\$out
$out
Definition: Preprocessor_DOM.php:743
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
PPNode_DOM\getChildrenOfType
getChildrenOfType( $type)
Definition: Preprocessor_DOM.php:1656
PPDPart\__construct
__construct( $out='')
Definition: Preprocessor_DOM.php:907
PPTemplateFrame_DOM\$namedArgs
$namedArgs
Definition: Preprocessor_DOM.php:1422
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
PPFrame_DOM\getArguments
getArguments()
Definition: Preprocessor_DOM.php:1358
PPFrame_DOM\isTemplate
isTemplate()
Return true if the frame is a template frame.
Definition: Preprocessor_DOM.php:1403
Preprocessor_DOM\memCheck
memCheck()
Definition: Preprocessor_DOM.php:95
PPFrame_DOM\$loopCheckHash
$loopCheckHash
Hashtable listing templates which are disallowed for expansion in this frame, having been encountered...
Definition: Preprocessor_DOM.php:935
PPDStack\$stack
$stack
Definition: Preprocessor_DOM.php:738
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
$value
$value
Definition: styleTest.css.php:45
PPFrame_DOM\expand
expand( $root, $flags=0)
Definition: Preprocessor_DOM.php:1006
PPDStackElement\$open
$open
Definition: Preprocessor_DOM.php:826
PPFrame_DOM
An expansion frame, used as a context to expand the result of preprocessToObj()
Definition: Preprocessor_DOM.php:916
PPDStack
Stack class to help Preprocessor::preprocessToObj()
Definition: Preprocessor_DOM.php:737
PPFrame
Definition: Preprocessor.php:72
PPTemplateFrame_DOM\$numberedArgs
$numberedArgs
Definition: Preprocessor_DOM.php:1422
$version
$version
Definition: parserTests.php:86
PPNode_DOM\__toString
__toString()
Definition: Preprocessor_DOM.php:1618
PPDStackElement\$parts
$parts
Definition: Preprocessor_DOM.php:826
PPDPart\$out
$out
Definition: Preprocessor_DOM.php:900
PPTemplateFrame_DOM\__construct
__construct( $preprocessor, $parent=false, $numberedArgs=array(), $namedArgs=array(), $title=false)
Definition: Preprocessor_DOM.php:1436
start
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to start
Definition: skin.txt:62
$count
$count
Definition: UtfNormalTest2.php:96
PPTemplateFrame_DOM\getArguments
getArguments()
Definition: Preprocessor_DOM.php:1480
$args
if( $line===false) $args
Definition: cdb.php:62
Title
Represents a title within MediaWiki.
Definition: Title.php:35
PPDStackElement\$close
$close
Definition: Preprocessor_DOM.php:826
PPCustomFrame_DOM\isEmpty
isEmpty()
Definition: Preprocessor_DOM.php:1578
PPFrame_DOM\$parser
Parser $parser
Definition: Preprocessor_DOM.php:924
PPNode_DOM\splitArg
splitArg()
Split a "<part>" node into an associative array containing:
Definition: Preprocessor_DOM.php:1700
in
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning in
Definition: maintenance.txt:1
are
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types are
Definition: contenthandler.txt:5
PPFrame_DOM\__toString
__toString()
Definition: Preprocessor_DOM.php:1343
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Preprocessor_DOM\newPartNodeArray
newPartNodeArray( $values)
Definition: Preprocessor_DOM.php:69
Preprocessor_DOM\newFrame
newFrame()
Definition: Preprocessor_DOM.php:53
PPFrame_DOM\getTitle
getTitle()
Get a title of frame.
Definition: Preprocessor_DOM.php:1412
PPFrame_DOM\newChild
newChild( $args=false, $title=false, $indexOffset=0)
Create a new child frame $args is optionally a multi-root PPNode or array containing the template arg...
Definition: Preprocessor_DOM.php:962
PPFrame_DOM\$title
Title $title
Definition: Preprocessor_DOM.php:928
PPNode_DOM\getFirstChild
getFirstChild()
Definition: Preprocessor_DOM.php:1640
PPCustomFrame_DOM\getArguments
getArguments()
Definition: Preprocessor_DOM.php:1589
PPFrame_DOM\__construct
__construct( $preprocessor)
Construct a new preprocessor frame.
Definition: Preprocessor_DOM.php:947
PPDStack\getCurrentPart
getCurrentPart()
Definition: Preprocessor_DOM.php:766
PPFrame_DOM\getNumberedArguments
getNumberedArguments()
Definition: Preprocessor_DOM.php:1365
PPTemplateFrame_DOM\isTemplate
isTemplate()
Return true if the frame is a template frame.
Definition: Preprocessor_DOM.php:1542
PPNode_DOM\splitExt
splitExt()
Split an "<ext>" node into an associative array containing name, attr, inner and close All values in ...
Definition: Preprocessor_DOM.php:1722
Preprocessor_DOM\preprocessToObj
preprocessToObj( $text, $flags=0)
Preprocess some wikitext and return the document tree.
Definition: Preprocessor_DOM.php:130
PPTemplateFrame_DOM\getArgument
getArgument( $name)
Get an argument to this frame by name.
Definition: Preprocessor_DOM.php:1529
PPFrame_DOM\virtualImplode
virtualImplode( $sep)
Makes an object that, when expand()ed, will be the same as one obtained with implode()
Definition: Preprocessor_DOM.php:1290
line
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for so if you want to use a style that puts opening braces on the next line
Definition: design.txt:79
PPDStack\getFlags
getFlags()
Definition: Preprocessor_DOM.php:809
PPNode_DOM\getNextSibling
getNextSibling()
Definition: Preprocessor_DOM.php:1647
PPTemplateFrame_DOM\getNamedArgument
getNamedArgument( $name)
Definition: Preprocessor_DOM.php:1517
$type
$type
Definition: testCompression.php:46
PPTemplateFrame_DOM
Expansion frame with template arguments.
Definition: Preprocessor_DOM.php:1421