Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php
index 56912b0db5..11ea1dcc6b 100644
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -1,46 +1,47 @@
<?php
final class PhabricatorPhurlApplication extends PhabricatorApplication {
public function getName() {
return pht('Phurl');
}
public function getShortDescription() {
return pht('URL Shortener');
}
public function getFlavorText() {
return pht('Shorten your favorite URL.');
}
public function getBaseURI() {
return '/phurl/';
}
public function getFontIcon() {
return 'fa-compress';
}
public function isPrototype() {
return true;
}
public function getRoutes() {
return array(
'/U(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLViewController',
'/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlURLAccessController',
+ '/u/(?P<alias>[^/]+)' => 'PhabricatorPhurlURLAccessController',
'/phurl/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPhurlURLListController',
'url/' => array(
'create/'
=> 'PhabricatorPhurlURLEditController',
'edit/(?P<id>[1-9]\d*)/'
=> 'PhabricatorPhurlURLEditController',
),
),
);
}
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
index 8c005a90b9..8d15f7a37b 100644
--- a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
@@ -1,28 +1,36 @@
<?php
final class PhabricatorPhurlURLAccessController
extends PhabricatorPhurlController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
+ $alias = $request->getURIData('alias');
- $url = id(new PhabricatorPhurlURLQuery())
- ->setViewer($viewer)
- ->withIDs(array($id))
- ->executeOne();
+ if ($id) {
+ $url = id(new PhabricatorPhurlURLQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+ } else if ($alias) {
+ $url = id(new PhabricatorPhurlURLQuery())
+ ->setViewer($viewer)
+ ->withAliases(array($alias))
+ ->executeOne();
+ }
if (!$url) {
return new Aphront404Response();
}
if ($url->isValid()) {
return id(new AphrontRedirectResponse())
->setURI($url->getLongURL())
->setIsExternal(true);
} else {
return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram());
}
}
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
index 15c25408a8..5a7cd9686d 100644
--- a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
@@ -1,240 +1,257 @@
<?php
final class PhabricatorPhurlURLEditController
extends PhabricatorPhurlController {
public function handleRequest(AphrontRequest $request) {
$id = $request->getURIData('id');
$is_create = !$id;
- $viewer = $request->getViewer();
+ $viewer = $this->getViewer();
$user_phid = $viewer->getPHID();
$error_name = true;
$error_long_url = true;
+ $error_alias = null;
$validation_exception = null;
$next_workflow = $request->getStr('next');
$uri_query = $request->getStr('query');
if ($is_create) {
$url = PhabricatorPhurlURL::initializeNewPhurlURL(
$viewer);
$submit_label = pht('Create');
$page_title = pht('Shorten URL');
$subscribers = array();
$cancel_uri = $this->getApplicationURI();
} else {
$url = id(new PhabricatorPhurlURLQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$url) {
return new Aphront404Response();
}
$submit_label = pht('Update');
$page_title = pht('Update URL');
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$url->getPHID());
$cancel_uri = '/U'.$url->getID();
}
if ($is_create) {
$projects = array();
} else {
$projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
$url->getPHID(),
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
$projects = array_reverse($projects);
}
$name = $url->getName();
$long_url = $url->getLongURL();
+ $alias = $url->getAlias();
$description = $url->getDescription();
$edit_policy = $url->getEditPolicy();
$view_policy = $url->getViewPolicy();
$space = $url->getSpacePHID();
if ($request->isFormPost()) {
$xactions = array();
$name = $request->getStr('name');
$long_url = $request->getStr('longURL');
+ $alias = $request->getStr('alias');
$projects = $request->getArr('projects');
$description = $request->getStr('description');
$subscribers = $request->getArr('subscribers');
$edit_policy = $request->getStr('editPolicy');
$view_policy = $request->getStr('viewPolicy');
$space = $request->getStr('spacePHID');
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(
PhabricatorPhurlURLTransaction::TYPE_NAME)
->setNewValue($name);
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(
PhabricatorPhurlURLTransaction::TYPE_URL)
->setNewValue($long_url);
+ $xactions[] = id(new PhabricatorPhurlURLTransaction())
+ ->setTransactionType(
+ PhabricatorPhurlURLTransaction::TYPE_ALIAS)
+ ->setNewValue($alias);
+
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(
PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue(array('=' => array_fuse($subscribers)));
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(
PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
->setNewValue($description);
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
->setNewValue($view_policy);
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
->setNewValue($edit_policy);
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
->setNewValue($space);
$editor = id(new PhabricatorPhurlURLEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true);
try {
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $proj_edge_type)
->setNewValue(array('=' => array_fuse($projects)));
$xactions = $editor->applyTransactions($url, $xactions);
return id(new AphrontRedirectResponse())
->setURI($url->getURI());
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$error_name = $ex->getShortMessage(
PhabricatorPhurlURLTransaction::TYPE_NAME);
$error_long_url = $ex->getShortMessage(
PhabricatorPhurlURLTransaction::TYPE_URL);
+ $error_alias = $ex->getShortMessage(
+ PhabricatorPhurlURLTransaction::TYPE_ALIAS);
}
}
$current_policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer)
->setObject($url)
->execute();
$name = id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setName('name')
->setValue($name)
->setError($error_name);
$long_url = id(new AphrontFormTextControl())
->setLabel(pht('URL'))
->setName('longURL')
->setValue($long_url)
->setError($error_long_url);
+ $alias = id(new AphrontFormTextControl())
+ ->setLabel(pht('Alias'))
+ ->setName('alias')
+ ->setValue($alias)
+ ->setError($error_alias);
+
$projects = id(new AphrontFormTokenizerControl())
->setLabel(pht('Projects'))
->setName('projects')
->setValue($projects)
->setUser($viewer)
->setDatasource(new PhabricatorProjectDatasource());
$description = id(new PhabricatorRemarkupControl())
->setLabel(pht('Description'))
->setName('description')
->setValue($description)
->setUser($viewer);
$view_policies = id(new AphrontFormPolicyControl())
->setUser($viewer)
->setValue($view_policy)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($url)
->setPolicies($current_policies)
->setSpacePHID($space)
->setName('viewPolicy');
$edit_policies = id(new AphrontFormPolicyControl())
->setUser($viewer)
->setValue($edit_policy)
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
->setPolicyObject($url)
->setPolicies($current_policies)
->setName('editPolicy');
$subscribers = id(new AphrontFormTokenizerControl())
->setLabel(pht('Subscribers'))
->setName('subscribers')
->setValue($subscribers)
->setUser($viewer)
->setDatasource(new PhabricatorMetaMTAMailableDatasource());
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild($name)
->appendChild($long_url)
+ ->appendChild($alias)
->appendControl($view_policies)
->appendControl($edit_policies)
->appendControl($subscribers)
->appendChild($projects)
->appendChild($description);
if ($request->isAjax()) {
return $this->newDialog()
->setTitle($page_title)
->setWidth(AphrontDialogView::WIDTH_FULL)
->appendForm($form)
->addCancelButton($cancel_uri)
->addSubmitButton($submit_label);
}
$submit = id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue($submit_label);
$form->appendChild($submit);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($page_title)
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
if (!$is_create) {
$crumbs->addTextCrumb($url->getMonogram(), $url->getURI());
} else {
$crumbs->addTextCrumb(pht('Create URL'));
}
$crumbs->addTextCrumb($page_title);
$object_box = id(new PHUIObjectBoxView())
->setHeaderText($page_title)
->setValidationException($validation_exception)
->appendChild($form);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
),
array(
'title' => $page_title,
));
}
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
index b067a30813..7702d67b7c 100644
--- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
@@ -1,150 +1,154 @@
<?php
final class PhabricatorPhurlURLViewController
extends PhabricatorPhurlController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$timeline = null;
$url = id(new PhabricatorPhurlURLQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$url) {
return new Aphront404Response();
}
$title = $url->getMonogram();
$page_title = $title.' '.$url->getName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $url->getURI());
$timeline = $this->buildTransactionTimeline(
$url,
new PhabricatorPhurlURLTransactionQuery());
$header = $this->buildHeaderView($url);
$actions = $this->buildActionView($url);
$properties = $this->buildPropertyView($url);
$properties->setActionList($actions);
$url_error = id(new PHUIInfoView())
->setErrors(array(pht('This URL is invalid due to a bad protocol.')))
->setIsHidden($url->isValid());
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties)
->setInfoView($url_error);
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$add_comment_header = $is_serious
? pht('Add Comment')
: pht('More Cowbell');
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $url->getPHID());
$comment_uri = $this->getApplicationURI(
'/phurl/comment/'.$url->getID().'/');
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($url->getPHID())
->setDraft($draft)
->setHeaderText($add_comment_header)
->setAction($comment_uri)
->setSubmitButtonName(pht('Add Comment'));
return $this->buildApplicationPage(
array(
$crumbs,
$box,
$timeline,
$add_comment_form,
),
array(
'title' => $page_title,
'pageObjects' => array($url->getPHID()),
));
}
private function buildHeaderView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$icon = 'fa-compress';
$color = 'green';
$status = pht('Active');
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($url->getName())
->setStatus($icon, $color, $status)
->setPolicyObject($url);
return $header;
}
private function buildActionView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$id = $url->getID();
$actions = id(new PhabricatorActionListView())
->setObjectURI($url->getURI())
->setUser($viewer)
->setObject($url);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$url,
PhabricatorPolicyCapability::CAN_EDIT);
$actions
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("url/edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit))
->addAction(
id(new PhabricatorActionView())
->setName(pht('Visit URL'))
->setIcon('fa-external-link')
->setHref("u/{$id}")
->setDisabled(!$url->isValid()));
return $actions;
}
private function buildPropertyView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($url);
$properties->addProperty(
pht('Original URL'),
$url->getLongURL());
+ $properties->addProperty(
+ pht('Alias'),
+ $url->getAlias());
+
$properties->invokeWillRenderEvent();
if (strlen($url->getDescription())) {
$description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($url->getDescription()),
'default',
$viewer);
$properties->addSectionHeader(
pht('Description'),
PHUIPropertyListView::ICON_SUMMARY);
$properties->addTextContent($description);
}
return $properties;
}
}
diff --git a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
index 094688ee49..b7dcb7e3db 100644
--- a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
+++ b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
@@ -1,222 +1,252 @@
<?php
final class PhabricatorPhurlURLEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorPhurlApplication';
}
public function getEditorObjectsDescription() {
return pht('Phurl');
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorPhurlURLTransaction::TYPE_NAME;
$types[] = PhabricatorPhurlURLTransaction::TYPE_URL;
+ $types[] = PhabricatorPhurlURLTransaction::TYPE_ALIAS;
$types[] = PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
return $object->getName();
case PhabricatorPhurlURLTransaction::TYPE_URL:
return $object->getLongURL();
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
+ return $object->getAlias();
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
case PhabricatorPhurlURLTransaction::TYPE_URL:
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return $xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
return;
case PhabricatorPhurlURLTransaction::TYPE_URL:
$object->setLongURL($xaction->getNewValue());
return;
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
+ $object->setAlias($xaction->getNewValue());
+ return;
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
case PhabricatorPhurlURLTransaction::TYPE_URL:
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
switch ($type) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
$missing = $this->validateIsEmptyTextField(
$object->getName(),
$xactions);
if ($missing) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('URL name is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
+ break;
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
+ foreach ($xactions as $xaction) {
+ if ($xaction->getOldValue() != $xaction->getNewValue()) {
+ $new_alias = $xaction->getNewValue();
+ if (!preg_match('/[a-zA-Z]/', $new_alias)) {
+ $errors[] = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Invalid Alias'),
+ pht('The alias must contain at least one letter.'),
+ $xaction);
+ }
+ if (preg_match('/[^a-z0-9]/i', $new_alias)) {
+ $errors[] = new PhabricatorApplicationTransactionValidationError(
+ $type,
+ pht('Invalid Alias'),
+ pht('The alias may only contain letters and numbers.'),
+ $xaction);
+ }
+ }
+ }
+
break;
case PhabricatorPhurlURLTransaction::TYPE_URL:
$missing = $this->validateIsEmptyTextField(
$object->getLongURL(),
$xactions);
if ($missing) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('URL path is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
foreach ($xactions as $xaction) {
if ($xaction->getOldValue() != $xaction->getNewValue()) {
$protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols');
$uri = new PhutilURI($xaction->getNewValue());
if (!isset($protocols[$uri->getProtocol()])) {
$errors[] = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Invalid URL'),
pht('The protocol of the URL is invalid.'),
null);
}
}
}
break;
}
return $errors;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function supportsSearch() {
return true;
}
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function getMailSubjectPrefix() {
return pht('[Phurl]');
}
protected function getMailTo(PhabricatorLiskDAO $object) {
$phids = array();
if ($object->getPHID()) {
$phids[] = $object->getPHID();
}
$phids[] = $this->getActingAsPHID();
$phids = array_unique($phids);
return $phids;
}
public function getMailTagsMap() {
return array(
PhabricatorPhurlURLTransaction::MAILTAG_CONTENT =>
pht(
"A URL's name or path changes."),
PhabricatorPhurlURLTransaction::MAILTAG_OTHER =>
pht('Other event activity not listed above occurs.'),
);
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$id = $object->getID();
$name = $object->getName();
return id(new PhabricatorMetaMTAMail())
->setSubject("U{$id}: {$name}")
->addHeader('Thread-Topic', "U{$id}: ".$object->getName());
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$description = $object->getDescription();
$body = parent::buildMailBody($object, $xactions);
if (strlen($description)) {
$body->addTextSection(
pht('URL DESCRIPTION'),
$object->getDescription());
}
$body->addLinkSection(
pht('URL DETAIL'),
PhabricatorEnv::getProductionURI('/U'.$object->getID()));
return $body;
}
}
diff --git a/src/applications/phurl/query/PhabricatorPhurlURLQuery.php b/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
index 1edcb1e5c3..412b085635 100644
--- a/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
+++ b/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
@@ -1,100 +1,113 @@
<?php
final class PhabricatorPhurlURLQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $names;
private $longURLs;
+ private $aliases;
private $authorPHIDs;
public function newResultObject() {
return new PhabricatorPhurlURL();
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withLongURLs(array $long_urls) {
$this->longURLs = $long_urls;
return $this;
}
+ public function withAliases(array $aliases) {
+ $this->aliases = $aliases;
+ return $this;
+ }
+
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
}
protected function getPagingValueMap($cursor, array $keys) {
$url = $this->loadCursorObject($cursor);
return array(
'id' => $url->getID(),
);
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'url.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'url.phid IN (%Ls)',
$this->phids);
}
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'url.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->names !== null) {
$where[] = qsprintf(
$conn,
'url.name IN (%Ls)',
$this->names);
}
if ($this->longURLs !== null) {
$where[] = qsprintf(
$conn,
'url.longURL IN (%Ls)',
$this->longURLs);
}
+ if ($this->aliases !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'url.alias IN (%Ls)',
+ $this->aliases);
+ }
+
return $where;
}
protected function getPrimaryTableAlias() {
return 'url';
}
public function getQueryApplicationClass() {
return 'PhabricatorPhurlApplication';
}
}
diff --git a/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php b/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
index 0c00c67f2d..1bfc79da9b 100644
--- a/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
+++ b/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
@@ -1,194 +1,219 @@
<?php
final class PhabricatorPhurlURLTransaction
extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'phurl.name';
const TYPE_URL = 'phurl.longurl';
+ const TYPE_ALIAS = 'phurl.alias';
const TYPE_DESCRIPTION = 'phurl.description';
const MAILTAG_CONTENT = 'phurl:content';
const MAILTAG_OTHER = 'phurl:other';
public function getApplicationName() {
return 'phurl';
}
public function getApplicationTransactionType() {
return PhabricatorPhurlURLPHIDType::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new PhabricatorPhurlURLTransactionComment();
}
public function getRequiredHandlePHIDs() {
$phids = parent::getRequiredHandlePHIDs();
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
$phids[] = $this->getObjectPHID();
break;
}
return $phids;
}
public function shouldHide() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case self::TYPE_DESCRIPTION:
return ($old === null);
}
return parent::shouldHide();
}
public function getIcon() {
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
return 'fa-pencil';
break;
}
return parent::getIcon();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if ($old === null) {
return pht(
'%s created this URL.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s changed the name of the URL from %s to %s.',
$this->renderHandleLink($author_phid),
$old,
$new);
}
case self::TYPE_URL:
return pht(
'%s changed the destination of the URL from %s to %s.',
$this->renderHandleLink($author_phid),
$old,
$new);
+ case self::TYPE_ALIAS:
+ return pht(
+ '%s changed the alias of the URL from %s to %s.',
+ $this->renderHandleLink($author_phid),
+ $old,
+ $new);
case self::TYPE_DESCRIPTION:
return pht(
"%s updated the URL's description.",
$this->renderHandleLink($author_phid));
}
return parent::getTitle();
}
public function getTitleForFeed() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$viewer = $this->getViewer();
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if ($old === null) {
return pht(
'%s created %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
} else {
return pht(
'%s changed the name of %s from %s to %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
$old,
$new);
}
case self::TYPE_URL:
if ($old === null) {
return pht(
'%s created %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
} else {
return pht(
'%s changed the destination of %s from %s to %s',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
$old,
$new);
}
+ case self::TYPE_ALIAS:
+ if ($old === null) {
+ return pht(
+ '%s created %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ } else {
+ return pht(
+ '%s changed the alias of %s from %s to %s',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid),
+ $old,
+ $new);
+ }
case self::TYPE_DESCRIPTION:
return pht(
'%s updated the description of %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
return parent::getTitleForFeed();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
return PhabricatorTransactions::COLOR_GREEN;
}
return parent::getColor();
}
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
case self::TYPE_DESCRIPTION:
return ($this->getOldValue() !== null);
}
return parent::hasChangeDetails();
}
public function renderChangeDetails(PhabricatorUser $viewer) {
switch ($this->getTransactionType()) {
case self::TYPE_DESCRIPTION:
$old = $this->getOldValue();
$new = $this->getNewValue();
return $this->renderTextCorpusChangeDetails(
$viewer,
$old,
$new);
}
return parent::renderChangeDetails($viewer);
}
public function getMailTags() {
$tags = array();
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_DESCRIPTION:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
$tags[] = self::MAILTAG_CONTENT;
break;
}
return $tags;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 21, 12:10 PM (6 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
352658
Default Alt Text
(32 KB)

Event Timeline