wiki.techinc.nl/includes/widget/ComplexTitleInputWidget.php
Dogu bbc74d93b0 Refactor widget classes to use cleaner namespacing
This patch refactors various widget classes in the includes/widget
directory to use cleaner namespacing. The patches remove redundant backslash
prefixes in class extending statements and add use statements for OOUI classes
and other MediaWiki-specific classes. This patch improves readability and
maintainability of the code by following the MediaWiki coding conventions and
leverages the benefits of PHP's namespacing system.

List of affected classes:
- CheckMatrixWidget
- DateInputWidget
- DateTimeInputWidget
- NamespaceInputWidget
- SearchInputWidget
- SelectWithInputWidget
- SizeFilterWidget
- SpinnerWidget
- TagMultiselectWidget
- TitleInputWidget
- UserInputWidget

Additionally, the code now correctly documents exceptions thrown by
constructors where missing, enforcing clearer developer expectations.

Change-Id: I0fdaf68a412a1c3b7049a79222f4dbeaa95a6bbc
2024-01-02 23:24:56 +00:00

68 lines
1.7 KiB
PHP

<?php
namespace MediaWiki\Widget;
use OOUI\Widget;
/**
* Complex title input widget.
*
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license MIT
*/
class ComplexTitleInputWidget extends Widget {
/** @var array */
protected $config;
protected $namespace = null;
protected $title = null;
/**
* Like TitleInputWidget, but the namespace has to be input through a separate dropdown field.
*
* @param array $config Configuration options
* - array $config['namespace'] Configuration for the NamespaceInputWidget dropdown
* with list of namespaces
* - array $config['title'] Configuration for the TitleInputWidget text field
* @phan-param array{namespace?:array,title?:array} $config
*/
public function __construct( array $config = [] ) {
// Configuration initialization
$config = array_merge(
[
'namespace' => [],
'title' => [],
],
$config
);
parent::__construct( $config );
// Properties
$this->config = $config;
$this->namespace = new NamespaceInputWidget( $config['namespace'] );
$this->title = new TitleInputWidget( array_merge(
$config['title'],
[
'relative' => true,
'namespace' => $config['namespace']['value'] ?? null,
]
) );
// Initialization
$this
->addClasses( [ 'mw-widget-complexTitleInputWidget' ] )
->appendContent( $this->namespace, $this->title );
}
protected function getJavaScriptClassName() {
return 'mw.widgets.ComplexTitleInputWidget';
}
public function getConfig( &$config ) {
$config['namespace'] = $this->config['namespace'];
$config['namespace']['dropdown']['$overlay'] = true;
$config['title'] = $this->config['title'];
$config['title']['$overlay'] = true;
return parent::getConfig( $config );
}
}