Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / widget / NamespaceInputWidget.php
index f10ea70..3e86738 100644 (file)
 namespace MediaWiki\Widget;
 
 /**
- * Namespace input widget. Displays a dropdown box with the choice of available namespaces, plus two
- * checkboxes to include associated namespace or to invert selection.
+ * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
  */
-class NamespaceInputWidget extends \OOUI\Widget {
+class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
 
-       protected $namespace = null;
-       protected $associated = null;
-       protected $invert = null;
-       protected $allValue = null;
+       protected $includeAllValue = null;
 
        /**
         * @param array $config Configuration options
-        * @param string $config['nameNamespace'] HTML input name for the namespace dropdown box (default:
-        *     'namespace')
-        * @param string $config['nameInvert'] HTML input name for the "invert selection" checkbox. If
-        *     null, the checkbox will not be generated. (default: 'invert')
-        * @param string $config['nameAssociated'] HTML input name for the "include associated namespace"
-        *     checkbox. If null, the checkbox will not be generated. (default: 'associated')
         * @param string $config['includeAllValue'] If specified, add a "all namespaces" option to the
         *     namespace dropdown, and use this as the input value for it
-        * @param int|string $config['valueNamespace'] Input value of the namespace dropdown box. May be a
-        *     string only if 'includeAllValue' is set.
-        * @param boolean $config['valueInvert'] Input value of the "invert selection" checkbox (default:
-        *     false)
-        * @param boolean $config['valueAssociated'] Input value of the "include associated namespace"
-        *     checkbox (default: false)
-        * @param string $config['labelInvert'] Text of label to use for "invert selection" checkbox
-        * @param string $config['labelAssociated'] Text of label to use for "include associated
-        *     namespace" checkbox
+        * @param number[] $config['exclude'] List of namespace numbers to exclude from the selector
         */
-       public function __construct( array $config = array() ) {
+       public function __construct( array $config = [] ) {
                // Configuration initialization
-               $config = array_merge(
-                       array(
-                               'nameNamespace' => 'namespace',
-                               'nameInvert' => 'invert',
-                               'nameAssociated' => 'associated',
-                               // Choose first available: either main namespace or the "all namespaces" option
-                               'valueNamespace' => null,
-                               'valueInvert' => false,
-                               'valueAssociated' => false,
-                       ),
-                       $config
-               );
+               $config['options'] = $this->getNamespaceDropdownOptions( $config );
 
                // Parent constructor
                parent::__construct( $config );
 
                // Properties
-               $this->allValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
-               $this->namespace = new \OOUI\DropdownInputWidget( array(
-                       'name' => $config['nameNamespace'],
-                       'value' => $config['valueNamespace'],
-                       'options' => $this->getNamespaceDropdownOptions( $config ),
-               ) );
-               if ( $config['nameAssociated'] !== null ) {
-                       // FIXME Should use a LabelWidget? But they don't work like HTML <label>s yet
-                       $this->associated = new \OOUI\FieldLayout(
-                               new \OOUI\CheckboxInputWidget( array(
-                                       'name' => $config['nameAssociated'],
-                                       'selected' => $config['valueAssociated'],
-                                       'value' => '1',
-                               ) ),
-                               array(
-                                       'align' => 'inline',
-                                       'label' => $config['labelAssociated'],
-                               )
-                       );
-               }
-               if ( $config['nameInvert'] !== null ) {
-                       $this->invert = new \OOUI\FieldLayout(
-                               new \OOUI\CheckboxInputWidget( array(
-                                       'name' => $config['nameInvert'],
-                                       'selected' => $config['valueInvert'],
-                                       'value' => '1',
-                               ) ),
-                               array(
-                                       'align' => 'inline',
-                                       'label' => $config['labelInvert'],
-                               )
-                       );
-               }
+               $this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
+               $this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : [];
 
                // Initialization
-               $this
-                       ->addClasses( array( 'mw-widget-namespaceInputWidget' ) )
-                       ->appendContent( $this->namespace, $this->associated, $this->invert );
+               $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
        }
 
        protected function getNamespaceDropdownOptions( array $config ) {
-               $namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
-                       array( 'all' => $config['includeAllValue'] ) : array();
+               $namespaceOptionsParams = [
+                       'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null,
+                       'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null
+               ];
                $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
 
-               $options = array();
+               $options = [];
                foreach ( $namespaceOptions as $id => $name ) {
-                       $options[] = array(
+                       $options[] = [
                                'data' => (string)$id,
                                'label' => $name,
-                       );
+                       ];
                }
 
                return $options;
@@ -118,10 +58,9 @@ class NamespaceInputWidget extends \OOUI\Widget {
        }
 
        public function getConfig( &$config ) {
-               $config['namespace'] = $this->namespace;
-               $config['associated'] = $this->associated;
-               $config['invert'] = $this->invert;
-               $config['allValue'] = $this->allValue;
-               return parent::getConfig( $config );
+               $config['includeAllValue'] = $this->includeAllValue;
+               $config['exclude'] = $this->exclude;
+               // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
+               return \OOUI\InputWidget::getConfig( $config );
        }
 }