MediaWiki  1.23.8
HTMLMultiSelectField.php
Go to the documentation of this file.
1 <?php
2 
7  function validate( $value, $alldata ) {
8  $p = parent::validate( $value, $alldata );
9 
10  if ( $p !== true ) {
11  return $p;
12  }
13 
14  if ( !is_array( $value ) ) {
15  return false;
16  }
17 
18  # If all options are valid, array_intersect of the valid options
19  # and the provided options will return the provided options.
20  $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
21 
22  $validValues = array_intersect( $value, $validOptions );
23  if ( count( $validValues ) == count( $value ) ) {
24  return true;
25  } else {
26  return $this->msg( 'htmlform-select-badoption' )->parse();
27  }
28  }
29 
30  function getInputHTML( $value ) {
32  $html = $this->formatOptions( $this->getOptions(), $value );
33 
34  return $html;
35  }
36 
37  function formatOptions( $options, $value ) {
38  $html = '';
39 
40  $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
41  $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
42 
43  foreach ( $options as $label => $info ) {
44  if ( is_array( $info ) ) {
45  $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
46  $html .= $this->formatOptions( $info, $value );
47  } else {
48  $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
49 
50  $checkbox = Xml::check(
51  $this->mName . '[]',
52  in_array( $info, $value, true ),
53  $attribs + $thisAttribs
54  );
55  $checkbox .= '&#160;' . call_user_func( $elementFunc,
56  'label',
57  array( 'for' => "{$this->mID}-$info" ),
58  $label
59  );
60 
61  $html .= ' ' . Html::rawElement(
62  'div',
63  array( 'class' => 'mw-htmlform-flatlist-item' ),
64  $checkbox
65  );
66  }
67  }
68 
69  return $html;
70  }
71 
77  function loadDataFromRequest( $request ) {
78  if ( $this->mParent->getMethod() == 'post' ) {
79  if ( $request->wasPosted() ) {
80  # Checkboxes are just not added to the request arrays if they're not checked,
81  # so it's perfectly possible for there not to be an entry at all
82  return $request->getArray( $this->mName, array() );
83  } else {
84  # That's ok, the user has not yet submitted the form, so show the defaults
85  return $this->getDefault();
86  }
87  } else {
88  # This is the impossible case: if we look at $_GET and see no data for our
89  # field, is it because the user has not yet submitted the form, or that they
90  # have submitted it with all the options unchecked? We will have to assume the
91  # latter, which basically means that you can't specify 'positive' defaults
92  # for GET forms.
93  # @todo FIXME...
94  return $request->getArray( $this->mName, array() );
95  }
96  }
97 
98  function getDefault() {
99  if ( isset( $this->mDefault ) ) {
100  return $this->mDefault;
101  } else {
102  return array();
103  }
104  }
105 
106  function filterDataForSubmit( $data ) {
107  $data = HTMLFormField::forceToStringRecursive( $data );
109 
110  $res = array();
111  foreach ( $options as $opt ) {
112  $res["$opt"] = in_array( $opt, $data, true );
113  }
114 
115  return $res;
116  }
117 
118  protected function needsLabel() {
119  return false;
120  }
121 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:550
HTMLMultiSelectField\loadDataFromRequest
loadDataFromRequest( $request)
Definition: HTMLMultiSelectField.php:77
HTMLMultiSelectField\needsLabel
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
Definition: HTMLMultiSelectField.php:118
HTMLMultiSelectField\getDefault
getDefault()
Definition: HTMLMultiSelectField.php:98
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
HTMLMultiSelectField\filterDataForSubmit
filterDataForSubmit( $data)
Support for seperating multi-option preferences into multiple preferences Due to lack of array suppor...
Definition: HTMLMultiSelectField.php:106
HTMLMultiSelectField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLMultiSelectField.php:7
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
HTMLFormField\$mDefault
$mDefault
Definition: HTMLFormField.php:16
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
$value
$value
Definition: styleTest.css.php:45
Xml\check
static check( $name, $checked=false, $attribs=array())
Convenience function to build an HTML checkbox.
Definition: Xml.php:339
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:51
HTMLMultiSelectField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLMultiSelectField.php:30
HTMLNestedFilterable
Definition: HTMLNestedFilterable.php:3
HTMLMultiSelectField
Multi-select field.
Definition: HTMLMultiSelectField.php:6
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
HTMLFormField\forceToStringRecursive
static forceToStringRecursive( $array)
Recursively forces values in an array to strings, because issues arise with integer 0 as a value.
Definition: HTMLFormField.php:536
HTMLMultiSelectField\formatOptions
formatOptions( $options, $value)
Definition: HTMLMultiSelectField.php:37
HTMLFormField\flattenOptions
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
Definition: HTMLFormField.php:601
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
$res
$res
Definition: database.txt:21
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:493