Index: trunk/extensions/WikiSync/WikiSync.php |
— | — | @@ -94,15 +94,16 @@ |
95 | 95 | static $ExtDir; // filesys path with windows path fix |
96 | 96 | static $ScriptPath; // apache virtual path |
97 | 97 | |
| 98 | + const JS_MSG_PREFIX = 'wikisync_js_'; |
98 | 99 | 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' |
107 | 108 | ); |
108 | 109 | |
109 | 110 | static function init() { |
— | — | @@ -122,6 +123,7 @@ |
123 | 124 | } |
124 | 125 | $wgAutoloadClasses['Snoopy'] = self::$ExtDir . '/Snoopy/Snoopy.class.php'; |
125 | 126 | $wgAutoloadClasses['Services_JSON'] = self::$ExtDir . '/pear/JSON.php'; |
| 127 | + $wgAutoloadClasses['WikiSyncSetup'] = self::$ExtDir . '/WikiSync.php'; |
126 | 128 | $wgAutoloadClasses['WikiSnoopy'] = |
127 | 129 | $wgAutoloadClasses['WikiSyncJSONresult'] = |
128 | 130 | $wgAutoloadClasses['WikiSyncClient'] = self::$ExtDir . '/WikiSyncClient.php'; |
— | — | @@ -155,6 +157,10 @@ |
156 | 158 | } |
157 | 159 | } |
158 | 160 | |
| 161 | + static function setJSprefix( $val ) { |
| 162 | + return self::JS_MSG_PREFIX . $val; |
| 163 | + } |
| 164 | + |
159 | 165 | /** |
160 | 166 | * MW 1.17+ ResourceLoader module hook (JS,CSS) |
161 | 167 | */ |
— | — | @@ -166,9 +172,9 @@ |
167 | 173 | array( |
168 | 174 | 'ext.wikisync' => new ResourceLoaderFileModule( |
169 | 175 | array( |
170 | | - 'scripts' => array( 'WikiSync.js', 'WikiSync_utils.js'), |
| 176 | + 'scripts' => array( 'WikiSync_utils.js', 'WikiSync.js' ), |
171 | 177 | 'styles' => 'WikiSync.css', |
172 | | - 'messages' => self::$jsMessages |
| 178 | + 'messages' => array_map( 'self::setJSprefix', self::$jsMessages ) |
173 | 179 | ), |
174 | 180 | $localpath, |
175 | 181 | $remotepath |
— | — | @@ -199,9 +205,8 @@ |
200 | 206 | ); |
201 | 207 | } |
202 | 208 | $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> |
206 | 211 | <script type="' . $wgJsMimeType . '"> |
207 | 212 | WikiSync.setLocalMessages( ' . |
208 | 213 | self::getJsObject( 'wsLocalMessages', self::$jsMessages ) . |
— | — | @@ -210,22 +215,16 @@ |
211 | 216 | } |
212 | 217 | |
213 | 218 | 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 ); |
223 | 223 | } |
224 | | - $result .= ' }'; |
225 | | - return $result; |
| 224 | + return json_encode( $result ); |
226 | 225 | } |
227 | 226 | |
228 | 227 | static function checkUserMembership( $groups ) { |
229 | | - global $wgUser; |
| 228 | + global $wgUser, $wgLang; |
230 | 229 | $ug = $wgUser->getEffectiveGroups(); |
231 | 230 | if ( !$wgUser->isAnon() && !in_array( 'user', $ug ) ) { |
232 | 231 | $ug[] = 'user'; |
— | — | @@ -233,7 +232,7 @@ |
234 | 233 | if ( array_intersect( $groups, $ug ) ) { |
235 | 234 | return true; |
236 | 235 | } |
237 | | - return wfMsg( 'wikisync_api_result_noaccess', implode( $groups, ',' ) ); |
| 236 | + return wfMsg( 'wikisync_api_result_noaccess', $wgLang->commaList( $groups ) ); |
238 | 237 | } |
239 | 238 | |
240 | 239 | /* |
Index: trunk/extensions/WikiSync/WikiSync.js |
— | — | @@ -101,14 +101,14 @@ |
102 | 102 | // these are not initialized in 1.17+ codepath |
103 | 103 | localMessages : null, |
104 | 104 | |
105 | | - setLocalNames : function( localMessages ) { |
| 105 | + setLocalMessages : function( localMessages ) { |
106 | 106 | this.localMessages = localMessages; |
107 | 107 | }, |
108 | 108 | |
109 | 109 | formatMessage : function() { |
110 | 110 | // in case of future ResourceLoader adoption in Extension:CategoryBrowser there |
111 | 111 | // should be few methods with different prefixes instead of just one |
112 | | - var prefix = 'wikisync_'; |
| 112 | + var prefix = 'wikisync_js_'; |
113 | 113 | if ( typeof mediaWiki === 'object' && |
114 | 114 | typeof mediaWiki.msg === 'function' ) { |
115 | 115 | // MW 1.17+ |
— | — | @@ -968,3 +968,5 @@ |
969 | 969 | } |
970 | 970 | |
971 | 971 | } |
| 972 | + |
| 973 | +WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler); |