Merge "Fix and make some types in PHPDoc and JSDoc tags more specific"
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormField.php
index 487d6f6..77ddc1a 100644 (file)
@@ -416,8 +416,8 @@ abstract class HTMLFormField {
                        $this->mDir = $params['dir'];
                }
 
-               $validName = Sanitizer::escapeId( $this->mName );
-               $validName = str_replace( [ '.5B', '.5D' ], [ '[', ']' ], $validName );
+               $validName = urlencode( $this->mName );
+               $validName = str_replace( [ '%5B', '%5D' ], [ '[', ']' ], $validName );
                if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
                        throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
                }
@@ -430,7 +430,7 @@ abstract class HTMLFormField {
 
                if ( isset( $params['id'] ) ) {
                        $id = $params['id'];
-                       $validId = Sanitizer::escapeId( $id );
+                       $validId = urlencode( $id );
 
                        if ( $id != $validId ) {
                                throw new MWException( "Invalid id '$id' passed to " . __METHOD__ );
@@ -475,7 +475,7 @@ abstract class HTMLFormField {
        public function getTableRow( $value ) {
                list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
                $inputHtml = $this->getInputHTML( $value );
-               $fieldType = get_class( $this );
+               $fieldType = static::class;
                $helptext = $this->getHelpTextHtmlTable( $this->getHelpText() );
                $cellAttributes = [];
                $rowAttributes = [];
@@ -533,7 +533,7 @@ abstract class HTMLFormField {
        public function getDiv( $value ) {
                list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value );
                $inputHtml = $this->getInputHTML( $value );
-               $fieldType = get_class( $this );
+               $fieldType = static::class;
                $helptext = $this->getHelpTextHtmlDiv( $this->getHelpText() );
                $cellAttributes = [];
                $label = $this->getLabelHtml( $cellAttributes );
@@ -601,7 +601,7 @@ abstract class HTMLFormField {
                        $infusable = false;
                }
 
-               $fieldType = get_class( $this );
+               $fieldType = static::class;
                $help = $this->getHelpText();
                $errors = $this->getErrorsRaw( $value );
                foreach ( $errors as &$error ) {
@@ -976,7 +976,7 @@ abstract class HTMLFormField {
        }
 
        /**
-        * Returns the attributes required for the tooltip and accesskey.
+        * Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
         *
         * @return array Attributes
         */
@@ -988,6 +988,22 @@ abstract class HTMLFormField {
                return Linker::tooltipAndAccesskeyAttribs( $this->mParams['tooltip'] );
        }
 
+       /**
+        * Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
+        *
+        * @return array Attributes
+        */
+       public function getTooltipAndAccessKeyOOUI() {
+               if ( empty( $this->mParams['tooltip'] ) ) {
+                       return [];
+               }
+
+               return [
+                       'title' => Linker::titleAttrib( $this->mParams['tooltip'] ),
+                       'accessKey' => Linker::accesskey( $this->mParams['tooltip'] ),
+               ];
+       }
+
        /**
         * Returns the given attributes from the parameters
         *
@@ -1145,6 +1161,9 @@ abstract class HTMLFormField {
         * @since 1.18
         */
        protected static function formatErrors( $errors ) {
+               // Note: If you change the logic in this method, change
+               // htmlform.Checker.js to match.
+
                if ( is_array( $errors ) && count( $errors ) === 1 ) {
                        $errors = array_shift( $errors );
                }