2015-07-14 20:30:06 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2015-07-14 20:30:06 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2024-01-02 18:31:56 +00:00
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
|
use OOUI\DropdownInputWidget;
|
|
|
|
|
use OOUI\InputWidget;
|
|
|
|
|
|
2015-07-14 20:30:06 +00:00
|
|
|
/**
|
2015-08-11 15:12:36 +00:00
|
|
|
* Namespace input widget. Displays a dropdown box with the choice of available namespaces.
|
2017-12-28 15:17:33 +00:00
|
|
|
*
|
|
|
|
|
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
* @license MIT
|
2015-07-14 20:30:06 +00:00
|
|
|
*/
|
2024-01-02 18:31:56 +00:00
|
|
|
class NamespaceInputWidget extends DropdownInputWidget {
|
2019-09-10 12:05:14 +00:00
|
|
|
/** @var string */
|
|
|
|
|
protected $includeAllValue;
|
2022-05-03 23:04:07 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
protected $userLang;
|
2019-09-10 12:05:14 +00:00
|
|
|
/** @var int[] */
|
|
|
|
|
protected $exclude;
|
2015-07-14 20:30:06 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
|
2015-07-14 20:30:06 +00:00
|
|
|
* namespace dropdown, and use this as the input value for it
|
2022-05-03 23:04:07 +00:00
|
|
|
* - bool $config['userLang'] Display namespaces in user language
|
2018-01-07 10:38:43 +00:00
|
|
|
* - 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::__construct( $config );
|
|
|
|
|
|
|
|
|
|
// Properties
|
2017-10-06 22:17:58 +00:00
|
|
|
$this->includeAllValue = $config['includeAllValue'] ?? null;
|
2022-05-03 23:04:07 +00:00
|
|
|
$this->userLang = $config['userLang'] ?? false;
|
2017-10-06 22:17:58 +00:00
|
|
|
$this->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 = [
|
2017-10-06 22:17:58 +00:00
|
|
|
'all' => $config['includeAllValue'] ?? null,
|
2022-05-03 23:04:07 +00:00
|
|
|
'in-user-lang' => $config['userLang'] ?? false,
|
2017-10-06 22:17:58 +00:00
|
|
|
'exclude' => $config['exclude'] ?? null
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2024-01-02 18:31:56 +00:00
|
|
|
$namespaceOptions = Html::namespaceSelectorOptions( $namespaceOptionsParams );
|
2015-07-14 20:30:06 +00:00
|
|
|
|
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;
|
2022-05-03 23:04:07 +00:00
|
|
|
$config['userLang'] = $this->userLang;
|
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
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['dropdown']['$overlay'] = true;
|
2024-01-02 18:31:56 +00:00
|
|
|
return InputWidget::getConfig( $config );
|
2015-07-14 20:30:06 +00:00
|
|
|
}
|
|
|
|
|
}
|