r94457 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94456‎ | r94457 | r94458 >
Date:13:54, 14 August 2011
Author:zhenya
Status:ok
Tags:
Comment:
added "like" system
Modified paths:
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus.js (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/userstatus.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStatus/userstatus.sql
@@ -1,18 +1,26 @@
22 CREATE TABLE /*_*/user_status (
3 - -- Unique status ID number
4 - `us_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
5 - -- ID number of the user who wrote this status update
6 - `us_user_id` int(11) NOT NULL default '0',
7 - -- Timestamp of the status update
8 - `us_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
9 - -- The text of the status update
10 - `us_status` varchar(140) NOT NULL default ''
 3+ -- Unique status ID number
 4+ `us_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
 5+ -- ID number of the user who wrote this status update
 6+ `us_user_id` int(11) NOT NULL default '0',
 7+ -- Timestamp of the status update
 8+ `us_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 9+ -- The text of the status update
 10+ `us_status` varchar(140) NOT NULL default ''
1111 )/*$wgDBTableOptions*/;
1212
1313 CREATE TABLE /*_*/user_status_history (
14 - `ush_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
15 - `ush_user_id` int(11) NOT NULL default '0',
16 - `ush_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
17 - `ush_status` varchar(140) NOT NULL default '',
18 - `ush_likes` int(11) NOT NULL default '0'
 14+ `ush_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
 15+ `ush_user_id` int(11) NOT NULL default '0',
 16+ `ush_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 17+ `ush_status` varchar(140) NOT NULL default '',
1918 )/*$wgDBTableOptions*/;
 19+
 20+CREATE TABLE /*_*/user_status_likes (
 21+ -- Unique ID number
 22+ `usl_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
 23+ --ID of the status which was liked
 24+ `usl_status_id` int(11) NOT NULL default '0',
 25+ --ID of the user who likes the (usl_status_id) status
 26+ `usl_user_id` int(11) NOT NULL default '0'
 27+)/*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
@@ -45,25 +45,29 @@
4646 } else {
4747 foreach ( $historyArray as $row ) {
4848 $us = htmlspecialchars( $row['ush_status'] );
49 - $statusId = intval( $row['ush_id'] );
50 -
 49+ $status_id = intval( $row['ush_id'] );
 50+ $status_likes = $us_class->likeCount( $status_id );
5151 $href = '';
5252 // We can only *view* other user's past status updates, we cannot
5353 // do anything with them...so don't bother generating the href
5454 // attribute when we're not viewing our own profile
5555 if ( $u_id == $wgUser->getId() ) {
56 - $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $statusId .
 56+ $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $status_id .
5757 ');"';
5858 }
59 -
 59+
6060 $output .= '<tr>
6161 <td width="60" id="status-history-time">' .
6262 $wgLang->timeanddate( wfTimestamp( TS_MW, $row['ush_timestamp'] ), true ) .
6363 '</td>
6464 <td width="360">
65 - <a id="status-history-entry-' . $statusId . '"' . $href . '>'.
66 - $us . '</a>
 65+ <a id="status-history-entry-' . $status_id . '"' . $href . '>'. $us . '</a>
6766 </td>
 67+ <td width="30" id="like-status">
 68+ <span id="like-status-' . $status_id . '" >' . $status_likes . '<span>
 69+ <a href="javascript:UserStatus.like(' . $wgUser->getId() . ',' . $status_id .
 70+ ');">&#9829;</a>
 71+ </td>
6872 </tr>';
6973 }
7074 }
@@ -73,6 +77,14 @@
7478 return $output;
7579 }
7680
 81+$wgAjaxExportList[] = 'wfStatusLike';
 82+
 83+function wfStatusLike ( $u_id, $status_id ) {
 84+ $us_class = new UserStatusClass();
 85+ $count = $us_class->likeStatus( $u_id, $status_id );
 86+ return $count;
 87+}
 88+
7789 $wgAjaxExportList[] = 'SpecialGetStatusByName';
7890
7991 function SpecialGetStatusByName( $user_name ) {
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js
@@ -25,7 +25,7 @@
2626
2727 publicHistoryButton: function( id ) {
2828 document.getElementById( 'user-status-block' ).innerHTML +=
29 - '<br /> <a id="us-link" href="javascript:UserStatus.useHistory(' + id + ');">' + _US_HISTORY + '</a>';
 29+ '<br /> <a class="us-link" href="javascript:UserStatus.useHistory(' + id + ');">' + _US_HISTORY + '</a>';
3030 },
3131
3232 /**
@@ -78,13 +78,15 @@
7979 historyBlock = document.createElement( 'div' );
8080 historyBlock.id = 'status-history-block';
8181 statusBlock.appendChild( historyBlock );
82 - sajax_do_call( 'wfGetHistory', [id], historyBlock );
8382 }
84 -
85 - if ( jQuery( '#status-history-block' ).is( 'visible' ) ) {
86 - jQuery( '#status-history-block' ).hide();
 83+
 84+ if ( historyBlock.style.display == "block" ) {
 85+ historyBlock.style.display = "none";
8786 } else {
88 - jQuery( '#status-history-block' ).show();
 87+ //This call should be here, as it fixes bug,
 88+ //when history does not change after first status save
 89+ sajax_do_call( 'wfGetHistory', [id], historyBlock );
 90+ historyBlock.style.display = "block";
8991 }
9092 },
9193
@@ -99,6 +101,11 @@
100102 document.getElementById( 'user-status-input' ).value =
101103 jQuery( '#status-history-entry-' + statusId ).text();
102104 },
 105+
 106+ like: function( userID, messageID ) {
 107+ var div = document.getElementById( 'like-status-' + messageID );
 108+ sajax_do_call( 'wfStatusLike', [userID, messageID], div );
 109+ },
103110
104111 specialGetHistory: function() {
105112 var us_name = document.getElementById( 'us-name-input' ).value;
Index: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php
@@ -158,6 +158,11 @@
159159 ),
160160 __METHOD__
161161 );
 162+ $dbw->delete(
 163+ 'user_status_likes',
 164+ array( 'usl_status_id' => $history[0]['ush_id'] ),
 165+ __METHOD__
 166+ );
162167 }
163168 return;
164169 }
@@ -170,6 +175,50 @@
171176 array( 'ush_id' => $status_id ),
172177 __METHOD__
173178 );
 179+ $dbw->delete(
 180+ 'user_status_likes',
 181+ array( 'usl_status_id' => $status_id ),
 182+ __METHOD__
 183+ );
174184 return;
175185 }
 186+
 187+ public function likeCount( $status_id ) {
 188+ $dbr = wfGetDB( DB_SLAVE );
 189+ $statusLikes = $dbr->select(
 190+ 'user_status_likes',
 191+ '*',
 192+ array( 'usl_status_id' => $status_id ),
 193+ __METHOD__
 194+ );
 195+
 196+ return $dbr->numRows( $statusLikes );
 197+ }
 198+
 199+ public function likeStatus( $liker_id, $status_id ) {
 200+ $dbw = wfGetDB( DB_MASTER );
 201+ $statusLikes = $dbw->select(
 202+ 'user_status_likes',
 203+ '*',
 204+ array(
 205+ 'usl_status_id' => $status_id,
 206+ 'usl_user_id' => $liker_id,
 207+ ),
 208+ __METHOD__
 209+ );
 210+
 211+ $i = $dbw->numRows( $statusLikes );
 212+
 213+ if ( $i==0 ) {
 214+ $dbw->insert(
 215+ 'user_status_likes',
 216+ array(
 217+ 'usl_status_id' => $status_id,
 218+ 'usl_user_id' => $liker_id,
 219+ ),
 220+ __METHOD__
 221+ );
 222+ }
 223+ return (string)$this->likeCount($status_id).' &#9829;';
 224+ }
176225 }
\ No newline at end of file

Status & tagging log