Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | $attribs = array( 'name' => $selectname ); |
136 | 136 | } |
137 | 137 | $attribs['style'] = 'width: 100%'; |
138 | | - $out .= wfElement( 'select', $attribs, null ); |
| 138 | + $out .= wfOpenElement( 'select', $attribs ); |
139 | 139 | |
140 | 140 | foreach( $groups as $group ) { |
141 | 141 | $attribs = array( 'value' => $group ); |
Index: trunk/phase3/includes/Xml.php |
— | — | @@ -19,9 +19,7 @@ |
20 | 20 | public static function element( $element, $attribs = null, $contents = '') { |
21 | 21 | $out = '<' . $element; |
22 | 22 | if( !is_null( $attribs ) ) { |
23 | | - foreach( $attribs as $name => $val ) { |
24 | | - $out .= ' ' . $name . '="' . Sanitizer::encodeAttribute( $val ) . '"'; |
25 | | - } |
| 23 | + $out .= self::expandAttributes( $attribs ); |
26 | 24 | } |
27 | 25 | if( is_null( $contents ) ) { |
28 | 26 | $out .= '>'; |
— | — | @@ -36,6 +34,25 @@ |
37 | 35 | } |
38 | 36 | |
39 | 37 | /** |
| 38 | + * Given an array of ('attributename' => 'value'), it generates the code |
| 39 | + * to set the XML attributes : attributename="value". |
| 40 | + * The values are passed to Sanitizer::encodeAttribute. |
| 41 | + * Return null if no attributes given. |
| 42 | + * @param $attribs Array of attributes for an XML element |
| 43 | + */ |
| 44 | + private static function expandAttributes( $attribs ) { |
| 45 | + if( is_null( $attribs ) ) { |
| 46 | + return null; |
| 47 | + } else { |
| 48 | + $out = ''; |
| 49 | + foreach( $attribs as $name => $val ) { |
| 50 | + $out .= ' ' . $name . '="' . Sanitizer::encodeAttribute( $val ) . '"'; |
| 51 | + } |
| 52 | + return $out; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + /** |
40 | 57 | * Format an XML element as with self::element(), but run text through the |
41 | 58 | * UtfNormal::cleanUp() validator first to ensure that no invalid UTF-8 |
42 | 59 | * is passed. |
— | — | @@ -57,8 +74,12 @@ |
58 | 75 | return self::element( $element, $attribs, $contents ); |
59 | 76 | } |
60 | 77 | |
61 | | - // Shortcuts |
62 | | - public static function openElement( $element, $attribs = null ) { return self::element( $element, $attribs, null ); } |
| 78 | + /** This open an XML element */ |
| 79 | + public static function openElement( $element, $attribs = null ) { |
| 80 | + return '<' . $element . self::expandAttributes( $attribs ) . '>'; |
| 81 | + } |
| 82 | + |
| 83 | + // Shortcut |
63 | 84 | public static function closeElement( $element ) { return "</$element>"; } |
64 | 85 | |
65 | 86 | /** |
— | — | @@ -66,7 +87,7 @@ |
67 | 88 | * content you have is already valid xml. |
68 | 89 | */ |
69 | 90 | public static function tags( $element, $attribs = null, $contents ) { |
70 | | - return self::element( $element, $attribs, null ) . $contents . "</$element>"; |
| 91 | + return self::openElement( $element, $attribs ) . $contents . "</$element>"; |
71 | 92 | } |
72 | 93 | |
73 | 94 | /** |