Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
index 1c9a66f237..4e79670143 100644
--- a/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
@@ -1,153 +1,157 @@
<?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);
$crumbs->setBorder(true);
$timeline = $this->buildTransactionTimeline(
$url,
new PhabricatorPhurlURLTransactionQuery());
$header = $this->buildHeaderView($url);
$curtain = $this->buildCurtain($url);
$details = $this->buildPropertySectionView($url);
$url_error = id(new PHUIInfoView())
->setErrors(array(pht('This URL is invalid due to a bad protocol.')))
->setIsHidden($url->isValid());
$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(
'/url/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'));
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setCurtain($curtain)
->setMainColumn(array(
$url_error,
$details,
$timeline,
$add_comment_form,
));
return $this->newPage()
->setTitle($page_title)
->setCrumbs($crumbs)
->setPageObjectPHIDs(array($url->getPHID()))
->appendChild(
array(
$view,
));
}
private function buildHeaderView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$icon = 'fa-check';
$color = 'bluegrey';
$status = pht('Active');
$id = $url->getID();
$visit = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Visit URL'))
->setIcon('fa-external-link')
- ->setHref("u/{$id}")
+ ->setHref($url->getRedirectURI())
->setDisabled(!$url->isValid());
$header = id(new PHUIHeaderView())
->setUser($viewer)
->setHeader($url->getDisplayName())
->setStatus($icon, $color, $status)
->setPolicyObject($url)
->setHeaderIcon('fa-compress')
->addActionLink($visit);
return $header;
}
private function buildCurtain(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$id = $url->getID();
$curtain = $this->newCurtainView($url);
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$url,
PhabricatorPolicyCapability::CAN_EDIT);
$curtain
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Phurl'))
->setIcon('fa-pencil')
->setHref($this->getApplicationURI("url/edit/{$id}/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
return $curtain;
}
private function buildPropertySectionView(PhabricatorPhurlURL $url) {
$viewer = $this->getViewer();
$properties = id(new PHUIPropertyListView())
->setUser($viewer);
+ $properties->addProperty(
+ pht('Short URL'),
+ $url->getRedirectURI());
+
$properties->addProperty(
pht('Original URL'),
$url->getLongURL());
$properties->addProperty(
pht('Alias'),
$url->getAlias());
$description = $url->getDescription();
if (strlen($description)) {
$description = new PHUIRemarkupView($viewer, $description);
$properties->addSectionHeader(pht('Description'));
$properties->addTextContent($description);
}
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Details'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($properties);
}
}
diff --git a/src/applications/phurl/storage/PhabricatorPhurlURL.php b/src/applications/phurl/storage/PhabricatorPhurlURL.php
index 19d5968b0c..db82e20baf 100644
--- a/src/applications/phurl/storage/PhabricatorPhurlURL.php
+++ b/src/applications/phurl/storage/PhabricatorPhurlURL.php
@@ -1,197 +1,205 @@
<?php
final class PhabricatorPhurlURL extends PhabricatorPhurlDAO
implements PhabricatorPolicyInterface,
PhabricatorProjectInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface,
PhabricatorDestructibleInterface,
PhabricatorMentionableInterface,
PhabricatorFlaggableInterface,
PhabricatorSpacesInterface {
protected $name;
protected $alias;
protected $longURL;
protected $description;
protected $viewPolicy;
protected $editPolicy;
protected $authorPHID;
protected $spacePHID;
protected $mailKey;
const DEFAULT_ICON = 'fa-compress';
public static function initializeNewPhurlURL(PhabricatorUser $actor) {
$app = id(new PhabricatorApplicationQuery())
->setViewer($actor)
->withClasses(array('PhabricatorPhurlApplication'))
->executeOne();
return id(new PhabricatorPhurlURL())
->setAuthorPHID($actor->getPHID())
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy())
->setEditPolicy($actor->getPHID())
->setSpacePHID($actor->getDefaultSpacePHID());
}
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text',
'alias' => 'sort64?',
'longURL' => 'text',
'description' => 'text',
'mailKey' => 'bytes20',
),
self::CONFIG_KEY_SCHEMA => array(
'key_instance' => array(
'columns' => array('alias'),
'unique' => true,
),
'key_author' => array(
'columns' => array('authorPHID'),
),
),
) + parent::getConfiguration();
}
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));
}
return parent::save();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPhurlURLPHIDType::TYPECONST);
}
public function getMonogram() {
return 'U'.$this->getID();
}
public function getURI() {
$uri = '/'.$this->getMonogram();
return $uri;
}
public function isValid() {
$allowed_protocols = PhabricatorEnv::getEnvConfig('uri.allowed-protocols');
$uri = new PhutilURI($this->getLongURL());
return isset($allowed_protocols[$uri->getProtocol()]);
}
public function getDisplayName() {
if ($this->getName()) {
return $this->getName();
} else {
return $this->getLongURL();
}
}
public function getRedirectURI() {
if (strlen($this->getAlias())) {
- return '/u/'.$this->getAlias();
+ $path = '/u/'.$this->getAlias();
} else {
- return '/u/'.$this->getID();
+ $path = '/u/'.$this->getID();
}
+ $short_domain = PhabricatorEnv::getEnvConfig('phurl.short-uri');
+ if (!$short_domain) {
+ return $path;
+ }
+
+ $uri = new PhutilURI($short_domain);
+ $uri->setPath($path);
+ return (string)$uri;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
return $this->getViewPolicy();
case PhabricatorPolicyCapability::CAN_EDIT:
return $this->getEditPolicy();
}
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
$user_phid = $this->getAuthorPHID();
if ($user_phid) {
$viewer_phid = $viewer->getPHID();
if ($viewer_phid == $user_phid) {
return true;
}
}
return false;
}
public function describeAutomaticCapability($capability) {
return pht('The owner of a URL can always view and edit it.');
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PhabricatorPhurlURLEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new PhabricatorPhurlURLTransaction();
}
public function willRenderTimeline(
PhabricatorApplicationTransactionView $timeline,
AphrontRequest $request) {
return $timeline;
}
/* -( PhabricatorSubscribableInterface )----------------------------------- */
public function isAutomaticallySubscribed($phid) {
return ($phid == $this->getAuthorPHID());
}
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
public function getUsersToNotifyOfTokenGiven() {
return array($this->getAuthorPHID());
}
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
$this->delete();
$this->saveTransaction();
}
/* -( PhabricatorSpacesInterface )----------------------------------------- */
public function getSpacePHID() {
return $this->spacePHID;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Sep 7, 10:41 AM (22 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
223163
Default Alt Text
(10 KB)

Event Timeline