Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F442628
PhabricatorRemarkupRuleObjectName.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhabricatorRemarkupRuleObjectName.php
View Options
<?php
/**
* @group markup
*/
abstract
class
PhabricatorRemarkupRuleObjectName
extends
PhutilRemarkupRule
{
abstract
protected
function
getObjectNamePrefix
();
protected
function
getObjectIDPattern
()
{
return
'[1-9]
\d
*'
;
}
public
function
apply
(
$text
)
{
$prefix
=
$this
->
getObjectNamePrefix
();
$id
=
$this
->
getObjectIDPattern
();
return
preg_replace_callback
(
"@
\b
({$prefix})({$id})(?:#([-
\w\d
]+))?
\b
@"
,
array
(
$this
,
'markupObjectNameLink'
),
$text
);
}
public
function
markupObjectNameLink
(
$matches
)
{
list
(,
$prefix
,
$id
)
=
$matches
;
if
(
isset
(
$matches
[
3
]))
{
$href
=
$matches
[
3
];
$text
=
$matches
[
3
];
if
(
preg_match
(
'@^(?:comment-)?(
\d
{1,7})$@'
,
$href
,
$matches
))
{
// Maximum length is 7 because 12345678 could be a file hash.
$href
=
"comment-{$matches[1]}"
;
$text
=
$matches
[
1
];
}
$href
=
"/{$prefix}{$id}#{$href}"
;
$text
=
"{$prefix}{$id}#{$text}"
;
}
else
{
$href
=
"/{$prefix}{$id}"
;
$text
=
"{$prefix}{$id}"
;
}
return
$this
->
getEngine
()->
storeText
(
phutil_tag
(
'a'
,
array
(
'href'
=>
$href
,
),
$text
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 9:16 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
64491
Default Alt Text
PhabricatorRemarkupRuleObjectName.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment