Debian Codegraph @

includes/htmlform/fields/HTMLSelectNamespace.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\HTMLForm\Field;
4
5 use MediaWiki\Html\Html;
6 use MediaWiki\HTMLForm\HTMLFormField;
7
8 /**
9 * Wrapper for Html::namespaceSelector to use in HTMLForm
10 *
11 * @stable to extend
12 */
13 class HTMLSelectNamespace extends HTMLFormField {
14
15 /** @var string|null */
16 protected $mAllValue;
17 /** @var bool */
18 protected $mUserLang;
19
20 /**
21 * @stable to call
22 * @inheritDoc
23 */
24 public function __construct( $params ) {
25 parent::__construct( $params );
26
27 $this->mAllValue = array_key_exists( 'all', $params )
28 ? $params['all']
29 : 'all';
30 $this->mUserLang = array_key_exists( 'in-user-lang', $params )
31 ? $params['in-user-lang']
32 : false;
33 }
34
35 /**
36 * @inheritDoc
37 * @stable to override
38 */
39 public function getInputHTML( $value ) {
40 return Html::namespaceSelector(
41 [
42 'selected' => $value,
43 'all' => $this->mAllValue,
44 'in-user-lang' => $this->mUserLang,
45 ], [
46 'name' => $this->mName,
47 'id' => $this->mID,
48 'class' => 'namespaceselector',
49 ]
50 );
51 }
52
53 /**
54 * @inheritDoc
55 * @stable to override
56 */
57 public function getInputOOUI( $value ) {
58 return new \MediaWiki\Widget\NamespaceInputWidget( [
59 'value' => $value,
60 'name' => $this->mName,
61 'id' => $this->mID,
62 'includeAllValue' => $this->mAllValue,
63 'userLang' => $this->mUserLang,
64 ] );
65 }
66
67 /**
68 * @inheritDoc
69 * @stable to override
70 */
71 public function getInputCodex( $value, $hasErrors ) {
72 $optionParams = [
73 'all' => $this->mAllValue,
74 'in-user-lang' => $this->mUserLang
75 ];
76 $select = new HTMLSelectField( [
77 'options' => array_flip( Html::namespaceSelectorOptions( $optionParams ) )
78 ] + $this->mParams );
79 return $select->getInputCodex( $value, $hasErrors );
80 }
81
82 /**
83 * @inheritDoc
84 * @stable to override
85 */
86 protected function getOOUIModules() {
87 // FIXME: NamespaceInputWidget should be in its own module (probably?)
88 return [ 'mediawiki.widgets' ];
89 }
90
91 /**
92 * @inheritDoc
93 * @stable to override
94 */
95 protected function shouldInfuseOOUI() {
96 return true;
97 }
98 }
99
100 /** @deprecated class alias since 1.42 */
101 class_alias( HTMLSelectNamespace::class, 'HTMLSelectNamespace' );