Index: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | |
13 | 13 | // Would probably be best to pass an edit token here, like most other MW |
14 | 14 | // forms do |
15 | | - if ( $u_id == $wgUser->getId() ) { |
| 15 | + if ( $u_id == $wgUser->getId() && !wfReadOnly() ) { |
16 | 16 | // Decode what we encoded in JS, UserStatus.saveStatus; this is safe |
17 | 17 | // because the Database class that UserStatusClass uses for its DB queries |
18 | 18 | // will do all the escaping for us. |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | $output = '<table id="user-status-history">'; |
43 | 43 | |
44 | 44 | if ( empty( $historyArray ) ) { |
45 | | - $output .= 'No status history.'; |
| 45 | + $output .= '<tr><td>No status history.</td></tr>'; |
46 | 46 | } else { |
47 | 47 | foreach ( $historyArray as $row ) { |
48 | 48 | $us = htmlspecialchars( $row['ush_status'] ); |
— | — | @@ -55,19 +55,27 @@ |
56 | 56 | $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $status_id . |
57 | 57 | ');"'; |
58 | 58 | } |
59 | | - |
| 59 | + |
| 60 | + $likeSymbol = '♥'; |
| 61 | + // Don't allow 1) the owner of the status update or 2) anonymous |
| 62 | + // users to like the status |
| 63 | + if ( !( $wgUser->getId() == $u_id ) && $wgUser->isLoggedIn() ) { |
| 64 | + $likeSymbol = '<a href="javascript:UserStatus.like(' . |
| 65 | + $wgUser->getId() . ',' . $status_id . ');">♥</a>'; |
| 66 | + } |
| 67 | + |
60 | 68 | $output .= '<tr> |
61 | 69 | <td width="60" id="status-history-time">' . |
62 | 70 | $wgLang->timeanddate( wfTimestamp( TS_MW, $row['ush_timestamp'] ), true ) . |
63 | 71 | '</td> |
64 | 72 | <td width="360"> |
65 | | - <a id="status-history-entry-' . $status_id . '"' . $href . '>'. $us . '</a> |
| 73 | + <a id="status-history-entry-' . $status_id . '"' . $href . |
| 74 | + '>' . $us . '</a> |
66 | 75 | </td> |
67 | 76 | <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> |
| 77 | + <span id="like-status-' . $status_id . '" >' . $status_likes . |
| 78 | + '<span>' . $likeSymbol . |
| 79 | + '</td> |
72 | 80 | </tr>'; |
73 | 81 | } |
74 | 82 | } |
— | — | @@ -79,10 +87,17 @@ |
80 | 88 | |
81 | 89 | $wgAjaxExportList[] = 'wfStatusLike'; |
82 | 90 | |
83 | | -function wfStatusLike ( $u_id, $status_id ) { |
84 | | - $us_class = new UserStatusClass(); |
85 | | - $count = $us_class->likeStatus( $u_id, $status_id ); |
86 | | - return $count; |
| 91 | +function wfStatusLike( $u_id, $status_id ) { |
| 92 | + global $wgUser; |
| 93 | + // Only logged-in users should be able to like people's statuses |
| 94 | + // @todo CHECKME: maybe we should introduce a new permission for liking |
| 95 | + // status updates and then use isAllowed( 'our-new-permission' ) here |
| 96 | + // instead of isLoggedIn()? |
| 97 | + if ( $wgUser->isLoggedIn() && $wgUser->getId() !== $u_id && !wfReadOnly() ) { |
| 98 | + $us_class = new UserStatusClass(); |
| 99 | + $count = $us_class->likeStatus( $u_id, $status_id ); |
| 100 | + return $count; |
| 101 | + } |
87 | 102 | } |
88 | 103 | |
89 | 104 | $wgAjaxExportList[] = 'SpecialGetStatusByName'; |
— | — | @@ -101,8 +116,8 @@ |
102 | 117 | if ( !empty( $currentStatus ) ) { |
103 | 118 | $output .="CURRENT STATUS:<br /> |
104 | 119 | <input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
105 | | - onclick=\"javascript:UserStatus.specialStatusDelete('".$currentStatus['us_id']."');\">" |
106 | | - .$currentStatus['us_status'] . '<br /><br />'; |
| 120 | + onclick=\"javascript:UserStatus.specialStatusDelete('" . $currentStatus['us_id'] . "');\">" |
| 121 | + . $currentStatus['us_status'] . '<br /><br />'; |
107 | 122 | } |
108 | 123 | |
109 | 124 | $output .= 'HISTORY:<br />'; |
— | — | @@ -113,8 +128,8 @@ |
114 | 129 | } else { |
115 | 130 | foreach ( $userHistory as $row ) { |
116 | 131 | $output .= "<input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
117 | | - onclick=\"javascript:UserStatus.specialHistoryDelete('".$row['ush_id']."');\">" |
118 | | - .$row['ush_timestamp']." - ".$row['ush_status']." <br />"; |
| 132 | + onclick=\"javascript:UserStatus.specialHistoryDelete('" . $row['ush_id'] . "');\">" |
| 133 | + . $row['ush_timestamp'] . ' - ' . $row['ush_status'] . ' <br />'; |
119 | 134 | } |
120 | 135 | } |
121 | 136 | } |
— | — | @@ -135,18 +150,13 @@ |
136 | 151 | return ''; |
137 | 152 | } |
138 | 153 | |
139 | | -$wgHooks['MakeGlobalVariablesScript'][] = 'addJSGlobals'; |
| 154 | +$wgHooks['MakeGlobalVariablesScript'][] = 'wfUserStatusAddJSGlobals'; |
140 | 155 | |
141 | | -function addJSGlobals( $vars ) { |
142 | | - $vars['_US_EDIT'] = wfMsg( 'userstatus-edit' ); |
143 | | - $vars['_US_SAVE'] = wfMsg( 'userstatus-save' ); |
144 | | - $vars['_US_CANCEL'] = wfMsg( 'userstatus-cancel' ); |
145 | | - $vars['_US_HISTORY'] = wfMsg( 'userstatus-history' ); |
| 156 | +function wfUserStatusAddJSGlobals( $vars ) { |
146 | 157 | $vars['_US_LETTERS'] = wfMsg( 'userstatus-letters-left' ); |
147 | 158 | return true; |
148 | 159 | } |
149 | 160 | |
150 | | - |
151 | 161 | $wgHooks['UserProfileBeginRight'][] = 'wfUserProfileStatusOutput'; |
152 | 162 | |
153 | 163 | /** |
— | — | @@ -192,11 +202,22 @@ |
193 | 203 | } |
194 | 204 | } |
195 | 205 | |
| 206 | + $publicHistoryLink = ''; |
| 207 | + // Public history link to the masses (i.e. everyone who is not the |
| 208 | + // owner of the profile; the owner has a history link in the edit links |
| 209 | + // below) |
| 210 | + if ( !( $user_profile->user_id == $wgUser->getId() ) ) { |
| 211 | + $publicHistoryLink = '<br /> <a class="us-link" href="javascript:UserStatus.useHistory(' . |
| 212 | + $user_profile->user_id . ');">' . |
| 213 | + wfMsg( 'userstatus-history' ) . '</a>'; |
| 214 | + } |
| 215 | + |
196 | 216 | $output = '<div id="status-box"> |
197 | 217 | <div id="status-box-top"></div> |
198 | 218 | <div id="status-box-content"> |
199 | 219 | <div id="user-status-block">' . |
200 | 220 | htmlspecialchars( $userStatus ) . $editLink . |
| 221 | + $publicHistoryLink . |
201 | 222 | '</div>'; |
202 | 223 | |
203 | 224 | // No need to show the editing controls to anyone else except the owner |
— | — | @@ -217,9 +238,6 @@ |
218 | 239 | <span id="status-letter-count"></span> |
219 | 240 | </div> |
220 | 241 | </div><!-- #status-edit-controls -->'; |
221 | | - } else { |
222 | | - // Public history link to the masses |
223 | | - $output .= "<script>UserStatus.publicHistoryButton('{$user_profile->user_id}');</script>"; |
224 | 242 | } |
225 | 243 | |
226 | 244 | $output .= '</div> |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js |
— | — | @@ -23,11 +23,6 @@ |
24 | 24 | document.getElementById( 'status-letter-count' ).innerHTML = len + ' ' + _US_LETTERS; |
25 | 25 | }, |
26 | 26 | |
27 | | - publicHistoryButton: function( id ) { |
28 | | - document.getElementById( 'user-status-block' ).innerHTML += |
29 | | - '<br /> <a class="us-link" href="javascript:UserStatus.useHistory(' + id + ');">' + _US_HISTORY + '</a>'; |
30 | | - }, |
31 | | - |
32 | 27 | /** |
33 | 28 | * Enter the edit mode by hiding the current status message and displaying |
34 | 29 | * the hidden input field which allows the user to enter a new status |
— | — | @@ -79,14 +74,14 @@ |
80 | 75 | historyBlock.id = 'status-history-block'; |
81 | 76 | statusBlock.appendChild( historyBlock ); |
82 | 77 | } |
83 | | - |
84 | | - if ( historyBlock.style.display == "block" ) { |
85 | | - historyBlock.style.display = "none"; |
| 78 | + |
| 79 | + if ( historyBlock.style.display == 'block' ) { |
| 80 | + historyBlock.style.display = 'none'; |
86 | 81 | } else { |
87 | | - //This call should be here, as it fixes bug, |
88 | | - //when history does not change after first status save |
| 82 | + // This call should be here, as it fixes bug, |
| 83 | + // when history does not change after first status save |
89 | 84 | sajax_do_call( 'wfGetHistory', [id], historyBlock ); |
90 | | - historyBlock.style.display = "block"; |
| 85 | + historyBlock.style.display = 'block'; |
91 | 86 | } |
92 | 87 | }, |
93 | 88 | |
— | — | @@ -101,7 +96,7 @@ |
102 | 97 | document.getElementById( 'user-status-input' ).value = |
103 | 98 | jQuery( '#status-history-entry-' + statusId ).text(); |
104 | 99 | }, |
105 | | - |
| 100 | + |
106 | 101 | like: function( userID, messageID ) { |
107 | 102 | var div = document.getElementById( 'like-status-' + messageID ); |
108 | 103 | sajax_do_call( 'wfStatusLike', [userID, messageID], div ); |