Summary: Sgrepped for `"=~/</"` and manually changed every HTML. Test Plan: This doesn't work yet but it is hopefully one of the last diffs before Phabricator will be undoubtedly HTML safe. Reviewers: epriestley CC: aran, Korvin Maniphest Tasks: T2432 Differential Revision: https://secure.phabricator.com/D4927
149 lines
4.6 KiB
PHP
149 lines
4.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFeedStoryProject extends PhabricatorFeedStory {
|
|
|
|
public function getPrimaryObjectPHID() {
|
|
return $this->getValue('projectPHID');
|
|
}
|
|
|
|
public function renderView() {
|
|
$data = $this->getStoryData();
|
|
|
|
$view = new PhabricatorFeedStoryView();
|
|
|
|
$type = $data->getValue('type');
|
|
$old = $data->getValue('old');
|
|
$new = $data->getValue('new');
|
|
$proj_phid = $data->getValue('projectPHID');
|
|
|
|
$author_phid = $data->getAuthorPHID();
|
|
|
|
switch ($type) {
|
|
case PhabricatorProjectTransactionType::TYPE_NAME:
|
|
if (strlen($old)) {
|
|
$action = hsprintf(
|
|
'renamed project %s from %s to %s.',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderString($old),
|
|
$this->renderString($new));
|
|
} else {
|
|
$action = hsprintf(
|
|
'created project %s (as %s).',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderString($new));
|
|
}
|
|
break;
|
|
case PhabricatorProjectTransactionType::TYPE_STATUS:
|
|
$action = hsprintf(
|
|
'changed project %s status from %s to %s.',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderString(PhabricatorProjectStatus::getNameForStatus($old)),
|
|
$this->renderString(PhabricatorProjectStatus::getNameForStatus($new))
|
|
);
|
|
break;
|
|
case PhabricatorProjectTransactionType::TYPE_MEMBERS:
|
|
$add = array_diff($new, $old);
|
|
$rem = array_diff($old, $new);
|
|
|
|
if ((count($add) == 1) && (count($rem) == 0) &&
|
|
(head($add) == $author_phid)) {
|
|
$action = hsprintf('joined project %s.', $this->linkTo($proj_phid));
|
|
} else if ((count($add) == 0) && (count($rem) == 1) &&
|
|
(head($rem) == $author_phid)) {
|
|
$action = hsprintf('left project %s.', $this->linkTo($proj_phid));
|
|
} else if (empty($rem)) {
|
|
$action = hsprintf(
|
|
'added members to project %s: %s.',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderHandleList($add));
|
|
} else if (empty($add)) {
|
|
$action = hsprintf(
|
|
'removed members from project %s: %s.',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderHandleList($rem));
|
|
} else {
|
|
$action = hsprintf(
|
|
'changed members of project %s, added: %s; removed: %s.',
|
|
$this->linkTo($proj_phid),
|
|
$this->renderHandleList($add),
|
|
$this->renderHandleList($rem));
|
|
}
|
|
break;
|
|
default:
|
|
$action = hsprintf('updated project %s.', $this->linkTo($proj_phid));
|
|
break;
|
|
}
|
|
$view->setTitle(hsprintf('%s %s', $this->linkTo($author_phid), $action));
|
|
$view->setOneLineStory(true);
|
|
|
|
return $view;
|
|
}
|
|
|
|
public function renderText() {
|
|
$type = $this->getValue('type');
|
|
$old = $this->getValue('old');
|
|
$new = $this->getValue('new');
|
|
|
|
$proj_handle = $this->getHandle($this->getPrimaryObjectPHID());
|
|
$proj_name = $proj_handle->getLinkName();
|
|
$proj_uri = PhabricatorEnv::getURI($proj_handle->getURI());
|
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
$author_name = $this->getHandle($author_phid)->getLinkName();
|
|
|
|
switch ($type) {
|
|
case PhabricatorProjectTransactionType::TYPE_NAME:
|
|
if (strlen($old)) {
|
|
$action = 'renamed project '.
|
|
$proj_name.
|
|
' from '.
|
|
$old.
|
|
' to '.
|
|
$new;
|
|
} else {
|
|
$action = 'created project '.
|
|
$proj_name.
|
|
' (as '.
|
|
$new.
|
|
')';
|
|
}
|
|
break;
|
|
case PhabricatorProjectTransactionType::TYPE_STATUS:
|
|
$action = 'changed project '.
|
|
$proj_name.
|
|
' status from '.
|
|
$old.
|
|
' to '.
|
|
$new;
|
|
break;
|
|
case PhabricatorProjectTransactionType::TYPE_MEMBERS:
|
|
$add = array_diff($new, $old);
|
|
$rem = array_diff($old, $new);
|
|
|
|
if ((count($add) == 1) && (count($rem) == 0) &&
|
|
(head($add) == $author_phid)) {
|
|
$action = 'joined project';
|
|
} else if ((count($add) == 0) && (count($rem) == 1) &&
|
|
(head($rem) == $author_phid)) {
|
|
$action = 'left project';
|
|
} else if (empty($rem)) {
|
|
$action = 'added members to project';
|
|
} else if (empty($add)) {
|
|
$action = 'removed members from project';
|
|
} else {
|
|
$action = 'changed members of project';
|
|
}
|
|
$action .= " {$proj_name}";
|
|
break;
|
|
default:
|
|
$action = "updated project {$proj_name}";
|
|
break;
|
|
}
|
|
|
|
$text = "{$author_name} {$action} {$proj_uri}";
|
|
|
|
return $text;
|
|
}
|
|
|
|
}
|