PHP Sucks. Having a value of 0 was making $value appear as false, so you couldn't...
[lhc/web/wiklou.git] / includes / Xml.php
index 4feff6d..05e93bc 100644 (file)
@@ -14,9 +14,10 @@ class Xml {
         * @param $element String: element name
         * @param $attribs Array: Name=>value pairs. Values will be escaped.
         * @param $contents String: NULL to make an open tag only; '' for a contentless closed tag (default)
+        * @param $allowShortTag Bool: whether '' in $contents will result in a contentless closed tag
         * @return string
         */
-       public static function element( $element, $attribs = null, $contents = '') {
+       public static function element( $element, $attribs = null, $contents = '', $allowShortTag = true ) {
                $out = '<' . $element;
                if( !is_null( $attribs ) ) {
                        $out .=  self::expandAttributes( $attribs );
@@ -24,7 +25,7 @@ class Xml {
                if( is_null( $contents ) ) {
                        $out .= '>';
                } else {
-                       if( $contents === '' ) {
+                       if( $allowShortTag && $contents === '' ) {
                                $out .= ' />';
                        } else {
                                $out .= '>' . htmlspecialchars( $contents ) . "</$element>";
@@ -40,7 +41,7 @@ class Xml {
         * Return null if no attributes given.
         * @param $attribs Array of attributes for an XML element
         */
-       private static function expandAttributes( $attribs ) {
+       public static function expandAttributes( $attribs ) {
                $out = '';
                if( is_null( $attribs ) ) {
                        return null;
@@ -489,7 +490,7 @@ class Xml {
                                                'cols' => $cols,
                                                'rows' => $rows
                                        ) + $attribs,
-                                       $content );
+                                       $content, false );
        }
 
        /**
@@ -638,7 +639,7 @@ class Xml {
                        $id = "mw-$labelmsg";
                        
                        $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
-                       $form .= Xml::tags( 'td', array('valign'=>'top','align' => 'right'), wfMsgExt( $labelmsg, array('parseinline') ) );
+                       $form .= Xml::tags( 'td', array('class' => 'mw-label'), wfMsgExt( $labelmsg, array('parseinline') ) );
                        $form .= Xml::openElement( 'td' ) . $input . Xml::closeElement( 'td' );
                        $form .= Xml::closeElement( 'tr' );
                }
@@ -673,7 +674,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 );
        }
 
@@ -681,4 +683,4 @@ class XmlSelect {
                return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) );
        }
 
-}
\ No newline at end of file
+}