From 92363755ce13d06cb5216bbcf2575fb34025f699 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Fri, 7 Mar 2008 14:02:12 +0000 Subject: [PATCH] * Parse MediaWiki message translations with a correct language setting on preview --- RELEASE-NOTES | 1 + includes/EditPage.php | 23 +++++++++++++++++++++-- includes/Parser.php | 8 +++++++- includes/ParserOptions.php | 4 ++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 07610f5be7..88273715ac 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -74,6 +74,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13274) Change links for messages to ucfirst * (bug 13273) "Categories:" message at the bottom of the page shouldn't have hardcoded colon, use new 'colon-separator' message instead +* Parse MediaWiki message translations with a correct language setting on preview === API changes in 1.13 === diff --git a/includes/EditPage.php b/includes/EditPage.php index 33bac6a460..25f1e024b6 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1494,7 +1494,7 @@ END * @todo document */ function getPreviewText() { - global $wgOut, $wgUser, $wgTitle, $wgParser; + global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang; $fname = 'EditPage::getPreviewText'; wfProfileIn( $fname ); @@ -1542,7 +1542,26 @@ END $toparse="== {$this->summary} ==\n\n".$toparse; } - if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ; + if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData; + + // Parse mediawiki messages with correct target language + if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + $pos = strrpos( $this->mTitle->getText(), '/' ); + if ( $pos !== false ) { + $code = substr( $this->mTitle->getText(), $pos+1 ); + switch ($code) { + case $wgLang->getCode(): + $obj = $wgLang; break; + case $wgContLang->getCode(): + $obj = $wgContLang; break; + default: + $obj = Language::factory( $code ); + } + $parserOptions->setTargetLanguage( $obj ); + } + } + + $parserOptions->setTidy(true); $parserOptions->enableLimitReport(); $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n", diff --git a/includes/Parser.php b/includes/Parser.php index fde3351978..acefb8dcaa 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -459,7 +459,13 @@ class Parser function getFunctionLang() { global $wgLang, $wgContLang; - return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang; + + $target = $this->mOptions->getTargetLanguage(); + if ( $target !== null ) { + return $target; + } else { + return $this->mOptions->getInterfaceMessage() ? $wgLang : $wgContLang; + } } /** diff --git a/includes/ParserOptions.php b/includes/ParserOptions.php index 996bba2171..7be42abf38 100644 --- a/includes/ParserOptions.php +++ b/includes/ParserOptions.php @@ -20,6 +20,7 @@ class ParserOptions var $mAllowSpecialInclusion; # Allow inclusion of special pages var $mTidy; # Ask for tidy cleanup var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR + var $mTargetLanguage; # Overrides above setting with arbitrary language var $mMaxIncludeSize; # Maximum size of template expansions, in bytes var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand() var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates @@ -40,6 +41,7 @@ class ParserOptions function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } function getTidy() { return $this->mTidy; } function getInterfaceMessage() { return $this->mInterfaceMessage; } + function getTargetLanguage() { return $this->mTargetLanguage; } function getMaxIncludeSize() { return $this->mMaxIncludeSize; } function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } function getMaxTemplateDepth() { return $this->mMaxTemplateDepth; } @@ -80,6 +82,7 @@ class ParserOptions function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); } function setSkin( $x ) { $this->mSkin = $x; } function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); } + function setTargetLanguage( $x ) { return wfSetVar( $this->mTargetLanguage, $x); } function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); } function setMaxPPNodeCount( $x ) { return wfSetVar( $this->mMaxPPNodeCount, $x ); } function setMaxTemplateDepth( $x ) { return wfSetVar( $this->mMaxTemplateDepth, $x ); } @@ -132,6 +135,7 @@ class ParserOptions $this->mAllowSpecialInclusion = $wgAllowSpecialInclusion; $this->mTidy = false; $this->mInterfaceMessage = false; + $this->mTargetLanguage = null; // default depends on InterfaceMessage setting $this->mMaxIncludeSize = $wgMaxArticleSize * 1024; $this->mMaxPPNodeCount = $wgMaxPPNodeCount; $this->mMaxTemplateDepth = $wgMaxTemplateDepth; -- 2.20.1