X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fparser%2FPreprocessor_DOM.php;h=602d88fad08906cb7f055f501c8eed243fa6e6a1;hb=843738b4cd68d2e3121430237de085a6dd9df8eb;hp=537abe98918ad2e7c5212d353a6051633c5e1c28;hpb=27b5141563906d369db232f1dbfa4a1ed82ea460;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php
index 537abe9891..602d88fad0 100644
--- a/includes/parser/Preprocessor_DOM.php
+++ b/includes/parser/Preprocessor_DOM.php
@@ -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 'Node-count limit exceeded';
}
if ( $expansionDepth > $this->parser->mOptions->getMaxPPExpandDepth() ) {
+ $this->parser->limitationWarn( 'expansion-depth-exceeded',
+ $expansionDepth,
+ $this->parser->mOptions->getMaxPPExpandDepth()
+ );
return 'Expansion depth limit exceeded';
}
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 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 node
+ * @return array
*/
function splitHeading() {
if ( $this->getName() !== 'h' ) {