2015-07-14 20:30:06 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* MediaWiki Widgets – NamespaceInputWidget class.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
|
|
*/
|
|
|
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-11 15:12:36 +00:00
|
|
|
|
* Namespace input widget. Displays a dropdown box with the choice of available namespaces.
|
2015-07-14 20:30:06 +00:00
|
|
|
|
*/
|
2015-08-11 15:12:36 +00:00
|
|
|
|
class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
2015-07-14 20:30:06 +00:00
|
|
|
|
|
2015-08-11 15:12:36 +00:00
|
|
|
|
protected $includeAllValue = null;
|
2015-07-14 20:30:06 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param array $config Configuration options
|
|
|
|
|
|
* @param string $config['includeAllValue'] If specified, add a "all namespaces" option to the
|
|
|
|
|
|
* namespace dropdown, and use this as the input value for it
|
2017-11-04 22:02:59 +00:00
|
|
|
|
* @param int[] $config['exclude'] List of namespace numbers to exclude from the selector
|
2015-07-14 20:30:06 +00:00
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
|
public function __construct( array $config = [] ) {
|
2015-07-14 20:30:06 +00:00
|
|
|
|
// Configuration initialization
|
2015-08-11 15:12:36 +00:00
|
|
|
|
$config['options'] = $this->getNamespaceDropdownOptions( $config );
|
2015-07-14 20:30:06 +00:00
|
|
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
|
|
parent::__construct( $config );
|
|
|
|
|
|
|
|
|
|
|
|
// Properties
|
2015-08-11 15:12:36 +00:00
|
|
|
|
$this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : [];
|
2015-07-14 20:30:06 +00:00
|
|
|
|
|
|
|
|
|
|
// Initialization
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
|
2015-07-14 20:30:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getNamespaceDropdownOptions( array $config ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$namespaceOptionsParams = [
|
2015-01-16 22:42:54 +00:00
|
|
|
|
'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null,
|
|
|
|
|
|
'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2015-07-14 20:30:06 +00:00
|
|
|
|
$namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
|
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$options = [];
|
2015-08-14 21:17:01 +00:00
|
|
|
|
foreach ( $namespaceOptions as $id => $name ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
|
$options[] = [
|
2015-07-14 20:30:06 +00:00
|
|
|
|
'data' => (string)$id,
|
|
|
|
|
|
'label' => $name,
|
2016-02-17 09:09:32 +00:00
|
|
|
|
];
|
2015-07-14 20:30:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function getJavaScriptClassName() {
|
|
|
|
|
|
return 'mw.widgets.NamespaceInputWidget';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getConfig( &$config ) {
|
2015-08-11 15:12:36 +00:00
|
|
|
|
$config['includeAllValue'] = $this->includeAllValue;
|
2015-01-16 22:42:54 +00:00
|
|
|
|
$config['exclude'] = $this->exclude;
|
2015-08-11 15:12:36 +00:00
|
|
|
|
// Skip DropdownInputWidget's getConfig(), we don't need 'options' config
|
|
|
|
|
|
return \OOUI\InputWidget::getConfig( $config );
|
2015-07-14 20:30:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|