From ca6fcb7e3fbf420d2a793de403ab113d2a9c046f Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Sat, 18 Jun 2011 14:49:01 +0000 Subject: [PATCH] Address comment by Platonides on r90320: * undefined variable $list in CategoryPage.php * move code in ParserOptions to a new member of Title class, which falls back to $wgContLang --- includes/CategoryPage.php | 11 +++++------ includes/EditPage.php | 18 +++++++++++------- includes/SkinTemplate.php | 3 +-- includes/Title.php | 21 +++++++++++++++++++++ includes/diff/DifferenceEngine.php | 6 ++---- includes/parser/ParserOptions.php | 12 +----------- 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 4b8ba0301f..989e9e9b12 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -506,19 +506,18 @@ class CategoryViewer { * @private */ function formatList( $articles, $articles_start_char, $cutoff = 6 ) { + $list = ''; if ( count ( $articles ) > $cutoff ) { $list = self::columnList( $articles, $articles_start_char ); } elseif ( count( $articles ) > 0 ) { // for short lists of articles in categories. $list = self::shortList( $articles, $articles_start_char ); } - global $wgBetterDirectionality; + global $wgBetterDirectionality, $wgTitle; if( $wgBetterDirectionality ) { - global $wgOut, $wgContLang; - $getPageLang = $wgOut->parserOptions()->getTargetLanguage(); - $pageLang = ( $getPageLang ? Language::factory( $getPageLang ) : $wgContLang ); - $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); - $list = Html::rawElement( 'div', $realBodyAttribs, $list ); + $pageLang = $wgTitle->getPageLanguage(); + $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); + $list = Html::rawElement( 'div', $attribs, $list ); } return $list; diff --git a/includes/EditPage.php b/includes/EditPage.php index ce696951da..7dc1c0a7a8 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1817,8 +1817,7 @@ HTML global $wgBetterDirectionality, $wgContLang; if( $wgBetterDirectionality ) { - $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle ); - $pageLang = ( $getPageLang ? $getPageLang : $wgContLang ); + $pageLang = $this->mTitle->getPageLanguage(); $attribs['lang'] = $pageLang->getCode(); $attribs['dir'] = $pageLang->getDir(); } @@ -2066,6 +2065,12 @@ HTML wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); + // In which language to parse the page + // (Should this still be only for MediaWiki pages, or for all pages?) + if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + $parserOptions->setTargetLanguage( $this->mTitle->getPageLanguage() ); + } + $parserOptions->setTargetLanguage( $this->mTitle->getPageLanguage() ); $parserOptions->setTidy( true ); $parserOptions->enableLimitReport(); $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ), @@ -2091,12 +2096,11 @@ HTML '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

" . $wgOut->parse( $note ) . $conflict . "\n"; - global $wgBetterDirectionality, $wgContLang; + global $wgBetterDirectionality; if( $wgBetterDirectionality ) { - $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle ); - $pageLang = ( $getPageLang ? $getPageLang : $wgContLang ); - $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); - $previewHTML = Html::rawElement( 'div', $realBodyAttribs, $previewHTML ); + $pageLang = $this->mTitle->getPageLanguage(); + $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); + $previewHTML = Html::rawElement( 'div', $attribs, $previewHTML ); } wfProfileOut( __METHOD__ ); return $previewhead . $previewHTML . $this->previewTextAfterContent; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index fad14f502f..2287bc6715 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -461,8 +461,7 @@ class SkinTemplate extends Skin { if( $this->getTitle()->getNamespace() != NS_SPECIAL && in_array( $action, array( 'view', 'render', 'print' ) ) && ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) { - $getPageLang = $out->parserOptions()->getTargetLanguage( $this->getTitle() ); - $pageLang = ( $getPageLang ? $getPageLang : $wgContLang ); + $pageLang = $this->getTitle()->getPageLanguage(); $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext ); } diff --git a/includes/Title.php b/includes/Title.php index d06b322d3e..1ec84540f2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -67,6 +67,7 @@ class Title { var $mRedirect = null; // /< Is the article at this title a redirect? var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false var $mBacklinkCache = null; // /< Cache of links to this title + var $mPageLanguage; // @} @@ -4221,6 +4222,26 @@ class Title { } return $unprefixed; } + + /** + * Get the language this page is written in + * Defaults to $wgContLang + * + * @return object Language + */ + public function getPageLanguage() { + global $wgContLang; + $this->mPageLanguage = $wgContLang; + if ( $this->isCssOrJsPage() ) { + // css/js should always be LTR and is, in fact, English + $this->mPageLanguage = Language::factory( 'en' ); + } elseif ( $this->getNamespace() == NS_MEDIAWIKI ) { + // Parse mediawiki messages with correct target language + list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->getText() ); + $this->mPageLanguage = wfGetLangObj( $lang ); + } + return $this->mPageLanguage; + } } /** diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 0306e790b1..69d8994f3d 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -936,14 +936,12 @@ CONTROL; * @return string */ static function addHeader( $diff, $otitle, $ntitle, $multi = '', $notice = '' ) { - global $wgBetterDirectionality; + global $wgBetterDirectionality, $wgTitle; $dirclass = ''; if( $wgBetterDirectionality ) { - global $wgContLang, $wgOut, $wgTitle; // shared.css sets diff in interface language/dir, // but the actual content should be in the page language/dir - $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $wgTitle ); - $pageLang = ( $getPageLang ? $getPageLang : $wgContLang ); + $pageLang = $wgTitle->getPageLanguage(); $dirclass = ' diff-contentalign-'.$pageLang->alignStart(); } $header = ""; diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 49473cabec..3b9b2d7808 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -66,17 +66,7 @@ class ParserOptions { function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } function getTidy() { return $this->mTidy; } function getInterfaceMessage() { return $this->mInterfaceMessage; } - function getTargetLanguage( $title = null ) { - if ( $title && $title->isCssOrJsPage() ) { - return Language::factory( 'en' ); // css/js should always be LTR - } elseif ( $title && $title->getNamespace() == NS_MEDIAWIKI ) { - // Parse mediawiki messages with correct target language - list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() ); - $obj = wfGetLangObj( $lang ); - return $obj; - } - return $this->mTargetLanguage; -} + function getTargetLanguage() { return $this->mTargetLanguage; } function getMaxIncludeSize() { return $this->mMaxIncludeSize; } function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; } -- 2.20.1