Merge "Don't process "all" option in Html::namespaceSelectorOptions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 6 Jul 2019 15:17:54 +0000 (15:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 6 Jul 2019 15:17:54 +0000 (15:17 +0000)
includes/Html.php
tests/phpunit/includes/HtmlTest.php

index fdc348b..07de58c 100644 (file)
@@ -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'] ) ) {
index 388b914..5d83b7e 100644 (file)
@@ -481,6 +481,26 @@ class HtmlTest extends MediaWikiTestCase {
                        ),
                        'Namespace selector namespace filtering.'
                );
+               $this->assertEquals(
+                       '<select id="namespace" name="namespace">' . "\n" .
+                               '<option value="" selected="">todos</option>' . "\n" .
+                               '<option value="2">User</option>' . "\n" .
+                               '<option value="4">MyWiki</option>' . "\n" .
+                               '<option value="5">MyWiki Talk</option>' . "\n" .
+                               '<option value="6">File</option>' . "\n" .
+                               '<option value="7">File talk</option>' . "\n" .
+                               '<option value="8">MediaWiki</option>' . "\n" .
+                               '<option value="9">MediaWiki talk</option>' . "\n" .
+                               '<option value="10">Template</option>' . "\n" .
+                               '<option value="11">Template talk</option>' . "\n" .
+                               '<option value="14">Category</option>' . "\n" .
+                               '<option value="15">Category talk</option>' . "\n" .
+                               '</select>',
+                       Html::namespaceSelector(
+                               [ 'exclude' => [ 0, 1, 3, 100, 101 ], 'all' => '' ]
+                       ),
+                       'Namespace selector namespace filtering with empty custom "all" option.'
+               );
        }
 
        /**