mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
99e3549522
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
74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class PholioRemarkupRule
|
|
extends PhabricatorRemarkupRuleObject {
|
|
|
|
protected function getObjectNamePrefix() {
|
|
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');
|
|
$mocks = id(new PholioMockQuery())
|
|
->setViewer($viewer)
|
|
->needCoverFiles(true)
|
|
->needImages(true)
|
|
->needTokenCounts(true)
|
|
->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) {
|
|
$embed_mock = id(new PholioMockEmbedView())
|
|
->setMock($object);
|
|
|
|
if (strlen($options)) {
|
|
$parser = new PhutilSimpleOptions();
|
|
$opts = $parser->parse(substr($options, 1));
|
|
|
|
if (isset($opts['image'])) {
|
|
$images = array_unique(
|
|
explode('&', preg_replace('/\s+/', '', $opts['image'])));
|
|
|
|
$embed_mock->setImages($images);
|
|
}
|
|
}
|
|
|
|
return $embed_mock->render();
|
|
}
|
|
|
|
}
|