@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move build-time resources to "CelerityPhysicalResources" to fix Phame

Summary:
Ref T4222. This fixes some issues with Phame's resource construction.

Phame requires a fully virtual resource source, and since I want to run wordpress templates unmodified some day I don't want to build resource maps for skins.

Move all the stuff that depends on resource lists being discoverable at build time to `CelerityPhysicalResources`, and only generate maps for subclasses.

The root `CelerityResources` can now construct virtual resources; construct a virtual resource for Phame and use it.

Test Plan: Off-domain blogs work correctly now. On-domain blogs with custom skins work correctly now.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7873

+126 -61
+5 -5
resources/celerity/map.php
··· 7 7 return array( 8 8 'names' => 9 9 array( 10 - 'core.pkg.css' => '6237350d', 10 + 'core.pkg.css' => 'c70f102f', 11 11 'core.pkg.js' => 'e5bed99d', 12 12 'css/aphront/aphront-bars.css' => 'acda2fd6', 13 13 'css/aphront/aphront-notes.css' => '93ef49a2', ··· 87 87 'css/application/ponder/feed.css' => 'ed499cdd', 88 88 'css/application/ponder/post.css' => '604dd0db', 89 89 'css/application/ponder/vote.css' => 'f7ae64cf', 90 - 'css/application/profile/profile-view.css' => '3a1ce3a0', 90 + 'css/application/profile/profile-view.css' => '2c0b2070', 91 91 'css/application/projects/phabricator-object-list-view.css' => '1f269d69', 92 92 'css/application/projects/project-tag.css' => '866ceb4c', 93 93 'css/application/releeph/releeph-branch.css' => '2e8bac9d', ··· 129 129 'css/phui/phui-info-panel.css' => '04242a5c', 130 130 'css/phui/phui-list.css' => 'ac42d16a', 131 131 'css/phui/phui-object-box.css' => '99263256', 132 - 'css/phui/phui-object-item-list-view.css' => '236014b6', 132 + 'css/phui/phui-object-item-list-view.css' => '6247b27c', 133 133 'css/phui/phui-pinboard-view.css' => '007436fb', 134 134 'css/phui/phui-property-list-view.css' => '405c1b0e', 135 135 'css/phui/phui-remarkup-preview.css' => '9a9bf0a0', ··· 695 695 'phabricator-object-selector-css' => '244c904f', 696 696 'phabricator-phtize' => '2abf8c21', 697 697 'phabricator-prefab' => '8925fbf3', 698 - 'phabricator-profile-css' => '3a1ce3a0', 698 + 'phabricator-profile-css' => '2c0b2070', 699 699 'phabricator-project-tag-css' => '866ceb4c', 700 700 'phabricator-remarkup-css' => '5e94c989', 701 701 'phabricator-search-results-css' => '194d433f', ··· 741 741 'phui-info-panel-css' => '04242a5c', 742 742 'phui-list-view-css' => 'ac42d16a', 743 743 'phui-object-box-css' => '99263256', 744 - 'phui-object-item-list-view-css' => '236014b6', 744 + 'phui-object-item-list-view-css' => '6247b27c', 745 745 'phui-pinboard-view-css' => '007436fb', 746 746 'phui-property-list-view-css' => '405c1b0e', 747 747 'phui-remarkup-preview-css' => '9a9bf0a0',
+5 -1
src/__phutil_library_map__.php
··· 98 98 'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php', 99 99 'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php', 100 100 'CelerityPhabricatorResources' => 'infrastructure/celerity/resources/CelerityPhabricatorResources.php', 101 + 'CelerityPhysicalResources' => 'infrastructure/celerity/resources/CelerityPhysicalResources.php', 101 102 'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php', 102 103 'CelerityResourceGraph' => 'infrastructure/celerity/CelerityResourceGraph.php', 103 104 'CelerityResourceMap' => 'infrastructure/celerity/CelerityResourceMap.php', ··· 2096 2097 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 2097 2098 'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php', 2098 2099 'PhameBlogViewController' => 'applications/phame/controller/blog/PhameBlogViewController.php', 2100 + 'PhameCelerityResources' => 'applications/phame/celerity/PhameCelerityResources.php', 2099 2101 'PhameController' => 'applications/phame/controller/PhameController.php', 2100 2102 'PhameDAO' => 'applications/phame/storage/PhameDAO.php', 2101 2103 'PhamePost' => 'applications/phame/storage/PhamePost.php', ··· 2514 2516 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 2515 2517 'CelerityPhabricatorResourceController' => 'CelerityResourceController', 2516 2518 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', 2519 + 'CelerityPhysicalResources' => 'CelerityResources', 2517 2520 'CelerityResourceController' => 'PhabricatorController', 2518 2521 'CelerityResourceGraph' => 'AbstractDirectedGraph', 2519 2522 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', 2520 - 'CelerityResourcesOnDisk' => 'CelerityResources', 2523 + 'CelerityResourcesOnDisk' => 'CelerityPhysicalResources', 2521 2524 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 2522 2525 'ConduitAPIMethod' => 2523 2526 array( ··· 4726 4729 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4727 4730 'PhameBlogSkin' => 'PhabricatorController', 4728 4731 'PhameBlogViewController' => 'PhameController', 4732 + 'PhameCelerityResources' => 'CelerityResources', 4729 4733 'PhameController' => 'PhabricatorController', 4730 4734 'PhameDAO' => 'PhabricatorLiskDAO', 4731 4735 'PhamePost' =>
+28
src/applications/phame/celerity/PhameCelerityResources.php
··· 1 + <?php 2 + 3 + /** 4 + * Defines Phabricator's static resources. 5 + */ 6 + final class PhameCelerityResources extends CelerityResources { 7 + 8 + private $skin; 9 + 10 + public function setSkin($skin) { 11 + $this->skin = $skin; 12 + return $this; 13 + } 14 + 15 + public function getSkin() { 16 + return $this->skin; 17 + } 18 + 19 + public function getName() { 20 + return 'phame:'.$this->getSkin()->getName(); 21 + } 22 + 23 + public function getResourceData($name) { 24 + $resource_path = $this->skin->getRootDirectory().DIRECTORY_SEPARATOR.$name; 25 + return Filesystem::readFile($resource_path); 26 + } 27 + 28 + }
+14 -4
src/applications/phame/controller/PhameResourceController.php
··· 9 9 private $hash; 10 10 private $name; 11 11 private $root; 12 + private $celerityResourceMap; 12 13 13 - protected function getRootDirectory() { 14 - return $this->root; 14 + public function getCelerityResourceMap() { 15 + return $this->celerityResourceMap; 15 16 } 16 17 17 18 public function willProcessRequest(array $data) { ··· 26 27 27 28 // We require a visible blog associated with a given skin to serve 28 29 // resources, so you can't go fishing around where you shouldn't be. 30 + // However, since these resources may be served off a CDN domain, we're 31 + // bypassing the actual policy check. The blog needs to exist, but you 32 + // don't necessarily need to be able to see it in order to see static 33 + // resources on it. 29 34 30 35 $blog = id(new PhameBlogQuery()) 31 - ->setViewer($user) 36 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 32 37 ->withIDs(array($this->id)) 33 38 ->executeOne(); 34 39 if (!$blog) { ··· 38 43 $skin = $blog->getSkinRenderer($request); 39 44 $spec = $skin->getSpecification(); 40 45 41 - $this->root = $spec->getRootDirectory().DIRECTORY_SEPARATOR; 46 + $resources = new PhameCelerityResources(); 47 + $resources->setSkin($spec); 48 + 49 + $this->root = $spec->getRootDirectory(); 50 + $this->celerityResourceMap = new CelerityResourceMap($resources); 51 + 42 52 return $this->serveResource($this->name); 43 53 } 44 54
+5 -3
src/infrastructure/celerity/CelerityResourceController.php
··· 2 2 3 3 abstract class CelerityResourceController extends PhabricatorController { 4 4 5 - abstract protected function getRootDirectory(); 6 - 7 5 protected function buildResourceTransformer() { 8 6 return null; 9 7 } ··· 14 12 15 13 public function shouldRequireEnabledUser() { 16 14 return false; 15 + } 16 + 17 + public function getCelerityResourceMap() { 18 + return CelerityResourceMap::getInstance(); 17 19 } 18 20 19 21 protected function serveResource($path, $package_hash = null) { ··· 37 39 return $this->makeResponseCacheable(new Aphront304Response()); 38 40 } 39 41 40 - $map = CelerityResourceMap::getInstance(); 42 + $map = $this->getCelerityResourceMap(); 41 43 42 44 if ($map->isPackageResource($path)) { 43 45 $resource_names = $map->getResourceNamesForPackageName($path);
+11 -9
src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php
··· 13 13 } 14 14 15 15 public function execute(PhutilArgumentParser $args) { 16 - $resources_map = CelerityResources::getAll(); 16 + $resources_map = CelerityPhysicalResources::getAll(); 17 17 18 18 $this->log( 19 19 pht( ··· 32 32 /** 33 33 * Rebuild the resource map for a resource source. 34 34 * 35 - * @param CelerityResources Resource source to rebuild. 35 + * @param CelerityPhysicalResources Resource source to rebuild. 36 36 * @return void 37 37 */ 38 - private function rebuildResources(CelerityResources $resources) { 38 + private function rebuildResources(CelerityPhysicalResources $resources) { 39 39 $this->log( 40 40 pht( 41 41 'Rebuilding resource source "%s" (%s)...', ··· 127 127 * Find binary resources (like PNG and SWF) and return information about 128 128 * them. 129 129 * 130 - * @param CelerityResources Resource map to find binary resources for. 130 + * @param CelerityPhysicalResources Resource map to find binary resources for. 131 131 * @return map<string, map<string, string>> Resource information map. 132 132 */ 133 - private function rebuildBinaryResources(CelerityResources $resources) { 133 + private function rebuildBinaryResources( 134 + CelerityPhysicalResources $resources) { 135 + 134 136 $binary_map = $resources->findBinaryResources(); 135 137 136 138 $result_map = array(); ··· 150 152 /** 151 153 * Find text resources (like JS and CSS) and return information about them. 152 154 * 153 - * @param CelerityResources Resource map to find text resources for. 155 + * @param CelerityPhysicalResources Resource map to find text resources for. 154 156 * @param CelerityResourceTransformer Configured resource transformer. 155 157 * @return map<string, map<string, string>> Resource information map. 156 158 */ 157 159 private function rebuildTextResources( 158 - CelerityResources $resources, 160 + CelerityPhysicalResources $resources, 159 161 CelerityResourceTransformer $xformer) { 160 162 161 163 $text_map = $resources->findTextResources(); ··· 262 264 /** 263 265 * Build package specifications for a given resource source. 264 266 * 265 - * @param CelerityResources Resource source to rebuild. 267 + * @param CelerityPhysicalResources Resource source to rebuild. 266 268 * @param list<string, string> Map of `@provides` to hashes. 267 269 * @param list<string, string> Map of hashes to resource names. 268 270 * @return map<string, map<string, string>> Package information maps. 269 271 */ 270 272 private function rebuildPackages( 271 - CelerityResources $resources, 273 + CelerityPhysicalResources $resources, 272 274 array $symbol_map, 273 275 array $reverse_map) { 274 276
+52
src/infrastructure/celerity/resources/CelerityPhysicalResources.php
··· 1 + <?php 2 + 3 + /** 4 + * Defines the location of physical static resources which exist at build time 5 + * and are precomputed into a resource map. 6 + */ 7 + abstract class CelerityPhysicalResources extends CelerityResources { 8 + 9 + private $map; 10 + 11 + abstract public function getPathToMap(); 12 + abstract public function findBinaryResources(); 13 + abstract public function findTextResources(); 14 + 15 + public function loadMap() { 16 + if ($this->map === null) { 17 + $this->map = include $this->getPathToMap(); 18 + } 19 + return $this->map; 20 + } 21 + 22 + public static function getAll() { 23 + static $resources_map; 24 + if ($resources_map === null) { 25 + $resources_map = array(); 26 + 27 + $resources_list = id(new PhutilSymbolLoader()) 28 + ->setAncestorClass('CelerityPhysicalResources') 29 + ->loadObjects(); 30 + 31 + foreach ($resources_list as $resources) { 32 + $name = $resources->getName(); 33 + if (empty($resources_map[$name])) { 34 + $resources_map[$name] = $resources; 35 + } else { 36 + $old = get_class($resources_map[$name]); 37 + $new = get_class($resources); 38 + throw new Exception( 39 + pht( 40 + 'Celerity resource maps must have unique names, but maps %s and '. 41 + '%s share the same name, "%s".', 42 + $old, 43 + $new, 44 + $name)); 45 + } 46 + } 47 + } 48 + 49 + return $resources_map; 50 + } 51 + 52 + }
+5 -38
src/infrastructure/celerity/resources/CelerityResources.php
··· 8 8 private $map; 9 9 10 10 abstract public function getName(); 11 - abstract public function getPathToMap(); 12 11 abstract public function getResourceData($name); 13 - abstract public function findBinaryResources(); 14 - abstract public function findTextResources(); 15 - abstract public function getResourceModifiedTime($name); 12 + 13 + public function getResourceModifiedTime($name) { 14 + return 0; 15 + } 16 16 17 17 public function getCelerityHash($data) { 18 18 $tail = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); ··· 33 33 } 34 34 35 35 public function loadMap() { 36 - if ($this->map === null) { 37 - $this->map = include $this->getPathToMap(); 38 - } 39 - return $this->map; 40 - } 41 - 42 - public static function getAll() { 43 - static $resources_map; 44 - if ($resources_map === null) { 45 - $resources_map = array(); 46 - 47 - $resources_list = id(new PhutilSymbolLoader()) 48 - ->setAncestorClass('CelerityResources') 49 - ->loadObjects(); 50 - 51 - foreach ($resources_list as $resources) { 52 - $name = $resources->getName(); 53 - if (empty($resources_map[$name])) { 54 - $resources_map[$name] = $resources; 55 - } else { 56 - $old = get_class($resources_map[$name]); 57 - $new = get_class($resources); 58 - throw new Exception( 59 - pht( 60 - 'Celerity resource maps must have unique names, but maps %s and '. 61 - '%s share the same name, "%s".', 62 - $old, 63 - $new, 64 - $name)); 65 - } 66 - } 67 - } 68 - 69 - return $resources_map; 36 + return array(); 70 37 } 71 38 72 39 }
+1 -1
src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php
··· 3 3 /** 4 4 * Defines the location of static resources on disk. 5 5 */ 6 - abstract class CelerityResourcesOnDisk extends CelerityResources { 6 + abstract class CelerityResourcesOnDisk extends CelerityPhysicalResources { 7 7 8 8 abstract public function getPathToResources(); 9 9