From ad1c51d0e2451d6d2eeabcfe5d94a3a87e041f06 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 12 Nov 2015 18:31:57 +0100 Subject: [PATCH] Allow a TitleInputWidget user to decide, if an empty value should be validated For some use cases an empty value is valid, too, or at least, it's not a reason to mark the form input red. Special:Search, e.g.. This change implements a new config for MediaWiki\Widgets\TitleInputWidget, validate, which allows a user of this widget to decide, if the value of the input type should be validated (empty -> flagged red). Extra points: * Fix php notice errors for previously added configuration * Added doc for previously added configuration Bug: T106946 Change-Id: I732a2f56a2375d8c708e3b295996187ee209f1a6 --- includes/widget/TitleInputWidget.php | 11 +++++++++++ .../src/mediawiki.widgets/mw.widgets.TitleWidget.js | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/widget/TitleInputWidget.php b/includes/widget/TitleInputWidget.php index 25030b1a60..8226148c15 100644 --- a/includes/widget/TitleInputWidget.php +++ b/includes/widget/TitleInputWidget.php @@ -15,6 +15,8 @@ class TitleInputWidget extends \OOUI\TextInputWidget { protected $namespace = null; protected $relative = null; protected $suggestions = null; + protected $highlightFirst = null; + protected $validate = null; /** * @param array $config Configuration options @@ -22,6 +24,9 @@ class TitleInputWidget extends \OOUI\TextInputWidget { * @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) + * @param bool|null $config['highlightFirst'] Automatically highlight + * the first result (default: true) + * @param bool|null $config['validate'] Whether the input must be a valid title (default: true) */ public function __construct( array $config = array() ) { // Parent constructor @@ -42,6 +47,9 @@ class TitleInputWidget extends \OOUI\TextInputWidget { if ( isset( $config['highlightFirst'] ) ) { $this->highlightFirst = $config['highlightFirst']; } + if ( isset( $config['validate'] ) ) { + $this->validate = $config['validate']; + } // Initialization $this->addClasses( array( 'mw-widget-titleInputWidget' ) ); @@ -64,6 +72,9 @@ class TitleInputWidget extends \OOUI\TextInputWidget { if ( $this->highlightFirst !== null ) { $config['highlightFirst'] = $this->highlightFirst; } + if ( $this->validate !== null ) { + $config['validate'] = $this->validate; + } return parent::getConfig( $config ); } } diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js index 67f3e01c1c..84732aab19 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js @@ -23,6 +23,7 @@ * @cfg {boolean} [showRedlink] Show red link to exact match if it doesn't exist * @cfg {boolean} [showImages] Show page images * @cfg {boolean} [showDescriptions] Show page descriptions + * @cfg {boolean} [validate=true] Whether the input must be a valid title * @cfg {Object} [cache] Result cache which implements a 'set' method, taking keyed values as an argument */ mw.widgets.TitleWidget = function MwWidgetsTitleWidget( config ) { @@ -44,6 +45,7 @@ this.showRedlink = !!config.showRedlink; this.showImages = !!config.showImages; this.showDescriptions = !!config.showDescriptions; + this.validate = config.validate !== undefined ? config.validate : true; this.cache = config.cache; // Initialization @@ -285,7 +287,7 @@ * @return {boolean} The query is valid */ mw.widgets.TitleWidget.prototype.isQueryValid = function () { - return !!this.getTitle(); + return this.validate ? !!this.getTitle() : true; }; }( jQuery, mediaWiki ) ); -- 2.20.1