Index: branches/resourceloader/phase3/skins/common/wikibits.js |
— | — | @@ -65,10 +65,6 @@ |
66 | 66 | } |
67 | 67 | } |
68 | 68 | |
69 | | -window.hookEvent = function( hookName, hookFunct ) { |
70 | | - addHandler( window, hookName, hookFunct ); |
71 | | -} |
72 | | - |
73 | 69 | window.importScript = function( page ) { |
74 | 70 | // TODO: might want to introduce a utility function to match wfUrlencode() in PHP |
75 | 71 | var uri = wgScript + '?title=' + |
— | — | @@ -133,7 +129,7 @@ |
134 | 130 | } |
135 | 131 | |
136 | 132 | |
137 | | -if ( wgBreakFrames ) { |
| 133 | +if ( 'wgBreakFrames' in window && window.wgBreakFrames ) { |
138 | 134 | // Un-trap us from framesets |
139 | 135 | if ( window.top != window ) { |
140 | 136 | window.top.location = window.location; |
— | — | @@ -1063,6 +1059,10 @@ |
1064 | 1060 | } |
1065 | 1061 | } |
1066 | 1062 | |
| 1063 | +window.hookEvent = function( hookName, hookFunct ) { |
| 1064 | + addHandler( window, hookName, hookFunct ); |
| 1065 | +} |
| 1066 | + |
1067 | 1067 | /** |
1068 | 1068 | * Add a click event handler to an element |
1069 | 1069 | * |
Index: branches/resourceloader/phase3/includes/OutputPage.php |
— | — | @@ -1604,13 +1604,13 @@ |
1605 | 1605 | $sk = $wgUser->getSkin(); |
1606 | 1606 | |
1607 | 1607 | // Add base resources |
1608 | | - $this->addModuleScripts( array( 'jquery', 'mediawiki' ) ); |
| 1608 | + $this->addModuleScripts( array( 'startup' ) ); |
1609 | 1609 | $this->addModules( array( 'mediawiki.legacy.wikibits' ) ); |
1610 | 1610 | |
1611 | 1611 | // Add site JS if enabled |
1612 | 1612 | global $wgUseSiteJs; |
1613 | 1613 | if ( $wgUseSiteJs ) { |
1614 | | - $this->addModules( 'sitejs' ); |
| 1614 | + $this->addModuleScripts( 'sitejs' ); |
1615 | 1615 | } |
1616 | 1616 | |
1617 | 1617 | // Add various resources if required |
— | — | @@ -2316,35 +2316,44 @@ |
2317 | 2317 | $scripts = ''; |
2318 | 2318 | // Support individual script requests in debug mode |
2319 | 2319 | if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) { |
| 2320 | + // Styles |
2320 | 2321 | foreach ( $this->getModuleStyles() as $name ) { |
2321 | 2322 | $scripts .= self::makeResourceLoaderLink( $sk, $name, 'styles' ); |
2322 | 2323 | } |
| 2324 | + // Scripts |
2323 | 2325 | foreach ( $this->getModuleScripts() as $name ) { |
2324 | 2326 | $scripts .= self::makeResourceLoaderLink( $sk, $name, 'scripts' ); |
2325 | 2327 | } |
| 2328 | + // Configuration |
| 2329 | + $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
| 2330 | + // Messages |
2326 | 2331 | foreach ( $this->getModuleMessages() as $name ) { |
2327 | 2332 | $scripts .= self::makeResourceLoaderLink( $sk, $name, 'messages' ); |
2328 | 2333 | } |
| 2334 | + // Modules |
2329 | 2335 | foreach ( $this->getModules() as $name ) { |
2330 | 2336 | $scripts .= self::makeResourceLoaderLink( $sk, $name ); |
2331 | 2337 | } |
2332 | 2338 | } else { |
| 2339 | + // Styles |
2333 | 2340 | if ( count( $this->getModuleStyles() ) ) { |
2334 | 2341 | $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' ); |
2335 | 2342 | } |
| 2343 | + // Scripts |
2336 | 2344 | if ( count( $this->getModuleScripts() ) ) { |
2337 | 2345 | $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' ); |
2338 | 2346 | } |
| 2347 | + // Configuration |
| 2348 | + $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
| 2349 | + // Messages |
2339 | 2350 | if ( count( $this->getModuleMessages() ) ) { |
2340 | 2351 | $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' ); |
2341 | 2352 | } |
| 2353 | + // Modules |
2342 | 2354 | if ( count( $this->getModules() ) ) { |
2343 | 2355 | $scripts .= self::makeResourceLoaderLink( $sk, $this->getModules() ); |
2344 | 2356 | } |
2345 | 2357 | } |
2346 | | - // Configure page |
2347 | | - $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
2348 | | - |
2349 | 2358 | // add user JS if enabled |
2350 | 2359 | if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) { |
2351 | 2360 | $action = $wgRequest->getVal( 'action', 'view' ); |
Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -185,7 +185,9 @@ |
186 | 186 | $scripts = ''; |
187 | 187 | $registrations = array(); |
188 | 188 | foreach ( self::$modules as $name => $module ) { |
189 | | - if ( !in_array( $name, self::$preRegisteredModules ) ) { |
| 189 | + if ( in_array( $name, self::$preRegisteredModules ) ) { |
| 190 | + $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ), array(), 'ready' ); |
| 191 | + } else { |
190 | 192 | // Support module loader scripts |
191 | 193 | if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
192 | 194 | $scripts .= "\n" . $loader; |
— | — | @@ -204,8 +206,7 @@ |
205 | 207 | } |
206 | 208 | } |
207 | 209 | } |
208 | | - $scripts .= "\nmediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n"; |
209 | | - return "window.mediaWikiStartUp = function() {" . $scripts . "};"; |
| 210 | + return $scripts . "\nmediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n"; |
210 | 211 | } |
211 | 212 | |
212 | 213 | /** |
— | — | @@ -324,11 +325,18 @@ |
325 | 326 | $scripts .= self::$modules[$name]->getScript( |
326 | 327 | $parameters['lang'], $parameters['skin'], $parameters['debug'] |
327 | 328 | ); |
328 | | - // Special meta-information for the 'mediawiki' module |
329 | | - if ( $name === 'mediawiki' && $parameters['only'] === 'scripts' ) { |
| 329 | + // Special meta-information for the 'startup' module |
| 330 | + if ( $name === 'startup' && $parameters['only'] === 'scripts' ) { |
| 331 | + $scripts .= self::getModuleRegistrations( |
| 332 | + $parameters['lang'], $parameters['skin'], $parameters['debug'] |
| 333 | + ); |
330 | 334 | $scripts .= "mediaWiki.config.set( " . |
331 | 335 | FormatJson::encode( array( 'server' => $server, 'debug' => $parameters['debug'] ) ) . " );\n"; |
332 | | - $scripts .= self::getModuleRegistrations( $parameters['lang'], $parameters['skin'], $parameters['debug'] ); |
| 336 | + // Wrap in a closure |
| 337 | + $scripts = "window.mediaWikiStartUp = function() {" . $scripts . "};"; |
| 338 | + $query = wfArrayToCGI( $parameters ); |
| 339 | + $scripts .= "document.write('<script type=\"text/javascript\" " . |
| 340 | + "src=\"{$server}?modules=jquery|mediawiki&{$query}\"></script>');"; |
333 | 341 | } |
334 | 342 | } |
335 | 343 | // Styles |
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -585,7 +585,7 @@ |
586 | 586 | private $modifiedTime = null; |
587 | 587 | |
588 | 588 | public function getScript( $lang, $skin, $debug ) { |
589 | | - return ResourceLoader::getModuleRegistrations( $lang, $skin, $debug ); |
| 589 | + return ''; |
590 | 590 | } |
591 | 591 | |
592 | 592 | public function getModifiedTime( $lang, $skin, $debug ) { |
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -624,10 +624,11 @@ |
625 | 625 | this.util = {}; |
626 | 626 | this.legacy = {}; |
627 | 627 | |
628 | | - /* Auto-register from pre-loaded startup scripts */ |
629 | | - |
630 | | - if ( typeof window['mediaWikiStartUp'] === 'function' ) { |
631 | | - window['mediaWikiStartUp'](); |
632 | | - delete window['mediaWikiStartUp']; |
633 | | - } |
634 | 628 | } )( jQuery ); |
| 629 | + |
| 630 | +/* Auto-register from pre-loaded startup scripts */ |
| 631 | + |
| 632 | +if ( typeof mediaWikiStartUp === 'function' ) { |
| 633 | + mediaWikiStartUp(); |
| 634 | + delete mediaWikiStartUp; |
| 635 | +} |
\ No newline at end of file |