aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>2011-02-09 15:19:45 +0000
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>2011-02-09 15:19:45 +0000
commit195eafd6ef664c2f7a238eb553f5653fd04a246e (patch)
treee426e28181e94107ec5373e8b779fc04e7de447e
parent4abff2596654626d04a13fb3c59d1db9f8ed93cd (diff)
downloadmediawikicore-195eafd6ef664c2f7a238eb553f5653fd04a246e.tar.gz
mediawikicore-195eafd6ef664c2f7a238eb553f5653fd04a246e.zip
* 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"
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/81816
-rw-r--r--RELEASE-NOTES1
-rw-r--r--includes/Message.php18
-rw-r--r--includes/MessageCache.php4
-rw-r--r--includes/api/ApiQueryAllmessages.php15
-rw-r--r--includes/parser/Parser.php9
5 files changed, 40 insertions, 7 deletions
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index c7c720baeecc..d148b6e88fd6 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 57cee6862f72..7dd14e15c478 100644
--- a/includes/Message.php
+++ b/includes/Message.php
@@ -95,6 +95,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
* @param $params Array message parameters
@@ -239,6 +244,17 @@ class Message {
}
/**
+ * 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,
* and then we can do, eg:
@@ -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 577c812fa9f0..ed5778db9ebb 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 9799c2c325c0..709f1f90012d 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 b7c63bfc1794..917f7dc43729 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