mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 18:51:12 +01:00
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
This commit is contained in:
parent
df23d893f7
commit
d8111f828f
7 changed files with 130 additions and 1 deletions
|
@ -2641,11 +2641,14 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSetupIssue' => 'Phobject',
|
||||
'PhabricatorSetupIssueUIExample' => 'PhabricatorUIExample',
|
||||
'PhabricatorSetupIssueView' => 'AphrontView',
|
||||
'PhabricatorShortSite' => 'PhabricatorSite',
|
||||
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
|
||||
'PhabricatorSite' => 'AphrontSite',
|
||||
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
|
||||
|
|
44
src/aphront/site/PhabricatorShortSite.php
Normal file
44
src/aphront/site/PhabricatorShortSite.php
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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')),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -51,4 +51,11 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
public function getShortRoutes() {
|
||||
return array(
|
||||
'/u/(?P<append>[^/]+)' => 'PhabricatorPhurlShortURLController',
|
||||
'.*' => 'PhabricatorPhurlShortURLDefaultController',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPhurlShortURLDefaultController
|
||||
extends PhabricatorPhurlController {
|
||||
|
||||
public function shouldRequireLogin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
}
|
|
@ -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 @@ final class PhabricatorPhurlURLAccessController
|
|||
return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue