1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02: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:
epriestley 2011-07-11 20:14:46 -07:00
parent 349a8c60e8
commit 7d152def3e
9 changed files with 144 additions and 5 deletions

View file

@ -469,6 +469,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/remarkup/markuprule/mention',
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/remarkup/markuprule/objectname',
'PhabricatorRemarkupRulePaste' => 'infrastructure/markup/remarkup/markuprule/paste',
'PhabricatorRemarkupRulePhriction' => 'infrastructure/markup/remarkup/markuprule/phriction',
'PhabricatorRemarkupRuleProxyImage' => 'infrastructure/markup/remarkup/markuprule/proxyimage',
'PhabricatorRemarkupRuleYoutube' => 'infrastructure/markup/remarkup/markuprule/youtube',
'PhabricatorRepository' => 'applications/repository/storage/repository',
@ -980,6 +981,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRulePaste' => 'PhabricatorRemarkupRuleObjectName',
'PhabricatorRemarkupRulePhriction' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleProxyImage' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule',
'PhabricatorRepository' => 'PhabricatorRepositoryDAO',

View file

@ -101,6 +101,7 @@ class PhabricatorMarkupEngine {
$rules[] = new PhabricatorRemarkupRulePaste();
$rules[] = new PhabricatorRemarkupRuleImageMacro();
$rules[] = new PhabricatorRemarkupRuleMention();
$rules[] = new PhabricatorRemarkupRulePhriction();
$custom_rule_classes = $options['custom-inline'];
if ($custom_rule_classes) {

View file

@ -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/mention');
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/youtube');

View file

@ -27,6 +27,8 @@ class PhrictionDocumentController
public function processRequest() {
$request = $this->getRequest();
$slug = PhrictionDocument::normalizeSlug($this->slug);
if ($slug != $this->slug) {
$uri = PhrictionDocument::getSlugURI($slug);
@ -41,19 +43,62 @@ class PhrictionDocumentController
$slug);
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';
$button = phutil_render_tag(
'a',
array(
'href' => '/phriction/edit/?slug='.$slug,
'href' => $create_uri,
'class' => 'green button',
),
'Create Page');
} else {
$content = id(new PhrictionContent())->load($document->getContentID());
$page_content = phutil_escape_html($content->getContent());
$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(
'a',
array(

View file

@ -7,6 +7,8 @@
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/storage/content');
phutil_require_module('phabricator', 'applications/phriction/storage/document');

View file

@ -58,7 +58,8 @@ class PhrictionEditController
$default_title = null;
if ($slug) {
$default_title = end(explode('/', trim($slug, '/')));
$parts = explode('/', trim($slug, '/'));
$default_title = end($parts);
$default_title = str_replace('_', ' ', $default_title);
$default_title = ucwords($default_title);
}

View file

@ -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)));
}
}

View file

@ -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');

View file

@ -3,10 +3,29 @@
*/
.phriction-header {
background: #dddddd;
background: #eeeeee;
border-bottom: 1px solid #dddddd;
padding: 1em;
}
.phriction-header a.button {
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;
}