Index: branches/resourceloader/phase3/includes/OutputPage.php |
— | — | @@ -1550,6 +1550,12 @@ |
1551 | 1551 | |
1552 | 1552 | // Add base resources |
1553 | 1553 | $this->addResources( array( 'jquery', 'mediawiki', 'mediawiki.legacy.wikibits' ) ); |
| 1554 | + |
| 1555 | + // Add site JS if enabled |
| 1556 | + global $wgUseSiteJs; |
| 1557 | + if ( $wgUseSiteJs ) { |
| 1558 | + $this->addResources( 'sitejs' ); |
| 1559 | + } |
1554 | 1560 | |
1555 | 1561 | // Add various resources if required |
1556 | 1562 | if ( $wgUseAjax ) { |
— | — | @@ -2223,6 +2229,7 @@ |
2224 | 2230 | $wgRequest->getVal( 'debug' ) === 'true' || |
2225 | 2231 | ( $wgRequest->getVal( 'debug' ) !== 'false' && $wgRequest->getBool( 'debug' ) ) |
2226 | 2232 | ), |
| 2233 | + 'skin' => $wgUser->getSkin()->getSkinName(), |
2227 | 2234 | ); |
2228 | 2235 | return Html::linkedScript( wfAppendQuery( $wgScriptPath . '/load.php', $query ) ); |
2229 | 2236 | } |
— | — | @@ -2236,7 +2243,7 @@ |
2237 | 2244 | * @return String: HTML fragment |
2238 | 2245 | */ |
2239 | 2246 | function getHeadScripts( Skin $sk ) { |
2240 | | - global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs; |
| 2247 | + global $wgUser, $wgRequest, $wgJsMimeType; |
2241 | 2248 | global $wgStylePath, $wgStyleVersion; |
2242 | 2249 | |
2243 | 2250 | // Include base modules and wikibits legacy code |
— | — | @@ -2244,18 +2251,6 @@ |
2245 | 2252 | // Configure page |
2246 | 2253 | $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
2247 | 2254 | |
2248 | | - // add site JS if enabled |
2249 | | - if( $wgUseSiteJs ) { |
2250 | | - $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; |
2251 | | - $this->addScriptFile( |
2252 | | - Skin::makeUrl( |
2253 | | - '-', |
2254 | | - "action=raw$jsCache&gen=js&useskin=" . |
2255 | | - urlencode( $sk->getSkinName() ) |
2256 | | - ) |
2257 | | - ); |
2258 | | - } |
2259 | | - |
2260 | 2255 | // add user JS if enabled |
2261 | 2256 | if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) { |
2262 | 2257 | $action = $wgRequest->getVal( 'action', 'view' ); |
Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -181,6 +181,8 @@ |
182 | 182 | * array( |
183 | 183 | * // Required module options |
184 | 184 | * 'script' => 'dir/script.js' | array( 'dir/script1.js', 'dir/script2.js' ... ), |
| 185 | + * 'callback' => callback, // Either 'script' or 'callback' (not both) must be set |
| 186 | + * |
185 | 187 | * // Optional module options |
186 | 188 | * 'locales' => array( |
187 | 189 | * '[locale name]' => 'dir/locale.js' | '[locale name]' => array( 'dir/locale1.js', 'dir/locale2.js' ... ) |
— | — | @@ -229,11 +231,15 @@ |
230 | 232 | 'style' => null, |
231 | 233 | 'themes' => null, |
232 | 234 | 'messages' => null, |
| 235 | + 'callback' => null, |
233 | 236 | ), $options ); |
234 | 237 | // Validate script option - which is required and must reference files that exist |
235 | | - if ( !is_string( $options['script'] ) ) { |
236 | | - throw new MWException( 'Module does not include a script: ' . $module ); |
| 238 | + if ( !is_string( $options['script'] ) && is_null( $options['callback'] ) ) { |
| 239 | + throw new MWException( 'Module does not include a script or a callback: ' . $module ); |
237 | 240 | } |
| 241 | + if ( is_string( $options['script'] ) && !is_null( $options['callback'] ) ) { |
| 242 | + throw new MWException( 'Module has both a script and a callback: ' . $module ); |
| 243 | + } |
238 | 244 | // Validate options that reference files |
239 | 245 | foreach ( array( 'script', 'locales', 'loader', 'debug', 'style', 'themes' ) as $option ) { |
240 | 246 | if ( $options[$option] !== null ) { |
— | — | @@ -269,6 +275,11 @@ |
270 | 276 | return $mtime; |
271 | 277 | } |
272 | 278 | |
| 279 | + public static function siteJSCallback( $parameters ) { |
| 280 | + // FIXME: Does this belong in this class? |
| 281 | + return Skin::newFromKey( $parameters['skin'] )->generateUserJs(); |
| 282 | + } |
| 283 | + |
273 | 284 | /* |
274 | 285 | * Outputs a response to a resource load-request, including a content-type header |
275 | 286 | * |
— | — | @@ -359,7 +370,11 @@ |
360 | 371 | foreach ( $modules as $module ) { |
361 | 372 | if ( !self::$modules[$module]['raw'] ) { |
362 | 373 | // Script |
363 | | - $script = self::read( self::$modules[$module]['script'] ); |
| 374 | + if ( !is_null( self::$modules[$module]['callback'] ) ) { |
| 375 | + $script = call_user_func( self::$modules[$module]['callback'], $parameters ); |
| 376 | + } else { |
| 377 | + $script = self::read( self::$modules[$module]['script'] ); |
| 378 | + } |
364 | 379 | // Debug |
365 | 380 | if ( $parameters['debug'] && self::$modules[$module]['debug'] ) { |
366 | 381 | $script .= self::read( self::$modules[$module]['debug'] ); |
Index: branches/resourceloader/phase3/includes/RawPage.php |
— | — | @@ -75,10 +75,6 @@ |
76 | 76 | $this->mGen = $gen; |
77 | 77 | if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage; |
78 | 78 | if($ctype == '') $ctype = 'text/css'; |
79 | | - } elseif( $gen == 'js' ) { |
80 | | - $this->mGen = $gen; |
81 | | - if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage; |
82 | | - if($ctype == '') $ctype = $wgJsMimeType; |
83 | 79 | } else { |
84 | 80 | $this->mGen = false; |
85 | 81 | } |
— | — | @@ -166,8 +162,6 @@ |
167 | 163 | $sk->initPage( $wgOut ); |
168 | 164 | if( $this->mGen == 'css' ) { |
169 | 165 | return $sk->generateUserStylesheet(); |
170 | | - } else if( $this->mGen == 'js' ) { |
171 | | - return $sk->generateUserJs(); |
172 | 166 | } |
173 | 167 | } else { |
174 | 168 | return $this->getArticleText(); |
Index: branches/resourceloader/phase3/resources/Resources.php |
— | — | @@ -1,6 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | ResourceLoader::register( array( |
| 5 | + |
| 6 | + /* Special resources (callbacks) */ |
| 7 | + 'sitejs' => array( 'callback' => array( 'ResourceLoader', 'siteJSCallback' ) ), |
5 | 8 | |
6 | 9 | /* jQuery */ |
7 | 10 | |