http://www.mediawiki.org/wiki/Special:Code/MediaWiki/76180
Revision: 76180
Author: tparscal
Date: 2010-11-06 03:40:13 +0000 (Sat, 06 Nov 2010)
Log Message:
-----------
Moved encoding farther down - last thing to happen!
Modified Paths:
--------------
trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php
trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php
trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php
trunk/extensions/HtmlUi/templates/HtmlUiForm.php
Modified: trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php
===================================================================
--- trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php
2010-11-06 01:34:47 UTC (rev 76179)
+++ trunk/extensions/HtmlUi/classes/HtmlUiFormElementCollection.php
2010-11-06 03:40:13 UTC (rev 76180)
@@ -44,12 +44,4 @@
public function setOption( $option, $value ) {
return isset( $this->options[$option] ) ?
$this->options[$option] = $value : null;
}
-
- public function renderElements() {
- $elements = array();
- foreach ( $this->elements as $element ) {
- $elements[] = $element->render();
- }
- return $elements;
- }
}
Modified: trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php
===================================================================
--- trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php 2010-11-06 01:34:47 UTC
(rev 76179)
+++ trunk/extensions/HtmlUi/classes/HtmlUiTemplate.php 2010-11-06 03:40:13 UTC
(rev 76180)
@@ -30,7 +30,7 @@
*/
public function __construct( $filePath ) {
if ( !file_exists( $filePath ) ) {
- throw new \MWException( sprintf(
+ throw new MWException( sprintf(
'Bad template file path error. "%s" is not a
path to an existing file', $filePath
) );
}
@@ -45,7 +45,7 @@
*/
public function render( array $data = array() ) {
// Expand bindings to vars, just for this scope - escaped by
default!
- extract( self::escape( $data ) );
+ extract( self::encode( $data ) );
// If $data had an element keyed as "data", then it's been
shadowed, otherwise we need to
// unset it so the template doesn't start using the unescaped
$data variable
if ( !isset( $data['data'] ) ) {
@@ -59,35 +59,35 @@
/* Static Methods */
/**
- * Escapes data to be safely rendered in an HTML document as text (not
code).
+ * Encodes raw data to be safely rendered in an HTML document as text
(not code).
*
- * @param $data Mixed: Data to escape, either a string or array of
strings
- * @return Mixed: Escaped version of $data
+ * @param $data Mixed: Data to encode, either a string or array of
strings
+ * @return Mixed: Encoded version of $data
*/
- public static function escape( $data ) {
+ public static function encode( $data ) {
if ( is_array( $data ) ) {
foreach ( array_keys( $data ) as $key ) {
- $data[$key] = self::escape( $data[$key] );
+ $data[$key] = self::encode( $data[$key] );
}
return $data;
}
- return htmlspecialchars( (string) $data );
+ return is_string( $data ) ? htmlspecialchars( $data ) : $data;
}
/**
- * Unescapes data to be rendered in an HTML document as HTML (not text).
+ * Decodes HTML-encoded data to be rendered in an HTML document as HTML
(not text).
*
- * @param $data Mixed: Data to unescape, either a string or array of
strings
- * @return Mixed: Unescaped version of $data
+ * @param $data Mixed: Data to decoded, either a string or array of
strings
+ * @return Mixed: Decoded version of $data
*/
- public static function unescape( $data ) {
+ public static function decode( $data ) {
if ( is_array( $data ) ) {
foreach ( array_keys( $data ) as $key ) {
- $data[$key] = self::unescape( $data[$key] );
+ $data[$key] = self::decode( $data[$key] );
}
return $data;
}
- return htmlspecialchars_decode( (string) $data );
+ return is_string( $data ) ? htmlspecialchars_decode( (string)
$data ) : $data;
}
/**
@@ -110,10 +110,10 @@
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
// Named list of attributes
- $result[] = self::escpae( $key ) . '="'
. implode( ' ', (string) $value ) . '"';
+ $result[] = self::encode( $key ) . '="'
. implode( ' ', (string) $value ) . '"';
} else if ( is_string( $key ) ) {
// Named attribute
- $result[] = self::escpae( $key ) . '="'
. $value . '"';
+ $result[] = self::encode( $key ) . '="'
. $value . '"';
} else {
// Value-less attribute such as
"checked"
$result[] = (string) $value;
@@ -123,6 +123,6 @@
// Value-less attribute such as "checked"
$result[] = (string) $value;
}
- return count( $result ) ? ( ' ' . implode( ' ', $result ) ) :
'';
+ echo count( $result ) ? ( ' ' . implode( ' ', $result ) ) : '';
}
}
Modified: trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php
===================================================================
--- trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php 2010-11-06
01:34:47 UTC (rev 76179)
+++ trunk/extensions/HtmlUi/templates/HtmlUiFieldset.php 2010-11-06
03:40:13 UTC (rev 76180)
@@ -1,3 +1,5 @@
<fieldset class="htmlUiFieldset" rel="<?php echo $id ?>">
- <?php echo implode( self::unescape( $elements ) ) ?>
+ <?php foreach( $elements as $element ) ?>
+ <?php echo $element->render(); ?>
+ <?php endforeach; ?>
</fieldset>
Modified: trunk/extensions/HtmlUi/templates/HtmlUiForm.php
===================================================================
--- trunk/extensions/HtmlUi/templates/HtmlUiForm.php 2010-11-06 01:34:47 UTC
(rev 76179)
+++ trunk/extensions/HtmlUi/templates/HtmlUiForm.php 2010-11-06 03:40:13 UTC
(rev 76180)
@@ -1,3 +1,5 @@
-<form class="htmlUiForm"<?php echo self::attributes( $attributes ) ?>>
- <?php echo implode( self::unescape( $elements ) ) ?>
+<form class="htmlUiForm"<?php self::attributes( $attributes ) ?>>
+ <?php foreach( $elements as $element ) ?>
+ <?php echo $element->render(); ?>
+ <?php endforeach; ?>
</form>
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs