X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=cbd73a4610749972d182d82b210fec6b3b9b3313;hb=a6b299d667bcb7b2999a3bb24b01e3aa592b90bf;hp=e7f0bd00f025233a68ceb49445bac6b232fca89b;hpb=aa487fcf9742f6990ddd58ce35cec2b76c2ef4a2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index e7f0bd00f0..cbd73a4610 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -1,45 +1,1550 @@ $info, + * where $info is an Associative Array with any of the following: + * + * 'class' -- the subclass of HTMLFormField that will be used + * to create the object. *NOT* the CSS class! + * 'type' -- roughly translates into the \n"; + function getDefault() { + if ( isset( $this->mDefault ) ) { + return $this->mDefault; + } else { + return array(); + } } - /* private */ function textbox( $varname, $value='', $size=20 ) { - $value = isset( $GLOBALS[$varname] ) ? $GLOBALS[$varname] : ''; - return "
\n"; + protected function needsLabel() { + return false; } - /* private */ function radiobox( $varname, $fields ) { - foreach ( $fields as $value => $checked ) { - $s .= "
\n"; +} + +/** + * Radio checkbox fields. + */ +class HTMLRadioField extends HTMLFormField { + function validate( $value, $alldata ) { + $p = parent::validate( $value, $alldata ); + + if ( $p !== true ) { + return $p; } - return $this->fieldset( 'sitesettings-'.$varname, $s ); + + if ( !is_string( $value ) && !is_int( $value ) ) { + return false; + } + + $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] ); + + if ( in_array( $value, $validOptions ) ) { + return true; + } else { + return wfMsgExt( 'htmlform-select-badoption', 'parseinline' ); + } + } + + /** + * This returns a block of all the radio options, in one cell. + * @see includes/HTMLFormField#getInputHTML() + */ + function getInputHTML( $value ) { + $html = $this->formatOptions( $this->mParams['options'], $value ); + + return $html; } - /* private */ function arraybox( $varname , $size=20 ) { - $s = ''; - if ( isset( $GLOBALS[$varname] ) && is_array( $GLOBALS[$varname] ) ) { - foreach ( $GLOBALS[$varname] as $index=>$element ) { - $s .= $element."\n"; + function formatOptions( $options, $value ) { + $html = ''; + + $attribs = array(); + if ( !empty( $this->mParams['disabled'] ) ) { + $attribs['disabled'] = 'disabled'; + } + + # TODO: should this produce an unordered list perhaps? + foreach ( $options as $label => $info ) { + if ( is_array( $info ) ) { + $html .= Html::rawElement( 'h1', array(), $label ) . "\n"; + $html .= $this->formatOptions( $info, $value ); + } else { + $id = Sanitizer::escapeId( $this->mID . "-$info" ); + $html .= Xml::radio( + $this->mName, + $info, + $info == $value, + $attribs + array( 'id' => $id ) + ); + $html .= ' ' . + Html::rawElement( 'label', array( 'for' => $id ), $label ); + + $html .= "
\n"; } } - return "