X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLFormField.php;h=77ddc1a1b5eca29f41b1ac0a9f4527df4b58018f;hp=487d6f647bbf4ebc2cc185a0a9e23d790f195ea5;hb=fb79f30319b9ad2a7eb0f5f4d1668143ec8f963e;hpb=cf3deb6637cf4aab2678949e5ccec8084eec9907 diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 487d6f647b..77ddc1a1b5 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -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 ); }