@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.

Improve routing of "/robots.txt", "/favicon.ico", "/status/", and 404 on custom Sites

Summary:
Fixes T12919. Fixes T13636. Prior to this change, some well-known resource paths don't route on sites like ResourceSite.

- `/robots.txt`: Make it route on ResourceSite and just deny the whole site.
- `/favicon.ico`: Make it route on ResourceSite.
- `/status/`: Make it route on ResourceSite.
- 404: Make it render a 404 on ResourceSite.

Test Plan:
- Visited all URIs on ResourceSite, got sensible responses.
- Visited all URIs on main site.
- Visited 404 while logged out, got login page.

Maniphest Tasks: T13636, T12919

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

+103 -26
+6
src/__phutil_library_map__.php
··· 4253 4253 'PhabricatorPhurlURLViewController' => 'applications/phurl/controller/PhabricatorPhurlURLViewController.php', 4254 4254 'PhabricatorPinnedApplicationsSetting' => 'applications/settings/setting/PhabricatorPinnedApplicationsSetting.php', 4255 4255 'PhabricatorPirateEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorPirateEnglishTranslation.php', 4256 + 'PhabricatorPlatform404Controller' => 'applications/base/controller/PhabricatorPlatform404Controller.php', 4256 4257 'PhabricatorPlatformSite' => 'aphront/site/PhabricatorPlatformSite.php', 4257 4258 'PhabricatorPointsEditField' => 'applications/transactions/editfield/PhabricatorPointsEditField.php', 4258 4259 'PhabricatorPointsFact' => 'applications/fact/fact/PhabricatorPointsFact.php', ··· 4689 4690 'PhabricatorResetPasswordUserLogType' => 'applications/people/userlog/PhabricatorResetPasswordUserLogType.php', 4690 4691 'PhabricatorResourceSite' => 'aphront/site/PhabricatorResourceSite.php', 4691 4692 'PhabricatorRobotsController' => 'applications/system/controller/PhabricatorRobotsController.php', 4693 + 'PhabricatorRobotsPlatformController' => 'applications/system/controller/PhabricatorRobotsPlatformController.php', 4694 + 'PhabricatorRobotsResourceController' => 'applications/system/controller/PhabricatorRobotsResourceController.php', 4692 4695 'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php', 4693 4696 'PhabricatorSMSAuthFactor' => 'applications/auth/factor/PhabricatorSMSAuthFactor.php', 4694 4697 'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php', ··· 10914 10917 'PhabricatorPhurlURLViewController' => 'PhabricatorPhurlController', 10915 10918 'PhabricatorPinnedApplicationsSetting' => 'PhabricatorInternalSetting', 10916 10919 'PhabricatorPirateEnglishTranslation' => 'PhutilTranslation', 10920 + 'PhabricatorPlatform404Controller' => 'PhabricatorController', 10917 10921 'PhabricatorPlatformSite' => 'PhabricatorSite', 10918 10922 'PhabricatorPointsEditField' => 'PhabricatorEditField', 10919 10923 'PhabricatorPointsFact' => 'PhabricatorFact', ··· 11471 11475 'PhabricatorResetPasswordUserLogType' => 'PhabricatorUserLogType', 11472 11476 'PhabricatorResourceSite' => 'PhabricatorSite', 11473 11477 'PhabricatorRobotsController' => 'PhabricatorController', 11478 + 'PhabricatorRobotsPlatformController' => 'PhabricatorRobotsController', 11479 + 'PhabricatorRobotsResourceController' => 'PhabricatorRobotsController', 11474 11480 'PhabricatorS3FileStorageEngine' => 'PhabricatorFileStorageEngine', 11475 11481 'PhabricatorSMSAuthFactor' => 'PhabricatorAuthFactor', 11476 11482 'PhabricatorSQLPatchList' => 'Phobject',
+4 -5
src/aphront/configuration/AphrontApplicationConfiguration.php
··· 32 32 return $request; 33 33 } 34 34 35 - public function build404Controller() { 36 - return array(new Phabricator404Controller(), array()); 37 - } 38 - 39 35 public function buildRedirectController($uri, $external) { 40 36 return array( 41 37 new PhabricatorRedirectController(), ··· 504 500 return array($result, array()); 505 501 } 506 502 507 - return $this->build404Controller(); 503 + throw new Exception( 504 + pht( 505 + 'Aphront site ("%s") failed to build a 404 controller.', 506 + get_class($site))); 508 507 } 509 508 510 509 /**
+8 -1
src/aphront/response/Aphront404Response.php
··· 10 10 $request = $this->getRequest(); 11 11 $viewer = $request->getViewer(); 12 12 13 + // See T13636. Note that this response may be served from a Site other than 14 + // the primary PlatformSite. For now, always link to the PlatformSite. 15 + 16 + // (This may not be the best possible place to send users who are currently 17 + // on "real" sites, like the BlogSite.) 18 + $return_uri = PhabricatorEnv::getURI('/'); 19 + 13 20 $dialog = id(new AphrontDialogView()) 14 21 ->setViewer($viewer) 15 22 ->setTitle(pht('404 Not Found')) 16 - ->addCancelButton('/', pht('Return to Charted Waters')) 23 + ->addCancelButton($return_uri, pht('Return to Charted Waters')) 17 24 ->appendParagraph( 18 25 pht( 19 26 'You arrive at your destination, but there is nothing here.'))
+1 -1
src/aphront/site/AphrontSite.php
··· 10 10 abstract public function getRoutingMaps(); 11 11 12 12 public function new404Controller(AphrontRequest $request) { 13 - return null; 13 + return new Phabricator404Controller(); 14 14 } 15 15 16 16 protected function isHostMatch($host, array $uris) {
+4
src/aphront/site/PhabricatorPlatformSite.php
··· 50 50 return $maps; 51 51 } 52 52 53 + public function new404Controller(AphrontRequest $request) { 54 + return new PhabricatorPlatform404Controller(); 55 + } 56 + 53 57 }
+7 -1
src/applications/auth/extension/PhabricatorAuthMainMenuBarExtension.php
··· 39 39 private function buildLoginMenu() { 40 40 $controller = $this->getController(); 41 41 42 - $uri = new PhutilURI('/auth/start/'); 42 + // See T13636. This button may be rendered by the 404 controller on sites 43 + // other than the primary PlatformSite. Link the button to the primary 44 + // site. 45 + 46 + $uri = '/auth/start/'; 47 + $uri = PhabricatorEnv::getURI($uri); 48 + $uri = new PhutilURI($uri); 43 49 if ($controller) { 44 50 $path = $controller->getRequest()->getPath(); 45 51 $uri->replaceQueryParam('next', $path);
+6 -1
src/applications/base/controller/Phabricator404Controller.php
··· 1 1 <?php 2 2 3 - final class Phabricator404Controller extends PhabricatorController { 3 + final class Phabricator404Controller 4 + extends PhabricatorController { 5 + 6 + public function shouldRequireLogin() { 7 + return false; 8 + } 4 9 5 10 public function processRequest() { 6 11 return new Aphront404Response();
+10
src/applications/base/controller/PhabricatorPlatform404Controller.php
··· 1 + <?php 2 + 3 + final class PhabricatorPlatform404Controller 4 + extends PhabricatorController { 5 + 6 + public function processRequest() { 7 + return new Aphront404Response(); 8 + } 9 + 10 + }
+9 -1
src/applications/system/application/PhabricatorSystemApplication.php
··· 25 25 '/status/' => 'PhabricatorStatusController', 26 26 '/debug/' => 'PhabricatorDebugController', 27 27 '/favicon.ico' => 'PhabricatorFaviconController', 28 - '/robots.txt' => 'PhabricatorRobotsController', 28 + '/robots.txt' => 'PhabricatorRobotsPlatformController', 29 29 '/services/' => array( 30 30 'encoding/' => 'PhabricatorSystemSelectEncodingController', 31 31 'highlight/' => 'PhabricatorSystemSelectHighlightController', ··· 35 35 '(?P<reason>[^/]+)/' => 'PhabricatorSystemReadOnlyController', 36 36 ), 37 37 '/object/(?P<name>[^/]+)/' => 'PhabricatorSystemObjectController', 38 + ); 39 + } 40 + 41 + public function getResourceRoutes() { 42 + return array( 43 + '/status/' => 'PhabricatorStatusController', 44 + '/favicon.ico' => 'PhabricatorFaviconController', 45 + '/robots.txt' => 'PhabricatorRobotsResourceController', 38 46 ); 39 47 } 40 48
+6 -16
src/applications/system/controller/PhabricatorRobotsController.php
··· 1 1 <?php 2 2 3 - final class PhabricatorRobotsController extends PhabricatorController { 3 + abstract class PhabricatorRobotsController extends PhabricatorController { 4 4 5 5 public function shouldRequireLogin() { 6 6 return false; 7 7 } 8 8 9 - public function processRequest() { 10 - $out = array(); 11 - 12 - // Prevent indexing of '/diffusion/', since the content is not generally 13 - // useful to index, web spiders get stuck scraping the history of every 14 - // file, and much of the content is Ajaxed in anyway so spiders won't even 15 - // see it. These pages are also relatively expensive to generate. 16 - 17 - // Note that this still allows commits (at '/rPxxxxx') to be indexed. 18 - // They're probably not hugely useful, but suffer fewer of the problems 19 - // Diffusion suffers and are hard to omit with 'robots.txt'. 20 - 21 - $out[] = 'User-Agent: *'; 22 - $out[] = 'Disallow: /diffusion/'; 23 - $out[] = 'Disallow: /source/'; 9 + final public function processRequest() { 10 + $out = $this->newRobotsRules(); 24 11 25 12 // Add a small crawl delay (number of seconds between requests) for spiders 26 13 // which respect it. The intent here is to prevent spiders from affecting ··· 36 23 ->setCacheDurationInSeconds(phutil_units('2 hours in seconds')) 37 24 ->setCanCDN(true); 38 25 } 26 + 27 + abstract protected function newRobotsRules(); 28 + 39 29 }
+25
src/applications/system/controller/PhabricatorRobotsPlatformController.php
··· 1 + <?php 2 + 3 + final class PhabricatorRobotsPlatformController 4 + extends PhabricatorRobotsController { 5 + 6 + protected function newRobotsRules() { 7 + $out = array(); 8 + 9 + // Prevent indexing of '/diffusion/', since the content is not generally 10 + // useful to index, web spiders get stuck scraping the history of every 11 + // file, and much of the content is Ajaxed in anyway so spiders won't even 12 + // see it. These pages are also relatively expensive to generate. 13 + 14 + // Note that this still allows commits (at '/rPxxxxx') to be indexed. 15 + // They're probably not hugely useful, but suffer fewer of the problems 16 + // Diffusion suffers and are hard to omit with 'robots.txt'. 17 + 18 + $out[] = 'User-Agent: *'; 19 + $out[] = 'Disallow: /diffusion/'; 20 + $out[] = 'Disallow: /source/'; 21 + 22 + return $out; 23 + } 24 + 25 + }
+17
src/applications/system/controller/PhabricatorRobotsResourceController.php
··· 1 + <?php 2 + 3 + final class PhabricatorRobotsResourceController 4 + extends PhabricatorRobotsController { 5 + 6 + protected function newRobotsRules() { 7 + $out = array(); 8 + 9 + // See T13636. Prevent indexing of any content on resource domains. 10 + 11 + $out[] = 'User-Agent: *'; 12 + $out[] = 'Disallow: /'; 13 + 14 + return $out; 15 + } 16 + 17 + }