Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93495359
PhabricatorRemarkupRuleObjectName.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Nov 29, 05:14
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Dec 1, 05:14 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22650058
Attached To
rPH Phabricator
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
$this
->
replaceHTML
(
"@
\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
));
}
}
Event Timeline
Log In to Comment