Index: trunk/phase3/includes/Xml.php |
— | — | @@ -91,41 +91,37 @@ |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | | - * Create a namespace selector |
| 95 | + * Build a drop-down box for selecting a namespace |
96 | 96 | * |
97 | | - * @param $selected Mixed: the namespace which should be selected, default '' |
98 | | - * @param $allnamespaces String: value of a special item denoting all namespaces. Null to not include (default) |
99 | | - * @param $includehidden Bool: include hidden namespaces? |
100 | | - * @param array $exclude Array of namespace indexes to exclude |
101 | | - * @return String: Html string containing the namespace selector |
| 97 | + * @param mixed $selected Namespace which should be pre-selected |
| 98 | + * @param mixed $all Value of an item denoting all namespaces, or null to omit |
| 99 | + * @param bool $hidden Include hidden namespaces? [WTF? --RC] |
| 100 | + * @param array $exclude Array of indexes to exclude |
| 101 | + * @return string |
102 | 102 | */ |
103 | | - public static function namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false, $exclude = array() ) { |
| 103 | + public static function namespaceSelector( $selected = '', $all = null, $hidden = false, $exclude = array() ) { |
104 | 104 | global $wgContLang; |
105 | | - if( is_null( $selected ) ) |
106 | | - $selected = ''; |
107 | | - $s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n"; |
108 | | - $arr = $wgContLang->getFormattedNamespaces(); |
109 | | - if( !is_null($allnamespaces) ) { |
110 | | - $arr = array($allnamespaces => wfMsg('namespacesall')) + $arr; |
111 | | - } |
112 | | - foreach ($arr as $index => $name) { |
| 105 | + $namespaces = $wgContLang->getFormattedNamespaces(); |
| 106 | + $options = array(); |
| 107 | + |
| 108 | + if( !is_null( $all ) ) |
| 109 | + $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces; |
| 110 | + foreach( $namespaces as $index => $name ) { |
113 | 111 | if( $index < NS_MAIN || in_array( $index, $exclude ) ) |
114 | 112 | continue; |
115 | | - |
116 | | - $name = $index !== 0 ? $name : wfMsg('blanknamespace'); |
117 | | - |
118 | | - if ($index === $selected) { |
119 | | - $s .= "\t" . self::element("option", |
120 | | - array("value" => $index, "selected" => "selected"), |
121 | | - $name) . "\n"; |
122 | | - } else { |
123 | | - $s .= "\t" . self::element("option", array("value" => $index), $name) . "\n"; |
124 | | - } |
| 113 | + if( $index === 0 ) |
| 114 | + $name = wfMsg( 'blanknamespace' ); |
| 115 | + $options[] = self::option( $name, $index, $index === $selected ); |
125 | 116 | } |
126 | | - $s .= "</select>\n"; |
127 | | - return $s; |
| 117 | + |
| 118 | + return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => 'namespace', |
| 119 | + 'class' => 'namespaceselector' ) ) |
| 120 | + . "\n" |
| 121 | + . implode( "\n", $options ) |
| 122 | + . "\n" |
| 123 | + . Xml::closeElement( 'select' ); |
128 | 124 | } |
129 | | - |
| 125 | + |
130 | 126 | /** |
131 | 127 | * Create a date selector |
132 | 128 | * |