diff --git a/src/applications/base/controller/PhabricatorController.php b/src/applications/base/controller/PhabricatorController.php index 495291d59f..6e79333711 100644 --- a/src/applications/base/controller/PhabricatorController.php +++ b/src/applications/base/controller/PhabricatorController.php @@ -1,310 +1,311 @@ shouldAllowPublic()) { return false; } return true; } public function shouldRequireAdmin() { return false; } public function shouldRequireEnabledUser() { return true; } public function shouldAllowPublic() { return false; } public function shouldRequireEmailVerification() { $need_verify = PhabricatorUserEmail::isEmailVerificationRequired(); $need_login = $this->shouldRequireLogin(); return ($need_login && $need_verify); } final public function willBeginExecution() { $request = $this->getRequest(); $user = new PhabricatorUser(); $phusr = $request->getCookie('phusr'); $phsid = $request->getCookie('phsid'); if (strlen($phusr) && $phsid) { $info = queryfx_one( $user->establishConnection('r'), 'SELECT u.* FROM %T u JOIN %T s ON u.phid = s.userPHID AND s.type LIKE %> AND s.sessionKey = %s', $user->getTableName(), 'phabricator_session', 'web-', $phsid); if ($info) { $user->loadFromArray($info); } } $translation = $user->getTranslation(); if ($translation && $translation != PhabricatorEnv::getEnvConfig('translation.provider')) { $translation = newv($translation, array()); PhutilTranslator::getInstance() ->setLanguage($translation->getLanguage()) ->addTranslations($translation->getTranslations()); } $request->setUser($user); if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) { $disabled_user_controller = new PhabricatorDisabledUserController( $request); return $this->delegateToController($disabled_user_controller); } $event = new PhabricatorEvent( PhabricatorEventType::TYPE_CONTROLLER_CHECKREQUEST, array( 'request' => $request, 'controller' => $this, )); $event->setUser($user); PhutilEventEngine::dispatchEvent($event); $checker_controller = $event->getValue('controller'); if ($checker_controller != $this) { return $this->delegateToController($checker_controller); } $preferences = $user->loadPreferences(); if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) { $dark_console = PhabricatorUserPreferences::PREFERENCE_DARK_CONSOLE; if ($preferences->getPreference($dark_console) || PhabricatorEnv::getEnvConfig('darkconsole.always-on')) { $console = new DarkConsoleCore(); $request->getApplicationConfiguration()->setConsole($console); } } if ($this->shouldRequireLogin() && !$user->getPHID()) { $login_controller = new PhabricatorLoginController($request); return $this->delegateToController($login_controller); } if ($this->shouldRequireEmailVerification()) { $email = $user->loadPrimaryEmail(); if (!$email) { throw new Exception( "No primary email address associated with this account!"); } if (!$email->getIsVerified()) { $verify_controller = new PhabricatorMustVerifyEmailController($request); return $this->delegateToController($verify_controller); } } if ($this->shouldRequireAdmin() && !$user->getIsAdmin()) { return new Aphront403Response(); } } public function buildStandardPageView() { $view = new PhabricatorStandardPageView(); $view->setRequest($this->getRequest()); $view->setController($this); return $view; } public function buildStandardPageResponse($view, array $data) { $page = $this->buildStandardPageView(); $page->appendChild($view); $response = new AphrontWebpageResponse(); $response->setContent($page->render()); return $response; } public function getApplicationURI($path = '') { if (!$this->getCurrentApplication()) { throw new Exception("No application!"); } return $this->getCurrentApplication()->getBaseURI().ltrim($path, '/'); } public function buildApplicationPage($view, array $options) { $page = $this->buildStandardPageView(); $application = $this->getCurrentApplication(); if ($application) { $page->setApplicationName($application->getName()); $page->setTitle(idx($options, 'title')); if ($application->getTitleGlyph()) { $page->setGlyph($application->getTitleGlyph()); } } if (!($view instanceof AphrontSideNavFilterView)) { $nav = new AphrontSideNavFilterView(); $nav->appendChild($view); $view = $nav; } $view->setUser($this->getRequest()->getUser()); $page->appendChild($view); if (idx($options, 'device')) { $page->setDeviceReady(true); } $application_menu = $this->buildApplicationMenu(); if ($application_menu) { $page->setApplicationMenu($application_menu); } $response = new AphrontWebpageResponse(); return $response->setContent($page->render()); } public function didProcessRequest($response) { $request = $this->getRequest(); $response->setRequest($request); $seen = array(); while ($response instanceof AphrontProxyResponse) { $hash = spl_object_hash($response); if (isset($seen[$hash])) { $seen[] = get_class($response); throw new Exception( "Cycle while reducing proxy responses: ". implode(' -> ', $seen)); } $seen[$hash] = get_class($response); $response = $response->reduceProxyResponse(); } if ($response instanceof AphrontDialogResponse) { if (!$request->isAjax()) { $view = new PhabricatorStandardPageView(); $view->setRequest($request); $view->setController($this); $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; } protected function getHandle($phid) { if (empty($this->handles[$phid])) { throw new Exception( "Attempting to access handle which wasn't loaded: {$phid}"); } return $this->handles[$phid]; } protected function loadHandles(array $phids) { $phids = array_filter($phids); $this->handles = $this->loadViewerHandles($phids); return $this; } protected function getLoadedHandles() { return $this->handles; } protected function loadViewerHandles(array $phids) { return id(new PhabricatorObjectHandleData($phids)) ->setViewer($this->getRequest()->getUser()) ->loadHandles(); } /** * Render a list of links to handles, identified by PHIDs. The handles must * already be loaded. * * @param list List of PHIDs to render links to. * @param string Style, one of "\n" (to put each item on its own line) * or "," (to list items inline, separated by commas). * @return string Rendered list of handle links. */ protected function renderHandlesForPHIDs(array $phids, $style = "\n") { $style_map = array( "\n" => '
', ',' => ', ', ); if (empty($style_map[$style])) { throw new Exception("Unknown handle list style '{$style}'!"); } $items = array(); foreach ($phids as $phid) { $items[] = $this->getHandle($phid)->renderLink(); } - return implode($style_map[$style], $items); + + return phutil_safe_html(implode($style_map[$style], $items)); } protected function buildApplicationMenu() { return null; } protected function buildApplicationCrumbs() { $crumbs = array(); $application = $this->getCurrentApplication(); if ($application) { $sprite = $application->getIconName(); if (!$sprite) { $sprite = 'application'; } $crumbs[] = id(new PhabricatorCrumbView()) ->setHref($this->getApplicationURI()) ->setIcon($sprite); } $view = new PhabricatorCrumbsView(); foreach ($crumbs as $crumb) { $view->addCrumb($crumb); } return $view; } } diff --git a/src/applications/config/controller/PhabricatorConfigAllController.php b/src/applications/config/controller/PhabricatorConfigAllController.php index e7b46c7c3c..60f95b2263 100644 --- a/src/applications/config/controller/PhabricatorConfigAllController.php +++ b/src/applications/config/controller/PhabricatorConfigAllController.php @@ -1,96 +1,99 @@ getRequest(); $user = $request->getUser(); $rows = array(); $options = PhabricatorApplicationConfigOptions::loadAllOptions(); ksort($options); foreach ($options as $option) { $key = $option->getKey(); if ($option->getMasked()) { $value = ''.pht('Masked').''; } else if ($option->getHidden()) { $value = ''.pht('Hidden').''; } else { $value = PhabricatorEnv::getEnvConfig($key); $value = PhabricatorConfigJSON::prettyPrintJSON($value); $value = phutil_escape_html($value); } $rows[] = array( phutil_tag( 'a', array( 'href' => $this->getApplicationURI('edit/'.$key.'/'), ), $key), $value, ); } $table = id(new AphrontTableView($rows)) ->setDeviceReadyTable(true) ->setColumnClasses( array( '', 'wide', )) ->setHeaders( array( pht('Key'), pht('Value'), )); $title = pht('Current Settings'); $crumbs = $this ->buildApplicationCrumbs() ->addCrumb( id(new PhabricatorCrumbView()) ->setName($title)); $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setNoBackground(); $phabricator_root = dirname(phutil_get_library_root('phabricator')); $future = id(new ExecFuture('git log --format=%%H -n 1 --')) ->setCWD($phabricator_root); list($err, $stdout) = $future->resolve(); if (!$err) { $display_version = trim($stdout); } else { $display_version = pht('Unknown'); } $version_property_list = id(new PhabricatorPropertyListView()); - $version_property_list->addProperty('Version', - phutil_escape_html($display_version)); + $version_property_list->addProperty( + pht('Version'), + $display_version); + $version_path = $phabricator_root.'/conf/local/VERSION'; if (Filesystem::pathExists($version_path)) { $version_from_file = Filesystem::readFile($version_path); - $version_property_list->addProperty('Local Version', - phutil_escape_html($version_from_file)); + $version_property_list->addProperty( + pht('Local Version'), + $version_from_file); } $nav = $this->buildSideNavView(); $nav->selectFilter('all/'); $nav->setCrumbs($crumbs); $nav->appendChild($version_property_list); $nav->appendChild($panel); return $this->buildApplicationPage( $nav, array( 'title' => $title, 'device' => true, ) ); } } diff --git a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php index 7c28657fcd..75f391c5a2 100644 --- a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php +++ b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php @@ -1,186 +1,186 @@ id = $data['id']; } public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $task = id(new PhabricatorWorkerActiveTask())->load($this->id); if (!$task) { $task = id(new PhabricatorWorkerArchiveTask())->load($this->id); } if (!$task) { $title = pht('Task Does Not Exist'); $error_view = new AphrontErrorView(); $error_view->setTitle('No Such Task'); $error_view->appendChild( '

This task may have recently been garbage collected.

'); $error_view->setSeverity(AphrontErrorView::SEVERITY_NODATA); $content = $error_view; } else { $title = 'Task '.$task->getID(); $header = id(new PhabricatorHeaderView()) ->setHeader('Task '.$task->getID().' ('.$task->getTaskClass().')'); $actions = $this->buildActionListView($task); $properties = $this->buildPropertyListView($task); $content = array( $header, $actions, $properties, ); } $nav = $this->buildSideNavView(); $nav->selectFilter(''); $nav->appendChild($content); return $this->buildApplicationPage( $nav, array( 'title' => $title, )); } private function buildActionListView(PhabricatorWorkerTask $task) { $user = $this->getRequest()->getUser(); $view = new PhabricatorActionListView(); $view->setUser($user); $id = $task->getID(); if ($task->isArchived()) { $result_success = PhabricatorWorkerArchiveTask::RESULT_SUCCESS; $can_retry = ($task->getResult() != $result_success); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Retry Task')) ->setHref($this->getApplicationURI('/task/'.$id.'/retry/')) ->setIcon('undo') ->setWorkflow(true) ->setDisabled(!$can_retry)); } else { $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Cancel Task')) ->setHref($this->getApplicationURI('/task/'.$id.'/cancel/')) ->setIcon('delete') ->setWorkflow(true)); } $can_release = (!$task->isArchived()) && ($task->getLeaseOwner()); $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Free Lease')) ->setHref($this->getApplicationURI('/task/'.$id.'/release/')) ->setIcon('unlock') ->setWorkflow(true) ->setDisabled(!$can_release)); return $view; } private function buildPropertyListView(PhabricatorWorkerTask $task) { $view = new PhabricatorPropertyListView(); if ($task->isArchived()) { switch ($task->getResult()) { case PhabricatorWorkerArchiveTask::RESULT_SUCCESS: $status = pht('Complete'); break; case PhabricatorWorkerArchiveTask::RESULT_FAILURE: $status = pht('Failed'); break; case PhabricatorWorkerArchiveTask::RESULT_CANCELLED: $status = pht('Cancelled'); break; default: throw new Exception("Unknown task status!"); } } else { $status = pht('Queued'); } $view->addProperty( pht('Task Status'), $status); $view->addProperty( pht('Task Class'), - phutil_escape_html($task->getTaskClass())); + $task->getTaskClass()); if ($task->getLeaseExpires()) { if ($task->getLeaseExpires() > time()) { $lease_status = pht('Leased'); } else { $lease_status = pht('Lease Expired'); } } else { - $lease_status = ''.pht('Not Leased').''; + $lease_status = phutil_tag('em', array(), pht('Not Leased')); } $view->addProperty( pht('Lease Status'), $lease_status); $view->addProperty( pht('Lease Owner'), $task->getLeaseOwner() - ? phutil_escape_html($task->getLeaseOwner()) - : ''.pht('None').''); + ? $task->getLeaseOwner() + : phutil_tag('em', array(), pht('None'))); if ($task->getLeaseExpires() && $task->getLeaseOwner()) { $expires = ($task->getLeaseExpires() - time()); $expires = phabricator_format_relative_time_detailed($expires); } else { - $expires = ''.pht('None').''; + $expires = phutil_tag('em', array(), pht('None')); } $view->addProperty( pht('Lease Expires'), $expires); $view->addProperty( pht('Failure Count'), - phutil_escape_html($task->getFailureCount())); + $task->getFailureCount()); if ($task->isArchived()) { - $duration = phutil_escape_html(number_format($task->getDuration()).' us'); + $duration = number_format($task->getDuration()).' us'; } else { - $duration = ''.pht('Not Completed').''; + $duration = phutil_tag('em', array(), pht('Not Completed')); } $view->addProperty( pht('Duration'), $duration); $data = id(new PhabricatorWorkerTaskData())->load($task->getDataID()); $task->setData($data->getData()); $worker = $task->getWorkerInstance(); $data = $worker->renderForDisplay(); $view->addProperty( pht('Data'), $data); return $view; } } diff --git a/src/applications/differential/field/specification/DifferentialApplyPatchFieldSpecification.php b/src/applications/differential/field/specification/DifferentialApplyPatchFieldSpecification.php index 3a8c0efd6f..193162cf48 100644 --- a/src/applications/differential/field/specification/DifferentialApplyPatchFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialApplyPatchFieldSpecification.php @@ -1,19 +1,19 @@ getRevision(); - return 'arc patch D'.$revision->getID().''; + return phutil_tag('tt', array(), 'arc patch D'.$revision->getID()); } } diff --git a/src/applications/differential/field/specification/DifferentialArcanistProjectFieldSpecification.php b/src/applications/differential/field/specification/DifferentialArcanistProjectFieldSpecification.php index c64839eb9b..085c8b7824 100644 --- a/src/applications/differential/field/specification/DifferentialArcanistProjectFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialArcanistProjectFieldSpecification.php @@ -1,56 +1,56 @@ getArcanistProjectPHID(); if (!$arcanist_phid) { return array(); } return array($arcanist_phid); } public function renderLabelForRevisionView() { return 'Arcanist Project:'; } public function renderValueForRevisionView() { $arcanist_phid = $this->getArcanistProjectPHID(); if (!$arcanist_phid) { return null; } $handle = $this->getHandle($arcanist_phid); - return phutil_escape_html($handle->getName()); + return $handle->getName(); } private function getArcanistProjectPHID() { $diff = $this->getDiff(); return $diff->getArcanistProjectPHID(); } public function renderValueForMail($phase) { $status = $this->getRevision()->getStatus(); if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION && $status != ArcanistDifferentialRevisionStatus::ACCEPTED) { return null; } $diff = $this->getRevision()->loadActiveDiff(); if ($diff) { $phid = $diff->getArcanistProjectPHID(); if ($phid) { $handle = PhabricatorObjectHandleData::loadOneHandle($phid); return "ARCANIST PROJECT\n ".$handle->getName(); } } } } diff --git a/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php b/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php index 2119d5699e..86b1399df8 100644 --- a/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php @@ -1,49 +1,49 @@ getManualDiff(); $branch = $diff->getBranch(); $bookmark = $diff->getBookmark(); $has_branch = ($branch != ''); $has_bookmark = ($bookmark != ''); if ($has_branch && $has_bookmark) { $branch = "{$bookmark} bookmark on {$branch} branch"; } else if ($has_bookmark) { $branch = "{$bookmark} bookmark"; } else if (!$has_branch) { return null; } - return phutil_escape_html($branch); + return $branch; } public function renderValueForMail($phase) { $status = $this->getRevision()->getStatus(); if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION && $status != ArcanistDifferentialRevisionStatus::ACCEPTED) { return null; } $diff = $this->getRevision()->loadActiveDiff(); if ($diff) { $branch = $diff->getBranch(); if ($branch) { return "BRANCH\n $branch"; } } } } diff --git a/src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php b/src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php index 671e3d5f9f..ae8339c05c 100644 --- a/src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php @@ -1,60 +1,60 @@ getCommitPHIDs(); } public function renderLabelForRevisionView() { return 'Commits:'; } public function renderValueForRevisionView() { $commit_phids = $this->getCommitPHIDs(); if (!$commit_phids) { return null; } $links = array(); foreach ($commit_phids as $commit_phid) { $links[] = $this->getHandle($commit_phid)->renderLink(); } - return implode('
', $links); + return array_interleave(phutil_tag('br'), $links); } private function getCommitPHIDs() { $revision = $this->getRevision(); return $revision->getCommitPHIDs(); } public function renderValueForMail($phase) { $revision = $this->getRevision(); if ($revision->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED) { return null; } $phids = $revision->loadCommitPHIDs(); if (!$phids) { return null; } $body = array(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $body[] = pht('COMMIT(S)', count($handles)); foreach ($handles as $handle) { $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); } return implode("\n", $body); } } diff --git a/src/applications/differential/field/specification/DifferentialDependenciesFieldSpecification.php b/src/applications/differential/field/specification/DifferentialDependenciesFieldSpecification.php index 6d03fe7ecb..43f387bb57 100644 --- a/src/applications/differential/field/specification/DifferentialDependenciesFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialDependenciesFieldSpecification.php @@ -1,38 +1,38 @@ getDependentRevisionPHIDs(); } public function renderLabelForRevisionView() { return 'Dependents:'; } public function renderValueForRevisionView() { $revision_phids = $this->getDependentRevisionPHIDs(); if (!$revision_phids) { return null; } $links = array(); foreach ($revision_phids as $revision_phids) { $links[] = $this->getHandle($revision_phids)->renderLink(); } - return implode('
', $links); + return array_interleave(phutil_tag('br'), $links); } private function getDependentRevisionPHIDs() { return PhabricatorEdgeQuery::loadDestinationPHIDs( $this->getRevision()->getPHID(), PhabricatorEdgeConfig::TYPE_DREV_DEPENDED_ON_BY_DREV); } } diff --git a/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php b/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php index 24096ccabd..09da33abc2 100644 --- a/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php @@ -1,38 +1,38 @@ getDependentRevisionPHIDs(); } public function renderLabelForRevisionView() { return 'Depends On:'; } public function renderValueForRevisionView() { $revision_phids = $this->getDependentRevisionPHIDs(); if (!$revision_phids) { return null; } $links = array(); foreach ($revision_phids as $revision_phids) { $links[] = $this->getHandle($revision_phids)->renderLink(); } - return implode('
', $links); + return phutil_safe_html(implode('
', $links)); } private function getDependentRevisionPHIDs() { return PhabricatorEdgeQuery::loadDestinationPHIDs( $this->getRevision()->getPHID(), PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV); } } diff --git a/src/applications/differential/field/specification/DifferentialExportPatchFieldSpecification.php b/src/applications/differential/field/specification/DifferentialExportPatchFieldSpecification.php index 00c16b4547..313279bcb2 100644 --- a/src/applications/differential/field/specification/DifferentialExportPatchFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialExportPatchFieldSpecification.php @@ -1,19 +1,22 @@ getRevision(); - return 'arc export --revision '.$revision->getID().''; + return phutil_tag( + 'tt', + array(), + 'arc export --revision '.$revision->getID()); } } diff --git a/src/applications/differential/field/specification/DifferentialFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFieldSpecification.php index 2f78967d7d..9453668fae 100644 --- a/src/applications/differential/field/specification/DifferentialFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialFieldSpecification.php @@ -1,1015 +1,1015 @@ value = $request->getStr('my-custom-field'); * * If you have some particularly complicated field, you may need to read * more data; this is why you have access to the entire request. * * You must implement this if you implement @{method:shouldAppearOnEdit}. * * You should not perform field validation here; instead, you should implement * @{method:validateField}. * * @param AphrontRequest HTTP request representing a user submitting a form * with this field in it. * @return this * @task edit */ public function setValueFromRequest(AphrontRequest $request) { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Build a renderable object (generally, some @{class:AphrontFormControl}) * which can be appended to a @{class:AphrontFormView} and represents the * interface the user sees on the "Edit Revision" screen when interacting * with this field. * * For example: * * return id(new AphrontFormTextControl()) * ->setLabel('Custom Field') * ->setName('my-custom-key') * ->setValue($this->value); * * You must implement this if you implement @{method:shouldAppearOnEdit}. * * @return AphrontView|string Something renderable. * @task edit */ public function renderEditControl() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * This method will be called after @{method:setValueFromRequest} but before * the field is saved. It gives you an opportunity to inspect the field value * and throw a @{class:DifferentialFieldValidationException} if there is a * problem with the value the user has provided (for example, the value the * user entered is not correctly formatted). This method is also called after * @{method:setValueFromParsedCommitMessage} before the revision is saved. * * By default, fields are not validated. * * @return void * @task edit */ public function validateField() { return; } /** * Determine if user mentions should be extracted from the value and added to * CC when creating revision. Mentions are then extracted from the string * returned by @{method:renderValueForCommitMessage}. * * By default, mentions are not extracted. * * @return bool * @task edit */ public function shouldExtractMentions() { return false; } /** * Hook for applying revision changes via the editor. Normally, you should * not implement this, but a number of builtin fields use the revision object * itself as storage. If you need to do something similar for whatever reason, * this method gives you an opportunity to interact with the editor or * revision before changes are saved (for example, you can write the field's * value into some property of the revision). * * @param DifferentialRevisionEditor Active editor which is applying changes * to the revision. * @return void * @task edit */ public function willWriteRevision(DifferentialRevisionEditor $editor) { return; } /** * Hook after an edit operation has completed. This allows you to update * link tables or do other write operations which should happen after the * revision is saved. Normally you don't need to implement this. * * * @param DifferentialRevisionEditor Active editor which has just applied * changes to the revision. * @return void * @task edit */ public function didWriteRevision(DifferentialRevisionEditor $editor) { return; } /* -( Extending the Revision View Interface )------------------------------ */ /** * Determine if this field should appear on the revision detail view * interface. One use of this interface is to add purely informational * fields to the revision view, without any sort of backing storage. * * If you return true from this method, you must implement the methods * @{method:renderLabelForRevisionView} and * @{method:renderValueForRevisionView}. * * @return bool True if this field should appear when viewing a revision. * @task view */ public function shouldAppearOnRevisionView() { return false; } /** * Return a string field label which will appear in the revision detail * table. * * You must implement this method if you return true from * @{method:shouldAppearOnRevisionView}. * * @return string Label for field in revision detail view. * @task view */ public function renderLabelForRevisionView() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Return a markup block representing the field for the revision detail * view. Note that you can return null to suppress display (for instance, * if the field shows related objects of some type and the revision doesn't * have any related objects). * * You must implement this method if you return true from * @{method:shouldAppearOnRevisionView}. * * @return string|null Display markup for field value, or null to suppress * field rendering. * @task view */ public function renderValueForRevisionView() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Load users, their current statuses and return a markup with links to the * user profiles and information about their current status. * * @return string Display markup. * @task view */ public function renderUserList(array $user_phids) { if (!$user_phids) { - return 'None'; + return phutil_tag('em', array(), pht('None')); } $links = array(); foreach ($user_phids as $user_phid) { $handle = $this->getHandle($user_phid); $links[] = $handle->renderLink(); } - return implode(', ', $links); + return phutil_safe_html(implode(', ', $links)); } /** * Return a markup block representing a warning to display with the comment * box when preparing to accept a diff. A return value of null indicates no * warning box should be displayed for this field. * * @return string|null Display markup for warning box, or null for no warning */ public function renderWarningBoxForRevisionAccept() { return null; } /* -( Extending the Revision List Interface )------------------------------ */ /** * Determine if this field should appear in the table on the revision list * interface. * * @return bool True if this field should appear in the table. * * @task list */ public function shouldAppearOnRevisionList() { return false; } /** * Return a column header for revision list tables. * * @return string Column header. * * @task list */ public function renderHeaderForRevisionList() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Optionally, return a column class for revision list tables. * * @return string CSS class for table cells. * * @task list */ public function getColumnClassForRevisionList() { return null; } /** * Return a table cell value for revision list tables. * * @param DifferentialRevision The revision to render a value for. * @return string Table cell value. * * @task list */ public function renderValueForRevisionList(DifferentialRevision $revision) { throw new DifferentialFieldSpecificationIncompleteException($this); } /* -( Extending the Diff View Interface )------------------------------ */ /** * Determine if this field should appear on the diff detail view * interface. One use of this interface is to add purely informational * fields to the diff view, without any sort of backing storage. * * NOTE: These diffs are not necessarily attached yet to a revision. * As such, a field on the diff view can not rely on the existence of a * revision or use storage attached to the revision. * * If you return true from this method, you must implement the methods * @{method:renderLabelForDiffView} and * @{method:renderValueForDiffView}. * * @return bool True if this field should appear when viewing a diff. * @task view */ public function shouldAppearOnDiffView() { return false; } /** * Return a string field label which will appear in the diff detail * table. * * You must implement this method if you return true from * @{method:shouldAppearOnDiffView}. * * @return string Label for field in revision detail view. * @task view */ public function renderLabelForDiffView() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Return a markup block representing the field for the diff detail * view. Note that you can return null to suppress display (for instance, * if the field shows related objects of some type and the revision doesn't * have any related objects). * * You must implement this method if you return true from * @{method:shouldAppearOnDiffView}. * * @return string|null Display markup for field value, or null to suppress * field rendering. * @task view */ public function renderValueForDiffView() { throw new DifferentialFieldSpecificationIncompleteException($this); } /* -( Extending the E-mail Interface )------------------------------------- */ /** * Return plain text to render in e-mail messages. The text may span * multiple lines. * * @return int One of DifferentialMailPhase constants. * @return string|null Plain text, or null for no message. * * @task mail */ public function renderValueForMail($phase) { return null; } /* -( Extending the Conduit Interface )------------------------------------ */ /** * @task conduit */ public function shouldAppearOnConduitView() { return false; } /** * @task conduit */ public function getValueForConduit() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * @task conduit */ public function getKeyForConduit() { $key = $this->getStorageKey(); if ($key === null) { throw new DifferentialFieldSpecificationIncompleteException($this); } return $key; } /* -( Extending the Search Interface )------------------------------------ */ /** * @task search */ public function shouldAddToSearchIndex() { return false; } /** * @task search */ public function getValueForSearchIndex() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * NOTE: Keys *must be* 4 characters for * @{class:PhabricatorSearchEngineMySQL}. * * @task search */ public function getKeyForSearchIndex() { throw new DifferentialFieldSpecificationIncompleteException($this); } /* -( Extending Commit Messages )------------------------------------------ */ /** * Determine if this field should appear in commit messages. You should return * true if this field participates in any part of the commit message workflow, * even if it is not rendered by default. * * If you implement this method, you must implement * @{method:getCommitMessageKey} and * @{method:setValueFromParsedCommitMessage}. * * @return bool True if this field appears in commit messages in any capacity. * @task commit */ public function shouldAppearOnCommitMessage() { return false; } /** * Key which identifies this field in parsed commit messages. Commit messages * exist in two forms: raw textual commit messages and parsed dictionaries of * fields. This method must return a unique string which identifies this field * in dictionaries. Principally, this dictionary is shipped to and from arc * over Conduit. Keys should be appropriate property names, like "testPlan" * (not "Test Plan") and must be globally unique. * * You must implement this method if you return true from * @{method:shouldAppearOnCommitMessage}. * * @return string Key which identifies the field in dictionaries. * @task commit */ public function getCommitMessageKey() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Set this field's value from a value in a parsed commit message dictionary. * Afterward, this field will go through the normal write workflows and the * change will be permanently stored via either the storage mechanisms (if * your field implements them), revision write hooks (if your field implements * them) or discarded (if your field implements neither, e.g. is just a * display field). * * The value you receive will either be null or something you originally * returned from @{method:parseValueFromCommitMessage}. * * You must implement this method if you return true from * @{method:shouldAppearOnCommitMessage}. * * @param mixed Field value from a parsed commit message dictionary. * @return this * @task commit */ public function setValueFromParsedCommitMessage($value) { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * In revision control systems which read revision information from the * working copy, the user may edit the commit message outside of invoking * "arc diff --edit". When they do this, only some fields (those fields which * can not be edited by other users) are safe to overwrite. For instance, it * is fine to overwrite "Summary" because no one else can edit it, but not * to overwrite "Reviewers" because reviewers may have been added or removed * via the web interface. * * If a field is safe to overwrite when edited in a working copy commit * message, return true. If the authoritative value should always be used, * return false. By default, fields can not be overwritten. * * arc will only attempt to overwrite field values if run with "--verbatim". * * @return bool True to indicate the field is save to overwrite. * @task commit */ public function shouldOverwriteWhenCommitMessageIsEdited() { return false; } /** * Return true if this field should be suggested to the user during * "arc diff --edit". Basicially, return true if the field is something the * user might want to fill out (like "Summary"), and false if it's a * system/display/readonly field (like "Differential Revision"). If this * method returns true, the field will be rendered even if it has no value * during edit and update operations. * * @return bool True to indicate the field should appear in the edit template. * @task commit */ public function shouldAppearOnCommitMessageTemplate() { return true; } /** * Render a human-readable label for this field, like "Summary" or * "Test Plan". This is distinct from the commit message key, but generally * they should be similar. * * @return string Human-readable field label for commit messages. * @task commit */ public function renderLabelForCommitMessage() { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Render a human-readable value for this field when it appears in commit * messages (for instance, lists of users should be rendered as user names). * * The ##$is_edit## parameter allows you to distinguish between commit * messages being rendered for editing and those being rendered for amending * or commit. Some fields may decline to render a value in one mode (for * example, "Reviewed By" appears only when doing commit/amend, not while * editing). * * @param bool True if the message is being edited. * @return string Human-readable field value. * @task commit */ public function renderValueForCommitMessage($is_edit) { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * Return one or more labels which this field parses in commit messages. For * example, you might parse all of "Task", "Tasks" and "Task Numbers" or * similar. This is just to make it easier to get commit messages to parse * when users are typing in the fields manually as opposed to using a * template, by accepting alternate spellings / pluralizations / etc. By * default, only the label returned from @{method:renderLabelForCommitMessage} * is parsed. * * @return list List of supported labels that this field can parse from commit * messages. * @task commit */ public function getSupportedCommitMessageLabels() { return array($this->renderLabelForCommitMessage()); } /** * Parse a raw text block from a commit message into a canonical * representation of the field value. For example, the "CC" field accepts a * comma-delimited list of usernames and emails and parses them into valid * PHIDs, emitting a PHID list. * * If you encounter errors (like a nonexistent username) while parsing, * you should throw a @{class:DifferentialFieldParseException}. * * Generally, this method should accept whatever you return from * @{method:renderValueForCommitMessage} and parse it back into a sensible * representation. * * You must implement this method if you return true from * @{method:shouldAppearOnCommitMessage}. * * @param string * @return mixed The canonical representation of the field value. For example, * you should lookup usernames and object references. * @task commit */ public function parseValueFromCommitMessage($value) { throw new DifferentialFieldSpecificationIncompleteException($this); } /** * This method allows you to take action when a commit appears in a tracked * branch (for example, by closing tasks associated with the commit). * * @param PhabricatorRepository The repository the commit appeared in. * @param PhabricatorRepositoryCommit The commit itself. * @param PhabricatorRepostioryCommitData Commit data. * @return void * * @task commit */ public function didParseCommit( PhabricatorRepository $repo, PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data) { return; } /* -( Loading Additional Data )-------------------------------------------- */ /** * Specify which @{class:PhabricatorObjectHandle}s need to be loaded for your * field to render correctly. * * This is a convenience method which makes the handles available on all * interfaces where the field appears. If your field needs handles on only * some interfaces (or needs different handles on different interfaces) you * can overload the more specific methods to customize which interfaces you * retrieve handles for. Requesting only the handles you need will improve * the performance of your field. * * You can later retrieve these handles by calling @{method:getHandle}. * * @return list List of PHIDs to load handles for. * @task load */ protected function getRequiredHandlePHIDs() { return array(); } /** * Specify which @{class:PhabricatorObjectHandle}s need to be loaded for your * field to render correctly on the view interface. * * This is a more specific version of @{method:getRequiredHandlePHIDs} which * can be overridden to improve field performance by loading only data you * need. * * @return list List of PHIDs to load handles for. * @task load */ public function getRequiredHandlePHIDsForRevisionView() { return $this->getRequiredHandlePHIDs(); } /** * Specify which @{class:PhabricatorObjectHandle}s need to be loaded for your * field to render correctly on the list interface. * * This is a more specific version of @{method:getRequiredHandlePHIDs} which * can be overridden to improve field performance by loading only data you * need. * * @param DifferentialRevision The revision to pull PHIDs for. * @return list List of PHIDs to load handles for. * @task load */ public function getRequiredHandlePHIDsForRevisionList( DifferentialRevision $revision) { return array(); } /** * Specify which @{class:PhabricatorObjectHandle}s need to be loaded for your * field to render correctly on the edit interface. * * This is a more specific version of @{method:getRequiredHandlePHIDs} which * can be overridden to improve field performance by loading only data you * need. * * @return list List of PHIDs to load handles for. * @task load */ public function getRequiredHandlePHIDsForRevisionEdit() { return $this->getRequiredHandlePHIDs(); } /** * Specify which @{class:PhabricatorObjectHandle}s need to be loaded for your * field to render correctly on the commit message interface. * * This is a more specific version of @{method:getRequiredHandlePHIDs} which * can be overridden to improve field performance by loading only data you * need. * * @return list List of PHIDs to load handles for. * @task load */ public function getRequiredHandlePHIDsForCommitMessage() { return $this->getRequiredHandlePHIDs(); } /** * Parse a list of users into a canonical PHID list. * * @param string Raw list of comma-separated user names. * @return list List of corresponding PHIDs. * @task load */ protected function parseCommitMessageUserList($value) { return $this->parseCommitMessageObjectList($value, $mailables = false); } /** * Parse a list of mailable objects into a canonical PHID list. * * @param string Raw list of comma-separated mailable names. * @return list List of corresponding PHIDs. * @task load */ protected function parseCommitMessageMailableList($value) { return $this->parseCommitMessageObjectList($value, $mailables = true); } /** * Parse and lookup a list of object names, converting them to PHIDs. * * @param string Raw list of comma-separated object names. * @param bool True to include mailing lists. * @param bool True to make a best effort. By default, an exception is * thrown if any item is invalid. * @return list List of corresponding PHIDs. * @task load */ public static function parseCommitMessageObjectList( $value, $include_mailables, $allow_partial = false) { $value = array_unique(array_filter(preg_split('/[\s,]+/', $value))); if (!$value) { return array(); } $object_map = array(); $users = id(new PhabricatorUser())->loadAllWhere( '(username IN (%Ls))', $value); $user_map = mpull($users, 'getPHID', 'getUsername'); foreach ($user_map as $username => $phid) { // Usernames may have uppercase letters in them. Put both names in the // map so we can try the original case first, so that username *always* // works in weird edge cases where some other mailable object collides. $object_map[$username] = $phid; $object_map[strtolower($username)] = $phid; } if ($include_mailables) { $mailables = id(new PhabricatorMetaMTAMailingList())->loadAllWhere( '(email IN (%Ls)) OR (name IN (%Ls))', $value, $value); $object_map += mpull($mailables, 'getPHID', 'getName'); $object_map += mpull($mailables, 'getPHID', 'getEmail'); } $invalid = array(); $results = array(); foreach ($value as $name) { if (empty($object_map[$name])) { if (empty($object_map[strtolower($name)])) { $invalid[] = $name; } else { $results[] = $object_map[strtolower($name)]; } } else { $results[] = $object_map[$name]; } } if ($invalid && !$allow_partial) { $invalid = implode(', ', $invalid); $what = $include_mailables ? "users and mailing lists" : "users"; throw new DifferentialFieldParseException( "Commit message references nonexistent {$what}: {$invalid}."); } return array_unique($results); } /* -( Contextual Data )---------------------------------------------------- */ /** * @task context */ final public function setRevision(DifferentialRevision $revision) { $this->revision = $revision; $this->didSetRevision(); return $this; } /** * @task context */ protected function didSetRevision() { return; } /** * @task context */ final public function setDiff(DifferentialDiff $diff) { $this->diff = $diff; return $this; } /** * @task context */ final public function setManualDiff(DifferentialDiff $diff) { $this->manualDiff = $diff; return $this; } /** * @task context */ final public function setHandles(array $handles) { assert_instances_of($handles, 'PhabricatorObjectHandle'); $this->handles = $handles; return $this; } /** * @task context */ final public function setDiffProperties(array $diff_properties) { $this->diffProperties = $diff_properties; return $this; } /** * @task context */ final public function setUser(PhabricatorUser $user) { $this->user = $user; return $this; } /** * @task context */ final protected function getRevision() { if (empty($this->revision)) { throw new DifferentialFieldDataNotAvailableException($this); } return $this->revision; } /** * Determine if revision context is currently available. * * @task context */ final protected function hasRevision() { return (bool)$this->revision; } /** * @task context */ final protected function getDiff() { if (empty($this->diff)) { throw new DifferentialFieldDataNotAvailableException($this); } return $this->diff; } /** * @task context */ final protected function getManualDiff() { if (!$this->manualDiff) { return $this->getDiff(); } return $this->manualDiff; } /** * @task context */ final protected function getUser() { if (empty($this->user)) { throw new DifferentialFieldDataNotAvailableException($this); } return $this->user; } /** * Get the handle for an object PHID. You must overload * @{method:getRequiredHandlePHIDs} (or a more specific version thereof) * and include the PHID you want in the list for it to be available here. * * @return PhabricatorObjectHandle Handle to the object. * @task context */ final protected function getHandle($phid) { if ($this->handles === null) { throw new DifferentialFieldDataNotAvailableException($this); } if (empty($this->handles[$phid])) { $class = get_class($this); throw new Exception( "A differential field (of class '{$class}') is attempting to retrieve ". "a handle ('{$phid}') which it did not request. Return all handle ". "PHIDs you need from getRequiredHandlePHIDs()."); } return $this->handles[$phid]; } /** * Get the list of properties for a diff set by @{method:setManualDiff}. * * @return array Array of all Diff properties. * @task context */ final public function getDiffProperties() { if ($this->diffProperties === null) { // This will be set to some (possibly empty) array if we've loaded // properties, so null means diff properties aren't available in this // context. throw new DifferentialFieldDataNotAvailableException($this); } return $this->diffProperties; } /** * Get a property of a diff set by @{method:setManualDiff}. * * @param string Diff property key. * @return mixed|null Diff property, or null if the property does not have * a value. * @task context */ final public function getDiffProperty($key) { return idx($this->getDiffProperties(), $key); } } diff --git a/src/applications/differential/field/specification/DifferentialHostFieldSpecification.php b/src/applications/differential/field/specification/DifferentialHostFieldSpecification.php index 1f9ed6b700..b1f1a9c099 100644 --- a/src/applications/differential/field/specification/DifferentialHostFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialHostFieldSpecification.php @@ -1,23 +1,23 @@ getManualDiff(); $host = $diff->getSourceMachine(); if (!$host) { return null; } - return phutil_escape_html($host); + return $host; } } diff --git a/src/applications/differential/field/specification/DifferentialLinesFieldSpecification.php b/src/applications/differential/field/specification/DifferentialLinesFieldSpecification.php index 01ac9ec1f7..31a7b7bac3 100644 --- a/src/applications/differential/field/specification/DifferentialLinesFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialLinesFieldSpecification.php @@ -1,35 +1,35 @@ getDiff(); - return phutil_escape_html(number_format($diff->getLineCount())); + return number_format($diff->getLineCount()); } public function shouldAppearOnRevisionList() { return true; } public function renderHeaderForRevisionList() { return 'Lines'; } public function getColumnClassForRevisionList() { return 'n'; } public function renderValueForRevisionList(DifferentialRevision $revision) { return number_format($revision->getLineCount()); } } diff --git a/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php b/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php index d628897632..44890675bd 100644 --- a/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php @@ -1,175 +1,175 @@ getManiphestTaskPHIDs(); } public function renderLabelForRevisionView() { return 'Maniphest Tasks:'; } public function renderValueForRevisionView() { $task_phids = $this->getManiphestTaskPHIDs(); if (!$task_phids) { return null; } $links = array(); foreach ($task_phids as $task_phid) { $links[] = $this->getHandle($task_phid)->renderLink(); } - return implode('
', $links); + return phutil_safe_html(implode('
', $links)); } private function getManiphestTaskPHIDs() { $revision = $this->getRevision(); if (!$revision->getPHID()) { return array(); } return PhabricatorEdgeQuery::loadDestinationPHIDs( $revision->getPHID(), PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK); } /** * Attach the revision to the task(s) and the task(s) to the revision. * * @return void */ public function didWriteRevision(DifferentialRevisionEditor $editor) { $revision = $editor->getRevision(); $revision_phid = $revision->getPHID(); $edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK; $old_phids = $this->oldManiphestTasks; $add_phids = $this->maniphestTasks; $rem_phids = array_diff($old_phids, $add_phids); $edge_editor = id(new PhabricatorEdgeEditor()) ->setActor($this->getUser()); foreach ($add_phids as $phid) { $edge_editor->addEdge($revision_phid, $edge_type, $phid); } foreach ($rem_phids as $phid) { $edge_editor->removeEdge($revision_phid, $edge_type, $phid); } $edge_editor->save(); } protected function didSetRevision() { $this->maniphestTasks = $this->getManiphestTaskPHIDs(); $this->oldManiphestTasks = $this->maniphestTasks; } public function getRequiredHandlePHIDsForCommitMessage() { return $this->maniphestTasks; } public function shouldAppearOnCommitMessageTemplate() { return PhabricatorEnv::getEnvConfig('maniphest.enabled'); } public function shouldAppearOnCommitMessage() { return PhabricatorEnv::getEnvConfig('maniphest.enabled'); } public function getCommitMessageKey() { return 'maniphestTaskPHIDs'; } public function setValueFromParsedCommitMessage($value) { $this->maniphestTasks = nonempty($value, array()); return $this; } public function renderLabelForCommitMessage() { return 'Maniphest Tasks'; } public function getSupportedCommitMessageLabels() { return array( 'Maniphest Task', 'Maniphest Tasks', ); } public function renderValueForCommitMessage($is_edit) { if (!$this->maniphestTasks) { return null; } $names = array(); foreach ($this->maniphestTasks as $phid) { $handle = $this->getHandle($phid); $names[] = 'T'.$handle->getAlternateID(); } return implode(', ', $names); } public function parseValueFromCommitMessage($value) { $matches = null; preg_match_all('/T(\d+)/', $value, $matches); if (empty($matches[0])) { return array(); } $task_ids = $matches[1]; $tasks = id(new ManiphestTask()) ->loadAllWhere('id in (%Ld)', $task_ids); $task_phids = array(); $invalid = array(); foreach ($task_ids as $task_id) { $task = idx($tasks, $task_id); if (empty($task)) { $invalid[] = 'T'.$task_id; } else { $task_phids[] = $task->getPHID(); } } if ($invalid) { $what = pht('Maniphest Task(s)', count($invalid)); $invalid = implode(', ', $invalid); throw new DifferentialFieldParseException( "Commit message references nonexistent {$what}: {$invalid}."); } return $task_phids; } public function renderValueForMail($phase) { if ($phase == DifferentialMailPhase::COMMENT) { return null; } if (!$this->maniphestTasks) { return null; } $handles = id(new PhabricatorObjectHandleData($this->maniphestTasks)) ->loadHandles(); $body = array(); $body[] = 'MANIPHEST TASKS'; foreach ($handles as $handle) { $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); } return implode("\n", $body); } } diff --git a/src/applications/differential/field/specification/DifferentialPathFieldSpecification.php b/src/applications/differential/field/specification/DifferentialPathFieldSpecification.php index 7a85823833..376d080add 100644 --- a/src/applications/differential/field/specification/DifferentialPathFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialPathFieldSpecification.php @@ -1,25 +1,25 @@ getManualDiff(); $path = $diff->getSourcePath(); if (!$path) { return null; } - return phutil_escape_html($path); + return $path; } } diff --git a/src/applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php b/src/applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php index f23b39c875..c3560c08a3 100644 --- a/src/applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php @@ -1,110 +1,110 @@ value; } public function setValueFromStorage($value) { $this->value = $value; return $this; } public function shouldAppearOnEdit() { return true; } public function setValueFromRequest(AphrontRequest $request) { $this->value = $request->getStr($this->getStorageKey()); return $this; } public function renderEditControl() { return id(new AphrontFormTextAreaControl()) ->setLabel('Revert Plan') ->setName($this->getStorageKey()) ->setCaption('Special steps required to safely revert this change.') ->setValue($this->value); } public function shouldAppearOnRevisionView() { return true; } public function renderLabelForRevisionView() { return 'Revert Plan:'; } public function renderValueForRevisionView() { if (!$this->value) { return null; } - return phutil_escape_html($this->value); + return $this->value; } public function shouldAppearOnConduitView() { return true; } public function getValueForConduit() { return $this->value; } public function shouldAppearOnCommitMessage() { return true; } public function getCommitMessageKey() { return 'revertPlan'; } public function setValueFromParsedCommitMessage($value) { $this->value = $value; return $this; } public function shouldOverwriteWhenCommitMessageIsEdited() { return true; } public function renderLabelForCommitMessage() { return 'Revert Plan'; } public function renderValueForCommitMessage($is_edit) { return $this->value; } public function getSupportedCommitMessageLabels() { return array( 'Revert Plan', 'Revert', ); } public function parseValueFromCommitMessage($value) { return $value; } public function shouldAddToSearchIndex() { return true; } public function getValueForSearchIndex() { return $this->value; } public function getKeyForSearchIndex() { return 'rpln'; } } diff --git a/src/applications/differential/view/DifferentialResultsTableView.php b/src/applications/differential/view/DifferentialResultsTableView.php index 519c9319f1..f2be210728 100644 --- a/src/applications/differential/view/DifferentialResultsTableView.php +++ b/src/applications/differential/view/DifferentialResultsTableView.php @@ -1,115 +1,115 @@ rows = $rows; return $this; } public function setShowMoreString($show_more_string) { $this->showMoreString = $show_more_string; return $this; } public function render() { $rows = array(); $any_hidden = false; foreach ($this->rows as $row) { $style = idx($row, 'style'); switch ($style) { case 'section': $cells = phutil_tag( 'th', array( 'colspan' => 2, ), idx($row, 'name')); break; default: $name = phutil_tag( 'th', array( ), idx($row, 'name')); $value = phutil_tag( 'td', array( ), idx($row, 'value')); $cells = array($name, $value); break; } $show = idx($row, 'show'); $rows[] = javelin_tag( 'tr', array( 'style' => $show ? null : 'display: none', 'sigil' => $show ? null : 'differential-results-row-toggle', 'class' => 'differential-results-row-'.$style, ), $cells); if (!$show) { $any_hidden = true; } } if ($any_hidden) { $show_more = javelin_tag( 'a', array( 'href' => '#', 'mustcapture' => true, ), $this->showMoreString); $hide_more = javelin_tag( 'a', array( 'href' => '#', 'mustcapture' => true, ), 'Hide'); $rows[] = javelin_tag( 'tr', array( 'class' => 'differential-results-row-show', 'sigil' => 'differential-results-row-show', ), phutil_tag('th', array('colspan' => 2), $show_more)); $rows[] = javelin_tag( 'tr', array( 'class' => 'differential-results-row-show', 'sigil' => 'differential-results-row-hide', 'style' => 'display: none', ), phutil_tag('th', array('colspan' => 2), $hide_more)); Javelin::initBehavior('differential-show-field-details'); } require_celerity_resource('differential-results-table-css'); - return javelin_render_tag( + return javelin_tag( 'table', array( 'class' => 'differential-results-table', 'sigil' => 'differential-results-table', ), - implode("\n", $rows)); + $rows); } } diff --git a/src/applications/differential/view/DifferentialRevisionDetailView.php b/src/applications/differential/view/DifferentialRevisionDetailView.php index 8e366f560c..1182012952 100644 --- a/src/applications/differential/view/DifferentialRevisionDetailView.php +++ b/src/applications/differential/view/DifferentialRevisionDetailView.php @@ -1,112 +1,112 @@ diff = $diff; return $this; } private function getDiff() { return $this->diff; } public function setRevision(DifferentialRevision $revision) { $this->revision = $revision; return $this; } public function setActions(array $actions) { $this->actions = $actions; return $this; } private function getActions() { return $this->actions; } public function setAuxiliaryFields(array $fields) { assert_instances_of($fields, 'DifferentialFieldSpecification'); $this->auxiliaryFields = $fields; return $this; } public function render() { require_celerity_resource('differential-core-view-css'); $revision = $this->revision; $user = $this->getUser(); $header = $this->renderHeader($revision); $actions = id(new PhabricatorActionListView()) ->setUser($user) ->setObject($revision); foreach ($this->getActions() as $action) { $obj = id(new PhabricatorActionView()) ->setIcon(idx($action, 'icon', 'edit')) ->setName($action['name']) ->setHref(idx($action, 'href')) ->setWorkflow(idx($action, 'sigil') == 'workflow') ->setUser($user) ->setDisabled(idx($action, 'disabled', false)); $actions->addAction($obj); } $properties = new PhabricatorPropertyListView(); $status = $revision->getStatus(); $local_vcs = $this->getDiff()->getSourceControlSystem(); $next_step = null; if ($status == ArcanistDifferentialRevisionStatus::ACCEPTED) { switch ($local_vcs) { case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: - $next_step = 'arc land'; + $next_step = phutil_tag('tt', array(), 'arc land'); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: - $next_step = 'arc commit'; + $next_step = phutil_tag('tt', array(), 'arc commit'); break; } } if ($next_step) { $properties->addProperty(pht('Next Step'), $next_step); } foreach ($this->auxiliaryFields as $field) { $value = $field->renderValueForRevisionView(); if (strlen($value)) { $label = rtrim($field->renderLabelForRevisionView(), ':'); $properties->addProperty($label, $value); } } $properties->setHasKeyboardShortcuts(true); return $header->render() . $actions->render() . $properties->render(); } private function renderHeader(DifferentialRevision $revision) { $view = id(new PhabricatorHeaderView()) ->setObjectName('D'.$revision->getID()) ->setHeader($revision->getTitle()); $status = $revision->getStatus(); $status_name = ArcanistDifferentialRevisionStatus::getNameForRevisionStatus($status); $status_color = DifferentialRevisionStatus::getRevisionStatusTagColor($status); $view->addTag( id(new PhabricatorTagView()) ->setType(PhabricatorTagView::TYPE_STATE) ->setName($status_name) ->setBackgroundColor($status_color) ); return $view; } } diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php index 624dbdb9ac..534ddd7e8c 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php @@ -1,945 +1,945 @@ getRequest(); $drequest = $this->getDiffusionRequest(); $before = $request->getStr('before'); if ($before) { return $this->buildBeforeResponse($before); } $path = $drequest->getPath(); $selected = $request->getStr('view'); $preferences = $request->getUser()->loadPreferences(); if (!$selected) { $selected = $preferences->getPreference( PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, 'highlighted'); } else if ($request->isFormPost() && $selected != 'raw') { $preferences->setPreference( PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, $selected); $preferences->save(); return id(new AphrontRedirectResponse()) ->setURI($request->getRequestURI()->alter('view', $selected)); } $needs_blame = ($selected == 'blame' || $selected == 'plainblame'); $file_query = DiffusionFileContentQuery::newFromDiffusionRequest( $this->diffusionRequest); $file_query->setViewer($request->getUser()); $file_query->setNeedsBlame($needs_blame); $file_query->loadFileContent(); $data = $file_query->getRawData(); if ($selected === 'raw') { return $this->buildRawResponse($path, $data); } $this->loadLintMessages(); // Build the content of the file. $corpus = $this->buildCorpus( $selected, $file_query, $needs_blame, $drequest, $path, $data); require_celerity_resource('diffusion-source-css'); if ($this->corpusType == 'text') { $view_select_panel = $this->renderViewSelectPanel($selected); } else { $view_select_panel = null; } // Render the page. $content = array(); $follow = $request->getStr('follow'); if ($follow) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_WARNING); $notice->setTitle('Unable to Continue'); switch ($follow) { case 'first': $notice->appendChild( "Unable to continue tracing the history of this file because ". "this commit is the first commit in the repository."); break; case 'created': $notice->appendChild( "Unable to continue tracing the history of this file because ". "this commit created the file."); break; } $content[] = $notice; } $renamed = $request->getStr('renamed'); if ($renamed) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('File Renamed'); $notice->appendChild( "File history passes through a rename from '". phutil_escape_html($drequest->getPath())."' to '". phutil_escape_html($renamed)."'."); $content[] = $notice; } $content[] = $view_select_panel; $content[] = $corpus; $content[] = $this->buildOpenRevisions(); $nav = $this->buildSideNav('browse', true); $nav->appendChild($content); $crumbs = $this->buildCrumbs( array( 'branch' => true, 'path' => true, 'view' => 'browse', )); $nav->setCrumbs($crumbs); $basename = basename($this->getDiffusionRequest()->getPath()); return $this->buildApplicationPage( $nav, array( 'title' => $basename, )); } private function loadLintMessages() { $drequest = $this->getDiffusionRequest(); $branch = $drequest->loadBranch(); if (!$branch || !$branch->getLintCommit()) { return; } $this->lintCommit = $branch->getLintCommit(); $conn = id(new PhabricatorRepository())->establishConnection('r'); $where = ''; if ($drequest->getLint()) { $where = qsprintf( $conn, 'AND code = %s', $drequest->getLint()); } $this->lintMessages = queryfx_all( $conn, 'SELECT * FROM %T WHERE branchID = %d %Q AND path = %s', PhabricatorRepository::TABLE_LINTMESSAGE, $branch->getID(), $where, '/'.$drequest->getPath()); } private function buildCorpus($selected, DiffusionFileContentQuery $file_query, $needs_blame, DiffusionRequest $drequest, $path, $data) { if (ArcanistDiffUtils::isHeuristicBinaryFile($data)) { $file = $this->loadFileForData($path, $data); $file_uri = $file->getBestURI(); if ($file->isViewableImage()) { $this->corpusType = 'image'; return $this->buildImageCorpus($file_uri); } else { $this->corpusType = 'binary'; return $this->buildBinaryCorpus($file_uri, $data); } } switch ($selected) { case 'plain': $style = "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; $corpus = phutil_tag( 'textarea', array( 'style' => $style, ), $file_query->getRawData()); break; case 'plainblame': $style = "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); $rows = array(); foreach ($text_list as $k => $line) { $rev = $rev_list[$k]; if (isset($blame_dict[$rev]['handle'])) { $author = $blame_dict[$rev]['handle']->getName(); } else { $author = $blame_dict[$rev]['author']; } $rows[] = sprintf("%-10s %-20s %s", substr($rev, 0, 7), $author, $line); } $corpus = phutil_tag( 'textarea', array( 'style' => $style, ), implode("\n", $rows)); break; case 'highlighted': case 'blame': default: require_celerity_resource('syntax-highlighting-css'); list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); $text_list = implode("\n", $text_list); $text_list = PhabricatorSyntaxHighlighter::highlightWithFilename( $path, $text_list); $text_list = explode("\n", $text_list); $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, $needs_blame, $drequest, $file_query, $selected); $id = celerity_generate_unique_node_id(); $projects = $drequest->loadArcanistProjects(); $langs = array(); foreach ($projects as $project) { $ls = $project->getSymbolIndexLanguages(); if (!$ls) { continue; } $dep_projects = $project->getSymbolIndexProjects(); $dep_projects[] = $project->getPHID(); foreach ($ls as $lang) { if (!isset($langs[$lang])) { $langs[$lang] = array(); } $langs[$lang] += $dep_projects + array($project); } } $lang = last(explode('.', $drequest->getPath())); $prefs = $this->getRequest()->getUser()->loadPreferences(); $pref_symbols = $prefs->getPreference( PhabricatorUserPreferences::PREFERENCE_DIFFUSION_SYMBOLS); if (isset($langs[$lang]) && $pref_symbols != 'disabled') { Javelin::initBehavior( 'repository-crossreference', array( 'container' => $id, 'lang' => $lang, 'projects' => $langs[$lang], )); } $corpus_table = javelin_render_tag( 'table', array( 'class' => "diffusion-source remarkup-code PhabricatorMonospaced", 'sigil' => 'diffusion-source', ), implode("\n", $rows)); $corpus = phutil_tag( 'div', array( 'style' => 'padding: 0 2em;', 'id' => $id, ), $corpus_table); break; } return $corpus; } private function renderViewSelectPanel($selected) { $toggle_blame = array( 'highlighted' => 'blame', 'blame' => 'highlighted', 'plain' => 'plainblame', 'plainblame' => 'plain', 'raw' => 'raw', // not a real case. ); $toggle_highlight = array( 'highlighted' => 'plain', 'blame' => 'plainblame', 'plain' => 'highlighted', 'plainblame' => 'blame', 'raw' => 'raw', // not a real case. ); $user = $this->getRequest()->getUser(); $base_uri = $this->getRequest()->getRequestURI(); $blame_on = ($selected == 'blame' || $selected == 'plainblame'); if ($blame_on) { $blame_text = pht('Disable Blame'); } else { $blame_text = pht('Enable Blame'); } $blame_button = $this->createViewAction( $blame_text, $base_uri->alter('view', $toggle_blame[$selected]), $user); $highlight_on = ($selected == 'blame' || $selected == 'highlighted'); if ($highlight_on) { $highlight_text = pht('Disable Highlighting'); } else { $highlight_text = pht('Enable Highlighting'); } $highlight_button = $this->createViewAction( $highlight_text, $base_uri->alter('view', $toggle_highlight[$selected]), $user); $href = null; if ($this->getRequest()->getStr('lint') !== null) { $lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages)); $href = $base_uri->alter('lint', null); } else if ($this->lintCommit === null) { $lint_text = pht('Lint not Available'); } else { $lint_text = pht( 'Show %d Lint Message(s)', count($this->lintMessages)); $href = $this->getDiffusionRequest()->generateURI(array( 'action' => 'browse', 'commit' => $this->lintCommit, ))->alter('lint', ''); } $lint_button = $this->createViewAction( $lint_text, $href, $user); if (!$href) { $lint_button->setDisabled(true); } $raw_button = $this->createViewAction( pht('View Raw File'), $base_uri->alter('view', 'raw'), $user, 'file'); $edit_button = $this->createEditAction(); return id(new PhabricatorActionListView()) ->setUser($user) ->addAction($blame_button) ->addAction($highlight_button) ->addAction($lint_button) ->addAction($raw_button) ->addAction($edit_button); } private function createViewAction( $localized_text, $href, $user, $icon = null) { return id(new PhabricatorActionView()) ->setName($localized_text) ->setIcon($icon) ->setUser($user) ->setRenderAsForm(true) ->setHref($href); } private function createEditAction() { $request = $this->getRequest(); $user = $request->getUser(); $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); $path = $drequest->getPath(); $line = nonempty((int)$drequest->getLine(), 1); $callsign = $repository->getCallsign(); $editor_link = $user->loadEditorLink($path, $line, $callsign); $action = id(new PhabricatorActionView()) ->setName(pht('Open in Editor')) ->setIcon('edit'); $action->setHref($editor_link); $action->setDisabled(!$editor_link); return $action; } private function buildDisplayRows( array $text_list, array $rev_list, array $blame_dict, $needs_blame, DiffusionRequest $drequest, DiffusionFileContentQuery $file_query, $selected) { if ($blame_dict) { $epoch_list = ipull(ifilter($blame_dict, 'epoch'), 'epoch'); $epoch_min = min($epoch_list); $epoch_max = max($epoch_list); $epoch_range = ($epoch_max - $epoch_min) + 1; } $line_arr = array(); $line_str = $drequest->getLine(); $ranges = explode(',', $line_str); foreach ($ranges as $range) { if (strpos($range, '-') !== false) { list($min, $max) = explode('-', $range, 2); $line_arr[] = array( 'min' => min($min, $max), 'max' => max($min, $max), ); } else if (strlen($range)) { $line_arr[] = array( 'min' => $range, 'max' => $range, ); } } $display = array(); $line_number = 1; $last_rev = null; $color = null; foreach ($text_list as $k => $line) { $display_line = array( 'color' => null, 'epoch' => null, 'commit' => null, 'author' => null, 'target' => null, 'highlighted' => null, 'line' => $line_number, 'data' => $line, ); if ($needs_blame) { // If the line's rev is same as the line above, show empty content // with same color; otherwise generate blame info. The newer a change // is, the more saturated the color. $rev = idx($rev_list, $k, $last_rev); if ($last_rev == $rev) { $display_line['color'] = $color; } else { $blame = $blame_dict[$rev]; if (!isset($blame['epoch'])) { $color = '#ffd'; // Render as warning. } else { $color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range; $color_value = 0xF6 * (1.0 - $color_ratio); $color = sprintf( '#%02x%02x%02x', $color_value, 0xF6, $color_value); } $display_line['epoch'] = idx($blame, 'epoch'); $display_line['color'] = $color; $display_line['commit'] = $rev; if (isset($blame['handle'])) { $author_link = $blame['handle']->renderLink(); } else { $author_link = phutil_tag( 'span', array( ), $blame['author']); } $display_line['author'] = $author_link; $last_rev = $rev; } } if ($line_arr) { if ($line_number == $line_arr[0]['min']) { $display_line['target'] = true; } foreach ($line_arr as $range) { if ($line_number >= $range['min'] && $line_number <= $range['max']) { $display_line['highlighted'] = true; } } } $display[] = $display_line; ++$line_number; } $commits = array_filter(ipull($display, 'commit')); if ($commits) { $commits = id(new PhabricatorAuditCommitQuery()) ->withIdentifiers($drequest->getRepository()->getID(), $commits) ->needCommitData(true) ->execute(); $commits = mpull($commits, null, 'getCommitIdentifier'); } $revision_ids = id(new DifferentialRevision()) ->loadIDsByCommitPHIDs(mpull($commits, 'getPHID')); $revisions = array(); if ($revision_ids) { $revisions = id(new DifferentialRevision())->loadAllWhere( 'id IN (%Ld)', $revision_ids); } $request = $this->getRequest(); $user = $request->getUser(); Javelin::initBehavior('phabricator-oncopy', array()); $engine = null; $inlines = array(); if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) { $engine = new PhabricatorMarkupEngine(); $engine->setViewer($user); foreach ($this->lintMessages as $message) { $inline = id(new PhabricatorAuditInlineComment()) ->setID($message['id']) ->setSyntheticAuthor( ArcanistLintSeverity::getStringForSeverity($message['severity']). ' '.$message['code'].' ('.$message['name'].')') ->setLineNumber($message['line']) ->setContent($message['description']); $inlines[$message['line']][] = $inline; $engine->addObject( $inline, PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); } $engine->process(); require_celerity_resource('differential-changeset-view-css'); } $rows = $this->renderInlines( idx($inlines, 0, array()), $needs_blame, $engine); foreach ($display as $line) { $line_href = $drequest->generateURI( array( 'action' => 'browse', 'line' => $line['line'], 'stable' => true, )); $blame = array(); if ($line['color']) { $color = $line['color']; $before_link = null; $commit_link = null; $revision_link = null; if (idx($line, 'commit')) { $commit = $line['commit']; $summary = 'Unknown'; if (idx($commits, $commit)) { $summary = $commits[$commit]->getCommitData()->getSummary(); } $tooltip = phabricator_date( $line['epoch'], $user)." \xC2\xB7 ".$summary; Javelin::initBehavior('phabricator-tooltips', array()); require_celerity_resource('aphront-tooltip-css'); $commit_link = javelin_tag( 'a', array( 'href' => $drequest->generateURI( array( 'action' => 'commit', 'commit' => $line['commit'], )), 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $tooltip, 'align' => 'E', 'size' => 600, ), ), phutil_utf8_shorten($line['commit'], 9, '')); $revision_id = null; if (idx($commits, $commit)) { $revision_id = idx($revision_ids, $commits[$commit]->getPHID()); } if ($revision_id) { $revision = idx($revisions, $revision_id); if (!$revision) { $tooltip = '(Invalid revision)'; } else { $tooltip = phabricator_date($revision->getDateModified(), $user). " \xC2\xB7 ". $revision->getTitle(); } $revision_link = javelin_tag( 'a', array( 'href' => '/D'.$revision_id, 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => $tooltip, 'align' => 'E', 'size' => 600, ), ), 'D'.$revision_id); } $uri = $line_href->alter('before', $commit); $before_link = javelin_tag( 'a', array( 'href' => $uri->setQueryParam('view', 'blame'), 'sigil' => 'has-tooltip', 'meta' => array( 'tip' => 'Skip Past This Commit', 'align' => 'E', 'size' => 300, ), ), "\xC2\xAB"); } $blame[] = phutil_tag( 'th', array( 'class' => 'diffusion-blame-link', 'style' => 'background: '.$color, ), $before_link); $blame[] = phutil_tag( 'th', array( 'class' => 'diffusion-rev-link', 'style' => 'background: '.$color, ), $commit_link); $blame[] = phutil_tag( 'th', array( 'class' => 'diffusion-rev-link', 'style' => 'background: '.$color, ), $revision_link); $blame[] = phutil_tag( 'th', array( 'class' => 'diffusion-author-link', 'style' => 'background: '.$color, ), idx($line, 'author')); } $line_link = phutil_tag( 'a', array( 'href' => $line_href, ), $line['line']); $blame[] = javelin_tag( 'th', array( 'class' => 'diffusion-line-link', 'sigil' => 'diffusion-line-link', 'style' => isset($color) ? 'background: '.$color : null, ), $line_link); Javelin::initBehavior('diffusion-line-linker'); if ($line['target']) { Javelin::initBehavior( 'diffusion-jump-to', array( 'target' => 'scroll_target', )); $anchor_text = ''; } else { $anchor_text = null; } $blame[] = phutil_render_tag( 'td', array( ), $anchor_text. "\xE2\x80\x8B". // NOTE: See phabricator-oncopy behavior. $line['data']); $rows[] = phutil_tag( 'tr', array( 'class' => ($line['highlighted'] ? 'highlighted' : null), ), $blame); $rows = array_merge($rows, $this->renderInlines( idx($inlines, $line['line'], array()), $needs_blame, $engine)); } return $rows; } private function renderInlines(array $inlines, $needs_blame, $engine) { $rows = array(); foreach ($inlines as $inline) { $inline_view = id(new DifferentialInlineCommentView()) ->setMarkupEngine($engine) ->setInlineComment($inline) ->render(); $rows[] = ''. str_repeat('', ($needs_blame ? 5 : 1)). ''.$inline_view.''. ''; } return $rows; } private function loadFileForData($path, $data) { return PhabricatorFile::buildFromFileDataOrHash( $data, array( 'name' => basename($path), )); } private function buildRawResponse($path, $data) { $file = $this->loadFileForData($path, $data); return id(new AphrontRedirectResponse())->setURI($file->getBestURI()); } private function buildImageCorpus($file_uri) { $properties = new PhabricatorPropertyListView(); $properties->addProperty( pht('Image'), phutil_tag( 'img', array( 'src' => $file_uri, ))); $actions = id(new PhabricatorActionListView()) ->setUser($this->getRequest()->getUser()) ->addAction($this->createEditAction()); return array($actions, $properties); } private function buildBinaryCorpus($file_uri, $data) { $properties = new PhabricatorPropertyListView(); $size = strlen($data); $properties->addTextContent( pht('This is a binary file. It is %2$s byte(s) in length.', - $size, - PhutilTranslator::getInstance()->formatNumber($size)) - ); + $size, + PhutilTranslator::getInstance()->formatNumber($size))); $actions = id(new PhabricatorActionListView()) ->setUser($this->getRequest()->getUser()) ->addAction($this->createEditAction()) - ->addAction(id(new PhabricatorActionView()) - ->setName(pht('Download Binary File...')) - ->setIcon('download') - ->setHref($file_uri)); + ->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Download Binary File...')) + ->setIcon('download') + ->setHref($file_uri)); return array($actions, $properties); } private function buildBeforeResponse($before) { $request = $this->getRequest(); $drequest = $this->getDiffusionRequest(); // NOTE: We need to get the grandparent so we can capture filename changes // in the parent. $parent = $this->loadParentRevisionOf($before); $old_filename = null; $was_created = false; if ($parent) { $grandparent = $this->loadParentRevisionOf( $parent->getCommitIdentifier()); if ($grandparent) { $rename_query = new DiffusionRenameHistoryQuery(); $rename_query->setRequest($drequest); $rename_query->setOldCommit($grandparent->getCommitIdentifier()); $old_filename = $rename_query->loadOldFilename(); $was_created = $rename_query->getWasCreated(); } } $follow = null; if ($was_created) { // If the file was created in history, that means older commits won't // have it. Since we know it existed at 'before', it must have been // created then; jump there. $target_commit = $before; $follow = 'created'; } else if ($parent) { // If we found a parent, jump to it. This is the normal case. $target_commit = $parent->getCommitIdentifier(); } else { // If there's no parent, this was probably created in the initial commit? // And the "was_created" check will fail because we can't identify the // grandparent. Keep the user at 'before'. $target_commit = $before; $follow = 'first'; } $path = $drequest->getPath(); $renamed = null; if ($old_filename !== null && $old_filename !== '/'.$path) { $renamed = $path; $path = $old_filename; } $line = null; // If there's a follow error, drop the line so the user sees the message. if (!$follow) { $line = $this->getBeforeLineNumber($target_commit); } $before_uri = $drequest->generateURI( array( 'action' => 'browse', 'commit' => $target_commit, 'line' => $line, 'path' => $path, )); $before_uri->setQueryParams($request->getRequestURI()->getQueryParams()); $before_uri = $before_uri->alter('before', null); $before_uri = $before_uri->alter('renamed', $renamed); $before_uri = $before_uri->alter('follow', $follow); return id(new AphrontRedirectResponse())->setURI($before_uri); } private function getBeforeLineNumber($target_commit) { $drequest = $this->getDiffusionRequest(); $line = $drequest->getLine(); if (!$line) { return null; } $diff_query = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest); $diff_query->setAgainstCommit($target_commit); try { $raw_diff = $diff_query->loadRawDiff(); $old_line = 0; $new_line = 0; foreach (explode("\n", $raw_diff) as $text) { if ($text[0] == '-' || $text[0] == ' ') { $old_line++; } if ($text[0] == '+' || $text[0] == ' ') { $new_line++; } if ($new_line == $line) { return $old_line; } } // We didn't find the target line. return $line; } catch (Exception $ex) { return $line; } } private function loadParentRevisionOf($commit) { $drequest = $this->getDiffusionRequest(); $before_req = DiffusionRequest::newFromDictionary( array( 'repository' => $drequest->getRepository(), 'commit' => $commit, )); $query = DiffusionCommitParentsQuery::newFromDiffusionRequest($before_req); $parents = $query->loadParents(); return head($parents); } } diff --git a/src/applications/diffusion/controller/DiffusionCommitController.php b/src/applications/diffusion/controller/DiffusionCommitController.php index 235be74c25..7181c0b5da 100644 --- a/src/applications/diffusion/controller/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/DiffusionCommitController.php @@ -1,924 +1,926 @@ diffusionRequest = $drequest; } public function processRequest() { $drequest = $this->getDiffusionRequest(); $request = $this->getRequest(); $user = $request->getUser(); if ($request->getStr('diff')) { return $this->buildRawDiffResponse($drequest); } $callsign = $drequest->getRepository()->getCallsign(); $content = array(); $repository = $drequest->getRepository(); $commit = $drequest->loadCommit(); if (!$commit) { $query = DiffusionExistsQuery::newFromDiffusionRequest($drequest); $exists = $query->loadExistentialData(); if (!$exists) { return new Aphront404Response(); } return $this->buildStandardPageResponse( id(new AphrontErrorView()) ->setTitle('Error displaying commit.') ->appendChild('Failed to load the commit because the commit has not '. 'been parsed yet.'), array('title' => 'Commit Still Parsing') ); } $commit_data = $drequest->loadCommitData(); $commit->attachCommitData($commit_data); $top_anchor = id(new PhabricatorAnchorView()) ->setAnchorName('top') ->setNavigationMarker(true); $is_foreign = $commit_data->getCommitDetail('foreign-svn-stub'); $changesets = null; if ($is_foreign) { $subpath = $commit_data->getCommitDetail('svn-subpath'); $error_panel = new AphrontErrorView(); $error_panel->setTitle('Commit Not Tracked'); $error_panel->setSeverity(AphrontErrorView::SEVERITY_WARNING); $error_panel->appendChild( "This Diffusion repository is configured to track only one ". "subdirectory of the entire Subversion repository, and this commit ". "didn't affect the tracked subdirectory ('". phutil_escape_html($subpath)."'), so no information is available."); $content[] = $error_panel; $content[] = $top_anchor; } else { $engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine(); require_celerity_resource('diffusion-commit-view-css'); require_celerity_resource('phabricator-remarkup-css'); $parent_query = DiffusionCommitParentsQuery::newFromDiffusionRequest( $drequest); $headsup_view = id(new PhabricatorHeaderView()) ->setHeader('Commit Detail'); $headsup_actions = $this->renderHeadsupActionList($commit, $repository); $commit_properties = $this->loadCommitProperties( $commit, $commit_data, $parent_query->loadParents() ); $property_list = id(new PhabricatorPropertyListView()) ->setHasKeyboardShortcuts(true); foreach ($commit_properties as $key => $value) { $property_list->addProperty($key, $value); } $property_list->addTextContent( - '
'. + phutil_tag( + 'div', + array( + 'class' => 'diffusion-commit-message phabricator-remarkup', + ), phutil_safe_html( - $engine->markupText($commit_data->getCommitMessage())). - '
' - ); + $engine->markupText($commit_data->getCommitMessage())))); $content[] = $top_anchor; $content[] = $headsup_view; $content[] = $headsup_actions; $content[] = $property_list; } $query = new PhabricatorAuditQuery(); $query->withCommitPHIDs(array($commit->getPHID())); $audit_requests = $query->execute(); $this->auditAuthorityPHIDs = PhabricatorAuditCommentEditor::loadAuditPHIDsForUser($user); $content[] = $this->buildAuditTable($commit, $audit_requests); $content[] = $this->buildComments($commit); $change_query = DiffusionPathChangeQuery::newFromDiffusionRequest( $drequest); $changes = $change_query->loadChanges(); $content[] = $this->buildMergesTable($commit); $owners_paths = array(); if ($this->highlightedAudits) { $packages = id(new PhabricatorOwnersPackage())->loadAllWhere( 'phid IN (%Ls)', mpull($this->highlightedAudits, 'getAuditorPHID')); if ($packages) { $owners_paths = id(new PhabricatorOwnersPath())->loadAllWhere( 'repositoryPHID = %s AND packageID IN (%Ld)', $repository->getPHID(), mpull($packages, 'getID')); } } $change_table = new DiffusionCommitChangeTableView(); $change_table->setDiffusionRequest($drequest); $change_table->setPathChanges($changes); $change_table->setOwnersPaths($owners_paths); $count = count($changes); $bad_commit = null; if ($count == 0) { $bad_commit = queryfx_one( id(new PhabricatorRepository())->establishConnection('r'), 'SELECT * FROM %T WHERE fullCommitName = %s', PhabricatorRepository::TABLE_BADCOMMIT, 'r'.$callsign.$commit->getCommitIdentifier()); } $pane_id = null; if ($bad_commit) { $error_panel = new AphrontErrorView(); $error_panel->setTitle('Bad Commit'); $error_panel->appendChild( phutil_escape_html($bad_commit['description'])); $content[] = $error_panel; } else if ($is_foreign) { // Don't render anything else. } else if (!count($changes)) { $no_changes = new AphrontErrorView(); $no_changes->setSeverity(AphrontErrorView::SEVERITY_WARNING); $no_changes->setTitle('Not Yet Parsed'); // TODO: This can also happen with weird SVN changes that don't do // anything (or only alter properties?), although the real no-changes case // is extremely rare and might be impossible to produce organically. We // should probably write some kind of "Nothing Happened!" change into the // DB once we parse these changes so we can distinguish between // "not parsed yet" and "no changes". $no_changes->appendChild( "This commit hasn't been fully parsed yet (or doesn't affect any ". "paths)."); $content[] = $no_changes; } else { $change_panel = new AphrontPanelView(); $change_panel->setHeader("Changes (".number_format($count).")"); $change_panel->setID('toc'); if ($count > self::CHANGES_LIMIT) { $show_all_button = phutil_tag( 'a', array( 'class' => 'button green', 'href' => '?show_all=true', ), 'Show All Changes'); $warning_view = id(new AphrontErrorView()) ->setSeverity(AphrontErrorView::SEVERITY_WARNING) ->setTitle('Very Large Commit') ->appendChild( "

This commit is very large. Load each file individually.

"); $change_panel->appendChild($warning_view); $change_panel->addButton($show_all_button); } $change_panel->appendChild($change_table); $change_panel->setNoBackground(); $content[] = $change_panel; $changesets = DiffusionPathChange::convertToDifferentialChangesets( $changes); $vcs = $repository->getVersionControlSystem(); switch ($vcs) { case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: $vcs_supports_directory_changes = true; break; case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: $vcs_supports_directory_changes = false; break; default: throw new Exception("Unknown VCS."); } $references = array(); foreach ($changesets as $key => $changeset) { $file_type = $changeset->getFileType(); if ($file_type == DifferentialChangeType::FILE_DIRECTORY) { if (!$vcs_supports_directory_changes) { unset($changesets[$key]); continue; } } $references[$key] = $drequest->generateURI( array( 'action' => 'rendering-ref', 'path' => $changeset->getFilename(), )); } // TODO: Some parts of the views still rely on properties of the // DifferentialChangeset. Make the objects ephemeral to make sure we don't // accidentally save them, and then set their ID to the appropriate ID for // this application (the path IDs). $path_ids = array_flip(mpull($changes, 'getPath')); foreach ($changesets as $changeset) { $changeset->makeEphemeral(); $changeset->setID($path_ids[$changeset->getFilename()]); } if ($count <= self::CHANGES_LIMIT) { $visible_changesets = $changesets; } else { $visible_changesets = array(); $inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere( 'commitPHID = %s AND (auditCommentID IS NOT NULL OR authorPHID = %s)', $commit->getPHID(), $user->getPHID()); $path_ids = mpull($inlines, null, 'getPathID'); foreach ($changesets as $key => $changeset) { if (array_key_exists($changeset->getID(), $path_ids)) { $visible_changesets[$key] = $changeset; } } } $change_list_title = DiffusionView::nameCommit( $repository, $commit->getCommitIdentifier() ); $change_list = new DifferentialChangesetListView(); $change_list->setTitle($change_list_title); $change_list->setChangesets($changesets); $change_list->setVisibleChangesets($visible_changesets); $change_list->setRenderingReferences($references); $change_list->setRenderURI('/diffusion/'.$callsign.'/diff/'); $change_list->setRepository($repository); $change_list->setUser($user); // pick the first branch for "Browse in Diffusion" View Option $branches = $commit_data->getCommitDetail('seenOnBranches', array()); $first_branch = reset($branches); $change_list->setBranch($first_branch); $change_list->setStandaloneURI( '/diffusion/'.$callsign.'/diff/'); $change_list->setRawFileURIs( // TODO: Implement this, somewhat tricky if there's an octopus merge // or whatever? null, '/diffusion/'.$callsign.'/diff/?view=r'); $change_list->setInlineCommentControllerURI( '/diffusion/inline/edit/'.phutil_escape_uri($commit->getPHID()).'/'); $change_references = array(); foreach ($changesets as $key => $changeset) { $change_references[$changeset->getID()] = $references[$key]; } $change_table->setRenderingReferences($change_references); // TODO: This is pretty awkward, unify the CSS between Diffusion and // Differential better. require_celerity_resource('differential-core-view-css'); $pane_id = celerity_generate_unique_node_id(); $add_comment_view = $this->renderAddCommentPanel($commit, $audit_requests, $pane_id); $main_pane = phutil_render_tag( 'div', array( 'id' => $pane_id ), $change_list->render(). id(new PhabricatorAnchorView()) ->setAnchorName('comment') ->setNavigationMarker(true) ->render(). $add_comment_view); $content[] = $main_pane; } $commit_id = 'r'.$callsign.$commit->getCommitIdentifier(); $short_name = DiffusionView::nameCommit( $repository, $commit->getCommitIdentifier() ); $crumbs = $this->buildCrumbs(array( 'commit' => true, )); if ($changesets) { $nav = id(new DifferentialChangesetFileTreeSideNavBuilder()) ->setAnchorName('top') ->setTitle($short_name) ->setBaseURI(new PhutilURI('/'.$commit_id)) ->build($changesets) ->setCrumbs($crumbs) ->appendChild($content); $content = $nav; } else { $content = array($crumbs, $content); } return $this->buildApplicationPage( $content, array( 'title' => $commit_id ) ); } private function loadCommitProperties( PhabricatorRepositoryCommit $commit, PhabricatorRepositoryCommitData $data, array $parents) { assert_instances_of($parents, 'PhabricatorRepositoryCommit'); $user = $this->getRequest()->getUser(); $commit_phid = $commit->getPHID(); $edges = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs(array($commit_phid)) ->withEdgeTypes(array( PhabricatorEdgeConfig::TYPE_COMMIT_HAS_TASK, PhabricatorEdgeConfig::TYPE_COMMIT_HAS_PROJECT )) ->execute(); $task_phids = array_keys( $edges[$commit_phid][PhabricatorEdgeConfig::TYPE_COMMIT_HAS_TASK] ); $proj_phids = array_keys( $edges[$commit_phid][PhabricatorEdgeConfig::TYPE_COMMIT_HAS_PROJECT] ); $phids = array_merge($task_phids, $proj_phids); if ($data->getCommitDetail('authorPHID')) { $phids[] = $data->getCommitDetail('authorPHID'); } if ($data->getCommitDetail('reviewerPHID')) { $phids[] = $data->getCommitDetail('reviewerPHID'); } if ($data->getCommitDetail('committerPHID')) { $phids[] = $data->getCommitDetail('committerPHID'); } if ($data->getCommitDetail('differential.revisionPHID')) { $phids[] = $data->getCommitDetail('differential.revisionPHID'); } if ($parents) { foreach ($parents as $parent) { $phids[] = $parent->getPHID(); } } $handles = array(); if ($phids) { $handles = $this->loadViewerHandles($phids); } $props = array(); if ($commit->getAuditStatus()) { $status = PhabricatorAuditCommitStatusConstants::getStatusName( $commit->getAuditStatus()); $props['Status'] = phutil_tag( 'strong', array(), $status); } $props['Committed'] = phabricator_datetime($commit->getEpoch(), $user); $author_phid = $data->getCommitDetail('authorPHID'); if ($data->getCommitDetail('authorPHID')) { $props['Author'] = $handles[$author_phid]->renderLink(); } else { - $props['Author'] = phutil_escape_html($data->getAuthorName()); + $props['Author'] = $data->getAuthorName(); } $reviewer_phid = $data->getCommitDetail('reviewerPHID'); if ($reviewer_phid) { $props['Reviewer'] = $handles[$reviewer_phid]->renderLink(); } $committer = $data->getCommitDetail('committer'); if ($committer) { $committer_phid = $data->getCommitDetail('committerPHID'); if ($data->getCommitDetail('committerPHID')) { $props['Committer'] = $handles[$committer_phid]->renderLink(); } else { - $props['Committer'] = phutil_escape_html($committer); + $props['Committer'] = $committer; } } $revision_phid = $data->getCommitDetail('differential.revisionPHID'); if ($revision_phid) { $props['Differential Revision'] = $handles[$revision_phid]->renderLink(); } if ($parents) { $parent_links = array(); foreach ($parents as $parent) { $parent_links[] = $handles[$parent->getPHID()]->renderLink(); } $props['Parents'] = implode(' · ', $parent_links); } $request = $this->getDiffusionRequest(); $props['Branches'] = 'Unknown'; $props['Tags'] = 'Unknown'; $callsign = $request->getRepository()->getCallsign(); $root = '/diffusion/'.$callsign.'/commit/'.$commit->getCommitIdentifier(); Javelin::initBehavior( 'diffusion-commit-branches', array( $root.'/branches/' => 'commit-branches', $root.'/tags/' => 'commit-tags', )); $refs = $this->buildRefs($request); if ($refs) { $props['References'] = $refs; } if ($task_phids) { $task_list = array(); foreach ($task_phids as $phid) { $task_list[] = $handles[$phid]->renderLink(); } - $task_list = implode('
', $task_list); + $task_list = array_interleave(phutil_tag('br'), $task_list); $props['Tasks'] = $task_list; } if ($proj_phids) { $proj_list = array(); foreach ($proj_phids as $phid) { $proj_list[] = $handles[$phid]->renderLink(); } - $proj_list = implode('
', $proj_list); + $proj_list = array_interleave(phutil_tag('br'), $proj_list); $props['Projects'] = $proj_list; } return $props; } private function buildAuditTable( PhabricatorRepositoryCommit $commit, array $audits) { assert_instances_of($audits, 'PhabricatorRepositoryAuditRequest'); $user = $this->getRequest()->getUser(); $view = new PhabricatorAuditListView(); $view->setAudits($audits); $view->setCommits(array($commit)); $view->setUser($user); $view->setShowDescriptions(false); $phids = $view->getRequiredHandlePHIDs(); $handles = $this->loadViewerHandles($phids); $view->setHandles($handles); $view->setAuthorityPHIDs($this->auditAuthorityPHIDs); $this->highlightedAudits = $view->getHighlightedAudits(); $panel = new AphrontPanelView(); $panel->setHeader('Audits'); $panel->setCaption('Audits you are responsible for are highlighted.'); $panel->appendChild($view); $panel->setNoBackground(); return $panel; } private function buildComments(PhabricatorRepositoryCommit $commit) { $user = $this->getRequest()->getUser(); $comments = id(new PhabricatorAuditComment())->loadAllWhere( 'targetPHID = %s ORDER BY dateCreated ASC', $commit->getPHID()); $inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere( 'commitPHID = %s AND auditCommentID IS NOT NULL', $commit->getPHID()); $path_ids = mpull($inlines, 'getPathID'); $path_map = array(); if ($path_ids) { $path_map = id(new DiffusionPathQuery()) ->withPathIDs($path_ids) ->execute(); $path_map = ipull($path_map, 'path', 'id'); } $engine = new PhabricatorMarkupEngine(); $engine->setViewer($user); foreach ($comments as $comment) { $engine->addObject( $comment, PhabricatorAuditComment::MARKUP_FIELD_BODY); } foreach ($inlines as $inline) { $engine->addObject( $inline, PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); } $engine->process(); $view = new DiffusionCommentListView(); $view->setMarkupEngine($engine); $view->setUser($user); $view->setComments($comments); $view->setInlineComments($inlines); $view->setPathMap($path_map); $phids = $view->getRequiredHandlePHIDs(); $handles = $this->loadViewerHandles($phids); $view->setHandles($handles); return $view; } private function renderAddCommentPanel( PhabricatorRepositoryCommit $commit, array $audit_requests, $pane_id = null) { assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest'); $user = $this->getRequest()->getUser(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); Javelin::initBehavior( 'differential-keyboard-navigation', array( 'haunt' => $pane_id, )); $draft = id(new PhabricatorDraft())->loadOneWhere( 'authorPHID = %s AND draftKey = %s', $user->getPHID(), 'diffusion-audit-'.$commit->getID()); if ($draft) { $draft = $draft->getDraft(); } else { $draft = null; } $actions = $this->getAuditActions($commit, $audit_requests); $form = id(new AphrontFormView()) ->setUser($user) ->setAction('/audit/addcomment/') ->addHiddenInput('commit', $commit->getPHID()) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel('Action') ->setName('action') ->setID('audit-action') ->setOptions($actions)) ->appendChild( id(new AphrontFormTokenizerControl()) ->setLabel('Add Auditors') ->setName('auditors') ->setControlID('add-auditors') ->setControlStyle('display: none') ->setID('add-auditors-tokenizer') ->setDisableBehavior(true)) ->appendChild( id(new AphrontFormTokenizerControl()) ->setLabel('Add CCs') ->setName('ccs') ->setControlID('add-ccs') ->setControlStyle('display: none') ->setID('add-ccs-tokenizer') ->setDisableBehavior(true)) ->appendChild( id(new PhabricatorRemarkupControl()) ->setLabel('Comments') ->setName('content') ->setValue($draft) ->setID('audit-content') ->setUser($user)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue($is_serious ? 'Submit' : 'Cook the Books')); $panel = new AphrontPanelView(); $panel->setHeader($is_serious ? 'Audit Commit' : 'Creative Accounting'); $panel->appendChild($form); $panel->addClass('aphront-panel-accent'); $panel->addClass('aphront-panel-flush'); require_celerity_resource('phabricator-transaction-view-css'); Javelin::initBehavior( 'differential-add-reviewers-and-ccs', array( 'dynamic' => array( 'add-auditors-tokenizer' => array( 'actions' => array('add_auditors' => 1), 'src' => '/typeahead/common/users/', 'row' => 'add-auditors', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user name...', ), 'add-ccs-tokenizer' => array( 'actions' => array('add_ccs' => 1), 'src' => '/typeahead/common/mailable/', 'row' => 'add-ccs', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), 'placeholder' => 'Type a user or mailing list...', ), ), 'select' => 'audit-action', )); Javelin::initBehavior('differential-feedback-preview', array( 'uri' => '/audit/preview/'.$commit->getID().'/', 'preview' => 'audit-preview', 'content' => 'audit-content', 'action' => 'audit-action', 'previewTokenizers' => array( 'auditors' => 'add-auditors-tokenizer', 'ccs' => 'add-ccs-tokenizer', ), 'inline' => 'inline-comment-preview', 'inlineuri' => '/diffusion/inline/preview/'.$commit->getPHID().'/', )); $preview_panel = '
Loading preview...
'; return phutil_render_tag( 'div', array( 'class' => 'differential-add-comment-panel', ), $panel->render(). $preview_panel); } /** * Return a map of available audit actions for rendering into a