summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/aurjson.class.php41
-rw-r--r--web/lib/config.inc.php.proto6
-rw-r--r--web/lib/pkgbasefuncs.inc.php199
-rw-r--r--web/lib/routing.inc.php7
4 files changed, 238 insertions, 15 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 9abb2d65..8187bef5 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -61,7 +61,7 @@ class AurJSON {
if (isset($http_data['v'])) {
$this->version = intval($http_data['v']);
}
- if ($this->version < 1 || $this->version > 2) {
+ if ($this->version < 1 || $this->version > 3) {
return $this->json_error('Invalid version specified.');
}
@@ -109,7 +109,11 @@ class AurJSON {
*/
private function json_error($msg) {
header('content-type: application/json');
- return $this->json_results('error', 0, $msg);
+ if ($this->version < 3) {
+ return $this->json_results('error', 0, $msg, NULL);
+ } elseif ($this->version >= 3) {
+ return $this->json_results('error', 0, array(), $msg);
+ }
}
/*
@@ -117,16 +121,23 @@ class AurJSON {
*
* @param $type The response method type.
* @param $data The result data to return
+ * @param $error An error message to include in the response
*
* @return mixed A json formatted result response.
*/
- private function json_results($type, $count, $data) {
- return json_encode(array(
+ private function json_results($type, $count, $data, $error) {
+ $json_array = array(
'version' => $this->version,
'type' => $type,
'resultcount' => $count,
'results' => $data
- ));
+ );
+
+ if ($error) {
+ $json_array['error'] = $error;
+ }
+
+ return json_encode($json_array);
}
private function get_extended_fields($pkgid) {
@@ -195,7 +206,7 @@ class AurJSON {
"WHERE ${where_condition} " .
"GROUP BY Packages.ID " .
"LIMIT $MAX_RPC_RESULTS";
- } elseif ($this->version == 2) {
+ } elseif ($this->version >= 2) {
$fields = implode(',', self::$fields_v2);
$query = "SELECT {$fields} " .
"FROM Packages LEFT JOIN PackageBases " .
@@ -225,14 +236,18 @@ class AurJSON {
$row[$field] = intval($row[$field]);
}
- if ($this->version == 2 && ($type == 'info' || $type == 'multiinfo')) {
+ if ($this->version >= 2 && ($type == 'info' || $type == 'multiinfo')) {
$row = array_merge($row, $this->get_extended_fields($row['ID']));
}
- if ($type == 'info') {
- $search_data = $row;
- break;
- } else {
+ if ($this->version < 3) {
+ if ($type == 'info') {
+ $search_data = $row;
+ break;
+ } else {
+ array_push($search_data, $row);
+ }
+ } elseif ($this->version >= 3) {
array_push($search_data, $row);
}
}
@@ -241,9 +256,9 @@ class AurJSON {
return $this->json_error('Too many package results.');
}
- return $this->json_results($type, $resultcount, $search_data);
+ return $this->json_results($type, $resultcount, $search_data, NULL);
} else {
- return $this->json_results($type, 0, array());
+ return $this->json_results($type, 0, array(), NULL);
}
}
diff --git a/web/lib/config.inc.php.proto b/web/lib/config.inc.php.proto
index 1fe7dbc4..cb71fa51 100644
--- a/web/lib/config.inc.php.proto
+++ b/web/lib/config.inc.php.proto
@@ -59,3 +59,9 @@ $USE_VIRTUAL_URLS = true;
# Maximum number of package results to return through an RPC connection.
# Avoid setting this too high and having a PHP too much memory error.
$MAX_RPC_RESULTS = 5000;
+
+# Mailing list to send package request notifications to.
+$AUR_REQUEST_ML = "aur-requests@archlinux.org";
+
+# Time to wait until a package request is due.
+$REQUEST_IDLE_TIME = 60 * 60 * 24 * 14;
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index 9f80ef26..9f3439d4 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -438,10 +438,11 @@ function pkgbase_unflag($atype, $base_ids) {
* @param string $atype Account type, output of account_from_sid
* @param array $base_ids Array of package base IDs to delete
* @param int $merge_base_id Package base to merge the deleted ones into
+ * @param int $via Package request to close upon deletion
*
* @return array Tuple of success/failure indicator and error message
*/
-function pkgbase_delete ($atype, $base_ids, $merge_base_id) {
+function pkgbase_delete ($atype, $base_ids, $merge_base_id, $via) {
if (!$atype) {
return array(false, __("You must be logged in before you can delete packages."));
}
@@ -537,6 +538,10 @@ function pkgbase_delete ($atype, $base_ids, $merge_base_id) {
$q = "DELETE FROM PackageBases WHERE ID IN (" . implode(",", $base_ids) . ")";
$dbh->exec($q);
+ if ($via) {
+ pkgbase_close_request(intval($via));
+ }
+
return array(true, __("The selected packages have been deleted."));
}
@@ -546,10 +551,11 @@ function pkgbase_delete ($atype, $base_ids, $merge_base_id) {
* @param string $atype Account type, output of account_from_sid
* @param array $base_ids Array of package base IDs to adopt/disown
* @param bool $action Adopts if true, disowns if false. Adopts by default
+ * @param int $via Package request to close upon adoption
*
* @return array Tuple of success/failure indicator and error message
*/
-function pkgbase_adopt ($atype, $base_ids, $action=true) {
+function pkgbase_adopt ($atype, $base_ids, $action=true, $via) {
if (!$atype) {
if ($action) {
return array(false, __("You must be logged in before you can adopt packages."));
@@ -590,6 +596,10 @@ function pkgbase_adopt ($atype, $base_ids, $action=true) {
$dbh->exec($q);
+ if ($via) {
+ pkgbase_close_request(intval($via));
+ }
+
if ($action) {
pkgbase_notify(account_from_sid($_COOKIE["AURSID"]), $base_ids);
return array(true, __("The selected packages have been adopted."));
@@ -962,3 +972,188 @@ function pkgbase_update_category($base_id, $category_id) {
$category_id, $base_id);
$dbh->exec($q);
}
+
+/**
+ * Get a list of all package requests
+ *
+ * @return array List of pacakge requests with details
+ */
+function pkgbase_request_list() {
+ $dbh = DB::connect();
+
+ $q = "SELECT PackageRequests.ID, ";
+ $q.= "PackageRequests.PackageBaseID AS BaseID, ";
+ $q.= "PackageRequests.PackageBaseName AS Name, ";
+ $q.= "PackageRequests.MergeBaseName AS MergeInto, ";
+ $q.= "RequestTypes.Name AS Type, PackageRequests.Comments, ";
+ $q.= "Users.Username AS User, PackageRequests.RequestTS, ";
+ $q.= "PackageRequests.Status ";
+ $q.= "FROM PackageRequests INNER JOIN RequestTypes ON ";
+ $q.= "RequestTypes.ID = PackageRequests.ReqTypeID ";
+ $q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID ";
+ $q.= "ORDER BY Status ASC, RequestTS DESC";
+
+ return $dbh->query($q)->fetchAll();
+}
+
+/**
+ * File a deletion/orphan request against a package base
+ *
+ * @global string $AUR_LOCATION The AUR's URL used for notification e-mails
+ * @global string $AUR_REQUEST_ML The request notification mailing list
+ * @param string $ids The package base IDs to file the request against
+ * @param string $type The type of the request
+ * @param string $merge_into The target of a merge operation
+ * @param string $comments The comments to be added to the request
+ *
+ * @return void
+ */
+function pkgbase_file_request($ids, $type, $merge_into, $comments) {
+ global $AUR_LOCATION;
+ global $AUR_REQUEST_ML;
+
+ if (empty($comments)) {
+ return array(false, __("The comment field must not be empty."));
+ }
+
+ $dbh = DB::connect();
+ $uid = uid_from_sid($_COOKIE["AURSID"]);
+
+ /* TODO: Allow for filing multiple requests at once. */
+ $base_id = $ids[0];
+ $pkgbase_name = pkgbase_name_from_id($base_id);
+
+ $q = "SELECT ID FROM RequestTypes WHERE Name = " . $dbh->quote($type);
+ $result = $dbh->query($q);
+ if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $type_id = $row['ID'];
+ } else {
+ return array(false, __("Invalid request type."));
+ }
+
+ $q = "INSERT INTO PackageRequests ";
+ $q.= "(ReqTypeID, PackageBaseID, PackageBaseName, MergeBaseName, ";
+ $q.= "UsersID, Comments, RequestTS) VALUES (" . $type_id . ", ";
+ $q.= intval($base_id) . ", " . $dbh->quote($pkgbase_name) . ", ";
+ $q.= $dbh->quote($merge_into) . ", " . $uid . ", ";
+ $q.= $dbh->quote($comments) . ", UNIX_TIMESTAMP())";
+ $dbh->exec($q);
+ $request_id = $dbh->lastInsertId();
+
+ /*
+ * Send e-mail notifications.
+ * TODO: Move notification logic to separate function where it belongs.
+ */
+ $q = "SELECT Users.Email ";
+ $q.= "FROM Users INNER JOIN PackageBases ";
+ $q.= "ON PackageBases.MaintainerUID = Users.ID ";
+ $q.= "WHERE PackageBases.ID = " . intval($base_id);
+ $result = $dbh->query($q);
+ if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $bcc = $row['Email'];
+ } else {
+ unset($bcc);
+ }
+
+ $q = "SELECT Name FROM PackageBases WHERE ID = ";
+ $q.= intval($base_id);
+ $result = $dbh->query($q);
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+
+ /*
+ * TODO: Add native language emails for users, based on their
+ * preferences. Simply making these strings translatable won't
+ * work, users would be getting emails in the language that the
+ * user who posted the comment was in.
+ */
+ $username = username_from_sid($_COOKIE['AURSID']);
+ $body =
+ $username . " [1] filed a " . $type . " request for " .
+ $row['Name'] . " [2]:\n\n" . $comments . "\n\n" .
+ "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n" .
+ "[2] " . $AUR_LOCATION . get_pkgbase_uri($row['Name']) . "\n";
+ $body = wordwrap($body, 70);
+ $headers = "MIME-Version: 1.0\r\n" .
+ "Content-type: text/plain; charset=UTF-8\r\n";
+ if (!empty($bcc)) {
+ $headers .= "Bcc: $bcc\r\n";
+ }
+ $thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>";
+ $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" .
+ "From: notify@aur.archlinux.org\r\n" .
+ "In-Reply-To: $thread_id\r\n" .
+ "References: $thread_id\r\n" .
+ "X-Mailer: AUR";
+ @mail($AUR_REQUEST_ML, "[PRQ#" . $request_id . "] " . ucfirst($type) .
+ " Request for " . $row['Name'], $body,
+ $headers);
+
+ return array(true, __("Added request successfully."));
+}
+
+/**
+ * Close a deletion/orphan request
+ *
+ * @global string $AUR_LOCATION The AUR's URL used for notification e-mails
+ * @global string $AUR_REQUEST_ML The request notification mailing list
+ * @param int $id The package request to close
+ *
+ * @return void
+ */
+function pkgbase_close_request($id) {
+ global $AUR_LOCATION;
+ global $AUR_REQUEST_ML;
+
+ $dbh = DB::connect();
+ $id = intval($id);
+
+ if (!check_user_privileges()) {
+ return array(false, __("Only TUs and developers can close requests."));
+ }
+
+ $q = "UPDATE PackageRequests SET Status = 1 WHERE ID = " . intval($id);
+ $dbh->exec($q);
+
+ /*
+ * Send e-mail notifications.
+ * TODO: Move notification logic to separate function where it belongs.
+ */
+ $q = "SELECT Users.Email ";
+ $q.= "FROM Users INNER JOIN PackageBases ";
+ $q.= "ON PackageBases.MaintainerUID = Users.ID ";
+ $q.= "INNER JOIN PackageRequests ";
+ $q.= "ON PackageRequests.PackageBaseID = PackageBases.ID ";
+ $q.= "WHERE PackageRequests.ID = " . $id;
+ $result = $dbh->query($q);
+ if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $bcc = $row['Email'];
+ } else {
+ unset($bcc);
+ }
+
+ /*
+ * TODO: Add native language emails for users, based on their
+ * preferences. Simply making these strings translatable won't
+ * work, users would be getting emails in the language that the
+ * user who posted the comment was in.
+ */
+ $username = username_from_sid($_COOKIE['AURSID']);
+ $body = $username . " [1] closed request #" . intval($id) . ".\n\n" .
+ "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n";
+ $body = wordwrap($body, 70);
+ $headers = "MIME-Version: 1.0\r\n" .
+ "Content-type: text/plain; charset=UTF-8\r\n";
+ if (!empty($bcc)) {
+ $headers .= "Bcc: $bcc\r\n";
+ }
+ $thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>";
+ $headers .= "Reply-to: noreply@aur.archlinux.org\r\n" .
+ "From: notify@aur.archlinux.org\r\n" .
+ "In-Reply-To: $thread_id\r\n" .
+ "References: $thread_id\r\n" .
+ "X-Mailer: AUR";
+ @mail($AUR_REQUEST_ML, "[PRQ#" . $id . "] Request Closed", $body,
+ $headers);
+
+ return array(true, __("Request closed successfully."));
+}
diff --git a/web/lib/routing.inc.php b/web/lib/routing.inc.php
index 1b2aa52b..2fa3e1f7 100644
--- a/web/lib/routing.inc.php
+++ b/web/lib/routing.inc.php
@@ -5,6 +5,7 @@ $ROUTES = array(
'/index.php' => 'home.php',
'/packages' => 'packages.php',
'/pkgbase' => 'pkgbase.php',
+ '/requests' => 'pkgreq.php',
'/register' => 'account.php',
'/account' => 'account.php',
'/accounts' => 'account.php',
@@ -20,6 +21,7 @@ $ROUTES = array(
$PKG_PATH = '/packages';
$PKGBASE_PATH = '/pkgbase';
+$PKGREQ_PATH = '/requests';
$USER_PATH = '/account';
function get_route($path) {
@@ -54,6 +56,11 @@ function get_pkgbase_route() {
return $PKGBASE_PATH;
}
+function get_pkgreq_route() {
+ global $PKGREQ_PATH;
+ return $PKGREQ_PATH;
+}
+
function get_pkg_uri($pkgname) {
global $USE_VIRTUAL_URLS;
global $PKG_PATH;