Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2362,21 +2362,6 @@ |
2363 | 2363 | protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array() ) { |
2364 | 2364 | global $wgLoadScript, $wgResourceLoaderUseESI, |
2365 | 2365 | $wgResourceLoaderInlinePrivateModules; |
2366 | | - $baseQuery = array( |
2367 | | - 'lang' => $this->getContext()->getLang()->getCode(), |
2368 | | - 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false', |
2369 | | - 'skin' => $this->getSkin()->getSkinName(), |
2370 | | - ) + $extraQuery; |
2371 | | - if ( $only !== ResourceLoaderModule::TYPE_COMBINED ) { |
2372 | | - $baseQuery['only'] = $only; |
2373 | | - } |
2374 | | - // Propagate printable and handheld parameters if present |
2375 | | - if ( $this->isPrintable() ) { |
2376 | | - $baseQuery['printable'] = 1; |
2377 | | - } |
2378 | | - if ( $this->getRequest()->getBool( 'handheld' ) ) { |
2379 | | - $baseQuery['handheld'] = 1; |
2380 | | - } |
2381 | 2366 | |
2382 | 2367 | if ( !count( $modules ) ) { |
2383 | 2368 | return ''; |
— | — | @@ -2422,14 +2407,26 @@ |
2423 | 2408 | |
2424 | 2409 | $links = ''; |
2425 | 2410 | foreach ( $groups as $group => $modules ) { |
2426 | | - $query = $baseQuery; |
2427 | 2411 | // Special handling for user-specific groups |
| 2412 | + $user = null; |
2428 | 2413 | if ( ( $group === 'user' || $group === 'private' ) && $this->getUser()->isLoggedIn() ) { |
2429 | | - $query['user'] = $this->getUser()->getName(); |
| 2414 | + $user = $this->getUser()->getName(); |
2430 | 2415 | } |
2431 | 2416 | |
2432 | 2417 | // Create a fake request based on the one we are about to make so modules return |
2433 | 2418 | // correct timestamp and emptiness data |
| 2419 | + $query = ResourceLoader::makeLoaderQuery( |
| 2420 | + array(), // modules; not determined yet |
| 2421 | + $this->getContext()->getLang()->getCode(), |
| 2422 | + $this->getSkin()->getSkinName(), |
| 2423 | + $user, |
| 2424 | + null, // version; not determined yet |
| 2425 | + ResourceLoader::inDebugMode(), |
| 2426 | + $only === ResourceLoaderModule::TYPE_COMBINED ? null : $only, |
| 2427 | + $this->isPrintable(), |
| 2428 | + $this->getRequest()->getBool( 'handheld' ), |
| 2429 | + $extraQuery |
| 2430 | + ); |
2434 | 2431 | $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) ); |
2435 | 2432 | // Drop modules that know they're empty |
2436 | 2433 | foreach ( $modules as $key => $module ) { |
— | — | @@ -2442,8 +2439,6 @@ |
2443 | 2440 | continue; |
2444 | 2441 | } |
2445 | 2442 | |
2446 | | - $query['modules'] = ResourceLoader::makePackedModulesString( array_keys( $modules ) ); |
2447 | | - |
2448 | 2443 | // Support inlining of private modules if configured as such |
2449 | 2444 | if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) { |
2450 | 2445 | if ( $only == ResourceLoaderModule::TYPE_STYLES ) { |
— | — | @@ -2465,6 +2460,7 @@ |
2466 | 2461 | // timestamp of these user-changable modules so we can ensure cache misses on change |
2467 | 2462 | // This should NOT be done for the site group (bug 27564) because anons get that too |
2468 | 2463 | // and we shouldn't be putting timestamps in Squid-cached HTML |
| 2464 | + $version = null; |
2469 | 2465 | if ( $group === 'user' ) { |
2470 | 2466 | // Get the maximum timestamp |
2471 | 2467 | $timestamp = 1; |
— | — | @@ -2472,15 +2468,21 @@ |
2473 | 2469 | $timestamp = max( $timestamp, $module->getModifiedTime( $context ) ); |
2474 | 2470 | } |
2475 | 2471 | // Add a version parameter so cache will break when things change |
2476 | | - $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, $timestamp ); |
| 2472 | + $version = wfTimestamp( TS_ISO_8601_BASIC, $timestamp ); |
2477 | 2473 | } |
2478 | | - // Make queries uniform in order |
2479 | | - ksort( $query ); |
2480 | | - |
2481 | | - $url = wfAppendQuery( $wgLoadScript, $query ); |
2482 | | - // Prevent the IE6 extension check from being triggered (bug 28840) |
2483 | | - // by appending a character that's invalid in Windows extensions ('*') |
2484 | | - $url .= '&*'; |
| 2474 | + |
| 2475 | + $url = ResourceLoader::makeLoaderURL( |
| 2476 | + array_keys( $modules ), |
| 2477 | + $this->getContext()->getLang()->getCode(), |
| 2478 | + $this->getSkin()->getSkinName(), |
| 2479 | + $user, |
| 2480 | + $version, |
| 2481 | + ResourceLoader::inDebugMode(), |
| 2482 | + $only === ResourceLoaderModule::TYPE_COMBINED ? null : $only, |
| 2483 | + $this->isPrintable(), |
| 2484 | + $this->getRequest()->getBool( 'handheld' ), |
| 2485 | + $extraQuery |
| 2486 | + ); |
2485 | 2487 | if ( $useESI && $wgResourceLoaderUseESI ) { |
2486 | 2488 | $esi = Xml::element( 'esi:include', array( 'src' => $url ) ); |
2487 | 2489 | if ( $only == ResourceLoaderModule::TYPE_STYLES ) { |
Index: trunk/phase3/includes/resourceloader/ResourceLoader.php |
— | — | @@ -867,4 +867,65 @@ |
868 | 868 | return $retval = $wgRequest->getFuzzyBool( 'debug', |
869 | 869 | $wgRequest->getCookie( 'resourceLoaderDebug', '', $wgResourceLoaderDebug ) ); |
870 | 870 | } |
| 871 | + |
| 872 | + /** |
| 873 | + * Build a load.php URL |
| 874 | + * @param $modules array of module names (strings) |
| 875 | + * @param $lang string Language code |
| 876 | + * @param $skin string Skin name |
| 877 | + * @param $user string|null User name. If null, the &user= parameter is omitted |
| 878 | + * @param $version string|null Versioning timestamp |
| 879 | + * @param $debug bool Whether the request should be in debug mode |
| 880 | + * @param $only string|null &only= parameter |
| 881 | + * @param $printable bool Printable mode |
| 882 | + * @param $handheld bool Handheld mode |
| 883 | + * @param $extraQuery array Extra query parameters to add |
| 884 | + * @return string URL to load.php. May be protocol-relative (if $wgLoadScript is procol-relative) |
| 885 | + */ |
| 886 | + public static function makeLoaderURL( $modules, $lang, $skin, $user = null, $version = null, $debug = false, $only = null, |
| 887 | + $printable = false, $handheld = false, $extraQuery = array() ) { |
| 888 | + global $wgLoadScript; |
| 889 | + $query = self::makeLoaderQuery( $modules, $lang, $skin, $user, $version, $debug, |
| 890 | + $only, $printable, $handheld, $extraQuery |
| 891 | + ); |
| 892 | + |
| 893 | + // Prevent the IE6 extension check from being triggered (bug 28840) |
| 894 | + // by appending a character that's invalid in Windows extensions ('*') |
| 895 | + return wfAppendQuery( $wgLoadScript, $query ) . '&*'; |
| 896 | + } |
| 897 | + |
| 898 | + /** |
| 899 | + * Build a query array (array representation of query string) for load.php. Helper |
| 900 | + * function for makeLoaderURL(). |
| 901 | + * @return array |
| 902 | + */ |
| 903 | + public static function makeLoaderQuery( $modules, $lang, $skin, $user = null, $version = null, $debug = false, $only = null, |
| 904 | + $printable = false, $handheld = false, $extraQuery = array() ) { |
| 905 | + $query = array( |
| 906 | + 'modules' => self::makePackedModulesString( $modules ), |
| 907 | + 'lang' => $lang, |
| 908 | + 'skin' => $skin, |
| 909 | + 'debug' => $debug ? 'true' : 'false', |
| 910 | + ); |
| 911 | + if ( $user !== null ) { |
| 912 | + $query['user'] = $user; |
| 913 | + } |
| 914 | + if ( $version !== null ) { |
| 915 | + $query['version'] = $version; |
| 916 | + } |
| 917 | + if ( $only !== null ) { |
| 918 | + $query['only'] = $only; |
| 919 | + } |
| 920 | + if ( $printable ) { |
| 921 | + $query['printable'] = 1; |
| 922 | + } |
| 923 | + if ( $handheld ) { |
| 924 | + $query['handheld'] = 1; |
| 925 | + } |
| 926 | + $query += $extraQuery; |
| 927 | + |
| 928 | + // Make queries uniform in order |
| 929 | + ksort( $query ); |
| 930 | + return $query; |
| 931 | + } |
871 | 932 | } |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderModule.php |
— | — | @@ -142,17 +142,18 @@ |
143 | 143 | * @return Array of URLs |
144 | 144 | */ |
145 | 145 | public function getScriptURLsForDebug( ResourceLoaderContext $context ) { |
146 | | - global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink() |
147 | | - $query = array( |
148 | | - 'modules' => $this->getName(), |
149 | | - 'only' => 'scripts', |
150 | | - 'skin' => $context->getSkin(), |
151 | | - 'user' => $context->getUser(), |
152 | | - 'debug' => 'true', |
153 | | - 'version' => $context->getVersion() |
| 146 | + $url = ResourceLoader::makeLoaderURL( |
| 147 | + array( $this->getName() ), |
| 148 | + $context->getLanguage(), |
| 149 | + $context->getSkin(), |
| 150 | + $context->getUser(), |
| 151 | + $context->getVersion(), |
| 152 | + true, // debug |
| 153 | + 'scripts', // only |
| 154 | + $context->getRequest()->getBool( 'printable' ), |
| 155 | + $context->getRequest()->getBool( 'handheld' ) |
154 | 156 | ); |
155 | | - ksort( $query ); |
156 | | - return array( wfAppendQuery( $wgLoadScript, $query ) . '&*' ); |
| 157 | + return array( $url ); |
157 | 158 | } |
158 | 159 | |
159 | 160 | /** |
— | — | @@ -186,17 +187,18 @@ |
187 | 188 | * @return Array: array( mediaType => array( URL1, URL2, ... ), ... ) |
188 | 189 | */ |
189 | 190 | public function getStyleURLsForDebug( ResourceLoaderContext $context ) { |
190 | | - global $wgLoadScript; // TODO factor out to ResourceLoader static method and deduplicate from makeResourceLoaderLink() |
191 | | - $query = array( |
192 | | - 'modules' => $this->getName(), |
193 | | - 'only' => 'styles', |
194 | | - 'skin' => $context->getSkin(), |
195 | | - 'user' => $context->getUser(), |
196 | | - 'debug' => 'true', |
197 | | - 'version' => $context->getVersion() |
| 191 | + $url = ResourceLoader::makeLoaderURL( |
| 192 | + array( $this->getName() ), |
| 193 | + $context->getLanguage(), |
| 194 | + $context->getSkin(), |
| 195 | + $context->getUser(), |
| 196 | + $context->getVersion(), |
| 197 | + true, // debug |
| 198 | + 'styles', // only |
| 199 | + $context->getRequest()->getBool( 'printable' ), |
| 200 | + $context->getRequest()->getBool( 'handheld' ) |
198 | 201 | ); |
199 | | - ksort( $query ); |
200 | | - return array( 'all' => array( wfAppendQuery( $wgLoadScript, $query ) . '&*' ) ); |
| 202 | + return array( 'all' => array( $url ) ); |
201 | 203 | } |
202 | 204 | |
203 | 205 | /** |