コード例 #1
0
 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;
 }