X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2Ffields%2FHTMLRadioField.php;h=42c2fdf392d4fcf5bce8f7466454dd86e92d8f57;hb=fb79f30319b9ad2a7eb0f5f4d1668143ec8f963e;hp=e5b5e68f203edc8ab6aa0a55590cdcfbe574de23;hpb=39bdb0cb4905eaebd24ebb0ed22728fa4b94e0ee;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/fields/HTMLRadioField.php b/includes/htmlform/fields/HTMLRadioField.php index e5b5e68f20..77ea7cd211 100644 --- a/includes/htmlform/fields/HTMLRadioField.php +++ b/includes/htmlform/fields/HTMLRadioField.php @@ -4,7 +4,22 @@ * Radio checkbox fields. */ class HTMLRadioField extends HTMLFormField { - function validate( $value, $alldata ) { + /** + * @param array $params + * In adition to the usual HTMLFormField parameters, this can take the following fields: + * - flatlist: If given, the options will be displayed on a single line (wrapping to following + * lines if necessary), rather than each one on a line of its own. This is desirable mostly + * for very short lists of concisely labelled options. + */ + public function __construct( $params ) { + parent::__construct( $params ); + + if ( isset( $params['flatlist'] ) ) { + $this->mClass .= ' mw-htmlform-flatlist'; + } + } + + public function validate( $value, $alldata ) { $p = parent::validate( $value, $alldata ); if ( $p !== true ) { @@ -12,7 +27,7 @@ class HTMLRadioField extends HTMLFormField { } if ( !is_string( $value ) && !is_int( $value ) ) { - return false; + return $this->msg( 'htmlform-required' ); } $validOptions = HTMLFormField::flattenOptions( $this->getOptions() ); @@ -20,7 +35,7 @@ class HTMLRadioField extends HTMLFormField { if ( in_array( strval( $value ), $validOptions, true ) ) { return true; } else { - return $this->msg( 'htmlform-select-badoption' )->parse(); + return $this->msg( 'htmlform-select-badoption' ); } } @@ -32,13 +47,13 @@ class HTMLRadioField extends HTMLFormField { * * @return string */ - function getInputHTML( $value ) { + public function getInputHTML( $value ) { $html = $this->formatOptions( $this->getOptions(), strval( $value ) ); return $html; } - function getInputOOUI( $value ) { + public function getInputOOUI( $value ) { $options = []; foreach ( $this->getOptions() as $label => $data ) { $options[] = [ @@ -57,7 +72,11 @@ class HTMLRadioField extends HTMLFormField { ) ); } - function formatOptions( $options, $value ) { + protected function shouldInfuseOOUI() { + return true; + } + + public function formatOptions( $options, $value ) { global $wgUseMediaWikiUIEverywhere; $html = ''; @@ -71,7 +90,7 @@ class HTMLRadioField extends HTMLFormField { $html .= Html::rawElement( 'h1', [], $label ) . "\n"; $html .= $this->formatOptions( $info, $value ); } else { - $id = Sanitizer::escapeId( $this->mID . "-$info" ); + $id = Sanitizer::escapeIdForAttribute( $this->mID . "-$info" ); $classes = [ 'mw-htmlform-flatlist-item' ]; if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) { $classes[] = 'mw-ui-radio';