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"
* 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 ===
*/
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
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,
* @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 );
}
/**
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;
$popts->setInterfaceMessage( $interface );
$popts->setTargetLanguage( $language );
$popts->setUserLang( $language );
- $message = $this->mParser->transformMsg( $message, $popts );
+ $message = $this->mParser->transformMsg( $message, $popts, $title );
}
return $message;
}
$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
} else {
// Check if the parser is enabled:
if ( $params['enableparser'] ) {
- $msgString = $msg->text();
+ $msgString = $msg->title( $title )->text();
} else {
$msgString = $msg->plain();
}
'lang' => null,
'from' => null,
'to' => null,
+ 'title' => null,
);
}
'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',
*
* @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
$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