@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.

Show missing Phriction documents as red links, invisible documents with a lock

Summary: Ref T7691 (errata). This shows links to Phriction documents in red if they're missing, and links to Phriction documents in grey with a lock icon if the user doesn't have the correct permissions to see the document.

Test Plan:
Tested a bunch of different configurations:

```
[[ ./../ ]] Back to Main Document
[[ ./../subdocument_2]] Mmmm more documents
[[ ./../invisible_document]] Mmmm more documents

[[ ./../ | Explicit Title ]] Back to Main Document
[[ ./../subdocument_2 | Explicit Title ]] Mmmm more documents
[[ ./../invisible_document | Explicit Title ]] Mmmm more documents

[[ ]] Absolute link
[[ subdocument_2 ]] Absolute link
[[ invisible_document ]] Absolute link

[[ | Explicit Title ]] Absolute link
[[ subdocument_2 | Explicit Title ]] Absolute link
[[ invisible_document | Explicit Title ]] Absolute link
```

Got the expected result:

{F1221106}

Reviewers: epriestley, chad, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T7691

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

+124 -26
+2 -2
resources/celerity/map.php
··· 88 88 'rsrc/css/application/phortune/phortune-credit-card-form.css' => '8391eb02', 89 89 'rsrc/css/application/phortune/phortune.css' => '9149f103', 90 90 'rsrc/css/application/phrequent/phrequent.css' => 'ffc185ad', 91 - 'rsrc/css/application/phriction/phriction-document-css.css' => 'd1861e06', 91 + 'rsrc/css/application/phriction/phriction-document-css.css' => '55446c91', 92 92 'rsrc/css/application/policy/policy-edit.css' => '815c66f7', 93 93 'rsrc/css/application/policy/policy-transaction-detail.css' => '82100a43', 94 94 'rsrc/css/application/policy/policy.css' => '957ea14c', ··· 807 807 'phortune-credit-card-form-css' => '8391eb02', 808 808 'phortune-css' => '9149f103', 809 809 'phrequent-css' => 'ffc185ad', 810 - 'phriction-document-css' => 'd1861e06', 810 + 'phriction-document-css' => '55446c91', 811 811 'phui-action-panel-css' => '91c7b835', 812 812 'phui-badge-view-css' => '3baef8db', 813 813 'phui-big-info-view-css' => 'bd903741',
+112 -24
src/applications/phriction/markup/PhrictionRemarkupRule.php
··· 2 2 3 3 final class PhrictionRemarkupRule extends PhutilRemarkupRule { 4 4 5 + const KEY_RULE_PHRICTION_LINK = 'phriction.link'; 6 + 5 7 public function getPriority() { 6 8 return 175.0; 7 9 } ··· 48 50 } 49 51 } 50 52 51 - $name = trim(idx($matches, 2, $link)); 53 + $name = trim(idx($matches, 2, '')); 52 54 if (empty($matches[2])) { 53 - $name = explode('/', trim($name, '/')); 54 - $name = end($name); 55 + $name = null; 55 56 } 56 57 57 - $uri = new PhutilURI($link); 58 - $slug = $uri->getPath(); 59 - $fragment = $uri->getFragment(); 60 - $slug = PhabricatorSlug::normalize($slug); 61 - $slug = PhrictionDocument::getSlugURI($slug); 62 - $href = (string)id(new PhutilURI($slug))->setFragment($fragment); 58 + // Link is now used for slug detection, so append a slash if one 59 + // is needed. 60 + $link = rtrim($link, '/').'/'; 63 61 64 - $text_mode = $this->getEngine()->isTextMode(); 65 - $mail_mode = $this->getEngine()->isHTMLMailMode(); 62 + $engine = $this->getEngine(); 63 + $token = $engine->storeText('x'); 64 + $metadata = $engine->getTextMetadata( 65 + self::KEY_RULE_PHRICTION_LINK, 66 + array()); 67 + $metadata[] = array( 68 + 'token' => $token, 69 + 'link' => $link, 70 + 'explicitName' => $name, 71 + ); 72 + $engine->setTextMetadata(self::KEY_RULE_PHRICTION_LINK, $metadata); 66 73 67 - if ($this->getEngine()->getState('toc')) { 68 - $text = $name; 69 - } else if ($text_mode || $mail_mode) { 70 - return PhabricatorEnv::getProductionURI($href); 71 - } else { 72 - $text = $this->newTag( 73 - 'a', 74 - array( 75 - 'href' => $href, 76 - 'class' => 'phriction-link', 77 - ), 78 - $name); 74 + return $token; 75 + } 76 + 77 + public function didMarkupText() { 78 + $engine = $this->getEngine(); 79 + $metadata = $engine->getTextMetadata( 80 + self::KEY_RULE_PHRICTION_LINK, 81 + array()); 82 + 83 + if (!$metadata) { 84 + return; 79 85 } 80 86 81 - return $this->getEngine()->storeText($text); 87 + $slugs = ipull($metadata, 'link'); 88 + 89 + // We have to make two queries here to distinguish between 90 + // documents the user can't see, and documents that don't 91 + // exist. 92 + $visible_documents = id(new PhrictionDocumentQuery()) 93 + ->setViewer($engine->getConfig('viewer')) 94 + ->withSlugs($slugs) 95 + ->needContent(true) 96 + ->execute(); 97 + $existant_documents = id(new PhrictionDocumentQuery()) 98 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 99 + ->withSlugs($slugs) 100 + ->execute(); 101 + 102 + $visible_documents = mpull($visible_documents, null, 'getSlug'); 103 + $existant_documents = mpull($existant_documents, null, 'getSlug'); 104 + 105 + foreach ($metadata as $spec) { 106 + $link = $spec['link']; 107 + $name = $spec['explicitName']; 108 + $class = 'phriction-link'; 109 + 110 + if (idx($existant_documents, $link) === null) { 111 + // The target document doesn't exist. 112 + if ($name === null) { 113 + $name = explode('/', trim($link, '/')); 114 + $name = end($name); 115 + } 116 + $class = 'phriction-link-missing'; 117 + } else if (idx($visible_documents, $link) === null) { 118 + // The document exists, but the user can't see it. 119 + if ($name === null) { 120 + $name = explode('/', trim($link, '/')); 121 + $name = end($name); 122 + } 123 + $class = 'phriction-link-lock'; 124 + } else { 125 + if ($name === null) { 126 + // Use the title of the document if no name is set. 127 + $name = $visible_documents[$link] 128 + ->getContent() 129 + ->getTitle(); 130 + } 131 + } 132 + 133 + $uri = new PhutilURI($link); 134 + $slug = $uri->getPath(); 135 + $fragment = $uri->getFragment(); 136 + $slug = PhabricatorSlug::normalize($slug); 137 + $slug = PhrictionDocument::getSlugURI($slug); 138 + $href = (string)id(new PhutilURI($slug))->setFragment($fragment); 139 + 140 + $text_mode = $this->getEngine()->isTextMode(); 141 + $mail_mode = $this->getEngine()->isHTMLMailMode(); 142 + 143 + if ($this->getEngine()->getState('toc')) { 144 + $text = $name; 145 + } else if ($text_mode || $mail_mode) { 146 + return PhabricatorEnv::getProductionURI($href); 147 + } else { 148 + if ($class === 'phriction-link-lock') { 149 + $name = array( 150 + $this->newTag( 151 + 'i', 152 + array( 153 + 'class' => 'phui-icon-view phui-font-fa fa-lock', 154 + ), 155 + ''), 156 + ' ', 157 + $name, 158 + ); 159 + } 160 + $text = $this->newTag( 161 + 'a', 162 + array( 163 + 'href' => $href, 164 + 'class' => $class, 165 + ), 166 + $name); 167 + $this->getEngine()->overwriteStoredText($spec['token'], $text); 168 + } 169 + } 82 170 } 83 171 84 172 }
+10
webroot/rsrc/css/application/phriction/phriction-document-css.css
··· 36 36 .phui-document-content .phriction-link { 37 37 font-weight: bold; 38 38 } 39 + 40 + .phui-document-content .phriction-link-missing { 41 + font-weight: bold; 42 + color: {$red}; 43 + } 44 + 45 + .phui-document-content .phriction-link-lock { 46 + font-weight: bold; 47 + color: {$greytext}; 48 + }