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
This commit is contained in:
parent
e5d24ccb9e
commit
bbc74d93b0
12 changed files with 59 additions and 30 deletions
|
|
@ -2,13 +2,19 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use OOUI\CheckboxInputWidget;
|
||||
use OOUI\FieldLayout;
|
||||
use OOUI\HtmlSnippet;
|
||||
use OOUI\Tag;
|
||||
use OOUI\Widget;
|
||||
|
||||
/**
|
||||
* Check matrix widget. Displays a matrix of checkboxes for given options
|
||||
*
|
||||
* @copyright 2018 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class CheckMatrixWidget extends \OOUI\Widget {
|
||||
class CheckMatrixWidget extends Widget {
|
||||
/** @var string|null */
|
||||
protected $name;
|
||||
/** @var string|null */
|
||||
|
|
@ -69,23 +75,23 @@ class CheckMatrixWidget extends \OOUI\Widget {
|
|||
$this->forcedOff = $config['forcedOff'] ?? [];
|
||||
|
||||
// Build the table
|
||||
$table = new \OOUI\Tag( 'table' );
|
||||
$table = new Tag( 'table' );
|
||||
$table->addClasses( [ 'mw-htmlform-matrix mw-widget-checkMatrixWidget-matrix' ] );
|
||||
$thead = new \OOUI\Tag( 'thead' );
|
||||
$thead = new Tag( 'thead' );
|
||||
$table->appendContent( $thead );
|
||||
$tr = new \OOUI\Tag( 'tr' );
|
||||
$tr = new Tag( 'tr' );
|
||||
|
||||
// Build the header
|
||||
$tr->appendContent( $this->getCellTag( "\u{00A0}" ) );
|
||||
foreach ( $this->columns as $columnLabel => $columnTag ) {
|
||||
$tr->appendContent(
|
||||
$this->getCellTag( new \OOUI\HtmlSnippet( $columnLabel ), 'th' )
|
||||
$this->getCellTag( new HtmlSnippet( $columnLabel ), 'th' )
|
||||
);
|
||||
}
|
||||
$thead->appendContent( $tr );
|
||||
|
||||
// Build the options matrix
|
||||
$tbody = new \OOUI\Tag( 'tbody' );
|
||||
$tbody = new Tag( 'tbody' );
|
||||
$table->appendContent( $tbody );
|
||||
foreach ( $this->rows as $rowLabel => $rowTag ) {
|
||||
$tbody->appendContent(
|
||||
|
|
@ -104,17 +110,18 @@ class CheckMatrixWidget extends \OOUI\Widget {
|
|||
*
|
||||
* @param string $label Row label (as HTML)
|
||||
* @param string $tag Row tag name
|
||||
* @return \OOUI\Tag The resulting table row
|
||||
*
|
||||
* @return Tag The resulting table row
|
||||
*/
|
||||
private function getTableRow( $label, $tag ) {
|
||||
$row = new \OOUI\Tag( 'tr' );
|
||||
$row = new Tag( 'tr' );
|
||||
$tooltip = $this->getTooltip( $label );
|
||||
$labelFieldConfig = $tooltip ? [ 'help' => $tooltip ] : [];
|
||||
// Build label cell
|
||||
$labelField = new \OOUI\FieldLayout(
|
||||
new \OOUI\Widget(), // Empty widget, since we don't have the checkboxes here
|
||||
$labelField = new FieldLayout(
|
||||
new Widget(), // Empty widget, since we don't have the checkboxes here
|
||||
[
|
||||
'label' => new \OOUI\HtmlSnippet( $label ),
|
||||
'label' => new HtmlSnippet( $label ),
|
||||
'align' => 'inline',
|
||||
] + $labelFieldConfig
|
||||
);
|
||||
|
|
@ -125,7 +132,7 @@ class CheckMatrixWidget extends \OOUI\Widget {
|
|||
$thisTag = "$columnTag-$tag";
|
||||
|
||||
// Construct a checkbox
|
||||
$checkbox = new \OOUI\CheckboxInputWidget( [
|
||||
$checkbox = new CheckboxInputWidget( [
|
||||
'value' => $thisTag,
|
||||
'name' => $this->name ? "{$this->name}[]" : null,
|
||||
'id' => $this->id ? "{$this->id}-$thisTag" : null,
|
||||
|
|
@ -143,10 +150,10 @@ class CheckMatrixWidget extends \OOUI\Widget {
|
|||
*
|
||||
* @param mixed $content Content for the <td> cell
|
||||
* @param string $tagElement
|
||||
* @return \OOUI\Tag Resulting cell
|
||||
* @return Tag Resulting cell
|
||||
*/
|
||||
private function getCellTag( $content, $tagElement = 'td' ) {
|
||||
$cell = new \OOUI\Tag( $tagElement );
|
||||
$cell = new Tag( $tagElement );
|
||||
$cell->appendContent( $content );
|
||||
return $cell;
|
||||
}
|
||||
|
|
@ -186,11 +193,12 @@ class CheckMatrixWidget extends \OOUI\Widget {
|
|||
* Get the tooltip help associated with this row
|
||||
*
|
||||
* @param string $label Label name
|
||||
*
|
||||
* @return string Tooltip. Null if none is available.
|
||||
*/
|
||||
private function getTooltip( $label ) {
|
||||
if ( isset( $this->tooltipsHtml[ $label ] ) ) {
|
||||
return new \OOUI\HtmlSnippet( $this->tooltipsHtml[ $label ] );
|
||||
return new HtmlSnippet( $this->tooltipsHtml[ $label ] );
|
||||
} else {
|
||||
return $this->tooltips[ $label ] ?? null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
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 \OOUI\Widget {
|
||||
class ComplexTitleInputWidget extends Widget {
|
||||
/** @var array */
|
||||
protected $config;
|
||||
protected $namespace = null;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace MediaWiki\Widget;
|
||||
|
||||
use DateTime;
|
||||
use OOUI\TextInputWidget;
|
||||
|
||||
/**
|
||||
* Date input widget.
|
||||
|
|
@ -11,7 +12,7 @@ use DateTime;
|
|||
* @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class DateInputWidget extends \OOUI\TextInputWidget {
|
||||
class DateInputWidget extends TextInputWidget {
|
||||
|
||||
protected $inputFormat = null;
|
||||
protected $displayFormat = null;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OOUI\InputWidget;
|
||||
use OOUI\Tag;
|
||||
|
||||
/**
|
||||
|
|
@ -10,7 +12,7 @@ use OOUI\Tag;
|
|||
* @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class DateTimeInputWidget extends \OOUI\InputWidget {
|
||||
class DateTimeInputWidget extends InputWidget {
|
||||
|
||||
protected $type = null;
|
||||
protected $min = null;
|
||||
|
|
@ -27,7 +29,7 @@ class DateTimeInputWidget extends \OOUI\InputWidget {
|
|||
public function __construct( array $config = [] ) {
|
||||
// We need $this->type set before calling the parent constructor
|
||||
if ( !isset( $config['type'] ) ) {
|
||||
throw new \InvalidArgumentException( '$config[\'type\'] must be specified' );
|
||||
throw new InvalidArgumentException( '$config[\'type\'] must be specified' );
|
||||
}
|
||||
$this->type = $config['type'];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use MediaWiki\Html\Html;
|
||||
use OOUI\DropdownInputWidget;
|
||||
use OOUI\InputWidget;
|
||||
|
||||
/**
|
||||
* Namespace input widget. Displays a dropdown box with the choice of available namespaces.
|
||||
*
|
||||
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
||||
class NamespaceInputWidget extends DropdownInputWidget {
|
||||
/** @var string */
|
||||
protected $includeAllValue;
|
||||
/** @var bool */
|
||||
|
|
@ -44,7 +48,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
'in-user-lang' => $config['userLang'] ?? false,
|
||||
'exclude' => $config['exclude'] ?? null
|
||||
];
|
||||
$namespaceOptions = \MediaWiki\Html\Html::namespaceSelectorOptions( $namespaceOptionsParams );
|
||||
$namespaceOptions = Html::namespaceSelectorOptions( $namespaceOptionsParams );
|
||||
|
||||
$options = [];
|
||||
foreach ( $namespaceOptions as $id => $name ) {
|
||||
|
|
@ -67,6 +71,6 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
$config['exclude'] = $this->exclude;
|
||||
// Skip DropdownInputWidget's getConfig(), we don't need 'options' config
|
||||
$config['dropdown']['$overlay'] = true;
|
||||
return \OOUI\InputWidget::getConfig( $config );
|
||||
return InputWidget::getConfig( $config );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use OOUI\Tag;
|
||||
|
||||
/**
|
||||
* Search input widget.
|
||||
*
|
||||
|
|
@ -56,7 +58,7 @@ class SearchInputWidget extends TitleInputWidget {
|
|||
}
|
||||
|
||||
protected function getInputElement( $config ) {
|
||||
return ( new \OOUI\Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
|
||||
return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
|
||||
}
|
||||
|
||||
protected function getJavaScriptClassName() {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace MediaWiki\Widget;
|
|||
|
||||
use OOUI\DropdownInputWidget;
|
||||
use OOUI\TextInputWidget;
|
||||
use OOUI\Widget;
|
||||
|
||||
/**
|
||||
* Select and input widget.
|
||||
|
|
@ -11,7 +12,7 @@ use OOUI\TextInputWidget;
|
|||
* @copyright 2011-2017 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class SelectWithInputWidget extends \OOUI\Widget {
|
||||
class SelectWithInputWidget extends Widget {
|
||||
/** @var array */
|
||||
protected $config;
|
||||
/** @var TextInputWidget */
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace MediaWiki\Widget;
|
|||
use OOUI\LabelWidget;
|
||||
use OOUI\RadioSelectInputWidget;
|
||||
use OOUI\TextInputWidget;
|
||||
use OOUI\Widget;
|
||||
|
||||
/**
|
||||
* Select and input widget.
|
||||
|
|
@ -12,7 +13,7 @@ use OOUI\TextInputWidget;
|
|||
* @copyright 2011-2018 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class SizeFilterWidget extends \OOUI\Widget {
|
||||
class SizeFilterWidget extends Widget {
|
||||
/** @var array */
|
||||
protected $config;
|
||||
/** @var LabelWidget */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use Exception;
|
||||
use MediaWiki\Html\Html;
|
||||
|
||||
/**
|
||||
* PHP version of jquery.spinner.
|
||||
*
|
||||
|
|
@ -47,7 +50,7 @@ class SpinnerWidget {
|
|||
* @return string HTML serialization
|
||||
*/
|
||||
public function toString() {
|
||||
return \MediaWiki\Html\Html::rawElement( 'div', $this->attributes, $this->content );
|
||||
return Html::rawElement( 'div', $this->attributes, $this->content );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +63,7 @@ class SpinnerWidget {
|
|||
public function __toString() {
|
||||
try {
|
||||
return $this->toString();
|
||||
} catch ( \Exception $ex ) {
|
||||
} catch ( Exception $ex ) {
|
||||
trigger_error( (string)$ex, E_USER_ERROR );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace MediaWiki\Widget;
|
||||
|
||||
use OOUI\MultilineTextInputWidget;
|
||||
use OOUI\Widget;
|
||||
|
||||
/**
|
||||
* Base class for widgets to select multiple users, titles,
|
||||
|
|
@ -11,7 +12,7 @@ use OOUI\MultilineTextInputWidget;
|
|||
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class TagMultiselectWidget extends \OOUI\Widget {
|
||||
class TagMultiselectWidget extends Widget {
|
||||
/** @var array */
|
||||
protected $selectedArray;
|
||||
/** @var string|null */
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use OOUI\TextInputWidget;
|
||||
|
||||
/**
|
||||
* Title input widget.
|
||||
*
|
||||
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class TitleInputWidget extends \OOUI\TextInputWidget {
|
||||
class TitleInputWidget extends TextInputWidget {
|
||||
|
||||
protected $namespace = null;
|
||||
protected $relative = null;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
namespace MediaWiki\Widget;
|
||||
|
||||
use OOUI\TextInputWidget;
|
||||
|
||||
/**
|
||||
* User input widget.
|
||||
*
|
||||
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class UserInputWidget extends \OOUI\TextInputWidget {
|
||||
class UserInputWidget extends TextInputWidget {
|
||||
|
||||
/**
|
||||
* @param array $config Configuration options
|
||||
|
|
|
|||
Loading…
Reference in a new issue