Index: trunk/phase3/includes/Xml.php |
— | — | @@ -330,7 +330,9 @@ |
331 | 331 | |
332 | 332 | /** |
333 | 333 | * Encode a variable of unknown type to JavaScript. |
334 | | - * Doesn't support hashtables just yet. |
| 334 | + * Arrays are converted to JS arrays, objects are converted to JS associative |
| 335 | + * arrays (objects). So cast your PHP associative arrays to objects before |
| 336 | + * passing them to here. |
335 | 337 | */ |
336 | 338 | public static function encodeJsVar( $value ) { |
337 | 339 | if ( is_bool( $value ) ) { |
— | — | @@ -341,13 +343,23 @@ |
342 | 344 | $s = $value; |
343 | 345 | } elseif ( is_array( $value ) ) { |
344 | 346 | $s = '['; |
345 | | - foreach ( $value as $name => $elt ) { |
| 347 | + foreach ( $value as $elt ) { |
346 | 348 | if ( $s != '[' ) { |
347 | 349 | $s .= ', '; |
348 | 350 | } |
349 | 351 | $s .= self::encodeJsVar( $elt ); |
350 | 352 | } |
351 | 353 | $s .= ']'; |
| 354 | + } elseif ( is_object( $value ) ) { |
| 355 | + $s = '{'; |
| 356 | + foreach ( (array)$value as $name => $elt ) { |
| 357 | + if ( $s != '{' ) { |
| 358 | + $s .= ', '; |
| 359 | + } |
| 360 | + $s .= '"' . self::escapeJsString( $name ) . '": ' . |
| 361 | + self::encodeJsVar( $elt ); |
| 362 | + } |
| 363 | + $s .= '}'; |
352 | 364 | } else { |
353 | 365 | $s = '"' . self::escapeJsString( $value ) . '"'; |
354 | 366 | } |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -297,6 +297,7 @@ |
298 | 298 | global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; |
299 | 299 | global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle; |
300 | 300 | global $wgBreakFrames, $wgRequest; |
| 301 | + global $wgUseAjax, $wgAjaxWatch; |
301 | 302 | |
302 | 303 | $ns = $wgTitle->getNamespace(); |
303 | 304 | $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText(); |
— | — | @@ -334,6 +335,15 @@ |
335 | 336 | $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' ); |
336 | 337 | } |
337 | 338 | |
| 339 | + if($wgUseAjax && $wgAjaxWatch) { |
| 340 | + $msgNames = array( 'watch', 'unwatch', 'watching', 'unwatching' ); |
| 341 | + $msgs = (object)array(); |
| 342 | + foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) { |
| 343 | + $msgs->{$msgName . 'Msg'} = wfMsg( $msgName ); |
| 344 | + } |
| 345 | + $vars['wgAjaxWatch'] = $msgs; |
| 346 | + } |
| 347 | + |
338 | 348 | return self::makeVariablesScript( $vars ); |
339 | 349 | } |
340 | 350 | |
— | — | @@ -419,20 +429,6 @@ |
420 | 430 | if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) { |
421 | 431 | $s .= $commonJs; |
422 | 432 | } |
423 | | - |
424 | | - global $wgUseAjax, $wgAjaxWatch; |
425 | | - if($wgUseAjax && $wgAjaxWatch) { |
426 | | - $s .= " |
427 | | - |
428 | | -/* AJAX (un)watch (see /skins/common/ajaxwatch.js) */ |
429 | | -var wgAjaxWatch = { |
430 | | - watchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."', |
431 | | - unwatchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."', |
432 | | - watchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."', |
433 | | - unwatchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."' |
434 | | -};"; |
435 | | - } |
436 | | - |
437 | 433 | wfProfileOut( __METHOD__ ); |
438 | 434 | return $s; |
439 | 435 | } |