From 8fa2314b2e2712937eb73f81909552c22e1a9615 Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 19 Nov 2013 14:08:16 +0100 Subject: [PATCH] Formatting fixes in includes/htmlform/* Change-Id: Iee9e4f3fcf8491022ffe97c74312871f97f8ce9c --- includes/htmlform/HTMLApiField.php | 3 +- includes/htmlform/HTMLButtonField.php | 9 +- includes/htmlform/HTMLCheckField.php | 27 +- includes/htmlform/HTMLCheckMatrix.php | 68 +++-- includes/htmlform/HTMLEditTools.php | 15 +- includes/htmlform/HTMLFloatField.php | 15 +- includes/htmlform/HTMLForm.php | 260 +++++++++++++----- includes/htmlform/HTMLFormField.php | 175 +++++++----- .../HTMLFormFieldRequiredOptionsException.php | 7 +- includes/htmlform/HTMLHiddenField.php | 7 +- includes/htmlform/HTMLInfoField.php | 13 +- includes/htmlform/HTMLIntField.php | 5 +- includes/htmlform/HTMLMultiSelectField.php | 38 ++- includes/htmlform/HTMLNestedFilterable.php | 3 +- includes/htmlform/HTMLRadioField.php | 22 +- includes/htmlform/HTMLSelectAndOtherField.php | 45 +-- includes/htmlform/HTMLSelectField.php | 11 +- includes/htmlform/HTMLSelectOrOtherField.php | 27 +- includes/htmlform/HTMLSubmitField.php | 3 +- includes/htmlform/HTMLTextAreaField.php | 25 +- includes/htmlform/HTMLTextField.php | 35 +-- 21 files changed, 514 insertions(+), 299 deletions(-) diff --git a/includes/htmlform/HTMLApiField.php b/includes/htmlform/HTMLApiField.php index 1753156cfa..f988e6224e 100644 --- a/includes/htmlform/HTMLApiField.php +++ b/includes/htmlform/HTMLApiField.php @@ -1,4 +1,5 @@ $this->mID, ); - if ( ! empty( $this->mParams[ 'disabled' ] ) ) { - $attr[ 'disabled' ] = 'disabled'; + if ( !empty( $this->mParams['disabled'] ) ) { + $attr['disabled'] = 'disabled'; } return Html::input( $this->mName, $value, $this->buttonType, $attr ); @@ -42,4 +43,4 @@ class HTMLButtonField extends HTMLFormField { public function validate( $value, $alldata ) { return true; } -} \ No newline at end of file +} diff --git a/includes/htmlform/HTMLCheckField.php b/includes/htmlform/HTMLCheckField.php index dc9603c74b..105a884da6 100644 --- a/includes/htmlform/HTMLCheckField.php +++ b/includes/htmlform/HTMLCheckField.php @@ -1,32 +1,37 @@ mParams[ 'invert' ] ) ) { - $value = ! $value; + if ( !empty( $this->mParams['invert'] ) ) { + $value = !$value; } $attr = $this->getTooltipAndAccessKey(); - $attr[ 'id' ] = $this->mID; + $attr['id'] = $this->mID; - if ( ! empty( $this->mParams[ 'disabled' ] ) ) { - $attr[ 'disabled' ] = 'disabled'; + if ( !empty( $this->mParams['disabled'] ) ) { + $attr['disabled'] = 'disabled'; } if ( $this->mClass !== '' ) { - $attr[ 'class' ] = $this->mClass; + $attr['class'] = $this->mClass; } if ( $this->mParent->isVForm() ) { // Nest checkbox inside label. - return Html::rawElement( 'label', array( + return Html::rawElement( 'label', + array( 'class' => 'mw-ui-checkbox-label' - ), Xml::check( $this->mName, $value, $attr ) . // Html:rawElement doesn't escape contents. + ), + Xml::check( $this->mName, $value, $attr ) . // Html:rawElement doesn't escape contents. htmlspecialchars( $this->mLabel ) ); } else { - return Xml::check( $this->mName, $value, $attr ) . ' ' . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel ); + return Xml::check( $this->mName, $value, $attr ) + . ' ' + . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel ); } } @@ -53,7 +58,7 @@ class HTMLCheckField extends HTMLFormField { */ function loadDataFromRequest( $request ) { $invert = false; - if ( isset( $this->mParams[ 'invert' ] ) && $this->mParams[ 'invert' ] ) { + if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) { $invert = true; } @@ -73,4 +78,4 @@ class HTMLCheckField extends HTMLFormField { return $this->getDefault(); } } -} \ No newline at end of file +} diff --git a/includes/htmlform/HTMLCheckMatrix.php b/includes/htmlform/HTMLCheckMatrix.php index dba0706994..323d2d97f4 100644 --- a/includes/htmlform/HTMLCheckMatrix.php +++ b/includes/htmlform/HTMLCheckMatrix.php @@ -1,4 +1,5 @@ mParams[ 'rows' ]; - $columns = $this->mParams[ 'columns' ]; + $rows = $this->mParams['rows']; + $columns = $this->mParams['columns']; // Make sure user-defined validation callback is run $p = parent::validate( $value, $alldata ); @@ -49,7 +49,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { } // Make sure submitted value is an array - if ( ! is_array( $value ) ) { + if ( !is_array( $value ) ) { return false; } @@ -58,7 +58,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { $validOptions = array(); foreach ( $rows as $rowTag ) { foreach ( $columns as $columnTag ) { - $validOptions[ ] = $columnTag . '-' . $rowTag; + $validOptions[] = $columnTag . '-' . $rowTag; } } $validValues = array_intersect( $value, $validOptions ); @@ -83,12 +83,12 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { $html = ''; $tableContents = ''; $attribs = array(); - $rows = $this->mParams[ 'rows' ]; - $columns = $this->mParams[ 'columns' ]; + $rows = $this->mParams['rows']; + $columns = $this->mParams['columns']; // If the disabled param is set, disable all the options - if ( ! empty( $this->mParams[ 'disabled' ] ) ) { - $attribs[ 'disabled' ] = 'disabled'; + if ( !empty( $this->mParams['disabled'] ) ) { + $attribs['disabled'] = 'disabled'; } // Build the column headers @@ -99,17 +99,17 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { $tableContents .= Html::rawElement( 'tr', array(), "\n$headerContents\n" ); $tooltipClass = 'mw-icon-question'; - if ( isset( $this->mParams[ 'tooltip-class' ] ) ) { - $tooltipClass = $this->mParams[ 'tooltip-class' ]; + if ( isset( $this->mParams['tooltip-class'] ) ) { + $tooltipClass = $this->mParams['tooltip-class']; } // Build the options matrix foreach ( $rows as $rowLabel => $rowTag ) { // Append tooltip if configured - if ( isset( $this->mParams[ 'tooltips' ][ $rowLabel ] ) ) { + if ( isset( $this->mParams['tooltips'][$rowLabel] ) ) { $tooltipAttribs = array( 'class' => "mw-htmlform-tooltip $tooltipClass", - 'title' => $this->mParams[ 'tooltips' ][ $rowLabel ], + 'title' => $this->mParams['tooltips'][$rowLabel], ); $rowLabel .= ' ' . Html::element( 'span', $tooltipAttribs, '' ); } @@ -124,28 +124,36 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { $checked = in_array( $thisTag, (array)$value, true ); if ( $this->isTagForcedOff( $thisTag ) ) { $checked = false; - $thisAttribs[ 'disabled' ] = 1; + $thisAttribs['disabled'] = 1; } elseif ( $this->isTagForcedOn( $thisTag ) ) { $checked = true; - $thisAttribs[ 'disabled' ] = 1; + $thisAttribs['disabled'] = 1; } - $rowContents .= Html::rawElement( 'td', array(), Xml::check( "{$this->mName}[]", $checked, $attribs + $thisAttribs ) ); + $rowContents .= Html::rawElement( + 'td', + array(), + Xml::check( "{$this->mName}[]", $checked, $attribs + $thisAttribs ) + ); } $tableContents .= Html::rawElement( 'tr', array(), "\n$rowContents\n" ); } // Put it all in a table - $html .= Html::rawElement( 'table', array( 'class' => 'mw-htmlform-matrix' ), Html::rawElement( 'tbody', array(), "\n$tableContents\n" ) ) . "\n"; + $html .= Html::rawElement( 'table', + array( 'class' => 'mw-htmlform-matrix' ), + Html::rawElement( 'tbody', array(), "\n$tableContents\n" ) ) . "\n"; return $html; } protected function isTagForcedOff( $tag ) { - return isset( $this->mParams[ 'force-options-off' ] ) && in_array( $tag, $this->mParams[ 'force-options-off' ] ); + return isset( $this->mParams['force-options-off'] ) + && in_array( $tag, $this->mParams['force-options-off'] ); } protected function isTagForcedOn( $tag ) { - return isset( $this->mParams[ 'force-options-on' ] ) && in_array( $tag, $this->mParams[ 'force-options-on' ] ); + return isset( $this->mParams['force-options-on'] ) + && in_array( $tag, $this->mParams['force-options-on'] ); } /** @@ -168,10 +176,16 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { $label = $this->getLabelHtml( $cellAttributes ); - $field = Html::rawElement( 'td', array( 'class' => 'mw-input' ) + $cellAttributes, $inputHtml . "\n$errors" ); + $field = Html::rawElement( + 'td', + array( 'class' => 'mw-input' ) + $cellAttributes, + $inputHtml . "\n$errors" + ); $html = Html::rawElement( 'tr', array( 'class' => 'mw-htmlform-vertical-label' ), $label ); - $html .= Html::rawElement( 'tr', array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass} $errorClass" ), $field ); + $html .= Html::rawElement( 'tr', + array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass} $errorClass" ), + $field ); return $html . $helptext; } @@ -210,23 +224,23 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable { } function filterDataForSubmit( $data ) { - $columns = HTMLFormField::flattenOptions( $this->mParams[ 'columns' ] ); - $rows = HTMLFormField::flattenOptions( $this->mParams[ 'rows' ] ); + $columns = HTMLFormField::flattenOptions( $this->mParams['columns'] ); + $rows = HTMLFormField::flattenOptions( $this->mParams['rows'] ); $res = array(); foreach ( $columns as $column ) { foreach ( $rows as $row ) { // Make sure option hasn't been forced $thisTag = "$column-$row"; if ( $this->isTagForcedOff( $thisTag ) ) { - $res[ $thisTag ] = false; + $res[$thisTag] = false; } elseif ( $this->isTagForcedOn( $thisTag ) ) { - $res[ $thisTag ] = true; + $res[$thisTag] = true; } else { - $res[ $thisTag ] = in_array( $thisTag, $data ); + $res[$thisTag] = in_array( $thisTag, $data ); } } } return $res; } -} \ No newline at end of file +} diff --git a/includes/htmlform/HTMLEditTools.php b/includes/htmlform/HTMLEditTools.php index 1bb350b973..4f1b530224 100644 --- a/includes/htmlform/HTMLEditTools.php +++ b/includes/htmlform/HTMLEditTools.php @@ -1,4 +1,5 @@ formatMsg(); - return '' . '
' . $msg->parseAsBlock() . "
\n"; + return + '' . + '
' . + $msg->parseAsBlock() . + "
\n"; } /** @@ -15,6 +20,7 @@ class HTMLEditTools extends HTMLFormField { */ public function getDiv( $value ) { $msg = $this->formatMsg(); + return '
' . $msg->parseAsBlock() . '
'; } @@ -26,15 +32,16 @@ class HTMLEditTools extends HTMLFormField { } protected function formatMsg() { - if ( empty( $this->mParams[ 'message' ] ) ) { + if ( empty( $this->mParams['message'] ) ) { $msg = $this->msg( 'edittools' ); } else { - $msg = $this->msg( $this->mParams[ 'message' ] ); + $msg = $this->msg( $this->mParams['message'] ); if ( $msg->isDisabled() ) { $msg = $this->msg( 'edittools' ); } } $msg->inContentLanguage(); + return $msg; } -} \ No newline at end of file +} diff --git a/includes/htmlform/HTMLFloatField.php b/includes/htmlform/HTMLFloatField.php index 817d9c51e6..3b38fbe892 100644 --- a/includes/htmlform/HTMLFloatField.php +++ b/includes/htmlform/HTMLFloatField.php @@ -1,10 +1,11 @@ mParams[ 'size' ] ) ? $this->mParams[ 'size' ] : 20; + return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 20; } function validate( $value, $alldata ) { @@ -18,22 +19,22 @@ class HTMLFloatField extends HTMLTextField { # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers # with the addition that a leading '+' sign is ok. - if ( ! preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) { + if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) { return $this->msg( 'htmlform-float-invalid' )->parseAsBlock(); } # The "int" part of these message names is rather confusing. # They make equal sense for all numbers. - if ( isset( $this->mParams[ 'min' ] ) ) { - $min = $this->mParams[ 'min' ]; + if ( isset( $this->mParams['min'] ) ) { + $min = $this->mParams['min']; if ( $min > $value ) { return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock(); } } - if ( isset( $this->mParams[ 'max' ] ) ) { - $max = $this->mParams[ 'max' ]; + if ( isset( $this->mParams['max'] ) ) { + $max = $this->mParams['max']; if ( $max < $value ) { return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock(); @@ -42,4 +43,4 @@ class HTMLFloatField extends HTMLTextField { return true; } -} \ No newline at end of file +} diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index e5a42ebdbc..5621b01f43 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -1,4 +1,5 @@ $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 type attribute. + * if 'class' is not specified, this is used as a map + * through HTMLForm::$typeMappings to get the class name. + * 'default' -- default value when the form is displayed + * 'id' -- HTML id attribute + * 'cssclass' -- CSS class + * 'options' -- varies according to the specific object. + * '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. + * 'label' -- alternatively, a raw text message. Overridden by + * label-message + * 'help' -- message text for a message to use as a help text. + * 'help-message' -- message key for a message to use as a help text. + * can be an array of msg key and then parameters to + * the message. + * Overwrites 'help-messages' and 'help'. + * 'help-messages' -- array of message key. As above, each item can + * be an array of msg key and then parameters. + * Overwrites 'help'. + * 'required' -- passed through to the object, indicating that it + * is a required field. + * 'size' -- the length of text fields + * 'filter-callback -- a function name to give you the chance to + * massage the inputted value before it's processed. + * @see HTMLForm::filter() + * 'validation-callback' -- a function name to give you the chance + * to impose extra validation on the field input. + * @see HTMLForm::validate() + * 'name' -- By default, the 'name' attribute of the input field + * is "wp{$fieldname}". If you want a different name + * (eg one without the "wp" prefix), specify it here and + * it will be used without modification. * * Since 1.20, you can chain mutators to ease the form generation: * @par Example: @@ -89,10 +90,9 @@ * Note that you will have prepareForm and displayForm at the end. Other * methods call done after that would simply not be part of the form :( * - * TODO: Document 'section' / 'subsection' stuff + * @todo Document 'section' / 'subsection' stuff */ class HTMLForm extends ContextSource { - // A mapping of 'type' inputs onto standard HTMLFormField subclasses public static $typeMappings = array( 'api' => 'HTMLApiField', @@ -112,7 +112,6 @@ class HTMLForm extends ContextSource { 'hidden' => 'HTMLHiddenField', 'edittools' => 'HTMLEditTools', 'checkmatrix' => 'HTMLCheckMatrix', - // HTMLTextField will output the correct type="" attribute automagically. // There are about four zillion other HTML5 input types, like url, but // we don't use those at the moment, so no point in adding all of them. @@ -120,6 +119,8 @@ class HTMLForm extends ContextSource { 'password' => 'HTMLTextField', ); + public $mFieldData; + protected $mMessagePrefix; /** @var HTMLFormField[] */ @@ -128,7 +129,6 @@ class HTMLForm extends ContextSource { protected $mFieldTree; protected $mShowReset = false; protected $mShowSubmit = true; - public $mFieldData; protected $mSubmitCallback; protected $mValidationErrorMessage; @@ -192,12 +192,15 @@ class HTMLForm extends ContextSource { /** * Build a new HTMLForm from an array of field attributes + * * @param array $descriptor of Field constructs, as described above * @param $context IContextSource available since 1.18, will become compulsory in 1.18. * Obviates the need to call $form->setTitle() * @param string $messagePrefix a prefix to go in front of default messages */ - public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) { + public function __construct( $descriptor, /*IContextSource*/ $context = null, + $messagePrefix = '' + ) { if ( $context instanceof IContextSource ) { $this->setContext( $context ); $this->mTitle = false; // We don't need them to set a title @@ -257,17 +260,21 @@ class HTMLForm extends ContextSource { /** * Set format in which to display the form + * * @param string $format the name of the format to use, must be one of * $this->availableDisplayFormats + * * @throws MWException * @since 1.20 * @return HTMLForm $this for chaining calls (since 1.20) */ public function setDisplayFormat( $format ) { if ( !in_array( $format, $this->availableDisplayFormats ) ) { - throw new MWException( 'Display format must be one of ' . print_r( $this->availableDisplayFormats, true ) ); + throw new MWException( 'Display format must be one of ' . + print_r( $this->availableDisplayFormats, true ) ); } $this->displayFormat = $format; + return $this; } @@ -300,8 +307,10 @@ class HTMLForm extends ContextSource { /** * Initialise a new Object for the field + * * @param $fieldname string * @param string $descriptor input Descriptor, as described above + * * @throws MWException * @return HTMLFormField subclass */ @@ -321,8 +330,7 @@ class HTMLForm extends ContextSource { $descriptor['fieldname'] = $fieldname; - # TODO - # This will throw a fatal error whenever someone try to use + # @todo This will throw a fatal error whenever someone try to use # 'class' to feed a CSS class instead of 'cssclass'. Would be # great to avoid the fatal error and show a nice error. $obj = new $class( $descriptor ); @@ -347,6 +355,7 @@ class HTMLForm extends ContextSource { # Load data from the request. $this->loadData(); + return $this; } @@ -394,6 +403,7 @@ class HTMLForm extends ContextSource { } $this->displayForm( $result ); + return false; } @@ -424,7 +434,8 @@ class HTMLForm extends ContextSource { $callback = $this->mSubmitCallback; if ( !is_callable( $callback ) ) { - throw new MWException( 'HTMLForm: no submit callback provided. Use setSubmitCallback() to set one.' ); + throw new MWException( 'HTMLForm: no submit callback provided. Use ' . + 'setSubmitCallback() to set one.' ); } $data = $this->filterDataForSubmit( $this->mFieldData ); @@ -437,63 +448,80 @@ class HTMLForm extends ContextSource { /** * Set a callback to a function to do something with the form * once it's been successfully validated. + * * @param string $cb function name. The function will be passed - * the output from HTMLForm::filterDataForSubmit, and must - * return Bool true on success, Bool false if no submission - * was attempted, or String HTML output to display on error. + * the output from HTMLForm::filterDataForSubmit, and must + * return Bool true on success, Bool false if no submission + * was attempted, or String HTML output to display on error. + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setSubmitCallback( $cb ) { $this->mSubmitCallback = $cb; + return $this; } /** * Set a message to display on a validation error. + * * @param $msg Mixed String or Array of valid inputs to wfMessage() - * (so each entry can be either a String or Array) + * (so each entry can be either a String or Array) + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setValidationErrorMessage( $msg ) { $this->mValidationErrorMessage = $msg; + return $this; } /** * Set the introductory message, overwriting any existing message. + * * @param string $msg complete text of message to display + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setIntro( $msg ) { $this->setPreText( $msg ); + return $this; } /** * Set the introductory message, overwriting any existing message. * @since 1.19 + * * @param string $msg complete text of message to display + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setPreText( $msg ) { $this->mPre = $msg; + return $this; } /** * Add introductory text. + * * @param string $msg complete text of message to display + * * @return HTMLForm $this for chaining calls (since 1.20) */ function addPreText( $msg ) { $this->mPre .= $msg; + return $this; } /** * Add header text, inside the form. + * * @param string $msg complete text of message to display * @param string $section The section to add the header to + * * @return HTMLForm $this for chaining calls (since 1.20) */ function addHeaderText( $msg, $section = null ) { @@ -505,14 +533,17 @@ class HTMLForm extends ContextSource { } $this->mSectionHeaders[$section] .= $msg; } + return $this; } /** * Set header text, inside the form. * @since 1.19 + * * @param string $msg complete text of message to display * @param $section The section to add the header to + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setHeaderText( $msg, $section = null ) { @@ -521,13 +552,16 @@ class HTMLForm extends ContextSource { } else { $this->mSectionHeaders[$section] = $msg; } + return $this; } /** * Add footer text, inside the form. + * * @param string $msg complete text of message to display * @param string $section The section to add the footer text to + * * @return HTMLForm $this for chaining calls (since 1.20) */ function addFooterText( $msg, $section = null ) { @@ -539,14 +573,17 @@ class HTMLForm extends ContextSource { } $this->mSectionFooters[$section] .= $msg; } + return $this; } /** * Set footer text, inside the form. * @since 1.19 + * * @param string $msg complete text of message to display * @param string $section The section to add the footer text to + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setFooterText( $msg, $section = null ) { @@ -555,39 +592,49 @@ class HTMLForm extends ContextSource { } else { $this->mSectionFooters[$section] = $msg; } + return $this; } /** * Add text to the end of the display. + * * @param string $msg complete text of message to display + * * @return HTMLForm $this for chaining calls (since 1.20) */ function addPostText( $msg ) { $this->mPost .= $msg; + return $this; } /** * Set text at the end of the display. + * * @param string $msg complete text of message to display + * * @return HTMLForm $this for chaining calls (since 1.20) */ function setPostText( $msg ) { $this->mPost = $msg; + return $this; } /** * Add a hidden field to the output + * * @param string $name field name. This will be used exactly as entered * @param string $value field value * @param $attribs Array + * * @return HTMLForm $this for chaining calls (since 1.20) */ public function addHiddenField( $name, $value, $attribs = array() ) { $attribs += array( 'name' => $name ); $this->mHiddenFields[] = array( $value, $attribs ); + return $this; } @@ -595,27 +642,33 @@ class HTMLForm extends ContextSource { * Add an array of hidden fields to the output * * @since 1.22 + * * @param array $fields Associative array of fields to add; * mapping names to their values + * * @return HTMLForm $this for chaining calls */ public function addHiddenFields( array $fields ) { foreach ( $fields as $name => $value ) { $this->mHiddenFields[] = array( $value, array( 'name' => $name ) ); } + return $this; } /** * Add a button to the form + * * @param string $name field name. * @param string $value field value * @param string $id DOM id for the button (default: null) * @param $attribs Array + * * @return HTMLForm $this for chaining calls (since 1.20) */ public function addButton( $name, $value, $id = null, $attribs = null ) { $this->mButtons[] = compact( 'name', 'value', 'id', 'attribs' ); + return $this; } @@ -628,6 +681,7 @@ class HTMLForm extends ContextSource { * call just after prepareForm(). * * @param $submitResult Mixed output from HTMLForm::trySubmit() + * * @return Nothing, should be last call */ function displayForm( $submitResult ) { @@ -636,7 +690,9 @@ class HTMLForm extends ContextSource { /** * Returns the raw HTML generated by the form + * * @param $submitResult Mixed output from HTMLForm::trySubmit() + * * @return string */ function getHTML( $submitResult ) { @@ -645,7 +701,7 @@ class HTMLForm extends ContextSource { $this->getOutput()->addModules( 'mediawiki.htmlform' ); if ( $this->isVForm() ) { $this->getOutput()->addModuleStyles( 'mediawiki.ui' ); - // TODO should vertical form set setWrapperLegend( false ) + // @todo Should vertical form set setWrapperLegend( false ) // to hide ugly fieldsets? } @@ -664,7 +720,9 @@ class HTMLForm extends ContextSource { /** * Wrap the form innards in an actual "
" element + * * @param string $html HTML contents to wrap. + * * @return String wrapped HTML. */ function wrapForm( $html ) { @@ -691,6 +749,7 @@ class HTMLForm extends ContextSource { if ( $this->isVForm() ) { array_push( $attribs['class'], 'mw-ui-vform', 'mw-ui-container' ); } + return Html::rawElement( 'form', $attribs, $html ); } @@ -703,7 +762,11 @@ class HTMLForm extends ContextSource { $html = ''; if ( $this->getMethod() == 'post' ) { - $html .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken(), array( 'id' => 'wpEditToken' ) ) . "\n"; + $html .= Html::hidden( + 'wpEditToken', + $this->getUser()->getEditToken(), + array( 'id' => 'wpEditToken' ) + ) . "\n"; $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n"; } @@ -761,12 +824,12 @@ class HTMLForm extends ContextSource { if ( $this->mShowReset ) { $html .= Html::element( - 'input', - array( - 'type' => 'reset', - 'value' => $this->msg( 'htmlform-reset' )->text() - ) - ) . "\n"; + 'input', + array( + 'type' => 'reset', + 'value' => $this->msg( 'htmlform-reset' )->text() + ) + ) . "\n"; } foreach ( $this->mButtons as $button ) { @@ -802,7 +865,9 @@ class HTMLForm extends ContextSource { /** * Format and display an error message stack. + * * @param $errors String|Array|Status + * * @return String */ function getErrors( $errors ) { @@ -825,7 +890,9 @@ class HTMLForm extends ContextSource { /** * Format a stack of error messages into a single HTML string + * * @param array $errors of message keys/values + * * @return String HTML, a "