Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | # A mapping of 'type' inputs onto standard HTMLFormField subclasses |
53 | 53 | static $typeMappings = array( |
54 | 54 | 'text' => 'HTMLTextField', |
| 55 | + 'textarea' => 'HTMLTextAreaField', |
55 | 56 | 'select' => 'HTMLSelectField', |
56 | 57 | 'radio' => 'HTMLRadioField', |
57 | 58 | 'multiselect' => 'HTMLMultiSelectField', |
— | — | @@ -737,17 +738,7 @@ |
738 | 739 | $errors = Html::rawElement( 'span', array( 'class' => 'error' ), $errors ); |
739 | 740 | } |
740 | 741 | |
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(); |
752 | 743 | $html .= Html::rawElement( 'td', array( 'class' => 'mw-input' ), |
753 | 744 | $this->getInputHTML( $value ) ."\n$errors" ); |
754 | 745 | |
— | — | @@ -781,6 +772,17 @@ |
782 | 773 | function getLabel() { |
783 | 774 | return $this->mLabel; |
784 | 775 | } |
| 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 | + } |
785 | 787 | |
786 | 788 | function getDefault() { |
787 | 789 | if ( isset( $this->mDefault ) ) { |
— | — | @@ -874,9 +876,11 @@ |
875 | 877 | } |
876 | 878 | } |
877 | 879 | # Options that apply to HTML4 as well |
878 | | - switch( $this->mParams['type'] ){ |
| 880 | + switch( $this->mParams['type'] ) { |
| 881 | + # Pass through |
879 | 882 | case 'password': |
880 | | - $attribs['type'] = 'password'; |
| 883 | + case 'file': |
| 884 | + $attribs['type'] = $this->mParams['type']; |
881 | 885 | break; |
882 | 886 | } |
883 | 887 | } |
— | — | @@ -884,7 +888,49 @@ |
885 | 889 | return Html::element( 'input', $attribs ); |
886 | 890 | } |
887 | 891 | } |
| 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 | + ); |
888 | 913 | |
| 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 | + |
889 | 935 | /** |
890 | 936 | * A field that will contain a numeric value |
891 | 937 | */ |