TitleInputWidget: Allow suppressing search suggestions
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 11 Aug 2015 18:29:05 +0000 (20:29 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 20 Aug 2015 15:11:22 +0000 (15:11 +0000)
Needed for Ice69df851137e3454ae2c9f4c75494b18cf8a75a.

Change-Id: Ibc7846bb08abdd1ebf271dfce526dd935f38e111

includes/widget/TitleInputWidget.php
resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js

index d3e2851..8b8010e 100644 (file)
@@ -14,11 +14,13 @@ 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
@@ -28,10 +30,12 @@ class TitleInputWidget extends \OOUI\TextInputWidget {
                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' ) );
@@ -48,6 +52,9 @@ class TitleInputWidget extends \OOUI\TextInputWidget {
                if ( $this->relative !== null ) {
                        $config['relative'] = $this->relative;
                }
+               if ( $this->suggestions !== null ) {
+                       $config['suggestions'] = $this->suggestions;
+               }
                return parent::getConfig( $config );
        }
 }
index 66b009f..4e3228f 100644 (file)
@@ -18,6 +18,7 @@
         * @cfg {number} [limit=10] Number of results to show
         * @cfg {number} [namespace] Namespace to prepend to queries
         * @cfg {boolean} [relative=true] If a namespace is set, return a title relative to it
+        * @cfg {boolean} [suggestions=true] Display search suggestions
         * @cfg {boolean} [showRedirectTargets=true] Show the targets of redirects
         * @cfg {boolean} [showRedlink] Show red link to exact match if it doesn't exist
         * @cfg {boolean} [showImages] Show page images
@@ -40,6 +41,7 @@
                this.limit = config.limit || 10;
                this.namespace = config.namespace !== undefined ? config.namespace : null;
                this.relative = config.relative !== undefined ? config.relative : true;
+               this.suggestions = config.suggestions !== undefined ? config.suggestions : true;
                this.showRedirectTargets = config.showRedirectTargets !== false;
                this.showRedlink = !!config.showRedlink;
                this.showImages = !!config.showImages;
@@ -55,6 +57,7 @@
                if ( this.showDescriptions ) {
                        this.lookupMenu.$element.addClass( 'mw-widget-titleInputWidget-menu-withDescriptions' );
                }
+               this.setLookupsDisabled( !this.suggestions );
 
                this.interwikiPrefixes = [];
                this.interwikiPrefixesPromise = new mw.Api().get( {
@@ -82,7 +85,7 @@
                this.closeLookupMenu();
                this.setLookupsDisabled( true );
                this.setValue( item.getData() );
-               this.setLookupsDisabled( false );
+               this.setLookupsDisabled( !this.suggestions );
        };
 
        /**
                // Parent method
                retval = mw.widgets.TitleInputWidget.parent.prototype.focus.apply( this, arguments );
 
-               this.setLookupsDisabled( false );
+               this.setLookupsDisabled( !this.suggestions );
 
                return retval;
        };