2013-05-18 11:46:39 +02:00
|
|
|
<?php
|
|
|
|
|
2014-08-04 16:55:43 +02:00
|
|
|
final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
|
2013-05-18 11:46:39 +02:00
|
|
|
|
|
|
|
protected function getObjectNamePrefix() {
|
|
|
|
return '#';
|
|
|
|
}
|
|
|
|
|
2015-05-04 23:33:00 +02:00
|
|
|
protected function renderObjectRef(
|
|
|
|
$object,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
$anchor,
|
|
|
|
$id) {
|
|
|
|
|
2014-07-05 19:16:58 +02:00
|
|
|
if ($this->getEngine()->isTextMode()) {
|
|
|
|
return '#'.$id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $handle->renderTag();
|
|
|
|
}
|
|
|
|
|
2013-05-18 11:46:39 +02:00
|
|
|
protected function getObjectIDPattern() {
|
2015-11-23 14:51:14 +01:00
|
|
|
// NOTE: The latter half of this rule matches monograms with internal
|
|
|
|
// periods, like `#domain.com`, but does not match monograms with terminal
|
|
|
|
// periods, because they're probably just puncutation.
|
2014-04-04 20:13:06 +02:00
|
|
|
|
|
|
|
// Broadly, this will not match every possible project monogram, and we
|
2015-11-23 14:51:14 +01:00
|
|
|
// accept some false negatives -- like `#dot.` -- in order to avoid a bunch
|
|
|
|
// of false positives on general use of the `#` character.
|
2014-04-04 20:13:06 +02:00
|
|
|
|
2014-07-24 00:05:46 +02:00
|
|
|
// In other contexts, the PhabricatorProjectProjectPHIDType pattern is
|
2014-04-04 20:13:06 +02:00
|
|
|
// controlling and these names should parse correctly.
|
|
|
|
|
2015-04-04 01:38:19 +02:00
|
|
|
// These characters may never appear anywhere in a hashtag.
|
2016-01-12 18:27:00 +01:00
|
|
|
$never = '\s?!,:;{}#\\(\\)"\'\\*/~';
|
2015-04-04 01:38:19 +02:00
|
|
|
|
2015-11-23 14:51:14 +01:00
|
|
|
// These characters may not appear at the edge of the string.
|
|
|
|
$never_edge = '.';
|
2015-04-04 01:38:19 +02:00
|
|
|
|
|
|
|
return
|
2015-11-23 14:51:14 +01:00
|
|
|
'[^'.$never_edge.$never.']+'.
|
2015-04-04 01:38:19 +02:00
|
|
|
'(?:'.
|
|
|
|
'[^'.$never.']*'.
|
2015-11-23 14:51:14 +01:00
|
|
|
'[^'.$never_edge.$never.']+'.
|
2015-04-04 01:38:19 +02:00
|
|
|
')*';
|
2013-05-18 11:46:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadObjects(array $ids) {
|
|
|
|
$viewer = $this->getEngine()->getConfig('viewer');
|
|
|
|
|
2014-01-03 21:24:21 +01:00
|
|
|
// Put the "#" back on the front of these IDs.
|
|
|
|
$names = array();
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$names[] = '#'.$id;
|
2013-05-18 11:46:39 +02:00
|
|
|
}
|
|
|
|
|
2014-01-03 21:24:21 +01:00
|
|
|
// Issue a query by object name.
|
|
|
|
$query = id(new PhabricatorObjectQuery())
|
2013-05-18 11:46:39 +02:00
|
|
|
->setViewer($viewer)
|
2014-01-03 21:24:21 +01:00
|
|
|
->withNames($names);
|
|
|
|
|
|
|
|
$query->execute();
|
|
|
|
$projects = $query->getNamedResults();
|
2013-05-18 11:46:39 +02:00
|
|
|
|
2014-01-03 21:24:21 +01:00
|
|
|
// Slice the "#" off again.
|
2013-05-18 11:46:39 +02:00
|
|
|
$result = array();
|
2014-01-03 21:24:21 +01:00
|
|
|
foreach ($projects as $name => $project) {
|
|
|
|
$result[substr($name, 1)] = $project;
|
2013-05-18 11:46:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|