http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71874

Revision: 71874
Author:   nikerabbit
Date:     2010-08-29 10:32:02 +0000 (Sun, 29 Aug 2010)

Log Message:
-----------
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: trunk/extensions/Translate/utils/MessageWebImporter.php
===================================================================
--- trunk/extensions/Translate/utils/MessageWebImporter.php     2010-08-29 
08:38:50 UTC (rev 71873)
+++ trunk/extensions/Translate/utils/MessageWebImporter.php     2010-08-29 
10:32:02 UTC (rev 71874)
@@ -169,13 +169,8 @@
                                $type = 'changed';
 
                                global $wgRequest;
+                               $action = $wgRequest->getVal( 
self::escapeNameForPHP( "action-$type-$key" ) );
 
-                               # Spaces don't seem to survive round trip in 
addition to dots
-                               # which are silently handled in getVal
-                               $safekey = str_replace( ' ', '_', $key );
-                               $safekey = str_replace( '.', '_', $key );
-                               $action = $wgRequest->getVal( 
"action-$type-$safekey" );
-
                                if ( $process ) {
                                        if ( !count( $changed ) ) {
                                                $changed[] = '<ul>';
@@ -221,7 +216,9 @@
 
                                foreach ( $actions as $action ) {
                                        $label = wfMsg( 
"translate-manage-action-$action" );
-                                       $act[] = Xml::radioLabel( $label, 
"action-$type-$key", $action, "action-$key-$action", $action === $defaction );
+                                       $name = self::escapeNameForPHP( 
"action-$type-$key" );
+                                       $id = Sanitizer::escapeId( 
"action-$key-$action" );
+                                       $act[] = Xml::radioLabel( $label, 
$nameid, $action, $id, $action === $defaction );
                                }
 
                                $name = wfMsg( 'translate-manage-import-diff',
@@ -434,10 +431,10 @@
        /**
         * Make section elements.
         *
-        * @param $legend \string Legend
-        * @param $type\string Contents of type class
-        * @param $content \string Contents
-        * @return \string Section element
+        * @param $legend \string Legend as raw html.
+        * @param $type \string Contents of type class.
+        * @param $content \string Contents as raw html.
+        * @return \string Section element as html.
         */
        public static function makeSectionElement( $legend, $type, $content ) {
                $containerParams = array( 'class' => "mw-tpt-sp-section 
mw-tpt-sp-section-type-{$type}" );
@@ -462,4 +459,28 @@
 
                return TRANSLATE_FUZZY . $message;
        }
+
+       /**
+        * Escape name such that it validates as name and id parameter in html, 
and
+        * so that we can get it back with WebRequest::getVal(). Especially dot 
and
+        * spaces are difficult for the latter.
+        * @param $name \string
+        * @return \string
+        */
+       public static function escapeNameForPHP( $name ) {
+               $replacements = array(
+                       "("  => '(OP)',
+                       " "  => '(SP)',
+                       "\t" => '(TAB)',
+                       "."  => '(DOT)',
+                       "'"  => '(SQ)',
+                       "\"" => '(DQ)',
+                       "%"  => '(PC)',
+                       "&"  => '(AMP)',
+               );
+
+               /* How nice of you PHP. No way to split array into keys and 
values in one
+                * function or have str_replace which takes one array? */
+               return str_replace( array_keys( $replacements ), array_values( 
$replacements ), $name );
+       }
 }



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to