MediaWiki  1.29.2
HTMLSelectOrOtherField.php
Go to the documentation of this file.
1 <?php
2 
10  public function __construct( $params ) {
11  parent::__construct( $params );
12  $this->getOptions();
13  if ( !in_array( 'other', $this->mOptions, true ) ) {
14  $msg =
15  isset( $params['other'] )
16  ? $params['other']
17  : wfMessage( 'htmlform-selectorother-other' )->text();
18  // Have 'other' always as first element
19  $this->mOptions = [ $msg => 'other' ] + $this->mOptions;
20  }
21  }
22 
23  public function getInputHTML( $value ) {
24  $valInSelect = false;
25 
26  if ( $value !== false ) {
27  $value = strval( $value );
28  $valInSelect = in_array(
30  );
31  }
32 
33  $selected = $valInSelect ? $value : 'other';
34 
35  $select = new XmlSelect( $this->mName, $this->mID, $selected );
36  $select->addOptions( $this->getOptions() );
37 
38  $select->setAttribute( 'class', 'mw-htmlform-select-or-other' );
39 
40  $tbAttribs = [ 'id' => $this->mID . '-other', 'size' => $this->getSize() ];
41 
42  if ( !empty( $this->mParams['disabled'] ) ) {
43  $select->setAttribute( 'disabled', 'disabled' );
44  $tbAttribs['disabled'] = 'disabled';
45  }
46 
47  if ( isset( $this->mParams['tabindex'] ) ) {
48  $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
49  $tbAttribs['tabindex'] = $this->mParams['tabindex'];
50  }
51 
52  $select = $select->getHTML();
53 
54  if ( isset( $this->mParams['maxlength'] ) ) {
55  $tbAttribs['maxlength'] = $this->mParams['maxlength'];
56  }
57 
58  if ( $this->mClass !== '' ) {
59  $tbAttribs['class'] = $this->mClass;
60  }
61 
62  $textbox = Html::input( $this->mName . '-other', $valInSelect ? '' : $value, 'text', $tbAttribs );
63 
64  return "$select<br />\n$textbox";
65  }
66 
67  public function getInputOOUI( $value ) {
68  return false;
69  }
70 
76  public function loadDataFromRequest( $request ) {
77  if ( $request->getCheck( $this->mName ) ) {
78  $val = $request->getText( $this->mName );
79 
80  if ( $val === 'other' ) {
81  $val = $request->getText( $this->mName . '-other' );
82  }
83 
84  return $val;
85  } else {
86  return $this->getDefault();
87  }
88  }
89 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:1053
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
HTMLSelectOrOtherField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
Definition: HTMLSelectOrOtherField.php:67
$params
$params
Definition: styleTest.css.php:40
HTMLSelectOrOtherField
Select dropdown field, with an additional "other" textbox.
Definition: HTMLSelectOrOtherField.php:9
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
Html\input
static input( $name, $value='', $type='text', array $attribs=[])
Convenience function to produce an "<input>" element.
Definition: Html.php:663
HTMLTextField
<input> field.
Definition: HTMLTextField.php:11
XmlSelect
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
HTMLSelectOrOtherField\loadDataFromRequest
loadDataFromRequest( $request)
Definition: HTMLSelectOrOtherField.php:76
HTMLSelectOrOtherField\__construct
__construct( $params)
Definition: HTMLSelectOrOtherField.php:10
$value
$value
Definition: styleTest.css.php:45
HTMLFormField\getDefault
getDefault()
Definition: HTMLFormField.php:970
HTMLFormField\$mOptions
$mOptions
Definition: HTMLFormField.php:20
HTMLSelectOrOtherField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLSelectOrOtherField.php:23
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:1126
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
HTMLTextField\getSize
getSize()
Definition: HTMLTextField.php:40