gen=js has the wrong cache properties for language-dependent text. Moved wgAjaxWatch...
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 5 Jul 2007 13:57:54 +0000 (13:57 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 5 Jul 2007 13:57:54 +0000 (13:57 +0000)
includes/Skin.php
includes/Xml.php

index a23e7c9..05dd7d2 100644 (file)
@@ -297,6 +297,7 @@ class Skin extends Linker {
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
                global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
                global $wgBreakFrames, $wgRequest;
+               global $wgUseAjax, $wgAjaxWatch;
 
                $ns = $wgTitle->getNamespace();
                $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
@@ -334,6 +335,15 @@ class Skin extends Linker {
                        $vars['wgLivepreviewMessageError']   = wfMsg( 'livepreview-error' );
                }
 
+               if($wgUseAjax && $wgAjaxWatch) {
+                       $msgNames = array( 'watch', 'unwatch', 'watching', 'unwatching' );
+                       $msgs = (object)array();
+                       foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
+                               $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
+                       }
+                       $vars['wgAjaxWatch'] = $msgs;
+               }
+
                return self::makeVariablesScript( $vars );
        }
 
@@ -419,20 +429,6 @@ class Skin extends Linker {
                if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
                        $s .= $commonJs;
                }
-
-               global $wgUseAjax, $wgAjaxWatch;
-               if($wgUseAjax && $wgAjaxWatch) {
-                       $s .= "
-
-/* AJAX (un)watch (see /skins/common/ajaxwatch.js) */
-var wgAjaxWatch = {
-       watchMsg: '".       str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."',
-       unwatchMsg: '".     str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."',
-       watchingMsg: '".    str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."',
-       unwatchingMsg: '".  str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."'
-};";
-               }
-
                wfProfileOut( __METHOD__ );
                return $s;
        }
index 86a28d2..1eeba94 100644 (file)
@@ -330,7 +330,9 @@ class Xml {
 
        /**
         * Encode a variable of unknown type to JavaScript.
-        * Doesn't support hashtables just yet.
+        * Arrays are converted to JS arrays, objects are converted to JS associative 
+        * arrays (objects). So cast your PHP associative arrays to objects before 
+        * passing them to here.
         */
        public static function encodeJsVar( $value ) {
                if ( is_bool( $value ) ) {
@@ -341,13 +343,23 @@ class Xml {
                        $s = $value;
                } elseif ( is_array( $value ) ) {
                        $s = '[';
-                       foreach ( $value as $name => $elt ) {
+                       foreach ( $value as $elt ) {
                                if ( $s != '[' ) {
                                        $s .= ', ';
                                }
                                $s .= self::encodeJsVar( $elt );
                        }
                        $s .= ']';
+               } elseif ( is_object( $value ) ) {
+                       $s = '{';
+                       foreach ( (array)$value as $name => $elt ) {
+                               if ( $s != '{' ) {
+                                       $s .= ', ';
+                               }
+                               $s .= '"' . self::escapeJsString( $name ) . '": ' . 
+                                       self::encodeJsVar( $elt );
+                       }
+                       $s .= '}';
                } else {
                        $s = '"' . self::escapeJsString( $value ) . '"';
                }