r65786 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65785‎ | r65786 | r65787 >
Date:05:59, 2 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added escaping to smwfEncodeMessages, updated it's docs and made var names clearer
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -210,16 +210,19 @@
211211 /**
212212 * Formats an array of message strings so that it appears as a tooltip.
213213 * $icon should be one of: 'warning' (default), 'info'.
214 - * @note callers of this funcion must ensure safety, since the $icon string is
215 - * used in the output directly. This is not hard: $icon acts simply like an
216 - * enum, and callers have no need to compute it but use constant strings.
 214+ *
 215+ * @param array $messages
 216+ * @param string $icon Acts like an enum. Callers must ensure safety, since this value is used directly in the output.
 217+ * @param string $seperator
 218+ *
 219+ * @return string
217220 */
218 -function smwfEncodeMessages( $msgarray, $icon = 'warning', $sep = " <!--br-->" ) {
219 - if ( count( $msgarray ) > 0 ) {
 221+function smwfEncodeMessages( array $messages, $icon = 'warning', $seperator = ' <!--br-->' ) {
 222+ if ( count( $messages ) > 0 ) {
220223 SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
221 - $msgs = implode( $sep, $msgarray );
222 - return '<span class="smwttpersist"><span class="smwtticon">' . $icon . '.png</span><span class="smwttcontent">' . $msgs . '</span> </span>';
223 - // Note: the space is essential to make FF (and maybe other) align icons properly in tables
 224+ foreach( $messages as &$message ) $message = htmlspecialchars( $message );
 225+ $messageString = implode( $seperator, $messages );
 226+ return '<span class="smwttpersist"><span class="smwtticon">' . $icon . '.png</span><span class="smwttcontent">' . $messageString . '</span> </span>';
224227 } else {
225228 return '';
226229 }

Status & tagging log