Language: Introduce new method equals( Language $lang )

Use

 $lang->equals( $wgContLang )

instead of

 $lang->getCode() === $wgContLang->getCode()

Change-Id: Id7ed6a21ce5e2ea2887ec98c7bd9d3eba83d733b
This commit is contained in:
Fomafix 2016-05-16 22:33:33 +00:00 committed by [[mw:User:Fomafix]]
parent 322641e961
commit 796d62d034
7 changed files with 20 additions and 11 deletions

View file

@ -447,12 +447,12 @@ class Message implements MessageSpecifier, Serializable {
public function getTitle() {
global $wgContLang, $wgForceUIMsgAsContentMsg;
$code = $this->getLanguage()->getCode();
$title = $this->key;
if (
$wgContLang->getCode() !== $code
!$this->language->equals( $wgContLang )
&& in_array( $this->key, (array)$wgForceUIMsgAsContentMsg )
) {
$code = $this->language->getCode();
$title .= '/' . $code;
}

View file

@ -1714,7 +1714,7 @@ class Title implements LinkTarget {
if ( $url === false
&& $wgVariantArticlePath
&& preg_match( '/^variant=([^&]*)$/', $query, $matches )
&& $wgContLang->getCode() === $this->getPageLanguage()->getCode()
&& $this->getPageLanguage()->equals( $wgContLang )
&& $this->getPageLanguage()->hasVariants()
) {
$variant = urldecode( $matches[1] );

View file

@ -113,15 +113,14 @@ class ApiQueryAllMessages extends ApiQueryBase {
$customiseFilterEnabled = $params['customised'] !== 'all';
if ( $customiseFilterEnabled ) {
global $wgContLang;
$lang = $langObj->getCode();
$customisedMessages = AllMessagesTablePager::getCustomisedStatuses(
array_map(
[ $langObj, 'ucfirst' ],
$messages_target
),
$lang,
$lang != $wgContLang->getCode()
$langObj->getCode(),
!$langObj->equals( $wgContLang )
);
$customised = $params['customised'] === 'modified';

View file

@ -124,11 +124,10 @@ class HTMLFileCache extends FileCacheBase {
$user = $context->getUser();
// Check for non-standard user language; this covers uselang,
// and extensions for auto-detecting user language.
$ulang = $context->getLanguage()->getCode();
$clang = $wgContLang->getCode();
$ulang = $context->getLanguage();
// Check that there are no other sources of variation
if ( $user->getId() || $user->getNewtalk() || $ulang != $clang ) {
if ( $user->getId() || $user->getNewtalk() || $ulang->equals( $wgContLang ) ) {
return false;
}
// Allow extensions to disable caching

View file

@ -701,7 +701,7 @@ class ParserOptions {
}
// Check the object and lazy-loaded options
return (
$this->mUserLang->getCode() === $other->mUserLang->getCode() &&
$this->mUserLang->equals( $other->mUserLang ) &&
$this->getDateFormat() === $other->getDateFormat()
);
}

View file

@ -56,7 +56,7 @@ class AllMessagesTablePager extends TablePager {
$this->lang = ( $langObj ? $langObj : $wgContLang );
$this->langcode = $this->lang->getCode();
$this->foreign = $this->langcode !== $wgContLang->getCode();
$this->foreign = !$this->lang->equals( $wgContLang );
$request = $this->getRequest();

View file

@ -4190,6 +4190,17 @@ class Language {
return $lang;
}
/**
* Compare with an other language object
*
* @since 1.28
* @param Language $lang
* @return boolean
*/
public function equals( Language $lang ) {
return $lang->getCode() === $this->mCode;
}
/**
* Get the internal language code for this language object
*