From 2ac9e2a4327af2102c20df5d186fc62858f0f9ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 14 Jul 2015 22:30:06 +0200 Subject: [PATCH] Implement NamespaceInputWidget MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Add PHP version of NamespaceInputWidget, co-authored by Florian, which consists of a DropdownInputWidget offering a choice of namespaces and two CheckboxInputWidgets allowing to also match associated namespace (talk/content) or to invert the choice. * Add an incomplete JS version of NamespaceInputWidget, which is only really functional when infused from the PHP version (it can't generate the dropdown by itself, for example). Implement some JS to improve the experience of selecting the "all namespaces" option in the dropdown (by disabling the checkboxes when this happens). * Split off a 'mediawiki.widgets.styles' module, which has the basic styles for PHP widgets which are to be loaded in the head. Make OutputPage::enableOOUI() also add this module (which should stay reasonably small). * Use the new widget in HTMLForm's HTMLSelectNamespace field. It can be seen in action on Special:LinkSearch, for example. Co-Authored-By: Florian Co-Authored-By: Bartosz Dziewoński Change-Id: I5cbfa9d0f6a8641148ce476b7dbe65e9096b4485 --- autoload.php | 1 + includes/OutputPage.php | 1 + includes/htmlform/HTMLSelectNamespace.php | 21 +-- includes/widget/AUTHORS.txt | 1 + includes/widget/NamespaceInputWidget.php | 128 ++++++++++++++++++ resources/Resources.php | 15 +- .../mw.widgets.NamespaceInputWidget.base.css | 26 ++++ .../mw.widgets.NamespaceInputWidget.js | 68 ++++++++++ 8 files changed, 246 insertions(+), 15 deletions(-) create mode 100644 includes/widget/NamespaceInputWidget.php create mode 100644 resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.base.css create mode 100644 resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js diff --git a/autoload.php b/autoload.php index 2c9dd8fe28..fd75c8a534 100644 --- a/autoload.php +++ b/autoload.php @@ -754,6 +754,7 @@ $wgAutoloadLocalClasses = array( 'MediaWiki\\Logger\\Monolog\\WikiProcessor' => __DIR__ . '/includes/debug/logger/monolog/WikiProcessor.php', 'MediaWiki\\Logger\\NullSpi' => __DIR__ . '/includes/debug/logger/NullSpi.php', 'MediaWiki\\Logger\\Spi' => __DIR__ . '/includes/debug/logger/Spi.php', + 'MediaWiki\\Widget\\NamespaceInputWidget' => __DIR__ . '/includes/widget/NamespaceInputWidget.php', 'MediaWiki\\Widget\\TitleInputWidget' => __DIR__ . '/includes/widget/TitleInputWidget.php', 'MemCachedClientforWiki' => __DIR__ . '/includes/objectcache/MemcachedClient.php', 'MemcLockManager' => __DIR__ . '/includes/filebackend/lockmanager/MemcLockManager.php', diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 30ee19cc5a..e832b82b42 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -3959,6 +3959,7 @@ class OutputPage extends ContextSource { 'oojs-ui.styles.icons', 'oojs-ui.styles.indicators', 'oojs-ui.styles.textures', + 'mediawiki.widgets.styles', ) ); } } diff --git a/includes/htmlform/HTMLSelectNamespace.php b/includes/htmlform/HTMLSelectNamespace.php index dfab6cf27b..d6d564e91f 100644 --- a/includes/htmlform/HTMLSelectNamespace.php +++ b/includes/htmlform/HTMLSelectNamespace.php @@ -22,21 +22,14 @@ class HTMLSelectNamespace extends HTMLFormField { } public function getInputOOUI( $value ) { - $namespaceOptions = Html::namespaceSelectorOptions( array( 'all' => $this->mAllValue ) ); - - $options = array(); - foreach( $namespaceOptions as $id => $name ) { - $options[] = array( - 'data' => (string)$id, - 'label' => $name, - ); - }; - - return new OOUI\DropdownInputWidget( array( - 'options' => $options, - 'value' => $value, - 'name' => $this->mName, + return new MediaWiki\Widget\NamespaceInputWidget( array( + 'valueNamespace' => $value, + 'nameNamespace' => $this->mName, 'id' => $this->mID, + 'includeAllValue' => $this->mAllValue, + // Disable additional checkboxes + 'nameInvert' => null, + 'nameAssociated' => null, ) ); } } diff --git a/includes/widget/AUTHORS.txt b/includes/widget/AUTHORS.txt index 10064b247e..a0d77030d2 100644 --- a/includes/widget/AUTHORS.txt +++ b/includes/widget/AUTHORS.txt @@ -3,6 +3,7 @@ Authors (alphabetically) Alex Monk Bartosz Dziewoński Ed Sanders +Florian Schmidt James D. Forrester Roan Kattouw Sucheta Ghoshal diff --git a/includes/widget/NamespaceInputWidget.php b/includes/widget/NamespaceInputWidget.php new file mode 100644 index 0000000000..69427c502e --- /dev/null +++ b/includes/widget/NamespaceInputWidget.php @@ -0,0 +1,128 @@ + 'namespace', + 'nameInvert' => 'invert', + 'nameAssociated' => 'associated', + // Choose first available: either main namespace or the "all namespaces" option + 'valueNamespace' => null, + 'valueInvert' => false, + 'valueAssociated' => false, + ), + $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