Index: trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php |
— | — | @@ -44,12 +44,4 @@ |
45 | 45 | public function setOption( $option, $value ) { |
46 | 46 | return isset( $this->options[$option] ) ? $this->options[$option] = $value : null; |
47 | 47 | } |
48 | | - |
49 | | - public function renderElements() { |
50 | | - $elements = array(); |
51 | | - foreach ( $this->elements as $element ) { |
52 | | - $elements[] = $element->render(); |
53 | | - } |
54 | | - return $elements; |
55 | | - } |
56 | 48 | } |
Index: trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | */ |
32 | 32 | public function __construct( $filePath ) { |
33 | 33 | if ( !file_exists( $filePath ) ) { |
34 | | - throw new \MWException( sprintf( |
| 34 | + throw new MWException( sprintf( |
35 | 35 | 'Bad template file path error. "%s" is not a path to an existing file', $filePath |
36 | 36 | ) ); |
37 | 37 | } |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | */ |
47 | 47 | public function render( array $data = array() ) { |
48 | 48 | // Expand bindings to vars, just for this scope - escaped by default! |
49 | | - extract( self::escape( $data ) ); |
| 49 | + extract( self::encode( $data ) ); |
50 | 50 | // If $data had an element keyed as "data", then it's been shadowed, otherwise we need to |
51 | 51 | // unset it so the template doesn't start using the unescaped $data variable |
52 | 52 | if ( !isset( $data['data'] ) ) { |
— | — | @@ -59,35 +59,35 @@ |
60 | 60 | /* Static Methods */ |
61 | 61 | |
62 | 62 | /** |
63 | | - * Escapes data to be safely rendered in an HTML document as text (not code). |
| 63 | + * Encodes raw data to be safely rendered in an HTML document as text (not code). |
64 | 64 | * |
65 | | - * @param $data Mixed: Data to escape, either a string or array of strings |
66 | | - * @return Mixed: Escaped version of $data |
| 65 | + * @param $data Mixed: Data to encode, either a string or array of strings |
| 66 | + * @return Mixed: Encoded version of $data |
67 | 67 | */ |
68 | | - public static function escape( $data ) { |
| 68 | + public static function encode( $data ) { |
69 | 69 | if ( is_array( $data ) ) { |
70 | 70 | foreach ( array_keys( $data ) as $key ) { |
71 | | - $data[$key] = self::escape( $data[$key] ); |
| 71 | + $data[$key] = self::encode( $data[$key] ); |
72 | 72 | } |
73 | 73 | return $data; |
74 | 74 | } |
75 | | - return htmlspecialchars( (string) $data ); |
| 75 | + return is_string( $data ) ? htmlspecialchars( $data ) : $data; |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | | - * Unescapes data to be rendered in an HTML document as HTML (not text). |
| 79 | + * Decodes HTML-encoded data to be rendered in an HTML document as HTML (not text). |
80 | 80 | * |
81 | | - * @param $data Mixed: Data to unescape, either a string or array of strings |
82 | | - * @return Mixed: Unescaped version of $data |
| 81 | + * @param $data Mixed: Data to decoded, either a string or array of strings |
| 82 | + * @return Mixed: Decoded version of $data |
83 | 83 | */ |
84 | | - public static function unescape( $data ) { |
| 84 | + public static function decode( $data ) { |
85 | 85 | if ( is_array( $data ) ) { |
86 | 86 | foreach ( array_keys( $data ) as $key ) { |
87 | | - $data[$key] = self::unescape( $data[$key] ); |
| 87 | + $data[$key] = self::decode( $data[$key] ); |
88 | 88 | } |
89 | 89 | return $data; |
90 | 90 | } |
91 | | - return htmlspecialchars_decode( (string) $data ); |
| 91 | + return is_string( $data ) ? htmlspecialchars_decode( (string) $data ) : $data; |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
— | — | @@ -110,10 +110,10 @@ |
111 | 111 | foreach ( $data as $key => $value ) { |
112 | 112 | if ( is_array( $value ) ) { |
113 | 113 | // Named list of attributes |
114 | | - $result[] = self::escpae( $key ) . '="' . implode( ' ', (string) $value ) . '"'; |
| 114 | + $result[] = self::encode( $key ) . '="' . implode( ' ', (string) $value ) . '"'; |
115 | 115 | } else if ( is_string( $key ) ) { |
116 | 116 | // Named attribute |
117 | | - $result[] = self::escpae( $key ) . '="' . $value . '"'; |
| 117 | + $result[] = self::encode( $key ) . '="' . $value . '"'; |
118 | 118 | } else { |
119 | 119 | // Value-less attribute such as "checked" |
120 | 120 | $result[] = (string) $value; |
— | — | @@ -123,6 +123,6 @@ |
124 | 124 | // Value-less attribute such as "checked" |
125 | 125 | $result[] = (string) $value; |
126 | 126 | } |
127 | | - return count( $result ) ? ( ' ' . implode( ' ', $result ) ) : ''; |
| 127 | + echo count( $result ) ? ( ' ' . implode( ' ', $result ) ) : ''; |
128 | 128 | } |
129 | 129 | } |
Index: trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php |
— | — | @@ -1,3 +1,5 @@ |
2 | 2 | <fieldset class="htmlUiFieldset" rel="<?php echo $id ?>"> |
3 | | - <?php echo implode( self::unescape( $elements ) ) ?> |
| 3 | + <?php foreach( $elements as $element ) ?> |
| 4 | + <?php echo $element->render(); ?> |
| 5 | + <?php endforeach; ?> |
4 | 6 | </fieldset> |
Index: trunk/extensions/HtmlUi/templates/HtmlUiForm.php |
— | — | @@ -1,3 +1,5 @@ |
2 | | -<form class="htmlUiForm"<?php echo self::attributes( $attributes ) ?>> |
3 | | - <?php echo implode( self::unescape( $elements ) ) ?> |
| 2 | +<form class="htmlUiForm"<?php self::attributes( $attributes ) ?>> |
| 3 | + <?php foreach( $elements as $element ) ?> |
| 4 | + <?php echo $element->render(); ?> |
| 5 | + <?php endforeach; ?> |
4 | 6 | </form> |