[aur-dev] [PATCH 1/7] Add virtual path support for package actions
This allows for using following URLs: * /package/$pkg_name/flag: Flag a package out-of-date * /package/$pkg_name/unflag: Unflag a package * /package/$pkg_name/notify: Enable comment notifications * /package/$pkg_name/unnotify: Disable comment notifications * /package/$pkg_name/vote: Vote for the package * /package/$pkg_name/unvote: Remove vote Note that this code is very hackish and should be refactored once we drop support for legacy URLs. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/html/index.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/web/html/index.php b/web/html/index.php index de38178..0af3f2d 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -3,14 +3,44 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); include_once("config.inc.php"); include_once("routing.inc.php"); +include_once("aur.inc.php"); +include_once("pkgfuncs.inc.php"); $path = rtrim($_SERVER['PATH_INFO'], '/'); $tokens = explode('/', $path); -if (isset($tokens[1]) &&'/' . $tokens[1] == get_pkg_route()) { +if (isset($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) { if (isset($tokens[2])) { unset($_GET['ID']); $_GET['N'] = $tokens[2]; + + if (isset($tokens[3])) { + /* TODO: Remove support for legacy URIs and move these + * actions to separate modules. */ + switch ($tokens[3]) { + case "vote": + $_POST['do_Vote'] = __('Vote'); + break; + case "unvote": + $_POST['do_UnVote'] = __('UnVote'); + break; + case "notify": + $_POST['do_Notify'] = __('Notify'); + break; + case "unnotify": + $_POST['do_UnNotify'] = __('UnNotify'); + break; + case "flag": + $_POST['do_Flag'] = __('Flag'); + break; + case "unflag": + $_POST['do_UnFlag'] = __('UnFlag'); + break; + } + + $_POST['token'] = $_COOKIE['AURSID']; + $_POST['IDs'] = array(pkgid_from_name($tokens[2]) => '1'); + } } include get_route('/' . $tokens[1]); -- 1.7.11.2
Note that this currently only works if the virtual path feature is enabled. If you don't use virtual paths, these will still be displayed as buttons below the package details listing. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/lib/pkgfuncs.inc.php | 1 + web/template/actions_form.php | 2 ++ web/template/pkg_details.php | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 0610617..1351e72 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -368,6 +368,7 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { # function package_details($id=0, $SID="", $dbh=NULL) { global $AUR_LOCATION; + global $USE_VIRTUAL_URLS; if(!$dbh) { $dbh = db_connect(); diff --git a/web/template/actions_form.php b/web/template/actions_form.php index 045022d..c58b3ec 100644 --- a/web/template/actions_form.php +++ b/web/template/actions_form.php @@ -5,6 +5,7 @@ <input type="hidden" name="ID" value="<?php echo $row['ID'] ?>" /> <input type="hidden" name="token" value="<?php echo htmlspecialchars($_COOKIE['AURSID']) ?>" /> + <?php if (!$USE_VIRTUAL_URLS): ?> <?php if (user_voted($uid, $row['ID'])): ?> <input type="submit" class="button" name="do_UnVote" value="<?php echo __("UnVote") ?>" /> <?php else: ?> @@ -22,6 +23,7 @@ <?php else: ?> <input type="submit" class="button" name="do_UnFlag" value="<?php echo __("UnFlag Out-of-date") ?>" /> <?php endif; ?> + <?php endif; ?> <?php if ($row["MaintainerUID"] === NULL): ?> <input type="submit" class="button" name="do_Adopt" value="<?php echo __("Adopt Packages") ?>" /> diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 6e19b3b..7542ea8 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -37,6 +37,23 @@ $sources = package_sources($row["ID"]); <li><a href="<?php echo $urlpath ?>/PKGBUILD"><?php echo __('View PKGBUILD') ?></a></li> <li><a href="<?php echo $urlpath . '/' . $row['Name'] ?>.tar.gz"><?php echo __('Download tarball') ?></a></li> <li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li> + <?php if ($USE_VIRTUAL_URLS && $uid): ?> + <?php if (user_voted($uid, $row['ID'])): ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unvote/'; ?>"><?php echo __('UnVote'); ?></a></li> + <?php else: ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'vote/'; ?>"><?php echo __('Vote'); ?></a></li> + <?php endif; ?> + <?php if (user_notify($uid, $row['ID'])): ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unnotify/'; ?>"><?php echo __('UnNotify'); ?></a></li> + <?php else: ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'notify/'; ?>"><?php echo __('Notify'); ?></a></li> + <?php endif; ?> + <?php if ($row["OutOfDateTS"] === NULL): ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'flag/'; ?>"><?php echo __('Flag'); ?></a></li> + <?php else: ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unflag/'; ?>"><?php echo __('UnFlag'); ?></a></li> + <?php endif; ?> + <?php endif; ?> </ul> </div> </div> -- 1.7.11.2
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/template/actions_form.php | 7 ------- web/template/pkg_details.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/web/template/actions_form.php b/web/template/actions_form.php index c58b3ec..4b3845d 100644 --- a/web/template/actions_form.php +++ b/web/template/actions_form.php @@ -25,13 +25,6 @@ <?php endif; ?> <?php endif; ?> - <?php if ($row["MaintainerUID"] === NULL): ?> - <input type="submit" class="button" name="do_Adopt" value="<?php echo __("Adopt Packages") ?>" /> - <?php elseif ($uid == $row["MaintainerUID"] || - $atype == "Trusted User" || $atype == "Developer"): ?> - <input type="submit" class="button" name="do_Disown" value="<?php echo __("Disown Packages") ?>" /> - <?php endif; ?> - <?php if ($atype == "Trusted User" || $atype == "Developer"): ?> <input type="submit" class="button" name="do_Delete" value="<?php echo __("Delete Packages") ?>" /> <label for="merge_Into" ><?php echo __("Merge into") ?></label> diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 7542ea8..2e7fc6c 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -55,6 +55,19 @@ $sources = package_sources($row["ID"]); <?php endif; ?> <?php endif; ?> </ul> + <form action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>" method="post"> + <fieldset> + <input type="hidden" name="IDs[<?php echo $row['ID'] ?>]" value="1" /> + <input type="hidden" name="ID" value="<?php echo $row['ID'] ?>" /> + <input type="hidden" name="token" value="<?php echo htmlspecialchars($_COOKIE['AURSID']) ?>" /> + <?php if ($row["MaintainerUID"] === NULL): ?> + <input type="submit" class="button" name="do_Adopt" value="<?php echo __("Adopt Packages") ?>" /> + <?php elseif ($uid == $row["MaintainerUID"] || + $atype == "Trusted User" || $atype == "Developer"): ?> + <input type="submit" class="button" name="do_Disown" value="<?php echo __("Disown Packages") ?>" /> + <?php endif; ?> + </fieldset> + </form> </div> </div> -- 1.7.11.2
Do not show the actions form if it doesn't contain any elements. This comes into effect if the virtual path feature is enabled and the current user doesn't have TU/developer privileges. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/template/actions_form.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/template/actions_form.php b/web/template/actions_form.php index 4b3845d..bfc0611 100644 --- a/web/template/actions_form.php +++ b/web/template/actions_form.php @@ -1,3 +1,4 @@ +<?php if (!$USE_VIRTUAL_URLS || $atype == "Trusted User" || $atype == "Developer" ): ?> <div class="box"> <form action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>" method="post"> <fieldset> @@ -36,3 +37,4 @@ </fieldset> </form> </div> +<?php endif; ?> -- 1.7.11.2
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/template/pkg_details.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index 2e7fc6c..d4ba828 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -39,19 +39,19 @@ $sources = package_sources($row["ID"]); <li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li> <?php if ($USE_VIRTUAL_URLS && $uid): ?> <?php if (user_voted($uid, $row['ID'])): ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unvote/'; ?>"><?php echo __('UnVote'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unvote/'; ?>"><?php echo __('Remove vote'); ?></a></li> <?php else: ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'vote/'; ?>"><?php echo __('Vote'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'vote/'; ?>"><?php echo __('Vote for this package'); ?></a></li> <?php endif; ?> <?php if (user_notify($uid, $row['ID'])): ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unnotify/'; ?>"><?php echo __('UnNotify'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unnotify/'; ?>"><?php echo __('Disable notifications'); ?></a></li> <?php else: ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'notify/'; ?>"><?php echo __('Notify'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'notify/'; ?>"><?php echo __('Notify of new comments'); ?></a></li> <?php endif; ?> <?php if ($row["OutOfDateTS"] === NULL): ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'flag/'; ?>"><?php echo __('Flag'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'flag/'; ?>"><?php echo __('Flag package out-of-date'); ?></a></li> <?php else: ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unflag/'; ?>"><?php echo __('UnFlag'); ?></a></li> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unflag/'; ?>"><?php echo __('Unflag package'); ?></a></li> <?php endif; ?> <?php endif; ?> </ul> -- 1.7.11.2
Move the flag/unflag action below the flag date. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- web/template/pkg_details.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index d4ba828..207ecfd 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -38,6 +38,11 @@ $sources = package_sources($row["ID"]); <li><a href="<?php echo $urlpath . '/' . $row['Name'] ?>.tar.gz"><?php echo __('Download tarball') ?></a></li> <li><span class="flagged"><?php if ($row["OutOfDateTS"] !== NULL) { echo __('Flagged out-of-date')." (${out_of_date_time})"; } ?></span></li> <?php if ($USE_VIRTUAL_URLS && $uid): ?> + <?php if ($row["OutOfDateTS"] === NULL): ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'flag/'; ?>"><?php echo __('Flag package out-of-date'); ?></a></li> + <?php else: ?> + <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unflag/'; ?>"><?php echo __('Unflag package'); ?></a></li> + <?php endif; ?> <?php if (user_voted($uid, $row['ID'])): ?> <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unvote/'; ?>"><?php echo __('Remove vote'); ?></a></li> <?php else: ?> @@ -48,11 +53,6 @@ $sources = package_sources($row["ID"]); <?php else: ?> <li><a href="<?php echo get_pkg_uri($row['Name']) . 'notify/'; ?>"><?php echo __('Notify of new comments'); ?></a></li> <?php endif; ?> - <?php if ($row["OutOfDateTS"] === NULL): ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'flag/'; ?>"><?php echo __('Flag package out-of-date'); ?></a></li> - <?php else: ?> - <li><a href="<?php echo get_pkg_uri($row['Name']) . 'unflag/'; ?>"><?php echo __('Unflag package'); ?></a></li> - <?php endif; ?> <?php endif; ?> </ul> <form action="<?php echo htmlspecialchars(get_pkg_uri($row['Name']), ENT_QUOTES); ?>" method="post"> -- 1.7.11.2
Fix a notice that appeared if comments were available and the package was requested by name. See 07d3649c2d68bd67ebbcbe10ee9535364903a0f8 for a similar fix for links to the voters page. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de> --- 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 40b2fd1..30ceea5 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -1,6 +1,6 @@ <?php $uid = uid_from_sid($SID); -$count = package_comments_count($_GET['ID']); +$count = package_comments_count($row['ID']); ?> <div id="news"> <h3> -- 1.7.11.2
participants (1)
-
Lukas Fleischer