Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TitleInputWidget
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
240
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
56
 getJavaScriptClassName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getConfig
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\TextInputWidget;
6
7/**
8 * Title input widget.
9 *
10 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 * @license MIT
12 */
13class TitleInputWidget extends TextInputWidget {
14
15    /** @var int|null */
16    protected $namespace = null;
17    /** @var bool|null */
18    protected $relative = null;
19    /** @var bool|null */
20    protected $suggestions = null;
21    /** @var bool|null */
22    protected $highlightFirst = null;
23    /** @var bool|null */
24    protected $validateTitle = null;
25    /** @var bool|null */
26    protected $creatable = null;
27
28    /**
29     * @param array $config Configuration options
30     *   - int|null $config['namespace'] Namespace to prepend to queries
31     *   - bool|null $config['relative'] If a namespace is set,
32     *     return a title relative to it (default: true)
33     *   - bool|null $config['suggestions'] Display search suggestions (default: true)
34     *   - bool|null $config['highlightFirst'] Automatically highlight
35     *     the first result (default: true)
36     *   - bool|null $config['validateTitle'] Whether the input must
37     *     be a valid title (default: true)
38     *   - bool|null $config['creatable'] Whether to validate the title
39     *     is creatable (not a special page) (default: false)
40     */
41    public function __construct( array $config = [] ) {
42        parent::__construct(
43            array_merge( [ 'maxLength' => 255 ], $config )
44        );
45
46        // Properties, which are ignored in PHP and just shipped back to JS
47        if ( isset( $config['namespace'] ) ) {
48            $this->namespace = $config['namespace'];
49        }
50        if ( isset( $config['relative'] ) ) {
51            $this->relative = $config['relative'];
52        }
53        if ( isset( $config['suggestions'] ) ) {
54            $this->suggestions = $config['suggestions'];
55        }
56        if ( isset( $config['highlightFirst'] ) ) {
57            $this->highlightFirst = $config['highlightFirst'];
58        }
59        if ( isset( $config['validateTitle'] ) ) {
60            $this->validateTitle = $config['validateTitle'];
61        }
62        if ( isset( $config['creatable'] ) ) {
63            $this->creatable = $config['creatable'];
64        }
65
66        // Initialization
67        $this->addClasses( [ 'mw-widget-titleInputWidget' ] );
68    }
69
70    /** @inheritDoc */
71    protected function getJavaScriptClassName() {
72        return 'mw.widgets.TitleInputWidget';
73    }
74
75    /** @inheritDoc */
76    public function getConfig( &$config ) {
77        if ( $this->namespace !== null ) {
78            $config['namespace'] = $this->namespace;
79        }
80        if ( $this->relative !== null ) {
81            $config['relative'] = $this->relative;
82        }
83        if ( $this->suggestions !== null ) {
84            $config['suggestions'] = $this->suggestions;
85        }
86        if ( $this->highlightFirst !== null ) {
87            $config['highlightFirst'] = $this->highlightFirst;
88        }
89        if ( $this->validateTitle !== null ) {
90            $config['validateTitle'] = $this->validateTitle;
91        }
92        if ( $this->creatable !== null ) {
93            $config['creatable'] = $this->creatable;
94        }
95
96        $config['$overlay'] = true;
97        return parent::getConfig( $config );
98    }
99}