mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Preserve original case in @mentions which whiff
Summary: See T632. When we miss a @mention, preserve the original case. This approach is slightly unwieldy, but preserves backward compatibility (remarkup is cached in Differential and Maniphest). Test Plan: https://secure.phabricator.com/file/view/PHID-FILE-u7z5j73dxrr4vuwkdcy3/ Reviewers: aran, btrahan Reviewed By: aran CC: aran, epriestley Differential Revision: 1141
This commit is contained in:
parent
9f201ef897
commit
30b578cff6
2 changed files with 31 additions and 13 deletions
|
@ -22,8 +22,10 @@
|
|||
class PhabricatorRemarkupRuleMention
|
||||
extends PhutilRemarkupRule {
|
||||
|
||||
const KEY_RULE_MENTION = 'rule.mention';
|
||||
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
|
||||
const KEY_RULE_MENTION = 'rule.mention';
|
||||
const KEY_RULE_MENTION_ORIGINAL = 'rule.mention.original';
|
||||
|
||||
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
|
||||
|
||||
public function apply($text) {
|
||||
|
||||
|
@ -41,13 +43,19 @@ class PhabricatorRemarkupRuleMention
|
|||
}
|
||||
|
||||
private function markupMention($matches) {
|
||||
$username = strtolower($matches[1]);
|
||||
$engine = $this->getEngine();
|
||||
|
||||
$token = $engine->storeText('');
|
||||
|
||||
// Store the original text exactly so we can preserve casing if it doesn't
|
||||
// resolve into a username.
|
||||
$original_key = self::KEY_RULE_MENTION_ORIGINAL;
|
||||
$original = $engine->getTextMetadata($original_key, array());
|
||||
$original[$token] = $matches[1];
|
||||
$engine->setTextMetadata($original_key, $original);
|
||||
|
||||
$metadata_key = self::KEY_RULE_MENTION;
|
||||
$metadata = $engine->getTextMetadata($metadata_key, array());
|
||||
$username = strtolower($matches[1]);
|
||||
if (empty($metadata[$username])) {
|
||||
$metadata[$username] = array();
|
||||
}
|
||||
|
@ -67,6 +75,9 @@ class PhabricatorRemarkupRuleMention
|
|||
return;
|
||||
}
|
||||
|
||||
$original_key = self::KEY_RULE_MENTION_ORIGINAL;
|
||||
$original = $engine->getTextMetadata($original_key, array());
|
||||
|
||||
$usernames = array_keys($metadata);
|
||||
$user_table = new PhabricatorUser();
|
||||
$real_user_names = queryfx_all(
|
||||
|
@ -102,16 +113,22 @@ class PhabricatorRemarkupRuleMention
|
|||
'title' => $actual_users[$username]['realName'],
|
||||
),
|
||||
phutil_escape_html('@'.$username));
|
||||
foreach ($tokens as $token) {
|
||||
$engine->overwriteStoredText($token, $tag);
|
||||
}
|
||||
} else {
|
||||
$tag = phutil_render_tag(
|
||||
'span',
|
||||
array(
|
||||
'class' => $class,
|
||||
),
|
||||
phutil_escape_html('@'.$username));
|
||||
}
|
||||
foreach ($tokens as $token) {
|
||||
$engine->overwriteStoredText($token, $tag);
|
||||
// NOTE: The structure here is different from the 'exists' branch,
|
||||
// because we want to preserve the original text capitalization and it
|
||||
// may differ for each token.
|
||||
foreach ($tokens as $token) {
|
||||
$tag = phutil_render_tag(
|
||||
'span',
|
||||
array(
|
||||
'class' => $class,
|
||||
),
|
||||
phutil_escape_html('@'.idx($original, $token, $username)));
|
||||
$engine->overwriteStoredText($token, $tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'storage/queryfx');
|
|||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorRemarkupRuleMention.php');
|
||||
|
|
Loading…
Reference in a new issue