From b9b85843572bf283f48285001e276ba7e61b63f6 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Feb 2009 13:37:51 +0100 Subject: updated to MediaWiki 1.14.0 --- includes/Xml.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'includes/Xml.php') diff --git a/includes/Xml.php b/includes/Xml.php index 32a68251..68990d86 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -112,11 +112,11 @@ class Xml { * * @param $selected Mixed: Namespace which should be pre-selected * @param $all Mixed: Value of an item denoting all namespaces, or null to omit - * @param $hidden Mixed: Include hidden namespaces? [WTF? --RC] * @param $element_name String: value of the "name" attribute of the select tag + * @param $label String: optional label to add to the field * @return string */ - public static function namespaceSelector( $selected = '', $all = null, $hidden = false, $element_name = 'namespace' ) { + public static function namespaceSelector( $selected = '', $all = null, $element_name = 'namespace', $label = null ) { global $wgContLang; $namespaces = $wgContLang->getFormattedNamespaces(); $options = array(); @@ -139,12 +139,16 @@ class Xml { $options[] = self::option( $name, $index, $index === $selected ); } - return Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => $element_name, + $ret = Xml::openElement( 'select', array( 'id' => 'namespace', 'name' => $element_name, 'class' => 'namespaceselector' ) ) . "\n" . implode( "\n", $options ) . "\n" . Xml::closeElement( 'select' ); + if ( !is_null( $label ) ) { + $ret = Xml::label( $label, $element_name ) . ' ' . $ret; + } + return $ret; } /** @@ -640,18 +644,63 @@ class Xml { $form .= Xml::openElement( 'tr', array( 'id' => $id ) ); $form .= Xml::tags( 'td', array('class' => 'mw-label'), wfMsgExt( $labelmsg, array('parseinline') ) ); - $form .= Xml::openElement( 'td' ) . $input . Xml::closeElement( 'td' ); + $form .= Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . $input . Xml::closeElement( 'td' ); + $form .= Xml::closeElement( 'tr' ); + } + + if( $submitLabel ) { + $form .= Xml::openElement( 'tr', array( 'id' => $id ) ); + $form .= Xml::tags( 'td', array(), '' ); + $form .= Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) . Xml::submitButton( wfMsg( $submitLabel ) ) . Xml::closeElement( 'td' ); $form .= Xml::closeElement( 'tr' ); } $form .= ""; - - if ($submitLabel) { - $form .= Xml::submitButton( wfMsg($submitLabel) ); - } + return $form; } + + /** + * Build a table of data + * @param array $rows An array of arrays of strings, each to be a row in a table + * @param array $attribs Attributes to apply to the table tag [optional] + * @param array $headers An array of strings to use as table headers [optional] + * @return string + */ + public static function buildTable( $rows, $attribs = array(), $headers = null ) { + $s = Xml::openElement( 'table', $attribs ); + if ( is_array( $headers ) ) { + foreach( $headers as $id => $header ) { + $attribs = array(); + if ( is_string( $id ) ) $attribs['id'] = $id; + $s .= Xml::element( 'th', $attribs, $header ); + } + } + foreach( $rows as $id => $row ) { + $attribs = array(); + if ( is_string( $id ) ) $attribs['id'] = $id; + $s .= Xml::buildTableRow( $attribs, $row ); + } + $s .= Xml::closeElement( 'table' ); + return $s; + } + + /** + * Build a row for a table + * @param array $cells An array of strings to put in + * @return string + */ + public static function buildTableRow( $attribs, $cells ) { + $s = Xml::openElement( 'tr', $attribs ); + foreach( $cells as $id => $cell ) { + $attribs = array(); + if ( is_string( $id ) ) $attribs['id'] = $id; + $s .= Xml::element( 'td', $attribs, $cell ); + } + $s .= Xml::closeElement( 'tr' ); + return $s; + } } class XmlSelect { @@ -674,7 +723,8 @@ class XmlSelect { } public function addOption( $name, $value = false ) { - $value = $value ? $value : $name; + // Stab stab stab + $value = ($value !== false) ? $value : $name; $this->options[] = Xml::option( $name, $value, $value === $this->default ); } @@ -682,4 +732,4 @@ class XmlSelect { return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) ); } -} \ No newline at end of file +} -- cgit v1.2.2