* Added code two commonly needed use cases: separate label and input, and select
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 10 May 2008 13:44:25 +0000 (13:44 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Sat, 10 May 2008 13:44:25 +0000 (13:44 +0000)
includes/Xml.php

index 84b5210..7dad20f 100644 (file)
@@ -264,9 +264,15 @@ class Xml {
         * @return string HTML
         */
        public static function inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=array() ) {
-               return Xml::label( $label, $id ) .
-                       '&nbsp;' .
-                       self::input( $name, $size, $value, array( 'id' => $id ) + $attribs );
+               list( $label, $input ) = self::inputLabelSep( $label, $name, $id, $size, $value, $attribs );
+               return $label . '&nbsp;' . $input;
+       }
+
+       public static function inputLabelSep( $label, $name, $id, $size=false, $value=false, $attribs=array() ) {
+               return array(
+                       Xml::label( $label, $id ),
+                       self::input( $name, $size, $value, array( 'id' => $id ) + $attribs )
+               );
        }
 
        /**
@@ -550,3 +556,33 @@ class Xml {
                return $form;
        }
 }
+
+class XMLSelect {
+       protected $options = array();
+       protected $default = false;
+       protected $attributes = array();
+
+       public function __construct( $name = false, $id = false, $default = false ) {
+               if ( $name ) $this->setAttribute( 'name', $name );
+               if ( $id ) $this->setAttribute( 'id', $id );
+               if ( $default ) $this->default = $default;
+       }
+
+       public function setDefault( $default ) {
+               $this->default = $default;
+       }
+
+       public function setAttribute( $name, $value ) {
+               $this->attributes[$name] = $value;
+       }
+
+       public function addOption( $name, $value = false ) {
+               $value = $value ? $value : $name;
+               $this->options[] = Xml::option( $name, $value, $value === $this->default );
+       }
+
+       public function getHTML() {
+               return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );
+       }
+
+}
\ No newline at end of file