Clarifying unorthodox MIME type
[lhc/web/wiklou.git] / includes / Xml.php
index e0548ed..650ad04 100644 (file)
@@ -42,11 +42,15 @@ class Xml {
         */
        private static function expandAttributes( $attribs ) {
                $out = '';
-               if( is_array( $attribs ) ) {
+               if( is_null( $attribs ) ) {
+                       return null;
+               } elseif( is_array( $attribs ) ) {
                        foreach( $attribs as $name => $val )
                                $out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"';
+                       return $out;
+               } else {
+                       throw new MWException( 'Expected attribute array, got something else in ' . __METHOD__ );
                }
-               return $out;
        }
 
        /**
@@ -95,11 +99,19 @@ class Xml {
         * @param bool $hidden Include hidden namespaces? [WTF? --RC]
         * @return string
         */
-       public static function namespaceSelector( $selected = '', $all = null, $hidden = false ) {
+       public static function namespaceSelector( $selected = '', $all = null, $hidden = false, $element_name = 'namespace' ) {
                global $wgContLang;
                $namespaces = $wgContLang->getFormattedNamespaces();
                $options = array();
                
+               // Godawful hack... we'll be frequently passed selected namespaces
+               // as strings since PHP is such a shithole.
+               // But we also don't want blanks and nulls and "all"s matching 0,
+               // so let's convert *just* string ints to clean ints.
+               if( preg_match( '/^\d+$/', $selected ) ) {
+                       $selected = intval( $selected );
+               }
+               
                if( !is_null( $all ) )
                        $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces;
                foreach( $namespaces as $index => $name ) {
@@ -110,7 +122,7 @@ class Xml {
                        $options[] = self::option( $name, $index, $index === $selected );
                }
                
-               return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace',
+               return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => $element_name,
                        'class' => 'namespaceselector' ) )
                        . "\n"
                        . implode( "\n", $options )