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