This is not really what we had in mind when developing the infusion feature and I think it's not helpful. Most of the time there is just no benefit; a ButtonWidget generated in PHP and in JS behaves and looks pretty much the same, and rebuilding it through infusion is a small performance hit. If you're not adding any event handlers, it only makes sense for various dropdowns, which have themed styling. For the primary use case of adding JS behaviors to PHP widgets you need to call OO.ui.infuse() anyway to get a reference to the JS widget, and not infusing automatically should make it easier to reason about your code. Infusion tries to be very transparent, but it can't hide the fact that the DOM is re-built, making your references to DOM nodes from before infusion useless and losing anything from PHP that wasn't included in the config (e.g. custom attributes). This commit removes automated infusion from mediawiki.page.ready and adds some custom code in mediawiki.special.movePage and mediawiki.htmlform. I see only two extensions using infusable OOjs UI widgets in Gerrit (ArticlePlaceholder and ExtensionDistributor) and neither should be affected by this change. Change-Id: I56608c537fc57c5c54960b0603694f2612f45618
72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* A select dropdown field. Basically a wrapper for Xmlselect class
|
|
*/
|
|
class HTMLSelectField extends HTMLFormField {
|
|
function validate( $value, $alldata ) {
|
|
$p = parent::validate( $value, $alldata );
|
|
|
|
if ( $p !== true ) {
|
|
return $p;
|
|
}
|
|
|
|
$validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
|
|
|
|
if ( in_array( strval( $value ), $validOptions, true ) ) {
|
|
return true;
|
|
} else {
|
|
return $this->msg( 'htmlform-select-badoption' )->parse();
|
|
}
|
|
}
|
|
|
|
function getInputHTML( $value ) {
|
|
$select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
|
|
|
|
if ( !empty( $this->mParams['disabled'] ) ) {
|
|
$select->setAttribute( 'disabled', 'disabled' );
|
|
}
|
|
|
|
$allowedParams = [ 'tabindex', 'size' ];
|
|
$customParams = $this->getAttributes( $allowedParams );
|
|
foreach ( $customParams as $name => $value ) {
|
|
$select->setAttribute( $name, $value );
|
|
}
|
|
|
|
if ( $this->mClass !== '' ) {
|
|
$select->setAttribute( 'class', $this->mClass );
|
|
}
|
|
|
|
$select->addOptions( $this->getOptions() );
|
|
|
|
return $select->getHTML();
|
|
}
|
|
|
|
function getInputOOUI( $value ) {
|
|
$disabled = false;
|
|
$allowedParams = [ 'tabindex' ];
|
|
$attribs = OOUI\Element::configFromHtmlAttributes(
|
|
$this->getAttributes( $allowedParams )
|
|
);
|
|
|
|
if ( $this->mClass !== '' ) {
|
|
$attribs['classes'] = [ $this->mClass ];
|
|
}
|
|
|
|
if ( !empty( $this->mParams['disabled'] ) ) {
|
|
$disabled = true;
|
|
}
|
|
|
|
return new OOUI\DropdownInputWidget( [
|
|
'name' => $this->mName,
|
|
'id' => $this->mID,
|
|
'options' => $this->getOptionsOOUI(),
|
|
'value' => strval( $value ),
|
|
'disabled' => $disabled,
|
|
] + $attribs );
|
|
}
|
|
|
|
protected function shouldInfuseOOUI() {
|
|
return true;
|
|
}
|
|
}
|