r34829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34828‎ | r34829 | r34830 >
Date:21:25, 14 May 2008
Author:ashley
Status:old
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:
  • /trunk/extensions/SocialProfile/UserBoard/README.txt (modified) (history)
  • /trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserProfile/UserProfile.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/UserRelationship.i18n.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/README.txt (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/UserStatsClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/avatars (added) (history)
  • /trunk/extensions/SocialProfile/avatars/README.txt (added) (history)
  • /trunk/extensions/SocialProfile/avatars/default_l.gif (added) (history)
  • /trunk/extensions/SocialProfile/avatars/default_m.gif (added) (history)
  • /trunk/extensions/SocialProfile/avatars/default_ml.gif (added) (history)
  • /trunk/extensions/SocialProfile/avatars/default_s.gif (added) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php
@@ -10,7 +10,7 @@
1111 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1212 */
1313
14 -class UserProfilePage extends Article{
 14+class UserProfilePage extends Article {
1515
1616 var $title = null;
1717
@@ -242,12 +242,12 @@
243243 } else if ($wgUser->getName()==$user_name) {
244244 $output .= "<div class=\"user-section-heading\">
245245 <div class=\"user-section-title\">
246 - ".wfMSg("custom-info-title")."
 246+ ".wfMsg("custom-info-title")."
247247 </div>
248248 <div class=\"user-section-actions\">
249249 <div class=\"action-right\">
250250 <a href=\"".$edit_info_link->escapeFullURL()."/custom\">
251 - ".wfMSg("user-edit-this")."
 251+ ".wfMsg("user-edit-this")."
252252 </a>
253253 </div>
254254 <div class=\"cleared\"></div>
@@ -255,7 +255,7 @@
256256 </div>
257257 <div class=\"cleared\"></div>
258258 <div class=\"no-info-container\">
259 - ".wfMSg("custom-no-info")."
 259+ ".wfMsg("custom-no-info")."
260260 </div>";
261261 }
262262
@@ -586,7 +586,7 @@
587587 <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>
588588 <textarea name=\"message\" id=\"message\" cols=\"43\" rows=\"4\"/></textarea>
589589 <div class=\"user-page-message-box-button\">
590 - <input type=\"button\" value=\"Send\" class=\"site-button\" onclick=\"javascript:send_message();\">
 590+ <input type=\"button\" value=" . wfMsg("userboard_sendbutton") . " class=\"site-button\" onclick=\"javascript:send_message();\">
591591 </div>
592592 </div>";
593593 } else {
Index: trunk/extensions/SocialProfile/UserProfile/UserProfile.php
@@ -1,5 +1,5 @@
22 <?php
3 -//GLOBAL VIDEO NAMESPACE REFERENCE
 3+//Global profile namespace reference
44 define( 'NS_USER_PROFILE', 202 );
55 define( 'NS_USER_WIKI', 200 );
66
@@ -17,7 +17,7 @@
1818 //ArticleFromTitle
1919 //Calls UserProfilePage instead of standard article
2020 function wfUserProfileFromTitle( &$title, &$article ){
21 - global $wgUser, $wgRequest, $IP, $wgOut, $wgTitle, $wgSupressPageTitle,$wgSupressSubTitle, $wgMemc,
 21+ global $wgUser, $wgRequest, $IP, $wgOut, $wgTitle, $wgSupressPageTitle, $wgSupressSubTitle, $wgMemc,
2222 $wgUserPageChoice, $wgParser, $wgUserProfileDirectory, $wgUserProfileScripts, $wgStyleVersion;
2323
2424 if ( strpos( $title->getText(), "/" ) === false && ( NS_USER == $title->getNamespace() || NS_USER_PROFILE == $title->getNamespace() ) ) {
@@ -40,7 +40,7 @@
4141 if( $wgRequest->getVal("action") == "edit" ){
4242 $wgOut->redirect( $title->getFullURL() );
4343 }
44 - }else{
 44+ } else {
4545 $wgOut->enableClientCache(false);
4646 $wgParser->disableCache();
4747 }
Index: trunk/extensions/SocialProfile/UserRelationship/SpecialAddRelationship.php
@@ -212,7 +212,7 @@
213213 <div class=\"cleared\"></div>
214214 </div>
215215 <div class=\"relationship-textbox-title\">
216 - Add a Personal Message
 216+ ".wfMsg('ur-add-personal-message')."
217217 </div>
218218 <textarea name=\"message\" id=\"message\" rows=\"3\" cols=\"50\"></textarea>
219219 <div class=\"relationship-buttons\">
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationship.i18n.php
@@ -23,6 +23,7 @@
2424 'ur-add-friend' => 'Add as friend',
2525 'ur-add-foe' => 'Add as foe',
2626 'ur-add-no-user' => 'No user selected. Please request friends/foes through the correct link.',
 27+ 'ur-add-personal-message' => 'Add a Personal Message',
2728 'ur-remove-relationship' => 'Remove as $1',
2829 'ur-give-gift' => 'Give a gift',
2930 'ur-previous' => 'prev',
@@ -2024,3 +2025,4 @@
20252026 'ur-login' => 'Đăng nhập',
20262027 );
20272028
 2029+
Index: trunk/extensions/SocialProfile/UserRelationship/UserRelationshipClass.php
@@ -25,7 +25,7 @@
2626 $user_id_to = User::idFromName($user_to);
2727 $dbr =& wfGetDB( DB_MASTER );
2828 $fname = $wgDBprefix.'user_relationship_request::addToDatabase';
29 - $dbr->insert( $wgDBprefix.'`user_relationship_request`',
 29+ $dbr->insert( '`'.$wgDBprefix.'user_relationship_request`',
3030 array(
3131 'ur_user_id_from' => $this->user_id,
3232 'ur_user_name_from' => $this->user_name,
@@ -141,7 +141,7 @@
142142 global $wgMemc, $wgDBprefix;
143143
144144 $dbr =& wfGetDB( DB_MASTER );
145 - $s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`',
 145+ $s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`',
146146 array( 'ur_user_id_from','ur_user_name_from','ur_type'),
147147 array( 'ur_id' => $relationship_request_id ), $fname
148148 );
@@ -156,7 +156,7 @@
157157 }
158158
159159 $fname = $wgDBprefix.'user_relationship::addToDatabase';
160 - $dbr->insert( $wgDBprefix.'`user_relationship`',
 160+ $dbr->insert( '`'.$wgDBprefix.'user_relationship`',
161161 array(
162162 'r_user_id' => $this->user_id,
163163 'r_user_name' => $this->user_name,
@@ -168,7 +168,7 @@
169169 );
170170
171171 $fname = $wgDBprefix.'user_relationship::addToDatabase';
172 - $dbr->insert( $wgDBprefix.'`user_relationship`',
 172+ $dbr->insert( '`'.$wgDBprefix.'user_relationship`',
173173 array(
174174 'r_user_id' => $ur_user_id_from,
175175 'r_user_name' => $ur_user_name_from,
@@ -247,7 +247,7 @@
248248 public function updateRelationshipRequestStatus($relationship_request_id, $status){
249249 global $wgDBprefix;
250250 $dbw =& wfGetDB( DB_MASTER );
251 - $dbw->update( $wgDBprefix.'`user_relationship_request`',
 251+ $dbw->update( '`'.$wgDBprefix.'user_relationship_request`',
252252 array( /* SET */
253253 'ur_status' => $status
254254 ), array( /* WHERE */
@@ -259,7 +259,7 @@
260260 public function verifyRelationshipRequest($relationship_request_id){
261261 global $wgDBprefix;
262262 $dbr =& wfGetDB( DB_MASTER );
263 - $s = $dbr->selectRow( $wgDBprefix.'`user_relationship_request`', array( 'ur_user_id_to' ), array( 'ur_id' => $relationship_request_id ), $fname );
 263+ $s = $dbr->selectRow( '`'.$wgDBprefix.'user_relationship_request`', array( 'ur_user_id_to' ), array( 'ur_id' => $relationship_request_id ), $fname );
264264 if ( $s !== false ) {
265265 if($this->user_id == $s->ur_user_id_to){
266266 return true;
@@ -280,13 +280,13 @@
281281 }
282282 }
283283
284 - static function userHasRequestByID($user1,$user2){
 284+ static function userHasRequestByID($user1, $user2){
285285 global $wgDBprefix;
286286 $dbr =& wfGetDB( DB_MASTER );
287 - $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__ );
 287+ $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__ );
288288 if ( $s === false ) {
289289 return false;
290 - }else{
 290+ } else {
291291 return true;
292292 }
293293 }
@@ -301,7 +301,7 @@
302302 while ($row = $dbr->fetchObject( $res ) ) {
303303 if($row->ur_type==1){
304304 $type_name = "Friend";
305 - }else{
 305+ } else {
306306 $type_name = "Foe";
307307 }
308308 $request[] = array(
@@ -359,7 +359,7 @@
360360 $key = wfMemcKey( 'user_relationship', 'open_request', $rel_type, $user_id );
361361 $dbr =& wfGetDB( DB_SLAVE );
362362 $request_count = 0;
363 - $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__ );
 363+ $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__ );
364364 if ( $s !== false )$request_count = $s->count;
365365
366366 $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
367367 + 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
368368 + 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
369369 + 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
370370 + application/octet-stream
Index: trunk/extensions/SocialProfile/avatars/README.txt
@@ -0,0 +1,4 @@
 2+==Avatar Notes==
 3+Please create an avatar directory under the path for images used in your MediaWiki Installaion. This directory should be writeable.
 4+
 5+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
16 + native
Index: trunk/extensions/SocialProfile/UserBoard/UserBoardClass.php
@@ -24,7 +24,7 @@
2525 $user_name_from = stripslashes($user_name_from);
2626 $user_name_to = stripslashes($user_name_to);
2727
28 - $dbr->insert( $wgDBprefix.'`user_board`',
 28+ $dbr->insert( '`'.$wgDBprefix.'user_board`',
2929 array(
3030 'ub_user_id_from' => $user_id_from,
3131 'ub_user_name_from' => $user_name_from,
@@ -48,7 +48,7 @@
4949 if($message_type==0){
5050 //public message count
5151 $stats->incStatField("user_board_count");
52 - }else{
 52+ } else {
5353 //private message count
5454 $stats->incStatField("user_board_count_priv");
5555 }
@@ -60,12 +60,7 @@
6161 }
6262
6363 public function sendBoardNotificationEmail($user_id_to,$user_from){
64 - require_once( "UserBoard.i18n.php" );
65 - # Add messages
66 - global $wgMessageCache;
67 - foreach( $wgUserBoardMessages as $key => $value ) {
68 - $wgMessageCache->addMessages( $wgUserBoardMessages[$key], $key );
69 - }
 64+ wfLoadExtensionMessages( 'SocialProfileUserBoard' );
7065
7166 $user = User::newFromId($user_id_to);
7267 $user->loadFromId();
@@ -129,7 +124,7 @@
130125
131126 if( $data != "" ){
132127 $count = $data;
133 - }else{
 128+ } else {
134129 $count = self::getNewMessageCountDB($user_id);
135130 }
136131 return $count;
@@ -182,7 +177,7 @@
183178 if(! ($user_id == $wgUser->getID() || $user_id_2 == $wgUser->getID()) ){
184179 $user_sql .= " and ub_type = 0 ";
185180 }
186 - }else{
 181+ } else {
187182 $user_sql = "ub_user_id = {$user_id}";
188183 if($user_id != $wgUser->getID() ){
189184 $user_sql .= " and ub_type = 0 ";
@@ -243,15 +238,15 @@
244239 public function displayMessages($user_id,$user_id_2=0,$count=10,$page=0){
245240 global $wgUser,$max_link_text_length, $wgTitle;
246241 $messages = $this->getUserBoardMessages($user_id,$user_id_2,$count,$page);
247 -
 242+ wfLoadExtensionMessages( 'SocialProfileUserBoard' );
248243 if ($messages) {
249244
250245 foreach ($messages as $message) {
251246 $user = Title::makeTitle( NS_USER, $message["user_name_from"] );
252247 $avatar = new wAvatar($message["user_id_from"],"m");
253248
254 - $board_to_board ="";
255 - $board_link="";
 249+ $board_to_board = "";
 250+ $board_link = "";
256251 $message_type_label = "";
257252 $delete_link = "";
258253 if($wgUser->getName()!=$message["user_name_from"]){
@@ -269,7 +264,7 @@
270265
271266 $max_link_text_length = 50;
272267 $message_text = $message["message_text"];
273 - $message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i",'cut_link_text',$message["message_text"]);
 268+ #$message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i",'cut_link_text',$message["message_text"]);
274269
275270 $output .= "<div class=\"user-board-message\" >
276271 <div class=\"user-board-message-from\">
Index: trunk/extensions/SocialProfile/UserBoard/README.txt
@@ -1,13 +1,11 @@
22 Requirements
33 =======================
4 -
5 -Mediawiki 1.11
 4+MediaWiki 1.11
65 YUI
76 UserStats package
87
98 Installation
109 =======================
11 -
1210 This assumes you have copied all the neccessary files into
1311 /extensions/SocialProfile/UserBoard.
1412
@@ -37,4 +35,4 @@
3836 add the following line (changing path as neccessary)
3937
4038 global $IP;
41 -require_once ("$IP/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php" );
 39+require_once ("$IP/extensions/SocialProfile/UserBoard/UserBoard_AjaxFunctions.php");
Index: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php
@@ -5,7 +5,7 @@
66 $wgUserStatsTrackWeekly = false;
77 $wgUserStatsTrackMonthly = false;
88
9 -class UserStatsTrack{
 9+class UserStatsTrack {
1010 //for referencing purposes
1111 var $stats_fields = array(
1212 "edit"=>"stats_edit_count",
@@ -97,7 +97,7 @@
9898 }
9999
100100 function incStatField( $field, $val=1 ){
101 - global $wgUser, $IP, $wgDBprefix, $wgMemc, $wgSitename,$wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues;
 101+ global $wgUser, $IP, $wgDBprefix, $wgMemc, $wgSitename, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, $wgUserStatsPointValues;
102102 if( !$wgUser->isBot() && !$wgUser->isAnon() && $this->stats_fields[$field]) {
103103 $dbw = wfGetDB( DB_MASTER );
104104 $dbw->update( 'user_stats',
@@ -158,7 +158,7 @@
159159 $sql .= 'stats_comment_blocked=';
160160 $sql .= "(SELECT COUNT(*) as CommentCount FROM Comments_block WHERE cb_user_id_blocked = " . $this->user_id;
161161 $sql .= ")";
162 - $sql .= " WHERE stats_user_id = " . $this->user_id ;
 162+ $sql .= " WHERE stats_user_id = " . $this->user_id;
163163 $res = $dbr->query($sql);
164164
165165 $this->clearCache();
@@ -202,12 +202,12 @@
203203 $sql = "update ".$wgDBprefix."user_stats set ";
204204 if($vote_type==1){
205205 $sql .= 'stats_comment_score_positive_rec=';
206 - }else{
 206+ } else {
207207 $sql .= 'stats_comment_score_negative_rec=';
208208 }
209209 $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;
210210 $sql .= ")";
211 - $sql .= " WHERE stats_user_id = " . $this->user_id ;
 211+ $sql .= " WHERE stats_user_id = " . $this->user_id;
212212 $res = $dbr->query($sql);
213213
214214 $this->clearCache();
@@ -217,7 +217,7 @@
218218 function updateCreatedOpinionsCount(){
219219 global $wgUser, $wgOut, $wgDBprefix;
220220 if( !$wgUser->isAnon() && $this->user_id) {
221 - $ctg = "Opinions by User " . ($this->user_name) ;
 221+ $ctg = "Opinions by User " . ($this->user_name);
222222 $parser = new Parser();
223223 $CtgTitle = Title::newFromText( $parser->transformMsg(trim($ctg), $wgOut->parserOptions() ) );
224224 $CtgTitle = $CtgTitle->getDbKey();
@@ -225,7 +225,7 @@
226226 $sql = "update ".$wgDBprefix."user_stats set stats_opinions_created=";
227227 $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) . " ";
228228 $sql .= ")";
229 - $sql .= " WHERE stats_user_id = " . $this->user_id ;
 229+ $sql .= " WHERE stats_user_id = " . $this->user_id;
230230
231231 $res = $dbr->query($sql);
232232
@@ -243,7 +243,7 @@
244244 $sql = "update ".$wgDBprefix."user_stats set stats_opinions_published = ";
245245 $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;
246246 $sql .= ")";
247 - $sql .= " WHERE stats_user_id = " . $this->user_id ;
 247+ $sql .= " WHERE stats_user_id = " . $this->user_id;
248248 $res = $dbr->query($sql);
249249
250250 $this->clearCache();
@@ -255,7 +255,7 @@
256256 $dbr = wfGetDB( DB_MASTER );
257257 if($rel_type==1){
258258 $col="stats_friends_count";
259 - }else{
 259+ } else {
260260 $col="stats_foe_count";
261261 } //Where is low_priority? where was this table created?
262262 $sql = "update low_priority ".$wgDBprefix."user_stats set {$col}=
@@ -268,7 +268,7 @@
269269 }
270270
271271 function updateGiftCountRec(){
272 - global $wgUser,$wgStatsStartTimestamp, $wgDBprefix;
 272+ global $wgUser, $wgStatsStartTimestamp, $wgDBprefix;
273273 if( !$wgUser->isAnon() ) {
274274 $dbr = wfGetDB( DB_MASTER );
275275 $sql = "update low_priority ".$wgDBprefix."user_stats set stats_gifts_rec_count=
@@ -368,7 +368,7 @@
369369
370370 $dbr =& wfGetDB( DB_MASTER );
371371 $sql = "SELECT *
372 - FROM ".$wgDBprefix."user_stats where stats_user_id = " . $this->user_id ;
 372+ FROM ".$wgDBprefix."user_stats where stats_user_id = " . $this->user_id;
373373 $res = $dbr->query($sql);
374374 $row = $dbr->fetchObject( $res );
375375 if($row){
@@ -393,7 +393,7 @@
394394 }
395395 }
396396
397 -class UserStats{
 397+class UserStats {
398398 /**
399399 * Constructor
400400 * @private
Index: trunk/extensions/SocialProfile/UserStats/README.txt
@@ -1,11 +1,9 @@
22 Requirements
33 =======================
 4+MediaWiki 1.11
45
5 -Mediawiki 1.11
6 -
76 Installation
87 =======================
9 -
108 If you are installing all extensions part of SocialProfile, there is no
119 need to follow the instructions below.
1210

Status & tagging log