public static function element( $element, $attribs = null, $contents = '') {
$out = '<' . $element;
if( !is_null( $attribs ) ) {
- foreach( $attribs as $name => $val ) {
- $out .= ' ' . $name . '="' . Sanitizer::encodeAttribute( $val ) . '"';
- }
+ $out .= self::expandAttributes( $attribs );
}
if( is_null( $contents ) ) {
$out .= '>';
return $out;
}
+ /**
+ * Given an array of ('attributename' => 'value'), it generates the code
+ * to set the XML attributes : attributename="value".
+ * The values are passed to Sanitizer::encodeAttribute.
+ * Return null if no attributes given.
+ * @param $attribs Array of attributes for an XML element
+ */
+ private static function expandAttributes( $attribs ) {
+ if( is_null( $attribs ) ) {
+ return null;
+ } else {
+ $out = '';
+ foreach( $attribs as $name => $val ) {
+ $out .= ' ' . $name . '="' . Sanitizer::encodeAttribute( $val ) . '"';
+ }
+ return $out;
+ }
+ }
+
/**
* Format an XML element as with self::element(), but run text through the
* UtfNormal::cleanUp() validator first to ensure that no invalid UTF-8
return self::element( $element, $attribs, $contents );
}
- // Shortcuts
- public static function openElement( $element, $attribs = null ) { return self::element( $element, $attribs, null ); }
+ /** This open an XML element */
+ public static function openElement( $element, $attribs = null ) {
+ return '<' . $element . self::expandAttributes( $attribs ) . '>';
+ }
+
+ // Shortcut
public static function closeElement( $element ) { return "</$element>"; }
/**
* content you have is already valid xml.
*/
public static function tags( $element, $attribs = null, $contents ) {
- return self::element( $element, $attribs, null ) . $contents . "</$element>";
+ return self::openElement( $element, $attribs ) . $contents . "</$element>";
}
/**
*/
public static function namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false) {
global $wgContLang;
- if( $selected !== '' ) {
- if( is_null( $selected ) ) {
- // No namespace selected; let exact match work without hitting Main
- $selected = '';
- } else {
- // Let input be numeric strings without breaking the empty match.
- $selected = intval( $selected );
- }
- }
+ if( is_null( $selected ) )
+ $selected = '';
$s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n";
$arr = $wgContLang->getFormattedNamespaces();
if( !is_null($allnamespaces) ) {