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