Skip to content

Commit d8111f8

Browse files
author
lkassianik
committedNov 9, 2015
Allow a domain other than the install domain to serve as a short Phurl domain
Summary: Ref T8995, config option for Phurl short domain to share shortened URL's Test Plan: - Configure Phurl short domain to something like "zz.us" - Navigate to `zz.us`; get 404 - Navigate to `zz.us/u/3` or `zz.us/u/alias` where `U3` is an existing Phurl; redirect to correct destination Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Maniphest Tasks: T8995 Differential Revision: https://secure.phabricator.com/D14447
1 parent df23d89 commit d8111f8

7 files changed

+130
-1
lines changed
 

‎src/__phutil_library_map__.php

+8
Original file line numberDiff line numberDiff line change
@@ -2641,11 +2641,14 @@
26412641
'PhabricatorPhrictionApplication' => 'applications/phriction/application/PhabricatorPhrictionApplication.php',
26422642
'PhabricatorPhrictionConfigOptions' => 'applications/phriction/config/PhabricatorPhrictionConfigOptions.php',
26432643
'PhabricatorPhurlApplication' => 'applications/phurl/application/PhabricatorPhurlApplication.php',
2644+
'PhabricatorPhurlConfigOptions' => 'applications/config/option/PhabricatorPhurlConfigOptions.php',
26442645
'PhabricatorPhurlController' => 'applications/phurl/controller/PhabricatorPhurlController.php',
26452646
'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php',
26462647
'PhabricatorPhurlLinkRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php',
26472648
'PhabricatorPhurlRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php',
26482649
'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php',
2650+
'PhabricatorPhurlShortURLController' => 'applications/phurl/controller/PhabricatorPhurlShortURLController.php',
2651+
'PhabricatorPhurlShortURLDefaultController' => 'applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php',
26492652
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
26502653
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
26512654
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
@@ -2954,6 +2957,7 @@
29542957
'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php',
29552958
'PhabricatorSetupIssueUIExample' => 'applications/uiexample/examples/PhabricatorSetupIssueUIExample.php',
29562959
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
2960+
'PhabricatorShortSite' => 'aphront/site/PhabricatorShortSite.php',
29572961
'PhabricatorSimpleEditType' => 'applications/transactions/edittype/PhabricatorSimpleEditType.php',
29582962
'PhabricatorSite' => 'aphront/site/PhabricatorSite.php',
29592963
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
@@ -6774,11 +6778,14 @@
67746778
'PhabricatorPhrictionApplication' => 'PhabricatorApplication',
67756779
'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions',
67766780
'PhabricatorPhurlApplication' => 'PhabricatorApplication',
6781+
'PhabricatorPhurlConfigOptions' => 'PhabricatorApplicationConfigOptions',
67776782
'PhabricatorPhurlController' => 'PhabricatorController',
67786783
'PhabricatorPhurlDAO' => 'PhabricatorLiskDAO',
67796784
'PhabricatorPhurlLinkRemarkupRule' => 'PhutilRemarkupRule',
67806785
'PhabricatorPhurlRemarkupRule' => 'PhabricatorObjectRemarkupRule',
67816786
'PhabricatorPhurlSchemaSpec' => 'PhabricatorConfigSchemaSpec',
6787+
'PhabricatorPhurlShortURLController' => 'PhabricatorPhurlController',
6788+
'PhabricatorPhurlShortURLDefaultController' => 'PhabricatorPhurlController',
67826789
'PhabricatorPhurlURL' => array(
67836790
'PhabricatorPhurlDAO',
67846791
'PhabricatorPolicyInterface',
@@ -7167,6 +7174,7 @@
71677174
'PhabricatorSetupIssue' => 'Phobject',
71687175
'PhabricatorSetupIssueUIExample' => 'PhabricatorUIExample',
71697176
'PhabricatorSetupIssueView' => 'AphrontView',
7177+
'PhabricatorShortSite' => 'PhabricatorSite',
71707178
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
71717179
'PhabricatorSite' => 'AphrontSite',
71727180
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class PhabricatorShortSite extends PhabricatorSite {
4+
5+
public function getDescription() {
6+
return pht('Serves shortened URLs.');
7+
}
8+
9+
public function getPriority() {
10+
return 2500;
11+
}
12+
13+
public function newSiteForRequest(AphrontRequest $request) {
14+
$host = $request->getHost();
15+
16+
$uri = PhabricatorEnv::getEnvConfig('phurl.short-uri');
17+
if (!strlen($uri)) {
18+
return null;
19+
}
20+
21+
$phurl_installed = PhabricatorApplication::isClassInstalled(
22+
'PhabricatorPhurlApplication');
23+
if (!$phurl_installed) {
24+
return false;
25+
}
26+
27+
if ($this->isHostMatch($host, array($uri))) {
28+
return new PhabricatorShortSite();
29+
}
30+
31+
return null;
32+
}
33+
34+
public function getRoutingMaps() {
35+
$app = PhabricatorApplication::getByClass('PhabricatorPhurlApplication');
36+
37+
$maps = array();
38+
$maps[] = $this->newRoutingMap()
39+
->setApplication($app)
40+
->setRoutes($app->getShortRoutes());
41+
return $maps;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
final class PhabricatorPhurlConfigOptions
4+
extends PhabricatorApplicationConfigOptions {
5+
6+
public function getName() {
7+
return pht('Phurl');
8+
}
9+
10+
public function getDescription() {
11+
return pht('Options for Phurl.');
12+
}
13+
14+
public function getFontIcon() {
15+
return 'fa-link';
16+
}
17+
18+
public function getGroup() {
19+
return 'phurl';
20+
}
21+
22+
public function getOptions() {
23+
return array(
24+
$this->newOption('phurl.short-uri', 'string', null)
25+
->setLocked(true)
26+
->setSummary(pht('URI that Phurl will use to shorten URLs.'))
27+
->setDescription(
28+
pht(
29+
'Set the URI that Phurl will use to share shortened URLs.'))
30+
->addExample(
31+
'https://some-very-short-domain.museum/',
32+
pht('Valid Setting')),
33+
);
34+
}
35+
}

‎src/applications/phurl/application/PhabricatorPhurlApplication.php

+7
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,11 @@ public function getRoutes() {
5151
);
5252
}
5353

54+
public function getShortRoutes() {
55+
return array(
56+
'/u/(?P<append>[^/]+)' => 'PhabricatorPhurlShortURLController',
57+
'.*' => 'PhabricatorPhurlShortURLDefaultController',
58+
);
59+
}
60+
5461
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
final class PhabricatorPhurlShortURLController
4+
extends PhabricatorPhurlController {
5+
6+
public function shouldRequireLogin() {
7+
return false;
8+
}
9+
10+
public function handleRequest(AphrontRequest $request) {
11+
$viewer = $this->getViewer();
12+
$append = $request->getURIData('append');
13+
$main_domain_uri = PhabricatorEnv::getProductionURI('/u/'.$append);
14+
15+
return id(new AphrontRedirectResponse())
16+
->setIsExternal(true)
17+
->setURI($main_domain_uri);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
final class PhabricatorPhurlShortURLDefaultController
4+
extends PhabricatorPhurlController {
5+
6+
public function shouldRequireLogin() {
7+
return false;
8+
}
9+
10+
public function handleRequest(AphrontRequest $request) {
11+
return new Aphront404Response();
12+
}
13+
}

‎src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
final class PhabricatorPhurlURLAccessController
44
extends PhabricatorPhurlController {
55

6+
public function shouldAllowPublic() {
7+
return true;
8+
}
9+
610
public function handleRequest(AphrontRequest $request) {
711
$viewer = $this->getViewer();
812
$id = $request->getURIData('id');
@@ -32,5 +36,4 @@ public function handleRequest(AphrontRequest $request) {
3236
return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram());
3337
}
3438
}
35-
3639
}

0 commit comments

Comments
 (0)
Failed to load comments.