$text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text );
}
# Template substitution
- $regex = '/{{(['.$titleChars.']*)(\\|.*?|)}}/s';
+ $regex = '/(\\n|{)?{{(['.$titleChars.']*)(\\|.*?|)}}/s';
$text = preg_replace_callback( $regex, 'wfBraceSubstitution', $text );
array_pop( $this->mArgStack );
$found = false;
$nowiki = false;
$noparse = false;
- $itcamefromthedatabase = false;
$title = NULL;
+ # Need to know if the template comes at the start of a line,
+ # to treat the beginning of the template like the beginning
+ # of a line for tables and block-level elements.
+ $linestart = $matches[1];
+
# $part1 is the bit before the first |, and must contain only title characters
# $args is a list of arguments, starting from index 0, not including $part1
- $part1 = $matches[1];
- # If the second subpattern matched anything, it will start with |
+ $part1 = $matches[2];
+ # If the third subpattern matched anything, it will start with |
- $args = $this->getTemplateArgs($matches[2]);
+ $args = $this->getTemplateArgs($matches[3]);
$argc = count( $args );
- # {{{}}}
- if ( strpos( $matches[0], '{{{' ) !== false ) {
+ # Don't parse {{{}}} because that's only for template arguments
+ if ( $linestart === '{' ) {
$text = $matches[0];
$found = true;
$noparse = true;
$mwInt =& MagicWord::get( MAG_INT );
if ( $mwInt->matchStartAndRemove( $part1 ) ) {
if ( $this->incrementIncludeCount( 'int:'.$part1 ) ) {
- $text = wfMsgReal( $part1, $args, true );
+ $text = $linestart . wfMsgReal( $part1, $args, true );
$found = true;
}
}
$mwNs = MagicWord::get( MAG_NS );
if ( $mwNs->matchStartAndRemove( $part1 ) ) {
if ( intval( $part1 ) ) {
- $text = $wgContLang->getNsText( intval( $part1 ) );
+ $text = $linestart . $wgContLang->getNsText( intval( $part1 ) );
$found = true;
} else {
$index = Namespace::getCanonicalIndex( strtolower( $part1 ) );
if ( !is_null( $index ) ) {
- $text = $wgContLang->getNsText( $index );
+ $text = $linestart . $wgContLang->getNsText( $index );
$found = true;
}
}
$title = Title::newFromText( $part1 );
if ( !is_null( $title ) ) {
if ( $argc > 0 ) {
- $text = $title->$func( $args[0] );
+ $text = $linestart . $title->$func( $args[0] );
} else {
- $text = $title->$func();
+ $text = $linestart . $title->$func();
}
$found = true;
}
if ( !$found && $argc == 1 ) {
$mwGrammar =& MagicWord::get( MAG_GRAMMAR );
if ( $mwGrammar->matchStartAndRemove( $part1 ) ) {
- $text = $wgContLang->convertGrammar( $args[0], $part1 );
+ $text = $linestart . $wgContLang->convertGrammar( $args[0], $part1 );
$found = true;
}
}
# and we need to check for loops.
if ( !$found && isset( $this->mTemplates[$part1] ) ) {
# set $text to cached message.
- $text = $this->mTemplates[$part1];
+ $text = $linestart . $this->mTemplates[$part1];
$found = true;
# Infinite loop test
$articleContent = $article->getContentWithoutUsingSoManyDamnGlobals();
if ( $articleContent !== false ) {
$found = true;
- $text = $articleContent;
- $itcamefromthedatabase = true;
+ $text = $linestart . $articleContent;
}
}
# If the title is valid but undisplayable, make a link to it
if ( $this->mOutputType == OT_HTML && !$found ) {
- $text = '[['.$title->getPrefixedText().']]';
+ $text = $linestart . '[['.$title->getPrefixedText().']]';
$found = true;
}
if ( $this->mOutputType == OT_HTML && !is_null( $title ) ) {
$wgLinkCache->addLinkObj( $title );
}
- }
- # Empties the template path
- $this->mTemplatePath = array();
- if ( !$found ) {
- return $matches[0];
- } else {
# replace ==section headers==
# XXX this needs to go away once we have a better parser.
- if ( $this->mOutputType != OT_WIKI && $itcamefromthedatabase ) {
+ if ( $this->mOutputType == OT_HTML ) {
if( !is_null( $title ) )
$encodedname = base64_encode($title->getPrefixedDBkey());
else
$encodedname = base64_encode("");
- $matches = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1,
+ $m = preg_split('/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1,
PREG_SPLIT_DELIM_CAPTURE);
$text = '';
$nsec = 0;
- for( $i = 0; $i < count($matches); $i += 2 ) {
- $text .= $matches[$i];
- if (!isset($matches[$i + 1]) || $matches[$i + 1] == "") continue;
- $hl = $matches[$i + 1];
+ for( $i = 0; $i < count($m); $i += 2 ) {
+ $text .= $m[$i];
+ if (!isset($m[$i + 1]) || $m[$i + 1] == "") continue;
+ $hl = $m[$i + 1];
if( strstr($hl, "<!--MWTEMPLATESECTION") ) {
$text .= $hl;
continue;
$nsec++;
}
}
+
+ # If the template begins with a table or block-level
+ # element, it should be treated as beginning a new line.
+ if ($linestart !== '\n' && preg_match('/^({\\||:|;|#|\*)/', $text)) {
+ $text = "\n" . $text;
+ }
+ }
+
+ # Empties the template path
+ $this->mTemplatePath = array();
+ if ( !$found ) {
+ return $matches[0];
+ } else {
return $text;
}
}