r49174 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r49173 | r49174 (on ViewVC) | r49175 >
Date:12:31, 4 April 2009
Author:ashley
Status:reverted (Comments)
Tags:
Comment:SocialProfile: cleanup, fixed a bunch of notices, removed unused globals, documented some functions, converted raw sql queries to use Database class etc.
Modified paths:

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.css
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGift.css	(revision 49173)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGift.css	(revision 49174)
@@ -130,4 +130,66 @@
 	color: #666666;
 	padding: 5px;
 	margin-bottom: 5px;
+}
+
+/* Special:TopAwards */
+.top-awards {
+	float: left;
+	width: 60%;
+	padding-top: 15px;
+}
+
+.top-awards-navigation {
+	float: right;
+	margin: 15px 0px 0px 0px;
+	width: 20%;
+}
+
+.top-awards-navigation p {
+	margin: 0px 0px 3px 0px;
+}
+
+.top-awards-navigation a {
+	font-weight: bold;
+	text-decoration: none;
+}
+
+.top-awards-navigation h1 {
+	color: #333333;
+	font-size: 16px;
+	font-weight: bold;
+	padding: 0px 0px 3px 0px;
+	margin: 0px 0px 10px 0px !important;
+	border-bottom: 1px solid #dcdcdc;
+}
+
+.top-award-title {
+	font-size: 16px;
+	font-weight: bold;
+	margin: 0px 0px 18px 0px;
+	color: #797979;
+}
+
+.top-award {
+	margin: 0px 0px 18px 0px;
+	font-size: 13px;
+	color: #797979;
+}
+
+.top-award-number {
+	font-size: 16px;
+	color: #dcdcdc;
+	font-weight: bold;
+	margin: 0px 10px 0px 0px;
+}
+
+.top-award img {
+	vertical-align: middle;
+	margin: 0px 3px 0px 0px;
+}
+
+.top-award a {
+	font-size: 16px;
+	font-weight: bold;
+	text-decoration: none;
 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/SystemGifts/TopAwards.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/TopAwards.php	(revision 49173)
+++ trunk/extensions/SocialProfile/SystemGifts/TopAwards.php	(revision 49174)
@@ -6,7 +6,7 @@
 	 * Constructor
 	 */
 	public function __construct(){
-		parent::__construct('TopAwards');
+		parent::__construct( 'TopAwards' );
 	}
 
 	/**
@@ -15,10 +15,9 @@
 	 * @param $par Mixed: parameter passed to the page or null
 	 */
 	public function execute( $par ){
-		global $wgRequest, $wgOut, $wgUser, $wgUploadPath, $wgDBprefix, $wgScriptPath;
+		global $wgRequest, $wgOut, $wgUser, $wgUploadPath, $wgScriptPath, $wgSystemGiftsScripts;
 
 		// Variables 
-		$output = '';
 		$gift_name_check = '';
 		$x = 0;
 		$category_number = $wgRequest->getVal( 'category' );
@@ -35,85 +34,32 @@
 		// Set title
 		if( !($category_number) or $category_number > 4 ) {
 			$category_number = 0;
-			$page_category = $categories[$category_number][category_name];
+			$page_category = $categories[$category_number]['category_name'];
 		} else {
-			$page_category = $categories[$category_number][category_name];
+			$page_category = $categories[$category_number]['category_name'];
 		}
 
 		// Database calls
-		$dbr = wfGetDB( DB_MASTER );
-		$sql = "SELECT sg_user_name, sg_user_id, gift_category, MAX(gift_threshold) AS top_gift FROM ".$wgDBprefix."user_system_gift INNER JOIN ".$wgDBprefix."system_gift ON gift_id=sg_gift_id WHERE gift_category = {$categories[$category_number][category_id]} AND gift_threshold > {$categories[$category_number][category_threshold]} GROUP BY sg_user_name ORDER BY top_gift DESC";
-		$res = $dbr->query($sql);
+		$dbr = wfGetDB( DB_SLAVE );
+		$res = $dbr->select(
+			array( 'user_system_gift', 'system_gift' ),
+			array( 'sg_user_name', 'sg_user_id', 'gift_category', 'MAX(gift_threshold) AS top_gift' ),
+			array(
+				"gift_category = {$categories[$category_number]['category_id']}",
+				"gift_threshold > {$categories[$category_number]['category_threshold']}"
+			),
+			__METHOD__,
+			array( 'GROUP BY' => 'sg_user_name', 'ORDER BY' => 'top_gift DESC' ),
+			array( 'system_gift' => array( 'INNER JOIN', 'gift_id=sg_gift_id' ) )
+		);
 
 		// Page title 
-		$wgOut->setPageTitle("Top Awards - {$page_category} Milestones");
+		$wgOut->setPageTitle( "Top Awards - {$page_category} Milestones" );
 
-		// Style
-		$output .= "<style>
+		// Add CSS
+		$wgOut->addStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
 
-			.top-awards {
-				float:left;
-				width:60%;
-				padding-top:15px
-			}
-
-			.top-awards-navigation {
-				float:right;
-				margin:15px 0px 0px 0px;
-				width:20%;
-			}
-
-			.top-awards-navigation p {
-				margin:0px 0px 3px 0px;
-			}
-
-			.top-awards-navigation a {
-				font-weight:bold;
-				text-decoration:none;
-			}
-
-			.top-awards-navigation h1 {
-				color:#333333;
-				font-size:16px;
-				font-weight:bold;
-				padding:0px 0px 3px 0px;
-				margin:0px 0px 10px 0px !important;
-				border-bottom:1px solid #dcdcdc;
-			}
-
-			.top-award-title {
-				font-size:16px;
-				font-weight:bold;
-				margin:0px 0px 18px 0px;
-				color:#797979;
-			}
-
-			.top-award {
-				margin:0px 0px 18px 0px;
-				font-size:13px;
-				color:#797979;
-			}
-
-			.top-award-number {
-				font-size:16px;
-				color:#dcdcdc;
-				font-weight:bold;
-				margin:0px 10px 0px 0px;
-			}
-
-			.top-award img {
-				vertical-align:middle;
-				margin:0px 3px 0px 0px;
-			}
-
-			.top-award a {
-				font-size:16px;
-				font-weight:bold;
-				text-decoration:none;
-			}
-		</style>";
-
-		$output .= '<div class="top-awards-navigation">
+		$output = '<div class="top-awards-navigation">
 			<h1>Award Categories</h1>';
 
 			$nav_x = 0;
@@ -121,24 +67,23 @@
 			foreach( $categories as $award_type ) {
 
 				if( $nav_x == $category_number ) {
-					$output .= "<p><b>{$award_type[category_name]}s</b></p>";
+					$output .= "<p><b>{$award_type['category_name']}s</b></p>";
 				} else {
-					$output .= "<p><a href=\"".$wgScriptPath."/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type[category_name]}s</a></p>";
+					$output .= "<p><a href=\"".$wgScriptPath."/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type['category_name']}s</a></p>";
 				}
 				$nav_x++;
 			}
 
 		$output .= '</div>';
-
 		$output .= '<div class="top-awards">';
 
 		while( $row = $dbr->fetchObject( $res ) ) {
 
 			$user_name = $row->sg_user_name;
 			$user_id = $row->sg_user_id;
-			$avatar = new wAvatar($user_id, 'm');
+			$avatar = new wAvatar( $user_id, 'm' );
 			$top_gift = $row->top_gift;
-			$gift_name = number_format($top_gift) . " {$categories[$category_number][category_name]}".( ( $top_gift > 1 ) ? 's' : '' )." Milestone";
+			$gift_name = number_format( $top_gift ) . " {$categories[$category_number][category_name]}".( ( $top_gift > 1 ) ? 's' : '' )." Milestone";
 
 				if( $gift_name !== $gift_name_check ) {
 					$x = 1;
@@ -160,8 +105,8 @@
 		}
 
 		$output .= '</div>
-		<div class=\"cleared\"></div>';
+		<div class="cleared"></div>';
 
-		$wgOut->addHTML($output);
+		$wgOut->addHTML( $output );
 	}
 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php	(revision 49173)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php	(revision 49174)
@@ -34,51 +34,52 @@
 	}
 
 	public function update_system_gifts(){
-		global $IP, $wgOut, $wgMemc, $wgDBprefix;
+		global $wgOut, $wgMemc;
 
 		$dbw = wfGetDB( DB_MASTER );
-		$stats = new UserStatsTrack(1, "");
-		$this->categories = array_flip($this->categories); 
+		$stats = new UserStatsTrack( 1, '' );
+		$this->categories = array_flip( $this->categories ); 
 
-		$sql = "SELECT gift_id,gift_category,gift_threshold, gift_name
-			FROM ".$wgDBprefix."system_gift
-			ORDER BY gift_category,gift_threshold ASC";
+		$res = $dbw->select( 'system_gift',
+			array( 'gift_id', 'gift_category', 'gift_threshold', 'gift_name' ),
+			array(),
+			__METHOD__,
+			array( 'ORDER BY' => 'gift_category, gift_threshold ASC' )
+		);
 
-		$res = $dbw->query($sql);
 		$x = 1;
 		while( $row = $dbw->fetchObject( $res ) ) {
 
 			if( $row->gift_category ){
-				$sql2 = "SELECT stats_user_id, stats_user_name
-					FROM ".$wgDBprefix."user_stats
-					WHERE " . $stats->stats_fields[$this->categories[$row->gift_category]] . " >= {$row->gift_threshold}
-					AND stats_user_id<>0";
+				$res2 = $dbw->select( 'user_stats',
+					array( 'stats_user_id', 'stats_user_name' ),
+					array( $stats->stats_fields[$this->categories[$row->gift_category]] . " >= {$row->gift_threshold}", 'stats_user_id<>0' ),
+					__METHOD__
+				);
 
-				$res2 = $dbw->query($sql2);
-
 				while( $row2 = $dbw->fetchObject( $res2 ) ) {
-					if( $this->doesUserHaveGift($row2->stats_user_id, $row->gift_id) == false ){
+					if( $this->doesUserHaveGift( $row2->stats_user_id, $row->gift_id ) == false ){
 
 						$dbw->insert( 'user_system_gift',
-						array(
-							'sg_gift_id' => $row->gift_id,
-							'sg_user_id' => $row2->stats_user_id,
-							'sg_user_name' => $row2->stats_user_name,
-							'sg_status' => 0,
-							'sg_date' => date("Y-m-d H:i:s", time() - (60 * 60 * 24 * 3) ),
+							array(
+								'sg_gift_id' => $row->gift_id,
+								'sg_user_id' => $row2->stats_user_id,
+								'sg_user_name' => $row2->stats_user_name,
+								'sg_status' => 0,
+								'sg_date' => date("Y-m-d H:i:s", time() - (60 * 60 * 24 * 3) ),
 							), __METHOD__
 						);
 
 						$sg_key = wfMemcKey( 'user', 'profile', 'system_gifts', "{$row2->stats_user_id}" );
-						$wgMemc->delete($sg_key);
+						$wgMemc->delete( $sg_key );
 
-						$wgOut->addHTML( $row2->stats_user_name. " got ". $row->gift_name . "<br />" );
+						$wgOut->addHTML( $row2->stats_user_name . ' got ' . $row->gift_name . '<br />' );
 						$x++;
 					}
 				}
 			}
 		}
-		$wgOut->addHTML("{$x} awards were given out");
+		$wgOut->addHTML( "{$x} awards were given out" );
 	}
 
 	public function doesUserHaveGift( $user_id, $gift_id ){
@@ -92,15 +93,14 @@
 	}
 
 	public function addGift( $gift_name, $gift_description, $gift_category, $gift_threshold ){
-		$user_id_to = User::idFromName($user_to);
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->insert( 'system_gift',
-		array(
-			'gift_name' => $gift_name,
-			'gift_description' => $gift_description,
-			'gift_category' => $gift_category,
-			'gift_threshold' => $gift_threshold,
-			'gift_createdate' => date("Y-m-d H:i:s"),
+			array(
+				'gift_name' => $gift_name,
+				'gift_description' => $gift_description,
+				'gift_category' => $gift_category,
+				'gift_threshold' => $gift_threshold,
+				'gift_createdate' => date("Y-m-d H:i:s"),
 			), __METHOD__
 		);	
 		return $dbw->insertId();
@@ -110,13 +110,13 @@
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->update( 'system_gift',
 			array( /* SET */
-			'gift_name' => $gift_name,
-			'gift_description' => $gift_description,
-			'gift_category' => $gift_category,
-			'gift_threshold' => $gift_threshold,
+				'gift_name' => $gift_name,
+				'gift_description' => $gift_description,
+				'gift_category' => $gift_category,
+				'gift_threshold' => $gift_threshold,
 			), array( /* WHERE */
-			'gift_id' => $id
-			), ""
+				'gift_id' => $id
+			), __METHOD__
 		);
 	}
 
@@ -131,18 +131,20 @@
 	}
 
 	static function getGift( $id ){
-		global $wgDBprefix;
 		$dbr = wfGetDB( DB_SLAVE );
-		$sql = "SELECT gift_id, gift_name, gift_description, gift_category, gift_threshold, gift_given_count
-			FROM ".$wgDBprefix."system_gift WHERE gift_id = {$id} LIMIT 0,1";
-		$res = $dbr->query($sql);
+		$res = $dbr->select( 'system_gift',
+			array( 'gift_id', 'gift_name', 'gift_description', 'gift_category', 'gift_threshold', 'gift_given_count' ),
+			array( 'gift_id' => $id ),
+			__METHOD__,
+			array( 'LIMIT' => 1 )
+		);
 		$row = $dbr->fetchObject( $res );
 		if( $row ){
-			$gift['gift_id']= $row->gift_id;
-			$gift['gift_name']= $row->gift_name;
-			$gift['gift_description']= $row->gift_description;
-			$gift['gift_category']= $row->gift_category;
-			$gift['gift_threshold']= $row->gift_threshold;
+			$gift['gift_id'] = $row->gift_id;
+			$gift['gift_name'] = $row->gift_name;
+			$gift['gift_description'] = $row->gift_description;
+			$gift['gift_category'] = $row->gift_category;
+			$gift['gift_threshold'] = $row->gift_threshold;
 			$gift['gift_given_count'] = $row->gift_given_count;
 		}
 		return $gift;
@@ -150,12 +152,12 @@
 
 	static function getGiftImage( $id, $size ){
 		global $wgUploadDirectory;
-		$files = glob($wgUploadDirectory . "/awards/sg_" . $id .  "_" . $size . "*");
+		$files = glob( $wgUploadDirectory . '/awards/sg_' . $id . '_' . $size . "*" );
 
 		if( !empty( $files[0] ) ) {
-			$img = basename($files[0]) ;
+			$img = basename( $files[0] );
 		} else {
-			$img = "default" . "_" . $size . ".gif";
+			$img = 'default_' . $size . '.gif';
 		}
 		return $img . "?r=" . rand();		
 	}
@@ -171,7 +173,7 @@
 			$limit_sql = " LIMIT {$limitvalue},{$limit} ";
 		}
 
-		$sql = "SELECT gift_id,gift_name,gift_description,gift_category, gift_threshold, gift_given_count
+		$sql = "SELECT gift_id,gift_createdate,gift_name,gift_description,gift_category, gift_threshold, gift_given_count
 			FROM ".$wgDBprefix."system_gift
 			ORDER BY gift_createdate DESC
 			{$limit_sql}";
@@ -181,7 +183,7 @@
 		while( $row = $dbr->fetchObject( $res ) ) {
 			$gifts[] = array(
 				'id' => $row->gift_id,
-				'timestamp' => ($row->gift_timestamp),
+				'timestamp' => ($row->gift_createdate),
 				'gift_name' => $row->gift_name,
 				'gift_description' => $row->gift_description,
 				'gift_category' => $row->gift_category,
Index: trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php
===================================================================
--- trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php	(revision 49173)
+++ trunk/extensions/SocialProfile/UserProfile/SpecialUpdateProfile.php	(revision 49174)
@@ -38,12 +38,12 @@
 	 * @param $section Mixed: parameter passed to the page or null
 	 */
 	public function execute( $section ){
-		global $wgUser, $wgOut, $wgRequest, $wgSiteView, $wgUserProfileScripts, $wgUpdateProfileInRecentChanges, $wgSupressPageTitle;
+		global $wgUser, $wgOut, $wgRequest, $wgUserProfileScripts, $wgUpdateProfileInRecentChanges, $wgSupressPageTitle;
 		$wgSupressPageTitle = true;
 
 		wfLoadExtensionMessages( 'SocialProfileUserProfile' );
 
-		$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg('edit-profile-title') ) );
+		$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'edit-profile-title' ) ) );
 
 		// This feature is only available for logged-in users.
 		if( !$wgUser->isLoggedIn() ) {
@@ -93,7 +93,7 @@
 				$log->updateRecentChanges = false;
 			}
 			$log->addEntry( wfMsgForContent( 'user-profile-update-profile' ), $wgUser->getUserPage(), wfMsgForContent( 'user-profile-update-log-section' ) . " '{$section}'" );
