* @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'] ) ) {
),
'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.'
+ );
}
/**