getResourceURIMapRules() + array( '/(?:(?Pjump)/)?' => 'PhabricatorDirectoryMainController', '/(?:(?Pfeed)/)' => array( 'public/' => 'PhabricatorFeedPublicStreamController', '(?:(?P[^/]+)/)?' => 'PhabricatorDirectoryMainController', ), '/directory/' => array( '(?P\d+)/' => 'PhabricatorDirectoryCategoryViewController', 'edit/' => 'PhabricatorDirectoryEditController', 'item/edit/(?:(?P\d+)/)?' => 'PhabricatorDirectoryItemEditController', 'item/delete/(?P\d+)/' => 'PhabricatorDirectoryItemDeleteController', 'category/edit/(?:(?P\d+)/)?' => 'PhabricatorDirectoryCategoryEditController', 'category/delete/(?P\d+)/' => 'PhabricatorDirectoryCategoryDeleteController', ), '/file/' => array( '' => 'PhabricatorFileListController', 'filter/(?P\w+)/' => 'PhabricatorFileListController', 'upload/' => 'PhabricatorFileUploadController', 'dropupload/' => 'PhabricatorFileDropUploadController', 'delete/(?P\d+)/' => 'PhabricatorFileDeleteController', 'info/(?P[^/]+)/' => 'PhabricatorFileInfoController', 'data/(?P[^/]+)/(?P[^/]+)/.*' => 'PhabricatorFileDataController', // TODO: This is a deprecated version of /data/. Remove it after // old links have had a chance to rot. 'alt/(?P[^/]+)/(?P[^/]+)/' => 'PhabricatorFileDataController', 'macro/' => array( '' => 'PhabricatorFileMacroListController', 'edit/(?:(?P\d+)/)?' => 'PhabricatorFileMacroEditController', 'delete/(?P\d+)/' => 'PhabricatorFileMacroDeleteController', ), 'proxy/' => 'PhabricatorFileProxyController', 'xform/(?P[^/]+)/(?P[^/]+)/' => 'PhabricatorFileTransformController', ), '/phid/' => array( '' => 'PhabricatorPHIDLookupController', ), '/people/' => array( '' => 'PhabricatorPeopleListController', 'logs/' => 'PhabricatorPeopleLogsController', 'edit/(?:(?P\d+)/(?:(?P\w+)/)?)?' => 'PhabricatorPeopleEditController', ), '/p/(?P\w+)/(?:(?P\w+)/)?' => 'PhabricatorPeopleProfileController', '/conduit/' => array( '' => 'PhabricatorConduitConsoleController', 'method/(?P[^/]+)/' => 'PhabricatorConduitConsoleController', 'log/' => 'PhabricatorConduitLogController', 'log/view/(?P[^/]+)/' => 'PhabricatorConduitLogController', 'token/' => 'PhabricatorConduitTokenController', ), '/api/(?P[^/]+)' => 'PhabricatorConduitAPIController', '/D(?P\d+)' => 'DifferentialRevisionViewController', '/differential/' => array( '' => 'DifferentialRevisionListController', 'filter/(?P\w+)/(?:(?P\w+)/)?' => 'DifferentialRevisionListController', 'stats/(?P\w+)/' => 'DifferentialRevisionStatsController', 'diff/' => array( '(?P\d+)/' => 'DifferentialDiffViewController', 'create/' => 'DifferentialDiffCreateController', ), 'changeset/' => 'DifferentialChangesetViewController', 'revision/edit/(?:(?P\d+)/)?' => 'DifferentialRevisionEditController', 'comment/' => array( 'preview/(?P\d+)/' => 'DifferentialCommentPreviewController', 'save/' => 'DifferentialCommentSaveController', 'inline/' => array( 'preview/(?P\d+)/' => 'DifferentialInlineCommentPreviewController', 'edit/(?P\d+)/' => 'DifferentialInlineCommentEditController', ), ), 'subscribe/(?Padd|rem)/(?P\d+)/' => 'DifferentialSubscribeController', ), '/typeahead/' => array( 'common/(?P\w+)/' => 'PhabricatorTypeaheadCommonDatasourceController', ), '/mail/' => array( '' => 'PhabricatorMetaMTAListController', 'send/' => 'PhabricatorMetaMTASendController', 'view/(?P\d+)/' => 'PhabricatorMetaMTAViewController', 'lists/' => 'PhabricatorMetaMTAMailingListsController', 'lists/edit/(?:(?P\d+)/)?' => 'PhabricatorMetaMTAMailingListEditController', 'receive/' => 'PhabricatorMetaMTAReceiveController', 'received/' => 'PhabricatorMetaMTAReceivedListController', 'sendgrid/' => 'PhabricatorMetaMTASendGridReceiveController', ), '/login/' => array( '' => 'PhabricatorLoginController', 'email/' => 'PhabricatorEmailLoginController', 'etoken/(?P\w+)/' => 'PhabricatorEmailTokenController', 'refresh/' => 'PhabricatorRefreshCSRFController', 'validate/' => 'PhabricatorLoginValidateController', ), '/logout/' => 'PhabricatorLogoutController', '/oauth/' => array( '(?P\w+)/' => array( 'login/' => 'PhabricatorOAuthLoginController', 'diagnose/' => 'PhabricatorOAuthDiagnosticsController', 'unlink/' => 'PhabricatorOAuthUnlinkController', ), ), '/oauthserver/' => array( 'auth/' => 'PhabricatorOAuthServerAuthController', 'test/' => 'PhabricatorOAuthServerTestController', 'token/' => 'PhabricatorOAuthServerTokenController', 'clientauthorization/' => array( '' => 'PhabricatorOAuthClientAuthorizationListController', 'delete/(?P[^/]+)/' => 'PhabricatorOAuthClientAuthorizationDeleteController', 'edit/(?P[^/]+)/' => 'PhabricatorOAuthClientAuthorizationEditController', ), 'client/' => array( '' => 'PhabricatorOAuthClientListController', 'create/' => 'PhabricatorOAuthClientEditController', 'delete/(?P[^/]+)/' => 'PhabricatorOAuthClientDeleteController', 'edit/(?P[^/]+)/' => 'PhabricatorOAuthClientEditController', 'view/(?P[^/]+)/' => 'PhabricatorOAuthClientViewController', ), ), '/xhprof/' => array( 'profile/(?P[^/]+)/' => 'PhabricatorXHProfProfileController', ), '/~/' => 'DarkConsoleController', '/settings/' => array( '(?:page/(?P[^/]+)/)?' => 'PhabricatorUserSettingsController', ), '/maniphest/' => array( '' => 'ManiphestTaskListController', 'view/(?P\w+)/' => 'ManiphestTaskListController', 'report/(?:(?P\w+)/)?' => 'ManiphestReportController', 'batch/' => 'ManiphestBatchEditController', 'task/' => array( 'create/' => 'ManiphestTaskEditController', 'edit/(?P\d+)/' => 'ManiphestTaskEditController', 'descriptionchange/(?:(?P\d+)/)?' => 'ManiphestTaskDescriptionChangeController', 'descriptionpreview/' => 'ManiphestTaskDescriptionPreviewController', ), 'transaction/' => array( 'save/' => 'ManiphestTransactionSaveController', 'preview/(?P\d+)/' => 'ManiphestTransactionPreviewController', ), 'export/(?P[^/]+)/' => 'ManiphestExportController', 'subpriority/' => 'ManiphestSubpriorityController', ), '/T(?P\d+)' => 'ManiphestTaskDetailController', '/repository/' => array( '' => 'PhabricatorRepositoryListController', 'create/' => 'PhabricatorRepositoryCreateController', 'edit/(?P\d+)/(?:(?P\w+)?/)?' => 'PhabricatorRepositoryEditController', 'delete/(?P\d+)/' => 'PhabricatorRepositoryDeleteController', 'project/(?P\d+)/' => 'PhabricatorRepositoryArcanistProjectEditController', ), '/search/' => array( '' => 'PhabricatorSearchController', '(?P[^/]+)/' => 'PhabricatorSearchController', 'attach/(?P[^/]+)/(?P\w+)/(?:(?P\w+)/)?' => 'PhabricatorSearchAttachController', 'select/(?P\w+)/' => 'PhabricatorSearchSelectController', 'index/(?P[^/]+)/' => 'PhabricatorSearchIndexController', ), '/project/' => array( '' => 'PhabricatorProjectListController', 'filter/(?P[^/]+)/' => 'PhabricatorProjectListController', 'edit/(?P\d+)/' => 'PhabricatorProjectProfileEditController', 'view/(?P\d+)/(?:(?P\w+)/)?' => 'PhabricatorProjectProfileController', 'create/' => 'PhabricatorProjectCreateController', 'update/(?P\d+)/(?P[^/]+)/' => 'PhabricatorProjectUpdateController', ), '/r(?P[A-Z]+)(?P[a-z0-9]+)' => 'DiffusionCommitController', '/diffusion/' => array( '' => 'DiffusionHomeController', '(?P[A-Z]+)/' => array( '' => 'DiffusionRepositoryController', 'repository/(?P.*)' => 'DiffusionRepositoryController', 'change/(?P.*)' => 'DiffusionChangeController', 'history/(?P.*)' => 'DiffusionHistoryController', 'browse/(?P.*)' => 'DiffusionBrowseController', 'lastmodified/(?P.*)' => 'DiffusionLastModifiedController', 'diff/' => 'DiffusionDiffController', ), 'inline/(?P[^/]+)/' => 'DiffusionInlineCommentController', 'services/' => array( 'path/' => array( 'complete/' => 'DiffusionPathCompleteController', 'validate/' => 'DiffusionPathValidateController', ), ), 'symbol/(?P[^/]+)/' => 'DiffusionSymbolController', 'external/' => 'DiffusionExternalController', ), '/daemon/' => array( 'task/(?P\d+)/' => 'PhabricatorWorkerTaskDetailController', 'task/(?P\d+)/(?P[^/]+)/' => 'PhabricatorWorkerTaskUpdateController', 'log/' => array( '' => 'PhabricatorDaemonLogListController', 'combined/' => 'PhabricatorDaemonCombinedLogController', '(?P\d+)/' => 'PhabricatorDaemonLogViewController', ), 'timeline/' => 'PhabricatorDaemonTimelineConsoleController', 'timeline/(?P\d+)/' => 'PhabricatorDaemonTimelineEventController', '' => 'PhabricatorDaemonConsoleController', ), '/herald/' => array( '' => 'HeraldHomeController', 'view/(?P[^/]+)/(?:(?P[^/]+)/)?' => 'HeraldHomeController', 'new/(?:(?P[^/]+)/(?:(?P[^/]+)/)?)?' => 'HeraldNewController', 'rule/(?:(?P\d+)/)?' => 'HeraldRuleController', 'history/(?:(?P\d+)/)?' => 'HeraldRuleEditHistoryController', 'delete/(?P\d+)/' => 'HeraldDeleteController', 'test/' => 'HeraldTestConsoleController', 'transcript/' => 'HeraldTranscriptListController', 'transcript/(?P\d+)/(?:(?P\w+)/)?' => 'HeraldTranscriptController', ), '/uiexample/' => array( '' => 'PhabricatorUIExampleRenderController', 'view/(?P[^/]+)/' => 'PhabricatorUIExampleRenderController', ), '/owners/' => array( '' => 'PhabricatorOwnersListController', 'view/(?P[^/]+)/' => 'PhabricatorOwnersListController', 'edit/(?P\d+)/' => 'PhabricatorOwnersEditController', 'new/' => 'PhabricatorOwnersEditController', 'package/(?P\d+)/' => 'PhabricatorOwnersDetailController', 'delete/(?P\d+)/' => 'PhabricatorOwnersDeleteController', ), '/audit/' => array( '' => 'PhabricatorAuditListController', 'view/(?P[^/]+)/(?:(?P[^/]+)/)?' => 'PhabricatorAuditListController', 'addcomment/' => 'PhabricatorAuditAddCommentController', 'preview/(?P\d+)/' => 'PhabricatorAuditPreviewController', ), '/xhpast/' => array( '' => 'PhabricatorXHPASTViewRunController', 'view/(?P\d+)/' => 'PhabricatorXHPASTViewFrameController', 'frameset/(?P\d+)/' => 'PhabricatorXHPASTViewFramesetController', 'input/(?P\d+)/' => 'PhabricatorXHPASTViewInputController', 'tree/(?P\d+)/' => 'PhabricatorXHPASTViewTreeController', 'stream/(?P\d+)/' => 'PhabricatorXHPASTViewStreamController', ), '/status/' => 'PhabricatorStatusController', '/paste/' => array( '' => 'PhabricatorPasteListController', 'filter/(?P\w+)/' => 'PhabricatorPasteListController', ), '/P(?P\d+)' => 'PhabricatorPasteViewController', '/help/' => array( 'keyboardshortcut/' => 'PhabricatorHelpKeyboardShortcutController', ), '/countdown/' => array( '' => 'PhabricatorCountdownListController', '(?P\d+)/' => 'PhabricatorCountdownViewController', 'edit/(?:(?P\d+)/)?' => 'PhabricatorCountdownEditController', 'delete/(?P\d+)/' => 'PhabricatorCountdownDeleteController' ), '/V(?P\d+)' => 'PhabricatorSlowvotePollController', '/vote/' => array( '(?:view/(?P\w+)/)?' => 'PhabricatorSlowvoteListController', 'create/' => 'PhabricatorSlowvoteCreateController', ), // Match "/w/" with slug "/". '/w(?P/)' => 'PhrictionDocumentController', // Match "/w/x/y/z/" with slug "x/y/z/". '/w/(?P.+/)' => 'PhrictionDocumentController', '/phriction/' => array( '' => 'PhrictionListController', 'list/(?P[^/]+)/' => 'PhrictionListController', 'history(?P/)' => 'PhrictionHistoryController', 'history/(?P.+/)' => 'PhrictionHistoryController', 'edit/(?:(?P\d+)/)?' => 'PhrictionEditController', 'delete/(?P\d+)/' => 'PhrictionDeleteController', 'preview/' => 'PhrictionDocumentPreviewController', 'diff/(?P\d+)/' => 'PhrictionDiffController', ), '/calendar/' => array( '' => 'PhabricatorCalendarBrowseController', ), '/drydock/' => array( '' => 'DrydockResourceListController', 'resource/' => 'DrydockResourceListController', 'resource/allocate/' => 'DrydockResourceAllocateController', 'host/' => array( '' => 'DrydockHostListController', 'edit/' => 'DrydockHostEditController', 'edit/(?P\d+)/' => 'DrydockhostEditController', ), 'lease/' => 'DrydockLeaseListController', 'log/' => 'DrydockLogController', ), '/chatlog/' => array( '' => 'PhabricatorChatLogChannelListController', 'channel/(?P[^/]+)/' => 'PhabricatorChatLogChannelLogController', ), '/aphlict/' => 'PhabricatorAphlictTestPageController', '/flag/' => array( '' => 'PhabricatorFlagListController', 'view/(?P[^/]+)/' => 'PhabricatorFlagListController', 'edit/(?P[^/]+)/' => 'PhabricatorFlagEditController', 'delete/(?P\d+)/' => 'PhabricatorFlagDeleteController', ), '/phortune/' => array( 'stripe/' => array( 'testpaymentform/' => 'PhortuneStripeTestPaymentFormController', ), ), ); } protected function getResourceURIMapRules() { return array( '/res/' => array( '(?Ppkg/)?(?P[a-f0-9]{8})/(?P.+\.(?:css|js))' => 'CelerityResourceController', ), ); } public function buildRequest() { $request = new AphrontRequest($this->getHost(), $this->getPath()); $request->setRequestData($_GET + $_POST); $request->setApplicationConfiguration($this); return $request; } public function handleException(Exception $ex) { // Always log the unhandled exception. phlog($ex); $class = phutil_escape_html(get_class($ex)); $message = phutil_escape_html($ex->getMessage()); $user = $this->getRequest()->getUser(); if (!$user) { // If we hit an exception very early, we won't have a user. $user = new PhabricatorUser(); } if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) { $trace = $this->renderStackTrace($ex->getTrace(), $user); } else { $trace = null; } $content = '
'. '
'.$message.'
'. $trace. '
'; $dialog = new AphrontDialogView(); $dialog ->setTitle('Unhandled Exception ("'.$class.'")') ->setClass('aphront-exception-dialog') ->setUser($user) ->appendChild($content); if ($this->getRequest()->isAjax()) { $dialog->addCancelButton('/', 'Close'); } $response = new AphrontDialogResponse(); $response->setDialog($dialog); return $response; } public function willSendResponse(AphrontResponse $response) { $request = $this->getRequest(); $response->setRequest($request); if ($response instanceof AphrontDialogResponse) { if (!$request->isAjax()) { $view = new PhabricatorStandardPageView(); $view->setRequest($request); $view->appendChild( '
'. $response->buildResponseString(). '
'); $response = new AphrontWebpageResponse(); $response->setContent($view->render()); return $response; } else { return id(new AphrontAjaxResponse()) ->setContent(array( 'dialog' => $response->buildResponseString(), )); } } else if ($response instanceof AphrontRedirectResponse) { if ($request->isAjax()) { return id(new AphrontAjaxResponse()) ->setContent( array( 'redirect' => $response->getURI(), )); } } return $response; } public function build404Controller() { return array(new Phabricator404Controller($this->getRequest()), array()); } public function buildRedirectController($uri) { return array( new PhabricatorRedirectController($this->getRequest()), array( 'uri' => $uri, )); } private function renderStackTrace($trace, PhabricatorUser $user) { $libraries = PhutilBootloader::getInstance()->getAllLibraries(); // TODO: Make this configurable? $path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/'; $callsigns = array( 'arcanist' => 'ARC', 'phutil' => 'PHU', 'phabricator' => 'P', ); $rows = array(); $depth = count($trace); foreach ($trace as $part) { $lib = null; $file = idx($part, 'file'); $relative = $file; foreach ($libraries as $library) { $root = phutil_get_library_root($library); if (Filesystem::isDescendant($file, $root)) { $lib = $library; $relative = Filesystem::readablePath($file, $root); break; } } $where = ''; if (isset($part['class'])) { $where .= $part['class'].'::'; } if (isset($part['function'])) { $where .= $part['function'].'()'; } if ($file) { if (isset($callsigns[$lib])) { $attrs = array('title' => $file); try { $attrs['href'] = $user->loadEditorLink( '/src/'.$relative, $part['line'], $callsigns[$lib]); } catch (Exception $ex) { // The database can be inaccessible. } if (empty($attrs['href'])) { $attrs['href'] = sprintf($path, $callsigns[$lib]). str_replace(DIRECTORY_SEPARATOR, '/', $relative). '$'.$part['line']; $attrs['target'] = '_blank'; } $file_name = phutil_render_tag( 'a', $attrs, phutil_escape_html($relative)); } else { $file_name = phutil_render_tag( 'span', array( 'title' => $file, ), phutil_escape_html($relative)); } $file_name = $file_name.' : '.(int)$part['line']; } else { $file_name = '(Internal)'; } $rows[] = array( $depth--, phutil_escape_html($lib), $file_name, phutil_escape_html($where), ); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'Depth', 'Library', 'File', 'Where', )); $table->setColumnClasses( array( 'n', '', '', 'wide', )); return '
'. '
Stack Trace
'. $table->render(). '
'; } }