mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
phutil_utf8_shorten => PhutilUTF8StringTruncator
Summary: Ref T3307. Only one I thought was tricky was Excel; I went with bytes there like it was email. Test Plan: played around on a few endpoints but mostly thought carefully Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T3307 Differential Revision: https://secure.phabricator.com/D10392
This commit is contained in:
parent
482784b9b2
commit
b93bc7e479
23 changed files with 76 additions and 28 deletions
|
@ -214,8 +214,9 @@ final class PhabricatorCalendarEventSearchEngine
|
|||
->setBarColor($color)
|
||||
->addByline(pht('Creator: %s', $creator_handle->renderLink()))
|
||||
->addAttribute(pht('From %s to %s', $from, $to))
|
||||
->addAttribute(
|
||||
phutil_utf8_shorten($event->getDescription(), 64));
|
||||
->addAttribute(id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(64)
|
||||
->truncateString($event->getDescription()));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,9 @@ final class PhabricatorChatLogChannelLogController
|
|||
$out = array();
|
||||
foreach ($blocks as $block) {
|
||||
$author = $block['author'];
|
||||
$author = phutil_utf8_shorten($author, 18);
|
||||
$author = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(18)
|
||||
->truncateString($author);
|
||||
$author = phutil_tag('td', array('class' => 'author'), $author);
|
||||
|
||||
$href = $uri->alter('at', $block['id']);
|
||||
|
|
|
@ -59,9 +59,9 @@ final class ConduitConnectConduitAPIMethod extends ConduitAPIMethod {
|
|||
$client = $request->getValue('client');
|
||||
$client_version = (int)$request->getValue('clientVersion');
|
||||
$client_description = (string)$request->getValue('clientDescription');
|
||||
// TODO: This should be character-oriented, not display-oriented.
|
||||
// See T3307.
|
||||
$client_description = phutil_utf8_shorten($client_description, 255);
|
||||
$client_description = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumCodepoints(255)
|
||||
->truncateString($client_description);
|
||||
$username = (string)$request->getValue('user');
|
||||
|
||||
// Log the connection, regardless of the outcome of checks below.
|
||||
|
|
|
@ -20,7 +20,9 @@ final class ConpherenceFileWidgetView extends ConpherenceWidgetView {
|
|||
'');
|
||||
$file_view = id(new PhabricatorFileLinkView())
|
||||
->setFilePHID($file->getPHID())
|
||||
->setFileName(phutil_utf8_shorten($file->getName(), 28))
|
||||
->setFileName(id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(28)
|
||||
->truncateString($file->getName()))
|
||||
->setFileViewable($file->isViewableImage())
|
||||
->setFileViewURI($file->getBestURI())
|
||||
->setCustomClass('file-title');
|
||||
|
|
|
@ -62,8 +62,10 @@ final class DifferentialDiffViewController extends DifferentialController {
|
|||
array(
|
||||
'value' => $revision->getID(),
|
||||
),
|
||||
phutil_utf8_shorten(
|
||||
'D'.$revision->getID().' '.$revision->getTitle(), 128));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString(
|
||||
'D'.$revision->getID().' '.$revision->getTitle()));
|
||||
}
|
||||
$select[] = hsprintf('</optgroup>');
|
||||
}
|
||||
|
|
|
@ -69,7 +69,9 @@ final class DifferentialHovercardEventListener
|
|||
|
||||
if ($rev->getSummary()) {
|
||||
$hovercard->addField(pht('Summary'),
|
||||
phutil_utf8_shorten($rev->getSummary(), 120));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(120)
|
||||
->truncateString($rev->getSummary()));
|
||||
}
|
||||
|
||||
$hovercard->addTag(
|
||||
|
|
|
@ -141,7 +141,11 @@ final class DifferentialCommitMessageParser {
|
|||
if (isset($fields[$key_title])) {
|
||||
$terminal = '...';
|
||||
$title = $fields[$key_title];
|
||||
$short = phutil_utf8_shorten($title, 250, $terminal);
|
||||
$short = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(250)
|
||||
->setTerminator($terminal)
|
||||
->truncateString($title);
|
||||
|
||||
if ($short != $title) {
|
||||
|
||||
// If we shortened the title, split the rest into the summary, so
|
||||
|
|
|
@ -77,7 +77,9 @@ final class DifferentialLocalCommitsView extends AphrontView {
|
|||
$message = idx($commit, 'message');
|
||||
|
||||
$summary = idx($commit, 'summary');
|
||||
$summary = phutil_utf8_shorten($summary, 80);
|
||||
$summary = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(80)
|
||||
->truncateString($summary);
|
||||
|
||||
$view = new AphrontMoreView();
|
||||
$view->setSome($summary);
|
||||
|
|
|
@ -684,7 +684,10 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
|
|||
'size' => 600,
|
||||
),
|
||||
),
|
||||
phutil_utf8_shorten($line['commit'], 9, ''));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(9)
|
||||
->setTerminator('')
|
||||
->truncateString($line['commit']));
|
||||
|
||||
$revision_id = null;
|
||||
if (idx($commits, $commit)) {
|
||||
|
|
|
@ -378,7 +378,9 @@ abstract class PhabricatorFeedStory
|
|||
|
||||
final protected function renderSummary($text, $len = 128) {
|
||||
if ($len) {
|
||||
$text = phutil_utf8_shorten($text, $len);
|
||||
$text = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs($len)
|
||||
->truncateString($text);
|
||||
}
|
||||
switch ($this->getRenderingTarget()) {
|
||||
case PhabricatorApplicationTransaction::TARGET_HTML:
|
||||
|
|
|
@ -196,7 +196,9 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
$log_source,
|
||||
$log_type) {
|
||||
|
||||
$log_source = phutil_utf8_shorten($log_source, 250);
|
||||
$log_source = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumCodepoints(250)
|
||||
->truncateString($log_source);
|
||||
|
||||
$log = HarbormasterBuildLog::initializeNewBuildLog($build_target)
|
||||
->setLogSource($log_source)
|
||||
|
|
|
@ -52,7 +52,7 @@ final class HeraldObjectTranscript {
|
|||
if (strlen($value) <= $length) {
|
||||
return $value;
|
||||
} else {
|
||||
// NOTE: phutil_utf8_shorten() has huge runtime for giant strings.
|
||||
// NOTE: PhutilUTF8StringTruncator has huge runtime for giant strings.
|
||||
return phutil_utf8ize(substr($value, 0, $length)."\n<...>");
|
||||
}
|
||||
} else if (is_array($value)) {
|
||||
|
|
|
@ -104,7 +104,9 @@ final class ManiphestExcelDefaultFormat extends ManiphestExcelFormat {
|
|||
$task->getTitle(),
|
||||
$projects,
|
||||
PhabricatorEnv::getProductionURI('/T'.$task->getID()),
|
||||
phutil_utf8_shorten($task->getDescription(), 512),
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumBytes(512)
|
||||
->truncateString($task->getDescription()),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -563,7 +563,9 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
|||
$body = idx($params, 'body', '');
|
||||
$max = PhabricatorEnv::getEnvConfig('metamta.email-body-limit');
|
||||
if (strlen($body) > $max) {
|
||||
$body = phutil_utf8_shorten($body, $max);
|
||||
$body = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumBytes($max)
|
||||
->truncateString($body);
|
||||
$body .= "\n";
|
||||
$body .= pht('(This email was truncated at %d bytes.)', $max);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,9 @@ final class PhabricatorPeopleHovercardEventListener
|
|||
|
||||
if ($profile->getBlurb()) {
|
||||
$hovercard->addField(pht('Blurb'),
|
||||
phutil_utf8_shorten($profile->getBlurb(), 120));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(120)
|
||||
->truncateString($profile->getBlurb()));
|
||||
}
|
||||
|
||||
$event->setValue('hovercard', $hovercard);
|
||||
|
|
|
@ -90,7 +90,9 @@ final class PhameCreatePostConduitAPIMethod extends PhameConduitAPIMethod {
|
|||
$post->setTitle($title);
|
||||
$phame_title = $request->getValue(
|
||||
'phameTitle',
|
||||
phutil_utf8_shorten($title, 64));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumCodepoints(64)
|
||||
->truncateString($title));
|
||||
$post->setPhameTitle(PhabricatorSlug::normalize($phame_title));
|
||||
$post->setBody($body);
|
||||
$post->save();
|
||||
|
|
|
@ -297,7 +297,9 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
|||
|
||||
if ($text) {
|
||||
return phutil_escape_html_newlines(
|
||||
phutil_utf8_shorten($text, 128));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($text));
|
||||
}
|
||||
|
||||
return parent::getBodyForFeed($story);
|
||||
|
|
|
@ -264,6 +264,9 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
|
|||
}
|
||||
|
||||
if ($feed_action) {
|
||||
$content = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(140)
|
||||
->truncateString($new_content->getContent());
|
||||
id(new PhabricatorFeedStoryPublisher())
|
||||
->setRelatedPHIDs($related_phids)
|
||||
->setStoryAuthorPHID($this->getActor()->getPHID())
|
||||
|
@ -273,7 +276,7 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
|
|||
array(
|
||||
'phid' => $document->getPHID(),
|
||||
'action' => $feed_action,
|
||||
'content' => phutil_utf8_shorten($new_content->getContent(), 140),
|
||||
'content' => $content,
|
||||
'project' => $project_phid,
|
||||
'movedFromPHID' => $this->fromDocumentPHID,
|
||||
))
|
||||
|
|
|
@ -71,7 +71,9 @@ final class PonderAnswerTransaction
|
|||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_CONTENT:
|
||||
return phutil_escape_html_newlines(
|
||||
phutil_utf8_shorten($new, 128));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($new));
|
||||
break;
|
||||
}
|
||||
return parent::getBodyForFeed($story);
|
||||
|
|
|
@ -252,14 +252,18 @@ final class PonderQuestionTransaction
|
|||
if ($old === null) {
|
||||
$question = $story->getObject($this->getObjectPHID());
|
||||
return phutil_escape_html_newlines(
|
||||
phutil_utf8_shorten($question->getContent(), 128));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($question->getContent()));
|
||||
}
|
||||
break;
|
||||
case self::TYPE_ANSWERS:
|
||||
$answer = $this->getNewAnswerObject($story);
|
||||
if ($answer) {
|
||||
return phutil_escape_html_newlines(
|
||||
phutil_utf8_shorten($answer->getContent(), 128));
|
||||
id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(128)
|
||||
->truncateString($answer->getContent()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@ final class PhabricatorRepositoryCommitData extends PhabricatorRepositoryDAO {
|
|||
public static function summarizeCommitMessage($message) {
|
||||
$summary = phutil_split_lines($message, $retain_endings = false);
|
||||
$summary = head($summary);
|
||||
$summary = phutil_utf8_shorten($summary, self::SUMMARY_MAX_LENGTH);
|
||||
$summary = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumCodepoints(self::SUMMARY_MAX_LENGTH)
|
||||
->truncateString($summary);
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
|
|
@ -155,7 +155,9 @@ final class PhabricatorSlowvoteSearchEngine
|
|||
|
||||
$description = $poll->getDescription();
|
||||
if (strlen($description)) {
|
||||
$item->addAttribute(phutil_utf8_shorten($poll->getDescription(), 120));
|
||||
$item->addAttribute(id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(120)
|
||||
->truncateString($poll->getDescription()));
|
||||
}
|
||||
|
||||
if ($author) {
|
||||
|
|
|
@ -58,9 +58,12 @@ final class AphrontFormPolicyControl extends AphrontFormControl {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
$policy_short_name = id(new PhutilUTF8StringTruncator())
|
||||
->setMaximumGlyphs(28)
|
||||
->truncateString($policy->getName());
|
||||
|
||||
$options[$policy->getType()][$policy->getPHID()] = array(
|
||||
'name' => phutil_utf8_shorten($policy->getName(), 28),
|
||||
'name' => $policy_short_name,
|
||||
'full' => $policy->getName(),
|
||||
'icon' => $policy->getIcon(),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue