Support namespace dropdown 'in-user-lang' option in HTMLForm and OOUI widget
Change-Id: I3dbb2ec9d3989a1278151090ad81c7fabd3afbde
This commit is contained in:
parent
89dbd94991
commit
fd5357d049
5 changed files with 48 additions and 13 deletions
|
|
@ -8,6 +8,8 @@ class HTMLSelectNamespace extends HTMLFormField {
|
|||
|
||||
/** @var string|null */
|
||||
protected $mAllValue;
|
||||
/** @var bool */
|
||||
protected $mUserLang;
|
||||
|
||||
/**
|
||||
* @stable to call
|
||||
|
|
@ -19,6 +21,9 @@ class HTMLSelectNamespace extends HTMLFormField {
|
|||
$this->mAllValue = array_key_exists( 'all', $params )
|
||||
? $params['all']
|
||||
: 'all';
|
||||
$this->mUserLang = array_key_exists( 'in-user-lang', $params )
|
||||
? $params['in-user-lang']
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +34,8 @@ class HTMLSelectNamespace extends HTMLFormField {
|
|||
return Html::namespaceSelector(
|
||||
[
|
||||
'selected' => $value,
|
||||
'all' => $this->mAllValue
|
||||
'all' => $this->mAllValue,
|
||||
'in-user-lang' => $this->mUserLang,
|
||||
], [
|
||||
'name' => $this->mName,
|
||||
'id' => $this->mID,
|
||||
|
|
@ -48,6 +54,7 @@ class HTMLSelectNamespace extends HTMLFormField {
|
|||
'name' => $this->mName,
|
||||
'id' => $this->mID,
|
||||
'includeAllValue' => $this->mAllValue,
|
||||
'userLang' => $this->mUserLang,
|
||||
] );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ namespace MediaWiki\Widget;
|
|||
class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
||||
/** @var string */
|
||||
protected $includeAllValue;
|
||||
/** @var bool */
|
||||
protected $userLang;
|
||||
/** @var int[] */
|
||||
protected $exclude;
|
||||
|
||||
|
|
@ -18,6 +20,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
* @param array $config Configuration options
|
||||
* - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
|
||||
* namespace dropdown, and use this as the input value for it
|
||||
* - bool $config['userLang'] Display namespaces in user language
|
||||
* - int[] $config['exclude'] List of namespace numbers to exclude from the selector
|
||||
*/
|
||||
public function __construct( array $config = [] ) {
|
||||
|
|
@ -28,6 +31,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
|
||||
// Properties
|
||||
$this->includeAllValue = $config['includeAllValue'] ?? null;
|
||||
$this->userLang = $config['userLang'] ?? false;
|
||||
$this->exclude = $config['exclude'] ?? [];
|
||||
|
||||
// Initialization
|
||||
|
|
@ -37,6 +41,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
protected function getNamespaceDropdownOptions( array $config ) {
|
||||
$namespaceOptionsParams = [
|
||||
'all' => $config['includeAllValue'] ?? null,
|
||||
'in-user-lang' => $config['userLang'] ?? false,
|
||||
'exclude' => $config['exclude'] ?? null
|
||||
];
|
||||
$namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
|
||||
|
|
@ -58,6 +63,7 @@ class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
|
|||
|
||||
public function getConfig( &$config ) {
|
||||
$config['includeAllValue'] = $this->includeAllValue;
|
||||
$config['userLang'] = $this->userLang;
|
||||
$config['exclude'] = $this->exclude;
|
||||
// Skip DropdownInputWidget's getConfig(), we don't need 'options' config
|
||||
$config['dropdown']['$overlay'] = true;
|
||||
|
|
|
|||
|
|
@ -2523,22 +2523,31 @@ return [
|
|||
],
|
||||
|
||||
'mediawiki.widgets' => [
|
||||
'scripts' => [
|
||||
'resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.ComplexNamespaceInputWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.TitleInputWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.ComplexTitleInputWidget.js',
|
||||
'resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js',
|
||||
'localBasePath' => "$wgBaseDirectory/resources/src/mediawiki.widgets",
|
||||
'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.widgets",
|
||||
'packageFiles' => [
|
||||
'index.js',
|
||||
[ 'name' => 'data.json', 'callback' => static function ( MessageLocalizer $messageLocalizer ) {
|
||||
$userLang = $messageLocalizer->msg( 'unused' )->getLanguage();
|
||||
return [
|
||||
'formattedNamespaces' => $userLang->getFormattedNamespaces(),
|
||||
];
|
||||
} ],
|
||||
'mw.widgets.NamespaceInputWidget.js',
|
||||
'mw.widgets.ComplexNamespaceInputWidget.js',
|
||||
'mw.widgets.CopyTextLayout.js',
|
||||
'mw.widgets.TitleWidget.js',
|
||||
'mw.widgets.TitleInputWidget.js',
|
||||
'mw.widgets.TitleSearchWidget.js',
|
||||
'mw.widgets.ComplexTitleInputWidget.js',
|
||||
'mw.widgets.TitleOptionWidget.js',
|
||||
],
|
||||
'styles' => [
|
||||
'resources/src/mediawiki.widgets/mw.widgets.CopyTextLayout.css',
|
||||
'mw.widgets.CopyTextLayout.css',
|
||||
],
|
||||
'skinStyles' => [
|
||||
'default' => [
|
||||
'resources/src/mediawiki.widgets/mw.widgets.TitleWidget.less',
|
||||
'mw.widgets.TitleWidget.less',
|
||||
],
|
||||
],
|
||||
'dependencies' => [
|
||||
|
|
|
|||
8
resources/src/mediawiki.widgets/index.js
Normal file
8
resources/src/mediawiki.widgets/index.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
require( './mw.widgets.NamespaceInputWidget.js' );
|
||||
require( './mw.widgets.ComplexNamespaceInputWidget.js' );
|
||||
require( './mw.widgets.CopyTextLayout.js' );
|
||||
require( './mw.widgets.TitleWidget.js' );
|
||||
require( './mw.widgets.TitleInputWidget.js' );
|
||||
require( './mw.widgets.TitleSearchWidget.js' );
|
||||
require( './mw.widgets.ComplexTitleInputWidget.js' );
|
||||
require( './mw.widgets.TitleOptionWidget.js' );
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
* @cfg {string|null} [includeAllValue] Value for "all namespaces" option, if any
|
||||
* @cfg {boolean} [userLang=false] Display namespaces in user language
|
||||
* @cfg {number[]} [exclude] List of namespace numbers to exclude from the selector
|
||||
*/
|
||||
mw.widgets.NamespaceInputWidget = function MwWidgetsNamespaceInputWidget( config ) {
|
||||
|
|
@ -45,8 +46,12 @@
|
|||
exclude = config.exclude || [],
|
||||
mainNamespace = mw.config.get( 'wgNamespaceIds' )[ '' ];
|
||||
|
||||
var namespaces = config.userLang ?
|
||||
require( './data.json' ).formattedNamespaces :
|
||||
mw.config.get( 'wgFormattedNamespaces' );
|
||||
|
||||
// eslint-disable-next-line no-jquery/no-map-util
|
||||
options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
|
||||
options = $.map( namespaces, function ( name, ns ) {
|
||||
if ( ns < mainNamespace || exclude.indexOf( Number( ns ) ) !== -1 ) {
|
||||
return null; // skip
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue