r59234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59233‎ | r59234 | r59235 >
Date:01:24, 19 November 2009
Author:simetrical
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -874,7 +874,6 @@
875875 }
876876
877877 function getInputHTML( $value ) {
878 - global $wgHtml5;
879878 $attribs = array(
880879 'id' => $this->mID,
881880 'name' => $this->mName,
@@ -890,20 +889,18 @@
891890 $attribs['disabled'] = 'disabled';
892891 }
893892
894 - if ( $wgHtml5 ) {
895 - # TODO: Enforce pattern, step, required, readonly on the server
896 - # side as well
897 - foreach ( array( 'min', 'max', 'pattern', 'title', 'step',
898 - 'placeholder' ) as $param ) {
899 - if ( isset( $this->mParams[$param] ) ) {
900 - $attribs[$param] = $this->mParams[$param];
901 - }
 893+ # TODO: Enforce pattern, step, required, readonly on the server side as
 894+ # well
 895+ foreach ( array( 'min', 'max', 'pattern', 'title', 'step',
 896+ 'placeholder' ) as $param ) {
 897+ if ( isset( $this->mParams[$param] ) ) {
 898+ $attribs[$param] = $this->mParams[$param];
902899 }
903 - foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' )
904 - as $param ) {
905 - if ( isset( $this->mParams[$param] ) ) {
906 - $attribs[$param] = '';
907 - }
 900+ }
 901+ foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) as
 902+ $param ) {
 903+ if ( isset( $this->mParams[$param] ) ) {
 904+ $attribs[$param] = '';
908905 }
909906 }
910907
@@ -911,23 +908,17 @@
912909 # here, rather than creating a new class for each one which
913910 # is essentially just a clone of this one.
914911 if ( isset( $this->mParams['type'] ) ) {
915 - # Options that apply only to HTML5
916 - if( $wgHtml5 ){
917 - switch ( $this->mParams['type'] ) {
918 - case 'email':
919 - $attribs['type'] = 'email';
920 - break;
921 - case 'int':
922 - $attribs['type'] = 'number';
923 - break;
924 - case 'float':
925 - $attribs['type'] = 'number';
926 - $attribs['step'] = 'any';
927 - break;
928 - }
929 - }
930 - # Options that apply to HTML4 as well
931 - switch( $this->mParams['type'] ) {
 912+ switch ( $this->mParams['type'] ) {
 913+ case 'email':
 914+ $attribs['type'] = 'email';
 915+ break;
 916+ case 'int':
 917+ $attribs['type'] = 'number';
 918+ break;
 919+ case 'float':
 920+ $attribs['type'] = 'number';
 921+ $attribs['step'] = 'any';
 922+ break;
932923 # Pass through
933924 case 'password':
934925 case 'file':
@@ -953,7 +944,6 @@
954945 }
955946
956947 function getInputHTML( $value ) {
957 - global $wgHtml5;
958948 $attribs = array(
959949 'id' => $this->mID,
960950 'name' => $this->mName,
@@ -969,14 +959,11 @@
970960 $attribs['readonly'] = 'readonly';
971961 }
972962
973 - if ( $wgHtml5 ) {
974 - foreach ( array( 'required', 'autofocus' ) as $param ) {
975 - if ( isset( $this->mParams[$param] ) ) {
976 - $attribs[$param] = '';
977 - }
 963+ foreach ( array( 'required', 'autofocus' ) as $param ) {
 964+ if ( isset( $this->mParams[$param] ) ) {
 965+ $attribs[$param] = '';
978966 }
979967 }
980 -
981968
982969 return Html::element( 'textarea', $attribs, $value );
983970 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57096Recommit r56947, partially overwritten in r57024.happy-melon09:46, 30 September 2009

Status & tagging log