if( in_array( 'content', $options, true ) ) {
$forContent = true;
$langCode = true;
+ $langCodeObj = null;
} elseif( array_key_exists( 'language', $options ) ) {
$forContent = false;
$langCode = wfGetLangObj( $options['language'] );
+ $langCodeObj = $langCode;
} else {
$forContent = false;
$langCode = false;
+ $langCodeObj = null;
}
$string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false );
}
if( in_array( 'parse', $options, true ) ) {
- $string = $wgOut->parse( $string, true, !$forContent );
+ $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
} elseif ( in_array( 'parseinline', $options, true ) ) {
- $string = $wgOut->parse( $string, true, !$forContent );
+ $string = $wgOut->parse( $string, true, !$forContent, $langCodeObj );
$m = array();
if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
$string = $m[1];
global $wgMessageCache;
if ( isset( $wgMessageCache ) ) {
$string = $wgMessageCache->transform( $string,
- !$forContent,
- is_object( $langCode ) ? $langCode : null );
+ !$forContent, $langCodeObj );
}
}
* @return Wikitext parsed into HTML
*/
protected function parseText( $string ) {
- global $wgOut, $wgLang, $wgContLang;
- if ( $this->language !== $wgLang && $this->language !== $wgContLang ) {
- # FIXME: remove this limitation
- throw new MWException( 'Can only parse in interface or content language' );
- }
- return $wgOut->parse( $string, /*linestart*/true, $this->interface );
+ global $wgOut;
+ return $wgOut->parse( $string, /*linestart*/true, $this->interface, $this->language );
}
/**
* @param $interface Boolean: use interface language ($wgLang instead of
* $wgContLang) while parsing language sensitive magic
* words like GRAMMAR and PLURAL
+ * @param $language Language object: target language object, will override
+ * $interface
* @return String: HTML
*/
- public function parse( $text, $linestart = true, $interface = false ) {
+ public function parse( $text, $linestart = true, $interface = false, $language = null ) {
global $wgParser;
+
if( is_null( $this->getTitle() ) ) {
throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
}
+
$popts = $this->parserOptions();
if ( $interface ) {
$popts->setInterfaceMessage( true );
}
+ if ( $language !== null ) {
+ $oldLang = $popts->setTargetLanguage( $language );
+ }
+
$parserOutput = $wgParser->parse(
$text, $this->getTitle(), $popts,
$linestart, true, $this->mRevisionId
);
+
if ( $interface ) {
$popts->setInterfaceMessage( false );
}
+ if ( $language !== null ) {
+ $popts->setTargetLanguage( $oldLang );
+ }
+
return $parserOutput->getText();
}