From b6046dff660fd5609e5a497b7907fb20004076c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 11 Aug 2015 17:12:36 +0200 Subject: [PATCH] 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 --- autoload.php | 1 + includes/htmlform/HTMLSelectNamespace.php | 7 +- .../widget/ComplexNamespaceInputWidget.php | 110 ++++++++++++++++ includes/widget/NamespaceInputWidget.php | 84 ++----------- resources/Resources.php | 8 +- ...dgets.ComplexNamespaceInputWidget.base.css | 26 ++++ .../mw.widgets.ComplexNamespaceInputWidget.js | 118 ++++++++++++++++++ .../mw.widgets.NamespaceInputWidget.base.css | 26 ---- .../mw.widgets.NamespaceInputWidget.js | 69 +++++----- 9 files changed, 307 insertions(+), 142 deletions(-) create mode 100644 includes/widget/ComplexNamespaceInputWidget.php create mode 100644 resources/src/mediawiki.widgets/mw.widgets.ComplexNamespaceInputWidget.base.css create mode 100644 resources/src/mediawiki.widgets/mw.widgets.ComplexNamespaceInputWidget.js delete mode 100644 resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.base.css diff --git a/autoload.php b/autoload.php index 48e0b8824a..8a6a34078d 100644 --- a/autoload.php +++ b/autoload.php @@ -762,6 +762,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\\ComplexNamespaceInputWidget' => __DIR__ . '/includes/widget/ComplexNamespaceInputWidget.php', 'MediaWiki\\Widget\\NamespaceInputWidget' => __DIR__ . '/includes/widget/NamespaceInputWidget.php', 'MediaWiki\\Widget\\TitleInputWidget' => __DIR__ . '/includes/widget/TitleInputWidget.php', 'MediaWiki\\Widget\\UserInputWidget' => __DIR__ . '/includes/widget/UserInputWidget.php', diff --git a/includes/htmlform/HTMLSelectNamespace.php b/includes/htmlform/HTMLSelectNamespace.php index d6d564e91f..4efdfbf306 100644 --- a/includes/htmlform/HTMLSelectNamespace.php +++ b/includes/htmlform/HTMLSelectNamespace.php @@ -23,13 +23,10 @@ class HTMLSelectNamespace extends HTMLFormField { public function getInputOOUI( $value ) { return new MediaWiki\Widget\NamespaceInputWidget( array( - 'valueNamespace' => $value, - 'nameNamespace' => $this->mName, + 'value' => $value, + 'name' => $this->mName, 'id' => $this->mID, 'includeAllValue' => $this->mAllValue, - // Disable additional checkboxes - 'nameInvert' => null, - 'nameAssociated' => null, ) ); } } diff --git a/includes/widget/ComplexNamespaceInputWidget.php b/includes/widget/ComplexNamespaceInputWidget.php new file mode 100644 index 0000000000..21c57099fb --- /dev/null +++ b/includes/widget/ComplexNamespaceInputWidget.php @@ -0,0 +1,110 @@ + 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