1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-18 18:51:12 +01:00

Support M123/456 mock references in Remarkup

Summary: Fixes T4729. This form is a little fluff, but we show it in the URI when you click an anchor on the page, and doing so seems desirable. I think it's reasonable to support this form, given that it appears in the URI.

Test Plan: Wrote some stuff like `M60`, `M60/71`, `M60/72/`, `M60/73/#13` and saw it all get picked up and rendered/linked properly.

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T4729

Differential Revision: https://secure.phabricator.com/D9555
This commit is contained in:
epriestley 2014-06-15 12:56:11 -07:00
parent bff58fac93
commit 99e3549522
2 changed files with 41 additions and 6 deletions

View file

@ -1,8 +1,5 @@
<?php
/**
* @group pholio
*/
final class PholioRemarkupRule
extends PhabricatorRemarkupRuleObject {
@ -10,15 +7,49 @@ final class PholioRemarkupRule
return 'M';
}
protected function getObjectIDPattern() {
// Match "M123", "M123/456", and "M123/456/". Users can hit the latter
// forms when clicking comment anchors on a mock page.
return '[1-9]\d*(?:/[1-9]\d*/?)?';
}
protected function getObjectHref($object, $handle, $id) {
$href = $handle->getURI();
// If the ID has a `M123/456` component, link to that specific image.
$id = explode('/', $id);
if (isset($id[1])) {
$href = $href.'/'.$id[1].'/';
}
return $href;
}
protected function loadObjects(array $ids) {
// Strip off any image ID components of the URI.
$map = array();
foreach ($ids as $id) {
$map[head(explode('/', $id))][] = $id;
}
$viewer = $this->getEngine()->getConfig('viewer');
return id(new PholioMockQuery())
$mocks = id(new PholioMockQuery())
->setViewer($viewer)
->needCoverFiles(true)
->needImages(true)
->needTokenCounts(true)
->withIDs($ids)
->withIDs(array_keys($map))
->execute();
$results = array();
foreach ($mocks as $mock) {
$ids = idx($map, $mock->getID(), array());
foreach ($ids as $id) {
$results[$id] = $mock;
}
}
return $results;
}
protected function renderObjectEmbed($object, $handle, $options) {

View file

@ -40,8 +40,12 @@ abstract class PhabricatorRemarkupRuleObject
return $result;
}
protected function getObjectHref($object, $handle, $id) {
return $handle->getURI();
}
protected function renderObjectRef($object, $handle, $anchor, $id) {
$href = $handle->getURI();
$href = $this->getObjectHref($object, $handle, $id);
$text = $this->getObjectNamePrefix().$id;
if ($anchor) {