Index: trunk/extensions/SocialProfile/UserStatus/userstatus.sql |
— | — | @@ -1,18 +1,26 @@ |
2 | 2 | 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 '' |
11 | 11 | )/*$wgDBTableOptions*/; |
12 | 12 | |
13 | 13 | 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 '', |
19 | 18 | )/*$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 @@ |
46 | 46 | } else { |
47 | 47 | foreach ( $historyArray as $row ) { |
48 | 48 | $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 ); |
51 | 51 | $href = ''; |
52 | 52 | // We can only *view* other user's past status updates, we cannot |
53 | 53 | // do anything with them...so don't bother generating the href |
54 | 54 | // attribute when we're not viewing our own profile |
55 | 55 | if ( $u_id == $wgUser->getId() ) { |
56 | | - $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $statusId . |
| 56 | + $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $status_id . |
57 | 57 | ');"'; |
58 | 58 | } |
59 | | - |
| 59 | + |
60 | 60 | $output .= '<tr> |
61 | 61 | <td width="60" id="status-history-time">' . |
62 | 62 | $wgLang->timeanddate( wfTimestamp( TS_MW, $row['ush_timestamp'] ), true ) . |
63 | 63 | '</td> |
64 | 64 | <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> |
67 | 66 | </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 | + ');">♥</a> |
| 71 | + </td> |
68 | 72 | </tr>'; |
69 | 73 | } |
70 | 74 | } |
— | — | @@ -73,6 +77,14 @@ |
74 | 78 | return $output; |
75 | 79 | } |
76 | 80 | |
| 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 | + |
77 | 89 | $wgAjaxExportList[] = 'SpecialGetStatusByName'; |
78 | 90 | |
79 | 91 | function SpecialGetStatusByName( $user_name ) { |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | |
27 | 27 | publicHistoryButton: function( id ) { |
28 | 28 | 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>'; |
30 | 30 | }, |
31 | 31 | |
32 | 32 | /** |
— | — | @@ -78,13 +78,15 @@ |
79 | 79 | historyBlock = document.createElement( 'div' ); |
80 | 80 | historyBlock.id = 'status-history-block'; |
81 | 81 | statusBlock.appendChild( historyBlock ); |
82 | | - sajax_do_call( 'wfGetHistory', [id], historyBlock ); |
83 | 82 | } |
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"; |
87 | 86 | } 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"; |
89 | 91 | } |
90 | 92 | }, |
91 | 93 | |
— | — | @@ -99,6 +101,11 @@ |
100 | 102 | document.getElementById( 'user-status-input' ).value = |
101 | 103 | jQuery( '#status-history-entry-' + statusId ).text(); |
102 | 104 | }, |
| 105 | + |
| 106 | + like: function( userID, messageID ) { |
| 107 | + var div = document.getElementById( 'like-status-' + messageID ); |
| 108 | + sajax_do_call( 'wfStatusLike', [userID, messageID], div ); |
| 109 | + }, |
103 | 110 | |
104 | 111 | specialGetHistory: function() { |
105 | 112 | var us_name = document.getElementById( 'us-name-input' ).value; |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php |
— | — | @@ -158,6 +158,11 @@ |
159 | 159 | ), |
160 | 160 | __METHOD__ |
161 | 161 | ); |
| 162 | + $dbw->delete( |
| 163 | + 'user_status_likes', |
| 164 | + array( 'usl_status_id' => $history[0]['ush_id'] ), |
| 165 | + __METHOD__ |
| 166 | + ); |
162 | 167 | } |
163 | 168 | return; |
164 | 169 | } |
— | — | @@ -170,6 +175,50 @@ |
171 | 176 | array( 'ush_id' => $status_id ), |
172 | 177 | __METHOD__ |
173 | 178 | ); |
| 179 | + $dbw->delete( |
| 180 | + 'user_status_likes', |
| 181 | + array( 'usl_status_id' => $status_id ), |
| 182 | + __METHOD__ |
| 183 | + ); |
174 | 184 | return; |
175 | 185 | } |
| 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).' ♥'; |
| 224 | + } |
176 | 225 | } |
\ No newline at end of file |