2017-01-08 02:37:29 +00:00
|
|
|
<?php
|
2017-12-28 15:17:33 +00:00
|
|
|
|
2017-01-08 02:37:29 +00:00
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2017-12-28 15:17:33 +00:00
|
|
|
use OOUI\MultilineTextInputWidget;
|
2017-01-08 02:37:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Widget to select multiple users.
|
2017-12-28 15:17:33 +00:00
|
|
|
*
|
|
|
|
|
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
* @license MIT
|
2017-01-08 02:37:29 +00:00
|
|
|
*/
|
|
|
|
|
class UsersMultiselectWidget extends \OOUI\Widget {
|
|
|
|
|
|
|
|
|
|
protected $usersArray = [];
|
|
|
|
|
protected $inputName = null;
|
|
|
|
|
protected $inputPlaceholder = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $config Configuration options
|
2018-01-07 10:38:43 +00:00
|
|
|
* - array $config['users'] Array of usernames to use as preset data
|
|
|
|
|
* - array $config['placeholder'] Placeholder message for input
|
|
|
|
|
* - array $config['name'] Name attribute (used in forms)
|
2017-01-08 02:37:29 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( array $config = [] ) {
|
|
|
|
|
parent::__construct( $config );
|
|
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
|
if ( isset( $config['default'] ) ) {
|
|
|
|
|
$this->usersArray = $config['default'];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $config['name'] ) ) {
|
|
|
|
|
$this->inputName = $config['name'];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $config['placeholder'] ) ) {
|
|
|
|
|
$this->inputPlaceholder = $config['placeholder'];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 21:36:40 +00:00
|
|
|
$textarea = new MultilineTextInputWidget( [
|
2017-01-08 02:37:29 +00:00
|
|
|
'name' => $this->inputName,
|
|
|
|
|
'value' => implode( "\n", $this->usersArray ),
|
|
|
|
|
'rows' => 25,
|
|
|
|
|
] );
|
|
|
|
|
$this->prependContent( $textarea );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getJavaScriptClassName() {
|
|
|
|
|
return 'mw.widgets.UsersMultiselectWidget';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getConfig( &$config ) {
|
|
|
|
|
if ( $this->usersArray !== null ) {
|
2017-06-09 02:13:45 +00:00
|
|
|
$config['selected'] = $this->usersArray;
|
2017-01-08 02:37:29 +00:00
|
|
|
}
|
|
|
|
|
if ( $this->inputName !== null ) {
|
|
|
|
|
$config['name'] = $this->inputName;
|
|
|
|
|
}
|
|
|
|
|
if ( $this->inputPlaceholder !== null ) {
|
|
|
|
|
$config['placeholder'] = $this->inputPlaceholder;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 22:25:01 +00:00
|
|
|
$config['$overlay'] = true;
|
2017-01-08 02:37:29 +00:00
|
|
|
return parent::getConfig( $config );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|