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
70 lines
1.4 KiB
PHP
70 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
use Exception;
|
|
use MediaWiki\Html\Html;
|
|
|
|
/**
|
|
* PHP version of jquery.spinner.
|
|
*
|
|
* If used with jquery.spinner.styles, can be used to show a
|
|
* spinner before JavaScript has loaded.
|
|
*
|
|
* @copyright 2011-2020 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
* @license MIT
|
|
*/
|
|
class SpinnerWidget {
|
|
|
|
private $attributes;
|
|
private $content;
|
|
|
|
/**
|
|
* @param array $config Configuration options
|
|
*/
|
|
public function __construct( array $config = [] ) {
|
|
$size = $config['size'] ?? 'small';
|
|
$type = $config['type'] ?? 'inline';
|
|
|
|
$this->attributes = [];
|
|
|
|
if ( isset( $config['id'] ) ) {
|
|
$this->attributes['id'] = $config['id'];
|
|
}
|
|
|
|
// Initialization
|
|
$this->attributes['class'] = [
|
|
'mw-spinner',
|
|
$size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large',
|
|
$type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block',
|
|
];
|
|
|
|
$this->content =
|
|
'<div class="mw-spinner-container">' .
|
|
str_repeat( '<div></div>', 12 ) .
|
|
'</div>';
|
|
}
|
|
|
|
/**
|
|
* Render element into HTML.
|
|
* @return string HTML serialization
|
|
*/
|
|
public function toString() {
|
|
return Html::rawElement( 'div', $this->attributes, $this->content );
|
|
}
|
|
|
|
/**
|
|
* Magic method implementation.
|
|
*
|
|
* Copied from OOUI\Tag
|
|
*
|
|
* @return string
|
|
*/
|
|
public function __toString() {
|
|
try {
|
|
return $this->toString();
|
|
} catch ( Exception $ex ) {
|
|
trigger_error( (string)$ex, E_USER_ERROR );
|
|
}
|
|
}
|
|
}
|