r70934 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70933‎ | r70934 | r70935 >
Date:09:34, 12 August 2010
Author:catrope
Status:deferred
Tags:
Comment:
resourceloader: Output site JS through resource loader. Rigged up a quick callback system for this, but that'll probably die as I migrate the array format to something object-based
Modified paths:
  • /branches/resourceloader/phase3/includes/OutputPage.php (modified) (history)
  • /branches/resourceloader/phase3/includes/RawPage.php (modified) (history)
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/resources/Resources.php (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/OutputPage.php
@@ -1550,6 +1550,12 @@
15511551
15521552 // Add base resources
15531553 $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+ }
15541560
15551561 // Add various resources if required
15561562 if ( $wgUseAjax ) {
@@ -2223,6 +2229,7 @@
22242230 $wgRequest->getVal( 'debug' ) === 'true' ||
22252231 ( $wgRequest->getVal( 'debug' ) !== 'false' && $wgRequest->getBool( 'debug' ) )
22262232 ),
 2233+ 'skin' => $wgUser->getSkin()->getSkinName(),
22272234 );
22282235 return Html::linkedScript( wfAppendQuery( $wgScriptPath . '/load.php', $query ) );
22292236 }
@@ -2236,7 +2243,7 @@
22372244 * @return String: HTML fragment
22382245 */
22392246 function getHeadScripts( Skin $sk ) {
2240 - global $wgUser, $wgRequest, $wgJsMimeType, $wgUseSiteJs;
 2247+ global $wgUser, $wgRequest, $wgJsMimeType;
22412248 global $wgStylePath, $wgStyleVersion;
22422249
22432250 // Include base modules and wikibits legacy code
@@ -2244,18 +2251,6 @@
22452252 // Configure page
22462253 $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
22472254
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 -
22602255 // add user JS if enabled
22612256 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
22622257 $action = $wgRequest->getVal( 'action', 'view' );
Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -181,6 +181,8 @@
182182 * array(
183183 * // Required module options
184184 * 'script' => 'dir/script.js' | array( 'dir/script1.js', 'dir/script2.js' ... ),
 185+ * 'callback' => callback, // Either 'script' or 'callback' (not both) must be set
 186+ *
185187 * // Optional module options
186188 * 'locales' => array(
187189 * '[locale name]' => 'dir/locale.js' | '[locale name]' => array( 'dir/locale1.js', 'dir/locale2.js' ... )
@@ -229,11 +231,15 @@
230232 'style' => null,
231233 'themes' => null,
232234 'messages' => null,
 235+ 'callback' => null,
233236 ), $options );
234237 // 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 );
237240 }
 241+ if ( is_string( $options['script'] ) && !is_null( $options['callback'] ) ) {
 242+ throw new MWException( 'Module has both a script and a callback: ' . $module );
 243+ }
238244 // Validate options that reference files
239245 foreach ( array( 'script', 'locales', 'loader', 'debug', 'style', 'themes' ) as $option ) {
240246 if ( $options[$option] !== null ) {
@@ -269,6 +275,11 @@
270276 return $mtime;
271277 }
272278
 279+ public static function siteJSCallback( $parameters ) {
 280+ // FIXME: Does this belong in this class?
 281+ return Skin::newFromKey( $parameters['skin'] )->generateUserJs();
 282+ }
 283+
273284 /*
274285 * Outputs a response to a resource load-request, including a content-type header
275286 *
@@ -359,7 +370,11 @@
360371 foreach ( $modules as $module ) {
361372 if ( !self::$modules[$module]['raw'] ) {
362373 // 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+ }
364379 // Debug
365380 if ( $parameters['debug'] && self::$modules[$module]['debug'] ) {
366381 $script .= self::read( self::$modules[$module]['debug'] );
Index: branches/resourceloader/phase3/includes/RawPage.php
@@ -75,10 +75,6 @@
7676 $this->mGen = $gen;
7777 if( is_null( $smaxage ) ) $smaxage = $wgSquidMaxage;
7878 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;
8379 } else {
8480 $this->mGen = false;
8581 }
@@ -166,8 +162,6 @@
167163 $sk->initPage( $wgOut );
168164 if( $this->mGen == 'css' ) {
169165 return $sk->generateUserStylesheet();
170 - } else if( $this->mGen == 'js' ) {
171 - return $sk->generateUserJs();
172166 }
173167 } else {
174168 return $this->getArticleText();
Index: branches/resourceloader/phase3/resources/Resources.php
@@ -1,6 +1,9 @@
22 <?php
33
44 ResourceLoader::register( array(
 5+
 6+ /* Special resources (callbacks) */
 7+ 'sitejs' => array( 'callback' => array( 'ResourceLoader', 'siteJSCallback' ) ),
58
69 /* jQuery */
710

Status & tagging log