From: Erik Bernhardson Date: Mon, 10 Sep 2018 20:14:20 +0000 (-0700) Subject: Render namespace lists in the user's language X-Git-Tag: 1.34.0-rc.0~3543^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=9f28aa0709d07f620b17ffede6667e18bb9bfe72;p=lhc%2Fweb%2Fwiklou.git Render namespace lists in the user's language Asking users to select from a list that is in a namespace other than their user language can be quite difficult. Transition a number of use cases. This was applied via a flag to avoid unexpectedly changing extensions also utilizing the namespace selector. Pages updated: * Special:Search * Special:Watchlist * Special:RecentChanges * Special:Contributions * Special:Import * Special:WhatLinksHere Bug: T174057 Change-Id: I3fdac72179a124849ef7ad1e0e54eb66396c3c6e --- diff --git a/includes/Html.php b/includes/Html.php index aac492c921..d066effd92 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -840,9 +840,14 @@ class Html { // Value is provided by user, the name shown is localized for the user. $options[$params['all']] = wfMessage( 'namespacesall' )->text(); } - // Add all namespaces as options (in the content language) - $options += - MediaWikiServices::getInstance()->getContentLanguage()->getFormattedNamespaces(); + if ( $params['in-user-lang'] ?? false ) { + global $wgLang; + $lang = $wgLang; + } else { + $lang = MediaWikiServices::getInstance()->getContentLanguage(); + } + // Add all namespaces as options + $options += $lang->getFormattedNamespaces(); $optionsOut = []; // Filter out namespaces below 0 and massage labels @@ -855,8 +860,7 @@ class Html { // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)") $nsName = wfMessage( 'blanknamespace' )->text(); } elseif ( is_int( $nsId ) ) { - $nsName = MediaWikiServices::getInstance()->getContentLanguage()-> - convertNamespace( $nsId ); + $nsName = $lang->convertNamespace( $nsId ); } $optionsOut[$nsId] = $nsName; } diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 63b64eab5b..72ab94cd8b 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -607,7 +607,7 @@ class SpecialContributions extends IncludableSpecialPage { '' ) . "\u{00A0}" . Html::namespaceSelector( - [ 'selected' => $this->opts['namespace'], 'all' => '' ], + [ 'selected' => $this->opts['namespace'], 'all' => '', 'in-user-lang' => true ], [ 'name' => 'namespace', 'id' => 'namespace', diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index 153b7d1e2b..3b3c801226 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -279,6 +279,7 @@ class SpecialImport extends SpecialPage { 'selected' => ( $isSameSourceAsBefore ? $this->namespace : ( $defaultNamespace || '' ) ), + 'in-user-lang' => true, ], [ 'name' => "namespace", // mw-import-namespace-interwiki, mw-import-namespace-upload diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 170f792ead..a857bb3c32 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -678,7 +678,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { */ protected function namespaceFilterForm( FormOptions $opts ) { $nsSelect = Html::namespaceSelector( - [ 'selected' => $opts['namespace'], 'all' => '' ], + [ 'selected' => $opts['namespace'], 'all' => '', 'in-user-lang' => true ], [ 'name' => 'namespace', 'id' => 'namespace' ] ); $nsLabel = Xml::label( $this->msg( 'namespace' )->text(), 'namespace' ); diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index feb449c847..0ca6f932a0 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -652,7 +652,8 @@ class SpecialWatchlist extends ChangesListSpecialPage { [ 'selected' => $opts['namespace'], 'all' => '', - 'label' => $this->msg( 'namespace' )->text() + 'label' => $this->msg( 'namespace' )->text(), + 'in-user-lang' => true, ], [ 'name' => 'namespace', 'id' => 'namespace', diff --git a/includes/specials/SpecialWhatlinkshere.php b/includes/specials/SpecialWhatlinkshere.php index 1d3ffd795a..8eee37cab8 100644 --- a/includes/specials/SpecialWhatlinkshere.php +++ b/includes/specials/SpecialWhatlinkshere.php @@ -515,7 +515,8 @@ class SpecialWhatLinksHere extends IncludableSpecialPage { [ 'selected' => $namespace, 'all' => '', - 'label' => $this->msg( 'namespace' )->text() + 'label' => $this->msg( 'namespace' )->text(), + 'in-user-lang' => true, ], [ 'name' => 'namespace', 'id' => 'namespace', diff --git a/includes/widget/search/SearchFormWidget.php b/includes/widget/search/SearchFormWidget.php index 7eb92fdfd6..0c809514fc 100644 --- a/includes/widget/search/SearchFormWidget.php +++ b/includes/widget/search/SearchFormWidget.php @@ -238,7 +238,7 @@ class SearchFormWidget { protected function powerSearchBox( $term, array $opts ) { $rows = []; $activeNamespaces = $this->specialSearch->getNamespaces(); - $langConverter = MediaWikiServices::getInstance()->getContentLanguage()->getConverter(); + $langConverter = $this->specialSearch->getLanguage(); foreach ( $this->searchConfig->searchableNamespaces() as $namespace => $name ) { $subject = MWNamespace::getSubject( $namespace ); if ( !isset( $rows[$subject] ) ) { diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 71e733b1c4..5663a60758 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -418,6 +418,33 @@ class HtmlTest extends MediaWikiTestCase { ), 'Basic namespace selector with a custom label but no id attribtue for the ' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '', + Html::namespaceSelector( + [ 'in-user-lang' => true ] + ), + 'Basic namespace selector in user language' + ); } /**