* (bug 16129) Transcluded special pages expose strip markers when they output parsed messages
Also adding some related documentation during my travels around the code
* UtfNormal::cleanUp on an invalid utf-8 sequence no longer returns false if intl installed.
* (bug 28561) The css class small will no longer make nested elements even smaller.
* (bug 13172) Array type exif data (like GPS) was not being extracted from images.
+* (bug 28532) wfMsgExt() and wfMsgWikiHtml() use $wgOut->parse()
+* (bug 16129) Transcluded special pages expose strip markers when they output parsed messages
=== API changes in 1.18 ===
* (bug 26339) Throw warning when truncating an overlarge API result
* @return string
*/
function wfMsgWikiHtml( $key ) {
- global $wgOut;
+ global $wgMessageCache;
$args = func_get_args();
array_shift( $args );
- return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args );
+ return wfMsgReplaceArgs(
+ $wgMessageCache->parse( wfMsgGetKey( $key, true ), null, /* can't be set to false */ true ),
+ $args );
}
/**
* Behavior for conflicting options (e.g., parse+parseinline) is undefined.
*/
function wfMsgExt( $key, $options ) {
- global $wgOut;
+ global $wgMessageCache;
$args = func_get_args();
array_shift( $args );
}
if( in_array( 'parse', $options, true ) ) {
- $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
+ $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj );
} elseif ( in_array( 'parseinline', $options, true ) ) {
- $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
+ $string = $wgMessageCache->parse( $string, null, true, !$forContent, $langCodeObj );
$m = array();
if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
$string = $m[1];
/**
* In which language to get this message. Overrides the $interface
* variable.
+ *
+ * @var Language
*/
protected $language = null;
return $message === false || $message === '' || $message === '-';
}
+ /**
+ * @param $value
+ * @return array
+ */
public static function rawParam( $value ) {
return array( 'raw' => $value );
}
-
+
+ /**
+ * @param $value
+ * @return array
+ */
public static function numParam( $value ) {
return array( 'num' => $value );
}
/**
* Wrapper for what ever method we use to parse wikitext.
* @param $string String: Wikitext message contents
- * @return Wikitext parsed into HTML
+ * @return string Wikitext parsed into HTML
*/
protected function parseText( $string ) {
- global $wgOut;
- return $wgOut->parse( $string, /*linestart*/true, $this->interface, $this->language );
+ return MessageCache::singleton()->parse( $string, /*linestart*/true, $this->interface, $this->language );
}
/**
* Wrapper for what ever method we use to {{-transform wikitext.
* @param $string String: Wikitext message contents
- * @return Wikitext with {{-constructs replaced with their values.
+ * @return string Wikitext with {{-constructs replaced with their values.
*/
protected function transformText( $string ) {
return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title );
/**
* Wrapper for what ever method we use to get message contents
+ *
+ * @return string
*/
protected function fetchMessage() {
if ( !isset( $this->message ) ) {
*/
private static $instance;
+ /**
+ * @var bool
+ */
+ protected $mInParser = false;
+
/**
* Get the signleton instance of this class
*
/**
* ParserOptions is lazy initialised.
+ *
+ * @return ParserOptions
*/
function getParserOptions() {
if ( !$this->mParserOptions ) {
/**
* Set the cache to $cache, if it is valid. Otherwise set the cache to false.
+ *
+ * @return bool
*/
function setCache( $cache, $code ) {
if ( isset( $cache['VERSION'] ) && $cache['VERSION'] == MSG_CACHE_VERSION ) {
return $message;
}
+ /**
+ * @param $message string
+ * @param $interface bool
+ * @param $language
+ * @param $title Title
+ * @return string
+ */
function transform( $message, $interface = false, $language = null, $title = null ) {
// Avoid creating parser if nothing to transform
if( strpos( $message, '{{' ) === false ) {
return $message;
}
+ if ( $this->mInParser ) {
+ return $message;
+ }
+
+ $parser = $this->getParser();
+ if ( $parser ) {
+ $popts = $this->getParserOptions();
+ $popts->setInterfaceMessage( $interface );
+ $popts->setTargetLanguage( $language );
+ $popts->setUserLang( $language );
+
+ $this->mInParser = true;
+ $message = $parser->transformMsg( $message, $popts, $title );
+ $this->mInParser = false;
+ }
+ return $message;
+ }
+
+ /**
+ * @return Parser
+ */
+ function getParser() {
global $wgParser, $wgParserConf;
if ( !$this->mParser && isset( $wgParser ) ) {
# Do some initialisation so that we don't have to do it twice
} else {
$this->mParser = clone $wgParser;
}
- #wfDebug( __METHOD__ . ": following contents triggered transform: $message\n" );
}
- if ( $this->mParser ) {
- $popts = $this->getParserOptions();
- $popts->setInterfaceMessage( $interface );
+ return $this->mParser;
+ }
+
+ /**
+ * @param $text string
+ * @param $title Title
+ * @param $interface bool
+ * @param $linestart bool
+ * @param $language
+ * @return ParserOutput
+ */
+ public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null ) {
+ if ( $this->mInParser ) {
+ return htmlspecialchars( $text );
+ }
+
+ $parser = $this->getParser();
+ $popts = $this->getParserOptions();
+
+ if ( $interface ) {
+ $popts->setInterfaceMessage( true );
+ }
+ if ( $language !== null ) {
$popts->setTargetLanguage( $language );
- $popts->setUserLang( $language );
- $message = $this->mParser->transformMsg( $message, $popts, $title );
}
- return $message;
+
+ $this->mInParser = true;
+ $res = $parser->parse( $text, $title, $popts, $linestart );
+ $this->mInParser = false;
+
+ return $res;
}
function disable() {
* @param $t Title object
*/
public function setTitle( $t ) {
- $this->getContext()->setTitle($t);
+ $this->getContext()->setTitle( $t );
}
/**
* Do not call this function recursively.
*
* @param $text String: text we want to parse
- * @param $title A title object
+ * @param $title Title object
* @param $options ParserOptions
* @param $linestart boolean
* @param $clearState boolean