From 086ae52d12011746a75f5588e877347bc0457352 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 21 Mar 2008 11:49:34 +0100 Subject: Update auf MediaWiki 1.12.0 --- includes/Xml.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'includes/Xml.php') diff --git a/includes/Xml.php b/includes/Xml.php index fe4bb0cd..6689a4a4 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -104,6 +104,14 @@ class Xml { $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 ) { @@ -301,7 +309,7 @@ class Xml { 'type' => 'hidden', 'value' => $value ) + $attribs ); } - + /** * Convenience function to build an HTML drop-down list item. * @param $text String: text for this item @@ -321,6 +329,63 @@ class Xml { return self::element( 'option', $attribs, $text ); } + /** + * Build a drop-down box from a textual list. + * + * @param mixed $name Name and id for the drop-down + * @param mixed $class CSS classes for the drop-down + * @param mixed $other Text for the "Other reasons" option + * @param mixed $list Correctly formatted text to be used to generate the options + * @param mixed $selected Option which should be pre-selected + * @return string + */ + public static function listDropDown( $name= '', $list = '', $other = '', $selected = '', $class = '', $tabindex = Null ) { + $options = ''; + $optgroup = false; + + $options = self::option( $other, 'other', $selected === 'other' ); + + foreach ( explode( "\n", $list ) as $option) { + $value = trim( $option ); + if ( $value == '' ) { + continue; + } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) { + // A new group is starting ... + $value = trim( substr( $value, 1 ) ); + if( $optgroup ) $options .= self::closeElement('optgroup'); + $options .= self::openElement( 'optgroup', array( 'label' => $value ) ); + $optgroup = true; + } elseif ( substr( $value, 0, 2) == '**' ) { + // groupmember + $value = trim( substr( $value, 2 ) ); + $options .= self::option( $value, $value, $selected === $value ); + } else { + // groupless reason list + if( $optgroup ) $options .= self::closeElement('optgroup'); + $options .= self::option( $value, $value, $selected === $value ); + $optgroup = false; + } + } + if( $optgroup ) $options .= self::closeElement('optgroup'); + + $attribs = array(); + if( $name ) { + $attribs['id'] = $name; + $attribs['name'] = $name; + } + if( $class ) { + $attribs['class'] = $class; + } + if( $tabindex ) { + $attribs['tabindex'] = $tabindex; + } + return Xml::openElement( 'select', $attribs ) + . "\n" + . $options + . "\n" + . Xml::closeElement( 'select' ); + } + /** * Returns an escaped string suitable for inclusion in a string literal * for JavaScript source code. -- cgit v1.2.2