MediaWiki
REL1_35
HTMLTitlesMultiselectField.php
Go to the documentation of this file.
1
<?php
2
3
use
MediaWiki\Widget\TitlesMultiselectWidget
;
4
23
class
HTMLTitlesMultiselectField
extends
HTMLTitleTextField
{
24
/*
25
* @stable to call
26
*/
27
public
function
__construct
( $params ) {
28
$params += [
29
// This overrides the default from HTMLTitleTextField
30
'required'
=>
false
,
31
];
32
33
parent::__construct( $params );
34
}
35
36
public
function
loadDataFromRequest
( $request ) {
37
$value = $request->getText( $this->mName, $this->
getDefault
() ??
''
);
38
39
$titlesArray = explode(
"\n"
, $value );
40
// Remove empty lines
41
$titlesArray = array_values( array_filter( $titlesArray,
function
(
$title
) {
42
return
trim(
$title
) !==
''
;
43
} ) );
44
// This function is expected to return a string
45
return
implode(
"\n"
, $titlesArray );
46
}
47
48
public
function
validate
( $value, $alldata ) {
49
if
( !$this->mParams[
'exists'
] ) {
50
return
true
;
51
}
52
53
if
( $value ===
null
) {
54
return
false
;
55
}
56
57
// $value is a string, because HTMLForm fields store their values as strings
58
$titlesArray = explode(
"\n"
, $value );
59
60
if
( isset( $this->mParams[
'max'
] ) && ( count( $titlesArray ) > $this->mParams[
'max'
] ) ) {
61
return
$this->
msg
(
'htmlform-multiselect-toomany'
, $this->mParams[
'max'
] );
62
}
63
64
foreach
( $titlesArray as
$title
) {
65
$result = parent::validate(
$title
, $alldata );
66
if
( $result !==
true
) {
67
return
$result;
68
}
69
}
70
71
return
true
;
72
}
73
74
public
function
getInputHTML
( $value ) {
75
$this->mParent->getOutput()->enableOOUI();
76
return
$this->
getInputOOUI
( $value );
77
}
78
79
public
function
getInputOOUI
( $value ) {
80
$params = [
81
'id'
=>
$this->mID
,
82
'name'
=>
$this->mName
,
83
'dir'
=>
$this->mDir
,
84
];
85
86
if
( isset( $this->mParams[
'disabled'
] ) ) {
87
$params[
'disabled'
] = $this->mParams[
'disabled'
];
88
}
89
90
if
( isset( $this->mParams[
'default'
] ) ) {
91
$params[
'default'
] = $this->mParams[
'default'
];
92
}
93
94
if
( isset( $this->mParams[
'placeholder'
] ) ) {
95
$params[
'placeholder'
] = $this->mParams[
'placeholder'
];
96
}
else
{
97
$params[
'placeholder'
] = $this->
msg
(
'mw-widgets-titlesmultiselect-placeholder'
)->plain();
98
}
99
100
if
( isset( $this->mParams[
'max'
] ) ) {
101
$params[
'tagLimit'
] = $this->mParams[
'max'
];
102
}
103
104
if
( isset( $this->mParams[
'showMissing'
] ) ) {
105
$params[
'showMissing'
] = $this->mParams[
'showMissing'
];
106
}
107
if
( isset( $this->mParams[
'excludeDynamicNamespaces'
] ) ) {
108
$params[
'excludeDynamicNamespaces'
] = $this->mParams[
'excludeDynamicNamespaces'
];
109
}
110
111
if
( isset( $this->mParams[
'input'
] ) ) {
112
$params[
'input'
] = $this->mParams[
'input'
];
113
}
114
115
if
( $value !==
null
) {
116
// $value is a string, but the widget expects an array
117
$params[
'default'
] = $value ===
''
? [] : explode(
"\n"
, $value );
118
}
119
120
// Make the field auto-infusable when it's used inside a legacy HTMLForm rather than OOUIHTMLForm
121
$params[
'infusable'
] =
true
;
122
$params[
'classes'
] = [
'mw-htmlform-field-autoinfuse'
];
123
$widget =
new
TitlesMultiselectWidget
( $params );
124
$widget->setAttributes( [
'data-mw-modules'
=> implode(
','
, $this->
getOOUIModules
() ) ] );
125
126
return
$widget;
127
}
128
129
protected
function
shouldInfuseOOUI
() {
130
return
true
;
131
}
132
133
protected
function
getOOUIModules
() {
134
return
[
'mediawiki.widgets.TitlesMultiselectWidget'
];
135
}
136
137
}
HTMLFormField\$mID
$mID
Definition
HTMLFormField.php:18
HTMLFormField\$mDir
$mDir
Definition
HTMLFormField.php:16
HTMLFormField\$mName
$mName
Definition
HTMLFormField.php:15
HTMLFormField\msg
msg( $key,... $params)
Get a translated interface message.
Definition
HTMLFormField.php:87
HTMLFormField\getDefault
getDefault()
Stable to override.
Definition
HTMLFormField.php:1011
HTMLTitleTextField
Implements a text input field for page titles.
Definition
HTMLTitleTextField.php:19
HTMLTitlesMultiselectField
Implements a tag multiselect input field for titles.
Definition
HTMLTitlesMultiselectField.php:23
HTMLTitlesMultiselectField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition
HTMLTitlesMultiselectField.php:48
HTMLTitlesMultiselectField\loadDataFromRequest
loadDataFromRequest( $request)
Get the value that this input has been set to from a posted form, or the input's default value if it ...
Definition
HTMLTitlesMultiselectField.php:36
HTMLTitlesMultiselectField\__construct
__construct( $params)
Stable to call.
Definition
HTMLTitlesMultiselectField.php:27
HTMLTitlesMultiselectField\shouldInfuseOOUI
shouldInfuseOOUI()
Whether the field should be automatically infused.
Definition
HTMLTitlesMultiselectField.php:129
HTMLTitlesMultiselectField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
Definition
HTMLTitlesMultiselectField.php:79
HTMLTitlesMultiselectField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
Definition
HTMLTitlesMultiselectField.php:74
HTMLTitlesMultiselectField\getOOUIModules
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
Definition
HTMLTitlesMultiselectField.php:133
MediaWiki\Widget\TitlesMultiselectWidget
Widget to select multiple titles.
Definition
TitlesMultiselectWidget.php:11
$title
$title
Definition
testCompression.php:38
includes
htmlform
fields
HTMLTitlesMultiselectField.php
Generated on Sat Apr 6 2024 00:07:16 for MediaWiki by
1.9.8