Remove patch-log_search-rename-index.sql from MW 1.16 updaters
[lhc/web/wiklou.git] / includes / XmlSelect.php
index 78f4764..89f2f41 100644 (file)
  */
 
 /**
- * Class for generating HTML <select> elements.
+ * Class for generating HTML <select> or <datalist> elements.
  */
 class XmlSelect {
-       protected $options = array();
+       protected $options = [];
        protected $default = false;
-       protected $attributes = array();
+       protected $tagName = 'select';
+       protected $attributes = [];
 
        public function __construct( $name = false, $id = false, $default = false ) {
                if ( $name ) {
@@ -49,6 +50,13 @@ class XmlSelect {
                $this->default = $default;
        }
 
+       /**
+        * @param string|array $tagName
+        */
+       public function setTagName( $tagName ) {
+               $this->tagName = $tagName;
+       }
+
        /**
         * @param string $name
         * @param string $value
@@ -75,7 +83,7 @@ class XmlSelect {
         */
        public function addOption( $label, $value = false ) {
                $value = $value !== false ? $value : $label;
-               $this->options[] = array( $label => $value );
+               $this->options[] = [ $label => $value ];
        }
 
        /**
@@ -104,7 +112,7 @@ class XmlSelect {
                foreach ( $options as $label => $value ) {
                        if ( is_array( $value ) ) {
                                $contents = self::formatOptions( $value, $default );
-                               $data .= Html::rawElement( 'optgroup', array( 'label' => $label ), $contents ) . "\n";
+                               $data .= Html::rawElement( 'optgroup', [ 'label' => $label ], $contents ) . "\n";
                        } else {
                                // If $default is an array, then the <select> probably has the multiple attribute,
                                // so we should check if each $value is in $default, rather than checking if
@@ -127,6 +135,6 @@ class XmlSelect {
                        $contents .= self::formatOptions( $options, $this->default );
                }
 
-               return Html::rawElement( 'select', $this->attributes, rtrim( $contents ) );
+               return Html::rawElement( $this->tagName, $this->attributes, rtrim( $contents ) );
        }
 }