http://www.mediawiki.org/wiki/Special:Code/MediaWiki/76204

Revision: 76204
Author:   questpc
Date:     2010-11-06 18:24:50 +0000 (Sat, 06 Nov 2010)
Log Message:
-----------
An attempt to use ResourceLoader

Modified Paths:
--------------
    trunk/extensions/WikiSync/WikiSync.js
    trunk/extensions/WikiSync/WikiSync.php

Modified: trunk/extensions/WikiSync/WikiSync.js
===================================================================
--- trunk/extensions/WikiSync/WikiSync.js       2010-11-06 18:18:31 UTC (rev 
76203)
+++ trunk/extensions/WikiSync/WikiSync.js       2010-11-06 18:24:50 UTC (rev 
76204)
@@ -101,14 +101,14 @@
        // these are not initialized in 1.17+ codepath
        localMessages : null,
 
-       setLocalNames : function( localMessages ) {
+       setLocalMessages : function( localMessages ) {
                this.localMessages = localMessages;
        },
 
        formatMessage : function() {
                // in case of future ResourceLoader adoption in 
Extension:CategoryBrowser there
                // should be few methods with different prefixes instead of 
just one
-               var prefix = 'wikisync_';
+               var prefix = 'wikisync_js_';
                if ( typeof mediaWiki === 'object' &&
                                typeof mediaWiki.msg === 'function' ) {
                        // MW 1.17+
@@ -968,3 +968,5 @@
        }
 
 }
+
+WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);

Modified: trunk/extensions/WikiSync/WikiSync.php
===================================================================
--- trunk/extensions/WikiSync/WikiSync.php      2010-11-06 18:18:31 UTC (rev 
76203)
+++ trunk/extensions/WikiSync/WikiSync.php      2010-11-06 18:24:50 UTC (rev 
76204)
@@ -94,15 +94,16 @@
        static $ExtDir; // filesys path with windows path fix
        static $ScriptPath; // apache virtual path
 
+       const JS_MSG_PREFIX = 'wikisync_js_';
        static $jsMessages = array(
-               'wikisync_last_op_error',
-               'wikisync_synchronization_confirmation',
-               'wikisync_synchronization_success',
-               'wikisync_already_synchronized',
-               'wikisync_sync_to_itself',
-               'wikisync_diff_search',
-               'wikisync_revision',
-               'wikisync_file_size_mismatch'
+               'last_op_error',
+               'synchronization_confirmation',
+               'synchronization_success',
+               'already_synchronized',
+               'sync_to_itself',
+               'diff_search',
+               'revision',
+               'file_size_mismatch'
        );
 
        static function init() {
@@ -122,6 +123,7 @@
                }
                $wgAutoloadClasses['Snoopy'] = self::$ExtDir . 
'/Snoopy/Snoopy.class.php';
                $wgAutoloadClasses['Services_JSON'] = self::$ExtDir . 
'/pear/JSON.php';
+               $wgAutoloadClasses['WikiSyncSetup'] = self::$ExtDir . 
'/WikiSync.php';
                $wgAutoloadClasses['WikiSnoopy'] =
                $wgAutoloadClasses['WikiSyncJSONresult'] =
                $wgAutoloadClasses['WikiSyncClient'] = self::$ExtDir . 
'/WikiSyncClient.php';
@@ -155,6 +157,10 @@
                }
        }
 
+       static function setJSprefix( $val ) {
+               return self::JS_MSG_PREFIX . $val;
+       }
+
        /**
         * MW 1.17+ ResourceLoader module hook (JS,CSS)
         */
@@ -166,9 +172,9 @@
                        array(
                                'ext.wikisync' => new ResourceLoaderFileModule(
                                        array(
-                                               'scripts' => array( 
'WikiSync.js', 'WikiSync_utils.js'),
+                                               'scripts' => array( 
'WikiSync_utils.js', 'WikiSync.js' ),
                                                'styles' => 'WikiSync.css',
-                                               'messages' => self::$jsMessages
+                                               'messages' => array_map( 
'self::setJSprefix', self::$jsMessages )
                                        ),
                                        $localpath,
                                        $remotepath
@@ -199,9 +205,8 @@
                        );
                }
                $outputPage->addScript(
-                       '<script type="' . $wgJsMimeType . '" src="' . 
self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script>
-                       <script type="' . $wgJsMimeType . '" src="' . 
self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version . '"></script>
-                       <script type="' . $wgJsMimeType . 
'">WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);</script>
+                       '<script type="' . $wgJsMimeType . '" src="' . 
self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version . '"></script>
+                       <script type="' . $wgJsMimeType . '" src="' . 
self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script>
                        <script type="' . $wgJsMimeType . '">
                        WikiSync.setLocalMessages( ' .
                                self::getJsObject( 'wsLocalMessages', 
self::$jsMessages ) .
@@ -210,22 +215,16 @@
        }
 
        static function getJsObject( $method_name, $jsMessages ) {
-               $result = '{ ';
-               $firstElem = true;
-               foreach ( $jsMessages as &$arg ) {
-                       if ( $firstElem ) {
-                               $firstElem = false;
-                       } else {
-                               $result .= ', ';
-                       }
-                       $result .= $arg . ': "' . Xml::escapeJsString( wfMsg( 
$arg ) ) . '"';
+               $result = array();
+               foreach ( $jsMessages as $arg ) {
+                       $arg = self::JS_MSG_PREFIX . $arg;
+                       $result[$arg] = wfMsg( $arg );
                }
-               $result .= ' }';
-               return $result;
+               return json_encode( $result );
        }
 
        static function checkUserMembership( $groups ) {
-               global $wgUser;
+               global $wgUser, $wgLang;
                $ug = $wgUser->getEffectiveGroups();
                if ( !$wgUser->isAnon() && !in_array( 'user', $ug ) ) {
                        $ug[] = 'user';
@@ -233,7 +232,7 @@
                if ( array_intersect( $groups, $ug ) ) {
                        return true;
                }
-               return wfMsg( 'wikisync_api_result_noaccess', implode( $groups, 
',' ) );
+               return wfMsg( 'wikisync_api_result_noaccess', 
$wgLang->commaList( $groups ) );
        }
 
        /*


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to