wiki.techinc.nl/includes/widget/NamespaceInputWidget.php
Bartosz Dziewoński b6046dff66 Refactor NamespaceInputWidget
* Refactor NamespaceInputWidget into two widgets: NamespaceInputWidget
  and ComplexNamespaceInputWidget. The former is now only the dropdown
  (and inherits from DropdownInputWidget), the latter is the dropdown
  plus two checkboxes.
* Change ComplexNamespaceInputWidget configuration to take nested config
  for `invert`, `associated`, and `namespace`, rather than require
  parameters like `invertName` and so on for every combination.
* Implement standalone JavaScript versions of both widgets (previously
  mw.widgets.NamespaceInputWidget could only be created via infusion
  of the PHP widget).

Bug: T99256
Bug: T106138
Bug: T109559
Change-Id: Ie2fee6d035339ceb934fca991675480db3d630d1
2015-08-20 15:10:51 +00:00

61 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
/**
* Namespace input widget. Displays a dropdown box with the choice of available namespaces.
*/
class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
protected $includeAllValue = null;
/**
* @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
*/
public function __construct( array $config = array() ) {
// Configuration initialization
$config['options'] = $this->getNamespaceDropdownOptions( $config );
// Parent constructor
parent::__construct( $config );
// Properties
$this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
// Initialization
$this->addClasses( array( 'mw-widget-namespaceInputWidget' ) );
}
protected function getNamespaceDropdownOptions( array $config ) {
$namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
array( 'all' => $config['includeAllValue'] ) : array();
$namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
$options = array();
foreach ( $namespaceOptions as $id => $name ) {
$options[] = array(
'data' => (string)$id,
'label' => $name,
);
}
return $options;
}
protected function getJavaScriptClassName() {
return 'mw.widgets.NamespaceInputWidget';
}
public function getConfig( &$config ) {
$config['includeAllValue'] = $this->includeAllValue;
// Skip DropdownInputWidget's getConfig(), we don't need 'options' config
return \OOUI\InputWidget::getConfig( $config );
}
}