language: Change Message from false to null internally for user lang

This simplifies the assignment with a Language object that fall back to
null.

The serialization of null is 2 byte shorter than the serialization of
false.

false and null are both falsey so the serialization is backward and
forward compatible.

Change-Id: Idbe21afcead4fb3973f63a4f5d7fa156457f8ca9
This commit is contained in:
Fomafix 2019-04-15 11:13:33 +02:00 committed by Krinkle
parent d96d55cc77
commit 5a30cdd782

View file

@ -171,9 +171,9 @@ class Message implements MessageSpecifier, Serializable {
/**
* In which language to get this message. Overrides the $interface setting.
*
* @var Language|false Explicit language object, or false for user language
* @var Language|null Explicit language object, or null for user language
*/
protected $language = false;
protected $language = null;
/**
* @var string The message key. If $keysToTry has more than one element,
@ -248,7 +248,7 @@ class Message implements MessageSpecifier, Serializable {
$this->parameters = array_values( $params );
// User language is only resolved in getLanguage(). This helps preserve the
// semantic intent of "user language" across serialize() and unserialize().
$this->language = $language ?: false;
$this->language = $language;
}
/**
@ -268,7 +268,7 @@ class Message implements MessageSpecifier, Serializable {
public function __serialize() {
return [
'interface' => $this->interface,
'language' => $this->language ? $this->language->getCode() : false,
'language' => $this->language ? $this->language->getCode() : null,
'key' => $this->key,
'keysToTry' => $this->keysToTry,
'parameters' => $this->parameters,
@ -309,7 +309,7 @@ class Message implements MessageSpecifier, Serializable {
$this->language = $data['language']
? MediaWikiServices::getInstance()->getLanguageFactory()
->getLanguage( $data['language'] )
: false;
: null;
// Since 1.35, the key 'titlevalue' is set, instead of 'titlestr'.
if ( isset( $data['titlevalue'] ) ) {
@ -380,8 +380,8 @@ class Message implements MessageSpecifier, Serializable {
* @return Language
*/
public function getLanguage() {
// Defaults to false which means current user language
return $this->language ?: RequestContext::getMain()->getLanguage();
// Defaults to null which means current user language
return $this->language ?? RequestContext::getMain()->getLanguage();
}
/**
@ -840,7 +840,7 @@ class Message implements MessageSpecifier, Serializable {
->getLanguage( $lang );
}
} elseif ( $lang instanceof StubUserLang ) {
$this->language = false;
$this->language = null;
} else {
$type = gettype( $lang );
throw new MWException( __METHOD__ . " must be "