r89038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89037‎ | r89038 | r89039 >
Date:14:54, 28 May 2011
Author:reedy
Status:ok
Tags:
Comment:
Loads more documentation for this file.. Hopefully CR will show it all ;)
Modified paths:
  • /trunk/phase3/includes/parser/Preprocessor_DOM.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Preprocessor_DOM.php
@@ -10,8 +10,14 @@
1111 * @ingroup Parser
1212 */
1313 class Preprocessor_DOM implements Preprocessor {
14 - var $parser, $memoryLimit;
1514
 15+ /**
 16+ * @var Parser
 17+ */
 18+ var $parser;
 19+
 20+ var $memoryLimit;
 21+
1622 const CACHE_VERSION = 1;
1723
1824 function __construct( $parser ) {
@@ -42,6 +48,10 @@
4349 return new PPCustomFrame_DOM( $this, $args );
4450 }
4551
 52+ /**
 53+ * @param $values
 54+ * @return PPNode_DOM
 55+ */
4656 function newPartNodeArray( $values ) {
4757 //NOTE: DOM manipulation is slower than building & parsing XML! (or so Tim sais)
4858 $xml = "<list>";
@@ -65,6 +75,10 @@
6676 return $node;
6777 }
6878
 79+ /**
 80+ * @throws MWException
 81+ * @return bool
 82+ */
6983 function memCheck() {
7084 if ( $this->memoryLimit === false ) {
7185 return;
@@ -97,7 +111,7 @@
98112 * cache may be implemented at a later date which takes further advantage of these strict
99113 * dependency requirements.
100114 *
101 - * @private
 115+ * @return PPNode_DOM
102116 */
103117 function preprocessToObj( $text, $flags = 0 ) {
104118 wfProfileIn( __METHOD__ );
@@ -154,6 +168,11 @@
155169 return $obj;
156170 }
157171
 172+ /**
 173+ * @param $text string
 174+ * @param $flags int
 175+ * @return string
 176+ */
158177 function preprocessToXml( $text, $flags = 0 ) {
159178 wfProfileIn( __METHOD__ );
160179 $rules = array(
@@ -430,9 +449,7 @@
431450 $accum .= '<inner>' . htmlspecialchars( $inner ) . '</inner>';
432451 }
433452 $accum .= $close . '</ext>';
434 - }
435 -
436 - elseif ( $found == 'line-start' ) {
 453+ } elseif ( $found == 'line-start' ) {
437454 // Is this the start of a heading?
438455 // Line break belongs before the heading element in any case
439456 if ( $fakeLineStart ) {
@@ -460,9 +477,7 @@
461478 extract( $flags );
462479 $i += $count;
463480 }
464 - }
465 -
466 - elseif ( $found == 'line-end' ) {
 481+ } elseif ( $found == 'line-end' ) {
467482 $piece = $stack->top;
468483 // A heading must be open, otherwise \n wouldn't have been in the search list
469484 assert( $piece->open == "\n" );
@@ -564,7 +579,7 @@
565580 }
566581 }
567582
568 - if ($matchingCount <= 0) {
 583+ if ( $matchingCount <= 0 ) {
569584 # No matching element found in callback array
570585 # Output a literal closing brace and continue
571586 $accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
@@ -614,7 +629,7 @@
615630 $accum =& $stack->getAccum();
616631
617632 # Re-add the old stack element if it still has unmatched opening characters remaining
618 - if ($matchingCount < $piece->count) {
 633+ if ( $matchingCount < $piece->count ) {
619634 $piece->parts = array( new PPDPart );
620635 $piece->count -= $matchingCount;
621636 # do we still qualify for any callback with remaining count?
@@ -637,16 +652,12 @@
638653
639654 # Add XML element to the enclosing accumulator
640655 $accum .= $element;
641 - }
642 -
643 - elseif ( $found == 'pipe' ) {
 656+ } elseif ( $found == 'pipe' ) {
644657 $findEquals = true; // shortcut for getFlags()
645658 $stack->addPart();
646659 $accum =& $stack->getAccum();
647660 ++$i;
648 - }
649 -
650 - elseif ( $found == 'equals' ) {
 661+ } elseif ( $found == 'equals' ) {
651662 $findEquals = false; // shortcut for getFlags()
652663 $stack->getCurrentPart()->eqpos = strlen( $accum );
653664 $accum .= '=';
@@ -672,7 +683,12 @@
673684 * @ingroup Parser
674685 */
675686 class PPDStack {
676 - var $stack, $rootAccum, $top;
 687+ var $stack, $rootAccum;
 688+
 689+ /**
 690+ * @var PPDStack
 691+ */
 692+ var $top;
677693 var $out;
678694 var $elementClass = 'PPDStackElement';
679695
@@ -685,6 +701,9 @@
686702 $this->accum =& $this->rootAccum;
687703 }
688704
 705+ /**
 706+ * @return int
 707+ */
689708 function count() {
690709 return count( $this->stack );
691710 }
@@ -733,6 +752,9 @@
734753 $this->accum =& $this->top->getAccum();
735754 }
736755
 756+ /**
 757+ * @return array
 758+ */
737759 function getFlags() {
738760 if ( !count( $this->stack ) ) {
739761 return array(
@@ -780,6 +802,9 @@
781803 return $this->parts[count($this->parts) - 1];
782804 }
783805
 806+ /**
 807+ * @return array
 808+ */
784809 function getFlags() {
785810 $partCount = count( $this->parts );
786811 $findPipe = $this->open != "\n" && $this->open != '[';
@@ -792,6 +817,8 @@
793818
794819 /**
795820 * Get the output string that would result if the close is not found.
 821+ *
 822+ * @return string
796823 */
797824 function breakSyntax( $openingCount = false ) {
798825 if ( $this->open == "\n" ) {
@@ -836,7 +863,21 @@
837864 * @ingroup Parser
838865 */
839866 class PPFrame_DOM implements PPFrame {
840 - var $preprocessor, $parser, $title;
 867+
 868+ /**
 869+ * @var Preprocessor
 870+ */
 871+ var $preprocessor;
 872+
 873+ /**
 874+ * @var Parser
 875+ */
 876+ var $parser;
 877+
 878+ /**
 879+ * @var Title
 880+ */
 881+ var $title;
841882 var $titleCache;
842883
843884 /**
@@ -854,7 +895,7 @@
855896
856897 /**
857898 * Construct a new preprocessor frame.
858 - * @param $preprocessor Preprocessor: The parent preprocessor
 899+ * @param $preprocessor Preprocessor The parent preprocessor
859900 */
860901 function __construct( $preprocessor ) {
861902 $this->preprocessor = $preprocessor;
@@ -868,6 +909,8 @@
869910 /**
870911 * Create a new child frame
871912 * $args is optionally a multi-root PPNode or array containing the template arguments
 913+ *
 914+ * @return PPTemplateFrame_DOM
872915 */
873916 function newChild( $args = false, $title = false ) {
874917 $namedArgs = array();
@@ -903,6 +946,12 @@
904947 return new PPTemplateFrame_DOM( $this->preprocessor, $this, $numberedArgs, $namedArgs, $title );
905948 }
906949
 950+ /**
 951+ * @throws MWException
 952+ * @param $root
 953+ * @param $flags int
 954+ * @return string
 955+ */
907956 function expand( $root, $flags = 0 ) {
908957 static $expansionDepth = 0;
909958 if ( is_string( $root ) ) {
@@ -1114,6 +1163,11 @@
11151164 return $outStack[0];
11161165 }
11171166
 1167+ /**
 1168+ * @param $sep
 1169+ * @param $flags
 1170+ * @return string
 1171+ */
11181172 function implodeWithFlags( $sep, $flags /*, ... */ ) {
11191173 $args = array_slice( func_get_args(), 2 );
11201174
@@ -1139,6 +1193,8 @@
11401194 /**
11411195 * Implode with no flags specified
11421196 * This previously called implodeWithFlags but has now been inlined to reduce stack depth
 1197+ *
 1198+ * @return string
11431199 */
11441200 function implode( $sep /*, ... */ ) {
11451201 $args = array_slice( func_get_args(), 1 );
@@ -1234,20 +1290,31 @@
12351291 }
12361292 }
12371293
 1294+ /**
 1295+ * @return array
 1296+ */
12381297 function getArguments() {
12391298 return array();
12401299 }
12411300
 1301+ /**
 1302+ * @return array
 1303+ */
12421304 function getNumberedArguments() {
12431305 return array();
12441306 }
12451307
 1308+ /**
 1309+ * @return array
 1310+ */
12461311 function getNamedArguments() {
12471312 return array();
12481313 }
12491314
12501315 /**
12511316 * Returns true if there are no arguments in this frame
 1317+ *
 1318+ * @return bool
12521319 */
12531320 function isEmpty() {
12541321 return true;
@@ -1259,6 +1326,8 @@
12601327
12611328 /**
12621329 * Returns true if the infinite loop check is OK, false if a loop is detected
 1330+ *
 1331+ * @return bool
12631332 */
12641333 function loopCheck( $title ) {
12651334 return !isset( $this->loopCheckHash[$title->getPrefixedDBkey()] );
@@ -1266,6 +1335,8 @@
12671336
12681337 /**
12691338 * Return true if the frame is a template frame
 1339+ *
 1340+ * @return bool
12701341 */
12711342 function isTemplate() {
12721343 return false;
@@ -1277,9 +1348,21 @@
12781349 * @ingroup Parser
12791350 */
12801351 class PPTemplateFrame_DOM extends PPFrame_DOM {
1281 - var $numberedArgs, $namedArgs, $parent;
 1352+ var $numberedArgs, $namedArgs;
 1353+
 1354+ /**
 1355+ * @var PPFrame_DOM
 1356+ */
 1357+ var $parent;
12821358 var $numberedExpansionCache, $namedExpansionCache;
12831359
 1360+ /**
 1361+ * @param $preprocessor
 1362+ * @param $parent PPFrame_DOM
 1363+ * @param $numberedArgs array
 1364+ * @param $namedArgs array
 1365+ * @param $title Title
 1366+ */
12841367 function __construct( $preprocessor, $parent = false, $numberedArgs = array(), $namedArgs = array(), $title = false ) {
12851368 parent::__construct( $preprocessor );
12861369
@@ -1314,8 +1397,11 @@
13151398 $s .= '}';
13161399 return $s;
13171400 }
 1401+
13181402 /**
13191403 * Returns true if there are no arguments in this frame
 1404+ *
 1405+ * @return bool
13201406 */
13211407 function isEmpty() {
13221408 return !count( $this->numberedArgs ) && !count( $this->namedArgs );
@@ -1380,6 +1466,8 @@
13811467
13821468 /**
13831469 * Return true if the frame is a template frame
 1470+ *
 1471+ * @return bool
13841472 */
13851473 function isTemplate() {
13861474 return true;
@@ -1414,6 +1502,9 @@
14151503 return $s;
14161504 }
14171505
 1506+ /**
 1507+ * @return bool
 1508+ */
14181509 function isEmpty() {
14191510 return !count( $this->args );
14201511 }
@@ -1430,8 +1521,13 @@
14311522 * @ingroup Parser
14321523 */
14331524 class PPNode_DOM implements PPNode {
1434 - var $node, $xpath;
14351525
 1526+ /**
 1527+ * @var DOMElement
 1528+ */
 1529+ var $node;
 1530+ var $xpath;
 1531+
14361532 function __construct( $node, $xpath = false ) {
14371533 $this->node = $node;
14381534 }

Status & tagging log