From: Sam Reed Date: Mon, 18 Apr 2011 12:43:53 +0000 (+0000) Subject: * (bug 28532) wfMsgExt() and wfMsgWikiHtml() use $wgOut->parse() X-Git-Tag: 1.31.0-rc.0~30742 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=3a0ed7a04492e4a73b7a3d96c2ca40336f73dcb1;p=lhc%2Fweb%2Fwiklou.git * (bug 28532) wfMsgExt() and wfMsgWikiHtml() use $wgOut->parse() * (bug 16129) Transcluded special pages expose strip markers when they output parsed messages Also adding some related documentation during my travels around the code --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9ce359fb7e..400ad59522 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -238,6 +238,8 @@ PHP if you have not done so prior to upgrading MediaWiki. * 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 diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 0c88816663..2f83b07d7b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -716,10 +716,12 @@ function wfMsgHtml( $key ) { * @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 ); } /** @@ -741,7 +743,7 @@ function wfMsgWikiHtml( $key ) { * 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 ); @@ -781,9 +783,9 @@ function wfMsgExt( $key, $options ) { } 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( '/^

(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { $string = $m[1]; diff --git a/includes/Message.php b/includes/Message.php index 6731f1b39f..8c8f4b4480 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -65,6 +65,8 @@ class Message { /** * In which language to get this message. Overrides the $interface * variable. + * + * @var Language */ protected $language = null; @@ -370,10 +372,18 @@ class Message { 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 ); } @@ -419,17 +429,16 @@ class Message { /** * 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 ); @@ -450,6 +459,8 @@ class Message { /** * Wrapper for what ever method we use to get message contents + * + * @return string */ protected function fetchMessage() { if ( !isset( $this->message ) ) { diff --git a/includes/MessageCache.php b/includes/MessageCache.php index d907a78714..ecb46ac8ad 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -67,6 +67,11 @@ class MessageCache { */ private static $instance; + /** + * @var bool + */ + protected $mInParser = false; + /** * Get the signleton instance of this class * @@ -102,6 +107,8 @@ class MessageCache { /** * ParserOptions is lazy initialised. + * + * @return ParserOptions */ function getParserOptions() { if ( !$this->mParserOptions ) { @@ -220,6 +227,8 @@ class MessageCache { /** * 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 ) { @@ -728,12 +737,41 @@ class MessageCache { 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 @@ -746,16 +784,38 @@ class MessageCache { } 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() { diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 120d55a01a..67a634d9c8 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -792,7 +792,7 @@ class OutputPage { * @param $t Title object */ public function setTitle( $t ) { - $this->getContext()->setTitle($t); + $this->getContext()->setTitle( $t ); } /** diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 13c91d8078..92cff97059 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -278,7 +278,7 @@ class Parser { * 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