Add comment undeletion functionality
[aur.git] / web / html / pkgbase.php
blob11fdf74a8cc4c9b0c7a78348f0fc384be30ccf27
1 <?php
3 set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
5 include_once("aur.inc.php");
6 set_lang();
7 include_once('pkgfuncs.inc.php');
8 check_sid();
11 * Retrieve package base ID and name, unless initialized by the routing
12 * framework.
14 if (!isset($base_id) || !isset($pkgbase_name)) {
15 if (isset($_GET['ID'])) {
16 $base_id = intval($_GET['ID']);
17 $pkgbase_name = pkgbase_name_from_id($_GET['ID']);
18 } else if (isset($_GET['N'])) {
19 $base_id = pkgbase_from_name($_GET['N']);
20 $pkgbase_name = $_GET['N'];
21 } else {
22 unset($base_id, $pkgbase_name);
25 if (isset($base_id) && ($base_id == 0 || $base_id == NULL || $pkgbase_name == NULL)) {
26 header("HTTP/1.0 404 Not Found");
27 include "./404.php";
28 return;
32 /* Set the title to package base name. */
33 $title = $pkgbase_name;
35 /* Grab the list of package base IDs to be operated on. */
36 $ids = array();
37 if (isset($_POST['IDs'])) {
38 foreach ($_POST['IDs'] as $id => $i) {
39 $id = intval($id);
40 if ($id > 0) {
41 $ids[] = $id;
46 /* Perform package base actions. */
47 $ret = false;
48 $output = "";
49 $fragment = "";
50 if (check_token()) {
51 if (current_action("do_Flag")) {
52 list($ret, $output) = pkgbase_flag($ids, $_POST['comments']);
53 } elseif (current_action("do_UnFlag")) {
54 list($ret, $output) = pkgbase_unflag($ids);
55 } elseif (current_action("do_Adopt")) {
56 list($ret, $output) = pkgbase_adopt($ids, true, NULL);
57 } elseif (current_action("do_Disown")) {
58 if (isset($_POST['confirm'])) {
59 $via = isset($_POST['via']) ? $_POST['via'] : NULL;
60 list($ret, $output) = pkgbase_adopt($ids, false, $via);
61 } else {
62 $output = __("The selected packages have not been disowned, check the confirmation checkbox.");
63 $ret = false;
65 } elseif (current_action("do_Vote")) {
66 list($ret, $output) = pkgbase_vote($ids, true);
67 } elseif (current_action("do_UnVote")) {
68 list($ret, $output) = pkgbase_vote($ids, false);
69 } elseif (current_action("do_Delete")) {
70 if (isset($_POST['confirm'])) {
71 $via = isset($_POST['via']) ? $_POST['via'] : NULL;
72 if (!isset($_POST['merge_Into']) || empty($_POST['merge_Into'])) {
73 list($ret, $output) = pkgbase_delete($ids, NULL, $via);
74 unset($_GET['ID']);
75 unset($base_id);
77 else {
78 $merge_base_id = pkgbase_from_name($_POST['merge_Into']);
79 if (!$merge_base_id) {
80 $output = __("Cannot find package to merge votes and comments into.");
81 $ret = false;
82 } elseif (in_array($merge_base_id, $ids)) {
83 $output = __("Cannot merge a package base with itself.");
84 $ret = false;
85 } else {
86 list($ret, $output) = pkgbase_delete($ids, $merge_base_id, $via);
87 unset($_GET['ID']);
88 unset($base_id);
92 else {
93 $output = __("The selected packages have not been deleted, check the confirmation checkbox.");
94 $ret = false;
96 } elseif (current_action("do_Notify")) {
97 list($ret, $output) = pkgbase_notify($ids);
98 } elseif (current_action("do_UnNotify")) {
99 list($ret, $output) = pkgbase_notify($ids, false);
100 } elseif (current_action("do_DeleteComment")) {
101 list($ret, $output) = pkgbase_delete_comment();
102 } elseif (current_action("do_UndeleteComment")) {
103 list($ret, $output) = pkgbase_delete_comment(true);
104 if ($ret && isset($_POST["comment_id"])) {
105 $fragment = '#comment-' . intval($_POST["comment_id"]);
107 } elseif (current_action("do_PinComment")) {
108 list($ret, $output) = pkgbase_pin_comment();
109 } elseif (current_action("do_UnpinComment")) {
110 list($ret, $output) = pkgbase_pin_comment(true);
111 } elseif (current_action("do_SetKeywords")) {
112 list($ret, $output) = pkgbase_set_keywords($base_id, preg_split("/[\s,;]+/", $_POST['keywords'], -1, PREG_SPLIT_NO_EMPTY));
113 } elseif (current_action("do_FileRequest")) {
114 list($ret, $output) = pkgreq_file($ids, $_POST['type'], $_POST['merge_into'], $_POST['comments']);
115 } elseif (current_action("do_CloseRequest")) {
116 list($ret, $output) = pkgreq_close($_POST['reqid'], $_POST['reason'], $_POST['comments']);
117 } elseif (current_action("do_EditComaintainers")) {
118 list($ret, $output) = pkgbase_set_comaintainers($base_id, explode("\n", $_POST['users']));
119 } elseif (current_action("do_AddComment")) {
120 $uid = uid_from_sid($_COOKIE["AURSID"]);
121 list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']);
122 $fragment = '#news';
123 } elseif (current_action("do_EditComment")) {
124 list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']);
125 if ($ret && isset($_POST["comment_id"])) {
126 $fragment = '#comment-' . intval($_POST["comment_id"]);
130 if ($ret) {
131 if (current_action("do_CloseRequest") ||
132 (current_action("do_Delete") && $_POST['via'])) {
133 /* Redirect back to package request page on success. */
134 header('Location: ' . get_pkgreq_route());
135 exit();
136 } if (isset($base_id)) {
137 /* Redirect back to package base page on success. */
138 header('Location: ' . get_pkgbase_uri($pkgbase_name) . $fragment);
139 exit();
140 } else {
141 /* Redirect back to package search page. */
142 header('Location: ' . get_pkg_route());
143 exit();
148 $pkgs = pkgbase_get_pkgnames($base_id);
149 if (!$output && count($pkgs) == 1) {
150 /* Not a split package. Redirect to the package page. */
151 if (empty($_SERVER['QUERY_STRING'])) {
152 header('Location: ' . get_pkg_uri($pkgs[0]) . $fragment);
153 } else {
154 header('Location: ' . get_pkg_uri($pkgs[0]) . '?' . $_SERVER['QUERY_STRING'] . $fragment);
158 $details = pkgbase_get_details($base_id);
159 html_header($title, $details);
162 <?php if ($output): ?>
163 <?php if ($ret): ?>
164 <p class="pkgoutput"><?= htmlspecialchars($output) ?></p>
165 <?php else: ?>
166 <ul class="errorlist"><li><?= htmlspecialchars($output) ?></li></ul>
167 <?php endif; ?>
168 <?php endif; ?>
170 <?php
171 include('pkg_search_form.php');
172 if (isset($_COOKIE["AURSID"])) {
173 pkgbase_display_details($base_id, $details, $_COOKIE["AURSID"]);
174 } else {
175 pkgbase_display_details($base_id, $details, null);
178 html_footer(AURWEB_VERSION);