Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -4269,10 +4269,10 @@ |
4270 | 4270 | * |
4271 | 4271 | * @param $text String: the text to preprocess |
4272 | 4272 | * @param $options ParserOptions: options |
| 4273 | + * @param $title Title object or null to use $wgTitle |
4273 | 4274 | * @return String |
4274 | 4275 | */ |
4275 | | - public function transformMsg( $text, $options ) { |
4276 | | - global $wgTitle; |
| 4276 | + public function transformMsg( $text, $options, $title = null ) { |
4277 | 4277 | static $executing = false; |
4278 | 4278 | |
4279 | 4279 | # Guard against infinite recursion |
— | — | @@ -4282,8 +4282,11 @@ |
4283 | 4283 | $executing = true; |
4284 | 4284 | |
4285 | 4285 | wfProfileIn( __METHOD__ ); |
4286 | | - $title = $wgTitle; |
4287 | 4286 | if ( !$title ) { |
| 4287 | + global $wgTitle; |
| 4288 | + $title = $wgTitle; |
| 4289 | + } |
| 4290 | + if ( !$title ) { |
4288 | 4291 | # It's not uncommon having a null $wgTitle in scripts. See r80898 |
4289 | 4292 | # Create a ghost title in such case |
4290 | 4293 | $title = Title::newFromText( 'Dwimmerlaik' ); |
Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -729,7 +729,7 @@ |
730 | 730 | return $message; |
731 | 731 | } |
732 | 732 | |
733 | | - function transform( $message, $interface = false, $language = null ) { |
| 733 | + function transform( $message, $interface = false, $language = null, $title = null ) { |
734 | 734 | // Avoid creating parser if nothing to transform |
735 | 735 | if( strpos( $message, '{{' ) === false ) { |
736 | 736 | return $message; |
— | — | @@ -754,7 +754,7 @@ |
755 | 755 | $popts->setInterfaceMessage( $interface ); |
756 | 756 | $popts->setTargetLanguage( $language ); |
757 | 757 | $popts->setUserLang( $language ); |
758 | | - $message = $this->mParser->transformMsg( $message, $popts ); |
| 758 | + $message = $this->mParser->transformMsg( $message, $popts, $title ); |
759 | 759 | } |
760 | 760 | return $message; |
761 | 761 | } |
Index: trunk/phase3/includes/api/ApiQueryAllmessages.php |
— | — | @@ -50,6 +50,17 @@ |
51 | 51 | $langObj = Language::factory( $params['lang'] ); |
52 | 52 | } |
53 | 53 | |
| 54 | + if ( $params['enableparser'] ) { |
| 55 | + if ( !is_null( $params['title'] ) ) { |
| 56 | + $title = Title::newFromText( $params['title'] ); |
| 57 | + if ( !$title ) { |
| 58 | + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
| 59 | + } |
| 60 | + } else { |
| 61 | + $title = Title::newFromText( 'API' ); |
| 62 | + } |
| 63 | + } |
| 64 | + |
54 | 65 | $prop = array_flip( (array)$params['prop'] ); |
55 | 66 | |
56 | 67 | // Determine which messages should we print |
— | — | @@ -101,7 +112,7 @@ |
102 | 113 | } else { |
103 | 114 | // Check if the parser is enabled: |
104 | 115 | if ( $params['enableparser'] ) { |
105 | | - $msgString = $msg->text(); |
| 116 | + $msgString = $msg->title( $title )->text(); |
106 | 117 | } else { |
107 | 118 | $msgString = $msg->plain(); |
108 | 119 | } |
— | — | @@ -158,6 +169,7 @@ |
159 | 170 | 'lang' => null, |
160 | 171 | 'from' => null, |
161 | 172 | 'to' => null, |
| 173 | + 'title' => null, |
162 | 174 | ); |
163 | 175 | } |
164 | 176 | |
— | — | @@ -167,6 +179,7 @@ |
168 | 180 | 'prop' => 'Which properties to get', |
169 | 181 | 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message', |
170 | 182 | 'Will substitute magic words, handle templates etc.' ), |
| 183 | + 'title' => 'Page name to use as context when parsing message (for enableparser option)', |
171 | 184 | 'args' => 'Arguments to be substituted into message', |
172 | 185 | 'filter' => 'Return only messages that contain this string', |
173 | 186 | 'lang' => 'Return messages in this language', |
Index: trunk/phase3/includes/Message.php |
— | — | @@ -95,6 +95,11 @@ |
96 | 96 | protected $useDatabase = true; |
97 | 97 | |
98 | 98 | /** |
| 99 | + * Title object to use as context |
| 100 | + */ |
| 101 | + protected $title = null; |
| 102 | + |
| 103 | + /** |
99 | 104 | * Constructor. |
100 | 105 | * @param $key: message key, or array of message keys to try and use the first non-empty message for |
101 | 106 | * @param $params Array message parameters |
— | — | @@ -239,6 +244,17 @@ |
240 | 245 | } |
241 | 246 | |
242 | 247 | /** |
| 248 | + * Set the Title object to use as context when transforming the message |
| 249 | + * |
| 250 | + * @param $title Title object |
| 251 | + * @return Message: $this |
| 252 | + */ |
| 253 | + public function title( $title ) { |
| 254 | + $this->title = $title; |
| 255 | + return $this; |
| 256 | + } |
| 257 | + |
| 258 | + /** |
243 | 259 | * Returns the message parsed from wikitext to HTML. |
244 | 260 | * TODO: in PHP >= 5.2.0, we can make this a magic method, |
245 | 261 | * and then we can do, eg: |
— | — | @@ -395,7 +411,7 @@ |
396 | 412 | * @return Wikitext with {{-constructs replaced with their values. |
397 | 413 | */ |
398 | 414 | protected function transformText( $string ) { |
399 | | - return MessageCache::singleton()->transform( $string, $this->interface, $this->language ); |
| 415 | + return MessageCache::singleton()->transform( $string, $this->interface, $this->language, $this->title ); |
400 | 416 | } |
401 | 417 | |
402 | 418 | /** |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -163,6 +163,7 @@ |
164 | 164 | * Expose list of skins in meta=siteinfo |
165 | 165 | * (bug 26548) Add iiurlparam param to query=imageinfo and query=stashimageinfo |
166 | 166 | * (bug 27205) aiprop=metadata and aiprop=parsedcomment need help text |
| 167 | +* Add a amtitle param to meta=allmessages |
167 | 168 | |
168 | 169 | === Languages updated in 1.18 === |
169 | 170 | |