Commit 8d6c8722 authored by canyonknight's avatar canyonknight Committed by Lukas Fleischer
Browse files

Remove unnecessary database connection parameter from all functions



All functions now have a database connection method that will use
the same database connection. This imitates the functionality of
passing a database connection as an argument and makes it redundant.

Signed-off-by: default avatarcanyonknight <canyonknight@gmail.com>
Signed-off-by: default avatarLukas Fleischer <archlinux@cryptocrack.de>
parent 8e03e68d
......@@ -80,7 +80,7 @@ $dbh = DB::connect();
<td class="pkg-name">
<?php
$userid = uid_from_sid($_COOKIE["AURSID"]);
user_table($userid, $dbh);
user_table($userid);
?>
</td>
</tr>
......@@ -100,10 +100,10 @@ $dbh = DB::connect();
</form>
</div>
<div id="pkg-updates" class="widget box">
<?php updates_table($dbh); ?>
<?php updates_table(); ?>
</div>
<div id="pkg-stats" class="widget box">
<?php general_stats_table($dbh); ?>
<?php general_stats_table(); ?>
</div>
</div>
......
......@@ -13,11 +13,11 @@ if (isset($_COOKIE["AURSID"])) {
if (!isset($dbh)) {
$dbh = DB::connect();
}
delete_session_id($_COOKIE["AURSID"], $dbh);
delete_session_id($_COOKIE["AURSID"]);
# setting expiration to 1 means '1 second after midnight January 1, 1970'
setcookie("AURSID", "", 1, "/", null, !empty($_SERVER['HTTPS']), true);
unset($_COOKIE['AURSID']);
clear_expired_sessions($dbh);
clear_expired_sessions();
}
header('Location: /');
......
......@@ -357,9 +357,9 @@ if ($uid):
# Update the backend database
if (!$error) {
$dbh = DB::connect();
begin_atomic_commit($dbh);
begin_atomic_commit();
$pdata = pkgdetails_by_pkgname($new_pkgbuild['pkgname'], $dbh);
$pdata = pkgdetails_by_pkgname($new_pkgbuild['pkgname']);
# Check the category to use, "1" meaning "none" (or "keep category" for
# existing packages).
......@@ -380,8 +380,8 @@ if ($uid):
$packageID = $pdata["ID"];
# Flush out old data that will be replaced with new data
remove_pkg_deps($packageID, $dbh);
remove_pkg_sources($packageID, $dbh);
remove_pkg_deps($packageID);
remove_pkg_sources($packageID);
# If a new category was chosen, change it to that
if ($category_id > 1) {
......@@ -389,11 +389,11 @@ if ($uid):
}
# Update package data
update_pkgdetails($new_pkgbuild['pkgname'], $new_pkgbuild['license'], $pkg_version, $new_pkgbuild['pkgdesc'], $new_pkgbuild['url'], $uid, $packageID, $dbh);
update_pkgdetails($new_pkgbuild['pkgname'], $new_pkgbuild['license'], $pkg_version, $new_pkgbuild['pkgdesc'], $new_pkgbuild['url'], $uid, $packageID);
} else {
# This is a brand new package
new_pkgdetails($new_pkgbuild['pkgname'], $new_pkgbuild['license'], $pkg_version, $category_id, $new_pkgbuild['pkgdesc'], $new_pkgbuild['url'], $uid, $dbh);
$packageID = last_insert_id($dbh);
new_pkgdetails($new_pkgbuild['pkgname'], $new_pkgbuild['license'], $pkg_version, $category_id, $new_pkgbuild['pkgdesc'], $new_pkgbuild['url'], $uid);
$packageID = last_insert_id();
}
......@@ -410,7 +410,7 @@ if ($uid):
else if ($deppkgname == "#") {
break;
}
add_pkg_dep($packageID, $deppkgname, $depcondition, $dbh);
add_pkg_dep($packageID, $deppkgname, $depcondition);
}
}
......@@ -418,18 +418,18 @@ if ($uid):
if (!empty($new_pkgbuild['source'])) {
$sources = explode(" ", $new_pkgbuild['source']);
foreach ($sources as $src) {
add_pkg_src($packageID, $src, $dbh);
add_pkg_src($packageID, $src);
}
}
# If we just created this package, or it was an orphan and we
# auto-adopted, add submitting user to the notification list.
if (!$pdata || $pdata["MaintainerUID"] === NULL) {
pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), array($packageID), true, $dbh);
pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID), true);
}
# Entire package creation process is atomic
end_atomic_commit($dbh);
end_atomic_commit();
header('Location: ' . get_pkg_uri($pkg_name));
}
......
......@@ -89,7 +89,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
* @return string|void Return void if successful, otherwise return error
*/
function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$P="",$C="",$R="",$L="",$I="",$K="",$UID=0,$dbh=NULL) {
$P="",$C="",$R="",$L="",$I="",$K="",$UID=0) {
# error check and process request for a new/modified account
global $SUPPORTED_LANGS;
......@@ -99,7 +99,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
}
if(isset($_COOKIE['AURSID'])) {
$editor_user = uid_from_sid($_COOKIE['AURSID'], $dbh);
$editor_user = uid_from_sid($_COOKIE['AURSID']);
}
else {
$editor_user = null;
......@@ -122,7 +122,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
}
}
if (!$error && !valid_username($U) && !user_is_privileged($editor_user, $dbh))
if (!$error && !valid_username($U) && !user_is_privileged($editor_user))
$error = __("The username is invalid.") . "<ul>\n"
."<li>" . __("It must be between %s and %s characters long",
USERNAME_MIN_LEN, USERNAME_MAX_LEN )
......@@ -230,7 +230,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
}
if ($S) {
/* Ensure suspended users can't keep an active session */
delete_user_sessions($UID, $dbh);
delete_user_sessions($UID);
$q.= ", Suspended = 1";
} else {
$q.= ", Suspended = 0";
......@@ -287,7 +287,7 @@ function search_accounts_form() {
* @return void
*/
function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
$S="",$E="",$R="",$I="",$K="",$dbh=NULL) {
$S="",$E="",$R="",$I="",$K="") {
$HITS_PER_PAGE = 50;
if ($O) {
......@@ -389,7 +389,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
*
* @return array Session ID for user, error message if applicable
*/
function try_login($dbh=NULL) {
function try_login() {
global $MAX_SESSIONS_PER_USER, $PERSISTENT_COOKIE_TIMEOUT;
$login_error = "";
......@@ -400,13 +400,13 @@ function try_login($dbh=NULL) {
if (!$dbh) {
$dbh = DB::connect();
}
$userID = valid_user($_REQUEST['user'], $dbh);
$userID = valid_user($_REQUEST['user']);
if ( user_suspended($userID, $dbh) ) {
if ( user_suspended($userID) ) {
$login_error = "Account Suspended.";
}
elseif ( $userID && isset($_REQUEST['passwd'])
&& valid_passwd($userID, $_REQUEST['passwd'], $dbh) ) {
&& valid_passwd($userID, $_REQUEST['passwd']) ) {
$logged_in = 0;
$num_tries = 0;
......@@ -518,7 +518,7 @@ function valid_username($user) {
*
* @return string|void Return user ID if in database, otherwise void
*/
function valid_user($user, $dbh=NULL) {
function valid_user($user) {
/* if ( $user = valid_username($user) ) { */
if(!$dbh) {
......@@ -547,7 +547,7 @@ function valid_user($user, $dbh=NULL) {
*
* @return bool True if there is an open proposal about the user, otherwise false
*/
function open_user_proposals($user, $dbh=NULL) {
function open_user_proposals($user) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -573,7 +573,7 @@ function open_user_proposals($user, $dbh=NULL) {
*
* @return void
*/
function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL) {
function add_tu_proposal($agenda, $user, $votelength, $submitteruid) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -594,7 +594,7 @@ function add_tu_proposal($agenda, $user, $votelength, $submitteruid, $dbh=NULL)
*
* @return void
*/
function create_resetkey($resetkey, $uid, $dbh=NULL) {
function create_resetkey($resetkey, $uid) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -615,7 +615,7 @@ function create_resetkey($resetkey, $uid, $dbh=NULL) {
*
* @return string|void Redirect page if successful, otherwise return error message
*/
function password_reset($hash, $salt, $resetkey, $email, $dbh=NULL) {
function password_reset($hash, $salt, $resetkey, $email) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -660,7 +660,7 @@ function good_passwd($passwd) {
*
* @return bool True if password was correct and properly salted, otherwise false
*/
function valid_passwd($userID, $passwd, $dbh=NULL) {
function valid_passwd($userID, $passwd) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -722,7 +722,7 @@ function valid_pgp_fingerprint($fingerprint) {
*
* @return bool True if the user is suspended, otherwise false
*/
function user_suspended($id, $dbh=NULL) {
function user_suspended($id) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -748,7 +748,7 @@ function user_suspended($id, $dbh=NULL) {
*
* @return void
*/
function user_delete($id, $dbh=NULL) {
function user_delete($id) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -765,7 +765,7 @@ function user_delete($id, $dbh=NULL) {
*
* @return int|string Return 0 if un-privileged, "2" if Trusted User, "3" if Developer
*/
function user_is_privileged($id, $dbh=NULL) {
function user_is_privileged($id) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -789,7 +789,7 @@ function user_is_privileged($id, $dbh=NULL) {
*
* @return void
*/
function delete_session_id($sid, $dbh=NULL) {
function delete_session_id($sid) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -806,7 +806,7 @@ function delete_session_id($sid, $dbh=NULL) {
*
* @return void
*/
function delete_user_sessions($uid, $dbh=NULL) {
function delete_user_sessions($uid) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -823,7 +823,7 @@ function delete_user_sessions($uid, $dbh=NULL) {
*
* @return void
*/
function clear_expired_sessions($dbh=NULL) {
function clear_expired_sessions() {
global $LOGIN_TIMEOUT;
if(!$dbh) {
......@@ -845,7 +845,7 @@ function clear_expired_sessions($dbh=NULL) {
*
* @return array Account details for the specified user
*/
function account_details($uid, $username, $dbh=NULL) {
function account_details($uid, $username) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -875,7 +875,7 @@ function account_details($uid, $username, $dbh=NULL) {
*
* @return bool True if the user has already voted, otherwise false
*/
function tu_voted($voteid, $uid, $dbh=NULL) {
function tu_voted($voteid, $uid) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -899,7 +899,7 @@ function tu_voted($voteid, $uid, $dbh=NULL) {
*
* @return array The details for all current Trusted User proposals
*/
function current_proposal_list($order, $dbh=NULL) {
function current_proposal_list($order) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -924,7 +924,7 @@ function current_proposal_list($order, $dbh=NULL) {
*
* @return array The details for the subset of past Trusted User proposals
*/
function past_proposal_list($order, $lim, $dbh=NULL) {
function past_proposal_list($order, $lim) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -947,7 +947,7 @@ function past_proposal_list($order, $lim, $dbh=NULL) {
*
* @return string The total number of Trusted User proposals
*/
function proposal_count($dbh=NULL) {
function proposal_count() {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -967,7 +967,7 @@ function proposal_count($dbh=NULL) {
*
* @return array All stored details for a specific vote
*/
function vote_details($voteid, $dbh=NULL) {
function vote_details($voteid) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -989,7 +989,7 @@ function vote_details($voteid, $dbh=NULL) {
*
* @return array All users who voted for a specific proposal
*/
function voter_list($voteid, $dbh=NULL) {
function voter_list($voteid) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -1022,7 +1022,7 @@ function voter_list($voteid, $dbh=NULL) {
*
* @return void
*/
function cast_proposal_vote($voteid, $uid, $vote, $newtotal, $dbh=NULL) {
function cast_proposal_vote($voteid, $uid, $vote, $newtotal) {
if (!$dbh) {
$dbh = DB::connect();
}
......
......@@ -30,7 +30,7 @@ include_once("cachefuncs.inc.php");
*
* @return void
*/
function check_sid($dbh=NULL) {
function check_sid() {
global $_COOKIE;
global $LOGIN_TIMEOUT;
......@@ -66,7 +66,7 @@ function check_sid($dbh=NULL) {
} elseif ($failed == 2) {
# session id timeout was reached and they must login again.
#
delete_session_id($_COOKIE["AURSID"], $dbh);
delete_session_id($_COOKIE["AURSID"]);
setcookie("AURSID", "", 1, "/", null, !empty($_SERVER['HTTPS']), true);
unset($_COOKIE['AURSID']);
......@@ -141,7 +141,7 @@ function new_sid() {
*
* @return string Username if it exists, otherwise "None"
*/
function username_from_id($id="", $dbh=NULL) {
function username_from_id($id="") {
if (!$id) {
return "";
}
......@@ -166,7 +166,7 @@ function username_from_id($id="", $dbh=NULL) {
*
* @return string Username of the visitor
*/
function username_from_sid($sid="", $dbh=NULL) {
function username_from_sid($sid="") {
if (!$sid) {
return "";
}
......@@ -194,7 +194,7 @@ function username_from_sid($sid="", $dbh=NULL) {
*
* @return string User's e-mail address as given during registration
*/
function email_from_sid($sid="", $dbh=NULL) {
function email_from_sid($sid="") {
if (!$sid) {
return "";
}
......@@ -222,7 +222,7 @@ function email_from_sid($sid="", $dbh=NULL) {
*
* @return string Account type of user ("User", "Trusted User", or "Developer")
*/
function account_from_sid($sid="", $dbh=NULL) {
function account_from_sid($sid="") {
if (!$sid) {
return "";
}
......@@ -251,7 +251,7 @@ function account_from_sid($sid="", $dbh=NULL) {
*
* @return string|int The user's name, 0 on query failure
*/
function uid_from_sid($sid="", $dbh=NULL) {
function uid_from_sid($sid="") {
if (!$sid) {
return "";
}
......@@ -311,7 +311,7 @@ function html_footer($ver="") {
*
* @return int 0 if the user can't submit, 1 if the user can submit
*/
function can_submit_pkg($name="", $sid="", $dbh=NULL) {
function can_submit_pkg($name="", $sid="") {
if (!$name || !$sid) {return 0;}
if(!$dbh) {
$dbh = DB::connect();
......@@ -324,7 +324,7 @@ function can_submit_pkg($name="", $sid="", $dbh=NULL) {
if (!$row[0]) {
return 1;
}
$my_uid = uid_from_sid($sid, $dbh);
$my_uid = uid_from_sid($sid);
if ($row[0] === NULL || $row[0] == $my_uid) {
return 1;
......@@ -368,7 +368,7 @@ function rm_tree($dirname) {
*
* @return string Return user ID if exists for username, otherwise "None"
*/
function uid_from_username($username="", $dbh=NULL) {
function uid_from_username($username="") {
if (!$username) {
return "";
}
......@@ -393,7 +393,7 @@ function uid_from_username($username="", $dbh=NULL) {
*
* @return string The user's ID
*/
function uid_from_email($email="", $dbh=NULL) {
function uid_from_email($email="") {
if (!$email) {
return "";
}
......@@ -462,7 +462,7 @@ function mkurl($append) {
*
* @return string|void Return the salt for the requested user, otherwise void
*/
function get_salt($user_id, $dbh=NULL) {
function get_salt($user_id) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -482,7 +482,7 @@ function get_salt($user_id, $dbh=NULL) {
* @param string $passwd The password of the user logging in
* @param \PDO $dbh Already established database connection
*/
function save_salt($user_id, $passwd, $dbh=NULL) {
function save_salt($user_id, $passwd) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -552,7 +552,7 @@ function parse_comment($comment) {
*
* @param \PDO $dbh Already established database connection
*/
function begin_atomic_commit($dbh=NULL) {
function begin_atomic_commit() {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -564,7 +564,7 @@ function begin_atomic_commit($dbh=NULL) {
*
* @param \PDO $dbh Already established database connection
*/
function end_atomic_commit($dbh=NULL) {
function end_atomic_commit() {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -579,7 +579,7 @@ function end_atomic_commit($dbh=NULL) {
*
* @return string The ID of the last inserted row
*/
function last_insert_id($dbh=NULL) {
function last_insert_id() {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -594,7 +594,7 @@ function last_insert_id($dbh=NULL) {
*
* @return array $packages Package info for the specified number of recent packages
*/
function latest_pkgs($numpkgs, $dbh=NULL) {
function latest_pkgs($numpkgs) {
if(!$dbh) {
$dbh = DB::connect();
}
......
......@@ -67,7 +67,8 @@ function get_cache_value($key, &$status=false) {
# Run a simple db query, retrieving and/or caching the value if APC is
# available for use. Accepts an optional TTL value (defaults to 600 seconds).
function db_cache_value($dbq, $dbh, $key, $ttl=600) {
function db_cache_value($dbq, $key, $ttl=600) {
$dbh = DB::connect();
$status = false;
$value = get_cache_value($key, $status);
if (!$status) {
......
......@@ -14,7 +14,7 @@ include_once("config.inc.php");
*
* @return bool True if the user can delete the comment, otherwise false
*/
function canDeleteComment($comment_id=0, $atype="", $uid=0, $dbh=NULL) {
function canDeleteComment($comment_id=0, $atype="", $uid=0) {
if ($atype == "Trusted User" || $atype == "Developer") {
# A TU/Dev can delete any comment
return TRUE;
......@@ -86,7 +86,7 @@ function canSubmitBlacklisted($atype = "") {
*
* @return array All package categories
*/
function pkgCategories($dbh=NULL) {
function pkgCategories() {
$cats = array();
if(!$dbh) {
$dbh = DB::connect();
......@@ -110,7 +110,7 @@ function pkgCategories($dbh=NULL) {
*
* @return string|void Package name if it already exists
*/
function pkgid_from_name($name="", $dbh=NULL) {
function pkgid_from_name($name="") {
if (!$name) {return NULL;}
if(!$dbh) {
$dbh = DB::connect();
......@@ -133,7 +133,7 @@ function pkgid_from_name($name="", $dbh=NULL) {
*
* @return array All package dependencies for the package
*/
function package_dependencies($pkgid, $dbh=NULL) {
function package_dependencies($pkgid) {
$deps = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
......@@ -163,7 +163,7 @@ function package_dependencies($pkgid, $dbh=NULL) {
*
* @return array All packages that depend on the specified package name
*/
function package_required($name="", $dbh=NULL) {
function package_required($name="") {
$deps = array();
if ($name != "") {
if(!$dbh) {
......@@ -190,7 +190,7 @@ function package_required($name="", $dbh=NULL) {
*
* @return string The number of comments left for a specific package
*/
function package_comments_count($pkgid, $dbh=NULL) {
function package_comments_count($pkgid) {
if (!$dbh) {
$dbh = DB::connect();
}
......@@ -222,7 +222,7 @@ function package_comments_count($pkgid, $dbh=NULL) {
*
* @return array All package comment information for a specific package
*/
function package_comments($pkgid, $dbh=NULL) {
function package_comments($pkgid) {
$comments = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
......@@ -264,7 +264,7 @@ function package_comments($pkgid, $dbh=NULL) {
*
* @return void
*/
function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
function add_package_comment($pkgid, $uid, $comment) {
global $AUR_LOCATION;
if(!$dbh) {
......@@ -303,7 +303,7 @@ function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
# getting emails in the language that the user who posted the comment was in
$body =
'from ' . $AUR_LOCATION . get_pkg_uri($row['Name']) . "\n"
. username_from_sid($_COOKIE['AURSID'], $dbh) . " wrote:\n\n"
. username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n"
. $comment
. "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
$body = wordwrap($body, 70);
......@@ -321,7 +321,7 @@ function add_package_comment($pkgid, $uid, $comment, $dbh=NULL) {
*
* @return array All sources associated with a specific package
*/
function package_sources($pkgid, $dbh=NULL) {
function package_sources($pkgid) {
$sources = array();
$pkgid = intval($pkgid);
if ($pkgid > 0) {
......@@ -350,7 +350,7 @@ function package_sources($pkgid, $dbh=NULL) {
*
* @return array All packages the visitor has voted for
*/
function pkgvotes_from_sid($sid="", $dbh=NULL) {
function pkgvotes_from_sid($sid="") {
$pkgs = array();
if (!$sid) {return $pkgs;}
if(!$dbh) {
......@@ -378,7 +378,7 @@ function pkgvotes_from_sid($sid="", $dbh=NULL) {
*
* @return array|string All names if multiple package IDs, otherwise package name
*/
function pkgname_from_id($pkgids, $dbh=NULL) {
function pkgname_from_id($pkgids) {
if (is_array($pkgids)) {
$pkgids = sanitize_ids($pkgids);
$names = array();
......@@ -419,7 +419,7 @@ function pkgname_from_id($pkgids, $dbh=NULL) {
*
* @return bool True if the name is blacklisted, otherwise false
*/
function pkgname_is_blacklisted($name, $dbh=NULL) {
function pkgname_is_blacklisted($name) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -439,7 +439,7 @@ function pkgname_is_blacklisted($name, $dbh=NULL) {
*
* @return array The package's details OR error message
**/
function get_package_details($id=0, $dbh=NULL) {
function get_package_details($id=0) {
if(!$dbh) {
$dbh = DB::connect();
}
......@@ -477,7 +477,7 @@ function get_package_details($id=0, $dbh=NULL) {
*
* @return void
*/
function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
function display_package_details($id=0, $row, $SID="") {
global $AUR_LOCATION;
global $USE_VIRTUAL_URLS;
......@@ -495,14 +495,14 @@ function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
if ($SID) {
include('actions_form.php');
if (isset($_REQUEST['comment']) && check_token()) {