diff options
Diffstat (limited to 'includes/widget')
-rw-r--r-- | includes/widget/AUTHORS.txt | 11 | ||||
-rw-r--r-- | includes/widget/ComplexNamespaceInputWidget.php | 110 | ||||
-rw-r--r-- | includes/widget/ComplexTitleInputWidget.php | 67 | ||||
-rw-r--r-- | includes/widget/LICENSE.txt | 25 | ||||
-rw-r--r-- | includes/widget/NamespaceInputWidget.php | 66 | ||||
-rw-r--r-- | includes/widget/TitleInputWidget.php | 60 | ||||
-rw-r--r-- | includes/widget/UserInputWidget.php | 29 |
7 files changed, 368 insertions, 0 deletions
diff --git a/includes/widget/AUTHORS.txt b/includes/widget/AUTHORS.txt new file mode 100644 index 00000000..a0d77030 --- /dev/null +++ b/includes/widget/AUTHORS.txt @@ -0,0 +1,11 @@ +Authors (alphabetically) + +Alex Monk <krenair@wikimedia.org> +Bartosz Dziewoński <bdziewonski@wikimedia.org> +Ed Sanders <esanders@wikimedia.org> +Florian Schmidt <florian.schmidt.welzow@t-online.de> +James D. Forrester <jforrester@wikimedia.org> +Roan Kattouw <roan@wikimedia.org> +Sucheta Ghoshal <sghoshal@wikimedia.org> +Timo Tijhof <timo@wikimedia.org> +Trevor Parscal <trevor@wikimedia.org> diff --git a/includes/widget/ComplexNamespaceInputWidget.php b/includes/widget/ComplexNamespaceInputWidget.php new file mode 100644 index 00000000..21c57099 --- /dev/null +++ b/includes/widget/ComplexNamespaceInputWidget.php @@ -0,0 +1,110 @@ +<?php +/** + * MediaWiki Widgets – ComplexNamespaceInputWidget 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, plus two + * checkboxes to include associated namespace or to invert selection. + */ +class ComplexNamespaceInputWidget extends \OOUI\Widget { + + protected $config; + protected $namespace; + protected $associated = null; + protected $associatedLabel = null; + protected $invert = null; + protected $invertLabel = null; + + /** + * @param array $config Configuration options + * @param array $config['namespace'] Configuration for the NamespaceInputWidget dropdown with list + * of namespaces + * @param string $config['namespace']['includeAllValue'] If specified, add a "all namespaces" + * option to the dropdown, and use this as the input value for it + * @param array|null $config['invert'] Configuration for the "invert selection" CheckboxInputWidget. If + * null, the checkbox will not be generated. + * @param array|null $config['associated'] Configuration for the "include associated namespace" + * CheckboxInputWidget. If null, the checkbox will not be generated. + * @param array $config['invertLabel'] Configuration for the FieldLayout with label wrapping the + * "invert selection" checkbox + * @param string $config['invertLabel']['label'] Label text for the label + * @param array $config['associatedLabel'] Configuration for the FieldLayout with label wrapping + * the "include associated namespace" checkbox + * @param string $config['associatedLabel']['label'] Label text for the label + */ + public function __construct( array $config = array() ) { + // Configuration initialization + $config = array_merge( + array( + // Config options for nested widgets + 'namespace' => array(), + 'invert' => array(), + 'invertLabel' => array(), + 'associated' => array(), + 'associatedLabel' => array(), + ), + $config + ); + + // Parent constructor + parent::__construct( $config ); + + // Properties + $this->config = $config; + + $this->namespace = new NamespaceInputWidget( $config['namespace'] ); + if ( $config['associated'] !== null ) { + $this->associated = new \OOUI\CheckboxInputWidget( array_merge( + array( 'value' => '1' ), + $config['associated'] + ) ); + // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet + $this->associatedLabel = new \OOUI\FieldLayout( + $this->associated, + array_merge( + array( 'align' => 'inline' ), + $config['associatedLabel'] + ) + ); + } + if ( $config['invert'] !== null ) { + $this->invert = new \OOUI\CheckboxInputWidget( array_merge( + array( 'value' => '1' ), + $config['invert'] + ) ); + // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet + $this->invertLabel = new \OOUI\FieldLayout( + $this->invert, + array_merge( + array( 'align' => 'inline' ), + $config['invertLabel'] + ) + ); + } + + // Initialization + $this + ->addClasses( array( 'mw-widget-complexNamespaceInputWidget' ) ) + ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel ); + } + + protected function getJavaScriptClassName() { + return 'mw.widgets.ComplexNamespaceInputWidget'; + } + + public function getConfig( &$config ) { + $config = array_merge( + $config, + array_intersect_key( + $this->config, + array_fill_keys( array( 'namespace', 'invert', 'invertLabel', 'associated', 'associatedLabel' ), true ) + ) + ); + return parent::getConfig( $config ); + } +} diff --git a/includes/widget/ComplexTitleInputWidget.php b/includes/widget/ComplexTitleInputWidget.php new file mode 100644 index 00000000..73ef54c8 --- /dev/null +++ b/includes/widget/ComplexTitleInputWidget.php @@ -0,0 +1,67 @@ +<?php +/** + * MediaWiki Widgets – ComplexTitleInputWidget class. + * + * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ +namespace MediaWiki\Widget; + +/** + * Complex title input widget. + */ +class ComplexTitleInputWidget extends \OOUI\Widget { + + protected $namespace = null; + protected $title = null; + + /** + * Like TitleInputWidget, but the namespace has to be input through a separate dropdown field. + * + * @param array $config Configuration options + * @param array $config['namespace'] Configuration for the NamespaceInputWidget dropdown with list + * of namespaces + * @param array $config['title'] Configuration for the TitleInputWidget text field + */ + public function __construct( array $config = array() ) { + // Configuration initialization + $config = array_merge( + array( + 'namespace' => array(), + 'title' => array(), + ), + $config + ); + + // Parent constructor + parent::__construct( $config ); + + // Properties + $this->config = $config; + $this->namespace = new NamespaceInputWidget( $config['namespace'] ); + $this->title = new TitleInputWidget( array_merge( + $config['title'], + array( + // The inner TitleInputWidget shouldn't be infusable, only the ComplexTitleInputWidget itself can be. + 'infusable' => false, + 'relative' => true, + 'namespace' => isset( $config['namespace']['value'] ) ? $config['namespace']['value'] : null, + ) + ) ); + + // Initialization + $this + ->addClasses( array( 'mw-widget-complexTitleInputWidget' ) ) + ->appendContent( $this->namespace, $this->title ); + } + + protected function getJavaScriptClassName() { + return 'mw.widgets.ComplexTitleInputWidget'; + } + + public function getConfig( &$config ) { + $config['namespace'] = $this->config['namespace']; + $config['title'] = $this->config['title']; + return parent::getConfig( $config ); + } +} diff --git a/includes/widget/LICENSE.txt b/includes/widget/LICENSE.txt new file mode 100644 index 00000000..b03ca801 --- /dev/null +++ b/includes/widget/LICENSE.txt @@ -0,0 +1,25 @@ +Copyright (c) 2011-2015 MediaWiki Widgets Team and others under the +terms of The MIT License (MIT), as follows: + +This software consists of voluntary contributions made by many +individuals (AUTHORS.txt) For exact contribution history, see the +revision history and logs, available at https://gerrit.wikimedia.org + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/includes/widget/NamespaceInputWidget.php b/includes/widget/NamespaceInputWidget.php new file mode 100644 index 00000000..696c8adf --- /dev/null +++ b/includes/widget/NamespaceInputWidget.php @@ -0,0 +1,66 @@ +<?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 + * @param number[] $config['exclude'] List of namespace numbers to exclude from the selector + */ + 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; + $this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : array(); + + // Initialization + $this->addClasses( array( 'mw-widget-namespaceInputWidget' ) ); + } + + protected function getNamespaceDropdownOptions( array $config ) { + $namespaceOptionsParams = array( + 'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null, + 'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null + ); + $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; + $config['exclude'] = $this->exclude; + // Skip DropdownInputWidget's getConfig(), we don't need 'options' config + return \OOUI\InputWidget::getConfig( $config ); + } +} diff --git a/includes/widget/TitleInputWidget.php b/includes/widget/TitleInputWidget.php new file mode 100644 index 00000000..8ac7014e --- /dev/null +++ b/includes/widget/TitleInputWidget.php @@ -0,0 +1,60 @@ +<?php +/** + * MediaWiki Widgets – TitleInputWidget class. + * + * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ +namespace MediaWiki\Widget; + +/** + * Title input widget. + */ +class TitleInputWidget extends \OOUI\TextInputWidget { + + protected $namespace = null; + protected $relative = null; + protected $suggestions = null; + + /** + * @param array $config Configuration options + * @param int|null $config['namespace'] Namespace to prepend to queries + * @param bool|null $config['relative'] If a namespace is set, return a title relative to it (default: true) + * @param bool|null $config['suggestions'] Display search suggestions (default: true) + */ + public function __construct( array $config = array() ) { + // Parent constructor + parent::__construct( array_merge( array( 'infusable' => true, 'maxLength' => 255 ), $config ) ); + + // Properties, which are ignored in PHP and just shipped back to JS + if ( isset( $config['namespace'] ) ) { + $this->namespace = $config['namespace']; + } + if ( isset( $config['relative'] ) ) { + $this->relative = $config['relative']; + } + if ( isset( $config['suggestions'] ) ) { + $this->suggestions = $config['suggestions']; + } + + // Initialization + $this->addClasses( array( 'mw-widget-titleInputWidget' ) ); + } + + protected function getJavaScriptClassName() { + return 'mw.widgets.TitleInputWidget'; + } + + public function getConfig( &$config ) { + if ( $this->namespace !== null ) { + $config['namespace'] = $this->namespace; + } + if ( $this->relative !== null ) { + $config['relative'] = $this->relative; + } + if ( $this->suggestions !== null ) { + $config['suggestions'] = $this->suggestions; + } + return parent::getConfig( $config ); + } +} diff --git a/includes/widget/UserInputWidget.php b/includes/widget/UserInputWidget.php new file mode 100644 index 00000000..1e2d3d61 --- /dev/null +++ b/includes/widget/UserInputWidget.php @@ -0,0 +1,29 @@ +<?php +/** + * MediaWiki Widgets – UserInputWidget class. + * + * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ +namespace MediaWiki\Widget; + +/** + * User input widget. + */ +class UserInputWidget extends \OOUI\TextInputWidget { + + /** + * @param array $config Configuration options + */ + public function __construct( array $config = array() ) { + // Parent constructor + parent::__construct( array_merge( array( 'infusable' => true ), $config ) ); + + // Initialization + $this->addClasses( array( 'mw-widget-userInputWidget' ) ); + } + + protected function getJavaScriptClassName() { + return 'mw.widgets.UserInputWidget'; + } +} |