AllMessagesTablePager: Simplify language handling
authorFomafix <fomafix@googlemail.com>
Tue, 15 Jan 2019 19:30:48 +0000 (20:30 +0100)
committerFomafix <fomafix@googlemail.com>
Tue, 15 Jan 2019 19:46:23 +0000 (20:46 +0100)
wfGetLangObj always returns a Language object and never returns null.
The ?? operator never reached the fallback $contLang.

Message::inLanguage supports language code strings and Language objects.
Language code strings get converted to a Language object. So directly
pass the available Language object.

Change-Id: I5e13d6350df8b9b0261c853939d3485c4ed835cd

includes/specials/pagers/AllMessagesTablePager.php

index 26c2c50..8081f4d 100644 (file)
@@ -66,9 +66,8 @@ class AllMessagesTablePager extends TablePager {
                // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
                $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
 
-               $langObj = wfGetLangObj( $opts->getValue( 'lang' ) );
                $contLang = MediaWikiServices::getInstance()->getContentLanguage();
-               $this->lang = $langObj ?? $contLang;
+               $this->lang = wfGetLangObj( $opts->getValue( 'lang' ) );
 
                $this->langcode = $this->lang->getCode();
                $this->foreign = !$this->lang->equals( $contLang );
@@ -188,8 +187,8 @@ class AllMessagesTablePager extends TablePager {
                                ( $descending && ( $key < $offset || !$offset ) || !$descending && $key > $offset ) &&
                                ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
                        ) {
-                               $actual = wfMessage( $key )->inLanguage( $this->langcode )->plain();
-                               $default = wfMessage( $key )->inLanguage( $this->langcode )->useDatabase( false )->plain();
+                               $actual = wfMessage( $key )->inLanguage( $this->lang )->plain();
+                               $default = wfMessage( $key )->inLanguage( $this->lang )->useDatabase( false )->plain();
                                $result->result[] = [
                                        'am_title' => $key,
                                        'am_actual' => $actual,