r71874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71873‎ | r71874 | r71875 >
Date:10:32, 29 August 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Implement own key escaping in order to have keys that validate in html and are not screwed by php
Modified paths:
  • /trunk/extensions/Translate/utils/MessageWebImporter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/MessageWebImporter.php
@@ -169,13 +169,8 @@
170170 $type = 'changed';
171171
172172 global $wgRequest;
 173+ $action = $wgRequest->getVal( self::escapeNameForPHP( "action-$type-$key" ) );
173174
174 - # Spaces don't seem to survive round trip in addition to dots
175 - # which are silently handled in getVal
176 - $safekey = str_replace( ' ', '_', $key );
177 - $safekey = str_replace( '.', '_', $key );
178 - $action = $wgRequest->getVal( "action-$type-$safekey" );
179 -
180175 if ( $process ) {
181176 if ( !count( $changed ) ) {
182177 $changed[] = '<ul>';
@@ -221,7 +216,9 @@
222217
223218 foreach ( $actions as $action ) {
224219 $label = wfMsg( "translate-manage-action-$action" );
225 - $act[] = Xml::radioLabel( $label, "action-$type-$key", $action, "action-$key-$action", $action === $defaction );
 220+ $name = self::escapeNameForPHP( "action-$type-$key" );
 221+ $id = Sanitizer::escapeId( "action-$key-$action" );
 222+ $act[] = Xml::radioLabel( $label, $nameid, $action, $id, $action === $defaction );
226223 }
227224
228225 $name = wfMsg( 'translate-manage-import-diff',
@@ -434,10 +431,10 @@
435432 /**
436433 * Make section elements.
437434 *
438 - * @param $legend \string Legend
439 - * @param $type\string Contents of type class
440 - * @param $content \string Contents
441 - * @return \string Section element
 435+ * @param $legend \string Legend as raw html.
 436+ * @param $type \string Contents of type class.
 437+ * @param $content \string Contents as raw html.
 438+ * @return \string Section element as html.
442439 */
443440 public static function makeSectionElement( $legend, $type, $content ) {
444441 $containerParams = array( 'class' => "mw-tpt-sp-section mw-tpt-sp-section-type-{$type}" );
@@ -462,4 +459,28 @@
463460
464461 return TRANSLATE_FUZZY . $message;
465462 }
 463+
 464+ /**
 465+ * Escape name such that it validates as name and id parameter in html, and
 466+ * so that we can get it back with WebRequest::getVal(). Especially dot and
 467+ * spaces are difficult for the latter.
 468+ * @param $name \string
 469+ * @return \string
 470+ */
 471+ public static function escapeNameForPHP( $name ) {
 472+ $replacements = array(
 473+ "(" => '(OP)',
 474+ " " => '(SP)',
 475+ "\t" => '(TAB)',
 476+ "." => '(DOT)',
 477+ "'" => '(SQ)',
 478+ "\"" => '(DQ)',
 479+ "%" => '(PC)',
 480+ "&" => '(AMP)',
 481+ );
 482+
 483+ /* How nice of you PHP. No way to split array into keys and values in one
 484+ * function or have str_replace which takes one array? */
 485+ return str_replace( array_keys( $replacements ), array_values( $replacements ), $name );
 486+ }
466487 }

Status & tagging log