2011-07-12 05:14:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
2012-03-14 00:21:04 +01:00
|
|
|
final class PhabricatorRemarkupRulePhriction
|
2011-07-12 05:14:46 +02:00
|
|
|
extends PhutilRemarkupRule {
|
|
|
|
|
|
|
|
public function apply($text) {
|
|
|
|
return preg_replace_callback(
|
Require double brackets for Phriction links
Summary:
Single brackets are getting some troublesome false positives in Facebook's
install. Particularly, there's a weird convention at Facebook of tagging diffs
by putting stuff like "[perf]" or "[chat]" in the title, although this isn't
turned into structured data at any stage. When commits appear in Diffusion, we
currently link such ad-hoc tags to Phriction.
Wikipedia uses double-bracket sytnax, as do many other wikis, so this seems like
a reasonable burden to place on the lightweightness of the markup. The
alternative is selectively disabling Phriction markup in some interfaces, but
I'd rather allow integration in commit messages and just guard the syntax more
closely.
(I'm not providing any sort of migration plan since this landed less than a week
ago and I'm pretty confident no one has built a huge wiki yet, but I added a
CHANGELOG note.)
Test Plan: Edited a wiki document and added some links. Verified single brackets
were unlinked and double brackets were linked.
Reviewed By: jungejason
Reviewers: hsb, aran, jungejason, tuomaspelkonen
CC: aran, jungejason, epriestley
Differential Revision: 689
2011-07-18 17:52:40 +02:00
|
|
|
'@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U',
|
2011-07-12 05:14:46 +02:00
|
|
|
array($this, 'markupDocumentLink'),
|
|
|
|
$text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markupDocumentLink($matches) {
|
|
|
|
|
2012-11-06 00:47:51 +01:00
|
|
|
$link = trim($matches[1]);
|
|
|
|
$name = trim(idx($matches, 2, $link));
|
2012-04-05 23:59:58 +02:00
|
|
|
$name = explode('/', trim($name, '/'));
|
|
|
|
$name = end($name);
|
2011-07-12 05:14:46 +02:00
|
|
|
|
2012-11-06 00:47:51 +01:00
|
|
|
$uri = new PhutilURI($link);
|
|
|
|
$slug = $uri->getPath();
|
|
|
|
$fragment = $uri->getFragment();
|
|
|
|
$slug = PhabricatorSlug::normalize($slug);
|
|
|
|
$slug = PhrictionDocument::getSlugURI($slug);
|
|
|
|
$href = (string) id(new PhutilURI($slug))->setFragment($fragment);
|
2011-07-12 05:14:46 +02:00
|
|
|
|
|
|
|
return $this->getEngine()->storeText(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2012-11-06 00:47:51 +01:00
|
|
|
'href' => $href,
|
2012-04-05 23:59:58 +02:00
|
|
|
'class' => 'phriction-link',
|
2011-07-12 05:14:46 +02:00
|
|
|
),
|
|
|
|
phutil_escape_html($name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|