2015-05-25 09:54:29 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2015-05-25 09:54:29 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2024-01-02 18:31:56 +00:00
|
|
|
use OOUI\TextInputWidget;
|
|
|
|
|
|
2015-05-25 09:54:29 +00:00
|
|
|
/**
|
|
|
|
|
* Title input widget.
|
2017-12-28 15:17:33 +00:00
|
|
|
*
|
|
|
|
|
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
* @license MIT
|
2015-05-25 09:54:29 +00:00
|
|
|
*/
|
2024-01-02 18:31:56 +00:00
|
|
|
class TitleInputWidget extends TextInputWidget {
|
2015-05-25 09:54:29 +00:00
|
|
|
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var int|null */
|
2015-05-25 09:54:29 +00:00
|
|
|
protected $namespace = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var bool|null */
|
2015-07-04 07:39:41 +00:00
|
|
|
protected $relative = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var bool|null */
|
2015-08-11 18:29:05 +00:00
|
|
|
protected $suggestions = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var bool|null */
|
2015-11-12 17:31:57 +00:00
|
|
|
protected $highlightFirst = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var bool|null */
|
2015-11-19 21:21:15 +00:00
|
|
|
protected $validateTitle = null;
|
2015-05-25 09:54:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - int|null $config['namespace'] Namespace to prepend to queries
|
|
|
|
|
* - bool|null $config['relative'] If a namespace is set,
|
|
|
|
|
* return a title relative to it (default: true)
|
|
|
|
|
* - bool|null $config['suggestions'] Display search suggestions (default: true)
|
|
|
|
|
* - bool|null $config['highlightFirst'] Automatically highlight
|
|
|
|
|
* the first result (default: true)
|
|
|
|
|
* - bool|null $config['validateTitle'] Whether the input must
|
|
|
|
|
* be a valid title (default: true)
|
2015-05-25 09:54:29 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function __construct( array $config = [] ) {
|
2015-09-26 18:19:00 +00:00
|
|
|
parent::__construct(
|
2016-07-26 11:56:47 +00:00
|
|
|
array_merge( [ 'maxLength' => 255 ], $config )
|
2015-09-26 18:19:00 +00:00
|
|
|
);
|
2015-05-25 09:54:29 +00:00
|
|
|
|
2015-07-04 07:39:41 +00:00
|
|
|
// Properties, which are ignored in PHP and just shipped back to JS
|
2015-05-25 09:54:29 +00:00
|
|
|
if ( isset( $config['namespace'] ) ) {
|
|
|
|
|
$this->namespace = $config['namespace'];
|
|
|
|
|
}
|
2015-07-04 07:39:41 +00:00
|
|
|
if ( isset( $config['relative'] ) ) {
|
|
|
|
|
$this->relative = $config['relative'];
|
|
|
|
|
}
|
2015-08-11 18:29:05 +00:00
|
|
|
if ( isset( $config['suggestions'] ) ) {
|
|
|
|
|
$this->suggestions = $config['suggestions'];
|
|
|
|
|
}
|
2015-11-06 17:17:29 +00:00
|
|
|
if ( isset( $config['highlightFirst'] ) ) {
|
|
|
|
|
$this->highlightFirst = $config['highlightFirst'];
|
|
|
|
|
}
|
2015-11-19 21:21:15 +00:00
|
|
|
if ( isset( $config['validateTitle'] ) ) {
|
|
|
|
|
$this->validateTitle = $config['validateTitle'];
|
2015-11-12 17:31:57 +00:00
|
|
|
}
|
2015-07-04 07:39:41 +00:00
|
|
|
|
2015-05-25 09:54:29 +00:00
|
|
|
// Initialization
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addClasses( [ 'mw-widget-titleInputWidget' ] );
|
2015-05-25 09:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-09 21:50:18 +00:00
|
|
|
protected function getJavaScriptClassName() {
|
|
|
|
|
return 'mw.widgets.TitleInputWidget';
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-25 09:54:29 +00:00
|
|
|
public function getConfig( &$config ) {
|
|
|
|
|
if ( $this->namespace !== null ) {
|
|
|
|
|
$config['namespace'] = $this->namespace;
|
|
|
|
|
}
|
2015-07-04 07:39:41 +00:00
|
|
|
if ( $this->relative !== null ) {
|
|
|
|
|
$config['relative'] = $this->relative;
|
|
|
|
|
}
|
2015-08-11 18:29:05 +00:00
|
|
|
if ( $this->suggestions !== null ) {
|
|
|
|
|
$config['suggestions'] = $this->suggestions;
|
|
|
|
|
}
|
2015-11-06 17:17:29 +00:00
|
|
|
if ( $this->highlightFirst !== null ) {
|
|
|
|
|
$config['highlightFirst'] = $this->highlightFirst;
|
|
|
|
|
}
|
2015-11-19 21:21:15 +00:00
|
|
|
if ( $this->validateTitle !== null ) {
|
|
|
|
|
$config['validateTitle'] = $this->validateTitle;
|
2015-11-12 17:31:57 +00:00
|
|
|
}
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['$overlay'] = true;
|
2015-05-25 09:54:29 +00:00
|
|
|
return parent::getConfig( $config );
|
|
|
|
|
}
|
|
|
|
|
}
|