r76204 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76203‎ | r76204 | r76205 >
Date:18:24, 6 November 2010
Author:questpc
Status:deferred
Tags:
Comment:
An attempt to use ResourceLoader
Modified paths:
  • /trunk/extensions/WikiSync/WikiSync.js (modified) (history)
  • /trunk/extensions/WikiSync/WikiSync.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiSync/WikiSync.php
@@ -94,15 +94,16 @@
9595 static $ExtDir; // filesys path with windows path fix
9696 static $ScriptPath; // apache virtual path
9797
 98+ const JS_MSG_PREFIX = 'wikisync_js_';
9899 static $jsMessages = array(
99 - 'wikisync_last_op_error',
100 - 'wikisync_synchronization_confirmation',
101 - 'wikisync_synchronization_success',
102 - 'wikisync_already_synchronized',
103 - 'wikisync_sync_to_itself',
104 - 'wikisync_diff_search',
105 - 'wikisync_revision',
106 - 'wikisync_file_size_mismatch'
 100+ 'last_op_error',
 101+ 'synchronization_confirmation',
 102+ 'synchronization_success',
 103+ 'already_synchronized',
 104+ 'sync_to_itself',
 105+ 'diff_search',
 106+ 'revision',
 107+ 'file_size_mismatch'
107108 );
108109
109110 static function init() {
@@ -122,6 +123,7 @@
123124 }
124125 $wgAutoloadClasses['Snoopy'] = self::$ExtDir . '/Snoopy/Snoopy.class.php';
125126 $wgAutoloadClasses['Services_JSON'] = self::$ExtDir . '/pear/JSON.php';
 127+ $wgAutoloadClasses['WikiSyncSetup'] = self::$ExtDir . '/WikiSync.php';
126128 $wgAutoloadClasses['WikiSnoopy'] =
127129 $wgAutoloadClasses['WikiSyncJSONresult'] =
128130 $wgAutoloadClasses['WikiSyncClient'] = self::$ExtDir . '/WikiSyncClient.php';
@@ -155,6 +157,10 @@
156158 }
157159 }
158160
 161+ static function setJSprefix( $val ) {
 162+ return self::JS_MSG_PREFIX . $val;
 163+ }
 164+
159165 /**
160166 * MW 1.17+ ResourceLoader module hook (JS,CSS)
161167 */
@@ -166,9 +172,9 @@
167173 array(
168174 'ext.wikisync' => new ResourceLoaderFileModule(
169175 array(
170 - 'scripts' => array( 'WikiSync.js', 'WikiSync_utils.js'),
 176+ 'scripts' => array( 'WikiSync_utils.js', 'WikiSync.js' ),
171177 'styles' => 'WikiSync.css',
172 - 'messages' => self::$jsMessages
 178+ 'messages' => array_map( 'self::setJSprefix', self::$jsMessages )
173179 ),
174180 $localpath,
175181 $remotepath
@@ -199,9 +205,8 @@
200206 );
201207 }
202208 $outputPage->addScript(
203 - '<script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script>
204 - <script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version . '"></script>
205 - <script type="' . $wgJsMimeType . '">WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);</script>
 209+ '<script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version . '"></script>
 210+ <script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script>
206211 <script type="' . $wgJsMimeType . '">
207212 WikiSync.setLocalMessages( ' .
208213 self::getJsObject( 'wsLocalMessages', self::$jsMessages ) .
@@ -210,22 +215,16 @@
211216 }
212217
213218 static function getJsObject( $method_name, $jsMessages ) {
214 - $result = '{ ';
215 - $firstElem = true;
216 - foreach ( $jsMessages as &$arg ) {
217 - if ( $firstElem ) {
218 - $firstElem = false;
219 - } else {
220 - $result .= ', ';
221 - }
222 - $result .= $arg . ': "' . Xml::escapeJsString( wfMsg( $arg ) ) . '"';
 219+ $result = array();
 220+ foreach ( $jsMessages as $arg ) {
 221+ $arg = self::JS_MSG_PREFIX . $arg;
 222+ $result[$arg] = wfMsg( $arg );
223223 }
224 - $result .= ' }';
225 - return $result;
 224+ return json_encode( $result );
226225 }
227226
228227 static function checkUserMembership( $groups ) {
229 - global $wgUser;
 228+ global $wgUser, $wgLang;
230229 $ug = $wgUser->getEffectiveGroups();
231230 if ( !$wgUser->isAnon() && !in_array( 'user', $ug ) ) {
232231 $ug[] = 'user';
@@ -233,7 +232,7 @@
234233 if ( array_intersect( $groups, $ug ) ) {
235234 return true;
236235 }
237 - return wfMsg( 'wikisync_api_result_noaccess', implode( $groups, ',' ) );
 236+ return wfMsg( 'wikisync_api_result_noaccess', $wgLang->commaList( $groups ) );
238237 }
239238
240239 /*
Index: trunk/extensions/WikiSync/WikiSync.js
@@ -101,14 +101,14 @@
102102 // these are not initialized in 1.17+ codepath
103103 localMessages : null,
104104
105 - setLocalNames : function( localMessages ) {
 105+ setLocalMessages : function( localMessages ) {
106106 this.localMessages = localMessages;
107107 },
108108
109109 formatMessage : function() {
110110 // in case of future ResourceLoader adoption in Extension:CategoryBrowser there
111111 // should be few methods with different prefixes instead of just one
112 - var prefix = 'wikisync_';
 112+ var prefix = 'wikisync_js_';
113113 if ( typeof mediaWiki === 'object' &&
114114 typeof mediaWiki.msg === 'function' ) {
115115 // MW 1.17+
@@ -968,3 +968,5 @@
969969 }
970970
971971 }
 972+
 973+WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);

Status & tagging log