2015-01-16 22:42:54 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2015-01-16 22:42:54 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2024-01-02 18:31:56 +00:00
|
|
|
use OOUI\Widget;
|
|
|
|
|
|
2015-01-16 22:42:54 +00:00
|
|
|
/**
|
|
|
|
|
* Complex 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-01-16 22:42:54 +00:00
|
|
|
*/
|
2024-01-02 18:31:56 +00:00
|
|
|
class ComplexTitleInputWidget extends Widget {
|
2019-09-10 12:05:14 +00:00
|
|
|
/** @var array */
|
|
|
|
|
protected $config;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var NamespaceInputWidget|null */
|
2015-01-16 22:42:54 +00:00
|
|
|
protected $namespace = null;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var TitleInputWidget|null */
|
2015-01-16 22:42:54 +00:00
|
|
|
protected $title = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
|
|
|
|
|
*
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - array $config['namespace'] Configuration for the NamespaceInputWidget dropdown
|
|
|
|
|
* with list of namespaces
|
|
|
|
|
* - array $config['title'] Configuration for the TitleInputWidget text field
|
2019-08-30 18:17:32 +00:00
|
|
|
* @phan-param array{namespace?:array,title?:array} $config
|
2015-01-16 22:42:54 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
public function __construct( array $config = [] ) {
|
2015-01-16 22:42:54 +00:00
|
|
|
// Configuration initialization
|
|
|
|
|
$config = array_merge(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'namespace' => [],
|
|
|
|
|
'title' => [],
|
|
|
|
|
],
|
2015-01-16 22:42:54 +00:00
|
|
|
$config
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
parent::__construct( $config );
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->namespace = new NamespaceInputWidget( $config['namespace'] );
|
|
|
|
|
$this->title = new TitleInputWidget( array_merge(
|
|
|
|
|
$config['title'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-01-16 22:42:54 +00:00
|
|
|
'relative' => true,
|
2017-10-06 22:17:58 +00:00
|
|
|
'namespace' => $config['namespace']['value'] ?? null,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2015-01-16 22:42:54 +00:00
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
|
$this
|
2016-02-17 09:09:32 +00:00
|
|
|
->addClasses( [ 'mw-widget-complexTitleInputWidget' ] )
|
2015-01-16 22:42:54 +00:00
|
|
|
->appendContent( $this->namespace, $this->title );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getJavaScriptClassName() {
|
|
|
|
|
return 'mw.widgets.ComplexTitleInputWidget';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getConfig( &$config ) {
|
|
|
|
|
$config['namespace'] = $this->config['namespace'];
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['namespace']['dropdown']['$overlay'] = true;
|
2015-01-16 22:42:54 +00:00
|
|
|
$config['title'] = $this->config['title'];
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['title']['$overlay'] = true;
|
2015-01-16 22:42:54 +00:00
|
|
|
return parent::getConfig( $config );
|
|
|
|
|
}
|
|
|
|
|
}
|