* Add a amtitle param to meta=allmessages
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 9 Feb 2011 15:19:45 +0000 (15:19 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Wed, 9 Feb 2011 15:19:45 +0000 (15:19 +0000)
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"

RELEASE-NOTES
includes/Message.php
includes/MessageCache.php
includes/api/ApiQueryAllmessages.php
includes/parser/Parser.php

index c7c720b..d148b6e 100644 (file)
@@ -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 ===
 
index 57cee68..7dd14e1 100644 (file)
@@ -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 );
        }
 
        /**
index 577c812..ed5778d 100644 (file)
@@ -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;
        }
index 9799c2c..709f1f9 100644 (file)
@@ -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',
index b7c63bf..917f7dc 100644 (file)
@@ -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