r34829 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r34828 | r34829 (on ViewVC) | r34830 >
Date:21:25, 14 May 2008
Author:ashley
Status:ok
Tags:
Comment:SocialProfile:
*add avatars directory with its contents so that people don't need to use an ugly, broken sourceforge release to obtain these required files
*fix sql issues when wgDBprefix was set and bad sql was generated
*fix one message loading bug where user board related messages weren't being loaded properly on user profile pages
*a bit more i18n
*standard coding style

this extension should now be quite usable (UserStatsClass.php still throws out a few errors though)
Modified paths:

Diff [purge]

Index: trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
===================================================================
--- trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php	(revision 34829)
@@ -10,7 +10,7 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
-class UserProfilePage extends Article{
+class UserProfilePage extends Article {
 
 	var $title = null;
 
@@ -242,12 +242,12 @@
 		} else if ($wgUser->getName()==$user_name) {
 			$output .= "<div class=\"user-section-heading\">
 				<div class=\"user-section-title\">
-					".wfMSg("custom-info-title")."
+					".wfMsg("custom-info-title")."
 				</div>
 				<div class=\"user-section-actions\">
 					<div class=\"action-right\">
 						<a href=\"".$edit_info_link->escapeFullURL()."/custom\">
-							".wfMSg("user-edit-this")."
+							".wfMsg("user-edit-this")."
 						</a>
 					</div>
 					<div class=\"cleared\"></div>
@@ -255,7 +255,7 @@
 			</div>
 			<div class=\"cleared\"></div>
 			<div class=\"no-info-container\">
-				".wfMSg("custom-no-info")."
+				".wfMsg("custom-no-info")."
 			</div>";
 		}
 
@@ -586,7 +586,7 @@
 						<span style=\"color:#797979;\">" . wfMsgHtml( 'userboard_messagetype' ) . "</span> <select id=\"message_type\"><option value=\"0\">" . wfMsgHtml( 'userboard_public' ) . "</option><option value=\"1\">" . wfMsgHtml( 'userboard_private' ) . "</option></select><p>
 						<textarea name=\"message\" id=\"message\" cols=\"43\" rows=\"4\"/></textarea>
 						<div class=\"user-page-message-box-button\">
-							<input type=\"button\" value=\"Send\" class=\"site-button\" onclick=\"javascript:send_message();\">
+							<input type=\"button\" value=" . wfMsg("userboard_sendbutton") . " class=\"site-button\" onclick=\"javascript:send_message();\">
 						</div>
 					</div>";
 			} else {
Index: trunk/extensions/SocialProfile/UserProfile/UserProfile.php
===================================================================
--- trunk/extensions/SocialProfile/UserProfile/UserProfile.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserProfile/UserProfile.php	(revision 34829)
@@ -1,5 +1,5 @@
 <?php
-//GLOBAL VIDEO NAMESPACE REFERENCE
+//Global profile namespace reference
 define( 'NS_USER_PROFILE', 202 );
 define( 'NS_USER_WIKI', 200 );
 
@@ -17,7 +17,7 @@
 //ArticleFromTitle
 //Calls UserProfilePage instead of standard article
 function wfUserProfileFromTitle( &$title, &$article ){
-	global $wgUser, $wgRequest, $IP, $wgOut, $wgTitle, $wgSupressPageTitle,$wgSupressSubTitle, $wgMemc,
+	global $wgUser, $wgRequest, $IP, $wgOut, $wgTitle, $wgSupressPageTitle, $wgSupressSubTitle, $wgMemc,
 	$wgUserPageChoice, $wgParser, $wgUserProfileDirectory, $wgUserProfileScripts, $wgStyleVersion;
 
 	if ( strpos( $title->getText(), "/" ) === false && ( NS_USER == $title->getNamespace() || NS_USER_PROFILE == $title->getNamespace() ) ) {
@@ -40,7 +40,7 @@
 			if( $wgRequest->getVal("action") == "edit" ){
 				$wgOut->redirect( $title->getFullURL() );
 			}
-		}else{
+		} else {
 			$wgOut->enableClientCache(false);
 			$wgParser->disableCache();
 		}
Index: trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php
===================================================================
--- trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php	(revision 34829)
@@ -212,7 +212,7 @@
 				<div class=\"cleared\"></div>
 				</div>
 				<div class=\"relationship-textbox-title\">
-				Add a Personal Message
+				".wfMsg('ur-add-personal-message')."
 				</div>
 				<textarea name=\"message\" id=\"message\" rows=\"3\" cols=\"50\"></textarea>
 				<div class=\"relationship-buttons\">
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationship.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/UserRelationship/UserRelationship.i18n.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserRelationship/UserRelationship.i18n.php	(revision 34829)
@@ -23,6 +23,7 @@
 	'ur-add-friend'                              => 'Add as friend',
 	'ur-add-foe'                                 => 'Add as foe',
 	'ur-add-no-user'                             => 'No user selected. Please request friends/foes through the correct link.',
+	'ur-add-personal-message'                    => 'Add a Personal Message',
 	'ur-remove-relationship'                     => 'Remove as $1',
 	'ur-give-gift'                               => 'Give a gift',
 	'ur-previous'                                => 'prev',
@@ -2024,3 +2025,4 @@
 	'ur-login'      => 'Đăng nhập',
 );
 
+
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php	(revision 34829)
@@ -25,7 +25,7 @@
 		$user_id_to = User::idFromName($user_to);
 		$dbr =& wfGetDB( DB_MASTER );
 		$fname = $wgDBprefix.'user_relationship_request::addToDatabase';
-		$dbr->insert( $wgDBprefix.'`user_relationship_request`',
+		$dbr->insert( '`'.$wgDBprefix.'user_relationship_request`',
 		array(
 			'ur_user_id_from' => $this->user_id,
 			'ur_user_name_from' => $this->user_name,
@@ -141,7 +141,7 @@
 		global $wgMemc, $wgDBprefix;
 
 		$dbr =& wfGetDB( DB_MASTER );
-		$s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`',
+		$s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`',
 				array( 'ur_user_id_from','ur_user_name_from','ur_type'),
 				array( 'ur_id' => $relationship_request_id ), $fname
 		);
@@ -156,7 +156,7 @@
 			}
 
 			$fname = $wgDBprefix.'user_relationship::addToDatabase';
-			$dbr->insert( $wgDBprefix.'`user_relationship`',
+			$dbr->insert( '`'.$wgDBprefix.'user_relationship`',
 			array(
 				'r_user_id' => $this->user_id,
 				'r_user_name' => $this->user_name,
@@ -168,7 +168,7 @@
 			);
 
 			$fname = $wgDBprefix.'user_relationship::addToDatabase';
-			$dbr->insert( $wgDBprefix.'`user_relationship`',
+			$dbr->insert( '`'.$wgDBprefix.'user_relationship`',
 			array(
 				'r_user_id' => $ur_user_id_from,
 				'r_user_name' => $ur_user_name_from,
@@ -247,7 +247,7 @@
 	public function updateRelationshipRequestStatus($relationship_request_id, $status){
 		global $wgDBprefix;
 		$dbw =& wfGetDB( DB_MASTER );
-		$dbw->update( $wgDBprefix.'`user_relationship_request`',
+		$dbw->update( '`'.$wgDBprefix.'user_relationship_request`',
 			array( /* SET */
 			'ur_status' => $status
 			), array( /* WHERE */
@@ -259,7 +259,7 @@
 	public function verifyRelationshipRequest($relationship_request_id){
 	global $wgDBprefix;
 		$dbr =& wfGetDB( DB_MASTER );
-		$s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`', array( 'ur_user_id_to' ), array( 'ur_id' => $relationship_request_id ), $fname );
+		$s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`', array( 'ur_user_id_to' ), array( 'ur_id' => $relationship_request_id ), $fname );
 		if ( $s !== false ) {
 			if($this->user_id == $s->ur_user_id_to){
 				return true;
@@ -280,13 +280,13 @@
 		}
 	}
 
-	static function userHasRequestByID($user1,$user2){
+	static function userHasRequestByID($user1, $user2){
 	global $wgDBprefix;
 		$dbr =& wfGetDB( DB_MASTER );
-		$s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`', array( 'ur_type' ), array( 'ur_user_id_to' => $user1, 'ur_user_id_from' => $user2, 'ur_status' => 0 ), __METHOD__ );
+		$s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`', array( 'ur_type' ), array( 'ur_user_id_to' => $user1, 'ur_user_id_from' => $user2, 'ur_status' => 0 ), __METHOD__ );
 		if ( $s === false ) {
 			return false;
-		}else{
+		} else {
 			return true;
 		}
 	}
@@ -301,7 +301,7 @@
 		while ($row = $dbr->fetchObject( $res ) ) {
 			if($row->ur_type==1){
 				$type_name = "Friend";
-			}else{
+			} else {
 				$type_name = "Foe";
 			}
 			 $request[] = array(
@@ -359,7 +359,7 @@
 		$key = wfMemcKey( 'user_relationship', 'open_request', $rel_type, $user_id );
 		$dbr =& wfGetDB( DB_SLAVE );
 		$request_count = 0;
-		$s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`', array( 'count(*) as count' ), array( 'ur_user_id_to' => $user_id, 'ur_status' => 0, 'ur_type' => $rel_type ), __METHOD__ );
+		$s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`', array( 'count(*) as count' ), array( 'ur_user_id_to' => $user_id, 'ur_status' => 0, 'ur_type' => $rel_type ), __METHOD__ );
 		if ( $s !== false )$request_count = $s->count;
 
 		$wgMemc->set($key,$request_count);
Index: trunk/extensions/SocialProfile/avatars/default_ml.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: trunk/extensions/SocialProfile/avatars/default_ml.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: trunk/extensions/SocialProfile/avatars/default_l.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: trunk/extensions/SocialProfile/avatars/default_l.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: trunk/extensions/SocialProfile/avatars/default_m.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: trunk/extensions/SocialProfile/avatars/default_m.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: trunk/extensions/SocialProfile/avatars/default_s.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: trunk/extensions/SocialProfile/avatars/default_s.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: trunk/extensions/SocialProfile/avatars/README.txt
===================================================================
--- trunk/extensions/SocialProfile/avatars/README.txt	(revision 0)
+++ trunk/extensions/SocialProfile/avatars/README.txt	(revision 34829)
@@ -0,0 +1,4 @@
+==Avatar Notes==
+Please create an avatar directory under the path for images used in your MediaWiki Installaion.  This directory should be writeable.
+
+Copy the 4 default images into the folder.  If a user does not have an avatar, these images will show up.
\ No newline at end of file

Property changes on: trunk/extensions/SocialProfile/avatars/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php	(revision 34829)
@@ -24,7 +24,7 @@
 		$user_name_from = stripslashes($user_name_from);
 		$user_name_to = stripslashes($user_name_to);
 
-		$dbr->insert( $wgDBprefix.'`user_board`',
+		$dbr->insert( '`'.$wgDBprefix.'user_board`',
 		array(
 			'ub_user_id_from' => $user_id_from,
 			'ub_user_name_from' => $user_name_from,
@@ -48,7 +48,7 @@
 		if($message_type==0){
 			//public message count
 			$stats->incStatField("user_board_count");
-		}else{
+		} else {
 			//private message count
 			$stats->incStatField("user_board_count_priv");
 		}
@@ -60,12 +60,7 @@
 	}
 
 	public function sendBoardNotificationEmail($user_id_to,$user_from){
-		require_once( "UserBoard.i18n.php" );
-		# Add messages
-		global $wgMessageCache;
-		foreach( $wgUserBoardMessages as $key => $value ) {
-			$wgMessageCache->addMessages( $wgUserBoardMessages[$key], $key );
-		}
+		wfLoadExtensionMessages( 'SocialProfileUserBoard' );
 
 		$user = User::newFromId($user_id_to);
 		$user->loadFromId();
@@ -129,7 +124,7 @@
 
 		if( $data != "" ){
 			$count = $data;
-		}else{
+		} else {
 			$count = self::getNewMessageCountDB($user_id);
 		}
 		return $count;
@@ -182,7 +177,7 @@
 			if(! ($user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID()) ){
 				$user_sql .= " and ub_type = 0 ";
 			}
-		}else{
+		} else {
 			$user_sql = "ub_user_id = {$user_id}";
 			if($user_id != $wgUser->getID() ){
 				$user_sql .= " and ub_type = 0 ";
@@ -243,15 +238,15 @@
 	public function displayMessages($user_id,$user_id_2=0,$count=10,$page=0){
 		global $wgUser,$max_link_text_length, $wgTitle;
 		$messages = $this->getUserBoardMessages($user_id,$user_id_2,$count,$page);
-
+		wfLoadExtensionMessages( 'SocialProfileUserBoard' );
 		if ($messages) {
 
 			foreach ($messages as $message) {
 				$user =  Title::makeTitle( NS_USER, $message["user_name_from"] );
 				$avatar = new wAvatar($message["user_id_from"],"m");
 
-				$board_to_board ="";
-				$board_link="";
+				$board_to_board = "";
+				$board_link = "";
 				$message_type_label = "";
 				$delete_link = "";
 				if($wgUser->getName()!=$message["user_name_from"]){
@@ -269,7 +264,7 @@
 
 				$max_link_text_length = 50;
 				$message_text = $message["message_text"];
-				$message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i",'cut_link_text',$message["message_text"]);
+				#$message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i",'cut_link_text',$message["message_text"]);
 
 				$output .= "<div class=\"user-board-message\" >
 					<div class=\"user-board-message-from\">
Index: trunk/extensions/SocialProfile/UserBoard/README.txt
===================================================================
--- trunk/extensions/SocialProfile/UserBoard/README.txt	(revision 34828)
+++ trunk/extensions/SocialProfile/UserBoard/README.txt	(revision 34829)
@@ -1,13 +1,11 @@
 Requirements
 =======================
-
-Mediawiki 1.11
+MediaWiki 1.11
 YUI
 UserStats package
 
 Installation
 =======================
-
 This assumes you have copied all the neccessary files into
 /extensions/SocialProfile/UserBoard.
 
@@ -37,4 +35,4 @@
 add the following line (changing path as neccessary)
 
 global $IP;
-require_once ("$IP/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php" );
+require_once ("$IP/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php");
Index: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/UserStatsClass.php	(revision 34828)
+++ trunk/extensions/SocialProfile/UserStats/UserStatsClass.php	(revision 34829)
@@ -5,7 +5,7 @@
 $wgUserStatsTrackWeekly = false;
 $wgUserStatsTrackMonthly = false;
 
-class UserStatsTrack{
+class UserStatsTrack {
 	//for referencing purposes
 	var $stats_fields = array(
 		"edit"=>"stats_edit_count",
@@ -97,7 +97,7 @@
 	}
 
 	function incStatField( $field, $val=1 ){
-		global $wgUser, $IP, $wgDBprefix, $wgMemc, $wgSitename,$wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues;
+		global $wgUser, $IP, $wgDBprefix, $wgMemc, $wgSitename, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues;
 		if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) {
 			$dbw = wfGetDB( DB_MASTER );
 			$dbw->update( 'user_stats',
@@ -158,7 +158,7 @@
 			$sql .= 'stats_comment_blocked=';
 			$sql .= "(SELECT COUNT(*) as CommentCount FROM Comments_block WHERE  cb_user_id_blocked = " . $this->user_id;
 			$sql .= ")";
-			$sql .= " WHERE stats_user_id = " . $this->user_id ;
+			$sql .= " WHERE stats_user_id = " . $this->user_id;
 			$res = $dbr->query($sql);
 
 			$this->clearCache();
@@ -202,12 +202,12 @@
 			$sql = "update ".$wgDBprefix."user_stats set ";
 			if($vote_type==1){
 				$sql  .= 'stats_comment_score_positive_rec=';
-			}else{
+			} else {
 				$sql  .= 'stats_comment_score_negative_rec=';
 			}
 			$sql .= "(SELECT COUNT(*) as CommentVoteCount FROM Comments_Vote WHERE Comment_Vote_ID IN (select CommentID FROM Comments WHERE Comment_user_id = " . $this->user_id . ") AND Comment_Vote_Score=" . $vote_type;
 			$sql .= ")";
-			$sql .= " WHERE stats_user_id = " . $this->user_id ;
+			$sql .= " WHERE stats_user_id = " . $this->user_id;
 			$res = $dbr->query($sql);
 
 			$this->clearCache();
@@ -217,7 +217,7 @@
 	function updateCreatedOpinionsCount(){
 		global $wgUser, $wgOut, $wgDBprefix;
 		if( !$wgUser->isAnon() && $this->user_id) {
-			$ctg = "Opinions by User " .  ($this->user_name) ;
+			$ctg = "Opinions by User " .  ($this->user_name);
 			$parser = new Parser();
 			$CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions() ) );
 			$CtgTitle = $CtgTitle->getDbKey();
@@ -225,7 +225,7 @@
 			$sql = "update ".$wgDBprefix."user_stats set stats_opinions_created=";
 			$sql .= "(SELECT count(*) as CreatedOpinions FROM {$dbr->tableName( 'page' )} INNER JOIN {$dbr->tableName( 'categorylinks' )} ON page_id = cl_from WHERE  (cl_to) = " . $dbr->addQuotes($CtgTitle) . " ";
 			$sql .= ")";
-			$sql .= " WHERE stats_user_id = " . $this->user_id ;
+			$sql .= " WHERE stats_user_id = " . $this->user_id;
 
 			$res = $dbr->query($sql);
 
@@ -243,7 +243,7 @@
 		$sql = "update ".$wgDBprefix."user_stats set stats_opinions_published = ";
 		$sql .= "(SELECT count(*) as PromotedOpinions FROM {$dbr->tableName( 'page' )} INNER JOIN {$dbr->tableName( 'categorylinks' )} ON page_id = cl_from INNER JOIN published_page ON page_id=published_page_id WHERE  (cl_to) = " . $dbr->addQuotes($CtgTitle) . " AND published_type=1 " . " " . $timeSQL;
 		$sql .= ")";
-		$sql .= " WHERE stats_user_id = " . $this->user_id ;
+		$sql .= " WHERE stats_user_id = " . $this->user_id;
 		$res = $dbr->query($sql);
 
 		$this->clearCache();
@@ -255,7 +255,7 @@
 			$dbr = wfGetDB( DB_MASTER );
 			if($rel_type==1){
 				$col="stats_friends_count";
-			}else{
+			} else {
 				$col="stats_foe_count";
 			} //Where is low_priority? where was this table created? 
 			$sql = "update low_priority ".$wgDBprefix."user_stats set {$col}=
@@ -268,7 +268,7 @@
 	}
 
 	function updateGiftCountRec(){
-		global $wgUser,$wgStatsStartTimestamp, $wgDBprefix;
+		global $wgUser, $wgStatsStartTimestamp, $wgDBprefix;
 		if( !$wgUser->isAnon() ) {
 			$dbr = wfGetDB( DB_MASTER );
 			$sql = "update low_priority ".$wgDBprefix."user_stats set stats_gifts_rec_count=
@@ -368,7 +368,7 @@
 
 		$dbr =& wfGetDB( DB_MASTER );
 		$sql = "SELECT *
-			FROM ".$wgDBprefix."user_stats where stats_user_id =  " . $this->user_id ;
+			FROM ".$wgDBprefix."user_stats where stats_user_id =  " . $this->user_id;
 		$res = $dbr->query($sql);
 		$row = $dbr->fetchObject( $res );
 		if($row){
@@ -393,7 +393,7 @@
 	}
 }
 
-class UserStats{
+class UserStats {
 	/**
 	 * Constructor
 	 * @private
Index: trunk/extensions/SocialProfile/UserStats/README.txt
===================================================================
--- trunk/extensions/SocialProfile/UserStats/README.txt	(revision 34828)
+++ trunk/extensions/SocialProfile/UserStats/README.txt	(revision 34829)
@@ -1,11 +1,9 @@
 Requirements
 =======================
+MediaWiki 1.11
 
-Mediawiki 1.11
-
 Installation
 =======================
-
 If you are installing all extensions part of SocialProfile, there is no
 need to follow the instructions below.
 

Image changes

Index: /trunk/extensions/SocialProfile/avatars/default_l.gif
added
Index: /trunk/extensions/SocialProfile/avatars/default_m.gif
added
Index: /trunk/extensions/SocialProfile/avatars/default_ml.gif
added
Index: /trunk/extensions/SocialProfile/avatars/default_s.gif
added
Views
Toolbox