[aur-dev] [PATCH 1/2] Remove success message from comment form
To be more flexible with messages, we shouldn't always output this message when a comment has been sent. Moreover, currently it is not displayed due to the POST-Redirect-GET pattern, where the comment parameter is lost after redirection. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/template/pkg_comment_form.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php index 7c16eb7..c450c4b 100644 --- a/web/template/pkg_comment_form.php +++ b/web/template/pkg_comment_form.php @@ -1,10 +1,5 @@ <form action="<?= get_pkgbase_uri($pkgbase_name) ?>" method="post"> <fieldset> -<?php -if (isset($_REQUEST['comment']) && check_token()) { - echo '<p>' . __('Comment has been added.') . '</p>'; -} -?> <div> <input type="hidden" name="action" value="<?= (isset($comment_id)) ? "do_EditComment" : "do_AddComment" ?>" /> <input type="hidden" name="ID" value="<?= intval($base_id) ?>" /> -- 2.5.0
Fixes FS#45870. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/html/pkgbase.php | 3 +-- web/lib/pkgbasefuncs.inc.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index 1581869..bc32e43 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -107,8 +107,7 @@ if (check_token()) { list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users'])); } elseif (current_action("do_AddComment")) { $uid = uid_from_sid($_COOKIE["AURSID"]); - pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']); - $ret = true; + list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']); $fragment = '#news'; } elseif (current_action("do_EditComment")) { list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']); diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index ccab635..677ae6b 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -81,6 +81,10 @@ function pkgbase_comments($base_id, $limit, $include_deleted) { function pkgbase_add_comment($base_id, $uid, $comment) { $dbh = DB::connect(); + if (trim($comment) == '') { + return array(false, __('Comment cannot be empty.')); + } + $q = "INSERT INTO PackageComments "; $q.= "(PackageBaseID, UsersID, Comments, CommentTS) VALUES ("; $q.= intval($base_id) . ", " . $uid . ", "; @@ -102,6 +106,8 @@ function pkgbase_add_comment($base_id, $uid, $comment) { if ($result) { notify(array('comment', $uid, $base_id), $comment); } + + return array(true, __('Comment has been added.')); } /** @@ -860,6 +866,10 @@ function pkgbase_edit_comment($comment) { return array(false, __("Missing comment ID.")); } + if (trim($comment) == '') { + return array(false, __('Comment cannot be empty.')); + } + $dbh = DB::connect(); if (can_edit_comment($comment_id)) { $q = "UPDATE PackageComments "; -- 2.5.0
participants (1)
-
Marcel Korpel