-			$wgOut->addHTML( '<span class="profile-on">' . wfMsgForContent( 'user-profile-update-saved' ) . '</span><br /><br />' );
+			$wgOut->addHTML( '<span class="profile-on">' . wfMsg( 'user-profile-update-saved' ) . '</span><br /><br />' );
 
 			// create user page if not exists
 			$title = Title::makeTitle( NS_USER, $wgUser->getName() );
@@ -122,12 +122,12 @@
 	}
 
 	function saveSettings_basic(){
-		global $wgUser, $wgOut, $wgRequest, $wgSiteView, $wgEmailAuthentication;
+		global $wgUser, $wgRequest, $wgEmailAuthentication;
 
-		$wgUser->setRealName( $wgRequest->getVal('real_name') );
-		$wgUser->setEmail( $wgRequest->getVal('email') );
+		$wgUser->setRealName( $wgRequest->getVal( 'real_name' ) );
+		$wgUser->setEmail( $wgRequest->getVal( 'email' ) );
 
-		if( $wgUser->getEmail() != $wgRequest->getVal('email') ){
+		if( $wgUser->getEmail() != $wgRequest->getVal( 'email' ) ){
 			$wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
 		}
 
@@ -145,7 +145,7 @@
 	}
 
 	function saveSettings_pref(){
-		global $wgUser, $wgOut, $wgRequest, $wgSiteView, $wgSitename;
+		global $wgUser, $wgOut, $wgRequest, $wgSitename;
 
 		$notify_friend = $wgRequest->getVal( 'notify_friend' );
 		$notify_gift = $wgRequest->getVal( 'notify_gift' );
@@ -167,13 +167,13 @@
 		if( $wgSitename == 'ArmchairGM' ){
 			$dbw = wfGetDB( DB_MASTER );
 			// If the user wants a weekly email, we'll put some info about that to the user_mailing_list table
-			if( $wgRequest->getVal('weeklyemail') == 1 ){
+			if( $wgRequest->getVal( 'weeklyemail' ) == 1 ){
 				$s = $dbw->selectRow( 'user_mailing_list', array( 'um_user_id' ), array( 'um_user_id' => $wgUser->getID() ), __METHOD__ );
 				if ( $s === false ){
 					$dbw->insert( 'user_mailing_list',
-					array(
-						'um_user_id' => $wgUser->getID(),
-						'um_user_name' => $wgUser->getName(),
+						array(
+							'um_user_id' => $wgUser->getID(),
+							'um_user_name' => $wgUser->getName(),
 						), __METHOD__
 					);
 				}
@@ -185,23 +185,23 @@
 	}
 
 	function formatBirthdayDB( $birthday ){
-		$dob = explode('/', $birthday);
-		if( count($dob) == 2 ){
+		$dob = explode( '/', $birthday );
+		if( count( $dob ) == 2 ){
 			$year = 2007;
 			$month = $dob[0];
 			$day = $dob[1];
-			$birthday_date = $year . "-" . $month . "-" . $day;
+			$birthday_date = $year . '-' . $month . '-' . $day;
 		}
-		return ($birthday_date);
+		return ( $birthday_date );
 	}
 
 	function formatBirthday( $birthday ){
-		$dob = explode('-', $birthday);
-		if( count($dob) == 3 ){
+		$dob = explode( '-', $birthday );
+		if( count( $dob ) == 3 ){
 			$year = 0000;
 			$month = $dob[1];
 			$day = $dob[2];
-			$birthday_date = $month . "/" . $day; // . "/" . $year;
+			$birthday_date = $month . '/' . $day; // . '/' . $year;
 		}
 		return $birthday_date;
 	}
@@ -261,7 +261,7 @@
 	}
 
 	function saveProfilePersonal(){
-		global $wgUser, $wgMemc, $wgRequest, $wgDBprefix;
+		global $wgUser, $wgMemc, $wgRequest;
 
 		$this->initProfile();
 		$dbw = wfGetDB( DB_MASTER );
@@ -284,7 +284,7 @@
 	}
 
 	function displayBasicForm(){
-		global $wgRequest, $wgSiteView, $wgUser, $wgDBprefix, $wgOut;
+		global $wgRequest, $wgUser, $wgOut;
 
 		$dbr = wfGetDB( DB_MASTER );
 		$s = $dbr->selectRow( 'user_profile',
@@ -323,10 +323,10 @@
 		}
 
 		$s = $dbr->selectRow( 'user',
-				array( 'user_real_name', 'user_email', 'user_email_authenticated' ),
-				array( 'user_id' => $wgUser->getID() ),
-				__METHOD__ 
-			);
+			array( 'user_real_name', 'user_email', 'user_email_authenticated' ),
+			array( 'user_id' => $wgUser->getID() ),
+			__METHOD__ 
+		);
 
 		if ( $s !== false ) {
 			$real_name = $s->user_real_name;
@@ -338,43 +338,44 @@
 		$countries = explode( "\n*", wfMsgForContent( 'userprofile-country-list' ) );
 		array_shift( $countries );
 
-		$wgOut->setPageTitle( wfMsg('edit-profile-title') );
+		$wgOut->setPageTitle( wfMsg( 'edit-profile-title' ) );
 		$form = UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-personal' ) );
 		$form .= '<form action="" method="post" enctype="multipart/form-data" name="profile">';
 		$form .= '<div class="profile-info clearfix">';
 		$form .= '<div class="profile-update">
-			<p class="profile-update-title">' . wfMsgForContent( 'user-profile-personal-info' ) . '</p>
-			<p class="profile-update-unit-left">' . wfMsgForContent( 'user-profile-personal-name' ) . '</p>
+			<p class="profile-update-title">' . wfMsg( 'user-profile-personal-info' ) . '</p>
+			<p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-name' ) . '</p>
 			<p class="profile-update-unit"><input type="text" size="25" name="real_name" id="real_name" value="'. $real_name . '"/></p>
 			<div class="cleared"></div>
-			<p class="profile-update-unit-left">' . wfMsgForContent( 'user-profile-personal-email' ) . '</p>
+			<p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-email' ) . '</p>
 			<p class="profile-update-unit"><input type="text" size="25" name="email" id="email" value="'. $email . '"/>';
 			if( !$wgUser->mEmailAuthenticated ){
 				$confirm = SpecialPage::getTitleFor( 'Confirmemail' );
-				$form .= " <a href=\"{$confirm->getFullURL()}\">" . wfMsgForContent( 'user-profile-personal-confirmemail' ) . "</a>";
+				$form .= " <a href=\"{$confirm->getFullURL()}\">" . wfMsg( 'user-profile-personal-confirmemail' ) . "</a>";
 			}
 			$form .= '</p>
 			<div class="cleared"></div>';
 			if( !$wgUser->mEmailAuthenticated ){
-				$form .= '<p class="profile-update-unit-left"></p><p class="profile-update-unit-small">'.wfMsgForContent('user-profile-personal-email-needs-auth').'</p>';
+				$form .= '<p class="profile-update-unit-left"></p>
+				<p class="profile-update-unit-small">'.wfMsg( 'user-profile-personal-email-needs-auth' ).'</p>';
 			}
 			$form .= '<div class="cleared"></div>
 		</div>
 		<div class="cleared"></div>';
 
 		$form .= '<div class="profile-update">
-			<p class="profile-update-title">' . wfMsgForContent( 'user-profile-personal-location' ) . '</p>
-			<p class="profile-update-unit-left">' . wfMsgForContent( 'user-profile-personal-city' ) . '</p>
-			<p class="profile-update-unit"><input type="text" size="25" name="location_city" id="location_city" value="'. $location_city . '"/></p>
+			<p class="profile-update-title">' . wfMsg( 'user-profile-personal-location' ) . '</p>
+			<p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-city' ) . '</p>
+			<p class="profile-update-unit"><input type="text" size="25" name="location_city" id="location_city" value="'. $location_city . '" /></p>
 			<div class="cleared"></div>
-			<p class="profile-update-unit-left" id="location_state_label">' . wfMsgForContent( 'user-profile-personal-country' ) . '</p>';
+			<p class="profile-update-unit-left" id="location_state_label">' . wfMsg( 'user-profile-personal-country' ) . '</p>';
 			$form .= '<p class="profile-update-unit">';
 			$form .= '<span id="location_state_form">';
 		 	$form .= "</span>
-		 		<script>
+		 		<script type=\"text/javascript\">
 					displaySection(\"location_state\",\"" . $location_country . "\",\"" . $location_state . "\")
 				</script>";
-		 	$form .= "<select name=\"location_country\" id=\"location_country\" onChange=\"displaySection('location_state',this.value,'')\"><option></option>";
+		 	$form .= "<select name=\"location_country\" id=\"location_country\" onhhange=\"displaySection('location_state',this.value,'')\"><option></option>";
 
 		foreach( $countries as $country ) {
 			$form .= "<option value=\"{$country}\"" . ( ( $country == $location_country ) ? ' selected="selected"' : '' ) . ">";
@@ -388,15 +389,15 @@
 		<div class="cleared"></div>';
 
 		$form .= '<div class="profile-update">
-			<p class="profile-update-title">' . wfMsgForContent( 'user-profile-personal-hometown' ) . '</p>
-			<p class="profile-update-unit-left">' . wfMsgForContent( 'user-profile-personal-city' ) . '</p>
-			<p class="profile-update-unit"><input type="text" size="25" name="hometown_city" id="hometown_city" value="'. $hometown_city . '"/></p>
+			<p class="profile-update-title">' . wfMsg( 'user-profile-personal-hometown' ) . '</p>
+			<p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-city' ) . '</p>
+			<p class="profile-update-unit"><input type="text" size="25" name="hometown_city" id="hometown_city" value="'. $hometown_city . '" /></p>
 			<div class="cleared"></div>
-			<p class="profile-update-unit-left" id="hometown_state_label">' . wfMsgForContent( 'user-profile-personal-country' ) . '</p>
+			<p class="profile-update-unit-left" id="hometown_state_label">' . wfMsg( 'user-profile-personal-country' ) . '</p>
 			<p class="profile-update-unit">';
 		$form .= '<span id="hometown_state_form">';
 		$form .= "</span>
-			<script>
+			<script type=\"text/javascript\">
 				displaySection(\"hometown_state\",\"" . $hometown_country . "\",\"" . $hometown_state . "\")
 			</script>";
 		$form .= "<select name=\"hometown_country\" id=\"hometown_country\" onChange=\"displaySection('hometown_state',this.value,'')\"><option></option>";
@@ -413,15 +414,15 @@
 		<div class="cleared"></div>';
 
 		$form .= '<div class="profile-update">
-			<p class="profile-update-title">' . wfMsgForContent( 'user-profile-personal-birthday' ) . '</p>
-			<p class="profile-update-unit-left">' . wfMsgForContent( 'user-profile-personal-birthdate' ) . '</p>
-			<p class="profile-update-unit"><input type="text" size="25" name="birthday" id="birthday" value="'. $birthday . '"/></p>
+			<p class="profile-update-title">' . wfMsg( 'user-profile-personal-birthday' ) . '</p>
+			<p class="profile-update-unit-left">' . wfMsg( 'user-profile-personal-birthdate' ) . '</p>
+			<p class="profile-update-unit"><input type="text" size="25" name="birthday" id="birthday" value="'. $birthday . '" /></p>
 			<div class="cleared"></div>
 		</div><div class="cleared"></div>';
 
 		$form .= "<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-personal-aboutme' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-personal-aboutme' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-personal-aboutme' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-personal-aboutme' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"about\" id=\"about\" rows=\"3\" cols=\"75\">{$about}</textarea>
 			</p>
@@ -430,8 +431,8 @@
 		<div class=\"cleared\"></div>
 
 		<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-personal-work' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-personal-occupation' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-personal-work' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-personal-occupation' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"occupation\" id=\"occupation\" rows=\"2\" cols=\"75\">{$occupation}</textarea>
 			</p>
@@ -440,8 +441,8 @@
 		<div class=\"cleared\"></div>
 
 		<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-personal-education' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-personal-schools' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-personal-education' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-personal-schools' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"schools\" id=\"schools\" rows=\"2\" cols=\"75\">{$schools}</textarea>
 			</p>
@@ -450,8 +451,8 @@
 		<div class=\"cleared\"></div>
 
 		<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-personal-places' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-personal-placeslived' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-personal-places' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-personal-placeslived' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"places\" id=\"places\" rows=\"3\" cols=\"75\">{$places}</textarea>
 			</p>
@@ -460,8 +461,8 @@
 		<div class=\"cleared\"></div>
 
 		<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-personal-web' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-personal-websites' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-personal-web' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-personal-websites' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"websites\" id=\"websites\" rows=\"2\" cols=\"75\">{$websites}</textarea>
 			</p>
@@ -470,25 +471,25 @@
 		<div class=\"cleared\"></div>";
 
 		$form .= '
-			<input type="button" class="site-button" value="' . wfMsgForContent('user-profile-update-button') . '" size="20" onclick="document.profile.submit()" />
+			<input type="button" class="site-button" value="' . wfMsg( 'user-profile-update-button' ) . '" size="20" onclick="document.profile.submit()" />
 			</div></form>';
 
 		return $form;
 	}
 
 	function displayPersonalForm(){
-		global $wgRequest, $wgSiteView, $wgUser, $wgOut, $wgDBprefix;
+		global $wgRequest, $wgUser, $wgOut;
 
 		$dbr = wfGetDB( DB_MASTER );
 		$s = $dbr->selectRow( 'user_profile',
-				array(
-					'up_about', 'up_places_lived', 'up_websites', 'up_relationship',
-					'up_occupation', 'up_companies', 'up_schools', 'up_movies', 'up_tv', 'up_music',
-					'up_books', 'up_video_games', 'up_magazines', 'up_snacks', 'up_drinks'
-				),
-				array( 'up_user_id' => $wgUser->getID() ),
-				__METHOD__
-			);
+			array(
+				'up_about', 'up_places_lived', 'up_websites', 'up_relationship',
+				'up_occupation', 'up_companies', 'up_schools', 'up_movies', 'up_tv', 'up_music',
+				'up_books', 'up_video_games', 'up_magazines', 'up_snacks', 'up_drinks'
+			),
+			array( 'up_user_id' => $wgUser->getID() ),
+			__METHOD__
+		);
 
 		if ( $s !== false ) {
 			$places = $s->up_places_lived;
@@ -508,93 +509,96 @@
 
 		wfLoadExtensionMessages( 'SocialProfileUserProfile' );
 
-		$wgOut->setPageTitle( wfMsg('user-profile-section-interests') );
+		$wgOut->setPageTitle( wfMsg( 'user-profile-section-interests' ) );
 		$form = UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-interests' ) );
-		$form .= "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"profile\">
-			<div class=\"profile-info clearfix\">";
+		$form .= '<form action="" method="post" enctype="multipart/form-data" name="profile">
+			<div class="profile-info clearfix">';
 		$form .= "<div class=\"profile-update\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-interests-entertainment' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-movies' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-interests-entertainment' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-movies' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"movies\" id=\"movies\" rows=\"3\" cols=\"75\">{$movies}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-tv' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-tv' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"tv\" id=\"tv\" rows=\"3\" cols=\"75\">{$tv}</textarea>
 				</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-music' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-music' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"music\" id=\"music\" rows=\"3\" cols=\"75\">{$music}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-books' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-books' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"books\" id=\"books\" rows=\"3\" cols=\"75\">{$books}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-magazines' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-magazines' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"magazines\" id=\"magazines\" rows=\"3\" cols=\"75\">{$magazines}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-videogames' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-videogames' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"videogames\" id=\"videogames\" rows=\"3\" cols=\"75\">{$videogames}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
 			</div>
 			<div class=\"profile-info clearfix\">
-			<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-interests-eats' ) . "</p>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-foodsnacks' ) . "</p>
+			<p class=\"profile-update-title\">" . wfMsg( 'user-profile-interests-eats' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-foodsnacks' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"snacks\" id=\"snacks\" rows=\"3\" cols=\"75\">{$snacks}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
-			<p class=\"profile-update-unit-left\">" . wfMsgForContent( 'user-profile-interests-drinks' ) . "</p>
+			<p class=\"profile-update-unit-left\">" . wfMsg( 'user-profile-interests-drinks' ) . "</p>
 			<p class=\"profile-update-unit\">
 				<textarea name=\"drinks\" id=\"drinks\" rows=\"3\" cols=\"75\">{$drinks}</textarea>
 			</p>
 			<div class=\"cleared\"></div>
 			</div>
-			<input type=\"button\" class=\"site-button\" value=" . wfMsgForContent( 'user-profile-update-button' ) . " size=\"20\" onclick=\"document.profile.submit()\" />
+			<input type=\"button\" class=\"site-button\" value=" . wfMsg( 'user-profile-update-button' ) . " size=\"20\" onclick=\"document.profile.submit()\" />
 			</div>
-			</form>
-			";
+			</form>";
 
 		return $form;
 	}
 
 	function displayPreferencesForm(){
-		global $wgRequest, $wgSiteView, $wgUser, $wgOut;
+		global $wgUser, $wgOut;
 
 		wfLoadExtensionMessages( 'SocialProfileUserProfile' );
 
-		// FIXME: if the checkboxes are in front of the option, this will look more like Special:Preferences
-		$wgOut->setPageTitle( wfMsg('user-profile-section-preferences') );
+		// @todo If the checkboxes are in front of the option, this would look more like Special:Preferences
+		$wgOut->setPageTitle( wfMsg( 'user-profile-section-preferences' ) );
 		$form = UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-preferences' ) );
-		$form .= '<form action="" method="post" enctype="multipart/form-data" name=profile>';
+		$form .= '<form action="" method="post" enctype="multipart/form-data" name="profile">';
 		$form .= '<div class="profile-info clearfix">
 			<div class="profile-update">
-				<p class="profile-update-title">' . wfMsgForContent( 'user-profile-preferences-emails' ) . '</p>
+				<p class="profile-update-title">' . wfMsg( 'user-profile-preferences-emails' ) . '</p>
 				<p class="profile-update-row">
-					' . wfMsgForContent( 'user-profile-preferences-emails-personalmessage' ) . ' <input type="checkbox" size="25" name="notify_message" id="notify_message" value="1"' . (($wgUser->getIntOption( 'notifymessage',1 ) == 1)?'checked':'') . '/>
+					' . wfMsg( 'user-profile-preferences-emails-personalmessage' ) . ' 
+					<input type="checkbox" size="25" name="notify_message" id="notify_message" value="1"' . ( ( $wgUser->getIntOption( 'notifymessage', 1 ) == 1 ) ? 'checked' : '' ) . '/>
 				</p>
 				<p class="profile-update-row">
-					' . wfMsgForContent( 'user-profile-preferences-emails-friendfoe' ) . ' <input type="checkbox" size="25" class="createbox" name="notify_friend" id="notify_friend" value="1" ' . (($wgUser->getIntOption( 'notifyfriendrequest',1) == 1)?'checked':'') . '/>
+					' . wfMsg( 'user-profile-preferences-emails-friendfoe' ) . ' 
+					<input type="checkbox" size="25" class="createbox" name="notify_friend" id="notify_friend" value="1" ' . ( ( $wgUser->getIntOption( 'notifyfriendrequest', 1 ) == 1 ) ? 'checked' : '' ) . '/>
 				</p>
 				<p class="profile-update-row">
-					' . wfMsgForContent( 'user-profile-preferences-emails-gift' ) . ' <input type="checkbox" size="25" name="notify_gift" id="notify_gift" value="1" ' . (($wgUser->getIntOption( 'notifygift',1 ) == 1)?'checked':'') . '/>
+					' . wfMsg( 'user-profile-preferences-emails-gift' ) . ' 
+					<input type="checkbox" size="25" name="notify_gift" id="notify_gift" value="1" ' . ( ( $wgUser->getIntOption( 'notifygift', 1 ) == 1 ) ? 'checked' : '' ) . '/>
 				</p>
 
 				<p class="profile-update-row">
-					' . wfMsgForContent( 'user-profile-preferences-emails-level' ) . ' <input type="checkbox" size="25" name="notify_honorifics" id="notify_honorifics" value="1"' . (($wgUser->getIntOption( 'notifyhonorifics',1 ) == 1)?'checked':'') . '/>
+					' . wfMsg( 'user-profile-preferences-emails-level' ) . ' 
+					<input type="checkbox" size="25" name="notify_honorifics" id="notify_honorifics" value="1"' . ( ( $wgUser->getIntOption( 'notifyhonorifics', 1 ) == 1 ) ? 'checked' : '' ) . '/>
 				</p>';
 
 		$form .= '</div>
 			<div class="cleared"></div>';
-		$form .= '<input type="button" class="site-button" value="' . wfMsgForContent('user-profile-update-button') . '" size="20" onclick="document.profile.submit()" />
+		$form .= '<input type="button" class="site-button" value="' . wfMsg( 'user-profile-update-button' ) . '" size="20" onclick="document.profile.submit()" />
 			</form>';
 		$form .= '</div>';
 
@@ -602,7 +606,7 @@
 	}
 
 	function displayCustomForm(){
-		global $wgRequest, $wgSiteView, $wgUser, $wgOut, $wgDBprefix;
+		global $wgRequest, $wgUser, $wgOut;
 
 		$dbr = wfGetDB( DB_MASTER );
 		$s = $dbr->selectRow( 'user_profile',
@@ -622,8 +626,8 @@
 
 		wfLoadExtensionMessages( 'SocialProfileUserProfile' );
 
-		$wgOut->setHTMLTitle( wfMsg('pagetitle', wfMsg('user-profile-tidbits-title')));
-		$form =  '<h1>'.wfMsg('user-profile-tidbits-title').'</h1>';
+		$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'user-profile-tidbits-title' ) ) );
+		$form = '<h1>' . wfMsg( 'user-profile-tidbits-title' ) . '</h1>';
 		$form .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-custom' ) );
 		$form .= "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"profile\">
 		 	<div class=\"profile-info clearfix\">
@@ -656,4 +660,4 @@
 
 		return $form;
 	}
-}
+}
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php
===================================================================
--- trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php	(revision 49173)
+++ trunk/extensions/SocialProfile/UserProfile/SpecialUploadAvatar.php	(revision 49174)
@@ -49,7 +49,7 @@
 		$wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg('user-profile-picture-title') ) );
 
 		$wgOut->addStyle( '../..' . $wgUserProfileScripts . '/UserProfile.css' );
-		$this->initAvatar($wgRequest);
+		$this->initAvatar( $wgRequest );
 		$this->executeAvatar();
 	}
 
@@ -69,7 +69,7 @@
 		$this->mUploadCopyStatus  = $request->getText( 'wpUploadCopyStatus' );
 		$this->mUploadSource      = $request->getText( 'wpUploadSource' );
 		$this->mWatchthis         = $request->getBool( 'wpWatchthis' );
-		wfDebug( "UploadForm: watchthis is: '$this->mWatchthis'\n" );
+		wfDebug( __METHOD__ . ": watchthis is: '$this->mWatchthis'\n" );
 
 		$this->mAction            = $request->getVal( 'action' );
 		$this->mSessionKey        = $request->getInt( 'wpSessionKey' );
@@ -99,10 +99,10 @@
 	}
 
 	function getAvatar( $size ){
-		global $wgUser, $wgDBname,$wgUploadDirectory, $wgUploadPath;
-		$files = glob($wgUploadDirectory . "/avatars/" . $wgDBname . "_" . $wgUser->getID() .  "_" . $size . "*");
+		global $wgUser, $wgDBname, $wgUploadDirectory, $wgUploadPath;
+		$files = glob( $wgUploadDirectory . '/avatars/' . $wgDBname . '_' . $wgUser->getID() . '_' . $size . "*" );
 		if( isset( $files[0] ) && $files[0] ){
-			return "<img src=\"{$wgUploadPath}/avatars/" .  basename($files[0]) . "\" alt=\"\" border=\"0\">";
+			return "<img src=\"{$wgUploadPath}/avatars/" . basename( $files[0] ) . "\" alt=\"\" border=\"0\" />";
 		}
 	}
 
@@ -111,7 +111,7 @@
 	 */
 	public function executeAvatar() {
 		global $wgUser, $wgOut, $wgEnableUploads, $wgUploadDirectory;
-		$this->avatarUploadDirectory = $wgUploadDirectory . "/avatars";
+		$this->avatarUploadDirectory = $wgUploadDirectory . '/avatars';
 		/** Show an error message if file upload is disabled */
 		if( !$wgEnableUploads ) {
 			$wgOut->addWikiMsg( 'uploaddisabled' );
@@ -157,7 +157,7 @@
 		* If there was no filename or a zero size given, give up quick.
 		*/
 		if( trim( $this->mOname ) == '' || empty( $this->mUploadSize ) ) {
-			return $this->mainUploadForm('<li>'.wfMsg( 'emptyfile' ).'</li>');
+			return $this->mainUploadForm( '<li>'.wfMsg( 'emptyfile' ).'</li>' );
 		}
 
 		# Chop off any directories in the given filename
@@ -198,7 +198,7 @@
 		 * probably not accept it.
 		 */
 		if( !$this->mStashed ) {
-			$veri = $this->verify($this->mUploadTempName, $finalExt);
+			$veri = $this->verify( $this->mUploadTempName, $finalExt );
 
 			if( $veri !== true ) { //it's a wiki error...
 				return $this->uploadError( $veri->toString() );
@@ -230,7 +230,7 @@
 
 			}
 			if ( $this->mUploadSize == 0 ) {
-				$warning .= '<li>'.wfMsg( 'emptyfile' ).'</li>';
+				$warning .= '<li>' . wfMsg( 'emptyfile' ) . '</li>';
 			}
 
 			if( $warning != '' ) {
@@ -238,7 +238,7 @@
 				 * Stash the file in a temporary location; the user can choose
 				 * to let it through and we'll complete the upload then.
 				 */
-				return $this->uploadWarning($warning);
+				return $this->uploadWarning( $warning );
 			}
 		}
 
@@ -250,20 +250,26 @@
 		$status = $this->saveUploadedFile( $this->mUploadSaveName, $this->mUploadTempName, strtoupper($fullExt) );
 
 		if( $status > 0 ) {
-			$this->showSuccess($status);
+			$this->showSuccess( $status );
 		}
 	}
 
 	function createThumbnail( $imageSrc, $ext, $imgDest, $thumbWidth ){
-		list($origWidth, $origHeight, $TypeCode) = getimagesize($imageSrc);
+		list( $origWidth, $origHeight, $TypeCode ) = getimagesize( $imageSrc );
 
-		if($origWidth < $thumbWidth)$thumbWidth = $origWidth;
-		$thumbHeight = ($thumbWidth * $origHeight / $origWidth);
-		if($thumbHeight < $thumbWidth)$border = " -bordercolor white  -border  0x" . (($thumbWidth - $thumbHeight) / 2);
-		// FIXME: Notice: Undefined variable: border		
-		if($TypeCode == 2)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0   -quality 100 " . $border . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".jpg");
-		if($TypeCode == 1)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0 " . $imageSrc . " " . $border . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".gif");
-		if($TypeCode == 3)exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0 " . $imageSrc . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".png");
+		if( $origWidth < $thumbWidth )
+			$thumbWidth = $origWidth;
+		$thumbHeight = ( $thumbWidth * $origHeight / $origWidth );
+		$border = ' -bordercolor white  -border  0x';
+		if( $thumbHeight < $thumbWidth ){
+			$border = " -bordercolor white  -border  0x" . ( ( $thumbWidth - $thumbHeight ) / 2 );
+		}
+		if( $TypeCode == 2 )
+			exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0   -quality 100 " . $border . " " . $imageSrc . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".jpg");
+		if( $TypeCode == 1 )
+			exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0 " . $imageSrc . " " . $border . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".gif");
+		if( $TypeCode == 3 )
+			exec("convert -size " . $thumbWidth . "x" . $thumbWidth . " -resize " . $thumbWidth . " -crop " . $thumbWidth . "x" . $thumbWidth . "+0+0 " . $imageSrc . " " . $this->avatarUploadDirectory . "/" . $imgDest . ".png");
 	}
 
 	/**
@@ -286,41 +292,53 @@
 		$avatar = new wAvatar( $wgUser->getID(), 'l' );
 		if ( strpos( $avatar->getAvatarImage(), 'default_' ) !== false ) {
 			$stats = new UserStatsTrack( $wgUser->getID(), $wgUser->getName() );
-			$stats->incStatField('user_image');
+			$stats->incStatField( 'user_image' );
 		}
 		$this->mSavedFile = "{$dest}/{$saveName}";
-		$this->createThumbnail($tempName, $ext, $wgDBname . "_" . $wgUser->mId . "_l", 75);
-		$this->createThumbnail($tempName, $ext, $wgDBname . "_" . $wgUser->mId . "_ml", 50);
-		$this->createThumbnail($tempName, $ext, $wgDBname . "_" . $wgUser->mId . "_m", 30);
-		$this->createThumbnail($tempName, $ext, $wgDBname . "_" . $wgUser->mId . "_s", 16);
+		$this->createThumbnail( $tempName, $ext, $wgDBname . '_' . $wgUser->mId . '_l', 75 );
+		$this->createThumbnail( $tempName, $ext, $wgDBname . '_' . $wgUser->mId . '_ml', 50 );
+		$this->createThumbnail( $tempName, $ext, $wgDBname . '_' . $wgUser->mId . '_m', 30 );
+		$this->createThumbnail( $tempName, $ext, $wgDBname . '_' . $wgUser->mId . '_s', 16 );
 
-		if( $ext == "JPG" && is_file( $this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.jpg" ) ){
+		if( $ext == "JPG" && is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.jpg' ) ){
 			$type = 2;
-		}
-		if( $ext == "GIF" && is_file( $this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.gif" ) ){
+		} else if( $ext == "GIF" && is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.gif' ) ){
 			$type = 1;
-		}
-		if( $ext == "PNG" && is_file( $this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.png" ) ){
+		} else if( $ext == "PNG" && is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.png' ) ){
 			$type = 3;
+		} else if( $type < 0 ){
+			$wgOut->fileCopyError( $tempName, $stash );
 		}
 
 		if( $ext != "JPG" ){
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.jpg") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.jpg");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.jpg") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.jpg");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.jpg") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.jpg");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.jpg") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.jpg");
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.jpg' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.jpg' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.jpg' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.jpg' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.jpg' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.jpg' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.jpg' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.jpg' );
 		}
 		if( $ext != "GIF" ){
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.gif") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.gif");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.gif") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.gif");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.gif") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.gif");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.gif") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.gif");
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.gif' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.gif' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.gif' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.gif' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.gif' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.gif' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.gif' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.gif' );
 		}
 		if( $ext != "PNG" ){
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.png") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_s.png");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.png") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_m.png");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.png") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_l.png");
-			if( is_file($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.png") ) unlink($this->avatarUploadDirectory . "/" . $wgDBname . "_" . $wgUser->mId . "_ml.png");
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.png' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_s.png' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.png' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_m.png' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.png' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_l.png' );
+			if( is_file( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.png' ) )
+				unlink( $this->avatarUploadDirectory . '/' . $wgDBname . '_' . $wgUser->mId . '_ml.png' );
 		}
 		global $wgMemc;
 		$key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID(), 's' );
@@ -334,15 +352,7 @@
 
 		$key = wfMemcKey( 'user', 'profile', 'avatar', $wgUser->getID() , 'ml' );
 		$data = $wgMemc->delete( $key );
-		// FIXME: Notice: Undefined variable: type
-		if( $type > 0 ){
-			//$dbr = wfGetDB( DB_SLAVE );
-			//$sql = "UPDATE user set user_avatar = " . $type . " WHERE user_id = " . $wgUser->mId;
-			//$res = $dbr->query($sql);
-		} else {
-			// FIXME: Notice: Undefined variable: stash
-			$wgOut->fileCopyError( $tempName, $stash );
-		}
+
 		return $type;
 	}
 
@@ -427,50 +437,49 @@
 
 		$ext = 'jpg';
 
-		$output = '';
-		$output .= '<h1>'.wfMsg( 'user-profile-picture-title' ).'</h1>';
+		$output = '<h1>'.wfMsg( 'user-profile-picture-title' ).'</h1>';
 		$output .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-picture' ) );
 		$output .= '<div class="profile-info">';
-		$output .= '<p class="profile-update-title">' . wfMsgForContent( 'user-profile-picture-yourpicture' ) . '</p>';
-		$output .= '<p>' . wfMsgForContent( 'user-profile-picture-yourpicturestext' ) . '</p>';
+		$output .= '<p class="profile-update-title">' . wfMsg( 'user-profile-picture-yourpicture' ) . '</p>';
+		$output .= '<p>' . wfMsg( 'user-profile-picture-yourpicturestext' ) . '</p>';
 		if( $status == 1 ) $ext = 'gif';
 		if( $status == 2 ) $ext = 'jpg';
 		if( $status == 3 ) $ext = 'png';
 
 		$output .= '<table cellspacing="0" cellpadding="0" style="margin-top:20px;">';
 		$output .= "<tr>
-			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsgForContent( 'user-profile-picture-large' ) . "</td>
+			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsg( 'user-profile-picture-large' ) . "</td>
 			<td style='padding-bottom:20px;'>
-				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_l." . $ext . "?ts=" .  rand()   . "\" alt=\"\" border=\"0\"/>
+				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_l." . $ext . "?ts=" . rand() . "\" alt=\"\" border=\"0\"/>
 			</td>
 		</tr>";
 		$output .= "<tr>
-			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsgForContent( 'user-profile-picture-medlarge' ) . "</td>
+			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsg( 'user-profile-picture-medlarge' ) . "</td>
 			<td style='padding-bottom:20px;'>
-				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_ml." . $ext . "?ts=" .  rand()   . "\" alt=\"\" border=\"0\"/>
+				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_ml." . $ext . "?ts=" . rand() . "\" alt=\"\" border=\"0\"/>
 			</td>
 		</tr>";
 		$output .= "<tr>
-			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsgForContent( 'user-profile-picture-medium' ) . "</td>
+			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsg( 'user-profile-picture-medium' ) . "</td>
 			<td style='padding-bottom:20px;'>
-				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_m." . $ext . "?ts=" .  rand()   . "\" alt=\"\" border=\"0\"/>
+				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_m." . $ext . "?ts=" . rand() . "\" alt=\"\" border=\"0\"/>
 			</td>
 		</tr>";
 		$output .= "<tr>
-			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsgForContent( 'user-profile-picture-small' ) . "</td>
+			<td valign=top style='color:#797979;font-size:12px;font-weight:bold;padding-bottom:20px;'>" . wfMsg( 'user-profile-picture-small' ) . "</td>
 			<td style='padding-bottom:20px;'>
-				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_s." . $ext . "?ts" .  rand()   . "\" alt=\"\" border=\"0\"/>
+				<img src=\"{$wgUploadPath}/avatars/" . $wgDBname . "_" . $wgUser->mId . "_s." . $ext . "?ts" . rand() . "\" alt=\"\" border=\"0\" />
 			</td>
 		</tr>";
 		$output .= '<tr>
 			<td>
-				<input type="button" onclick="javascript:history.go(-1)" class="site-button" value="' . wfMsgForContent( 'user-profile-picture-uploaddifferent' ) . '">
+				<input type="button" onclick="javascript:history.go(-1)" class="site-button" value="' . wfMsg( 'user-profile-picture-uploaddifferent' ) . '" />
 			</td>
 		</tr>';
 		$output .= '</table>';
 		$output .= '</div>';
 
-		$wgOut->addHTML($output);
+		$wgOut->addHTML( $output );
 	}
 
 	/**
@@ -483,7 +492,7 @@
 		$sub = wfMsg( 'uploadwarning' );
 		$wgOut->addHTML( "<h2>{$sub}</h2>\n" );
 		$wgOut->addHTML( "<h4 class='error'>{$error}</h4>\n" );
-		$wgOut->addHTML( '<br /><input type="button" onclick="javascript:history.go(-1)" value="' . wfMsgForContent( 'user-profile-goback' ) . '"/>' );
+		$wgOut->addHTML( '<br /><input type="button" onclick="javascript:history.go(-1)" value="' . wfMsg( 'user-profile-goback' ) . '"/>' );
 	}
 
 	/**
@@ -604,15 +613,15 @@
 		$output .= UserProfile::getEditProfileNav( wfMsg( 'user-profile-section-picture' ) );
 		$output .= '<div class="profile-info">';
 
-		if( $this->getAvatar('l') != '' ){
+		if( $this->getAvatar( 'l' ) != '' ){
 			$output .= '<table>
 				<tr>
 					<td>
-						<p class="profile-update-title">' . wfMsgForContent( 'user-profile-picture-currentimage' ) . '</p>
+						<p class="profile-update-title">' . wfMsg( 'user-profile-picture-currentimage' ) . '</p>
 					</td>
 				</tr>';
 				$output .= '<tr>
-					<td>' . $this->getAvatar('l') . '</td>
+					<td>' . $this->getAvatar( 'l' ) . '</td>
 				</tr>
 			</table>';
 		}
@@ -621,8 +630,8 @@
 			<table border='0'>
 				<tr>
 					<td>
-						<p class=\"profile-update-title\">" . wfMsgForContent( 'user-profile-picture-choosepicture' ) . "</p>
-						<p style=\"margin-bottom:10px;\">" . wfMsgForContent( 'user-profile-picture-picsize' ) . "</p>
+						<p class=\"profile-update-title\">" . wfMsg( 'user-profile-picture-choosepicture' ) . "</p>
+						<p style=\"margin-bottom:10px;\">" . wfMsg( 'user-profile-picture-picsize' ) . "</p>
 						<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile'  size='36'/>
 						</td>
 				</tr>
@@ -639,7 +648,7 @@
 
 		$output .= '</div>';
 
-		$wgOut->addHTML($output);
+		$wgOut->addHTML( $output );
 	}
 
 	/**
@@ -695,10 +704,8 @@
 	function verify( $tmpfile, $extension ) {
 		#magically determine mime type
 		$magic = & wfGetMimeMagic();
-		$mime = $magic->guessMimeType($tmpfile, false);
+		$mime = $magic->guessMimeType( $tmpfile, false );
 
-		$fname = "SpecialUploadAvatar::verify";
-
 		#check mime type, if desired
 		global $wgVerifyMimeType;
 		if ( $wgVerifyMimeType ) {
@@ -710,7 +717,7 @@
 
 			#check mime type blacklist
 			global $wgMimeTypeBlacklist;
-			if( isset($wgMimeTypeBlacklist) && !is_null($wgMimeTypeBlacklist)
+			if( isset( $wgMimeTypeBlacklist ) && !is_null( $wgMimeTypeBlacklist )
 				&& $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
 				return new WikiErrorMsg( 'badfiletype', htmlspecialchars( $mime ) );
 			}
@@ -724,12 +731,12 @@
 		/**
 		* Scan the uploaded file for viruses
 		*/
-		$virus = $this->detectVirus($tmpfile);
+		$virus = $this->detectVirus( $tmpfile );
 		if ( $virus ) {
-			return new WikiErrorMsg( 'uploadvirus', htmlspecialchars($virus) );
+			return new WikiErrorMsg( 'uploadvirus', htmlspecialchars( $virus ) );
 		}
 
-		wfDebug( "$fname: all clear; passing.\n" );
+		wfDebug( __METHOD__ . ": all clear; passing.\n" );
 		return true;
 	}
 
@@ -741,32 +748,28 @@
 	 * @return bool
 	 */
 	function verifyExtension( $mime, $extension ) {
-		$fname = 'SpecialUploadAvatar::verifyExtension';
-
 		$magic =& wfGetMimeMagic();
 
-		if ( ! $mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
-			if ( ! $magic->isRecognizableExtension( $extension ) ) {
-				wfDebug( "$fname: passing file with unknown detected mime type; unrecognized extension '$extension', can't verify\n" );
+		if ( !$mime || $mime == 'unknown' || $mime == 'unknown/unknown' )
+			if ( !$magic->isRecognizableExtension( $extension ) ) {
+				wfDebug( __METHOD__ . ": passing file with unknown detected mime type; unrecognized extension '$extension', can't verify\n" );
 				return true;
 			} else {
-				wfDebug( "$fname: rejecting file with unknown detected mime type; recognized extension '$extension', so probably invalid file\n" );
+				wfDebug( __METHOD__ . ": rejecting file with unknown detected mime type; recognized extension '$extension', so probably invalid file\n" );
 				return false;
 			}
 
-		$match = $magic->isMatchingExtension($extension,$mime);
+		$match = $magic->isMatchingExtension( $extension, $mime );
 
 		if ( $match === NULL ) {
-			wfDebug( "$fname: no file extension known for mime type $mime, passing file\n" );
+			wfDebug( __METHOD__ . ": no file extension known for mime type $mime, passing file\n" );
 			return true;
 		} elseif ( $match === true ) {
-			wfDebug( "$fname: mime type $mime matches extension $extension, passing file\n" );
-
+			wfDebug( __METHOD__ . ": mime type $mime matches extension $extension, passing file\n" );
 			#TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it!
 			return true;
-
 		} else {
-			wfDebug( "$fname: mime type $mime mismatches file extension $extension, rejecting file\n" );
+			wfDebug( __METHOD__ . ": mime type $mime mismatches file extension $extension, rejecting file\n" );
 			return false;
 		}
 	}
@@ -781,12 +784,12 @@
 	 * @return bool true if the file contains something looking like embedded scripts
 	 */
 	function detectScript( $file, $mime ) {
-
 		#ugly hack: for text files, always look at the entire file.
 		#For binarie field, just check the first K.
 
-		if( strpos($mime, 'text/') === 0 ) $chunk = file_get_contents( $file );
-		else {
+		if( strpos( $mime, 'text/' ) === 0 ){
+			$chunk = file_get_contents( $file );
+		} else {
 			$fp = fopen( $file, 'rb' );
 			$chunk = fread( $fp, 1024 );
 			fclose( $fp );
@@ -801,16 +804,16 @@
 		elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) $enc = "UTF-16LE";
 		else $enc = NULL;
 
-		if ($enc) $chunk = iconv($enc, "ASCII//IGNORE", $chunk);
+		if( $enc ) $chunk = iconv( $enc, "ASCII//IGNORE", $chunk );
 
-		$chunk = trim($chunk);
+		$chunk = trim( $chunk );
 
 		#FIXME: convert from UTF-16 if necessarry!
 
-		wfDebug("SpecialUploadAvatar::detectScript: checking for embedded scripts and HTML stuff\n");
+		wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" );
 
 		#check for HTML doctype
-		if (eregi("<!DOCTYPE *X?HTML",$chunk)) return true;
+		if( eregi( "<!DOCTYPE *X?HTML", $chunk ) ) return true;
 
 		/**
 		* Internet Explorer for Windows performs some really stupid file type
@@ -853,15 +856,15 @@
 		$chunk = Sanitizer::decodeCharReferences( $chunk );
 
 		#look for script-types
-		if( preg_match("!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", $chunk) ) return true;
+		if( preg_match( "!type\s*=\s*['\"]?\s*(\w*/)?(ecma|java)!sim", $chunk ) ) return true;
 
 		#look for html-style script-urls
-		if( preg_match("!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk) ) return true;
+		if( preg_match( "!(href|src|data)\s*=\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) return true;
 
 		#look for css-style script-urls
-		if( preg_match("!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", $chunk) ) return true;
+		if( preg_match( "!url\s*\(\s*['\"]?\s*(ecma|java)script:!sim", $chunk ) ) return true;
 
-		wfDebug("SpecialUploadAvatar::detectScript: no scripts found\n");
+		wfDebug( __METHOD__ . ": no scripts found\n" );
 		return false;
 	}
 
@@ -878,15 +881,13 @@
 	function detectVirus( $file ) {
 		global $wgAntivirus, $wgAntivirusSetup, $wgAntivirusRequired;
 
-		$fname = "SpecialUploadAvatar::detectVirus";
-
 		if ( !$wgAntivirus ) { #disabled?
-			wfDebug("$fname: virus scanner disabled\n");
+			wfDebug( __METHOD__ . ": virus scanner disabled\n" );
 			return NULL;
 		}
 
 		if ( !$wgAntivirusSetup[$wgAntivirus] ) {
-			wfDebug("$fname: unknown virus scanner: $wgAntivirus\n");
+			wfDebug( __METHOD__ . ":unknown virus scanner: $wgAntivirus\n" );
 			$wgOut->addHTML( '<div class="error">' . wfMsg( 'virus-badscanner', $wgAntivirus ) . "\n" );
 			return wfMsg( 'virus-unknownscanner' ) . $wgAntivirus;
 		}
@@ -898,10 +899,13 @@
 
 		$scanner = $virus_scanner; #copy, so we can resolve the pattern
 
-		if (strpos($scanner,"%f")===false) $scanner.= " ".wfEscapeShellArg($file); #simple pattern: append file to scan
-		else $scanner= str_replace("%f",wfEscapeShellArg($file),$scanner); #complex pattern: replace "%f" with file to scan
+		if( strpos( $scanner, "%f" ) === false ){
+			$scanner.= " ".wfEscapeShellArg( $file ); #simple pattern: append file to scan
+		} else {
+			$scanner = str_replace( "%f", wfEscapeShellArg( $file ), $scanner ); #complex pattern: replace "%f" with file to scan
+		}
 
-		wfDebug("$fname: running virus scan: $scanner \n");
+		wfDebug( __METHOD__ . ": running virus scan: $scanner \n" );
 
 		#execute virus scanner
 		$code = false;
@@ -909,8 +913,11 @@
 		#NOTE: there's a 50 line workaround to make stderr redirection work on windows, too.
 		#      that does not seem to be worth the pain.
 		#      Ask me (Duesentrieb) about it if it's ever needed.
-		if ( wfIsWindows() ) exec("$scanner", $output, $code);
-		else exec("$scanner 2>&1", $output, $code);
+		if ( wfIsWindows() ){
+			exec( "$scanner", $output, $code );
+		} else {
+			exec( "$scanner 2>&1", $output, $code );
+		}
 
 		$exit_code = $code; #remeber for user feedback
 
@@ -920,29 +927,31 @@
 		}
 
 		if ( $code === AV_SCAN_FAILED ) { #scan failed (code was mapped to false by $virus_scanner_codes)
-			wfDebug("$fname: failed to scan $file (code $exit_code).\n");
-
-			if ( $wgAntivirusRequired ) return wfMsg( 'virus-scanfailed' );
-			else return NULL;
-		} else if ( $code === AV_SCAN_ABORTED ) { #scan failed because filetype is unknown (probably imune)
-			wfDebug("$fname: unsupported file type $file (code $exit_code).\n");
+			wfDebug( __METHOD__ . ": failed to scan $file (code $exit_code).\n" );
+			if ( $wgAntivirusRequired ){
+				return wfMsg( 'virus-scanfailed' );
+			} else {
+				return NULL;
+			}
+		} else if ( $code === AV_SCAN_ABORTED ) { #scan failed because filetype is unknown (probably immune)
+			wfDebug( __METHOD__ . ": unsupported file type $file (code $exit_code).\n" );
 			return NULL;
 		} else if ( $code === AV_NO_VIRUS ) {
-			wfDebug("$fname: file passed virus scan.\n");
+			wfDebug( __METHOD__ . ": file passed virus scan.\n" );
 			return false; #no virus found
 		} else {
-			$output = join("\n", $output);
-			$output = trim($output);
+			$output = join( "\n", $output );
+			$output = trim( $output );
 
 			if ( !$output ) $output = true; #if there's no output, return true
 			else if ( $msg_pattern ) {
 				$groups = array();
-				if ( preg_match($msg_pattern, $output, $groups) ) {
+				if ( preg_match( $msg_pattern, $output, $groups ) ) {
 					if( $groups[1] ) $output = $groups[1];
 				}
 			}
 
-			wfDebug("$fname: FOUND VIRUS! scanner feedback: $output");
+			wfDebug( __METHOD__ . ": FOUND VIRUS! scanner feedback: $output" );
 			return $output;
 		}
 	}
Index: trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php	(revision 49173)
+++ trunk/extensions/SocialProfile/UserGifts/UserGiftsClass.php	(revision 49174)
@@ -1,6 +1,7 @@
 <?php
 /**
- *
+ * UserGifts class
+ * @todo document
  */
 class UserGifts {
 
@@ -20,48 +21,48 @@
 	 * @private
 	 */
 	/* private */ function __construct( $username ) {
-		$title1 = Title::newFromDBkey($username);
+		$title1 = Title::newFromDBkey( $username );
 		$this->user_name = $title1->getText();
-		$this->user_id = User::idFromName($this->user_name);
+		$this->user_id = User::idFromName( $this->user_name );
 	}
 
 	public function sendGift( $user_to, $gift_id, $type, $message ){
-		$user_id_to = User::idFromName($user_to);
+		$user_id_to = User::idFromName( $user_to );
 		$dbw = wfGetDB( DB_MASTER );
 
 		$dbw->insert( 'user_gift',
-		array(
-			'ug_gift_id' => $gift_id,
-			'ug_user_id_from' => $this->user_id,
-			'ug_user_name_from' => $this->user_name,
-			'ug_user_id_to' => $user_id_to,
-			'ug_user_name_to' => $user_to,
-			'ug_type' => $type,
-			'ug_status' => 1,
-			'ug_message' => $message,
-			'ug_date' => date("Y-m-d H:i:s"),
+			array(
+				'ug_gift_id' => $gift_id,
+				'ug_user_id_from' => $this->user_id,
+				'ug_user_name_from' => $this->user_name,
+				'ug_user_id_to' => $user_id_to,
+				'ug_user_name_to' => $user_to,
+				'ug_type' => $type,
+				'ug_status' => 1,
+				'ug_message' => $message,
+				'ug_date' => date("Y-m-d H:i:s"),
 			), __METHOD__
 		);
 		$ug_gift_id = $dbw->insertId();
-		$this->incGiftGivenCount($gift_id);
-		$this->sendGiftNotificationEmail($user_id_to, $this->user_name, $gift_id, $type);
+		$this->incGiftGivenCount( $gift_id );
+		$this->sendGiftNotificationEmail( $user_id_to, $this->user_name, $gift_id, $type );
 
-		//add to new gift count cache for receiving user
-		$this->incNewGiftCount($user_id_to);
+		// Add to new gift count cache for receiving user
+		$this->incNewGiftCount( $user_id_to );
 
-		$stats = new UserStatsTrack($user_id_to, $user_to);
-		$stats->incStatField('gift_rec');
+		$stats = new UserStatsTrack( $user_id_to, $user_to );
+		$stats->incStatField( 'gift_rec' );
 
-		$stats = new UserStatsTrack($this->user_id, $this->user_name);
-		$stats->incStatField('gift_sent');
+		$stats = new UserStatsTrack( $this->user_id, $this->user_name );
+		$stats->incStatField( 'gift_sent' );
 		return $ug_gift_id;
 	}
 
 	public function sendGiftNotificationEmail( $user_id_to, $user_from, $gift_id, $type ){
-		wfLoadExtensionMessages('UserGifts');
+		wfLoadExtensionMessages( 'UserGifts' );
 
-		$gift = Gifts::getGift($gift_id);
-		$user = User::newFromId($user_id_to);
+		$gift = Gifts::getGift( $gift_id );
+		$user = User::newFromId( $user_id_to );
 		$user->loadFromDatabase();
 		if( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ){
 			$gifts_link = SpecialPage::getTitleFor( 'ViewGifts' );
@@ -69,7 +70,7 @@
 			$subject = wfMsgExt( 'gift_received_subject', 'parsemag',
 				$user_from,
 				$gift['gift_name']
-				);
+			);
 			$body = wfMsgExt( 'gift_received_body', 'parsemag',
 				( ( trim( $user->getRealName() ) ) ? $user->getRealName() : $user->getName() ),
 				$user_from,
@@ -85,26 +86,27 @@
 	public function clearAllUserGiftStatus(){
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->update( 'user_gift',
-			array( /* SET */
-			'ug_status' => 0
-			), array( /* WHERE */
-			'ug_user_id_to' => $this->user_id
-			), ""
+			/* SET */array( 'ug_status' => 0 ),
+			/* WHERE */array( 'ug_user_id_to' => $this->user_id ),
+			__METHOD__
 		);
-		$this->clearNewGiftCountCache($this->user_id);
+		$this->clearNewGiftCountCache( $this->user_id );
 	}
 
 	static function clearUserGiftStatus( $id ){
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->update( 'user_gift',
-			array( /* SET */
-			'ug_status' => 0
-			), array( /* WHERE */
-			'ug_id' => $id
-			), ""
+			/* SET */array( 'ug_status' => 0 ),
+			/* WHERE */array( 'ug_id' => $id ),
+			__METHOD__
 		);
 	}
 
+	/**
+	 * Checks if a given user owns the gift
+	 * @param $user_id Integer: user ID of the given user
+	 * @param $ug_id Integer: ID number of the gift that we're checking
+	 */
 	public function doesUserOwnGift( $user_id, $ug_id ){
 		$dbr = wfGetDB( DB_SLAVE );
 		$s = $dbr->selectRow( 'user_gift', array( 'ug_user_id_to' ), array( 'ug_id' => $ug_id ), __METHOD__ );
@@ -116,36 +118,43 @@
 		return false;
 	}
 
+	/**
+	 * Deletes a gift from the user_gift table
+	 * @param $ug_id Integer: ID number of the gift to delete
+	 */
 	static function deleteGift( $ug_id ){
-		global $wgDBprefix;
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->delete( 'user_gift', array( 'ug_id' => $ug_id ), __METHOD__ );
 	}
 
 	static function getUserGift( $id ){
-		global $wgDBprefix;
-		if( !is_numeric($id) ) return '';
+		if( !is_numeric( $id ) )
+			return '';
 
 		$dbr = wfGetDB( DB_SLAVE );
-		$sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from, ug_user_id_to,ug_user_name_to,ug_message,gift_id, ug_date,
-			ug_status,gift_name, gift_description, gift_given_count
-			FROM {$dbr->tableName( 'user_gift' )} INNER JOIN {$dbr->tableName( 'gift' )} ON ug_gift_id=gift_id  
-			WHERE ug_id = {$id} LIMIT 0,1";
-		$res = $dbr->query($sql);
+		$res = $dbr->select(
+			array( 'user_gift', 'gift' ),
+			array( 'ug_id', 'ug_user_id_from', 'ug_user_name_from', 'ug_user_id_to', 'ug_user_name_to', 'ug_message',
+				'gift_id', 'ug_date', 'ug_status', 'gift_name', 'gift_description', 'gift_given_count' ),
+			array( 'ug_id' => $id ),
+			__METHOD__,
+			array( 'LIMIT' => 1 ),
+			array( 'INNER JOIN' => array( 'gift', 'ug_gift_id=gift_id' ) )
+		);
 		$row = $dbr->fetchObject( $res );
 		if( $row ){
-			$gift['id']= $row->ug_id;
-			$gift['user_id_from']= $row->ug_user_id_from;
-			$gift['user_name_from']= $row->ug_user_name_from;
-			$gift['user_id_to']= $row->ug_user_id_to;
-			$gift['user_name_to']= $row->ug_user_name_to;
-			$gift['message']= $row->ug_message;
-			$gift['gift_count']= $row->gift_given_count;
-			$gift['timestamp']= $row->ug_date;
-			$gift['gift_id']= $row->gift_id;
-			$gift['name']= $row->gift_name;
-			$gift['description']= $row->gift_description;
-			$gift['status']= $row->ug_status;
+			$gift['id'] = $row->ug_id;
+			$gift['user_id_from'] = $row->ug_user_id_from;
+			$gift['user_name_from'] = $row->ug_user_name_from;
+			$gift['user_id_to'] = $row->ug_user_id_to;
+			$gift['user_name_to'] = $row->ug_user_name_to;
+			$gift['message'] = $row->ug_message;
+			$gift['gift_count'] = $row->gift_given_count;
+			$gift['timestamp'] = $row->ug_date;
+			$gift['gift_id'] = $row->gift_id;
+			$gift['name'] = $row->gift_name;
+			$gift['description'] = $row->gift_description;
+			$gift['status'] = $row->ug_status;
 		}
 
 		return $gift;
@@ -167,7 +176,6 @@
 		global $wgMemc;
 		$key = wfMemcKey( 'user_gifts', 'new_count', $this->user_id );
 		$wgMemc->set( $key, 0 );
-		//$wgMemc->delete($key);
 	}
 
 	static function getNewGiftCountCache( $user_id ){
@@ -181,49 +189,50 @@
 	}
 
 	static function getNewGiftCount( $user_id ){
-		global $wgMemc;
-		$data = self::getNewGiftCountCache($user_id);
+		$data = self::getNewGiftCountCache( $user_id );
 
 		if( $data != '' ){
 			$count = $data;
 		} else {
-			$count = self::getNewGiftCountDB($user_id);
-		}	
+			$count = self::getNewGiftCountDB( $user_id );
+		}
 		return $count;
 	}
-	
+
 	static function getNewGiftCountDB( $user_id ){
 		wfDebug( "Got new gift count for id $user_id from DB\n" );
 
 		global $wgMemc;
 		$key = wfMemcKey( 'user_gifts', 'new_count', $user_id );
-		$dbr = wfGetDB( DB_MASTER );
+		$dbr = wfGetDB( DB_SLAVE );
 		$new_gift_count = 0;
 		$s = $dbr->selectRow( 'user_gift', array( 'count(*) AS count' ), array( 'ug_user_id_to' => $user_id, 'ug_status' => 1 ), __METHOD__ );
-		if ( $s !== false ) $new_gift_count = $s->count;
+		if( $s !== false )
+			$new_gift_count = $s->count;
 
-		$wgMemc->set($key, $new_gift_count);
+		$wgMemc->set( $key, $new_gift_count );
 
 		return $new_gift_count;
 	}
-	
+
 	public function getUserGiftList( $type, $limit = 0, $page = 0 ){
 		$dbr = wfGetDB( DB_SLAVE );
 
 		if( $limit > 0 ){
-			$limitvalue = 0;
-			if( $page ) $limitvalue = $page * $limit - ($limit); 
-			$limit_sql = " LIMIT {$limitvalue},{$limit} ";
+			if( $page )
+				$limit = $page * $limit - ($limit);
 		}
 
-		$sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from, ug_gift_id, ug_date, ug_status,
-			gift_name, gift_description, gift_given_count, UNIX_TIMESTAMP(ug_date) AS unix_time
-			FROM {$dbr->tableName( 'user_gift' )} INNER JOIN {$dbr->tableName( 'gift' )} ON ug_gift_id=gift_id 
-			WHERE ug_user_id_to = {$this->user_id}
-			ORDER BY ug_id DESC
-			{$limit_sql}";
+		$res = $dbr->select(
+			array( 'user_gift', 'gift' ),
+			array( 'ug_id', 'ug_user_id_from', 'ug_user_name_from', 'ug_gift_id', 'ug_date', 'ug_status',
+					'gift_name', 'gift_description', 'gift_given_count', 'UNIX_TIMESTAMP(ug_date) AS unix_time' ),
+			array( 'ug_user_id_to' => $this->user_id ),
+			__METHOD__,
+			array( 'ORDER BY' => 'ug_id DESC', 'LIMIT' => $limit ),
+			array( 'gift' => array( 'INNER JOIN', 'ug_gift_id=gift_id' ) )
+		);
 
-		$res = $dbr->query($sql);
 		$requests = array();
 		while( $row = $dbr->fetchObject( $res ) ) {
 			$requests[] = array(
@@ -246,18 +255,20 @@
 		$dbr = wfGetDB( DB_SLAVE );
 
 		if( $limit > 0 ){
-			$limitvalue = 0;
-			if( $page ) $limitvalue = $page * $limit - ($limit);
-			$limit_sql = " LIMIT {$limitvalue},{$limit} ";
+			if( $page )
+				$limit = $page * $limit - ($limit);
 		}
 
-		$sql = "SELECT ug_id, ug_user_id_from, ug_user_name_from, ug_gift_id, ug_date, ug_status,
-			gift_name, gift_description, gift_given_count, UNIX_TIMESTAMP(ug_date) AS unix_time
-			FROM {$dbr->tableName( 'user_gift' )} INNER JOIN {$dbr->tableName( 'gift' )} ON ug_gift_id=gift_id 
-			ORDER BY ug_id DESC
-			{$limit_sql}";
+		$res = $dbr->select(
+			array( 'user_gift', 'gift' ),
+			array( 'ug_id', 'ug_user_id_from', 'ug_user_name_from', 'ug_gift_id', 'ug_date', 'ug_status',
+					'gift_name', 'gift_description', 'gift_given_count', 'UNIX_TIMESTAMP(ug_date) AS unix_time' ),
+			array(),
+			__METHOD__,
+			array( 'ORDER BY' => 'ug_id DESC', 'LIMIT' => $limit ),
+			array( 'gift' => array( 'INNER JOIN', 'ug_gift_id=gift_id' ) )
+		);
 
-		$res = $dbr->query($sql);
 		$requests = array();
 		while( $row = $dbr->fetchObject( $res ) ) {
 			$requests[] = array(
@@ -281,17 +292,19 @@
 		$dbw->update( 'gift',
 			array( 'gift_given_count=gift_given_count+1' ),
 			array( 'gift_id' => $gift_id ),
-			__METHOD__ );
+			__METHOD__
+		);
 	}
 
 	static function getGiftCountByUsername( $user_name ){
 		$dbr = wfGetDB( DB_SLAVE );
-		$user_id = User::idFromName($user_name);
-		$sql = "SELECT count(*) AS count
-			FROM {$dbr->tableName( 'user_gift' )}
-			WHERE ug_user_id_to = {$user_id}
-			LIMIT 0,1";
-		$res = $dbr->query($sql);
+		$user_id = User::idFromName( $user_name );
+		$res = $dbr->select( 'user_gift',
+			array( 'COUNT(*) AS count' ),
+			array( 'ug_user_id_to' => $user_id ),
+			__METHOD__,
+			array( 'LIMIT' => 1 )
+		);
 		$row = $dbr->fetchObject( $res );
 		$gift_count = 0;
 		if( $row ){
Index: trunk/extensions/SocialProfile/UserGifts/GiftsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserGifts/GiftsClass.php	(revision 49173)
+++ trunk/extensions/SocialProfile/UserGifts/GiftsClass.php	(revision 49174)
@@ -1,6 +1,7 @@
 <?php
 /**
- *
+ * Gifts class
+ * Functions for managing individual social gifts (add to/fetch/remove from database etc.)
  */
 class Gifts {
 
@@ -23,93 +24,111 @@
 
 	}
 
+	/**
+	 * Adds a gift to the database
+	 * @param $gift_name Mixed: name of the gift, as supplied by the user
+	 * @param $gift_description Mixed: a short description about the gift, as supplied by the user
+	 * @param $gift_access Integer: 0 by default
+	 */
 	static function addGift( $gift_name, $gift_description, $gift_access = 0 ){
 		global $wgUser;
 
-		// FIXME: undefined variable user_to
-		$user_id_to = User::idFromName($user_to);
 		$dbw = wfGetDB( DB_MASTER );
 
 		$dbw->insert( 'gift',
-		array(
-			'gift_name' => $gift_name,
-			'gift_description' => $gift_description,
-			'gift_createdate' => date("Y-m-d H:i:s"),
-			'gift_creator_user_id' => $wgUser->getID(), 
-			'gift_creator_user_name' => $wgUser->getName(),
-			'gift_access' => $gift_access,
+			array(
+				'gift_name' => $gift_name,
+				'gift_description' => $gift_description,
+				'gift_createdate' => date("Y-m-d H:i:s"),
+				'gift_creator_user_id' => $wgUser->getID(), 
+				'gift_creator_user_name' => $wgUser->getName(),
+				'gift_access' => $gift_access,
 			), __METHOD__
 		);
 		return $dbw->insertId();
 	}
 
+	/**
+	 * Updates a gift's info in the database
+	 * @param $id Integer: internal ID number of the gift that we want to update
+	 * @param $gift_name Mixed: name of the gift, as supplied by the user
+	 * @param $gift_description Mixed: a short description about the gift, as supplied by the user
+	 * @param $gift_access Integer: 0 by default
+	 */
 	public function updateGift( $id, $gift_name, $gift_description, $access = 0 ){
 		$dbw = wfGetDB( DB_MASTER );
 		$dbw->update( 'gift',
-			array( /* SET */
-			'gift_name' => $gift_name,
-			'gift_description' => $gift_description,
-			'gift_access' => $access
-			), array( /* WHERE */
-			'gift_id' => $id
-			), ""
+			/* SET */array( 
+				'gift_name' => $gift_name,
+				'gift_description' => $gift_description,
+				'gift_access' => $access
+			),
+			/* WHERE */array( 'gift_id' => $id ),
+			__METHOD__
 		);
 	}
 
+	/**
+	 * Gets information, such as name and description, about a given gift from the database
+	 * @param $id Integer: internal ID number of the gift
+	 * @return Gift information, including ID number, name, description, creator's user name and ID and gift access
+	 */
 	static function getGift( $id ){
-		if( !is_numeric($id) ) return '';
+		if( !is_numeric( $id ) )
+			return '';
 		$dbr = wfGetDB( DB_SLAVE );
-		$sql = "SELECT gift_id, gift_name, gift_description,
-			gift_creator_user_id, gift_creator_user_name, gift_access
-			FROM {$dbr->tableName( 'gift' )} WHERE gift_id = {$id} LIMIT 0,1";
-		$res = $dbr->query($sql);
+		$res = $dbr->select( 'gift',
+			array( 'gift_id', 'gift_name', 'gift_description',
+					'gift_creator_user_id', 'gift_creator_user_name', 'gift_access' ),
+			array( 'gift_id' => $id ),
+			__METHOD__,
+			array( 'LIMIT' => 1 )
+		);
 		$row = $dbr->fetchObject( $res );
 		$gift = '';
 		if( $row ){
-			$gift['gift_id']= $row->gift_id;	
-			$gift['gift_name']= $row->gift_name;	
-			$gift['gift_description']= $row->gift_description;	
-			$gift['creator_user_id']= $row->gift_creator_user_id;
-			$gift['creator_user_name']= $row->gift_creator_user_name;
-			$gift['access']= $row->gift_access;
+			$gift['gift_id'] = $row->gift_id;
+			$gift['gift_name'] = $row->gift_name;
+			$gift['gift_description'] = $row->gift_description;
+			$gift['creator_user_id'] = $row->gift_creator_user_id;
+			$gift['creator_user_name'] = $row->gift_creator_user_name;
+			$gift['access'] = $row->gift_access;
 		}
 		return $gift;
 	}
 
 	static function getGiftImage( $id, $size ){
 		global $wgUploadDirectory;
-		$files = glob($wgUploadDirectory . "/awards/" . $id .  "_" . $size . "*");
+		$files = glob( $wgUploadDirectory . '/awards/' . $id .  '_' . $size . "*" );
 
 		if( !empty( $files[0] ) ) {
-			$img = basename($files[0]) ;
+			$img = basename( $files[0] );
 		} else {
-			$img = "default" . "_" . $size . ".gif";
+			$img = 'default_' . $size . '.gif';
 		}
-		return $img . "?r=" . rand();		
+		return $img . '?r=' . rand();
 	}
 
-	static function getGiftList( $limit = 0, $page = 0, $order = "gift_createdate DESC" ){
+	static function getGiftList( $limit = 0, $page = 0, $order = 'gift_createdate DESC' ){
 		global $wgUser;
 
 		$dbr = wfGetDB( DB_SLAVE );
 
 		if( $limit > 0 ){
-			$limitvalue = 0;
-			if( $page ) $limitvalue = $page * $limit - ($limit); 
-			$limit_sql = " LIMIT {$limitvalue},{$limit} ";
+			if( $page )
+				$limit = $page * $limit - ($limit);
 		}
 
-		$sql = "SELECT gift_id,gift_name,gift_description,gift_given_count
-			FROM {$dbr->tableName( 'gift' )}
-			WHERE gift_access=0 OR gift_creator_user_id = {$wgUser->getID()}
-			ORDER BY {$order}
-			{$limit_sql}";
-
-		$res = $dbr->query($sql);
+		$res = $dbr->select( 'gift',
+			array( 'gift_id', 'gift_createdate', 'gift_name', 'gift_description', 'gift_given_count' ),
+			array( "gift_access=0 OR gift_creator_user_id = {$wgUser->getID()}" ),
+			__METHOD__,
+			array( 'ORDER BY' => $order, 'LIMIT' => $limit )
+		);
 		while ( $row = $dbr->fetchObject( $res ) ) {
 			$gifts[] = array(
 				'id' => $row->gift_id,
-				'timestamp' => ($row->gift_timestamp),
+				'timestamp' => ($row->gift_createdate),
 				'gift_name' => $row->gift_name,
 				'gift_description' => $row->gift_description,
 				'gift_given_count' => $row->gift_given_count
@@ -124,16 +143,19 @@
 
 		$where = ''; // Prevent E_NOTICE
 		$params['ORDER BY'] = 'gift_createdate';
-		if( $limit ) $params['LIMIT'] = $limit;
+		if( $limit )
+			$params['LIMIT'] = $limit;
 
-		if( !in_array( 'giftadmin', ( $wgUser->getGroups() ) ) && !$wgUser->isAllowed('delete') ){
+		// If the user isn't in giftadmin group and isn't allowed to delete pages, only show them the gifts they've created
+		if( !in_array( 'giftadmin', ( $wgUser->getGroups() ) ) && !$wgUser->isAllowed( 'delete' ) ){
 			$where = array( 'gift_creator_user_id' => $wgUser->getID() );
 		}
 
-		$dbr = wfGetDB( DB_MASTER );
+		$dbr = wfGetDB( DB_SLAVE );
 		$res = $dbr->select( 'gift', 
-				array('gift_id', 'gift_name', 'gift_description', 'gift_given_count', 'gift_access', 'gift_creator_user_id', 'gift_creator_user_name'),
-			$where, __METHOD__, 
+			array( 'gift_id', 'gift_createdate', 'gift_name', 'gift_description', 'gift_given_count',
+				'gift_access', 'gift_creator_user_id', 'gift_creator_user_name' ),
+			$where, __METHOD__,
 			$params
 		);
 
@@ -141,7 +163,7 @@
 		while ( $row = $dbr->fetchObject( $res ) ) {
 			$gifts[] = array(
 				'id' => $row->gift_id,
-				'timestamp' => ($row->gift_timestamp),
+				'timestamp' => ($row->gift_createdate),
 				'gift_name' => $row->gift_name,
 				'gift_description' => $row->gift_description,
 				'gift_given_count' => $row->gift_given_count
@@ -154,7 +176,7 @@
 		$dbr = wfGetDB( DB_SLAVE );
 		$gift_count = 0;
 		$s = $dbr->selectRow( 'gift', array( 'count(*) AS count' ), array( 'gift_creator_user_id' => $user_id ), __METHOD__ );
-		if ( $s !== false ) $gift_count = $s->count;	
+		if ( $s !== false ) $gift_count = $s->count;
 		return $gift_count;
 	}
 

Follow-up revisions

RevisionCommit summaryAuthorDate
r49175SocialProfile: follow-up to r49174 - forgot to commit bugfixes in SpecialRemoveG...ashley12:34, 4 April 2009
r49176SocialProfile: partial revert of r49174 - something went wrong and broke GiveGif...ashley15:01, 4 April 2009

Comments

#Comment by Jack Phoenix (Talk | contribs)   15:04, 4 April 2009

SQL changes reverted in r49176 due to excess breakage (Special:GiveGift was totally unusable, Special:ViewGifts wasn't working properly, incorrect gift count was displayed on profile pages...).

Status & tagging log

Views
Toolbox