1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

Basic @mentions support

Summary:
Provides basic Remarkup support for @mentions. No application integration yet so
these aren't terribly useful until that happens.

Test Plan:
https://secure.phabricator.com/file/view/PHID-FILE-83d68e7af6085ae928df/

Reviewers: tomo, mroch, jsp
Commenters: tomo
CC: aran, tomo, epriestley
Differential Revision: 517
This commit is contained in:
epriestley 2011-06-24 10:59:57 -07:00
parent b664d67a22
commit 405b05a490
7 changed files with 143 additions and 18 deletions

View file

@ -1057,7 +1057,7 @@ celerity_register_resource_map(array(
),
'phabricator-remarkup-css' =>
array(
'uri' => '/res/774d4078/rsrc/css/core/remarkup.css',
'uri' => '/res/d7e98209/rsrc/css/core/remarkup.css',
'type' => 'css',
'requires' =>
array(
@ -1132,7 +1132,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/2892314d/typeahead.pkg.js',
'type' => 'js',
),
'c2d123fd' =>
'd752b5da' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
@ -1153,7 +1153,7 @@ celerity_register_resource_map(array(
13 => 'phabricator-remarkup-css',
14 => 'syntax-highlighting-css',
),
'uri' => '/res/pkg/c2d123fd/core.pkg.css',
'uri' => '/res/pkg/d752b5da/core.pkg.css',
'type' => 'css',
),
'da416e1c' =>
@ -1225,15 +1225,15 @@ celerity_register_resource_map(array(
),
'reverse' =>
array (
'aphront-crumbs-view-css' => 'c2d123fd',
'aphront-dialog-view-css' => 'c2d123fd',
'aphront-form-view-css' => 'c2d123fd',
'aphront-list-filter-view-css' => 'c2d123fd',
'aphront-panel-view-css' => 'c2d123fd',
'aphront-side-nav-view-css' => 'c2d123fd',
'aphront-table-view-css' => 'c2d123fd',
'aphront-tokenizer-control-css' => 'c2d123fd',
'aphront-typeahead-control-css' => 'c2d123fd',
'aphront-crumbs-view-css' => 'd752b5da',
'aphront-dialog-view-css' => 'd752b5da',
'aphront-form-view-css' => 'd752b5da',
'aphront-list-filter-view-css' => 'd752b5da',
'aphront-panel-view-css' => 'd752b5da',
'aphront-side-nav-view-css' => 'd752b5da',
'aphront-table-view-css' => 'd752b5da',
'aphront-tokenizer-control-css' => 'd752b5da',
'aphront-typeahead-control-css' => 'd752b5da',
'differential-changeset-view-css' => '55967526',
'differential-core-view-css' => '55967526',
'differential-revision-add-comment-css' => '55967526',
@ -1270,13 +1270,13 @@ celerity_register_resource_map(array(
'javelin-util' => 'db95a6d0',
'javelin-vector' => 'db95a6d0',
'javelin-workflow' => 'f1d27e2a',
'phabricator-core-buttons-css' => 'c2d123fd',
'phabricator-core-css' => 'c2d123fd',
'phabricator-directory-css' => 'c2d123fd',
'phabricator-core-buttons-css' => 'd752b5da',
'phabricator-core-css' => 'd752b5da',
'phabricator-directory-css' => 'd752b5da',
'phabricator-keyboard-shortcut' => 'f1d27e2a',
'phabricator-keyboard-shortcut-manager' => 'f1d27e2a',
'phabricator-remarkup-css' => 'c2d123fd',
'phabricator-standard-page-view' => 'c2d123fd',
'syntax-highlighting-css' => 'c2d123fd',
'phabricator-remarkup-css' => 'd752b5da',
'phabricator-standard-page-view' => 'd752b5da',
'syntax-highlighting-css' => 'd752b5da',
),
));

View file

@ -440,6 +440,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleDiffusion' => 'infrastructure/markup/remarkup/markuprule/diffusion',
'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/remarkup/markuprule/imagemacro',
'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest',
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/remarkup/markuprule/mention',
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/remarkup/markuprule/objectname',
'PhabricatorRemarkupRuleProxyImage' => 'infrastructure/markup/remarkup/markuprule/proxyimage',
'PhabricatorRemarkupRuleYoutube' => 'infrastructure/markup/remarkup/markuprule/youtube',
@ -907,6 +908,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleDiffusion' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleManiphest' => 'PhabricatorRemarkupRuleObjectName',
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleProxyImage' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule',

View file

@ -42,6 +42,7 @@ class DifferentialMarkupEngineFactory {
$rules[] = new PhabricatorRemarkupRuleDiffusion();
$rules[] = new PhabricatorRemarkupRuleManiphest();
$rules[] = new PhabricatorRemarkupRuleImageMacro();
$rules[] = new PhabricatorRemarkupRuleMention();
$custom_rule_classes =
PhabricatorEnv::getEnvConfig('differential.custom-remarkup-rules');

View file

@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/diffusion');
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/imagemacro');
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/proxyimage');
phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/youtube');

View file

@ -0,0 +1,93 @@
<?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 PhabricatorRemarkupRuleMention
extends PhutilRemarkupRule {
private $actualUsers;
public function apply($text) {
// NOTE: Negative lookahead for period prevents us from picking up email
// addresses, while allowing constructs like "@tomo, lol".
$regexp = '/@([a-zA-Z0-9]+)\b(?![.])/';
$matches = null;
$ok = preg_match_all($regexp, $text, $matches);
if (!$ok) {
// No mentions in this text.
return $text;
}
$usernames = $matches[1];
// TODO: This is a little sketchy perf-wise. Once APC comes up, it is an
// ideal candidate to back with an APC cache.
$user_table = new PhabricatorUser();
$real_user_names = queryfx_all(
$user_table->establishConnection('r'),
'SELECT username, phid, realName FROM %T WHERE username IN (%Ls)',
$user_table->getTableName(),
$usernames);
foreach ($real_user_names as $row) {
$this->actualUsers[strtolower($row['username'])] = $row;
}
return preg_replace_callback(
$regexp,
array($this, 'markupMention'),
$text);
}
public function markupMention($matches) {
$username = strtolower($matches[1]);
$exists = isset($this->actualUsers[$username]);
$real = $this->actualUsers[$username]['realName'];
$class = $exists
? 'phabricator-remarkup-mention-exists'
: 'phabricator-remarkup-mention-unknown';
if ($exists) {
$tag = phutil_render_tag(
'a',
array(
'class' => $class,
'href' => '/p/'.$username.'/',
'target' => '_blank',
'title' => $real,
),
phutil_escape_html('@'.$username));
} else {
$tag = phutil_render_tag(
'span',
array(
'class' => $class,
),
phutil_escape_html('@'.$username));
}
return $this->getEngine()->storeText($tag);
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/people/storage/user');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base');
phutil_require_source('PhabricatorRemarkupRuleMention.php');

View file

@ -59,3 +59,15 @@
max-width: 640px;
max-height: 640px;
}
.phabricator-remarkup-mention-exists {
font-weight: bold;
padding: 0 .25em;
background: #aaffaa;
}
.aphront-panel-preview .phabricator-remarkup-mention-unknown {
font-weight: bold;
padding: 0 .25em;
background: #ffaaaa;
}