Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F548930
ProjectRemarkupRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ProjectRemarkupRule.php
View Options
<?php
final
class
ProjectRemarkupRule
extends
PhabricatorObjectRemarkupRule
{
protected
function
getObjectNamePrefix
()
{
return
'#'
;
}
protected
function
renderObjectRef
(
$object
,
PhabricatorObjectHandle
$handle
,
$anchor
,
$id
)
{
if
(
$this
->
getEngine
()->
isTextMode
())
{
return
'#'
.
$id
;
}
$tag
=
$handle
->
renderTag
();
$tag
->
setPHID
(
$handle
->
getPHID
());
return
$tag
;
}
protected
function
getObjectIDPattern
()
{
// NOTE: This rule matches monograms with internal periods,
// like `#domain.com`, but does not match monograms with terminal
// periods, because they're probably just punctuation.
// Broadly, this will not match every possible project monogram, and we
// accept some false negatives -- like `#dot.` -- in order to avoid a bunch
// of false positives on general use of the `#` character.
// In other contexts, the PhabricatorProjectProjectPHIDType pattern is
// controlling and these names should parse correctly.
// These characters may never appear anywhere in a hashtag.
$never
=
'
\s
?!,:;{}#
\\
(
\\
)"
\'\\
*/~'
;
// These characters may not appear at the edge of the string.
$never_edge
=
'.'
;
return
'(?:'
.
// Short project name with one or two characters not in $never_edge or
'[^'
.
$never_edge
.
$never
.
']{1,2}|'
.
// A single character not in $never or $never_edge,
// then any number of characters not in $never then a single character
// not in $never or $never_edge
'[^'
.
$never_edge
.
$never
.
'][^'
.
$never
.
']+[^'
.
$never_edge
.
$never
.
']'
.
')'
;
}
protected
function
loadObjects
(
array
$ids
)
{
$viewer
=
$this
->
getEngine
()->
getConfig
(
'viewer'
);
// Put the "#" back on the front of these IDs.
$names
=
array
();
foreach
(
$ids
as
$id
)
{
$names
[]
=
'#'
.
$id
;
}
// Issue a query by object name.
$query
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withNames
(
$names
);
$query
->
execute
();
$projects
=
$query
->
getNamedResults
();
// Slice the "#" off again.
$result
=
array
();
foreach
(
$projects
as
$name
=>
$project
)
{
$result
[
substr
(
$name
,
1
)]
=
$project
;
}
return
$result
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 1:57 PM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
100268
Default Alt Text
ProjectRemarkupRule.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment