MediaWiki  1.23.2
HTMLRadioField.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_string( $value ) && !is_int( $value ) ) {
15  return false;
16  }
17 
18  $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
19 
20  if ( in_array( strval( $value ), $validOptions, true ) ) {
21  return true;
22  } else {
23  return $this->msg( 'htmlform-select-badoption' )->parse();
24  }
25  }
26 
35  function getInputHTML( $value ) {
36  $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
37 
38  return $html;
39  }
40 
41  function formatOptions( $options, $value ) {
42  $html = '';
43 
44  $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
45  $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
46 
47  # @todo Should this produce an unordered list perhaps?
48  foreach ( $options as $label => $info ) {
49  if ( is_array( $info ) ) {
50  $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
51  $html .= $this->formatOptions( $info, $value );
52  } else {
53  $id = Sanitizer::escapeId( $this->mID . "-$info" );
54  $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + array( 'id' => $id ) );
55  $radio .= '&#160;' . call_user_func( $elementFunc, 'label', array( 'for' => $id ), $label );
56 
57  $html .= ' ' . Html::rawElement(
58  'div',
59  array( 'class' => 'mw-htmlform-flatlist-item' ),
60  $radio
61  );
62  }
63  }
64 
65  return $html;
66  }
67 
68  protected function needsLabel() {
69  return false;
70  }
71 }
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
$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
HTMLRadioField\getInputHTML
getInputHTML( $value)
This returns a block of all the radio options, in one cell.
Definition: HTMLRadioField.php:35
HTMLRadioField\needsLabel
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
Definition: HTMLRadioField.php:68
HTMLRadioField
Radio checkbox fields.
Definition: HTMLRadioField.php:6
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:7
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Sanitizer\escapeId
static escapeId( $id, $options=array())
Given a value, escape it so that it can be used in an id attribute and return it.
Definition: Sanitizer.php:1082
$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
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:51
Xml\radio
static radio( $name, $value, $checked=false, $attribs=array())
Convenience function to build an HTML radio button.
Definition: Xml.php:357
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: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
HTMLRadioField\formatOptions
formatOptions( $options, $value)
Definition: HTMLRadioField.php:41
HTMLRadioField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLRadioField.php:7
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:493