r76180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76179‎ | r76180 | r76181 >
Date:03:40, 6 November 2010
Author:tparscal
Status:deferred
Tags:
Comment:
Moved encoding farther down - last thing to happen!
Modified paths:
  • /trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php (modified) (history)
  • /trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php (modified) (history)
  • /trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php (modified) (history)
  • /trunk/extensions/HtmlUi/templates/HtmlUiForm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php
@@ -44,12 +44,4 @@
4545 public function setOption( $option, $value ) {
4646 return isset( $this->options[$option] ) ? $this->options[$option] = $value : null;
4747 }
48 -
49 - public function renderElements() {
50 - $elements = array();
51 - foreach ( $this->elements as $element ) {
52 - $elements[] = $element->render();
53 - }
54 - return $elements;
55 - }
5648 }
Index: trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php
@@ -30,7 +30,7 @@
3131 */
3232 public function __construct( $filePath ) {
3333 if ( !file_exists( $filePath ) ) {
34 - throw new \MWException( sprintf(
 34+ throw new MWException( sprintf(
3535 'Bad template file path error. "%s" is not a path to an existing file', $filePath
3636 ) );
3737 }
@@ -45,7 +45,7 @@
4646 */
4747 public function render( array $data = array() ) {
4848 // Expand bindings to vars, just for this scope - escaped by default!
49 - extract( self::escape( $data ) );
 49+ extract( self::encode( $data ) );
5050 // If $data had an element keyed as "data", then it's been shadowed, otherwise we need to
5151 // unset it so the template doesn't start using the unescaped $data variable
5252 if ( !isset( $data['data'] ) ) {
@@ -59,35 +59,35 @@
6060 /* Static Methods */
6161
6262 /**
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).
6464 *
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
6767 */
68 - public static function escape( $data ) {
 68+ public static function encode( $data ) {
6969 if ( is_array( $data ) ) {
7070 foreach ( array_keys( $data ) as $key ) {
71 - $data[$key] = self::escape( $data[$key] );
 71+ $data[$key] = self::encode( $data[$key] );
7272 }
7373 return $data;
7474 }
75 - return htmlspecialchars( (string) $data );
 75+ return is_string( $data ) ? htmlspecialchars( $data ) : $data;
7676 }
7777
7878 /**
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).
8080 *
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
8383 */
84 - public static function unescape( $data ) {
 84+ public static function decode( $data ) {
8585 if ( is_array( $data ) ) {
8686 foreach ( array_keys( $data ) as $key ) {
87 - $data[$key] = self::unescape( $data[$key] );
 87+ $data[$key] = self::decode( $data[$key] );
8888 }
8989 return $data;
9090 }
91 - return htmlspecialchars_decode( (string) $data );
 91+ return is_string( $data ) ? htmlspecialchars_decode( (string) $data ) : $data;
9292 }
9393
9494 /**
@@ -110,10 +110,10 @@
111111 foreach ( $data as $key => $value ) {
112112 if ( is_array( $value ) ) {
113113 // Named list of attributes
114 - $result[] = self::escpae( $key ) . '="' . implode( ' ', (string) $value ) . '"';
 114+ $result[] = self::encode( $key ) . '="' . implode( ' ', (string) $value ) . '"';
115115 } else if ( is_string( $key ) ) {
116116 // Named attribute
117 - $result[] = self::escpae( $key ) . '="' . $value . '"';
 117+ $result[] = self::encode( $key ) . '="' . $value . '"';
118118 } else {
119119 // Value-less attribute such as "checked"
120120 $result[] = (string) $value;
@@ -123,6 +123,6 @@
124124 // Value-less attribute such as "checked"
125125 $result[] = (string) $value;
126126 }
127 - return count( $result ) ? ( ' ' . implode( ' ', $result ) ) : '';
 127+ echo count( $result ) ? ( ' ' . implode( ' ', $result ) ) : '';
128128 }
129129 }
Index: trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php
@@ -1,3 +1,5 @@
22 <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; ?>
46 </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; ?>
46 </form>

Status & tagging log