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();
$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 );
}
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;
}
/**
* 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 ) ) {
$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 ) . '"';
}