Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -756,12 +756,15 @@ |
757 | 757 | if( in_array( 'content', $options, true ) ) { |
758 | 758 | $forContent = true; |
759 | 759 | $langCode = true; |
| 760 | + $langCodeObj = null; |
760 | 761 | } elseif( array_key_exists( 'language', $options ) ) { |
761 | 762 | $forContent = false; |
762 | 763 | $langCode = wfGetLangObj( $options['language'] ); |
| 764 | + $langCodeObj = $langCode; |
763 | 765 | } else { |
764 | 766 | $forContent = false; |
765 | 767 | $langCode = false; |
| 768 | + $langCodeObj = null; |
766 | 769 | } |
767 | 770 | |
768 | 771 | $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false ); |
— | — | @@ -771,9 +774,9 @@ |
772 | 775 | } |
773 | 776 | |
774 | 777 | if( in_array( 'parse', $options, true ) ) { |
775 | | - $string = $wgOut->parse( $string, true, !$forContent ); |
| 778 | + $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
776 | 779 | } elseif ( in_array( 'parseinline', $options, true ) ) { |
777 | | - $string = $wgOut->parse( $string, true, !$forContent ); |
| 780 | + $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj ); |
778 | 781 | $m = array(); |
779 | 782 | if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) { |
780 | 783 | $string = $m[1]; |
— | — | @@ -782,8 +785,7 @@ |
783 | 786 | global $wgMessageCache; |
784 | 787 | if ( isset( $wgMessageCache ) ) { |
785 | 788 | $string = $wgMessageCache->transform( $string, |
786 | | - !$forContent, |
787 | | - is_object( $langCode ) ? $langCode : null ); |
| 789 | + !$forContent, $langCodeObj ); |
788 | 790 | } |
789 | 791 | } |
790 | 792 | |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -1227,24 +1227,37 @@ |
1228 | 1228 | * @param $interface Boolean: use interface language ($wgLang instead of |
1229 | 1229 | * $wgContLang) while parsing language sensitive magic |
1230 | 1230 | * words like GRAMMAR and PLURAL |
| 1231 | + * @param $language Language object: target language object, will override |
| 1232 | + * $interface |
1231 | 1233 | * @return String: HTML |
1232 | 1234 | */ |
1233 | | - public function parse( $text, $linestart = true, $interface = false ) { |
| 1235 | + public function parse( $text, $linestart = true, $interface = false, $language = null ) { |
1234 | 1236 | global $wgParser; |
| 1237 | + |
1235 | 1238 | if( is_null( $this->getTitle() ) ) { |
1236 | 1239 | throw new MWException( 'Empty $mTitle in ' . __METHOD__ ); |
1237 | 1240 | } |
| 1241 | + |
1238 | 1242 | $popts = $this->parserOptions(); |
1239 | 1243 | if ( $interface ) { |
1240 | 1244 | $popts->setInterfaceMessage( true ); |
1241 | 1245 | } |
| 1246 | + if ( $language !== null ) { |
| 1247 | + $oldLang = $popts->setTargetLanguage( $language ); |
| 1248 | + } |
| 1249 | + |
1242 | 1250 | $parserOutput = $wgParser->parse( |
1243 | 1251 | $text, $this->getTitle(), $popts, |
1244 | 1252 | $linestart, true, $this->mRevisionId |
1245 | 1253 | ); |
| 1254 | + |
1246 | 1255 | if ( $interface ) { |
1247 | 1256 | $popts->setInterfaceMessage( false ); |
1248 | 1257 | } |
| 1258 | + if ( $language !== null ) { |
| 1259 | + $popts->setTargetLanguage( $oldLang ); |
| 1260 | + } |
| 1261 | + |
1249 | 1262 | return $parserOutput->getText(); |
1250 | 1263 | } |
1251 | 1264 | |
Index: trunk/phase3/includes/Message.php |
— | — | @@ -315,12 +315,8 @@ |
316 | 316 | * @return Wikitext parsed into HTML |
317 | 317 | */ |
318 | 318 | protected function parseText( $string ) { |
319 | | - global $wgOut, $wgLang, $wgContLang; |
320 | | - if ( $this->language !== $wgLang && $this->language !== $wgContLang ) { |
321 | | - # FIXME: remove this limitation |
322 | | - throw new MWException( 'Can only parse in interface or content language' ); |
323 | | - } |
324 | | - return $wgOut->parse( $string, /*linestart*/true, $this->interface ); |
| 319 | + global $wgOut; |
| 320 | + return $wgOut->parse( $string, /*linestart*/true, $this->interface, $this->language ); |
325 | 321 | } |
326 | 322 | |
327 | 323 | /** |