Don't abort on too long notices in Notice::saveActivity

This commit is contained in:
Mikael Nordfeldth 2016-01-05 17:31:09 +01:00
parent 9a75778b29
commit 8ad6b8809a
2 changed files with 12 additions and 20 deletions

View File

@ -131,6 +131,17 @@ class NewnoticeAction extends FormAction
$content = $this->scoped->shortenLinks($content); $content = $this->scoped->shortenLinks($content);
// Reject notice if it is too long (without the HTML)
// Should we do this before or after the upload attachment link? I think before...
if (Notice::contentTooLong($content)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
throw new ClientException(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
'That\'s too long. Maximum notice size is %d characters.',
Notice::maxContent()),
Notice::maxContent()));
}
$upload = null; $upload = null;
try { try {
// throws exception on failure // throws exception on failure
@ -140,15 +151,7 @@ class NewnoticeAction extends FormAction
} }
Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options)); Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
if (Notice::contentTooLong($content)) { // We could check content length here if the URL was added, but I'll just let it slide for now...
$upload->delete();
// TRANS: Client error displayed exceeding the maximum notice length.
// TRANS: %d is the maximum length for a notice.
$this->clientError(sprintf(_m('Maximum notice size is %d character, including attachment URL.',
'Maximum notice size is %d characters, including attachment URL.',
Notice::maxContent()),
Notice::maxContent()));
}
$act->enclosures[] = $upload->getEnclosure(); $act->enclosures[] = $upload->getEnclosure();
} catch (NoUploadedMediaException $e) { } catch (NoUploadedMediaException $e) {

View File

@ -825,17 +825,6 @@ class Notice extends Managed_DataObject
$stored->rendered = $actor->isLocal() ? $content : common_purify($content); $stored->rendered = $actor->isLocal() ? $content : common_purify($content);
$stored->content = common_strip_html($stored->rendered); $stored->content = common_strip_html($stored->rendered);
// Reject notice if it is too long (without the HTML)
// FIXME: Reject if too short (empty) too? But we have to pass the
if ($actor->isLocal() && Notice::contentTooLong($stored->content)) {
// TRANS: Client error displayed when the parameter "status" is missing.
// TRANS: %d is the maximum number of character for a notice.
throw new ClientException(sprintf(_m('That\'s too long. Maximum notice size is %d character.',
'That\'s too long. Maximum notice size is %d characters.',
Notice::maxContent()),
Notice::maxContent()));
}
// Maybe a missing act-time should be fatal if the actor is not local? // Maybe a missing act-time should be fatal if the actor is not local?
if (!empty($act->time)) { if (!empty($act->time)) {
$stored->created = common_sql_date($act->time); $stored->created = common_sql_date($act->time);