@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remarkup links to link to short url instead of long and fix commenting on Phurl's

Summary: Ref T6049, remarkup links to use short URLs and make commenting on Phurl's actually work

Test Plan:
- Create Phurl `U123`
- Comment on that Phurl `((123))`
Comment should link to `/u/123`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T6049

Differential Revision: https://secure.phabricator.com/D14477

+101 -28
+2
src/__phutil_library_map__.php
··· 2669 2669 'PhabricatorPhurlShortURLDefaultController' => 'applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php', 2670 2670 'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php', 2671 2671 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 2672 + 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', 2672 2673 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 2673 2674 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 2674 2675 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', ··· 6846 6847 'PhabricatorSpacesInterface', 6847 6848 ), 6848 6849 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 6850 + 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', 6849 6851 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 6850 6852 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 6851 6853 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
+1 -1
src/applications/config/option/PhabricatorPhurlConfigOptions.php
··· 16 16 } 17 17 18 18 public function getGroup() { 19 - return 'phurl'; 19 + return 'apps'; 20 20 } 21 21 22 22 public function getOptions() {
+2
src/applications/phurl/application/PhabricatorPhurlApplication.php
··· 46 46 => 'PhabricatorPhurlURLEditController', 47 47 'edit/(?P<id>[1-9]\d*)/' 48 48 => 'PhabricatorPhurlURLEditController', 49 + 'comment/(?P<id>[1-9]\d*)/' 50 + => 'PhabricatorPhurlURLCommentController', 49 51 ), 50 52 ), 51 53 );
+63
src/applications/phurl/controller/PhabricatorPhurlURLCommentController.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLCommentController 4 + extends PhabricatorPhurlController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + if (!$request->isFormPost()) { 8 + return new Aphront400Response(); 9 + } 10 + 11 + $viewer = $request->getViewer(); 12 + $id = $request->getURIData('id'); 13 + 14 + $is_preview = $request->isPreviewRequest(); 15 + $draft = PhabricatorDraft::buildFromRequest($request); 16 + 17 + $phurl = id(new PhabricatorPhurlURLQuery()) 18 + ->setViewer($viewer) 19 + ->withIDs(array($id)) 20 + ->executeOne(); 21 + if (!$phurl) { 22 + return new Aphront404Response(); 23 + } 24 + 25 + $view_uri = '/'.$phurl->getMonogram(); 26 + 27 + $xactions = array(); 28 + $xactions[] = id(new PhabricatorPhurlURLTransaction()) 29 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 30 + ->attachComment( 31 + id(new PhabricatorPhurlURLTransactionComment()) 32 + ->setContent($request->getStr('comment'))); 33 + 34 + $editor = id(new PhabricatorPhurlURLEditor()) 35 + ->setActor($viewer) 36 + ->setContinueOnNoEffect($request->isContinueRequest()) 37 + ->setContentSourceFromRequest($request) 38 + ->setIsPreview($is_preview); 39 + 40 + try { 41 + $xactions = $editor->applyTransactions($phurl, $xactions); 42 + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 43 + return id(new PhabricatorApplicationTransactionNoEffectResponse()) 44 + ->setCancelURI($view_uri) 45 + ->setException($ex); 46 + } 47 + 48 + if ($draft) { 49 + $draft->replaceOrDelete(); 50 + } 51 + 52 + if ($request->isAjax() && $is_preview) { 53 + return id(new PhabricatorApplicationTransactionResponse()) 54 + ->setViewer($viewer) 55 + ->setTransactions($xactions) 56 + ->setIsPreview($is_preview); 57 + } else { 58 + return id(new AphrontRedirectResponse()) 59 + ->setURI($view_uri); 60 + } 61 + } 62 + 63 + }
+1 -5
src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
··· 9 9 10 10 $viewer = $this->getViewer(); 11 11 $user_phid = $viewer->getPHID(); 12 - $error_name = true; 13 12 $error_long_url = true; 14 13 $error_alias = null; 15 14 $validation_exception = null; ··· 131 130 ->setURI($url->getURI()); 132 131 } catch (PhabricatorApplicationTransactionValidationException $ex) { 133 132 $validation_exception = $ex; 134 - $error_name = $ex->getShortMessage( 135 - PhabricatorPhurlURLTransaction::TYPE_NAME); 136 133 $error_long_url = $ex->getShortMessage( 137 134 PhabricatorPhurlURLTransaction::TYPE_URL); 138 135 $error_alias = $ex->getShortMessage( ··· 148 145 $name = id(new AphrontFormTextControl()) 149 146 ->setLabel(pht('Name')) 150 147 ->setName('name') 151 - ->setValue($name) 152 - ->setError($error_name); 148 + ->setValue($name); 153 149 154 150 $long_url = id(new AphrontFormTextControl()) 155 151 ->setLabel(pht('URL'))
+1 -1
src/applications/phurl/controller/PhabricatorPhurlURLViewController.php
··· 49 49 : pht('More Cowbell'); 50 50 $draft = PhabricatorDraft::newFromUserAndKey($viewer, $url->getPHID()); 51 51 $comment_uri = $this->getApplicationURI( 52 - '/phurl/comment/'.$url->getID().'/'); 52 + '/url/comment/'.$url->getID().'/'); 53 53 $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) 54 54 ->setUser($viewer) 55 55 ->setObjectPHID($url->getPHID())
-16
src/applications/phurl/editor/PhabricatorPhurlURLEditor.php
··· 106 106 $errors = parent::validateTransaction($object, $type, $xactions); 107 107 108 108 switch ($type) { 109 - case PhabricatorPhurlURLTransaction::TYPE_NAME: 110 - $missing = $this->validateIsEmptyTextField( 111 - $object->getName(), 112 - $xactions); 113 - 114 - if ($missing) { 115 - $error = new PhabricatorApplicationTransactionValidationError( 116 - $type, 117 - pht('Required'), 118 - pht('URL name is required.'), 119 - nonempty(last($xactions), null)); 120 - 121 - $error->setIsMissingFieldError(true); 122 - $errors[] = $error; 123 - } 124 - break; 125 109 case PhabricatorPhurlURLTransaction::TYPE_ALIAS: 126 110 $overdrawn = $this->validateIsTextFieldTooLong( 127 111 $object->getName(),
+15 -5
src/applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php
··· 7 7 } 8 8 9 9 public function apply($text) { 10 - // `((U123))` remarkup link to `/u/123` 10 + // `((123))` remarkup link to `/u/123` 11 11 // `((alias))` remarkup link to `/u/alias` 12 12 return preg_replace_callback( 13 13 '/\(\(([^ )]+)\)\)/', ··· 25 25 } 26 26 27 27 $ref = $matches[1]; 28 + $monogram = null; 29 + $is_monogram = '/^U(?P<id>[1-9]\d*)/'; 28 30 29 - if (ctype_digit($ref)) { 31 + if (preg_match($is_monogram, $ref, $monogram)) { 32 + $phurls = id(new PhabricatorPhurlURLQuery()) 33 + ->setViewer($viewer) 34 + ->withIDs(array($monogram[1])) 35 + ->execute(); 36 + } else if (ctype_digit($ref)) { 30 37 $phurls = id(new PhabricatorPhurlURLQuery()) 31 38 ->setViewer($viewer) 32 39 ->withIDs(array($ref)) ··· 42 49 43 50 if ($phurl) { 44 51 if ($text_mode) { 45 - return $phurl->getName().' <'.$phurl->getLongURL().'>'; 52 + return $phurl->getDisplayName(). 53 + ' <'. 54 + $phurl->getRedirectURI(). 55 + '>'; 46 56 } 47 57 48 58 $link = phutil_tag( 49 59 'a', 50 60 array( 51 - 'href' => $phurl->getLongURL(), 61 + 'href' => $phurl->getRedirectURI(), 52 62 'target' => '_blank', 53 63 ), 54 - $phurl->getName()); 64 + $phurl->getDisplayName()); 55 65 56 66 return $this->getEngine()->storeText($link); 57 67 } else {
+16
src/applications/phurl/storage/PhabricatorPhurlURL.php
··· 79 79 return isset($allowed_protocols[$uri->getProtocol()]); 80 80 } 81 81 82 + public function getDisplayName() { 83 + if ($this->getName()) { 84 + return $this->getName(); 85 + } else { 86 + return $this->getMonogram(); 87 + } 88 + } 89 + 90 + public function getRedirectURI() { 91 + if (strlen($this->getAlias())) { 92 + return '/u/'.$this->getAlias(); 93 + } else { 94 + return '/u/'.$this->getID(); 95 + } 96 + } 97 + 82 98 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 83 99 84 100