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
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Widget\UserInputWidget;
|
|
|
|
/**
|
|
* Implements a text input field for user names.
|
|
* Automatically auto-completes if using the OOUI display format.
|
|
*
|
|
* FIXME: Does not work for forms that support GET requests.
|
|
*
|
|
* Optional parameters:
|
|
* 'exists' - Whether to validate that the user already exists
|
|
*
|
|
* @since 1.26
|
|
*/
|
|
class HTMLUserTextField extends HTMLTextField {
|
|
public function __construct( $params ) {
|
|
$params += [
|
|
'exists' => false,
|
|
'ipallowed' => false,
|
|
];
|
|
|
|
parent::__construct( $params );
|
|
}
|
|
|
|
public function validate( $value, $alldata ) {
|
|
// check, if a user exists with the given username
|
|
$user = User::newFromName( $value, false );
|
|
|
|
if ( !$user ) {
|
|
return $this->msg( 'htmlform-user-not-valid', $value )->parse();
|
|
} elseif (
|
|
( $this->mParams['exists'] && $user->getId() === 0 ) &&
|
|
!( $this->mParams['ipallowed'] && User::isIP( $value ) )
|
|
) {
|
|
return $this->msg( 'htmlform-user-not-exists', $user->getName() )->parse();
|
|
}
|
|
|
|
return parent::validate( $value, $alldata );
|
|
}
|
|
|
|
protected function getInputWidget( $params ) {
|
|
$this->mParent->getOutput()->addModules( 'mediawiki.widgets.UserInputWidget' );
|
|
|
|
return new UserInputWidget( $params );
|
|
}
|
|
|
|
protected function shouldInfuseOOUI() {
|
|
return true;
|
|
}
|
|
|
|
public function getInputHtml( $value ) {
|
|
// add the required module and css class for user suggestions in non-OOUI mode
|
|
$this->mParent->getOutput()->addModules( 'mediawiki.userSuggest' );
|
|
$this->mClass .= ' mw-autocomplete-user';
|
|
|
|
// return parent html
|
|
return parent::getInputHTML( $value );
|
|
}
|
|
}
|