summaryrefslogtreecommitdiff
path: root/includes/Xml.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/Xml.php')
-rw-r--r--includes/Xml.php67
1 files changed, 66 insertions, 1 deletions
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
@@ -322,6 +330,63 @@ class Xml {
}
/**
+ * 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.
* Illegal control characters are assumed not to be present.