[aur-dev] [PATCH 2/5] Remove unnecessary database connection parameter from all functions

canyonknight canyonknight at gmail.com
Sun Feb 3 11:26:29 EST 2013


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: canyonknight <canyonknight at gmail.com>
---
 web/html/home.php          |   6 +--
 web/html/logout.php        |   4 +-
 web/html/pkgsubmit.php     |  22 ++++-----
 web/lib/acctfuncs.inc.php  |  58 ++++++++++++------------
 web/lib/aur.inc.php        |  34 +++++++-------
 web/lib/cachefuncs.inc.php |   3 +-
 web/lib/pkgfuncs.inc.php   | 108 ++++++++++++++++++++++-----------------------
 web/lib/stats.inc.php      |  28 ++++++------
 web/lib/translator.inc.php |   2 +-
 9 files changed, 133 insertions(+), 132 deletions(-)

diff --git a/web/html/home.php b/web/html/home.php
index a10ebf0..8fccc7f 100644
--- a/web/html/home.php
+++ b/web/html/home.php
@@ -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>
diff --git a/web/html/logout.php b/web/html/logout.php
index 2d8bebc..6c98290 100644
--- a/web/html/logout.php
+++ b/web/html/logout.php
@@ -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: /');
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php
index 78fceac..12203c4 100644
--- a/web/html/pkgsubmit.php
+++ b/web/html/pkgsubmit.php
@@ -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));
 		}
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 1e25f62..fe13b49 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -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();
 	}
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index 9a84ec7..77a84e4 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -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();
 	}
diff --git a/web/lib/cachefuncs.inc.php b/web/lib/cachefuncs.inc.php
index f109bcf..d558be4 100644
--- a/web/lib/cachefuncs.inc.php
+++ b/web/lib/cachefuncs.inc.php
@@ -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) {
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index b29acb3..21fc37c 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -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()) {
-				$uid = uid_from_sid($SID, $dbh);
-				add_package_comment($id, $uid, $_REQUEST['comment'], $dbh);
+				$uid = uid_from_sid($SID);
+				add_package_comment($id, $uid, $_REQUEST['comment']);
 			}
 			include('pkg_comment_form.php');
 		}
 
 		# Print Comments
-		$comments = package_comments($id, $dbh);
+		$comments = package_comments($id);
 		if (!empty($comments)) {
 			include('pkg_comments.php');
 		}
@@ -554,7 +554,7 @@ function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
  *                     do_Notify - Enable notification
  *                     do_UnNotify - Disable notification
  */
