MediaWiki REL1_33
HTMLNamespacesMultiselectField.php
Go to the documentation of this file.
1<?php
2
4
17 public function loadDataFromRequest( $request ) {
18 $value = $request->getText( $this->mName, $this->getDefault() );
19
20 $namespaces = explode( "\n", $value );
21 // Remove empty lines
22 $namespaces = array_values( array_filter( $namespaces, function ( $namespace ) {
23 return trim( $namespace ) !== '';
24 } ) );
25 // This function is expected to return a string
26 return implode( "\n", $namespaces );
27 }
28
29 public function validate( $value, $alldata ) {
30 if ( !$this->mParams['exists'] ) {
31 return true;
32 }
33
34 if ( is_null( $value ) ) {
35 return false;
36 }
37
38 // $value is a string, because HTMLForm fields store their values as strings
39 $namespaces = explode( "\n", $value );
40
41 if ( isset( $this->mParams['max'] ) && ( count( $namespaces ) > $this->mParams['max'] ) ) {
42 return $this->msg( 'htmlform-int-toohigh', $this->mParams['max'] );
43 }
44
45 foreach ( $namespaces as $namespace ) {
46 if ( $namespace < 0 ) {
47 return $this->msg( 'htmlform-select-badoption' );
48 }
49
50 $result = parent::validate( $namespace, $alldata );
51 if ( $result !== true ) {
52 return $result;
53 }
54 }
55
56 return true;
57 }
58
59 public function getInputHTML( $value ) {
60 $this->mParent->getOutput()->enableOOUI();
61 return $this->getInputOOUI( $value );
62 }
63
64 public function getInputOOUI( $value ) {
65 $params = [
66 'id' => $this->mID,
67 'name' => $this->mName,
68 'dir' => $this->mDir,
69 ];
70
71 if ( isset( $this->mParams['disabled'] ) ) {
72 $params['disabled'] = $this->mParams['disabled'];
73 }
74
75 if ( isset( $this->mParams['default'] ) ) {
76 $params['default'] = $this->mParams['default'];
77 }
78
79 if ( isset( $this->mParams['placeholder'] ) ) {
80 $params['placeholder'] = $this->mParams['placeholder'];
81 } else {
82 $params['placeholder'] = $this->msg( 'mw-widgets-titlesmultiselect-placeholder' )->plain();
83 }
84
85 if ( isset( $this->mParams['max'] ) ) {
86 $params['tagLimit'] = $this->mParams['max'];
87 }
88
89 if ( isset( $this->mParams['input'] ) ) {
90 $params['input'] = $this->mParams['input'];
91 }
92
93 if ( !is_null( $value ) ) {
94 // $value is a string, but the widget expects an array
95 $params['default'] = $value === '' ? [] : explode( "\n", $value );
96 }
97
98 // Make the field auto-infusable when it's used inside a legacy HTMLForm rather than OOUIHTMLForm
99 $params['infusable'] = true;
100 $params['classes'] = [ 'mw-htmlform-field-autoinfuse' ];
101 $widget = new NamespacesMultiselectWidget( $params );
102 $widget->setAttributes( [ 'data-mw-modules' => implode( ',', $this->getOOUIModules() ) ] );
103
104 return $widget;
105 }
106
107 protected function shouldInfuseOOUI() {
108 return true;
109 }
110
111 protected function getOOUIModules() {
112 return [ 'mediawiki.widgets.NamespacesMultiselectWidget' ];
113 }
114
115}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
msg()
Get a translated interface message.
Implements a tag multiselect input field for namespaces.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
shouldInfuseOOUI()
Whether the field should be automatically infused.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
Wrapper for Html::namespaceSelector to use in HTMLForm.
namespace being checked & $result
Definition hooks.txt:2340
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2843
namespace and then decline to actually register it & $namespaces
Definition hooks.txt:925
$params