Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLSelectNamespace.php
blobee2ec9953f1592e325f3df49b6e0ca9fa80464f9
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\Html\Html;
6 use MediaWiki\HTMLForm\HTMLFormField;
8 /**
9 * Wrapper for Html::namespaceSelector to use in HTMLForm
11 * @stable to extend
13 class HTMLSelectNamespace extends HTMLFormField {
15 /** @var string|null */
16 protected $mAllValue;
17 /** @var bool */
18 protected $mUserLang;
19 /** @var int[]|null */
20 protected $mInclude;
22 /**
23 * @stable to call
24 * @inheritDoc
26 public function __construct( $params ) {
27 parent::__construct( $params );
29 $this->mAllValue = array_key_exists( 'all', $params )
30 ? $params['all']
31 : 'all';
32 $this->mUserLang = array_key_exists( 'in-user-lang', $params )
33 ? $params['in-user-lang']
34 : false;
36 $this->mInclude = array_key_exists( 'include', $params )
37 ? $params['include']
38 : null;
41 /**
42 * @inheritDoc
43 * @stable to override
45 public function getInputHTML( $value ) {
46 return Html::namespaceSelector(
48 'selected' => $value,
49 'all' => $this->mAllValue,
50 'in-user-lang' => $this->mUserLang,
51 'include' => $this->mInclude
52 ], [
53 'name' => $this->mName,
54 'id' => $this->mID,
55 'class' => 'namespaceselector',
60 /**
61 * @inheritDoc
62 * @stable to override
64 public function getInputOOUI( $value ) {
65 return new \MediaWiki\Widget\NamespaceInputWidget( [
66 'value' => $value,
67 'name' => $this->mName,
68 'id' => $this->mID,
69 'includeAllValue' => $this->mAllValue,
70 'userLang' => $this->mUserLang,
71 'include' => $this->mInclude,
72 ] );
75 /**
76 * @inheritDoc
77 * @stable to override
79 public function getInputCodex( $value, $hasErrors ) {
80 $optionParams = [
81 'all' => $this->mAllValue,
82 'in-user-lang' => $this->mUserLang
84 $select = new HTMLSelectField( [
85 'options' => array_flip( Html::namespaceSelectorOptions( $optionParams ) )
86 ] + $this->mParams );
87 return $select->getInputCodex( $value, $hasErrors );
90 /**
91 * @inheritDoc
92 * @stable to override
94 protected function getOOUIModules() {
95 // FIXME: NamespaceInputWidget should be in its own module (probably?)
96 return [ 'mediawiki.widgets' ];
99 /**
100 * @inheritDoc
101 * @stable to override
103 protected function shouldInfuseOOUI() {
104 return true;
108 /** @deprecated class alias since 1.42 */
109 class_alias( HTMLSelectNamespace::class, 'HTMLSelectNamespace' );