$endpos = strpos( $text, '-->', $i + 4 );
if ( $endpos === false ) {
// Unclosed comment in input, runs to end
- $accum .= htmlspecialchars( substr( $text, $i ) );
+ $inner = substr( $text, $i );
if ( $this->ot['html'] ) {
// Close it so later stripping can remove it
- $accum .= htmlspecialchars( '-->' );
+ $inner .= '-->';
}
+ $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
$i = strlen( $text );
- continue;
+ } else {
+ $inner = substr( $text, $i, $endpos - $i + 3 );
+ $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
+ $i = $endpos + 3;
}
- $accum .= htmlspecialchars( substr( $text, $i, $endpos - $i + 3 ) );
- #$inner = substr( $text, $i + 4, $endpos - $i - 4 );
- #$accum .= '<ext><name>!--</name><inner>' . htmlspecialchars( $inner ) . '</inner></ext>';
- $i = $endpos + 3;
continue;
}
$name = $matches[1];
throw new MWException( __METHOD__ . ' called using the old argument format' );
}
+ # Remove comments
+ # This could theoretically be merged into preprocessToDom()
+ if ( $this->ot['html'] || ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) ) {
+ $text = Sanitizer::removeHTMLcomments( $text );
+ }
+
$dom = $this->preprocessToDom( $text );
$flags = $argsOnly ? PPFrame::NO_TEMPLATES : 0;
$text = $frame->expand( $dom, $flags );
$text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
}
+ # Remove comments
+ # This could theoretically be merged into preprocessToDom()
+ if ( $this->ot['html'] || ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) ) {
+ $text = Sanitizer::removeHTMLcomments( $text );
+ }
+
$dom = $this->preprocessToDom( $text );
$this->mTplDomCache[ $titleText ] = $dom;
$marker = "{$this->mUniqPrefix}-$name-" . sprintf('%08X', $n++) . $this->mMarkerSuffix;
if ( $this->ot['html'] ) {
- if ( $name == '!--' ) {
- return '';
- }
$name = strtolower( $name );
$params = Sanitizer::decodeTagAttributes( $attrText );
}
}
} else {
- if ( $name == '!--' ) {
- $output = '<!--' . $content . '-->';
+ if ( $content === null ) {
+ $output = "<$name$attrText/>";
} else {
- if ( $content === null ) {
- $output = "<$name$attrText/>";
- } else {
- $close = is_null( $params['close'] ) ? '' : $frame->expand( $params['close'] );
- $output = "<$name$attrText>$content$close";
- }
+ $close = is_null( $params['close'] ) ? '' : $frame->expand( $params['close'] );
+ $output = "<$name$attrText>$content$close";
}
}
* for "replace", the whole page with the section replaced.
*/
private function extractSections( $text, $section, $mode, $newText='' ) {
+ global $wgTitle;
$this->clearState();
+ $this->mTitle = $wgTitle; // not generally used but removes an ugly failure mode
$this->mOptions = new ParserOptions;
$this->setOutputType( OT_WIKI );
$curIndex = 0;
function srvus( $text ) {
$text = $this->replaceVariables( $text );
$text = $this->mStripState->unstripBoth( $text );
+ $text = Sanitizer::removeHTMLtags( $text );
return $text;
}
}
const NO_ARGS = 1;
const NO_TEMPLATES = 2;
+ const STRIP_COMMENTS = 4;
+
const RECOVER_ORIG = 3;
/**
$name = $nameNodes->item( 0 )->attributes->getNamedItem( 'index' )->textContent;
} else {
// Named parameter
- $name = $this->expand( $nameNodes->item( 0 ) );
+ $name = $this->expand( $nameNodes->item( 0 ), PPFrame::STRIP_COMMENTS );
}
$value = $xpath->query( 'value', $arg );
$params = array( 'title' => $title, 'parts' => $parts, 'text' => 'FIXME' );
$s = $this->parser->argSubstitution( $params, $this );
}
+ } elseif ( $root->nodeName == 'comment' ) {
+ # HTML-style comment
+ if ( $flags & self::STRIP_COMMENTS ) {
+ $s = '';
+ } else {
+ $s = $root->textContent;
+ }
} elseif ( $root->nodeName == 'ext' ) {
# Extension tag
$xpath = new DOMXPath( $root->ownerDocument );