Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97230891
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, Jan 3, 15:40
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Jan 5, 15:40 (2 d)
Engine
blob
Format
Raw Data
Handle
23360096
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