MediaWiki  1.32.5
HTMLSelectField.php
Go to the documentation of this file.
1 <?php
2 
7  public function validate( $value, $alldata ) {
8  $p = parent::validate( $value, $alldata );
9 
10  if ( $p !== true ) {
11  return $p;
12  }
13 
14  $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
15 
16  if ( in_array( strval( $value ), $validOptions, true ) ) {
17  return true;
18  } else {
19  return $this->msg( 'htmlform-select-badoption' );
20  }
21  }
22 
23  public function getInputHTML( $value ) {
24  $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
25 
26  if ( !empty( $this->mParams['disabled'] ) ) {
27  $select->setAttribute( 'disabled', 'disabled' );
28  }
29 
30  $allowedParams = [ 'tabindex', 'size' ];
31  $customParams = $this->getAttributes( $allowedParams );
32  foreach ( $customParams as $name => $value ) {
33  $select->setAttribute( $name, $value );
34  }
35 
36  if ( $this->mClass !== '' ) {
37  $select->setAttribute( 'class', $this->mClass );
38  }
39 
40  $select->addOptions( $this->getOptions() );
41 
42  return $select->getHTML();
43  }
44 
45  public function getInputOOUI( $value ) {
46  $disabled = false;
47  $allowedParams = [ 'tabindex' ];
48  $attribs = OOUI\Element::configFromHtmlAttributes(
49  $this->getAttributes( $allowedParams )
50  );
51 
52  if ( $this->mClass !== '' ) {
53  $attribs['classes'] = [ $this->mClass ];
54  }
55 
56  if ( !empty( $this->mParams['disabled'] ) ) {
57  $disabled = true;
58  }
59 
60  return new OOUI\DropdownInputWidget( [
61  'name' => $this->mName,
62  'id' => $this->mID,
63  'options' => $this->getOptionsOOUI(),
64  'value' => strval( $value ),
65  'disabled' => $disabled,
66  ] + $attribs );
67  }
68 
69  protected function shouldInfuseOOUI() {
70  return true;
71  }
72 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:1100
HTMLSelectField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLSelectField.php:23
HTMLFormField\$mClass
$mClass
Definition: HTMLFormField.php:16
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
XmlSelect
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
HTMLSelectField\shouldInfuseOOUI
shouldInfuseOOUI()
Whether the field should be automatically infused.
Definition: HTMLSelectField.php:69
HTMLSelectField
A select dropdown field.
Definition: HTMLSelectField.php:6
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
$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:2044
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$value
$value
Definition: styleTest.css.php:49
HTMLSelectField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
Definition: HTMLSelectField.php:45
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:80
HTMLSelectField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLSelectField.php:7
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\flattenOptions
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
Definition: HTMLFormField.php:1139
HTMLFormField\getOptionsOOUI
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
Definition: HTMLFormField.php:1122
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:1044