MediaWiki  1.23.2
HTMLSelectAndOtherField.php
Go to the documentation of this file.
1 <?php
2 
14  function __construct( $params ) {
15  if ( array_key_exists( 'other', $params ) ) {
16  } elseif ( array_key_exists( 'other-message', $params ) ) {
17  $params['other'] = wfMessage( $params['other-message'] )->plain();
18  } else {
19  $params['other'] = wfMessage( 'htmlform-selectorother-other' )->plain();
20  }
21 
22  parent::__construct( $params );
23 
24  if ( $this->getOptions() === null ) {
25  # Sulk
26  throw new MWException( 'HTMLSelectAndOtherField called without any options' );
27  }
28  if ( !in_array( 'other', $this->mOptions, true ) ) {
29  $this->mOptions[$params['other']] = 'other';
30  }
31  $this->mFlatOptions = self::flattenOptions( $this->getOptions() );
32 
33  }
34 
35  function getInputHTML( $value ) {
36  $select = parent::getInputHTML( $value[1] );
37 
38  $textAttribs = array(
39  'id' => $this->mID . '-other',
40  'size' => $this->getSize(),
41  );
42 
43  if ( $this->mClass !== '' ) {
44  $textAttribs['class'] = $this->mClass;
45  }
46 
47  $allowedParams = array(
48  'required',
49  'autofocus',
50  'multiple',
51  'disabled',
52  'tabindex'
53  );
54 
55  $textAttribs += $this->getAttributes( $allowedParams );
56 
57  $textbox = Html::input( $this->mName . '-other', $value[2], 'text', $textAttribs );
58 
59  return "$select<br />\n$textbox";
60  }
61 
67  function loadDataFromRequest( $request ) {
68  if ( $request->getCheck( $this->mName ) ) {
69 
70  $list = $request->getText( $this->mName );
71  $text = $request->getText( $this->mName . '-other' );
72 
73  if ( $list == 'other' ) {
74  $final = $text;
75  } elseif ( !in_array( $list, $this->mFlatOptions, true ) ) {
76  # User has spoofed the select form to give an option which wasn't
77  # in the original offer. Sulk...
78  $final = $text;
79  } elseif ( $text == '' ) {
80  $final = $list;
81  } else {
82  $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text;
83  }
84  } else {
85  $final = $this->getDefault();
86 
87  $list = 'other';
88  $text = $final;
89  foreach ( $this->mFlatOptions as $option ) {
90  $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text();
91  if ( strpos( $text, $match ) === 0 ) {
92  $list = $option;
93  $text = substr( $text, strlen( $match ) );
94  break;
95  }
96  }
97  }
98 
99  return array( $final, $list, $text );
100  }
101 
102  function getSize() {
103  return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
104  }
105 
106  function validate( $value, $alldata ) {
107  # HTMLSelectField forces $value to be one of the options in the select
108  # field, which is not useful here. But we do want the validation further up
109  # the chain
110  $p = parent::validate( $value[1], $alldata );
111 
112  if ( $p !== true ) {
113  return $p;
114  }
115 
116  if ( isset( $this->mParams['required'] )
117  && $this->mParams['required'] !== false
118  && $value[1] === ''
119  ) {
120  return $this->msg( 'htmlform-required' )->parse();
121  }
122 
123  return true;
124  }
125 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:550
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
$params
$params
Definition: styleTest.css.php:40
HTMLFormField\$mClass
$mClass
Definition: HTMLFormField.php:15
HTMLSelectField
A select dropdown field.
Definition: HTMLSelectField.php:6
MWException
MediaWiki exception.
Definition: MWException.php:26
wfMessage
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 after in associative array form externallinks including delete and has completed for all link tables 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
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Html\input
static input( $name, $value='', $type='text', $attribs=array())
Convenience function to produce an "<input>" element.
Definition: Html.php:645
HTMLSelectAndOtherField
Double field with a dropdown list constructed from a system message in the format.
Definition: HTMLSelectAndOtherField.php:13
HTMLSelectAndOtherField\loadDataFromRequest
loadDataFromRequest( $request)
Definition: HTMLSelectAndOtherField.php:67
$value
$value
Definition: styleTest.css.php:45
HTMLSelectAndOtherField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself.
Definition: HTMLSelectAndOtherField.php:35
HTMLFormField\getDefault
getDefault()
Definition: HTMLFormField.php:466
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:51
HTMLSelectAndOtherField\__construct
__construct( $params)
Initialise the object.
Definition: HTMLSelectAndOtherField.php:14
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
HTMLSelectAndOtherField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLSelectAndOtherField.php:106
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
HTMLSelectAndOtherField\getSize
getSize()
Definition: HTMLSelectAndOtherField.php:102
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:493