1
0
Fork 0
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:
epriestley 2011-11-30 08:45:31 -08:00
parent 9f201ef897
commit 30b578cff6
2 changed files with 31 additions and 13 deletions

View file

@ -22,8 +22,10 @@
class PhabricatorRemarkupRuleMention class PhabricatorRemarkupRuleMention
extends PhutilRemarkupRule { extends PhutilRemarkupRule {
const KEY_RULE_MENTION = 'rule.mention'; const KEY_RULE_MENTION = 'rule.mention';
const KEY_MENTIONED = 'phabricator.mentioned-user-phids'; const KEY_RULE_MENTION_ORIGINAL = 'rule.mention.original';
const KEY_MENTIONED = 'phabricator.mentioned-user-phids';
public function apply($text) { public function apply($text) {
@ -41,13 +43,19 @@ class PhabricatorRemarkupRuleMention
} }
private function markupMention($matches) { private function markupMention($matches) {
$username = strtolower($matches[1]);
$engine = $this->getEngine(); $engine = $this->getEngine();
$token = $engine->storeText(''); $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_key = self::KEY_RULE_MENTION;
$metadata = $engine->getTextMetadata($metadata_key, array()); $metadata = $engine->getTextMetadata($metadata_key, array());
$username = strtolower($matches[1]);
if (empty($metadata[$username])) { if (empty($metadata[$username])) {
$metadata[$username] = array(); $metadata[$username] = array();
} }
@ -67,6 +75,9 @@ class PhabricatorRemarkupRuleMention
return; return;
} }
$original_key = self::KEY_RULE_MENTION_ORIGINAL;
$original = $engine->getTextMetadata($original_key, array());
$usernames = array_keys($metadata); $usernames = array_keys($metadata);
$user_table = new PhabricatorUser(); $user_table = new PhabricatorUser();
$real_user_names = queryfx_all( $real_user_names = queryfx_all(
@ -102,16 +113,22 @@ class PhabricatorRemarkupRuleMention
'title' => $actual_users[$username]['realName'], 'title' => $actual_users[$username]['realName'],
), ),
phutil_escape_html('@'.$username)); phutil_escape_html('@'.$username));
foreach ($tokens as $token) {
$engine->overwriteStoredText($token, $tag);
}
} else { } else {
$tag = phutil_render_tag( // NOTE: The structure here is different from the 'exists' branch,
'span', // because we want to preserve the original text capitalization and it
array( // may differ for each token.
'class' => $class, foreach ($tokens as $token) {
), $tag = phutil_render_tag(
phutil_escape_html('@'.$username)); 'span',
} array(
foreach ($tokens as $token) { 'class' => $class,
$engine->overwriteStoredText($token, $tag); ),
phutil_escape_html('@'.idx($original, $token, $username)));
$engine->overwriteStoredText($token, $tag);
}
} }
} }

View file

@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base'); phutil_require_module('phutil', 'markup/engine/remarkup/markuprule/base');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorRemarkupRuleMention.php'); phutil_require_source('PhabricatorRemarkupRuleMention.php');