mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-06 03:48:28 +01:00
Basic remarkup integration for Phriction
Summary: Document linking and some general layout improvements. I'd like to eventually do more meta-dataey things with links (like store them separately and check them for 404s) but this is a decent start. Test Plan: https://secure.phabricator.com/file/view/PHID-FILE-d756b94a06b69c273fce/ Reviewed By: jungejason Reviewers: hsb, codeblock, jungejason, tuomaspelkonen, aran CC: aran, jungejason, epriestley Differential Revision: 650
This commit is contained in:
parent
349a8c60e8
commit
7d152def3e
9 changed files with 144 additions and 5 deletions
|
@ -469,6 +469,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/remarkup/markuprule/mention',
|
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/remarkup/markuprule/mention',
|
||||||
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/remarkup/markuprule/objectname',
|
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/remarkup/markuprule/objectname',
|
||||||
'PhabricatorRemarkupRulePaste' => 'infrastructure/markup/remarkup/markuprule/paste',
|
'PhabricatorRemarkupRulePaste' => 'infrastructure/markup/remarkup/markuprule/paste',
|
||||||
|
'PhabricatorRemarkupRulePhriction' => 'infrastructure/markup/remarkup/markuprule/phriction',
|
||||||
'PhabricatorRemarkupRuleProxyImage' => 'infrastructure/markup/remarkup/markuprule/proxyimage',
|
'PhabricatorRemarkupRuleProxyImage' => 'infrastructure/markup/remarkup/markuprule/proxyimage',
|
||||||
'PhabricatorRemarkupRuleYoutube' => 'infrastructure/markup/remarkup/markuprule/youtube',
|
'PhabricatorRemarkupRuleYoutube' => 'infrastructure/markup/remarkup/markuprule/youtube',
|
||||||
'PhabricatorRepository' => 'applications/repository/storage/repository',
|
'PhabricatorRepository' => 'applications/repository/storage/repository',
|
||||||
|
@ -980,6 +981,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRulePaste' => 'PhabricatorRemarkupRuleObjectName',
|
'PhabricatorRemarkupRulePaste' => 'PhabricatorRemarkupRuleObjectName',
|
||||||
|
'PhabricatorRemarkupRulePhriction' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleProxyImage' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleProxyImage' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRepository' => 'PhabricatorRepositoryDAO',
|
'PhabricatorRepository' => 'PhabricatorRepositoryDAO',
|
||||||
|
|
|
@ -101,6 +101,7 @@ class PhabricatorMarkupEngine {
|
||||||
$rules[] = new PhabricatorRemarkupRulePaste();
|
$rules[] = new PhabricatorRemarkupRulePaste();
|
||||||
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
||||||
$rules[] = new PhabricatorRemarkupRuleMention();
|
$rules[] = new PhabricatorRemarkupRuleMention();
|
||||||
|
$rules[] = new PhabricatorRemarkupRulePhriction();
|
||||||
|
|
||||||
$custom_rule_classes = $options['custom-inline'];
|
$custom_rule_classes = $options['custom-inline'];
|
||||||
if ($custom_rule_classes) {
|
if ($custom_rule_classes) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/
|
||||||
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/maniphest');
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/maniphest');
|
||||||
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/mention');
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/mention');
|
||||||
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/paste');
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/paste');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/phriction');
|
||||||
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/proxyimage');
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/proxyimage');
|
||||||
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/youtube');
|
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/youtube');
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ class PhrictionDocumentController
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
|
|
||||||
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$slug = PhrictionDocument::normalizeSlug($this->slug);
|
$slug = PhrictionDocument::normalizeSlug($this->slug);
|
||||||
if ($slug != $this->slug) {
|
if ($slug != $this->slug) {
|
||||||
$uri = PhrictionDocument::getSlugURI($slug);
|
$uri = PhrictionDocument::getSlugURI($slug);
|
||||||
|
@ -41,19 +43,62 @@ class PhrictionDocumentController
|
||||||
$slug);
|
$slug);
|
||||||
|
|
||||||
if (!$document) {
|
if (!$document) {
|
||||||
$page_content = '<em>No content here!</em>';
|
$create_uri = '/phriction/edit/?slug='.$slug;
|
||||||
|
|
||||||
|
$page_content =
|
||||||
|
'<div class="phriction-content">'.
|
||||||
|
'<em>No content here!</em><br />'.
|
||||||
|
'No document found at <tt>'.phutil_escape_html($slug).'</tt>. '.
|
||||||
|
'You can <strong>'.
|
||||||
|
phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $create_uri,
|
||||||
|
),
|
||||||
|
'create a new document').'</strong>.'.
|
||||||
|
'</div>';
|
||||||
$page_title = 'Page Not Found';
|
$page_title = 'Page Not Found';
|
||||||
$button = phutil_render_tag(
|
$button = phutil_render_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'href' => '/phriction/edit/?slug='.$slug,
|
'href' => $create_uri,
|
||||||
'class' => 'green button',
|
'class' => 'green button',
|
||||||
),
|
),
|
||||||
'Create Page');
|
'Create Page');
|
||||||
} else {
|
} else {
|
||||||
$content = id(new PhrictionContent())->load($document->getContentID());
|
$content = id(new PhrictionContent())->load($document->getContentID());
|
||||||
$page_content = phutil_escape_html($content->getContent());
|
|
||||||
$page_title = $content->getTitle();
|
$page_title = $content->getTitle();
|
||||||
|
|
||||||
|
$phids = array($content->getAuthorPHID());
|
||||||
|
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||||
|
|
||||||
|
$age = time() - $content->getDateCreated();
|
||||||
|
$age = floor($age / (60 * 60 * 24));
|
||||||
|
|
||||||
|
if ($age < 1) {
|
||||||
|
$when = 'today';
|
||||||
|
} else if ($age == 1) {
|
||||||
|
$when = 'yesterday';
|
||||||
|
} else {
|
||||||
|
$when = "{$age} days ago";
|
||||||
|
}
|
||||||
|
|
||||||
|
$byline =
|
||||||
|
'<div class="phriction-byline">'.
|
||||||
|
"Last updated {$when} by ".
|
||||||
|
$handles[$content->getAuthorPHID()]->renderLink().'.'.
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
$engine = PhabricatorMarkupEngine::newPhrictionMarkupEngine();
|
||||||
|
|
||||||
|
$page_content =
|
||||||
|
'<div class="phriction-content">'.
|
||||||
|
$byline.
|
||||||
|
'<div class="phabricator-remarkup">'.
|
||||||
|
$engine->markupText($content->getContent()).
|
||||||
|
'</div>'.
|
||||||
|
'</div>';
|
||||||
|
|
||||||
$button = phutil_render_tag(
|
$button = phutil_render_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||||
|
phutil_require_module('phabricator', 'applications/markup/engine');
|
||||||
|
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||||
phutil_require_module('phabricator', 'applications/phriction/controller/base');
|
phutil_require_module('phabricator', 'applications/phriction/controller/base');
|
||||||
phutil_require_module('phabricator', 'applications/phriction/storage/content');
|
phutil_require_module('phabricator', 'applications/phriction/storage/content');
|
||||||
phutil_require_module('phabricator', 'applications/phriction/storage/document');
|
phutil_require_module('phabricator', 'applications/phriction/storage/document');
|
||||||
|
|
|
@ -58,7 +58,8 @@ class PhrictionEditController
|
||||||
|
|
||||||
$default_title = null;
|
$default_title = null;
|
||||||
if ($slug) {
|
if ($slug) {
|
||||||
$default_title = end(explode('/', trim($slug, '/')));
|
$parts = explode('/', trim($slug, '/'));
|
||||||
|
$default_title = end($parts);
|
||||||
$default_title = str_replace('_', ' ', $default_title);
|
$default_title = str_replace('_', ' ', $default_title);
|
||||||
$default_title = ucwords($default_title);
|
$default_title = ucwords($default_title);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2011 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group markup
|
||||||
|
*/
|
||||||
|
class PhabricatorRemarkupRulePhriction
|
||||||
|
extends PhutilRemarkupRule {
|
||||||
|
|
||||||
|
public function apply($text) {
|
||||||
|
return preg_replace_callback(
|
||||||
|
'@\B\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\B@U',
|
||||||
|
array($this, 'markupDocumentLink'),
|
||||||
|
$text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markupDocumentLink($matches) {
|
||||||
|
|
||||||
|
$slug = trim($matches[1]);
|
||||||
|
$name = trim(idx($matches, 2, $slug));
|
||||||
|
$name = explode('/', $name);
|
||||||
|
$name = end($name);
|
||||||
|
|
||||||
|
$slug = PhrictionDocument::normalizeSlug($slug);
|
||||||
|
$uri = PhrictionDocument::getSlugURI($slug);
|
||||||
|
|
||||||
|
return $this->getEngine()->storeText(
|
||||||
|
phutil_render_tag(
|
||||||
|
'a',
|
||||||
|
array(
|
||||||
|
'href' => $uri,
|
||||||
|
'class' => 'phriction-link',
|
||||||
|
),
|
||||||
|
phutil_escape_html($name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is automatically generated. Lint this module to rebuild it.
|
||||||
|
* @generated
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_module('phabricator', 'applications/phriction/storage/document');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'markup');
|
||||||
|
phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base');
|
||||||
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
|
phutil_require_source('PhabricatorRemarkupRulePhriction.php');
|
|
@ -3,10 +3,29 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.phriction-header {
|
.phriction-header {
|
||||||
background: #dddddd;
|
background: #eeeeee;
|
||||||
|
border-bottom: 1px solid #dddddd;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.phriction-header a.button {
|
.phriction-header a.button {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.phriction-header h1 {
|
||||||
|
margin: .25em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phriction-content {
|
||||||
|
max-width: 960px;
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phriction-byline {
|
||||||
|
padding: .25em 0 1em;
|
||||||
|
color: #444444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phriction-content .phriction-link {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue