From 38331bbce03e6c7879ee55fd09c46b3ebedc5fe1 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 19 Nov 2009 01:24:58 +0000 Subject: [PATCH] Avoid pointless $wgHtml5 checks Html::rawElement() should strip out any invalid attributes if $wgHtml5 is off. This commit should introduce no functional change. Any future problems with attributes being added incorrectly should be fixed in Html.php, not callers. Follow-up to r57096. --- includes/HTMLForm.php | 63 +++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index ed17476600..c97b42643f 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -874,7 +874,6 @@ class HTMLTextField extends HTMLFormField { } function getInputHTML( $value ) { - global $wgHtml5; $attribs = array( 'id' => $this->mID, 'name' => $this->mName, @@ -890,20 +889,18 @@ class HTMLTextField extends HTMLFormField { $attribs['disabled'] = 'disabled'; } - if ( $wgHtml5 ) { - # TODO: Enforce pattern, step, required, readonly on the server - # side as well - foreach ( array( 'min', 'max', 'pattern', 'title', 'step', - 'placeholder' ) as $param ) { - if ( isset( $this->mParams[$param] ) ) { - $attribs[$param] = $this->mParams[$param]; - } + # TODO: Enforce pattern, step, required, readonly on the server side as + # well + foreach ( array( 'min', 'max', 'pattern', 'title', 'step', + 'placeholder' ) as $param ) { + if ( isset( $this->mParams[$param] ) ) { + $attribs[$param] = $this->mParams[$param]; } - foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) - as $param ) { - if ( isset( $this->mParams[$param] ) ) { - $attribs[$param] = ''; - } + } + foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) as + $param ) { + if ( isset( $this->mParams[$param] ) ) { + $attribs[$param] = ''; } } @@ -911,23 +908,17 @@ class HTMLTextField extends HTMLFormField { # here, rather than creating a new class for each one which # is essentially just a clone of this one. if ( isset( $this->mParams['type'] ) ) { - # Options that apply only to HTML5 - if( $wgHtml5 ){ - switch ( $this->mParams['type'] ) { - case 'email': - $attribs['type'] = 'email'; - break; - case 'int': - $attribs['type'] = 'number'; - break; - case 'float': - $attribs['type'] = 'number'; - $attribs['step'] = 'any'; - break; - } - } - # Options that apply to HTML4 as well - switch( $this->mParams['type'] ) { + switch ( $this->mParams['type'] ) { + case 'email': + $attribs['type'] = 'email'; + break; + case 'int': + $attribs['type'] = 'number'; + break; + case 'float': + $attribs['type'] = 'number'; + $attribs['step'] = 'any'; + break; # Pass through case 'password': case 'file': @@ -953,7 +944,6 @@ class HTMLTextAreaField extends HTMLFormField { } function getInputHTML( $value ) { - global $wgHtml5; $attribs = array( 'id' => $this->mID, 'name' => $this->mName, @@ -969,14 +959,11 @@ class HTMLTextAreaField extends HTMLFormField { $attribs['readonly'] = 'readonly'; } - if ( $wgHtml5 ) { - foreach ( array( 'required', 'autofocus' ) as $param ) { - if ( isset( $this->mParams[$param] ) ) { - $attribs[$param] = ''; - } + foreach ( array( 'required', 'autofocus' ) as $param ) { + if ( isset( $this->mParams[$param] ) ) { + $attribs[$param] = ''; } } - return Html::element( 'textarea', $attribs, $value ); } -- 2.20.1