@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<?php
2
3final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
4
5 protected function getObjectNamePrefix() {
6 return '#';
7 }
8
9 protected function renderObjectRef(
10 $object,
11 PhabricatorObjectHandle $handle,
12 $anchor,
13 $id) {
14
15 if ($this->getEngine()->isTextMode()) {
16 return '#'.$id;
17 }
18
19 $tag = $handle->renderTag();
20 $tag->setPHID($handle->getPHID());
21 return $tag;
22 }
23
24 /**
25 * @return string Regex which defines a valid object ID
26 */
27 protected function getObjectIDPattern() {
28 // NOTE: This rule matches monograms with internal periods,
29 // like `#domain.com`, but does not match monograms with terminal
30 // periods, because they're probably just punctuation.
31
32 // Broadly, this will not match every possible project monogram, and we
33 // accept some false negatives -- like `#dot.` -- in order to avoid a bunch
34 // of false positives on general use of the `#` character.
35
36 // In other contexts, the PhabricatorProjectProjectPHIDType pattern is
37 // controlling and these names should parse correctly.
38
39 // These characters may never appear anywhere in a hashtag.
40 $never = '\s?!,:;{}#\\(\\)"\'\\*/~';
41
42 // These characters may not appear at the edge of the string.
43 $never_edge = '.';
44
45 return '(?:'.
46 '[^'.$never_edge.$never.'](?:[^'.$never.']*[^'.$never_edge.$never.'])?'.
47 ')';
48 }
49
50 protected function loadObjects(array $ids) {
51 $viewer = $this->getEngine()->getConfig('viewer');
52
53 // Put the "#" back on the front of these IDs.
54 $names = array();
55 foreach ($ids as $id) {
56 $names[] = '#'.$id;
57 }
58
59 // Issue a query by object name.
60 $query = id(new PhabricatorObjectQuery())
61 ->setViewer($viewer)
62 ->withNames($names);
63
64 $query->execute();
65 $projects = $query->getNamedResults();
66
67 // Slice the "#" off again.
68 $result = array();
69 foreach ($projects as $name => $project) {
70 $result[substr($name, 1)] = $project;
71 }
72
73 return $result;
74 }
75
76}