Index: resources/celerity/map.php =================================================================== --- resources/celerity/map.php +++ resources/celerity/map.php @@ -7,7 +7,7 @@ return array( 'names' => array( - 'core.pkg.css' => '6237350d', + 'core.pkg.css' => 'c70f102f', 'core.pkg.js' => 'e5bed99d', 'css/aphront/aphront-bars.css' => 'acda2fd6', 'css/aphront/aphront-notes.css' => '93ef49a2', @@ -87,7 +87,7 @@ 'css/application/ponder/feed.css' => 'ed499cdd', 'css/application/ponder/post.css' => '604dd0db', 'css/application/ponder/vote.css' => 'f7ae64cf', - 'css/application/profile/profile-view.css' => '3a1ce3a0', + 'css/application/profile/profile-view.css' => '2c0b2070', 'css/application/projects/phabricator-object-list-view.css' => '1f269d69', 'css/application/projects/project-tag.css' => '866ceb4c', 'css/application/releeph/releeph-branch.css' => '2e8bac9d', @@ -129,7 +129,7 @@ 'css/phui/phui-info-panel.css' => '04242a5c', 'css/phui/phui-list.css' => 'ac42d16a', 'css/phui/phui-object-box.css' => '99263256', - 'css/phui/phui-object-item-list-view.css' => '236014b6', + 'css/phui/phui-object-item-list-view.css' => '6247b27c', 'css/phui/phui-pinboard-view.css' => '007436fb', 'css/phui/phui-property-list-view.css' => '405c1b0e', 'css/phui/phui-remarkup-preview.css' => '9a9bf0a0', @@ -695,7 +695,7 @@ 'phabricator-object-selector-css' => '244c904f', 'phabricator-phtize' => '2abf8c21', 'phabricator-prefab' => '8925fbf3', - 'phabricator-profile-css' => '3a1ce3a0', + 'phabricator-profile-css' => '2c0b2070', 'phabricator-project-tag-css' => '866ceb4c', 'phabricator-remarkup-css' => '5e94c989', 'phabricator-search-results-css' => '194d433f', @@ -741,7 +741,7 @@ 'phui-info-panel-css' => '04242a5c', 'phui-list-view-css' => 'ac42d16a', 'phui-object-box-css' => '99263256', - 'phui-object-item-list-view-css' => '236014b6', + 'phui-object-item-list-view-css' => '6247b27c', 'phui-pinboard-view-css' => '007436fb', 'phui-property-list-view-css' => '405c1b0e', 'phui-remarkup-preview-css' => '9a9bf0a0', Index: src/__phutil_library_map__.php =================================================================== --- src/__phutil_library_map__.php +++ src/__phutil_library_map__.php @@ -98,6 +98,7 @@ 'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php', 'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php', 'CelerityPhabricatorResources' => 'infrastructure/celerity/resources/CelerityPhabricatorResources.php', + 'CelerityPhysicalResources' => 'infrastructure/celerity/resources/CelerityPhysicalResources.php', 'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php', 'CelerityResourceGraph' => 'infrastructure/celerity/CelerityResourceGraph.php', 'CelerityResourceMap' => 'infrastructure/celerity/CelerityResourceMap.php', @@ -2096,6 +2097,7 @@ 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php', 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', + 'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php', 'PhameController' => 'applications/phame/controller/PhameController.php', 'PhameDAO' => 'applications/phame/storage/PhameDAO.php', 'PhamePost' => 'applications/phame/storage/PhamePost.php', @@ -2514,10 +2516,11 @@ 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 'CelerityPhabricatorResourceController' => 'CelerityResourceController', 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', + 'CelerityPhysicalResources' => 'CelerityResources', 'CelerityResourceController' => 'PhabricatorController', 'CelerityResourceGraph' => 'AbstractDirectedGraph', 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', - 'CelerityResourcesOnDisk' => 'CelerityResources', + 'CelerityResourcesOnDisk' => 'CelerityPhysicalResources', 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 'ConduitAPIMethod' => array( @@ -4726,6 +4729,7 @@ 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhameBlogSkin' => 'PhabricatorController', 'PhameBlogViewController' => 'PhameController', + 'PhameCelerityResources' => 'CelerityResources', 'PhameController' => 'PhabricatorController', 'PhameDAO' => 'PhabricatorLiskDAO', 'PhamePost' => Index: src/applications/phame/celerity/PhameCelerityResources.php =================================================================== --- /dev/null +++ src/applications/phame/celerity/PhameCelerityResources.php @@ -0,0 +1,28 @@ +skin = $skin; + return $this; + } + + public function getSkin() { + return $this->skin; + } + + public function getName() { + return 'phame:'.$this->getSkin()->getName(); + } + + public function getResourceData($name) { + $resource_path = $this->skin->getRootDirectory().DIRECTORY_SEPARATOR.$name; + return Filesystem::readFile($resource_path); + } + +} Index: src/applications/phame/controller/PhameResourceController.php =================================================================== --- src/applications/phame/controller/PhameResourceController.php +++ src/applications/phame/controller/PhameResourceController.php @@ -9,9 +9,10 @@ private $hash; private $name; private $root; + private $celerityResourceMap; - protected function getRootDirectory() { - return $this->root; + public function getCelerityResourceMap() { + return $this->celerityResourceMap; } public function willProcessRequest(array $data) { @@ -26,9 +27,13 @@ // We require a visible blog associated with a given skin to serve // resources, so you can't go fishing around where you shouldn't be. + // However, since these resources may be served off a CDN domain, we're + // bypassing the actual policy check. The blog needs to exist, but you + // don't necessarily need to be able to see it in order to see static + // resources on it. $blog = id(new PhameBlogQuery()) - ->setViewer($user) + ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withIDs(array($this->id)) ->executeOne(); if (!$blog) { @@ -38,7 +43,12 @@ $skin = $blog->getSkinRenderer($request); $spec = $skin->getSpecification(); - $this->root = $spec->getRootDirectory().DIRECTORY_SEPARATOR; + $resources = new PhameCelerityResources(); + $resources->setSkin($spec); + + $this->root = $spec->getRootDirectory(); + $this->celerityResourceMap = new CelerityResourceMap($resources); + return $this->serveResource($this->name); } Index: src/infrastructure/celerity/CelerityResourceController.php =================================================================== --- src/infrastructure/celerity/CelerityResourceController.php +++ src/infrastructure/celerity/CelerityResourceController.php @@ -2,8 +2,6 @@ abstract class CelerityResourceController extends PhabricatorController { - abstract protected function getRootDirectory(); - protected function buildResourceTransformer() { return null; } @@ -16,6 +14,10 @@ return false; } + public function getCelerityResourceMap() { + return CelerityResourceMap::getInstance(); + } + protected function serveResource($path, $package_hash = null) { // Sanity checking to keep this from exposing anything sensitive, since it // ultimately boils down to disk reads. @@ -37,7 +39,7 @@ return $this->makeResponseCacheable(new Aphront304Response()); } - $map = CelerityResourceMap::getInstance(); + $map = $this->getCelerityResourceMap(); if ($map->isPackageResource($path)) { $resource_names = $map->getResourceNamesForPackageName($path); Index: src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php =================================================================== --- src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php +++ src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php @@ -13,7 +13,7 @@ } public function execute(PhutilArgumentParser $args) { - $resources_map = CelerityResources::getAll(); + $resources_map = CelerityPhysicalResources::getAll(); $this->log( pht( @@ -32,10 +32,10 @@ /** * Rebuild the resource map for a resource source. * - * @param CelerityResources Resource source to rebuild. + * @param CelerityPhysicalResources Resource source to rebuild. * @return void */ - private function rebuildResources(CelerityResources $resources) { + private function rebuildResources(CelerityPhysicalResources $resources) { $this->log( pht( 'Rebuilding resource source "%s" (%s)...', @@ -127,10 +127,12 @@ * Find binary resources (like PNG and SWF) and return information about * them. * - * @param CelerityResources Resource map to find binary resources for. + * @param CelerityPhysicalResources Resource map to find binary resources for. * @return map> Resource information map. */ - private function rebuildBinaryResources(CelerityResources $resources) { + private function rebuildBinaryResources( + CelerityPhysicalResources $resources) { + $binary_map = $resources->findBinaryResources(); $result_map = array(); @@ -150,12 +152,12 @@ /** * Find text resources (like JS and CSS) and return information about them. * - * @param CelerityResources Resource map to find text resources for. + * @param CelerityPhysicalResources Resource map to find text resources for. * @param CelerityResourceTransformer Configured resource transformer. * @return map> Resource information map. */ private function rebuildTextResources( - CelerityResources $resources, + CelerityPhysicalResources $resources, CelerityResourceTransformer $xformer) { $text_map = $resources->findTextResources(); @@ -262,13 +264,13 @@ /** * Build package specifications for a given resource source. * - * @param CelerityResources Resource source to rebuild. + * @param CelerityPhysicalResources Resource source to rebuild. * @param list Map of `@provides` to hashes. * @param list Map of hashes to resource names. * @return map> Package information maps. */ private function rebuildPackages( - CelerityResources $resources, + CelerityPhysicalResources $resources, array $symbol_map, array $reverse_map) { Index: src/infrastructure/celerity/resources/CelerityPhysicalResources.php =================================================================== --- src/infrastructure/celerity/resources/CelerityPhysicalResources.php +++ src/infrastructure/celerity/resources/CelerityPhysicalResources.php @@ -1,36 +1,16 @@ map === null) { @@ -45,7 +25,7 @@ $resources_map = array(); $resources_list = id(new PhutilSymbolLoader()) - ->setAncestorClass('CelerityResources') + ->setAncestorClass('CelerityPhysicalResources') ->loadObjects(); foreach ($resources_list as $resources) { Index: src/infrastructure/celerity/resources/CelerityResources.php =================================================================== --- src/infrastructure/celerity/resources/CelerityResources.php +++ src/infrastructure/celerity/resources/CelerityResources.php @@ -8,11 +8,11 @@ private $map; abstract public function getName(); - abstract public function getPathToMap(); abstract public function getResourceData($name); - abstract public function findBinaryResources(); - abstract public function findTextResources(); - abstract public function getResourceModifiedTime($name); + + public function getResourceModifiedTime($name) { + return 0; + } public function getCelerityHash($data) { $tail = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); @@ -33,40 +33,7 @@ } public function loadMap() { - if ($this->map === null) { - $this->map = include $this->getPathToMap(); - } - return $this->map; - } - - public static function getAll() { - static $resources_map; - if ($resources_map === null) { - $resources_map = array(); - - $resources_list = id(new PhutilSymbolLoader()) - ->setAncestorClass('CelerityResources') - ->loadObjects(); - - foreach ($resources_list as $resources) { - $name = $resources->getName(); - if (empty($resources_map[$name])) { - $resources_map[$name] = $resources; - } else { - $old = get_class($resources_map[$name]); - $new = get_class($resources); - throw new Exception( - pht( - 'Celerity resource maps must have unique names, but maps %s and '. - '%s share the same name, "%s".', - $old, - $new, - $name)); - } - } - } - - return $resources_map; + return array(); } } Index: src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php =================================================================== --- src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php +++ src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php @@ -3,7 +3,7 @@ /** * Defines the location of static resources on disk. */ -abstract class CelerityResourcesOnDisk extends CelerityResources { +abstract class CelerityResourcesOnDisk extends CelerityPhysicalResources { abstract public function getPathToResources();