Merge "Add semantic tags to license info text"
[lhc/web/wiklou.git] / includes / widget / TitleInputWidget.php
1 <?php
2 /**
3 * MediaWiki Widgets – TitleInputWidget class.
4 *
5 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
7 */
8 namespace MediaWiki\Widget;
9
10 /**
11 * Title input widget.
12 */
13 class TitleInputWidget extends \OOUI\TextInputWidget {
14
15 protected $namespace = null;
16 protected $relative = null;
17 protected $suggestions = null;
18 protected $highlightFirst = null;
19 protected $validateTitle = null;
20
21 /**
22 * @param array $config Configuration options
23 * @param int|null $config['namespace'] Namespace to prepend to queries
24 * @param bool|null $config['relative'] If a namespace is set,
25 * return a title relative to it (default: true)
26 * @param bool|null $config['suggestions'] Display search suggestions (default: true)
27 * @param bool|null $config['highlightFirst'] Automatically highlight
28 * the first result (default: true)
29 * @param bool|null $config['validateTitle'] Whether the input must
30 * be a valid title (default: true)
31 */
32 public function __construct( array $config = [] ) {
33 parent::__construct(
34 array_merge( [ 'maxLength' => 255 ], $config )
35 );
36
37 // Properties, which are ignored in PHP and just shipped back to JS
38 if ( isset( $config['namespace'] ) ) {
39 $this->namespace = $config['namespace'];
40 }
41 if ( isset( $config['relative'] ) ) {
42 $this->relative = $config['relative'];
43 }
44 if ( isset( $config['suggestions'] ) ) {
45 $this->suggestions = $config['suggestions'];
46 }
47 if ( isset( $config['highlightFirst'] ) ) {
48 $this->highlightFirst = $config['highlightFirst'];
49 }
50 if ( isset( $config['validateTitle'] ) ) {
51 $this->validateTitle = $config['validateTitle'];
52 }
53
54 // Initialization
55 $this->addClasses( [ 'mw-widget-titleInputWidget' ] );
56 }
57
58 protected function getJavaScriptClassName() {
59 return 'mw.widgets.TitleInputWidget';
60 }
61
62 public function getConfig( &$config ) {
63 if ( $this->namespace !== null ) {
64 $config['namespace'] = $this->namespace;
65 }
66 if ( $this->relative !== null ) {
67 $config['relative'] = $this->relative;
68 }
69 if ( $this->suggestions !== null ) {
70 $config['suggestions'] = $this->suggestions;
71 }
72 if ( $this->highlightFirst !== null ) {
73 $config['highlightFirst'] = $this->highlightFirst;
74 }
75 if ( $this->validateTitle !== null ) {
76 $config['validateTitle'] = $this->validateTitle;
77 }
78 $config['$overlay'] = true;
79 return parent::getConfig( $config );
80 }
81 }