Index: branches/resourceloader/phase3/includes/OutputPage.php |
— | — | @@ -2176,7 +2176,18 @@ |
2177 | 2177 | |
2178 | 2178 | return $ret; |
2179 | 2179 | } |
2180 | | - |
| 2180 | + |
| 2181 | + static function makeResourceLoaderLinkedScript( $skin, $modules ) { |
| 2182 | + global $wgUser, $wgLang, $wgRequest, $wgScriptPath; |
| 2183 | + $query = array( |
| 2184 | + 'modules' => implode( '|', $modules ), |
| 2185 | + 'user' => $wgUser->isLoggedIn(), |
| 2186 | + 'lang' => $wgLang->getCode(), |
| 2187 | + 'debug' => ( $wgRequest->getVal( 'debug' ) === 'true' ), |
| 2188 | + ); |
| 2189 | + return Html::linkedScript( "{$wgScriptPath}/load.php?" . http_build_query( $query ) ); |
| 2190 | + } |
| 2191 | + |
2181 | 2192 | /** |
2182 | 2193 | * Gets the global variables and mScripts; also adds userjs to the end if |
2183 | 2194 | * enabled |
— | — | @@ -2187,10 +2198,14 @@ |
2188 | 2199 | function getHeadScripts( Skin $sk ) { |
2189 | 2200 | global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs; |
2190 | 2201 | global $wgStylePath, $wgStyleVersion; |
2191 | | - |
2192 | | - $scripts = Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
2193 | | - $scripts .= Html::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" ); |
2194 | | - |
| 2202 | + |
| 2203 | + // Include base modules |
| 2204 | + $scripts = self::makeResourceLoaderLinkedScript( $sk, array( 'jquery', 'mediawiki' ) ); |
| 2205 | + // Configure page |
| 2206 | + $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
| 2207 | + // Wikibits legacy code |
| 2208 | + $scripts .= self::makeResourceLoaderLinkedScript( $sk, array( 'mediawiki.legacy.wikibits' ) ); |
| 2209 | + |
2195 | 2210 | // add site JS if enabled |
2196 | 2211 | if( $wgUseSiteJs ) { |
2197 | 2212 | $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; |
Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -82,19 +82,23 @@ |
83 | 83 | if ( $cached !== false && $cached !== null ) { |
84 | 84 | return $cached; |
85 | 85 | } |
86 | | - switch ( $filter ) { |
87 | | - case 'minify-js': |
88 | | - $result = JSMin::minify( $data ); |
89 | | - break; |
90 | | - case 'minify-css': |
91 | | - $result = Minify_CSS::minify( $data, array( 'currentDir' => dirname( $file ), 'docRoot' => '.' ) ); |
92 | | - break; |
93 | | - case 'flip-css': |
94 | | - $result = CSSJanus::transform( $data, true, false ); |
95 | | - break; |
96 | | - default: |
97 | | - // Don't cache anything, just pass right through |
98 | | - return $data; |
| 86 | + try { |
| 87 | + switch ( $filter ) { |
| 88 | + case 'minify-js': |
| 89 | + $result = JSMin::minify( $data ); |
| 90 | + break; |
| 91 | + case 'minify-css': |
| 92 | + $result = Minify_CSS::minify( $data, array( 'currentDir' => dirname( $file ), 'docRoot' => '.' ) ); |
| 93 | + break; |
| 94 | + case 'flip-css': |
| 95 | + $result = CSSJanus::transform( $data, true, false ); |
| 96 | + break; |
| 97 | + default: |
| 98 | + // Don't cache anything, just pass right through |
| 99 | + return $data; |
| 100 | + } |
| 101 | + } catch ( Exception $exception ) { |
| 102 | + throw new MWException( 'Filter threw an exception: ' . $exception->getMessage() ); |
99 | 103 | } |
100 | 104 | $wgMemc->set( $key, $result ); |
101 | 105 | return $result; |
— | — | @@ -272,8 +276,8 @@ |
273 | 277 | ); |
274 | 278 | // Mediawiki's WebRequest::getBool is a bit on the annoying side - we need to allow 'true' and 'false' values |
275 | 279 | // to be converted to boolean true and false |
276 | | - $parameters['user'] = $parameters['user'] === 'true' || $parameters['user'] === true; |
277 | | - $parameters['debug'] = $parameters['debug'] === 'true' || $parameters['debug'] === true; |
| 280 | + $parameters['user'] = $parameters['user'] === 'true'; |
| 281 | + $parameters['debug'] = $parameters['debug'] === 'true'; |
278 | 282 | // Get the direction from the requested language |
279 | 283 | if ( !isset( $parameters['dir'] ) ) { |
280 | 284 | $lang = $wgLang->factory( $parameters['lang'] ); |
— | — | @@ -305,16 +309,7 @@ |
306 | 310 | } |
307 | 311 | // Special meta-information for the 'mediawiki' module |
308 | 312 | if ( in_array( 'mediawiki', $modules ) ) { |
309 | | - /* |
310 | | - * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but |
311 | | - * also put them into the initial payload like this: |
312 | | - * |
313 | | - * // Sets the inital configuration |
314 | | - * mw.config.set( { 'name': 'value', ... } ); |
315 | | - * |
316 | | - * Also, the naming of these variables is horrible and sad, hopefully this can be worked on |
317 | | - */ |
318 | | - echo "mw.config.set( " . json_encode( $parameters ) . " );\n"; |
| 313 | + echo "mediaWiki.config.set( 'debug', " . ( $parameters['debug'] ? 'true' : 'false' ) . " );\n"; |
319 | 314 | // Generate list of registrations and collect all loader scripts |
320 | 315 | $loaders = array(); |
321 | 316 | $registrations = array(); |
— | — | @@ -337,7 +332,7 @@ |
338 | 333 | // Include loaders |
339 | 334 | self::read( $loaders, true ); |
340 | 335 | // Register modules without loaders |
341 | | - echo "mw.loader.register( " . json_encode( array_values( $registrations ) ) . " );\n"; |
| 336 | + echo "mediaWiki.loader.register( " . json_encode( array_values( $registrations ) ) . " );\n"; |
342 | 337 | } |
343 | 338 | // Output non-raw modules |
344 | 339 | $blobs = MessageBlobStore::get( $modules, $parameters['lang'] ); |
— | — | @@ -373,7 +368,7 @@ |
374 | 369 | // Messages |
375 | 370 | $messages = isset( $blobs[$module] ) ? $blobs[$module] : '{}'; |
376 | 371 | // Output |
377 | | - echo "mw.loader.implement( '{$module}', function() {\n{$script}\n}, '{$style}', {$messages} );\n"; |
| 372 | + echo "mediaWiki.loader.implement( '{$module}', function() {\n{$script}\n}, '{$style}', {$messages} );\n"; |
378 | 373 | } |
379 | 374 | } |
380 | 375 | // Set headers -- when we support CSS only mode, this might change! |
Index: branches/resourceloader/phase3/includes/Skin.php |
— | — | @@ -339,16 +339,10 @@ |
340 | 340 | $out->out( "\n</body></html>" ); |
341 | 341 | wfProfileOut( __METHOD__ ); |
342 | 342 | } |
343 | | - |
| 343 | + |
344 | 344 | static function makeVariablesScript( $data ) { |
345 | 345 | if( $data ) { |
346 | | - $r = array(); |
347 | | - foreach ( $data as $name => $value ) { |
348 | | - $encValue = Xml::encodeJsVar( $value ); |
349 | | - $r[] = "$name=$encValue"; |
350 | | - } |
351 | | - $js = 'var ' . implode( ",\n", $r ) . ';'; |
352 | | - return Html::inlineScript( "\n$js\n" ); |
| 346 | + return Html::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' ); |
353 | 347 | } else { |
354 | 348 | return ''; |
355 | 349 | } |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.history.js |
— | — | @@ -112,4 +112,4 @@ |
113 | 113 | mw.legacy.histrowinit(); |
114 | 114 | } ); |
115 | 115 | |
116 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 116 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.search.js |
— | — | @@ -60,4 +60,4 @@ |
61 | 61 | } |
62 | 62 | } ); |
63 | 63 | |
64 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 64 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.changepassword.js |
— | — | @@ -26,4 +26,4 @@ |
27 | 27 | mw.legacy.onNameChangeHook(); |
28 | 28 | } ); |
29 | 29 | |
30 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 30 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.ajaxwatch.js |
— | — | @@ -133,4 +133,4 @@ |
134 | 134 | mw.legacy.wgAjaxWatch.$links = $links; |
135 | 135 | } ); |
136 | 136 | |
137 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 137 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.prefs.js |
— | — | @@ -230,4 +230,4 @@ |
231 | 231 | mw.legacy.tabbedprefs(); |
232 | 232 | } ); |
233 | 233 | |
234 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 234 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.protect.js |
— | — | @@ -343,4 +343,4 @@ |
344 | 344 | } |
345 | 345 | } ); |
346 | 346 | |
347 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 347 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.preview.js |
— | — | @@ -118,4 +118,4 @@ |
119 | 119 | $j('#wpPreview').click( doLivePreview ); |
120 | 120 | } ); |
121 | 121 | |
122 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 122 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.upload.js |
— | — | @@ -330,4 +330,4 @@ |
331 | 331 | mw.legacy.wgUploadSetup(); |
332 | 332 | } ); |
333 | 333 | |
334 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 334 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.edit.js |
— | — | @@ -261,4 +261,4 @@ |
262 | 262 | } ); |
263 | 263 | } ); |
264 | 264 | |
265 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 265 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.htmlform.js |
— | — | @@ -47,4 +47,4 @@ |
48 | 48 | } ); |
49 | 49 | } ); |
50 | 50 | |
51 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 51 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.rightclickedit.js |
— | — | @@ -62,4 +62,4 @@ |
63 | 63 | mw.legacy.setupRightClickEdit(); |
64 | 64 | } ); |
65 | 65 | |
66 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 66 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.block.js |
— | — | @@ -41,4 +41,4 @@ |
42 | 42 | mw.legacy.considerChangingExpiryFocus(); |
43 | 43 | } ); |
44 | 44 | |
45 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 45 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.IEFixes.js |
— | — | @@ -138,4 +138,4 @@ |
139 | 139 | mw.legacy.hookit(); |
140 | 140 | } ); |
141 | 141 | |
142 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 142 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/legacy/mediawiki.legacy.enhancedchanges.js |
— | — | @@ -43,4 +43,4 @@ |
44 | 44 | ); |
45 | 45 | } ); |
46 | 46 | |
47 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 47 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/views/mediawiki.views.install.js |
— | — | @@ -97,4 +97,4 @@ |
98 | 98 | } ); |
99 | 99 | } ); |
100 | 100 | |
101 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 101 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/views/mediawiki.views.diff.js |
— | — | @@ -27,4 +27,4 @@ |
28 | 28 | } |
29 | 29 | } ); |
30 | 30 | |
31 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 31 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -36,7 +36,8 @@ |
37 | 37 | /* |
38 | 38 | * Core MediaWiki JavaScript Library |
39 | 39 | */ |
40 | | -( function( $ ) { |
| 40 | +// Attach to window |
| 41 | +window.mediaWiki = new ( function( $ ) { |
41 | 42 | |
42 | 43 | /* Constants */ |
43 | 44 | |
— | — | @@ -90,10 +91,14 @@ |
91 | 92 | } |
92 | 93 | } |
93 | 94 | return result; |
94 | | - } else if ( typeof values[keys] === 'undefined' ) { |
95 | | - return typeof fallback !== 'undefined' ? fallback : null; |
| 95 | + } else if ( typeof keys === 'string' ) { |
| 96 | + if ( typeof values[keys] === 'undefined' ) { |
| 97 | + return typeof fallback !== 'undefined' ? fallback : null; |
| 98 | + } else { |
| 99 | + return values[keys]; |
| 100 | + } |
96 | 101 | } else { |
97 | | - return values[keys]; |
| 102 | + return values; |
98 | 103 | } |
99 | 104 | }; |
100 | 105 | /** |
— | — | @@ -285,7 +290,7 @@ |
286 | 291 | } |
287 | 292 | // Add localizations to message system |
288 | 293 | if ( typeof registry[module].messages === 'object' ) { |
289 | | - mw.msg.set( registry[module].messages ); |
| 294 | + mediaWiki.msg.set( registry[module].messages ); |
290 | 295 | } |
291 | 296 | // Execute script |
292 | 297 | try { |
— | — | @@ -310,7 +315,7 @@ |
311 | 316 | } |
312 | 317 | } |
313 | 318 | } catch ( e ) { |
314 | | - mw.log( 'Exception thrown by ' + module + ': ' + e.message ); |
| 319 | + mediaWiki.log( 'Exception thrown by ' + module + ': ' + e.message ); |
315 | 320 | registry[module].state = 'error'; |
316 | 321 | // Run error callbacks of jobs affected by this condition |
317 | 322 | for ( var j = 0; j < jobs.length; j++ ) { |
— | — | @@ -387,7 +392,12 @@ |
388 | 393 | // Always order modules alphabetically to help reduce cache misses for otherwise identical content |
389 | 394 | batch.sort(); |
390 | 395 | // Build a list of request parameters |
391 | | - var base = mw.config.get( [ 'user', 'skin', 'lang', 'debug' ] ); |
| 396 | + var base = { |
| 397 | + 'user': mediaWiki.config.get( 'wgUserName' ) !== null, |
| 398 | + 'skin': mediaWiki.config.get( 'skin' ), |
| 399 | + 'lang': mediaWiki.config.get( 'wgUserLanguage' ), |
| 400 | + 'skin': mediaWiki.config.get( 'debug' ), |
| 401 | + }; |
392 | 402 | // Extend request parameters with a list of modules in the batch |
393 | 403 | var requests = []; |
394 | 404 | if ( base.debug == '1' ) { |
— | — | @@ -406,7 +416,7 @@ |
407 | 417 | var html = ''; |
408 | 418 | for ( var r = 0; r < requests.length; r++ ) { |
409 | 419 | // Build out the HTML |
410 | | - var src = mw.config.get( 'server' ) + '/load.php?' + jQuery.param( requests[r] ); |
| 420 | + var src = mediaWiki.config.get( 'server' ) + '/load.php?' + jQuery.param( requests[r] ); |
411 | 421 | html += '<script type="text/javascript" src="' + src + '"></script>'; |
412 | 422 | } |
413 | 423 | // Append script to body |
— | — | @@ -535,7 +545,7 @@ |
536 | 546 | } |
537 | 547 | // Allow calling with a single need as a string |
538 | 548 | if ( typeof modules === 'string' ) { |
539 | | - modules = [needs]; |
| 549 | + modules = [modules]; |
540 | 550 | } |
541 | 551 | // Resolve entire dependency map |
542 | 552 | modules = resolve( modules ); |
— | — | @@ -565,7 +575,4 @@ |
566 | 576 | /* Extension points */ |
567 | 577 | |
568 | 578 | this.utilities = {}; |
569 | | - |
570 | | - // Attach to window |
571 | | - window.MediaWiki = window.mw = this; |
572 | | -} )( jQuery ); |
\ No newline at end of file |
| 579 | +} )( jQuery ); |
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.log.js |
— | — | @@ -60,4 +60,4 @@ |
61 | 61 | } |
62 | 62 | } ); |
63 | 63 | |
64 | | -} )( jQuery, MediaWiki ); |
\ No newline at end of file |
| 64 | +} )( jQuery, mediaWiki ); |
\ No newline at end of file |