r57560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57559‎ | r57560 | r57561 >
Date:14:22, 9 October 2009
Author:btongminh
Status:ok
Tags:
Comment:
* Add file and textarea support to HTMLForm.
* Move HTML label generation to separate function, because it needs to be overridden for SpecialUpload
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -51,6 +51,7 @@
5252 # A mapping of 'type' inputs onto standard HTMLFormField subclasses
5353 static $typeMappings = array(
5454 'text' => 'HTMLTextField',
 55+ 'textarea' => 'HTMLTextAreaField',
5556 'select' => 'HTMLSelectField',
5657 'radio' => 'HTMLRadioField',
5758 'multiselect' => 'HTMLMultiSelectField',
@@ -737,17 +738,7 @@
738739 $errors = Html::rawElement( 'span', array( 'class' => 'error' ), $errors );
739740 }
740741
741 - $html = '';
742 -
743 - # Don't output a for= attribute for labels with no associated input.
744 - # Kind of hacky here, possibly we don't want these to be <label>s at all.
745 - $for = array();
746 - if ( $this->needsLabel() ) {
747 - $for['for'] = $this->mID;
748 - }
749 - $html .= Html::rawElement( 'td', array( 'class' => 'mw-label' ),
750 - Html::rawElement( 'label', $for, $this->getLabel() )
751 - );
 742+ $html = $this->getLabelHtml();
752743 $html .= Html::rawElement( 'td', array( 'class' => 'mw-input' ),
753744 $this->getInputHTML( $value ) ."\n$errors" );
754745
@@ -781,6 +772,17 @@
782773 function getLabel() {
783774 return $this->mLabel;
784775 }
 776+ function getLabelHtml() {
 777+ # Don't output a for= attribute for labels with no associated input.
 778+ # Kind of hacky here, possibly we don't want these to be <label>s at all.
 779+ $for = array();
 780+ if ( $this->needsLabel() ) {
 781+ $for['for'] = $this->mID;
 782+ }
 783+ return Html::rawElement( 'td', array( 'class' => 'mw-label' ),
 784+ Html::rawElement( 'label', $for, $this->getLabel() )
 785+ );
 786+ }
785787
786788 function getDefault() {
787789 if ( isset( $this->mDefault ) ) {
@@ -874,9 +876,11 @@
875877 }
876878 }
877879 # Options that apply to HTML4 as well
878 - switch( $this->mParams['type'] ){
 880+ switch( $this->mParams['type'] ) {
 881+ # Pass through
879882 case 'password':
880 - $attribs['type'] = 'password';
 883+ case 'file':
 884+ $attribs['type'] = $this->mParams['type'];
881885 break;
882886 }
883887 }
@@ -884,7 +888,49 @@
885889 return Html::element( 'input', $attribs );
886890 }
887891 }
 892+class HTMLTextAreaField extends HTMLFormField {
 893+
 894+ function getCols() {
 895+ return isset( $this->mParams['cols'] )
 896+ ? $this->mParams['cols']
 897+ : 80;
 898+ }
 899+ function getRows() {
 900+ return isset( $this->mParams['rows'] )
 901+ ? $this->mParams['rows']
 902+ : 25;
 903+ }
 904+
 905+ function getInputHTML( $value ) {
 906+ global $wgHtml5;
 907+ $attribs = array(
 908+ 'id' => $this->mID,
 909+ 'name' => $this->mName,
 910+ 'cols' => $this->getCols(),
 911+ 'rows' => $this->getRows(),
 912+ );
888913
 914+
 915+ if ( !empty( $this->mParams['disabled'] ) ) {
 916+ $attribs['disabled'] = 'disabled';
 917+ }
 918+ if ( !empty( $this->mParams['readonly'] ) ) {
 919+ $attribs['readonly'] = 'readonly';
 920+ }
 921+
 922+ if ( $wgHtml5 ) {
 923+ foreach ( array( 'required', 'autofocus' ) as $param ) {
 924+ if ( isset( $this->mParams[$param] ) ) {
 925+ $attribs[$param] = '';
 926+ }
 927+ }
 928+ }
 929+
 930+
 931+ return Html::element( 'textarea', $attribs, $value );
 932+ }
 933+}
 934+
889935 /**
890936 * A field that will contain a numeric value
891937 */

Status & tagging log