From 9f04548ab9183dffcc89b871005923aa06c08f87 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 29 Jan 2011 16:16:09 -0800 Subject: [PATCH 1/3] I guess this can support JS too. --- scripts/celerity_mapper.php | 14 ++++++++++- src/__phutil_library_map__.php | 2 ++ .../AphrontApplicationConfiguration.php | 5 ++++ ...AphrontDefaultApplicationConfiguration.php | 4 +++ .../404/Phabricator404Controller.php | 25 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/applications/base/controller/404/Phabricator404Controller.php diff --git a/scripts/celerity_mapper.php b/scripts/celerity_mapper.php index d281da41ce..7fa40e2d87 100755 --- a/scripts/celerity_mapper.php +++ b/scripts/celerity_mapper.php @@ -111,12 +111,24 @@ foreach ($file_map as $path => $info) { $package_map = array(); foreach ($package_spec as $name => $package) { $hashes = array(); + $type = null; foreach ($package as $symbol) { if (empty($hash_map[$symbol])) { throw new Exception( "Package specification for '{$name}' includes '{$symbol}', but that ". "symbol is not defined anywhere."); } + if ($type === null) { + $type = $runtime_map[$symbol]['type']; + } else { + $ntype = $runtime_map[$symbol]['type']; + if ($type !== $ntype) { + throw new Exception( + "Package specification for '{$name}' mixes resources of type ". + "'{$type}' with resources of type '{$ntype}'. Each package may only ". + "contain one type of resource."); + } + } $hashes[] = $symbol.':'.$hash_map[$symbol]; } $key = substr(md5(implode("\n", $hashes)), 0, 8); @@ -124,7 +136,7 @@ foreach ($package_spec as $name => $package) { 'name' => $name, 'symbols' => $package, 'uri' => '/res/pkg/'.$key.'/'.$name, - 'type' => 'css', // TODO LOL + 'type' => $type, ); foreach ($package as $symbol) { $package_map['reverse'][$symbol] = $key; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 94cf87f8f7..74defb7455 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -97,6 +97,7 @@ phutil_register_library_map(array( 'DifferentialUnitStatus' => 'applications/differential/constants/unitstatus', 'Javelin' => 'infratructure/javelin/api', 'LiskDAO' => 'storage/lisk/dao', + 'Phabricator404Controller' => 'applications/base/controller/404', 'PhabricatorAuthController' => 'applications/auth/controlller/base', 'PhabricatorConduitAPIController' => 'applications/conduit/controller/api', 'PhabricatorConduitConnectionLog' => 'applications/conduit/storage/connectionlog', @@ -240,6 +241,7 @@ phutil_register_library_map(array( 'DifferentialRevisionListController' => 'DifferentialController', 'DifferentialRevisionUpdateHistoryView' => 'AphrontView', 'DifferentialRevisionViewController' => 'DifferentialController', + 'Phabricator404Controller' => 'PhabricatorController', 'PhabricatorAuthController' => 'PhabricatorController', 'PhabricatorConduitAPIController' => 'PhabricatorConduitController', 'PhabricatorConduitConnectionLog' => 'PhabricatorConduitDAO', diff --git a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php index 32f9bbef9b..cba9578bb4 100644 --- a/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php +++ b/src/aphront/applicationconfiguration/AphrontApplicationConfiguration.php @@ -28,6 +28,7 @@ abstract class AphrontApplicationConfiguration { abstract public function getApplicationName(); abstract public function getURIMap(); abstract public function buildRequest(); + abstract public function build404Controller(); final public function setRequest(AphrontRequest $request) { $this->request = $request; @@ -45,6 +46,10 @@ abstract class AphrontApplicationConfiguration { $path = $request->getPath(); list($controller_class, $uri_data) = $mapper->mapPath($path); + if (!$controller_class) { + return $this->build404Controller(); + } + PhutilSymbolLoader::loadClass($controller_class); $controller = newv($controller_class, array($request)); diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index a5553423ee..c81c7a6c7a 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -155,5 +155,9 @@ class AphrontDefaultApplicationConfiguration return $response; } + public function build404Controller() { + return new Phabricator404Controller($request); + } + } diff --git a/src/applications/base/controller/404/Phabricator404Controller.php b/src/applications/base/controller/404/Phabricator404Controller.php new file mode 100644 index 0000000000..591e7a3c3e --- /dev/null +++ b/src/applications/base/controller/404/Phabricator404Controller.php @@ -0,0 +1,25 @@ + Date: Sun, 30 Jan 2011 08:44:28 -0800 Subject: [PATCH 2/3] Somewhat proper 404 page, plus HTTP response code. --- .../AphrontDefaultApplicationConfiguration.php | 11 ++++++++++- src/aphront/default/configuration/__init__.php | 1 + src/aphront/response/base/AphrontResponse.php | 10 ++++++++++ src/applications/base/controller/404/__init__.php | 13 +++++++++++++ webroot/index.php | 6 ++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/applications/base/controller/404/__init__.php diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index c81c7a6c7a..d040b13277 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -150,13 +150,22 @@ class AphrontDefaultApplicationConfiguration $response->setContent($view->render()); return $response; } + } else if ($response instanceof Aphront404Response) { + $view = new PhabricatorStandardPageView(); + $view->appendChild('404 Not Found'); + $view->setTitle('404 Not Found'); + + $response = new AphrontWebpageResponse(); + $response->setContent($view->render()); + $response->setHTTPResponseCode(404); + return $response; } return $response; } public function build404Controller() { - return new Phabricator404Controller($request); + return array(new Phabricator404Controller($this->getRequest()), array()); } diff --git a/src/aphront/default/configuration/__init__.php b/src/aphront/default/configuration/__init__.php index f841860f69..66935aa326 100644 --- a/src/aphront/default/configuration/__init__.php +++ b/src/aphront/default/configuration/__init__.php @@ -9,6 +9,7 @@ phutil_require_module('phabricator', 'aphront/applicationconfiguration'); phutil_require_module('phabricator', 'aphront/request'); phutil_require_module('phabricator', 'aphront/response/webpage'); +phutil_require_module('phabricator', 'applications/base/controller/404'); phutil_require_module('phabricator', 'view/page/standard'); phutil_require_module('phutil', 'markup'); diff --git a/src/aphront/response/base/AphrontResponse.php b/src/aphront/response/base/AphrontResponse.php index 29a371c08d..c8ea750562 100644 --- a/src/aphront/response/base/AphrontResponse.php +++ b/src/aphront/response/base/AphrontResponse.php @@ -23,6 +23,7 @@ abstract class AphrontResponse { private $request; private $cacheable = false; + private $responseCode = 200; public function setRequest($request) { $this->request = $request; @@ -41,6 +42,15 @@ abstract class AphrontResponse { $this->cacheable = $duration; return $this; } + + public function setHTTPResponseCode($code) { + $this->responseCode = $code; + return $this; + } + + public function getHTTPResponseCode() { + return $this->responseCode; + } public function getCacheHeaders() { if ($this->cacheable) { diff --git a/src/applications/base/controller/404/__init__.php b/src/applications/base/controller/404/__init__.php new file mode 100644 index 0000000000..e3accbe46e --- /dev/null +++ b/src/applications/base/controller/404/__init__.php @@ -0,0 +1,13 @@ +willSendResponse($response); $response->setRequest($request); $response_string = $response->buildResponseString(); + +$code = $response->getHTTPResponseCode(); +if ($code != 200) { + header("HTTP/1.0 {$code}"); +} + $headers = $response->getCacheHeaders(); $headers = array_merge($headers, $response->getHeaders()); foreach ($headers as $header) { From 406a14ebe519aef7906d199649b58d4dcf8a8135 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 30 Jan 2011 09:15:01 -0800 Subject: [PATCH 3/3] Make 404 page somewhat prettier. --- src/__celerity_resource_map__.php | 9 ++++ src/__phutil_library_map__.php | 2 + ...AphrontDefaultApplicationConfiguration.php | 10 ++++- .../default/configuration/__init__.php | 1 + src/aphront/response/base/AphrontResponse.php | 6 +-- .../failure/AphrontRequestFailureView.php | 43 +++++++++++++++++++ src/view/page/failure/__init__.php | 14 ++++++ .../rsrc/css/aphront/request-failure-view.css | 27 ++++++++++++ 8 files changed, 107 insertions(+), 5 deletions(-) create mode 100755 src/view/page/failure/AphrontRequestFailureView.php create mode 100644 src/view/page/failure/__init__.php create mode 100644 webroot/rsrc/css/aphront/request-failure-view.css diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 1500a5ed97..7c73c57ed0 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -34,6 +34,15 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/aphront/panel-view.css', ), + 'aphront-request-failure-view-css' => + array( + 'uri' => '/res/d7df3b42/rsrc/css/aphront/request-failure-view.css', + 'type' => 'css', + 'requires' => + array( + ), + 'disk' => '/rsrc/css/aphront/request-failure-view.css', + ), 'aphront-side-nav-view-css' => array( 'uri' => '/res/0fc0545c/rsrc/css/aphront/side-nav-view.css', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 74defb7455..d7dc179c5a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -45,6 +45,7 @@ phutil_register_library_map(array( 'AphrontRedirectException' => 'aphront/exception/redirect', 'AphrontRedirectResponse' => 'aphront/response/redirect', 'AphrontRequest' => 'aphront/request', + 'AphrontRequestFailureView' => 'view/page/failure', 'AphrontResponse' => 'aphront/response/base', 'AphrontSideNavView' => 'view/layout/sidenav', 'AphrontTableView' => 'view/control/table', @@ -210,6 +211,7 @@ phutil_register_library_map(array( 'AphrontQueryRecoverableException' => 'AphrontQueryException', 'AphrontRedirectException' => 'AphrontException', 'AphrontRedirectResponse' => 'AphrontResponse', + 'AphrontRequestFailureView' => 'AphrontView', 'AphrontSideNavView' => 'AphrontView', 'AphrontTableView' => 'AphrontView', 'AphrontWebpageResponse' => 'AphrontResponse', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index d040b13277..ee7c71caa6 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -151,10 +151,16 @@ class AphrontDefaultApplicationConfiguration return $response; } } else if ($response instanceof Aphront404Response) { + + $failure = new AphrontRequestFailureView(); + $failure->setHeader('404 Not Found'); + $failure->appendChild( + '

The page you requested was not found.

'); + $view = new PhabricatorStandardPageView(); - $view->appendChild('404 Not Found'); $view->setTitle('404 Not Found'); - + $view->appendChild($failure); + $response = new AphrontWebpageResponse(); $response->setContent($view->render()); $response->setHTTPResponseCode(404); diff --git a/src/aphront/default/configuration/__init__.php b/src/aphront/default/configuration/__init__.php index 66935aa326..ea6f86450a 100644 --- a/src/aphront/default/configuration/__init__.php +++ b/src/aphront/default/configuration/__init__.php @@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'aphront/applicationconfiguration'); phutil_require_module('phabricator', 'aphront/request'); phutil_require_module('phabricator', 'aphront/response/webpage'); phutil_require_module('phabricator', 'applications/base/controller/404'); +phutil_require_module('phabricator', 'view/page/failure'); phutil_require_module('phabricator', 'view/page/standard'); phutil_require_module('phutil', 'markup'); diff --git a/src/aphront/response/base/AphrontResponse.php b/src/aphront/response/base/AphrontResponse.php index c8ea750562..786f56b77e 100644 --- a/src/aphront/response/base/AphrontResponse.php +++ b/src/aphront/response/base/AphrontResponse.php @@ -37,17 +37,17 @@ abstract class AphrontResponse { public function getHeaders() { return array(); } - + public function setCacheDurationInSeconds($duration) { $this->cacheable = $duration; return $this; } - + public function setHTTPResponseCode($code) { $this->responseCode = $code; return $this; } - + public function getHTTPResponseCode() { return $this->responseCode; } diff --git a/src/view/page/failure/AphrontRequestFailureView.php b/src/view/page/failure/AphrontRequestFailureView.php new file mode 100755 index 0000000000..832838e921 --- /dev/null +++ b/src/view/page/failure/AphrontRequestFailureView.php @@ -0,0 +1,43 @@ +header = $header; + return $this; + } + + + final public function render() { + require_celerity_resource('aphront-request-failure-view-css'); + + return + '
'. + '
'. + '

'.phutil_escape_html($this->header).'

'. + '
'. + '
'. + $this->renderChildren(). + '
'. + '
'; + } + +} diff --git a/src/view/page/failure/__init__.php b/src/view/page/failure/__init__.php new file mode 100644 index 0000000000..e753355fdb --- /dev/null +++ b/src/view/page/failure/__init__.php @@ -0,0 +1,14 @@ +