r23739 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23738‎ | r23739 | r23740 >
Date:13:57, 5 July 2007
Author:tstarling
Status:old
Tags:
Comment:
gen=js has the wrong cache properties for language-dependent text. Moved wgAjaxWatch initialisation to makeGlobalVariablesScript(). Added associative array capability to Xml::encodeJsVar().
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -330,7 +330,9 @@
331331
332332 /**
333333 * 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.
335337 */
336338 public static function encodeJsVar( $value ) {
337339 if ( is_bool( $value ) ) {
@@ -341,13 +343,23 @@
342344 $s = $value;
343345 } elseif ( is_array( $value ) ) {
344346 $s = '[';
345 - foreach ( $value as $name => $elt ) {
 347+ foreach ( $value as $elt ) {
346348 if ( $s != '[' ) {
347349 $s .= ', ';
348350 }
349351 $s .= self::encodeJsVar( $elt );
350352 }
351353 $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 .= '}';
352364 } else {
353365 $s = '"' . self::escapeJsString( $value ) . '"';
354366 }
Index: trunk/phase3/includes/Skin.php
@@ -297,6 +297,7 @@
298298 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
299299 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
300300 global $wgBreakFrames, $wgRequest;
 301+ global $wgUseAjax, $wgAjaxWatch;
301302
302303 $ns = $wgTitle->getNamespace();
303304 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
@@ -334,6 +335,15 @@
335336 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
336337 }
337338
 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+
338348 return self::makeVariablesScript( $vars );
339349 }
340350
@@ -419,20 +429,6 @@
420430 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
421431 $s .= $commonJs;
422432 }
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 -
437433 wfProfileOut( __METHOD__ );
438434 return $s;
439435 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log