Rewrite Xml::namespaceSelector() before it drives me to totemize somebody.
authorRob Church <robchurch@users.mediawiki.org>
Sat, 4 Aug 2007 12:50:43 +0000 (12:50 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Sat, 4 Aug 2007 12:50:43 +0000 (12:50 +0000)
includes/Xml.php

index 8f178f5..a35d21b 100644 (file)
@@ -91,41 +91,37 @@ class Xml {
        }
 
        /**
-        * Create a namespace selector
+        * Build a drop-down box for selecting a namespace
         *
-        * @param $selected Mixed: the namespace which should be selected, default ''
-        * @param $allnamespaces String: value of a special item denoting all namespaces. Null to not include (default)
-        * @param $includehidden Bool: include hidden namespaces?
-        * @param array $exclude Array of namespace indexes to exclude
-        * @return String: Html string containing the namespace selector
+        * @param mixed $selected Namespace which should be pre-selected
+        * @param mixed $all Value of an item denoting all namespaces, or null to omit
+        * @param bool $hidden Include hidden namespaces? [WTF? --RC]
+        * @param array $exclude Array of indexes to exclude
+        * @return string
         */
-       public static function namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false, $exclude = array() ) {
+       public static function namespaceSelector( $selected = '', $all = null, $hidden = false, $exclude = array() ) {
                global $wgContLang;
-               if( is_null( $selected ) )
-                       $selected = '';
-               $s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n";
-               $arr = $wgContLang->getFormattedNamespaces();
-               if( !is_null($allnamespaces) ) {
-                       $arr = array($allnamespaces => wfMsg('namespacesall')) + $arr;
-               }
-               foreach ($arr as $index => $name) {
+               $namespaces = $wgContLang->getFormattedNamespaces();
+               $options = array();
+               
+               if( !is_null( $all ) )
+                       $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces;
+               foreach( $namespaces as $index => $name ) {
                        if( $index < NS_MAIN || in_array( $index, $exclude ) )
                                continue;
-
-                       $name = $index !== 0 ? $name : wfMsg('blanknamespace');
-
-                       if ($index === $selected) {
-                               $s .= "\t" . self::element("option",
-                                               array("value" => $index, "selected" => "selected"),
-                                               $name) . "\n";
-                       } else {
-                               $s .= "\t" . self::element("option", array("value" => $index), $name) . "\n";
-                       }
+                       if( $index === 0 )
+                               $name = wfMsg( 'blanknamespace' );
+                       $options[] = self::option( $name, $index, $index === $selected );
                }
-               $s .= "</select>\n";
-               return $s;
+               
+               return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace',
+                       'class' => 'namespaceselector' ) )
+                       . "\n"
+                       . implode( "\n", $options )
+                       . "\n"
+                       . Xml::closeElement( 'select' );
        }
-       
+               
        /**
        * Create a date selector         
        *