Page MenuHomePhabricator

D14395.id.diff
No OneTemporary

D14395.id.diff

diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -30,6 +30,7 @@
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',
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
@@ -6,11 +6,19 @@
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();
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
@@ -7,10 +7,11 @@
$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');
@@ -58,6 +59,7 @@
$name = $url->getName();
$long_url = $url->getLongURL();
+ $alias = $url->getAlias();
$description = $url->getDescription();
$edit_policy = $url->getEditPolicy();
$view_policy = $url->getViewPolicy();
@@ -67,6 +69,7 @@
$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');
@@ -86,6 +89,11 @@
$xactions[] = id(new PhabricatorPhurlURLTransaction())
->setTransactionType(
+ PhabricatorPhurlURLTransaction::TYPE_ALIAS)
+ ->setNewValue($alias);
+
+ $xactions[] = id(new PhabricatorPhurlURLTransaction())
+ ->setTransactionType(
PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue(array('=' => array_fuse($subscribers)));
@@ -127,6 +135,8 @@
PhabricatorPhurlURLTransaction::TYPE_NAME);
$error_long_url = $ex->getShortMessage(
PhabricatorPhurlURLTransaction::TYPE_URL);
+ $error_alias = $ex->getShortMessage(
+ PhabricatorPhurlURLTransaction::TYPE_ALIAS);
}
}
@@ -147,6 +157,12 @@
->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')
@@ -187,6 +203,7 @@
->setUser($viewer)
->appendChild($name)
->appendChild($long_url)
+ ->appendChild($alias)
->appendControl($view_policies)
->appendControl($edit_policies)
->appendControl($subscribers)
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
@@ -129,6 +129,10 @@
pht('Original URL'),
$url->getLongURL());
+ $properties->addProperty(
+ pht('Alias'),
+ $url->getAlias());
+
$properties->invokeWillRenderEvent();
if (strlen($url->getDescription())) {
diff --git a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
--- a/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
+++ b/src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
@@ -16,6 +16,7 @@
$types[] = PhabricatorPhurlURLTransaction::TYPE_NAME;
$types[] = PhabricatorPhurlURLTransaction::TYPE_URL;
+ $types[] = PhabricatorPhurlURLTransaction::TYPE_ALIAS;
$types[] = PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
@@ -33,6 +34,8 @@
return $object->getName();
case PhabricatorPhurlURLTransaction::TYPE_URL:
return $object->getLongURL();
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
+ return $object->getAlias();
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
}
@@ -46,6 +49,7 @@
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
case PhabricatorPhurlURLTransaction::TYPE_URL:
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return $xaction->getNewValue();
}
@@ -64,6 +68,9 @@
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;
@@ -79,6 +86,7 @@
switch ($xaction->getTransactionType()) {
case PhabricatorPhurlURLTransaction::TYPE_NAME:
case PhabricatorPhurlURLTransaction::TYPE_URL:
+ case PhabricatorPhurlURLTransaction::TYPE_ALIAS:
case PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION:
return;
}
@@ -110,6 +118,28 @@
$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(),
diff --git a/src/applications/phurl/query/PhabricatorPhurlURLQuery.php b/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
--- a/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
+++ b/src/applications/phurl/query/PhabricatorPhurlURLQuery.php
@@ -7,6 +7,7 @@
private $phids;
private $names;
private $longURLs;
+ private $aliases;
private $authorPHIDs;
public function newResultObject() {
@@ -33,6 +34,11 @@
return $this;
}
+ public function withAliases(array $aliases) {
+ $this->aliases = $aliases;
+ return $this;
+ }
+
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
@@ -87,6 +93,13 @@
$this->longURLs);
}
+ if ($this->aliases !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'url.alias IN (%Ls)',
+ $this->aliases);
+ }
+
return $where;
}
diff --git a/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php b/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
--- a/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
+++ b/src/applications/phurl/storage/PhabricatorPhurlURLTransaction.php
@@ -5,6 +5,7 @@
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';
@@ -28,6 +29,7 @@
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
$phids[] = $this->getObjectPHID();
break;
@@ -49,6 +51,7 @@
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
return 'fa-pencil';
break;
@@ -83,6 +86,12 @@
$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.",
@@ -130,6 +139,20 @@
$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.',
@@ -147,6 +170,7 @@
switch ($this->getTransactionType()) {
case self::TYPE_NAME:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
case self::TYPE_DESCRIPTION:
return PhabricatorTransactions::COLOR_GREEN;
}
@@ -185,6 +209,7 @@
case self::TYPE_NAME:
case self::TYPE_DESCRIPTION:
case self::TYPE_URL:
+ case self::TYPE_ALIAS:
$tags[] = self::MAILTAG_CONTENT;
break;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 1:23 AM (11 h, 48 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6712127
Default Alt Text
D14395.id.diff (11 KB)

Event Timeline