X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles_versions%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLForm.php;h=21505a8ad3e131c7f2f798354121409f53da7b10;hb=1ba0445c127d4b152509db0d4450d29506f29b9d;hp=1e8da45d80d32fba3b8e9048a2cd117325641e74;hpb=5df5a5b4a8ce61cda82af3c636a9b1f3016e6464;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index 1e8da45d80..21505a8ad3 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -36,8 +36,8 @@ * the HTML for the input field to be placed in the table. * * You can find extensive documentation on the www.mediawiki.org wiki: - * - http://www.mediawiki.org/wiki/HTMLForm - * - http://www.mediawiki.org/wiki/HTMLForm/tutorial + * - https://www.mediawiki.org/wiki/HTMLForm + * - https://www.mediawiki.org/wiki/HTMLForm/tutorial * * The constructor input is an associative array of $fieldname => $info, * where $info is an Associative Array with any of the following: @@ -50,7 +50,12 @@ * 'default' -- default value when the form is displayed * 'id' -- HTML id attribute * 'cssclass' -- CSS class - * 'options' -- varies according to the specific object. + * 'options' -- associative array mapping labels to values. + * Some field types support multi-level arrays. + * 'options-messages' -- associative array mapping message keys to values. + * Some field types support multi-level arrays. + * 'options-message' -- message key to be parsed to extract the list of + * options (like 'ipbreason-dropdown'). * 'label-message' -- message key for a message to use as the label. * can be an array of msg key and then parameters to * the message. @@ -113,10 +118,11 @@ class HTMLForm extends ContextSource { 'edittools' => 'HTMLEditTools', 'checkmatrix' => 'HTMLCheckMatrix', // HTMLTextField will output the correct type="" attribute automagically. - // There are about four zillion other HTML5 input types, like url, but + // There are about four zillion other HTML5 input types, like range, but // we don't use those at the moment, so no point in adding all of them. 'email' => 'HTMLTextField', 'password' => 'HTMLTextField', + 'url' => 'HTMLTextField', ); public $mFieldData; @@ -306,15 +312,22 @@ class HTMLForm extends ContextSource { } /** - * Initialise a new Object for the field + * Get the HTMLFormField subclass for this descriptor. + * + * The descriptor can be passed either 'class' which is the name of + * a HTMLFormField subclass, or a shorter 'type' which is an alias. + * This makes sure the 'class' is always set, and also is returned by + * this function for ease. + * + * @since 1.23 * - * @param $fieldname string - * @param string $descriptor input Descriptor, as described above + * @param string $fieldname Name of the field + * @param array $descriptor Input Descriptor, as described above * * @throws MWException - * @return HTMLFormField subclass + * @return string Name of a HTMLFormField subclass */ - static function loadInputFromParameters( $fieldname, $descriptor ) { + public static function getClassFromDescriptor( $fieldname, &$descriptor ) { if ( isset( $descriptor['class'] ) ) { $class = $descriptor['class']; } elseif ( isset( $descriptor['type'] ) ) { @@ -325,8 +338,22 @@ class HTMLForm extends ContextSource { } if ( !$class ) { - throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) ); + throw new MWException( "Descriptor with no class for $fieldname: " . print_r( $descriptor, true ) ); } + return $class; + } + + /** + * Initialise a new Object for the field + * + * @param string $fieldname Name of the field + * @param array $descriptor Input Descriptor, as described above + * + * @throws MWException + * @return HTMLFormField subclass + */ + public static function loadInputFromParameters( $fieldname, $descriptor ) { + $class = self::getClassFromDescriptor( $fieldname, $descriptor ); $descriptor['fieldname'] = $fieldname; @@ -790,7 +817,7 @@ class HTMLForm extends ContextSource { * @return String HTML. */ function getButtons() { - $html = ''; + $buttons = ''; if ( $this->mShowSubmit ) { $attribs = array(); @@ -812,28 +839,27 @@ class HTMLForm extends ContextSource { if ( $this->isVForm() ) { // mw-ui-block is necessary because the buttons aren't necessarily in an // immediate child div of the vform. - // TODO Let client specify if the primary submit button is progressive or destructive - array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-big', 'mw-ui-constructive', 'mw-ui-block' ); + // @todo Let client specify if the primary submit button is progressive or destructive + array_push( + $attribs['class'], + 'mw-ui-button', + 'mw-ui-big', + 'mw-ui-constructive', + 'mw-ui-block' + ); } - $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n"; - - // Buttons are top-level form elements in table and div layouts, - // but vform wants all elements inside divs to get spaced-out block - // styling. - if ( $this->isVForm() ) { - $html = Html::rawElement( 'div', null, "\n$html\n" ); - } + $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n"; } if ( $this->mShowReset ) { - $html .= Html::element( - 'input', - array( - 'type' => 'reset', - 'value' => $this->msg( 'htmlform-reset' )->text() - ) - ) . "\n"; + $buttons .= Html::element( + 'input', + array( + 'type' => 'reset', + 'value' => $this->msg( 'htmlform-reset' )->text() + ) + ) . "\n"; } foreach ( $this->mButtons as $button ) { @@ -851,10 +877,18 @@ class HTMLForm extends ContextSource { $attrs['id'] = $button['id']; } - $html .= Html::element( 'input', $attrs ); + $buttons .= Html::element( 'input', $attrs ) . "\n"; } - $html .= ''; + $html = Html::rawElement( 'span', + array( 'class' => 'mw-htmlform-submit-buttons' ), "\n$buttons" ) . "\n"; + + // Buttons are top-level form elements in table and div layouts, + // but vform wants all elements inside divs to get spaced-out block + // styling. + if ( $this->mShowSubmit && $this->isVForm() ) { + $html = Html::rawElement( 'div', null, "\n$html" ) . "\n"; + } return $html; }