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

Allow custom Sites to have custom 404 controllers

Summary:
Currently, custom Sites must match `.*` or similar to handle 404's, since the fallback is always generic.

This locks them out of the "redirect to canonicalize to `path/` code", so they currently have a choice between a custom 404 page or automatic correction of `/`.

Instead, allow the 404 controller to be constructed explicitly. Sites can now customize 404 by implementing this method and not matching everything.

(Sites can still match everything with a catchall rule if they don't want this behavior for some reason, so this should be strictly more powerful than the old behavior.)

See next diff for CORGI.

Test Plan:
- Visited real 404 (like "/asdfafewfq"), missing-slash-404 (like "/maniphest") and real page (like "/maniphest/") URIs on blog, main, and CORGI sites.
- Got 404 behavior, redirects, and real pages, respectively.

Reviewers: chad

Reviewed By: chad

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

+25 -5
+7
src/aphront/AphrontRequest.php
··· 545 545 return id(new PhutilURI($path))->setQueryParams($get); 546 546 } 547 547 548 + public function getAbsoluteRequestURI() { 549 + $uri = $this->getRequestURI(); 550 + $uri->setDomain($this->getHost()); 551 + $uri->setProtocol($this->isHTTPS() ? 'https' : 'http'); 552 + return $uri; 553 + } 554 + 548 555 public function isDialogFormPost() { 549 556 return $this->isFormPost() && $this->getStr('__dialog__'); 550 557 }
+10 -4
src/aphront/configuration/AphrontApplicationConfiguration.php
··· 409 409 if (!preg_match('@/$@', $path) && $request->isHTTPGet()) { 410 410 $result = $this->routePath($maps, $path.'/'); 411 411 if ($result) { 412 - $slash_uri = $request->getRequestURI()->setPath($path.'/'); 412 + $target_uri = $request->getAbsoluteRequestURI(); 413 413 414 414 // We need to restore URI encoding because the webserver has 415 415 // interpreted it. For example, this allows us to redirect a path 416 416 // like `/tag/aa%20bb` to `/tag/aa%20bb/`, which may eventually be 417 417 // resolved meaningfully by an application. 418 - $slash_uri = phutil_escape_uri($slash_uri); 418 + $target_path = phutil_escape_uri($path.'/'); 419 + $target_uri->setPath($target_path); 420 + $target_uri = (string)$target_uri; 419 421 420 - $external = strlen($request->getRequestURI()->getDomain()); 421 - return $this->buildRedirectController($slash_uri, $external); 422 + return $this->buildRedirectController($target_uri, true); 422 423 } 424 + } 425 + 426 + $result = $site->new404Controller($request); 427 + if ($result) { 428 + return array($result, array()); 423 429 } 424 430 425 431 return $this->build404Controller();
+4
src/aphront/site/AphrontSite.php
··· 9 9 abstract public function newSiteForRequest(AphrontRequest $request); 10 10 abstract public function getRoutingMaps(); 11 11 12 + public function new404Controller(AphrontRequest $request) { 13 + return null; 14 + } 15 + 12 16 protected function isHostMatch($host, array $uris) { 13 17 foreach ($uris as $uri) { 14 18 if (!strlen($uri)) {
-1
src/applications/phame/application/PhabricatorPhameApplication.php
··· 92 92 '/' => array( 93 93 '' => 'PhameBlogViewController', 94 94 'post/(?P<id>\d+)/(?:(?P<slug>[^/]+)/)?' => 'PhamePostViewController', 95 - '.*' => 'PhameBlog404Controller', 96 95 ), 97 96 98 97 );
+4
src/applications/phame/site/PhameBlogSite.php
··· 60 60 return id(new PhameBlogSite())->setBlog($blog); 61 61 } 62 62 63 + public function new404Controller(AphrontRequest $request) { 64 + return new PhameBlog404Controller(); 65 + } 66 + 63 67 public function getRoutingMaps() { 64 68 $app = PhabricatorApplication::getByClass('PhabricatorPhameApplication'); 65 69