Index: trunk/extensions/WikiSync/WikiSyncPage.php |
— | — | @@ -160,67 +160,13 @@ |
161 | 161 | ); |
162 | 162 | } |
163 | 163 | |
164 | | - /* |
165 | | - * include stylesheets and scripts; set javascript variables |
166 | | - * @param $outputPage - an instance of OutputPage |
167 | | - * @param $isRTL - whether the current language is RTL |
168 | | - */ |
169 | | - static function headScripts( &$outputPage, $isRTL ) { |
170 | | - global $wgJsMimeType; |
171 | | - $outputPage->addLink( |
172 | | - array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => WikiSyncSetup::$ScriptPath . '/WikiSync.css?' . WikiSyncSetup::$version ) |
173 | | - ); |
174 | | - if ( $isRTL ) { |
175 | | - $outputPage->addLink( |
176 | | - array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => WikiSyncSetup::$ScriptPath . '/WikiSync_rtl.css?' . WikiSyncSetup::$version ) |
177 | | - ); |
178 | | - } |
179 | | - $outputPage->addScript( |
180 | | - '<script type="' . $wgJsMimeType . '" src="' . WikiSyncSetup::$ScriptPath . '/WikiSync.js?' . WikiSyncSetup::$version . '"></script> |
181 | | - <script type="' . $wgJsMimeType . '" src="' . WikiSyncSetup::$ScriptPath . '/WikiSync_Utils.js?' . WikiSyncSetup::$version . '"></script> |
182 | | - <script type="' . $wgJsMimeType . '">WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);</script> |
183 | | - <script type="' . $wgJsMimeType . '"> |
184 | | - WikiSync.setLocalNames( ' . |
185 | | - self::getJsObject( 'wsLocalMessages', 'last_op_error', 'synchronization_confirmation', 'synchronization_success', 'already_synchronized', 'sync_to_itself', 'diff_search', 'revision', 'file_size_mismatch' ) . |
186 | | - ');</script>' . "\n" |
187 | | - ); |
188 | | - } |
189 | | - |
190 | | - static function getJsObject( $method_name ) { |
191 | | - $args = func_get_args(); |
192 | | - array_shift( $args ); // remove $method_name from $args |
193 | | - $result = '{ '; |
194 | | - $firstElem = true; |
195 | | - foreach ( $args as &$arg ) { |
196 | | - if ( $firstElem ) { |
197 | | - $firstElem = false; |
198 | | - } else { |
199 | | - $result .= ', '; |
200 | | - } |
201 | | - $result .= $arg . ': "' . Xml::escapeJsString( call_user_func( array( 'self', $method_name ), $arg ) ) . '"'; |
202 | | - } |
203 | | - $result .= ' }'; |
204 | | - return $result; |
205 | | - } |
206 | | - |
207 | | - /* |
208 | | - * currently passed to Javascript: |
209 | | - * localMessages |
210 | | - */ |
211 | | - /* |
212 | | - * getJsObject callback |
213 | | - */ |
214 | | - static private function wsLocalMessages( $arg ) { |
215 | | - return wfMsg( "wikisync_js_${arg}" ); |
216 | | - } |
217 | | - |
218 | 164 | function __construct() { |
219 | 165 | parent::__construct( 'WikiSync', 'edit' ); |
220 | 166 | $this->initUser = WikiSyncSetup::initUser(); |
221 | 167 | } |
222 | 168 | |
223 | 169 | function execute( $param ) { |
224 | | - global $wgOut, $wgContLang; |
| 170 | + global $wgOut; |
225 | 171 | global $wgUser; |
226 | 172 | # commented out, ignored by FF 3+ anyway |
227 | 173 | # $wgOut->enableClientCache( false ); |
— | — | @@ -236,7 +182,6 @@ |
237 | 183 | if ( !$wgUser->isAnon() ) { |
238 | 184 | WikiSyncSetup::$remote_wiki_user = $wgUser->getName(); |
239 | 185 | } |
240 | | - self::headScripts( $wgOut, $wgContLang->isRTL() ); |
241 | 186 | $wgOut->setPagetitle( wfMsgHtml( 'wikisync' ) ); |
242 | 187 | $this->initSyncDirectionTpl(); |
243 | 188 | $this->initRemoteLoginFormTpl(); |
Index: trunk/extensions/WikiSync/WikiSync.php |
— | — | @@ -94,11 +94,23 @@ |
95 | 95 | static $ExtDir; // filesys path with windows path fix |
96 | 96 | static $ScriptPath; // apache virtual path |
97 | 97 | |
| 98 | + 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' |
| 107 | + ); |
| 108 | + |
98 | 109 | static function init() { |
99 | 110 | global $wgScriptPath; |
100 | 111 | global $wgAutoloadClasses; |
101 | 112 | global $wgAjaxExportList; |
102 | 113 | global $wgAPIModules; |
| 114 | + global $wgHooks; |
103 | 115 | |
104 | 116 | self::$ExtDir = str_replace( "\\", "/", dirname( __FILE__ ) ); |
105 | 117 | $top_dir = explode( '/', self::$ExtDir ); |
— | — | @@ -133,6 +145,8 @@ |
134 | 146 | $wgAjaxExportList[] = 'WikiSyncClient::transferFileBlock'; |
135 | 147 | $wgAjaxExportList[] = 'WikiSyncClient::uploadLocalFile'; |
136 | 148 | |
| 149 | + $wgHooks['ResourceLoaderRegisterModules'][] = 'WikiSyncSetup::registerModules'; |
| 150 | + |
137 | 151 | if ( ($parsed_url = parse_url( self::$proxy_address )) !== false ) { |
138 | 152 | if ( isset( $parsed_url['host'] ) ) { self::$proxy_host = $parsed_url['host']; } |
139 | 153 | if ( isset( $parsed_url['port'] ) ) { self::$proxy_port = $parsed_url['port']; } |
— | — | @@ -141,16 +155,87 @@ |
142 | 156 | } |
143 | 157 | } |
144 | 158 | |
| 159 | + /** |
| 160 | + * MW 1.17+ ResourceLoader module hook (JS,CSS) |
| 161 | + */ |
| 162 | + static function registerModules( $resourceLoader ) { |
| 163 | + global $wgExtensionAssetsPath; |
| 164 | + $localpath = dirname( __FILE__ ); |
| 165 | + $remotepath = "$wgExtensionAssetsPath/WikiSync"; |
| 166 | + sdv_debug(__METHOD__,array($localpath,$remotepath),true); |
| 167 | + $resourceLoader->register( |
| 168 | + array( |
| 169 | + 'ext.wikisync' => new ResourceLoaderFileModule( |
| 170 | + array( |
| 171 | + 'scripts' => array( 'WikiSync.js', 'WikiSync_utils.js'), |
| 172 | + 'styles' => 'WikiSync.css', |
| 173 | + 'messages' => self::$jsMessages |
| 174 | + ), |
| 175 | + $localpath, |
| 176 | + $remotepath |
| 177 | + ) |
| 178 | + ) |
| 179 | + ); |
| 180 | + return true; |
| 181 | + } |
| 182 | + |
| 183 | + /* |
| 184 | + * include stylesheets and scripts; set javascript variables |
| 185 | + * @param $outputPage - an instance of OutputPage |
| 186 | + * @param $isRTL - whether the current language is RTL |
| 187 | + */ |
| 188 | + static function headScripts( &$outputPage, $isRTL ) { |
| 189 | + global $wgJsMimeType; |
| 190 | + if ( class_exists( 'ResourceLoader' ) ) { |
| 191 | +# $outputPage->addModules( 'jquery' ); |
| 192 | + $outputPage->addModules( 'ext.wikisync' ); |
| 193 | + return; |
| 194 | + } |
| 195 | + $outputPage->addLink( |
| 196 | + array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => self::$ScriptPath . '/WikiSync.css?' . self::$version ) |
| 197 | + ); |
| 198 | + if ( $isRTL ) { |
| 199 | + $outputPage->addLink( |
| 200 | + array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => self::$ScriptPath . '/WikiSync_rtl.css?' . self::$version ) |
| 201 | + ); |
| 202 | + } |
| 203 | + $outputPage->addScript( |
| 204 | + '<script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script> |
| 205 | + <script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version . '"></script> |
| 206 | + <script type="' . $wgJsMimeType . '">WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);</script> |
| 207 | + <script type="' . $wgJsMimeType . '"> |
| 208 | + WikiSync.setLocalMessages( ' . |
| 209 | + self::getJsObject( 'wsLocalMessages', self::$jsMessages ) . |
| 210 | + ');</script>' . "\n" |
| 211 | + ); |
| 212 | + } |
| 213 | + |
| 214 | + static function getJsObject( $method_name, $jsMessages ) { |
| 215 | + $result = '{ '; |
| 216 | + $firstElem = true; |
| 217 | + foreach ( $jsMessages as &$arg ) { |
| 218 | + if ( $firstElem ) { |
| 219 | + $firstElem = false; |
| 220 | + } else { |
| 221 | + $result .= ', '; |
| 222 | + } |
| 223 | + $result .= $arg . ': "' . Xml::escapeJsString( wfMsg( $arg ) ) . '"'; |
| 224 | + } |
| 225 | + $result .= ' }'; |
| 226 | + return $result; |
| 227 | + } |
| 228 | + |
145 | 229 | static function checkUserMembership( $groups ) { |
146 | | - global $wgUser, $wgLang; |
| 230 | + global $wgUser; |
147 | 231 | $ug = $wgUser->getEffectiveGroups(); |
148 | 232 | if ( !$wgUser->isAnon() && !in_array( 'user', $ug ) ) { |
149 | 233 | $ug[] = 'user'; |
150 | 234 | } |
| 235 | + sdv_debug("ug",$ug,true); |
151 | 236 | if ( array_intersect( $groups, $ug ) ) { |
152 | 237 | return true; |
153 | 238 | } |
154 | | - return wfMsg( 'wikisync_api_result_noaccess', $wgLang->commaList( $groups ) ); |
| 239 | + return wfMsg( 'wikisync_api_result_noaccess', implode( $groups, ',' ) ); |
155 | 240 | } |
156 | 241 | |
157 | 242 | /* |
— | — | @@ -171,6 +256,7 @@ |
172 | 257 | return self::checkUserMembership( self::$ltr_access_groups ); |
173 | 258 | } elseif ( $direction === null ) { |
174 | 259 | $groups = array_merge( self::$rtl_access_groups, self::$ltr_access_groups ); |
| 260 | + sdv_debug("initUser groups",$groups,true); |
175 | 261 | return self::checkUserMembership( $groups ); |
176 | 262 | } |
177 | 263 | return 'Bug: direction should be boolean or null, value (' . $direction . ') given in ' . __METHOD__; |
Index: trunk/extensions/WikiSync/WikiSync.js |
— | — | @@ -97,6 +97,8 @@ |
98 | 98 | }, |
99 | 99 | |
100 | 100 | // localized UI messages |
| 101 | + // warning: do not access directly anymore, because |
| 102 | + // these are not initialized in 1.17+ codepath |
101 | 103 | localMessages : null, |
102 | 104 | |
103 | 105 | setLocalNames : function( localMessages ) { |
— | — | @@ -104,16 +106,28 @@ |
105 | 107 | }, |
106 | 108 | |
107 | 109 | formatMessage : function() { |
108 | | - var formatted = this.localMessages[ arguments[0] ]; |
| 110 | + // in case of future ResourceLoader adoption in Extension:CategoryBrowser there |
| 111 | + // should be few methods with different prefixes instead of just one |
| 112 | + var prefix = 'wikisync_'; |
| 113 | + if ( typeof mediaWiki === 'object' && |
| 114 | + typeof mediaWiki.msg === 'function' ) { |
| 115 | + // MW 1.17+ |
| 116 | + var args = arguments; |
| 117 | + args[0] = prefix + args[0]; |
| 118 | + return mediaWiki.msg.apply( mediaWiki.msg, args ); |
| 119 | + } |
| 120 | + var formatted = this.localMessages[ prefix + arguments[0] ]; |
109 | 121 | var indexes = []; |
110 | 122 | var pos; |
111 | 123 | var j; |
112 | | - // going in reverse order is very important for the next for loop to be correct |
| 124 | + // gettting $n parameter indexes |
| 125 | + // going in reverse order is very important for the second for loop to be correct |
113 | 126 | for ( var i = arguments.length - 1; i > 0; i-- ) { |
114 | 127 | if ( ( pos = formatted.indexOf( '$' + i ) ) !== -1 ) { |
115 | 128 | indexes.push( pos ); |
116 | 129 | } |
117 | 130 | } |
| 131 | + // substituting the parameters |
118 | 132 | for ( i = 0; i < indexes.length; i++ ) { |
119 | 133 | pos = indexes[i]; |
120 | 134 | j = formatted.charAt( pos + 1 ); |
— | — | @@ -907,7 +921,7 @@ |
908 | 922 | this.srcLastId = this.srcHiId = parseInt( this.popAJAXresult( 'src_rev_last', ['query', 'revisionhistory', 0, 'revid'] ) ); |
909 | 923 | // uncomment next line for "live" debugging |
910 | 924 | // this.srcLastId = this.srcHiId = 75054; |
911 | | - this.syncPercents.display( { 'desc' : this.localMessages['diff_search'], 'curr' : 0, 'min' : 0, 'max' : Math.ceil( this.mathLogBase( this.srcLastId - this.srcFirstId, 2 ) ) } ); |
| 925 | + this.syncPercents.display( { 'desc' : this.formatMessage( 'diff_search' ), 'curr' : 0, 'min' : 0, 'max' : Math.ceil( this.mathLogBase( this.srcLastId - this.srcFirstId, 2 ) ) } ); |
912 | 926 | this.findCommonRev( { 'opcode' : 'start' } ); |
913 | 927 | return; |
914 | 928 | } |