Page MenuHomePhabricator

D14447.id.diff
No OneTemporary

D14447.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2641,11 +2641,14 @@
'PhabricatorPhrictionApplication' => 'applications/phriction/application/PhabricatorPhrictionApplication.php',
'PhabricatorPhrictionConfigOptions' => 'applications/phriction/config/PhabricatorPhrictionConfigOptions.php',
'PhabricatorPhurlApplication' => 'applications/phurl/application/PhabricatorPhurlApplication.php',
+ 'PhabricatorPhurlConfigOptions' => 'applications/config/option/PhabricatorPhurlConfigOptions.php',
'PhabricatorPhurlController' => 'applications/phurl/controller/PhabricatorPhurlController.php',
'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php',
'PhabricatorPhurlLinkRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php',
'PhabricatorPhurlRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php',
'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php',
+ 'PhabricatorPhurlShortURLController' => 'applications/phurl/controller/PhabricatorPhurlShortURLController.php',
+ 'PhabricatorPhurlShortURLDefaultController' => 'applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php',
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
@@ -2954,6 +2957,7 @@
'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php',
'PhabricatorSetupIssueUIExample' => 'applications/uiexample/examples/PhabricatorSetupIssueUIExample.php',
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
+ 'PhabricatorShortSite' => 'aphront/site/PhabricatorShortSite.php',
'PhabricatorSimpleEditType' => 'applications/transactions/edittype/PhabricatorSimpleEditType.php',
'PhabricatorSite' => 'aphront/site/PhabricatorSite.php',
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
@@ -6774,11 +6778,14 @@
'PhabricatorPhrictionApplication' => 'PhabricatorApplication',
'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhurlApplication' => 'PhabricatorApplication',
+ 'PhabricatorPhurlConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhurlController' => 'PhabricatorController',
'PhabricatorPhurlDAO' => 'PhabricatorLiskDAO',
'PhabricatorPhurlLinkRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorPhurlRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PhabricatorPhurlSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+ 'PhabricatorPhurlShortURLController' => 'PhabricatorPhurlController',
+ 'PhabricatorPhurlShortURLDefaultController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURL' => array(
'PhabricatorPhurlDAO',
'PhabricatorPolicyInterface',
@@ -7167,6 +7174,7 @@
'PhabricatorSetupIssue' => 'Phobject',
'PhabricatorSetupIssueUIExample' => 'PhabricatorUIExample',
'PhabricatorSetupIssueView' => 'AphrontView',
+ 'PhabricatorShortSite' => 'PhabricatorSite',
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
'PhabricatorSite' => 'AphrontSite',
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
diff --git a/src/aphront/site/PhabricatorShortSite.php b/src/aphront/site/PhabricatorShortSite.php
new file mode 100644
--- /dev/null
+++ b/src/aphront/site/PhabricatorShortSite.php
@@ -0,0 +1,44 @@
+<?php
+
+final class PhabricatorShortSite extends PhabricatorSite {
+
+ public function getDescription() {
+ return pht('Serves shortened URLs.');
+ }
+
+ public function getPriority() {
+ return 2500;
+ }
+
+ public function newSiteForRequest(AphrontRequest $request) {
+ $host = $request->getHost();
+
+ $uri = PhabricatorEnv::getEnvConfig('phurl.short-uri');
+ if (!strlen($uri)) {
+ return null;
+ }
+
+ $phurl_installed = PhabricatorApplication::isClassInstalled(
+ 'PhabricatorPhurlApplication');
+ if (!$phurl_installed) {
+ return false;
+ }
+
+ if ($this->isHostMatch($host, array($uri))) {
+ return new PhabricatorShortSite();
+ }
+
+ return null;
+ }
+
+ public function getRoutingMaps() {
+ $app = PhabricatorApplication::getByClass('PhabricatorPhurlApplication');
+
+ $maps = array();
+ $maps[] = $this->newRoutingMap()
+ ->setApplication($app)
+ ->setRoutes($app->getShortRoutes());
+ return $maps;
+ }
+
+}
diff --git a/src/applications/config/option/PhabricatorPhurlConfigOptions.php b/src/applications/config/option/PhabricatorPhurlConfigOptions.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/option/PhabricatorPhurlConfigOptions.php
@@ -0,0 +1,35 @@
+<?php
+
+final class PhabricatorPhurlConfigOptions
+ extends PhabricatorApplicationConfigOptions {
+
+ public function getName() {
+ return pht('Phurl');
+ }
+
+ public function getDescription() {
+ return pht('Options for Phurl.');
+ }
+
+ public function getFontIcon() {
+ return 'fa-link';
+ }
+
+ public function getGroup() {
+ return 'phurl';
+ }
+
+ public function getOptions() {
+ return array(
+ $this->newOption('phurl.short-uri', 'string', null)
+ ->setLocked(true)
+ ->setSummary(pht('URI that Phurl will use to shorten URLs.'))
+ ->setDescription(
+ pht(
+ 'Set the URI that Phurl will use to share shortened URLs.'))
+ ->addExample(
+ 'https://some-very-short-domain.museum/',
+ pht('Valid Setting')),
+ );
+ }
+}
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
@@ -51,4 +51,11 @@
);
}
+ public function getShortRoutes() {
+ return array(
+ '/u/(?P<append>[^/]+)' => 'PhabricatorPhurlShortURLController',
+ '.*' => 'PhabricatorPhurlShortURLDefaultController',
+ );
+ }
+
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php
@@ -0,0 +1,19 @@
+<?php
+
+final class PhabricatorPhurlShortURLController
+ extends PhabricatorPhurlController {
+
+ public function shouldRequireLogin() {
+ return false;
+ }
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $this->getViewer();
+ $append = $request->getURIData('append');
+ $main_domain_uri = PhabricatorEnv::getProductionURI('/u/'.$append);
+
+ return id(new AphrontRedirectResponse())
+ ->setIsExternal(true)
+ ->setURI($main_domain_uri);
+ }
+}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php
@@ -0,0 +1,13 @@
+<?php
+
+final class PhabricatorPhurlShortURLDefaultController
+ extends PhabricatorPhurlController {
+
+ public function shouldRequireLogin() {
+ return false;
+ }
+
+ public function handleRequest(AphrontRequest $request) {
+ return new Aphront404Response();
+ }
+}
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
@@ -3,6 +3,10 @@
final class PhabricatorPhurlURLAccessController
extends PhabricatorPhurlController {
+ public function shouldAllowPublic() {
+ return true;
+ }
+
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
@@ -32,5 +36,4 @@
return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram());
}
}
-
}

File Metadata

Mime Type
text/plain
Expires
Sun, May 19, 11:35 AM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6281718
Default Alt Text
D14447.id.diff (8 KB)

Event Timeline