MediaWiki  1.29.1
HTMLRadioField.php
Go to the documentation of this file.
1 <?php
2 
14  public function __construct( $params ) {
15  parent::__construct( $params );
16 
17  if ( isset( $params['flatlist'] ) ) {
18  $this->mClass .= ' mw-htmlform-flatlist';
19  }
20  }
21 
22  public function validate( $value, $alldata ) {
23  $p = parent::validate( $value, $alldata );
24 
25  if ( $p !== true ) {
26  return $p;
27  }
28 
29  if ( !is_string( $value ) && !is_int( $value ) ) {
30  return $this->msg( 'htmlform-required' );
31  }
32 
33  $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
34 
35  if ( in_array( strval( $value ), $validOptions, true ) ) {
36  return true;
37  } else {
38  return $this->msg( 'htmlform-select-badoption' );
39  }
40  }
41 
50  public function getInputHTML( $value ) {
51  $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
52 
53  return $html;
54  }
55 
56  public function getInputOOUI( $value ) {
57  $options = [];
58  foreach ( $this->getOptions() as $label => $data ) {
59  $options[] = [
60  'data' => $data,
61  'label' => $this->mOptionsLabelsNotFromMessage ? new OOUI\HtmlSnippet( $label ) : $label,
62  ];
63  }
64 
65  return new OOUI\RadioSelectInputWidget( [
66  'name' => $this->mName,
67  'id' => $this->mID,
68  'value' => $value,
69  'options' => $options,
70  ] + OOUI\Element::configFromHtmlAttributes(
71  $this->getAttributes( [ 'disabled', 'tabindex' ] )
72  ) );
73  }
74 
75  protected function shouldInfuseOOUI() {
76  return true;
77  }
78 
79  public function formatOptions( $options, $value ) {
80  global $wgUseMediaWikiUIEverywhere;
81 
82  $html = '';
83 
84  $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
85  $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ];
86 
87  # @todo Should this produce an unordered list perhaps?
88  foreach ( $options as $label => $info ) {
89  if ( is_array( $info ) ) {
90  $html .= Html::rawElement( 'h1', [], $label ) . "\n";
91  $html .= $this->formatOptions( $info, $value );
92  } else {
93  $id = Sanitizer::escapeId( $this->mID . "-$info" );
94  $classes = [ 'mw-htmlform-flatlist-item' ];
95  if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
96  $classes[] = 'mw-ui-radio';
97  }
98  $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + [ 'id' => $id ] );
99  $radio .= '&#160;' . call_user_func( $elementFunc, 'label', [ 'for' => $id ], $label );
100 
101  $html .= ' ' . Html::rawElement(
102  'div',
103  [ 'class' => $classes ],
104  $radio
105  );
106  }
107  }
108 
109  return $html;
110  }
111 
112  protected function needsLabel() {
113  return false;
114  }
115 }
HTMLFormField\getOptions
getOptions()
Fetch the array of options from the field's parameters.
Definition: HTMLFormField.php:1053
HTMLRadioField\getInputHTML
getInputHTML( $value)
This returns a block of all the radio options, in one cell.
Definition: HTMLRadioField.php:50
Xml\radio
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.
Definition: Xml.php:341
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:112
$params
$params
Definition: styleTest.css.php:40
VFormHTMLForm
Compact stacked vertical format for forms.
Definition: VFormHTMLForm.php:27
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
HTMLRadioField\__construct
__construct( $params)
Definition: HTMLRadioField.php:14
$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:1956
HTMLRadioField
Radio checkbox fields.
Definition: HTMLRadioField.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:1956
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
HTMLRadioField\shouldInfuseOOUI
shouldInfuseOOUI()
Whether the field should be automatically infused.
Definition: HTMLRadioField.php:75
$value
$value
Definition: styleTest.css.php:45
HTMLFormField\msg
msg()
Get a translated interface message.
Definition: HTMLFormField.php:77
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
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
HTMLRadioField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
Definition: HTMLRadioField.php:56
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
HTMLRadioField\formatOptions
formatOptions( $options, $value)
Definition: HTMLRadioField.php:79
HTMLRadioField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
Definition: HTMLRadioField.php:22
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition: HTMLFormField.php:997