Bug 36785 Special:Shortpages lists only NS_MAIN pages. (pages from all $wgContentName...
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index 537abe9..602d88f 100644 (file)
@@ -2,6 +2,21 @@
 /**
  * Preprocessor using PHP's dom extension
  *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Parser
  */
@@ -81,7 +96,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 +170,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 +494,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 +558,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 );
@@ -956,16 +972,26 @@ class PPFrame_DOM implements PPFrame {
                        return $root;
                }
 
-               if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() )
-               {
+               if ( ++$this->parser->mPPNodeCount > $this->parser->mOptions->getMaxPPNodeCount() ) {
+                       $this->parser->limitationWarn( 'node-count-exceeded',
+                               $this->parser->mPPNodeCount,
+                               $this->parser->mOptions->getMaxPPNodeCount()
+                       );
                        return '<span class="error">Node-count limit exceeded</span>';
                }
 
                if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
+                       $this->parser->limitationWarn( 'expansion-depth-exceeded',
+                               $expansionDepth,
+                               $this->parser->mOptions->getMaxPPExpandDepth()
+                       );
                        return '<span class="error">Expansion depth limit exceeded</span>';
                }
                wfProfileIn( __METHOD__ );
                ++$expansionDepth;
+               if ( $expansionDepth > $this->parser->mHighestExpansionDepth ) {
+                       $this->parser->mHighestExpansionDepth = $expansionDepth;
+               }
 
                if ( $root instanceof PPNode_DOM ) {
                        $root = $root->node;
@@ -1089,11 +1115,8 @@ class PPFrame_DOM implements PPFrame {
                                        # OT_WIKI will only respect <ignore> in substed templates.
                                        # The other output types respect it unless NO_IGNORE is set.
                                        # extractSections() sets NO_IGNORE and so never respects it.
-                                       if ( $flags & PPFrame::NO_IGNORE ) {
+                                       if ( ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) || ( $flags & PPFrame::NO_IGNORE ) ) {
                                                $out .= $contextNode->textContent;
-                                       # Add a strip marker in PST mode so that pstPass2() can run some old-fashioned regexes on the result
-                                       } elseif ( !isset( $this->parent ) && $this->parser->ot['wiki'] ) {
-                                               $out .= $this->parser->insertStripItem( $contextNode->textContent );
                                        } else {
                                                $out .= '';
                                        }
@@ -1253,6 +1276,7 @@ class PPFrame_DOM implements PPFrame {
 
        /**
         * Virtual implode with brackets
+        * @return array
         */
        function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
                $args = array_slice( func_get_args(), 3 );
@@ -1342,6 +1366,15 @@ class PPFrame_DOM implements PPFrame {
        function isTemplate() {
                return false;
        }
+
+       /**
+        * Get a title of frame
+        *
+        * @return Title
+        */
+       function getTitle() {
+               return $this->title;
+       }
 }
 
 /**
@@ -1668,6 +1701,7 @@ class PPNode_DOM implements PPNode {
 
        /**
         * Split a <h> node
+        * @return array
         */
        function splitHeading() {
                if ( $this->getName() !== 'h' ) {