Sanitizing already existing use of PHP's assert
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index dcda8a2..f129f73 100644 (file)
@@ -81,7 +81,7 @@ class Preprocessor_DOM implements Preprocessor {
         */
        function memCheck() {
                if ( $this->memoryLimit === false ) {
-                       return;
+                       return true;
                }
                $usage = memory_get_usage();
                if ( $usage > $this->memoryLimit * 0.9 ) {
@@ -155,7 +155,8 @@ class Preprocessor_DOM implements Preprocessor {
                if ( !$result ) {
                        // Try running the XML through UtfNormal to get rid of invalid characters
                        $xml = UtfNormal::cleanUp( $xml );
-                       $result = $dom->loadXML( $xml );
+                       // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep
+                       $result = $dom->loadXML( $xml, 1 << 19 );
                        if ( !$result ) {
                                throw new MWException( __METHOD__.' generated invalid XML' );
                        }
@@ -478,7 +479,7 @@ class Preprocessor_DOM implements Preprocessor {
                        } elseif ( $found == 'line-end' ) {
                                $piece = $stack->top;
                                // A heading must be open, otherwise \n wouldn't have been in the search list
-                               assert( $piece->open == "\n" );
+                               assert( '$piece->open == "\n"' );
                                $part = $piece->getCurrentPart();
                                // Search back through the input to see if it has a proper close
                                // Do this using the reversed string since the other solutions (end anchor, etc.) are inefficient
@@ -542,7 +543,7 @@ class Preprocessor_DOM implements Preprocessor {
                                                'open' => $curChar,
                                                'close' => $rule['end'],
                                                'count' => $count,
-                                               'lineStart' => ($i == 0 || $text[$i-1] == "\n"),
+                                               'lineStart' => ($i > 0 && $text[$i-1] == "\n"),
                                        );
 
                                        $stack->push( $piece );
@@ -1038,8 +1039,7 @@ class PPFrame_DOM implements PPFrame {
                                                $params = array(
                                                        'title' => new PPNode_DOM( $title ),
                                                        'parts' => new PPNode_DOM( $parts ),
-                                                       'lineStart' => $lineStart,
-                                                       'interwiki' => $this->title->getInterwiki( ) );
+                                                       'lineStart' => $lineStart );
                                                $ret = $this->parser->braceSubstitution( $params, $this );
                                                if ( isset( $ret['object'] ) ) {
                                                        $newIterator = $ret['object'];
@@ -1250,6 +1250,7 @@ class PPFrame_DOM implements PPFrame {
 
        /**
         * Virtual implode with brackets
+        * @return array
         */
        function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
                $args = array_slice( func_get_args(), 3 );
@@ -1339,6 +1340,15 @@ class PPFrame_DOM implements PPFrame {
        function isTemplate() {
                return false;
        }
+
+       /**
+        * Get a title of frame
+        *
+        * @return Title
+        */
+       function getTitle() {
+               return $this->title;
+       }
 }
 
 /**
@@ -1665,6 +1675,7 @@ class PPNode_DOM implements PPNode {
 
        /**
         * Split a <h> node
+        * @return array
         */
        function splitHeading() {
                if ( $this->getName() !== 'h' ) {