(bug 47070) check content model namespace on import.
[lhc/web/wiklou.git] / includes / htmlform / HTMLSelectField.php
1 <?php
2 /**
3 * A select dropdown field. Basically a wrapper for Xmlselect class
4 */
5 class HTMLSelectField extends HTMLFormField {
6 function validate( $value, $alldata ) {
7 $p = parent::validate( $value, $alldata );
8
9 if ( $p !== true ) {
10 return $p;
11 }
12
13 $validOptions = HTMLFormField::flattenOptions( $this->mParams[ 'options' ] );
14
15 if ( in_array( $value, $validOptions ) ) {
16 return true;
17 } else {
18 return $this->msg( 'htmlform-select-badoption' )->parse();
19 }
20 }
21
22 function getInputHTML( $value ) {
23 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
24
25 # If one of the options' 'name' is int(0), it is automatically selected.
26 # because PHP sucks and thinks int(0) == 'some string'.
27 # Working around this by forcing all of them to strings.
28 foreach ( $this->mParams[ 'options' ] as &$opt ) {
29 if ( is_int( $opt ) ) {
30 $opt = strval( $opt );
31 }
32 }
33 unset( $opt ); # PHP keeps $opt around as a reference, which is a bit scary
34
35 if ( ! empty( $this->mParams[ 'disabled' ] ) ) {
36 $select->setAttribute( 'disabled', 'disabled' );
37 }
38
39 if ( $this->mClass !== '' ) {
40 $select->setAttribute( 'class', $this->mClass );
41 }
42
43 $select->addOptions( $this->mParams[ 'options' ] );
44
45 return $select->getHTML();
46 }
47 }