Merge "Fix tests that don't check composer's autoloader"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLButtonField.php
index 64fe7ed..a19bd5a 100644 (file)
@@ -13,6 +13,9 @@
  *   of the value from 'default'. Overrides 'buttonlabel-raw'.
  * - buttonlabel-raw: HTMLto display for the button display text, instead
  *   of the value from 'default'.
+ * - formnovalidate: Set to true if clicking this button should suppress
+ *   client-side form validation. Used in HTMLFormFieldCloner for add/remove
+ *   buttons.
  *
  * Note that the buttonlabel parameters are not supported on IE6 and IE7 due to
  * bugs in those browsers. If detected, they will be served buttons using the
@@ -27,12 +30,18 @@ class HTMLButtonField extends HTMLFormField {
        /** @var array $mFlags Flags to add to OOUI Button widget */
        protected $mFlags = [];
 
+       protected $mFormnovalidate = false;
+
        public function __construct( $info ) {
                $info['nodata'] = true;
                if ( isset( $info['flags'] ) ) {
                        $this->mFlags = $info['flags'];
                }
 
+               if ( isset( $info['formnovalidate'] ) ) {
+                       $this->mFormnovalidate = $info['formnovalidate'];
+               }
+
                # Generate the label from a message, if possible
                if ( isset( $info['buttonlabel-message'] ) ) {
                        $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
@@ -71,6 +80,7 @@ class HTMLButtonField extends HTMLFormField {
                        'type' => $this->buttonType,
                        'name' => $this->mName,
                        'value' => $this->getDefault(),
+                       'formnovalidate' => $this->mFormnovalidate,
                ] + $this->getAttributes( [ 'disabled', 'tabindex' ] );
 
                if ( $this->isBadIE() ) {
@@ -113,7 +123,7 @@ class HTMLButtonField extends HTMLFormField {
         * @param string $value
         * @param array $alldata
         *
-        * @return bool
+        * @return bool|string|Message
         */
        public function validate( $value, $alldata ) {
                return true;
@@ -127,6 +137,6 @@ class HTMLButtonField extends HTMLFormField {
                $request = $this->mParent
                        ? $this->mParent->getRequest()
                        : RequestContext::getMain()->getRequest();
-               return preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
+               return (bool)preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );
        }
 }