Small doc fix to JobQueueRedis.
[lhc/web/wiklou.git] / includes / HTMLForm.php
index 06e7ee4..e204087 100644 (file)
@@ -95,7 +95,7 @@
 class HTMLForm extends ContextSource {
 
        // A mapping of 'type' inputs onto standard HTMLFormField subclasses
-       static $typeMappings = array(
+       private static $typeMappings = array(
                'api' => 'HTMLApiField',
                'text' => 'HTMLTextField',
                'textarea' => 'HTMLTextAreaField',
@@ -128,6 +128,7 @@ class HTMLForm extends ContextSource {
 
        protected $mFieldTree;
        protected $mShowReset = false;
+       protected $mShowSubmit = true;
        public $mFieldData;
 
        protected $mSubmitCallback;
@@ -190,10 +191,10 @@ class HTMLForm extends ContextSource {
 
        /**
         * Build a new HTMLForm from an array of field attributes
-        * @param $descriptor Array of Field constructs, as described above
+        * @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 $messagePrefix String a prefix to go in front of default messages
+        * @param string $messagePrefix a prefix to go in front of default messages
         */
        public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) {
                if ( $context instanceof IContextSource ) {
@@ -248,7 +249,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Set format in which to display the form
-        * @param $format String the name of the format to use, must be one of
+        * @param string $format the name of the format to use, must be one of
         *        $this->availableDisplayFormats
         * @throws MWException
         * @since 1.20
@@ -256,7 +257,7 @@ class HTMLForm extends ContextSource {
         */
        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;
@@ -281,7 +282,7 @@ class HTMLForm extends ContextSource {
        /**
         * Initialise a new Object for the field
         * @param $fieldname string
-        * @param $descriptor string input Descriptor, as described above
+        * @param string $descriptor input Descriptor, as described above
         * @throws MWException
         * @return HTMLFormField subclass
         */
@@ -378,7 +379,7 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * Validate all the fields, and call the submision callback
+        * Validate all the fields, and call the submission callback
         * function if everything is kosher.
         * @throws MWException
         * @return Mixed Bool true == Successful submission, Bool false
@@ -417,7 +418,7 @@ class HTMLForm extends ContextSource {
        /**
         * Set a callback to a function to do something with the form
         * once it's been successfully validated.
-        * @param $cb String function name.  The function will be passed
+        * @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.
@@ -441,7 +442,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Set the introductory message, overwriting any existing message.
-        * @param $msg String complete text of message to display
+        * @param string $msg complete text of message to display
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function setIntro( $msg ) {
@@ -452,7 +453,7 @@ class HTMLForm extends ContextSource {
        /**
         * Set the introductory message, overwriting any existing message.
         * @since 1.19
-        * @param $msg String complete text of message to display
+        * @param string $msg complete text of message to display
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function setPreText( $msg ) {
@@ -462,7 +463,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add introductory text.
-        * @param $msg String complete text of message to display
+        * @param string $msg complete text of message to display
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function addPreText( $msg ) {
@@ -472,8 +473,8 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add header text, inside the form.
-        * @param $msg String complete text of message to display
-        * @param $section string The section to add the header to
+        * @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 ) {
@@ -491,7 +492,7 @@ class HTMLForm extends ContextSource {
        /**
         * Set header text, inside the form.
         * @since 1.19
-        * @param $msg String complete text of message to display
+        * @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)
         */
@@ -506,8 +507,8 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add footer text, inside the form.
-        * @param $msg String complete text of message to display
-        * @param $section string The section to add the footer text to
+        * @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 ) {
@@ -525,8 +526,8 @@ class HTMLForm extends ContextSource {
        /**
         * Set footer text, inside the form.
         * @since 1.19
-        * @param $msg String complete text of message to display
-        * @param $section string The section to add the footer text to
+        * @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 ) {
@@ -540,7 +541,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add text to the end of the display.
-        * @param $msg String complete text of message to display
+        * @param string $msg complete text of message to display
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function addPostText( $msg ) {
@@ -550,7 +551,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Set text at the end of the display.
-        * @param $msg String complete text of message to display
+        * @param string $msg complete text of message to display
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function setPostText( $msg ) {
@@ -560,8 +561,8 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add a hidden field to the output
-        * @param $name String field name.  This will be used exactly as entered
-        * @param $value String field value
+        * @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)
         */
@@ -573,9 +574,9 @@ class HTMLForm extends ContextSource {
 
        /**
         * Add a button to the form
-        * @param $name String field name.
-        * @param $value String field value
-        * @param $id String DOM id for the button (default: null)
+        * @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)
         */
@@ -625,7 +626,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Wrap the form innards in an actual "<form>" element
-        * @param $html String HTML contents to wrap.
+        * @param string $html HTML contents to wrap.
         * @return String wrapped HTML.
         */
        function wrapForm( $html ) {
@@ -683,23 +684,26 @@ class HTMLForm extends ContextSource {
         */
        function getButtons() {
                $html = '';
-               $attribs = array();
 
-               if ( isset( $this->mSubmitID ) ) {
-                       $attribs['id'] = $this->mSubmitID;
-               }
+               if ( $this->mShowSubmit ) {
+                       $attribs = array();
 
-               if ( isset( $this->mSubmitName ) ) {
-                       $attribs['name'] = $this->mSubmitName;
-               }
+                       if ( isset( $this->mSubmitID ) ) {
+                               $attribs['id'] = $this->mSubmitID;
+                       }
 
-               if ( isset( $this->mSubmitTooltip ) ) {
-                       $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
-               }
+                       if ( isset( $this->mSubmitName ) ) {
+                               $attribs['name'] = $this->mSubmitName;
+                       }
 
-               $attribs['class'] = 'mw-htmlform-submit';
+                       if ( isset( $this->mSubmitTooltip ) ) {
+                               $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
+                       }
 
-               $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+                       $attribs['class'] = 'mw-htmlform-submit';
+
+                       $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+               }
 
                if ( $this->mShowReset ) {
                        $html .= Html::element(
@@ -765,7 +769,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Format a stack of error messages into a single HTML string
-        * @param $errors Array of message keys/values
+        * @param array $errors of message keys/values
         * @return String HTML, a "<ul>" list of errors
         */
        public static function formatErrors( $errors ) {
@@ -793,7 +797,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Set the text for the submit button
-        * @param $t String plaintext.
+        * @param string $t plaintext.
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        function setSubmitText( $t ) {
@@ -804,7 +808,7 @@ class HTMLForm extends ContextSource {
        /**
         * Set the text for the submit button to a message
         * @since 1.19
-        * @param $msg String message key
+        * @param string $msg message key
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setSubmitTextMsg( $msg ) {
@@ -823,7 +827,7 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * @param $name String Submit button name
+        * @param string $name Submit button name
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setSubmitName( $name ) {
@@ -832,7 +836,7 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * @param $name String Tooltip for the submit button
+        * @param string $name Tooltip for the submit button
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setSubmitTooltip( $name ) {
@@ -852,7 +856,22 @@ class HTMLForm extends ContextSource {
        }
 
        /**
-        * @param $id String DOM id for the form
+        * Stop a default submit button being shown for this form. This implies that an
+        * alternate submit method must be provided manually.
+        *
+        * @since 1.22
+        *
+        * @param bool $suppressSubmit Set to false to re-enable the button again
+        *
+        * @return HTMLForm $this for chaining calls
+        */
+       function suppressDefaultSubmit( $suppressSubmit = true ) {
+               $this->mShowSubmit = !$suppressSubmit;
+               return $this;
+       }
+
+       /**
+        * @param string $id DOM id for the form
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setId( $id ) {
@@ -862,7 +881,7 @@ class HTMLForm extends ContextSource {
        /**
         * Prompt the whole form to be wrapped in a "<fieldset>", with
         * this text as its "<legend>" element.
-        * @param $legend String HTML to go inside the "<legend>" element.
+        * @param string $legend HTML to go inside the "<legend>" element.
         *       Will be escaped
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
@@ -875,7 +894,7 @@ class HTMLForm extends ContextSource {
         * Prompt the whole form to be wrapped in a "<fieldset>", with
         * this message as its "<legend>" element.
         * @since 1.19
-        * @param $msg String message key
+        * @param string $msg message key
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setWrapperLegendMsg( $msg ) {
@@ -886,7 +905,7 @@ class HTMLForm extends ContextSource {
        /**
         * Set the prefix for various default messages
         * @todo currently only used for the "<fieldset>" legend on forms
-        * with multiple sections; should be used elsewhre?
+        * with multiple sections; should be used elsewhere?
         * @param $p String
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
@@ -932,8 +951,8 @@ class HTMLForm extends ContextSource {
        /**
         * @todo Document
         * @param $fields array[]|HTMLFormField[] array of fields (either arrays or objects)
-        * @param $sectionName string ID attribute of the "<table>" tag for this section, ignored if empty
-        * @param $fieldsetIDPrefix string ID prefix for the "<fieldset>" tag of each subsection, ignored if empty
+        * @param string $sectionName ID attribute of the "<table>" tag for this section, ignored if empty
+        * @param string $fieldsetIDPrefix ID prefix for the "<fieldset>" tag of each subsection, ignored if empty
         * @return String
         */
        public function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '' ) {
@@ -1030,7 +1049,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Stop a reset button being shown for this form
-        * @param $suppressReset Bool set to false to re-enable the
+        * @param bool $suppressReset set to false to re-enable the
         *       button again
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
@@ -1100,7 +1119,7 @@ abstract class HTMLFormField {
         * This function must be implemented to return the HTML to generate
         * the input object itself.  It should not implement the surrounding
         * table cells/rows, or labels/help messages.
-        * @param $value String the value to set the input to; eg a default
+        * @param string $value the value to set the input to; eg a default
         *       text for a text input.
         * @return String valid HTML.
         */
@@ -1109,7 +1128,7 @@ abstract class HTMLFormField {
        /**
         * Get a translated interface message
         *
-        * This is a wrapper arround $this->mParent->msg() if $this->mParent is set
+        * This is a wrapper around $this->mParent->msg() if $this->mParent is set
         * and wfMessage() otherwise.
         *
         * Parameters are the same as wfMessage().
@@ -1132,8 +1151,8 @@ abstract class HTMLFormField {
         * Override this function to add specific validation checks on the
         * field input.  Don't forget to call parent::validate() to ensure
         * that the user-defined callback mValidationCallback is still run
-        * @param $value String the value the field was submitted with
-        * @param $alldata Array the data collected from the form
+        * @param string $value the value the field was submitted with
+        * @param array $alldata the data collected from the form
         * @return Mixed Bool true on success, or String error to display.
         */
        function validate( $value, $alldata ) {
@@ -1182,7 +1201,7 @@ abstract class HTMLFormField {
 
        /**
         * Initialise the object
-        * @param $params array Associative Array. See HTMLForm doc for syntax.
+        * @param array $params Associative Array. See HTMLForm doc for syntax.
         * @throws MWException
         */
        function __construct( $params ) {
@@ -1251,7 +1270,7 @@ abstract class HTMLFormField {
        /**
         * Get the complete table row for the input, including help text,
         * labels, and whatever.
-        * @param $value String the value to set the input to.
+        * @param string $value the value to set the input to.
         * @return String complete HTML table row.
         */
        function getTableRow( $value ) {
@@ -1295,7 +1314,7 @@ abstract class HTMLFormField {
         * Get the complete div for the input, including help text,
         * labels, and whatever.
         * @since 1.20
-        * @param $value String the value to set the input to.
+        * @param string $value the value to set the input to.
         * @return String complete HTML table row.
         */
        public function getDiv( $value ) {
@@ -1322,11 +1341,11 @@ abstract class HTMLFormField {
         * Get the complete raw fields for the input, including help text,
         * labels, and whatever.
         * @since 1.20
-        * @param $value String the value to set the input to.
+        * @param string $value the value to set the input to.
         * @return String complete HTML table row.
         */
        public function getRaw( $value ) {
-               list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
+               list( $errors, ) = $this->getErrorsAndErrorClass( $value );
                $inputHtml = $this->getInputHTML( $value );
                $helptext = $this->getHelpTextHtmlRaw( $this->getHelpText() );
                $cellAttributes = array();
@@ -1420,7 +1439,7 @@ abstract class HTMLFormField {
        /**
         * Determine form errors to display and their classes
         * @since 1.20
-        * @param $value String the value of the input
+        * @param string $value the value of the input
         * @return Array
         */
        public function getErrorsAndErrorClass( $value ) {
@@ -1488,7 +1507,7 @@ abstract class HTMLFormField {
        /**
         * flatten an array of options to a single array, for instance,
         * a set of "<options>" inside "<optgroups>".
-        * @param $options array Associative Array with values either Strings
+        * @param array $options Associative Array with values either Strings
         *       or Arrays
         * @return Array flattened input
         */
@@ -1826,7 +1845,7 @@ class HTMLCheckMatrix extends HTMLFormField {
         * The value of each option is a combination of the row tag and column tag.
         * mParams['rows'] is an array with row labels as keys and row tags as values.
         * mParams['columns'] is an array with column labels as keys and column tags as values.
-        * @param $value Array of the options that should be checked
+        * @param array $value of the options that should be checked
         * @return String
         */
        function getInputHTML( $value ) {
@@ -1886,7 +1905,7 @@ class HTMLCheckMatrix extends HTMLFormField {
         * We override this function since the label should always be on a separate
         * line above the options in the case of a checkbox matrix, i.e. it's always
         * a "vertical-label".
-        * @param $value String the value to set the input to
+        * @param string $value the value to set the input to
         * @return String complete HTML table row
         */
        function getTableRow( $value ) {
@@ -1996,7 +2015,6 @@ class HTMLSelectField extends HTMLFormField {
  * Select dropdown field, with an additional "other" textbox.
  */
 class HTMLSelectOrOtherField extends HTMLTextField {
-       static $jsAdded = false;
 
        function __construct( $params ) {
                if ( !in_array( 'other', $params['options'], true ) ) {
@@ -2222,8 +2240,8 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
 
        /**
         * Build a drop-down box from a textual list.
-        * @param $string String message text
-        * @param $otherName String name of "other reason" option
+        * @param string $string message text
+        * @param string $otherName name of "other reason" option
         * @return Array
         * TODO: this is copied from Xml::listDropDown(), deprecate/avoid duplication?
         */
@@ -2527,14 +2545,17 @@ class HTMLSubmitField extends HTMLFormField {
        }
 
        public function getInputHTML( $value ) {
-               return Xml::submitButton(
-                       $value,
-                       array(
-                               'class' => 'mw-htmlform-submit ' . $this->mClass,
-                               'name' => $this->mName,
-                               'id' => $this->mID,
-                       )
+               $attr = array(
+                       'class' => 'mw-htmlform-submit ' . $this->mClass,
+                       'name' => $this->mName,
+                       'id' => $this->mID,
                );
+
+               if ( !empty( $this->mParams['disabled'] ) ) {
+                       $attr['disabled'] = 'disabled';
+               }
+
+               return Xml::submitButton( $value, $attr );
        }
 
        protected function needsLabel() {