var $mRedirect = null; // /< Is the article at this title a redirect?
var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false
var $mHasSubpage; // /< Whether a page has any subpages
+ private $mPageLanguage = false; // /< The (string) language code of the page's language and content code.
// @}
/**
$this->mLatestID = false;
$this->mContentModel = false;
$this->mEstimateRevisions = null;
+ $this->mPageLanguage = false;
}
/**
* @return Language
*/
public function getPageLanguage() {
- global $wgLang;
+ global $wgLang, $wgLanguageCode;
+ wfProfileIn( __METHOD__ );
if ( $this->isSpecialPage() ) {
// special pages are in the user language
+ wfProfileOut( __METHOD__ );
return $wgLang;
}
- //TODO: use the LinkCache to cache this! Note that this may depend on user settings, so the cache should be only per-request.
- //NOTE: ContentHandler::getPageLanguage() may need to load the content to determine the page language!
- $contentHandler = ContentHandler::getForTitle( $this );
- $pageLang = $contentHandler->getPageLanguage( $this );
-
- return wfGetLangObj( $pageLang );
+ if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
+ // Note that this may depend on user settings, so the cache should be only per-request.
+ // NOTE: ContentHandler::getPageLanguage() may need to load the content to determine the page language!
+ // Checking $wgLanguageCode hasn't changed for the benefit of unit tests.
+ $contentHandler = ContentHandler::getForTitle( $this );
+ $langObj = wfGetLangObj( $contentHandler->getPageLanguage( $this ) );
+ $this->mPageLanguage = array( $langObj->getCode(), $wgLanguageCode );
+ } else {
+ $langObj = wfGetLangObj( $this->mPageLanguage[0] );
+ }
+ wfProfileOut( __METHOD__ );
+ return $langObj;
}
/**