*/
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;
}
/**
* @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 ) {
$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 )