[aur-dev] [PATCH 0/6] Add comment edit functionality
Implements FS#34690. Marcel Korpel (6): Add comment edit icon and form Edit a comment in the backend Show dateline when a comment is edited or deleted Only autofocus search field on the package search page Add IDs to comments Jump to comment after editing schema/aur-schema.sql | 2 ++ web/html/commentedit.php | 21 +++++++++++++ web/html/css/aurweb.css | 19 ++++++++++-- web/html/images/pencil.min.svg | 3 ++ web/html/images/pencil.svg | 55 ++++++++++++++++++++++++++++++++++ web/html/index.php | 4 +++ web/html/pkgbase.php | 14 +++++---- web/lib/credentials.inc.php | 2 ++ web/lib/pkgbasefuncs.inc.php | 62 ++++++++++++++++++++++++++++++++++++--- web/lib/pkgfuncs.inc.php | 40 +++++++++++++++++++++++++ web/template/pkg_comment_form.php | 10 +++++-- web/template/pkg_comments.php | 32 +++++++++++++++++--- web/template/pkg_search_form.php | 2 +- 13 files changed, 246 insertions(+), 20 deletions(-) create mode 100644 web/html/commentedit.php create mode 100644 web/html/images/pencil.min.svg create mode 100644 web/html/images/pencil.svg -- 2.4.5
Shows an icon next to the comment deletion icon, which leads to a comment edit form. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/html/commentedit.php | 21 +++++++++++++++ web/html/css/aurweb.css | 13 ++++++--- web/html/images/pencil.min.svg | 3 +++ web/html/images/pencil.svg | 55 +++++++++++++++++++++++++++++++++++++++ web/html/index.php | 4 +++ web/html/pkgbase.php | 4 +-- web/lib/credentials.inc.php | 2 ++ web/lib/pkgbasefuncs.inc.php | 19 ++++++++++++++ web/lib/pkgfuncs.inc.php | 14 ++++++++++ web/template/pkg_comment_form.php | 10 ++++--- web/template/pkg_comments.php | 3 +++ 11 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 web/html/commentedit.php create mode 100644 web/html/images/pencil.min.svg create mode 100644 web/html/images/pencil.svg diff --git a/web/html/commentedit.php b/web/html/commentedit.php new file mode 100644 index 0000000..a8b1819 --- /dev/null +++ b/web/html/commentedit.php @@ -0,0 +1,21 @@ +<?php + +set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); + +include_once("aur.inc.php"); +include_once("pkgbasefuncs.inc.php"); + +set_lang(); +check_sid(); + +$comment_id = intval($_REQUEST['comment_id']); +$comment = pkgbase_get_comment($comment_id); + +if (!isset($base_id) || !has_credential(CRED_COMMENT_EDIT, array(pkgbase_maintainer_uid($base_id))) || is_null($comment)) { + header('Location: /'); + exit(); +} + +html_header(__("Edit comment")); +include('pkg_comment_form.php'); +html_footer(AURWEB_VERSION); diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css index adc02bb..b5ca1f3 100644 --- a/web/html/css/aurweb.css +++ b/web/html/css/aurweb.css @@ -96,17 +96,24 @@ color: #999; } -.delete-comment-form { +.delete-comment-form, .edit-comment { float: right; + margin-left: 8px; } -.delete-comment { +.edit-comment { + height: 11px; + position: relative; + top: 1px; +} + +.delete-comment, .edit-comment { -webkit-filter: grayscale(100%); filter: grayscale(100%); opacity: 0.6; } -.delete-comment:hover { +.delete-comment:hover, .edit-comment:hover { -webkit-filter: none; filter: none; opacity: 1; diff --git a/web/html/images/pencil.min.svg b/web/html/images/pencil.min.svg new file mode 100644 index 0000000..06125ae --- /dev/null +++ b/web/html/images/pencil.min.svg @@ -0,0 +1,3 @@ +<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="8" width="8" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox="0 0 8 8"> +<path fill="#36a" d="m6 0l-1 1 2 2 1-1-2-2zm-2 2l-4 4v2h2l4-4-2-2z"/> +</svg> diff --git a/web/html/images/pencil.svg b/web/html/images/pencil.svg new file mode 100644 index 0000000..91f0899 --- /dev/null +++ b/web/html/images/pencil.svg @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="8" + height="8" + viewBox="0 0 8 8" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + sodipodi:docname="pencil-arch.svg"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs8" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="659" + inkscape:window-height="480" + id="namedview6" + showgrid="false" + inkscape:zoom="29.5" + inkscape:cx="4" + inkscape:cy="4" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="0" + inkscape:current-layer="svg2" /> + <path + d="M6 0l-1 1 2 2 1-1-2-2zm-2 2l-4 4v2h2l4-4-2-2z" + id="path4" + style="fill:#3366aa;fill-opacity:1" /> +</svg> diff --git a/web/html/index.php b/web/html/index.php index 2d5f2a9..175a533 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -89,6 +89,9 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) { case "comaintainers": include('comaintainers.php'); return; + case "edit-comment": + include('commentedit.php'); + return; default: header("HTTP/1.0 404 Not Found"); include "./404.php"; @@ -174,6 +177,7 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) { readfile("./$path"); break; case "/images/x.min.svg": + case "/images/pencil.min.svg": header("Content-Type: image/svg+xml"); readfile("./$path"); break; diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index 5179d0c..f908029 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -104,9 +104,7 @@ if (check_token()) { list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason'], $_POST['comments']); } elseif (current_action("do_EditComaintainers")) { list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users'])); - } - - if (isset($_REQUEST['comment'])) { + } elseif (current_action("do_AddComment")) { $uid = uid_from_sid($_COOKIE["AURSID"]); pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']); $ret = true; diff --git a/web/lib/credentials.inc.php b/web/lib/credentials.inc.php index cf1fcca..648d78c 100644 --- a/web/lib/credentials.inc.php +++ b/web/lib/credentials.inc.php @@ -7,6 +7,7 @@ define("CRED_ACCOUNT_LAST_LOGIN", 4); define("CRED_ACCOUNT_SEARCH", 5); define("CRED_COMMENT_DELETE", 6); define("CRED_COMMENT_VIEW_DELETED", 22); +define("CRED_COMMENT_EDIT", 25); define("CRED_PKGBASE_ADOPT", 7); define("CRED_PKGBASE_SET_KEYWORDS", 8); define("CRED_PKGBASE_DELETE", 9); @@ -58,6 +59,7 @@ function has_credential($credential, $approved_users=array()) { case CRED_ACCOUNT_SEARCH: case CRED_COMMENT_DELETE: case CRED_COMMENT_VIEW_DELETED: + case CRED_COMMENT_EDIT: case CRED_PKGBASE_ADOPT: case CRED_PKGBASE_SET_KEYWORDS: case CRED_PKGBASE_DELETE: diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 5d191eb..09282e9 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -102,6 +102,25 @@ function pkgbase_add_comment($base_id, $uid, $comment) { } /** + * Get a package comment + * + * @param int $comment_id The ID of the comment + * + * @return string The comment + */ +function pkgbase_get_comment($comment_id) { + $dbh = DB::connect(); + $q = "SELECT Comments FROM PackageComments "; + $q.= "WHERE ID = " . $comment_id; + $result = $dbh->query($q); + if (!$result) { + return null; + } + + return $result->fetchColumn(0); +} + +/** * Get a list of all packages a logged-in user has voted for * * @param string $sid The session ID of the visitor diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 110290b..7cb2ffc 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -43,6 +43,20 @@ function can_delete_comment_array($comment) { } /** + * Determine if the user can edit a specific package comment using an array + * + * Only the comment submitter, Trusted Users, and Developers can edit + * comments. This function is used for the frontend side of comment editing. + * + * @param array $comment All database information relating a specific comment + * + * @return bool True if the user can edit the comment, otherwise false + */ +function can_edit_comment_array($comment) { + return has_credential(CRED_COMMENT_EDIT, array($comment['UsersID'])); +} + +/** * Check to see if the package name already exists in the database * * @param string $name The package name to check diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php index 8a74dc1..16a92b1 100644 --- a/web/template/pkg_comment_form.php +++ b/web/template/pkg_comment_form.php @@ -1,5 +1,5 @@ <div id="generic-form" class="box"> - <h2><?= __("Add Comment"); ?></h2> + <h2><?= (isset($comment_id)) ? __('Edit comment for: %s', htmlspecialchars($pkgbase_name)) : __("Add Comment"); ?></h2> <form action="<?= get_pkgbase_uri($pkgbase_name) ?>" method="post"> <fieldset> <?php @@ -8,14 +8,18 @@ if (isset($_REQUEST['comment']) && check_token()) { } ?> <div> + <input type="hidden" name="action" value="<?= (isset($comment_id)) ? "do_EditComment" : "do_AddComment" ?>" /> <input type="hidden" name="ID" value="<?= intval($base_id) ?>" /> + <?php if (isset($comment_id)): ?> + <input type="hidden" name="comment_id" value="<?= $comment_id ?>" /> + <?php endif; ?> <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" /> </div> <p> - <textarea id="id_comment" name="comment" cols="80" rows="10"></textarea> + <textarea id="id_comment" name="comment" cols="80" rows="10"><?= (isset($comment_id)) ? htmlspecialchars($comment) : "" ?></textarea> </p> <p> - <input type="submit" value="<?= __("Add Comment") ?>" /> + <input type="submit" value="<?= (isset($comment_id)) ? __("Save") : __("Add Comment") ?>" /> </p> </fieldset> </form> diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index 03a6581..6cc9555 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -39,6 +39,9 @@ $count = pkgbase_comments_count($base_id, $include_deleted); </fieldset> </form> <?php endif; ?> + <?php if (!$row['DelUsersID'] && can_edit_comment_array($row)): ?> + <a href="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name) . 'edit-comment/?comment_id=' . $row['ID'], ENT_QUOTES) ?>" class="edit-comment" title="<?= __('Edit comment') ?>"><img src="/images/pencil.min.svg" alt="<?= __('Edit comment') ?>" width="11" height="11"></a> + <?php endif; ?> </h4> <div class="article-content<?php if ($row['DelUsersID']): ?> comment-deleted<?php endif; ?>"> <p> -- 2.4.5
On Fri, 10 Jul 2015 at 16:24:03, Marcel Korpel wrote:
[...] +function pkgbase_get_comment($comment_id) {
Should this function really be called pkgbase_get_comment()? It does not expect a package base ID parameter which is an indication that this should rather be called comment_by_id() or similar.
+ $dbh = DB::connect(); + $q = "SELECT Comments FROM PackageComments "; + $q.= "WHERE ID = " . $comment_id; [...]
Please explicitly cast into an integer here (even if the called already does that). Looks good otherwise, thanks!
In the backend I created two new actions, do_AddComment and do_EditComment. When editing or deleting a comment, a timestamp is added. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- schema/aur-schema.sql | 2 ++ web/html/pkgbase.php | 2 ++ web/lib/pkgbasefuncs.inc.php | 34 +++++++++++++++++++++++++++++++++- web/lib/pkgfuncs.inc.php | 26 ++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql index 594a804..3aef7a3 100644 --- a/schema/aur-schema.sql +++ b/schema/aur-schema.sql @@ -254,6 +254,8 @@ CREATE TABLE PackageComments ( UsersID INTEGER UNSIGNED NULL DEFAULT NULL, Comments TEXT NOT NULL DEFAULT '', CommentTS BIGINT UNSIGNED NOT NULL DEFAULT 0, + EditedTS BIGINT UNSIGNED NULL DEFAULT NULL, + EditedUsersID INTEGER UNSIGNED NULL DEFAULT NULL, DelUsersID INTEGER UNSIGNED NULL DEFAULT NULL, PRIMARY KEY (ID), INDEX (UsersID), diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index f908029..5886f71 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -108,6 +108,8 @@ if (check_token()) { $uid = uid_from_sid($_COOKIE["AURSID"]); pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']); $ret = true; + } elseif (current_action("do_EditComment")) { + list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']); } if ($ret) { diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 09282e9..85e38cd 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -849,7 +849,8 @@ function pkgbase_delete_comment() { $dbh = DB::connect(); if (can_delete_comment($comment_id)) { $q = "UPDATE PackageComments "; - $q.= "SET DelUsersID = ".$uid." "; + $q.= "SET DelUsersID = ".$uid.", "; + $q.= "EditedTS = UNIX_TIMESTAMP() "; $q.= "WHERE ID = ".intval($comment_id); $dbh->exec($q); return array(true, __("Comment has been deleted.")); @@ -859,6 +860,37 @@ function pkgbase_delete_comment() { } /** + * Edit a package comment + * + * @return array Tuple of success/failure indicator and error message + */ +function pkgbase_edit_comment($comment) { + $uid = uid_from_sid($_COOKIE["AURSID"]); + if (!$uid) { + return array(false, __("You must be logged in before you can edit package information.")); + } + + if (isset($_POST["comment_id"])) { + $comment_id = $_POST["comment_id"]; + } else { + return array(false, __("Missing comment ID.")); + } + + $dbh = DB::connect(); + if (can_edit_comment($comment_id)) { + $q = "UPDATE PackageComments "; + $q.= "SET EditedUsersID = ".$uid.", "; + $q.= "Comments = ".$dbh->quote($comment).", "; + $q.= "EditedTS = UNIX_TIMESTAMP() "; + $q.= "WHERE ID = ".intval($comment_id); + $dbh->exec($q); + return array(true, __("Comment has been edited.")); + } else { + return array(false, __("You are not allowed to edit this comment.")); + } +} + +/** * Get a list of package base keywords * * @param int $base_id The package base ID to retrieve the keywords for diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 7cb2ffc..de57c3e 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -43,6 +43,32 @@ function can_delete_comment_array($comment) { } /** + * Determine if the user can edit a specific package comment + * + * Only the comment submitter, Trusted Users, and Developers can edit + * comments. This function is used for the backend side of comment editing. + * + * @param string $comment_id The comment ID in the database + * + * @return bool True if the user can edit the comment, otherwise false + */ +function can_edit_comment($comment_id=0) { + $dbh = DB::connect(); + + $q = "SELECT UsersID FROM PackageComments "; + $q.= "WHERE ID = " . intval($comment_id); + $result = $dbh->query($q); + + if (!$result) { + return false; + } + + $uid = $result->fetch(PDO::FETCH_COLUMN, 0); + + return has_credential(CRED_COMMENT_EDIT, array($uid)); +} + +/** * Determine if the user can edit a specific package comment using an array * * Only the comment submitter, Trusted Users, and Developers can edit -- 2.4.5
Also, in pkg_comments.php, always use htmlspecialchars when outputting user names. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/html/css/aurweb.css | 6 ++++++ web/lib/pkgbasefuncs.inc.php | 9 ++++++--- web/template/pkg_comments.php | 27 ++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css index b5ca1f3..bad5f00 100644 --- a/web/html/css/aurweb.css +++ b/web/html/css/aurweb.css @@ -96,6 +96,12 @@ color: #999; } +.edited { + font-size: 0.9em; + font-style: italic; + color: #666; +} + .delete-comment-form, .edit-comment { float: right; margin-left: 8px; diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 85e38cd..44a80b5 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -47,9 +47,12 @@ function pkgbase_comments($base_id, $limit, $include_deleted) { } $dbh = DB::connect(); - $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, "; - $q.= "CommentTS, DelUsersID FROM PackageComments LEFT JOIN Users "; - $q.= "ON PackageComments.UsersID = Users.ID "; + $q = "SELECT PackageComments.ID, A.UserName AS UserName, UsersID, Comments, "; + $q.= "CommentTS, EditedTS, B.UserName AS EditUserName, "; + $q.= "DelUsersID, C.UserName AS DelUserName FROM PackageComments "; + $q.= "LEFT JOIN Users A ON PackageComments.UsersID = A.ID "; + $q.= "LEFT JOIN Users B ON PackageComments.EditedUsersID = B.ID "; + $q.= "LEFT JOIN Users C ON PackageComments.DelUsersID = C.ID "; $q.= "WHERE PackageBaseID = " . $base_id . " "; if (!$include_deleted) { $q.= "AND DelUsersID IS NULL "; diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index 6cc9555..380c858 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -16,9 +16,21 @@ $count = pkgbase_comments_count($base_id, $include_deleted); </h3> <?php while (list($indx, $row) = each($comments)): ?> - <?php if ($row['UserName'] && $SID): - $row['UserName'] = "<a href=\"" . get_user_uri($row['UserName']) . "\">{$row['UserName']}</a>"; - endif; ?> + <?php if ($row['UserName'] && $SID) { + $row['UserName'] = '<a href="' . get_user_uri($row['UserName']) . '">' . htmlspecialchars($row['UserName']) . '</a>'; + } else { + $row['UserName'] = htmlspecialchars($row['UserName']); + } + if ($row['DelUserName'] && $SID) { + $row['DelUserName'] = '<a href="' . get_user_uri($row['DelUserName']) . '">' . htmlspecialchars($row['DelUserName']) . '</a>'; + } else { + $row['DelUserName'] = htmlspecialchars($row['DelUserName']); + } + if ($row['EditUserName'] && $SID) { + $row['EditUserName'] = '<a href="' . get_user_uri($row['EditUserName']) . '">' . htmlspecialchars($row['EditUserName']) . '</a>'; + } else { + $row['EditUserName'] = htmlspecialchars($row['EditUserName']); + } ?> <h4<?php if ($row['DelUsersID']): ?> class="comment-deleted"<?php endif; ?>> <?php if ($row['UserName']): ?> <?= __('%s commented', $row['UserName']) ?> @@ -47,6 +59,15 @@ $count = pkgbase_comments_count($base_id, $include_deleted); <p> <?= parse_comment($row['Comments']) ?> </p> + <?php if ($row['EditedTS']): ?> + <p class="edited"> + <?php if ($row['DelUsersID']) { + echo __('Deleted %s by %s', gmdate('Y-m-d H:i', $row['EditedTS']), $row['DelUserName']); + } else { + echo __('Last edited %s by %s', gmdate('Y-m-d H:i', $row['EditedTS']), $row['EditUserName']); + }?> + </p> + <?php endif; ?> </div> <?php endwhile; ?> </div> -- 2.4.5
On Fri, 10 Jul 2015 at 16:24:05, Marcel Korpel wrote:
[...] - <?php if ($row['UserName'] && $SID): - $row['UserName'] = "<a href=\"" . get_user_uri($row['UserName']) . "\">{$row['UserName']}</a>"; - endif; ?> + <?php if ($row['UserName'] && $SID) { + $row['UserName'] = '<a href="' . get_user_uri($row['UserName']) . '">' . htmlspecialchars($row['UserName']) . '</a>'; + } else { + $row['UserName'] = htmlspecialchars($row['UserName']); + } + if ($row['DelUserName'] && $SID) { + $row['DelUserName'] = '<a href="' . get_user_uri($row['DelUserName']) . '">' . htmlspecialchars($row['DelUserName']) . '</a>'; + } else { + $row['DelUserName'] = htmlspecialchars($row['DelUserName']); + } + if ($row['EditUserName'] && $SID) { + $row['EditUserName'] = '<a href="' . get_user_uri($row['EditUserName']) . '">' . htmlspecialchars($row['EditUserName']) . '</a>'; + } else { + $row['EditUserName'] = htmlspecialchars($row['EditUserName']); + } ?> [...]
Can we use html_format_username() or a similar helper function here?
This needs to be disabled on package pages to be able to add a URL fragment after comment editing. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/template/pkg_search_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php index 2d03cfa..404d16e 100644 --- a/web/template/pkg_search_form.php +++ b/web/template/pkg_search_form.php @@ -57,7 +57,7 @@ $per_page = array(50, 100, 250); </div> <div> <label for="id_q"><?= __("Keywords"); ?></label> - <input type='text' name='K' size='30' value="<?php if (isset($_REQUEST["K"])) { print stripslashes(trim(htmlspecialchars($_REQUEST["K"], ENT_QUOTES))); } ?>" maxlength='35' autofocus="autofocus" /> + <input type='text' name='K' size='30' value="<?php if (isset($_REQUEST["K"])) { print stripslashes(trim(htmlspecialchars($_REQUEST["K"], ENT_QUOTES))); } ?>" maxlength='35' <?= (empty($tokens[1])) ? 'autofocus="autofocus"' : '' ?> /> </div> <div> <label for="id_out_of_date"><?= __('Out of Date'); ?></label> -- 2.4.5
On Fri, 10 Jul 2015 at 16:24:06, Marcel Korpel wrote:
This needs to be disabled on package pages to be able to add a URL fragment after comment editing.
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/template/pkg_search_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php index 2d03cfa..404d16e 100644 --- a/web/template/pkg_search_form.php +++ b/web/template/pkg_search_form.php @@ -57,7 +57,7 @@ $per_page = array(50, 100, 250); </div> <div> <label for="id_q"><?= __("Keywords"); ?></label> - <input type='text' name='K' size='30' value="<?php if (isset($_REQUEST["K"])) { print stripslashes(trim(htmlspecialchars($_REQUEST["K"], ENT_QUOTES))); } ?>" maxlength='35' autofocus="autofocus" /> + <input type='text' name='K' size='30' value="<?php if (isset($_REQUEST["K"])) { print stripslashes(trim(htmlspecialchars($_REQUEST["K"], ENT_QUOTES))); } ?>" maxlength='35' <?= (empty($tokens[1])) ? 'autofocus="autofocus"' : '' ?> />
Huh? Doesn't this disable the autofocus on the package search page as well?
</div> <div> <label for="id_out_of_date"><?= __('Out of Date'); ?></label> -- 2.4.5
* Lukas Fleischer <lfleischer@archlinux.org> (Fri, 10 Jul 2015 16:35:37 +0200):
Huh? Doesn't this disable the autofocus on the package search page as well?
No: $tokens[0] will contain 'packages' and $tokens[1] will be empty, even if there are query parameters specified, e.g.: http://aur:8888/packages/?K=invented&SeB=m $tokens[1] will only be set if there is a package page opened. Best, Marcel
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/template/pkg_comments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index 380c858..8d6675b 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -31,7 +31,7 @@ $count = pkgbase_comments_count($base_id, $include_deleted); } else { $row['EditUserName'] = htmlspecialchars($row['EditUserName']); } ?> - <h4<?php if ($row['DelUsersID']): ?> class="comment-deleted"<?php endif; ?>> + <h4 id="comment-<?= $row['ID'] ?>"<?php if ($row['DelUsersID']): ?> class="comment-deleted"<?php endif; ?>> <?php if ($row['UserName']): ?> <?= __('%s commented', $row['UserName']) ?> <?php else: ?> -- 2.4.5
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/html/pkgbase.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php index 5886f71..36b2aa5 100644 --- a/web/html/pkgbase.php +++ b/web/html/pkgbase.php @@ -46,6 +46,7 @@ if (isset($_POST['IDs'])) { /* Perform package base actions. */ $ret = false; $output = ""; +$fragment = ""; if (check_token()) { if (current_action("do_Flag")) { list($ret, $output) = pkgbase_flag($ids); @@ -110,6 +111,9 @@ if (check_token()) { $ret = true; } elseif (current_action("do_EditComment")) { list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']); + if ($ret && isset($_POST["comment_id"])) { + $fragment = '#comment-' . intval($_POST["comment_id"]); + } } if ($ret) { @@ -120,7 +124,7 @@ if (check_token()) { exit(); } if (isset($base_id)) { /* Redirect back to package base page on success. */ - header('Location: ' . get_pkgbase_uri($pkgbase_name)); + header('Location: ' . get_pkgbase_uri($pkgbase_name) . $fragment); exit(); } else { /* Redirect back to package search page. */ @@ -134,7 +138,7 @@ $pkgs = pkgbase_get_pkgnames($base_id); if (!$output && count($pkgs) == 1) { /* Not a split package. Redirect to the package page. */ if (empty($_SERVER['QUERY_STRING'])) { - header('Location: ' . get_pkg_uri($pkgs[0])); + header('Location: ' . get_pkg_uri($pkgs[0]) . $fragment); } else { header('Location: ' . get_pkg_uri($pkgs[0]) . '?' . $_SERVER['QUERY_STRING']); } -- 2.4.5
participants (2)
-
Lukas Fleischer
-
Marcel Korpel