Allow a TitleInputWidget user to decide, if an empty value should be validated
[lhc/web/wiklou.git] / includes / widget / TitleInputWidget.php
index d3e2851..8226148 100644 (file)
@@ -14,24 +14,42 @@ 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
         * @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['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
-               parent::__construct( array_merge( $config, array( 'infusable' => true ) ) );
+               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'];
+               }
+               if ( isset( $config['highlightFirst'] ) ) {
+                       $this->highlightFirst = $config['highlightFirst'];
+               }
+               if ( isset( $config['validate'] ) ) {
+                       $this->validate = $config['validate'];
+               }
 
                // Initialization
                $this->addClasses( array( 'mw-widget-titleInputWidget' ) );
@@ -48,6 +66,15 @@ class TitleInputWidget extends \OOUI\TextInputWidget {
                if ( $this->relative !== null ) {
                        $config['relative'] = $this->relative;
                }
+               if ( $this->suggestions !== null ) {
+                       $config['suggestions'] = $this->suggestions;
+               }
+               if ( $this->highlightFirst !== null ) {
+                       $config['highlightFirst'] = $this->highlightFirst;
+               }
+               if ( $this->validate !== null ) {
+                       $config['validate'] = $this->validate;
+               }
                return parent::getConfig( $config );
        }
 }