-function pkg_search_page($SID="", $dbh=NULL) {
+function pkg_search_page($SID="") {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -563,7 +563,7 @@ function pkg_search_page($SID="", $dbh=NULL) {
 	// TODO: REDUCE DB HITS.
 	// grab info for user if they're logged in
 	if ($SID)
-		$myuid = uid_from_sid($SID, $dbh);
+		$myuid = uid_from_sid($SID);
 	// get a list of package categories
 	$cats = pkgCategories($dbh); //meow
 
@@ -633,7 +633,7 @@ function pkg_search_page($SID="", $dbh=NULL) {
 		}
 		# Search by submitter
 		elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "s") {
-			$q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'], $dbh)." ";
+			$q_where .= "AND SubmitterUID = ".uid_from_username($_GET['K'])." ";
 		}
 		# Search by name
 		elseif (isset($_GET["SeB"]) && $_GET["SeB"] == "n") {
@@ -801,7 +801,7 @@ function sanitize_ids($ids) {
  *
  * @return string Translated success or error messages
  */
-function pkg_flag($atype, $ids, $dbh=NULL) {
+function pkg_flag($atype, $ids) {
 	global $AUR_LOCATION;
 
 	if (!$atype) {
@@ -826,9 +826,9 @@ function pkg_flag($atype, $ids, $dbh=NULL) {
 
 	if ($affected_pkgs > 0) {
 		# Notify of flagging by email
-		$f_name = username_from_sid($_COOKIE['AURSID'], $dbh);
-		$f_email = email_from_sid($_COOKIE['AURSID'], $dbh);
-		$f_uid = uid_from_sid($_COOKIE['AURSID'], $dbh);
+		$f_name = username_from_sid($_COOKIE['AURSID']);
+		$f_email = email_from_sid($_COOKIE['AURSID']);
+		$f_uid = uid_from_sid($_COOKIE['AURSID']);
 		$q = "SELECT Packages.Name, Users.Email, Packages.ID ";
 		$q.= "FROM Packages, Users ";
 		$q.= "WHERE Packages.ID IN (" . implode(",", $ids) .") ";
@@ -857,7 +857,7 @@ function pkg_flag($atype, $ids, $dbh=NULL) {
  *
  * @return string Translated success or error messages
  */
-function pkg_unflag($atype, $ids, $dbh=NULL) {
+function pkg_unflag($atype, $ids) {
 	if (!$atype) {
 		return __("You must be logged in before you can unflag packages.");
 	}
@@ -876,7 +876,7 @@ function pkg_unflag($atype, $ids, $dbh=NULL) {
 	$q.= "WHERE ID IN (" . implode(",", $ids) . ") ";
 
 	if ($atype != "Trusted User" && $atype != "Developer") {
-		$q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
+		$q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"]);
 	}
 
 	$result = $dbh->exec($q);
@@ -895,7 +895,7 @@ function pkg_unflag($atype, $ids, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_delete ($atype, $ids, $mergepkgid, $dbh=NULL) {
+function pkg_delete ($atype, $ids, $mergepkgid) {
 	if (!$atype) {
 		return __("You must be logged in before you can delete packages.");
 	}
@@ -915,7 +915,7 @@ function pkg_delete ($atype, $ids, $mergepkgid, $dbh=NULL) {
 	}
 
 	if ($mergepkgid) {
-		$mergepkgname = pkgname_from_id($mergepkgid, $dbh);
+		$mergepkgname = pkgname_from_id($mergepkgid);
 	}
 
 	# Send email notifications
@@ -994,7 +994,7 @@ function pkg_delete ($atype, $ids, $mergepkgid, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) {
+function pkg_adopt ($atype, $ids, $action=true) {
 	if (!$atype) {
 		if ($action) {
 			return __("You must be logged in before you can adopt packages.");
@@ -1020,7 +1020,7 @@ function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) {
 	$q = "UPDATE Packages ";
 
 	if ($action) {
-		$user = uid_from_sid($_COOKIE["AURSID"], $dbh);
+		$user = uid_from_sid($_COOKIE["AURSID"]);
 	} else {
 		$user = 'NULL';
 	}
@@ -1032,13 +1032,13 @@ function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) {
 		# Regular users may only adopt orphan packages from unsupported
 		$q.= "AND $field IS NULL ";
 	} else if ($atype == "User") {
-		$q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
+		$q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]);
 	}
 
 	$dbh->exec($q);
 
 	if ($action) {
-		pkg_notify(account_from_sid($_COOKIE["AURSID"], $dbh), $ids, $dbh);
+		pkg_notify(account_from_sid($_COOKIE["AURSID"]), $ids);
 		return __("The selected packages have been adopted.");
 	} else {
 		return __("The selected packages have been disowned.");
@@ -1054,7 +1054,7 @@ function pkg_adopt ($atype, $ids, $action=true, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) {
+function pkg_vote ($atype, $ids, $action=true) {
 	if (!$atype) {
 		if ($action) {
 			return __("You must be logged in before you can vote for packages.");
@@ -1075,8 +1075,8 @@ function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
-	$my_votes = pkgvotes_from_sid($_COOKIE["AURSID"], $dbh);
-	$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
+	$my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]);
+	$uid = uid_from_sid($_COOKIE["AURSID"]);
 
 	$first = 1;
 	foreach ($ids as $pid) {
@@ -1141,7 +1141,7 @@ function pkg_vote ($atype, $ids, $action=true, $dbh=NULL) {
  *
  * @return array User IDs and usernames that voted for a specific package
  */
-function getvotes($pkgid, $dbh=NULL) {
+function getvotes($pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1173,7 +1173,7 @@ function getvotes($pkgid, $dbh=NULL) {
  *
  * @return bool True if the user has already voted, otherwise false
  */
-function user_voted($uid, $pkgid, $dbh=NULL) {
+function user_voted($uid, $pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1199,7 +1199,7 @@ function user_voted($uid, $pkgid, $dbh=NULL) {
  *
  * @return bool True if the user wants notifications, otherwise false
  */
-function user_notify($uid, $pkgid, $dbh=NULL) {
+function user_notify($uid, $pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1224,7 +1224,7 @@ function user_notify($uid, $pkgid, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_notify ($atype, $ids, $action=true, $dbh=NULL) {
+function pkg_notify ($atype, $ids, $action=true) {
 	if (!$atype) {
 #		return __("You must be logged in before you can get notifications on comments.");
 		return;
@@ -1238,7 +1238,7 @@ function pkg_notify ($atype, $ids, $action=true, $dbh=NULL) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
-	$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
+	$uid = uid_from_sid($_COOKIE["AURSID"]);
 
 	$output = "";
 
@@ -1302,7 +1302,7 @@ function pkg_notify ($atype, $ids, $action=true, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_delete_comment($atype, $dbh=NULL) {
+function pkg_delete_comment($atype) {
 	if (!$atype) {
 		return __("You must be logged in before you can edit package information.");
 	}
@@ -1317,8 +1317,8 @@ function pkg_delete_comment($atype, $dbh=NULL) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
-	$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
-	if (canDeleteComment($comment_id, $atype, $uid, $dbh)) {
+	$uid = uid_from_sid($_COOKIE["AURSID"]);
+	if (canDeleteComment($comment_id, $atype, $uid)) {
 		   $q = "UPDATE PackageComments ";
 		   $q.= "SET DelUsersID = ".$uid." ";
 		   $q.= "WHERE ID = ".intval($comment_id);
@@ -1336,7 +1336,7 @@ function pkg_delete_comment($atype, $dbh=NULL) {
  *
  * @return string Translated error or success message
  */
-function pkg_change_category($pid, $atype, $dbh=NULL) {
+function pkg_change_category($pid, $atype) {
 	if (!$atype)  {
 		return __("You must be logged in before you can edit package information.");
 	}
@@ -1368,7 +1368,7 @@ function pkg_change_category($pid, $atype, $dbh=NULL) {
 		return __("You are not allowed to change this package category.");
 	}
 
-	$uid = uid_from_sid($_COOKIE["AURSID"], $dbh);
+	$uid = uid_from_sid($_COOKIE["AURSID"]);
 	if ($uid == $row["MaintainerUID"] ||
 	($atype == "Developer" || $atype == "Trusted User")) {
 		$q = "UPDATE Packages ";
@@ -1389,7 +1389,7 @@ function pkg_change_category($pid, $atype, $dbh=NULL) {
  *
  * @return array All package details for a specific package
  */
-function pkgdetails_by_pkgname($pkgname, $dbh=NULL) {
+function pkgdetails_by_pkgname($pkgname) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1415,7 +1415,7 @@ function pkgdetails_by_pkgname($pkgname, $dbh=NULL) {
  *
  * @return void
  */
-function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pkgurl, $uid, $dbh=NULL) {
+function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pkgurl, $uid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1446,7 +1446,7 @@ function new_pkgdetails($pkgname, $license, $pkgver, $category_id, $pkgdesc, $pk
  *
  * @return void
  */
-function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid, $dbh=NULL) {
+function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid, $pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1473,7 +1473,7 @@ function update_pkgdetails($pkgname, $license, $pkgver, $pkgdesc, $pkgurl, $uid,
  *
  * @return void
  */
-function add_pkg_dep($pkgid, $depname, $depcondition, $dbh=NULL) {
+function add_pkg_dep($pkgid, $depname, $depcondition) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1494,7 +1494,7 @@ function add_pkg_dep($pkgid, $depname, $depcondition, $dbh=NULL) {
  *
  * @return void
  */
-function add_pkg_src($pkgid, $pkgsrc, $dbh=NULL) {
+function add_pkg_src($pkgid, $pkgsrc) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1513,7 +1513,7 @@ function add_pkg_src($pkgid, $pkgsrc, $dbh=NULL) {
  *
  * @return void
  */
-function update_pkg_category($pkgid, $category_id, $dbh=NULL) {
+function update_pkg_category($pkgid, $category_id) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1532,7 +1532,7 @@ function update_pkg_category($pkgid, $category_id, $dbh=NULL) {
  *
  * @return void
  */
-function remove_pkg_deps($pkgid, $dbh=NULL) {
+function remove_pkg_deps($pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
@@ -1549,7 +1549,7 @@ function remove_pkg_deps($pkgid, $dbh=NULL) {
  *
  * @return void
  */
-function remove_pkg_sources($pkgid, $dbh=NULL) {
+function remove_pkg_sources($pkgid) {
 	if(!$dbh) {
 		$dbh = DB::connect();
 	}
diff --git a/web/lib/stats.inc.php b/web/lib/stats.inc.php
index cfae794..3b7cb8f 100644
--- a/web/lib/stats.inc.php
+++ b/web/lib/stats.inc.php
@@ -9,7 +9,8 @@ include_once('aur.inc.php');
  *
  * @return void
  */
-function updates_table($dbh) {
+function updates_table() {
+	$dbh = DB::connect();
 	$key = 'recent_updates';
 	if(!($newest_packages = get_cache_value($key))) {
 		$q = 'SELECT * FROM Packages ORDER BY ModifiedTS DESC LIMIT 10';
@@ -32,16 +33,15 @@ function updates_table($dbh) {
  *
  * @return void
  */
-function user_table($userid, $dbh) {
+function user_table($userid) {
 	$base_q = "SELECT count(*) FROM Packages WHERE Packages.MaintainerUID = " . $userid;
 
-	$maintainer_unsupported_count = db_cache_value($base_q, $dbh,
+	$maintainer_unsupported_count = db_cache_value($base_q,
 		'user_unsupported_count:' . $userid);
 
 	$q = "SELECT count(*) FROM Packages WHERE Packages.OutOfDateTS IS NOT NULL AND Packages.MaintainerUID = " . $userid;
 
-	$flagged_outdated = db_cache_value($q, $dbh,
-		'user_flagged_outdated:' . $userid);
+	$flagged_outdated = db_cache_value($q, 'user_flagged_outdated:' . $userid);
 
 	include('stats/user_table.php');
 }
@@ -53,34 +53,34 @@ function user_table($userid, $dbh) {
  *
  * @return void
  */
-function general_stats_table($dbh) {
+function general_stats_table() {
 	# AUR statistics
 	$q = "SELECT count(*) FROM Packages";
-	$unsupported_count = db_cache_value($q, $dbh, 'unsupported_count');
+	$unsupported_count = db_cache_value($q, 'unsupported_count');
 
 	$q = "SELECT count(*) FROM Packages WHERE MaintainerUID IS NULL";
-	$orphan_count = db_cache_value($q, $dbh, 'orphan_count');
+	$orphan_count = db_cache_value($q, 'orphan_count');
 
 	$q = "SELECT count(*) FROM Users";
-	$user_count = db_cache_value($q, $dbh, 'user_count');
+	$user_count = db_cache_value($q, 'user_count');
 
 	$q = "SELECT count(*) FROM Users,AccountTypes WHERE Users.AccountTypeID = AccountTypes.ID AND AccountTypes.AccountType = 'Trusted User'";
-	$tu_count = db_cache_value($q, $dbh, 'tu_count');
+	$tu_count = db_cache_value($q, 'tu_count');
 
 	$targstamp = intval(strtotime("-7 days"));
 	$yearstamp = intval(strtotime("-1 year"));
 
 	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $targstamp AND Packages.ModifiedTS = Packages.SubmittedTS";
-	$add_count = db_cache_value($q, $dbh, 'add_count');
+	$add_count = db_cache_value($q, 'add_count');
 
 	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $targstamp AND Packages.ModifiedTS != Packages.SubmittedTS";
-	$update_count = db_cache_value($q, $dbh, 'update_count');
+	$update_count = db_cache_value($q, 'update_count');
 
 	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS >= $yearstamp AND Packages.ModifiedTS != Packages.SubmittedTS";
-	$update_year_count = db_cache_value($q, $dbh, 'update_year_count');
+	$update_year_count = db_cache_value($q, 'update_year_count');
 
 	$q = "SELECT count(*) FROM Packages WHERE Packages.ModifiedTS = Packages.SubmittedTS";
-	$never_update_count = db_cache_value($q, $dbh, 'never_update_count');
+	$never_update_count = db_cache_value($q, 'never_update_count');
 
 	include('stats/general_stats_table.php');
 }
diff --git a/web/lib/translator.inc.php b/web/lib/translator.inc.php
index ec8cb58..df798d1 100644
--- a/web/lib/translator.inc.php
+++ b/web/lib/translator.inc.php
@@ -69,7 +69,7 @@ function __() {
 
 # set up the visitor's language
 #
-function set_lang($dbh=NULL) {
+function set_lang() {
 	global $LANG;
 	global $SUPPORTED_LANGS;
 	global $PERSISTENT_COOKIE_TIMEOUT;
-- 
1.8.1.2



More information about the aur-dev mailing list