From: Matěj Suchánek Date: Thu, 4 Jul 2019 08:02:28 +0000 (+0200) Subject: Don't process "all" option in Html::namespaceSelectorOptions X-Git-Tag: 1.34.0-rc.0~1147^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=5fa9a2a191bf72c18deaf0eb5b8ca29672c9c3c4;p=lhc%2Fweb%2Fwiklou.git Don't process "all" option in Html::namespaceSelectorOptions The value of "all" can be completely arbitrary and in practice it's usually an empty string. Avoid attempting to filter it out and format anyhow. Bug: T227202 Change-Id: I371466407bd038914faa4dc3b0cae9547cf427eb --- diff --git a/includes/Html.php b/includes/Html.php index fdc348b852..07de58c6da 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -831,27 +831,25 @@ class Html { * @return array */ public static function namespaceSelectorOptions( array $params = [] ) { - $options = []; - if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) { $params['exclude'] = []; } - if ( isset( $params['all'] ) ) { - // add an option that would let the user select all namespaces. - // Value is provided by user, the name shown is localized for the user. - $options[$params['all']] = wfMessage( 'namespacesall' )->text(); - } if ( $params['in-user-lang'] ?? false ) { global $wgLang; $lang = $wgLang; } else { $lang = MediaWikiServices::getInstance()->getContentLanguage(); } - // Add all namespaces as options - $options += $lang->getFormattedNamespaces(); $optionsOut = []; + if ( isset( $params['all'] ) ) { + // add an option that would let the user select all namespaces. + // Value is provided by user, the name shown is localized for the user. + $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text(); + } + // Add all namespaces as options + $options = $lang->getFormattedNamespaces(); // Filter out namespaces below 0 and massage labels foreach ( $options as $nsId => $nsName ) { if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) { diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 388b914ddd..5d83b7eb5b 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -481,6 +481,26 @@ class HtmlTest extends MediaWikiTestCase { ), 'Namespace selector namespace filtering.' ); + $this->assertEquals( + '', + Html::namespaceSelector( + [ 'exclude' => [ 0, 1, 3, 100, 101 ], 'all' => '' ] + ), + 'Namespace selector namespace filtering with empty custom "all" option.' + ); } /**