protected static function registerSources(ResourceLoader $resourceLoader) { global $wgScriptPath, $wgScriptExtension, $wgMedusaHostPrefix, $wgCdnRootUrl, $wgDevelEnvironment, $wgStagingEnvironment, $wgCityId, $wgEnableResourceLoaderRewrites; $sources = $resourceLoader->getSources(); // staff and internal special case if ($wgCityId === null || $wgCityId === 11) { $resourceLoader->addSource('common', $sources['local']); return true; } // Determine the shared domain name $isProduction = empty($wgDevelEnvironment) && empty($wgStagingEnvironment); if ($isProduction) { $host = 'http://' . (empty($wgMedusaHostPrefix) ? 'community.' : $wgMedusaHostPrefix) . 'wikia.com'; } else { $host = $wgCdnRootUrl; } // Feed RL with the "common" source $scriptUri = "{$host}{$wgScriptPath}/load{$wgScriptExtension}"; $apiUri = "{$host}{$wgScriptPath}/api{$wgScriptExtension}"; $sources['common'] = array('loadScript' => $scriptUri, 'apiScript' => $sources['local']['apiScript']); if (!empty($wgEnableResourceLoaderRewrites)) { // rewrite local source $url = $sources['local']['loadScript']; $url = str_replace("/load{$wgScriptExtension}", "/__load/-/", $url); $sources['local']['loadScript'] = $url; // rewrite common source $url = $sources['common']['loadScript']; $url = str_replace("/load{$wgScriptExtension}", "/__load/-/", $url); if ($isProduction) { $url = str_replace($host, $wgCdnRootUrl, $url); } $sources['common']['loadScript'] = $url; } $resourceLoader->setSource('local', $sources['local']); $resourceLoader->addSource('common', $sources['common']); return true; }
/** * @covers ResourceLoader::getLoadScript */ public function testGetLoadScript() { $this->setMwGlobals('wgResourceLoaderSources', array()); $rl = new ResourceLoader(); $sources = self::fakeSources(); $rl->addSource($sources); foreach (array('examplewiki', 'example2wiki') as $name) { $this->assertEquals($rl->getLoadScript($name), $sources[$name]['loadScript']); } try { $rl->getLoadScript('thiswasneverreigstered'); $this->assertTrue(false, 'ResourceLoader::getLoadScript should have thrown an exception'); } catch (MWException $e) { $this->assertTrue(true); } }