Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / includes / HTMLForm.php
index ce9c377..5c00b9f 100644 (file)
@@ -424,7 +424,7 @@ class HTMLForm extends ContextSource {
 
        /**
         * Set a message to display on a validation error.
-        * @param $msg Mixed String or Array of valid inputs to wfMsgExt()
+        * @param $msg Mixed String or Array of valid inputs to wfMessage()
         *       (so each entry can be either a String or Array)
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
@@ -700,7 +700,7 @@ class HTMLForm extends ContextSource {
                                'input',
                                array(
                                        'type' => 'reset',
-                                       'value' => wfMsg( 'htmlform-reset' )
+                                       'value' => $this->msg( 'htmlform-reset' )->text()
                                )
                        ) . "\n";
                }
@@ -776,7 +776,7 @@ class HTMLForm extends ContextSource {
                        $errorstr .= Html::rawElement(
                                'li',
                                array(),
-                               wfMsgExt( $msg, array( 'parseinline' ), $error )
+                               wfMessage( $msg, $error )->parse()
                        );
                }
 
@@ -813,7 +813,7 @@ class HTMLForm extends ContextSource {
        function getSubmitText() {
                return $this->mSubmitText
                        ? $this->mSubmitText
-                       : wfMsg( 'htmlform-submit' );
+                       : $this->msg( 'htmlform-submit' )->text();
        }
 
        /**
@@ -873,7 +873,7 @@ class HTMLForm extends ContextSource {
         * @return HTMLForm $this for chaining calls (since 1.20)
         */
        public function setWrapperLegendMsg( $msg ) {
-               $this->setWrapperLegend( $this->msg( $msg )->escaped() );
+               $this->setWrapperLegend( $this->msg( $msg )->text() );
                return $this;
        }
 
@@ -1051,7 +1051,7 @@ class HTMLForm extends ContextSource {
         * @return String
         */
        public function getLegend( $key ) {
-               return wfMsg( "{$this->mMessagePrefix}-$key" );
+               return $this->msg( "{$this->mMessagePrefix}-$key" )->text();
        }
 
        /**
@@ -1100,6 +1100,28 @@ abstract class HTMLFormField {
         */
        abstract function getInputHTML( $value );
 
+       /**
+        * Get a translated interface message
+        *
+        * This is a wrapper arround $this->mParent->msg() if $this->mParent is set
+        * and wfMessage() otherwise.
+        *
+        * Parameters are the same as wfMessage().
+        *
+        * @return Message object
+        */
+       function msg() {
+               $args = func_get_args();
+
+               if ( $this->mParent ) {
+                       $callback = array( $this->mParent, 'msg' );
+               } else {
+                       $callback = 'wfMessage';
+               }
+
+               return call_user_func_array( $callback, $args );
+       }
+
        /**
         * Override this function to add specific validation checks on the
         * field input.  Don't forget to call parent::validate() to ensure
@@ -1109,8 +1131,8 @@ abstract class HTMLFormField {
         * @return Mixed Bool true on success, or String error to display.
         */
        function validate( $value, $alldata ) {
-               if ( isset( $this->mParams['required'] ) && $value === '' ) {
-                       return wfMsgExt( 'htmlform-required', 'parseinline' );
+               if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value === '' ) {
+                       return $this->msg( 'htmlform-required' )->parse();
                }
 
                if ( isset( $this->mValidationCallback ) ) {
@@ -1170,7 +1192,7 @@ abstract class HTMLFormField {
                                $msgInfo = array();
                        }
 
-                       $this->mLabel = wfMsgExt( $msg, 'parseinline', $msgInfo );
+                       $this->mLabel = wfMessage( $msg, $msgInfo )->parse();
                } elseif ( isset( $params['label'] ) ) {
                        $this->mLabel = $params['label'];
                }
@@ -1371,13 +1393,13 @@ abstract class HTMLFormField {
                if ( isset( $this->mParams['help-messages'] ) ) {
                        foreach ( $this->mParams['help-messages'] as $name ) {
                                $helpMessage = (array)$name;
-                               $msg = wfMessage( array_shift( $helpMessage ), $helpMessage );
+                               $msg = $this->msg( array_shift( $helpMessage ), $helpMessage );
 
                                if ( $msg->exists() ) {
                                        if ( is_null( $helptext ) ) {
                                                $helptext = '';
                                        } else {
-                                               $helptext .= wfMessage( 'word-separator' )->escaped(); // some space
+                                               $helptext .= $this->msg( 'word-separator' )->escaped(); // some space
                                        }
                                        $helptext .= $msg->parse(); // Append message
                                }
@@ -1527,18 +1549,15 @@ class HTMLTextField extends HTMLFormField {
                        $attribs['class'] = $this->mClass;
                }
 
-               if ( isset( $this->mParams['maxlength'] ) ) {
-                       $attribs['maxlength'] = $this->mParams['maxlength'];
-               }
-
                if ( !empty( $this->mParams['disabled'] ) ) {
                        $attribs['disabled'] = 'disabled';
                }
 
                # TODO: Enforce pattern, step, required, readonly on the server side as
                # well
-               foreach ( array( 'min', 'max', 'pattern', 'title', 'step',
-               'placeholder' ) as $param ) {
+               $allowedParams = array( 'min', 'max', 'pattern', 'title', 'step',
+                       'placeholder', 'list', 'maxlength' );
+               foreach ( $allowedParams as $param ) {
                        if ( isset( $this->mParams[$param] ) ) {
                                $attribs[$param] = $this->mParams[$param];
                        }
@@ -1645,7 +1664,7 @@ 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 ) ) {
-                       return wfMsgExt( 'htmlform-float-invalid', 'parse' );
+                       return $this->msg( 'htmlform-float-invalid' )->parseAsBlock();
                }
 
                # The "int" part of these message names is rather confusing.
@@ -1654,7 +1673,7 @@ class HTMLFloatField extends HTMLTextField {
                        $min = $this->mParams['min'];
 
                        if ( $min > $value ) {
-                               return wfMsgExt( 'htmlform-int-toolow', 'parse', array( $min ) );
+                               return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
                        }
                }
 
@@ -1662,7 +1681,7 @@ class HTMLFloatField extends HTMLTextField {
                        $max = $this->mParams['max'];
 
                        if ( $max < $value ) {
-                               return wfMsgExt( 'htmlform-int-toohigh', 'parse', array( $max ) );
+                               return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
                        }
                }
 
@@ -1689,7 +1708,7 @@ class HTMLIntField extends HTMLFloatField {
                # value to, eg, save in the DB, clean it up with intval().
                if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) )
                ) {
-                       return wfMsgExt( 'htmlform-int-invalid', 'parse' );
+                       return $this->msg( 'htmlform-int-invalid' )->parseAsBlock();
                }
 
                return true;
@@ -1773,7 +1792,7 @@ class HTMLSelectField extends HTMLFormField {
                if ( in_array( $value, $validOptions ) )
                        return true;
                else
-                       return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
+                       return $this->msg( 'htmlform-select-badoption' )->parse();
        }
 
        function getInputHTML( $value ) {
@@ -1811,7 +1830,9 @@ class HTMLSelectOrOtherField extends HTMLTextField {
 
        function __construct( $params ) {
                if ( !in_array( 'other', $params['options'], true ) ) {
-                       $msg = isset( $params['other'] ) ? $params['other'] : wfMsg( 'htmlform-selectorother-other' );
+                       $msg = isset( $params['other'] ) ?
+                               $params['other'] :
+                               wfMessage( 'htmlform-selectorother-other' )->text();
                        $params['options'][$msg] = 'other';
                }
 
@@ -1915,7 +1936,7 @@ class HTMLMultiSelectField extends HTMLFormField {
                if ( count( $validValues ) == count( $value ) ) {
                        return true;
                } else {
-                       return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
+                       return $this->msg( 'htmlform-select-badoption' )->parse();
                }
        }
 
@@ -2117,7 +2138,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        } elseif ( $text == '' ) {
                                $final = $list;
                        } else {
-                               $final = $list . wfMsgForContent( 'colon-separator' ) . $text;
+                               $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text;
                        }
 
                } else {
@@ -2126,7 +2147,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        $list = 'other';
                        $text = $final;
                        foreach ( $this->mFlatOptions as $option ) {
-                               $match = $option . wfMsgForContent( 'colon-separator' );
+                               $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text();
                                if ( strpos( $text, $match ) === 0 ) {
                                        $list = $option;
                                        $text = substr( $text, strlen( $match ) );
@@ -2153,8 +2174,8 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        return $p;
                }
 
-               if ( isset( $this->mParams['required'] ) && $value[1] === '' ) {
-                       return wfMsgExt( 'htmlform-required', 'parseinline' );
+               if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value[1] === '' ) {
+                       return $this->msg( 'htmlform-required' )->parse();
                }
 
                return true;
@@ -2183,7 +2204,7 @@ class HTMLRadioField extends HTMLFormField {
                if ( in_array( $value, $validOptions ) ) {
                        return true;
                } else {
-                       return wfMsgExt( 'htmlform-select-badoption', 'parseinline' );
+                       return $this->msg( 'htmlform-select-badoption' )->parse();
                }
        }
 
@@ -2393,11 +2414,11 @@ class HTMLEditTools extends HTMLFormField {
 
        protected function formatMsg() {
                if ( empty( $this->mParams['message'] ) ) {
-                       $msg = wfMessage( 'edittools' );
+                       $msg = $this->msg( 'edittools' );
                } else {
-                       $msg = wfMessage( $this->mParams['message'] );
+                       $msg = $this->msg( $this->mParams['message'] );
                        if ( $msg->isDisabled() ) {
-                               $msg = wfMessage( 'edittools' );
+                               $msg = $this->msg( 'edittools' );
                        }
                }
                $msg->inContentLanguage();