// Encode as though it's a wiki page, '_' for ' '.
case 'url_wiki':
- return wfUrlencode( str_replace( ' ', '_', $s ) );
+ $func = 'wfUrlencode';
+ $s = str_replace( ' ', '_', $s );
+ break;
// Encode for an HTTP Path, '%20' for ' '.
case 'url_path':
- return rawurlencode( $s );
+ $func = 'rawurlencode';
+ break;
// Encode for HTTP query, '+' for ' '.
case 'url_query':
default:
- return urlencode( $s );
+ $func = 'urlencode';
}
+ return $parser->markerSkipCallback( $s, $func );
}
static function lcfirst( $parser, $s = '' ) {
*/
static function lc( $parser, $s = '' ) {
global $wgContLang;
- if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
- return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
- } else {
- return $wgContLang->lc( $s );
- }
+ return $parser->markerSkipCallback( $s, array( $wgContLang, 'lc' ) );
}
/**
*/
static function uc( $parser, $s = '' ) {
global $wgContLang;
- if ( is_callable( array( $parser, 'markerSkipCallback' ) ) ) {
- return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
- } else {
- return $wgContLang->uc( $s );
- }
+ return $parser->markerSkipCallback( $s, array( $wgContLang, 'uc' ) );
}
static function localurl( $parser, $s = '', $arg = null ) { return self::urlFunction( 'getLocalURL', $s, $arg ); }
* @param null $raw
* @return
*/
- static function formatNum( $parser, $num = '', $raw = null) {
- if ( self::israw( $raw ) ) {
- return $parser->getFunctionLang()->parseFormattedNumber( $num );
+ static function formatnum( $parser, $num = '', $raw = null) {
+ if ( self::isRaw( $raw ) ) {
+ $func = array( $parser->getFunctionLang(), 'parseFormattedNumber' );
} else {
- return $parser->getFunctionLang()->formatNum( $num );
+ $func = array( $parser->getFunctionLang(), 'formatNum' );
}
+ return $parser->markerSkipCallback( $num, $func );
}
/**
* @return
*/
static function grammar( $parser, $case = '', $word = '' ) {
+ $word = $parser->killMarkers( $word );
return $parser->getFunctionLang()->convertGrammar( $word, $case );
}
* Unicode-safe str_pad with the restriction that $length is forced to be <= 500
* @return string
*/
- static function pad( $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
+ static function pad( $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) {
+ $padding = $parser->killMarkers( $padding );
$lengthOfPadding = mb_strlen( $padding );
if ( $lengthOfPadding == 0 ) return $string;
}
static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
- return self::pad( $string, $length, $padding, STR_PAD_LEFT );
+ return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
}
static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
- return self::pad( $string, $length, $padding );
+ return self::pad( $parser, $string, $length, $padding );
}
/**
* @return string
*/
static function anchorencode( $parser, $text ) {
+ $text = $parser->killMarkers( $text );
return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
}
}
# The safe header is a version of the header text safe to use for links
- # Avoid insertion of weird stuff like <math> by expanding the relevant sections
- $safeHeadline = $this->mStripState->unstripBoth( $headline );
# Remove link placeholders by the link text.
# <!--LINK number-->
# turns into
# link text with suffix
- $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline );
+ # Do this before unstrip since link text can contain strip markers
+ $safeHeadline = $this->replaceLinkHoldersText( $headline );
+
+ # Avoid insertion of weird stuff like <math> by expanding the relevant sections
+ $safeHeadline = $this->mStripState->unstripBoth( $safeHeadline );
# Strip out HTML (first regex removes any tag not allowed)
# Allowed tags are <sup> and <sub> (bug 8393), <i> (bug 26375) and <b> (r105284)
return $out;
}
+ /**
+ * Remove any strip markers found in the given text.
+ *
+ * @param $text Input string
+ * @return string
+ */
+ function killMarkers( $text ) {
+ return $this->mStripState->killMarkers( $text );
+ }
+
/**
* Save the parser state required to convert the given half-parsed text to
* HTML. "Half-parsed" in this context means the output of
!! end
+!! test
+Strip marker in urlencode
+!! input
+{{urlencode:x<nowiki/>y}}
+{{urlencode:x<nowiki/>y|wiki}}
+{{urlencode:x<nowiki/>y|path}}
+!! result
+<p>xy
+xy
+xy
+</p>
+!! end
+
+!! test
+Strip marker in lc
+!! input
+{{lc:x<nowiki/>y}}
+!! result
+<p>xy
+</p>
+!! end
+
+!! test
+Strip marker in uc
+!! input
+{{uc:x<nowiki/>y}}
+!! result
+<p>XY
+</p>
+!! end
+
+!! test
+Strip marker in formatNum
+!! input
+{{formatnum:1<nowiki/>2}}
+{{formatnum:1<nowiki/>2|R}}
+!! result
+<p>12
+12
+</p>
+!! end
+
+!! test
+Strip marker in grammar
+!! options
+language=fi
+!! input
+{{grammar:elative|foo<nowiki/>bar}}
+!! result
+<p>foobarista
+</p>
+!! end
+
+!! test
+Strip marker in padleft
+!! input
+{{padleft:|2|x<nowiki/>y}}
+!! result
+<p>xy
+</p>
+!! end
+
+!! test
+Strip marker in padright
+!! input
+{{padright:|2|x<nowiki/>y}}
+!! result
+<p>xy
+</p>
+!! end
+
+!! test
+Strip marker in anchorencode
+!! input
+{{anchorencode:x<nowiki/>y}}
+!! result
+<p>xy
+</p>
+!! end
+
+!! test
+nowiki inside link inside heading (bug 18295)
+!! input
+==[[foo|x<nowiki>y</nowiki>z]]==
+!! result
+<h2><span class="editsection">[<a href="/index.php?title=Parser_test&action=edit&section=1" title="Edit section: xyz">edit</a>]</span> <span class="mw-headline" id="xyz"><a href="/index.php?title=Foo&action=edit&redlink=1" class="new" title="Foo (page does not exist)">xyz</a></span></h2>
+
+!! end
+
+
TODO:
more images
more tables