From: Alexandre Emsenhuber Date: Wed, 9 Feb 2011 15:19:45 +0000 (+0000) Subject: * Add a amtitle param to meta=allmessages X-Git-Tag: 1.31.0-rc.0~32096 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=195eafd6ef664c2f7a238eb553f5653fd04a246e;p=lhc%2Fweb%2Fwiklou.git * Add a amtitle param to meta=allmessages Only used used when amenableparser is passed; the user can now define the page used for {{PAGENAME}} and related stuff instead of being hardcoded to "API" --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c7c720baee..d148b6e88f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -163,6 +163,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Expose list of skins in meta=siteinfo * (bug 26548) Add iiurlparam param to query=imageinfo and query=stashimageinfo * (bug 27205) aiprop=metadata and aiprop=parsedcomment need help text +* Add a amtitle param to meta=allmessages === Languages updated in 1.18 === diff --git a/includes/Message.php b/includes/Message.php index 57cee6862f..7dd14e15c4 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -94,6 +94,11 @@ class Message { */ protected $useDatabase = true; + /** + * Title object to use as context + */ + protected $title = null; + /** * Constructor. * @param $key: message key, or array of message keys to try and use the first non-empty message for @@ -238,6 +243,17 @@ class Message { return $this; } + /** + * Set the Title object to use as context when transforming the message + * + * @param $title Title object + * @return Message: $this + */ + public function title( $title ) { + $this->title = $title; + return $this; + } + /** * Returns the message parsed from wikitext to HTML. * TODO: in PHP >= 5.2.0, we can make this a magic method, @@ -395,7 +411,7 @@ class Message { * @return Wikitext with {{-constructs replaced with their values. */ protected function transformText( $string ) { - return MessageCache::singleton()->transform( $string, $this->interface, $this->language ); + return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title ); } /** diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 577c812fa9..ed5778db9e 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -729,7 +729,7 @@ class MessageCache { return $message; } - function transform( $message, $interface = false, $language = null ) { + function transform( $message, $interface = false, $language = null, $title = null ) { // Avoid creating parser if nothing to transform if( strpos( $message, '{{' ) === false ) { return $message; @@ -754,7 +754,7 @@ class MessageCache { $popts->setInterfaceMessage( $interface ); $popts->setTargetLanguage( $language ); $popts->setUserLang( $language ); - $message = $this->mParser->transformMsg( $message, $popts ); + $message = $this->mParser->transformMsg( $message, $popts, $title ); } return $message; } diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index 9799c2c325..709f1f9001 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -50,6 +50,17 @@ class ApiQueryAllmessages extends ApiQueryBase { $langObj = Language::factory( $params['lang'] ); } + if ( $params['enableparser'] ) { + if ( !is_null( $params['title'] ) ) { + $title = Title::newFromText( $params['title'] ); + if ( !$title ) { + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + } + } else { + $title = Title::newFromText( 'API' ); + } + } + $prop = array_flip( (array)$params['prop'] ); // Determine which messages should we print @@ -101,7 +112,7 @@ class ApiQueryAllmessages extends ApiQueryBase { } else { // Check if the parser is enabled: if ( $params['enableparser'] ) { - $msgString = $msg->text(); + $msgString = $msg->title( $title )->text(); } else { $msgString = $msg->plain(); } @@ -158,6 +169,7 @@ class ApiQueryAllmessages extends ApiQueryBase { 'lang' => null, 'from' => null, 'to' => null, + 'title' => null, ); } @@ -167,6 +179,7 @@ class ApiQueryAllmessages extends ApiQueryBase { 'prop' => 'Which properties to get', 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message', 'Will substitute magic words, handle templates etc.' ), + 'title' => 'Page name to use as context when parsing message (for enableparser option)', 'args' => 'Arguments to be substituted into message', 'filter' => 'Return only messages that contain this string', 'lang' => 'Return messages in this language', diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index b7c63bfc17..917f7dc437 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4269,10 +4269,10 @@ class Parser { * * @param $text String: the text to preprocess * @param $options ParserOptions: options + * @param $title Title object or null to use $wgTitle * @return String */ - public function transformMsg( $text, $options ) { - global $wgTitle; + public function transformMsg( $text, $options, $title = null ) { static $executing = false; # Guard against infinite recursion @@ -4282,7 +4282,10 @@ class Parser { $executing = true; wfProfileIn( __METHOD__ ); - $title = $wgTitle; + if ( !$title ) { + global $wgTitle; + $title = $wgTitle; + } if ( !$title ) { # It's not uncommon having a null $wgTitle in scripts. See r80898 # Create a ghost title in such case