Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / htmlform / HTMLRadioField.php
blobe5b5e68f203edc8ab6aa0a55590cdcfbe574de23
1 <?php
3 /**
4 * Radio checkbox fields.
5 */
6 class HTMLRadioField extends HTMLFormField {
7 function validate( $value, $alldata ) {
8 $p = parent::validate( $value, $alldata );
10 if ( $p !== true ) {
11 return $p;
14 if ( !is_string( $value ) && !is_int( $value ) ) {
15 return false;
18 $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
20 if ( in_array( strval( $value ), $validOptions, true ) ) {
21 return true;
22 } else {
23 return $this->msg( 'htmlform-select-badoption' )->parse();
27 /**
28 * This returns a block of all the radio options, in one cell.
29 * @see includes/HTMLFormField#getInputHTML()
31 * @param string $value
33 * @return string
35 function getInputHTML( $value ) {
36 $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
38 return $html;
41 function getInputOOUI( $value ) {
42 $options = [];
43 foreach ( $this->getOptions() as $label => $data ) {
44 $options[] = [
45 'data' => $data,
46 'label' => $this->mOptionsLabelsNotFromMessage ? new OOUI\HtmlSnippet( $label ) : $label,
50 return new OOUI\RadioSelectInputWidget( [
51 'name' => $this->mName,
52 'id' => $this->mID,
53 'value' => $value,
54 'options' => $options,
55 ] + OOUI\Element::configFromHtmlAttributes(
56 $this->getAttributes( [ 'disabled', 'tabindex' ] )
57 ) );
60 function formatOptions( $options, $value ) {
61 global $wgUseMediaWikiUIEverywhere;
63 $html = '';
65 $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
66 $elementFunc = [ 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' ];
68 # @todo Should this produce an unordered list perhaps?
69 foreach ( $options as $label => $info ) {
70 if ( is_array( $info ) ) {
71 $html .= Html::rawElement( 'h1', [], $label ) . "\n";
72 $html .= $this->formatOptions( $info, $value );
73 } else {
74 $id = Sanitizer::escapeId( $this->mID . "-$info" );
75 $classes = [ 'mw-htmlform-flatlist-item' ];
76 if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
77 $classes[] = 'mw-ui-radio';
79 $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + [ 'id' => $id ] );
80 $radio .= '&#160;' . call_user_func( $elementFunc, 'label', [ 'for' => $id ], $label );
82 $html .= ' ' . Html::rawElement(
83 'div',
84 [ 'class' => $classes ],
85 $radio
90 return $html;
93 protected function needsLabel() {
94 return false;