From: Tim Starling Date: Thu, 5 Jul 2007 13:57:54 +0000 (+0000) Subject: gen=js has the wrong cache properties for language-dependent text. Moved wgAjaxWatch... X-Git-Tag: 1.31.0-rc.0~52272 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=e1a8b177c111399aaa7f8453ba2a4cedd0bb81d5;p=lhc%2Fweb%2Fwiklou.git gen=js has the wrong cache properties for language-dependent text. Moved wgAjaxWatch initialisation to makeGlobalVariablesScript(). Added associative array capability to Xml::encodeJsVar(). --- diff --git a/includes/Skin.php b/includes/Skin.php index a23e7c9726..05dd7d2cc2 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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; } diff --git a/includes/Xml.php b/includes/Xml.php index 86a28d21eb..1eeba94ec3 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -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 ) . '"'; }