r94906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94905‎ | r94906 | r94907 >
Date:16:35, 18 August 2011
Author:ashley
Status:deferred (Comments)
Tags:
Comment:
SocialProfile: in UserStatus, moved the public history button from JS to PHP, added some <tr> and <td> tags around the "no status history" message in wfGetHistory, made it so that the owner of a status update and anons can't "like" the status update, removed unused JS globals and renamed the method which outputs the new JS global and added some wfReadOnly() checks
Modified paths:
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus.js (modified) (history)
  • /trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php
@@ -11,7 +11,7 @@
1212
1313 // Would probably be best to pass an edit token here, like most other MW
1414 // forms do
15 - if ( $u_id == $wgUser->getId() ) {
 15+ if ( $u_id == $wgUser->getId() && !wfReadOnly() ) {
1616 // Decode what we encoded in JS, UserStatus.saveStatus; this is safe
1717 // because the Database class that UserStatusClass uses for its DB queries
1818 // will do all the escaping for us.
@@ -41,7 +41,7 @@
4242 $output = '<table id="user-status-history">';
4343
4444 if ( empty( $historyArray ) ) {
45 - $output .= 'No status history.';
 45+ $output .= '<tr><td>No status history.</td></tr>';
4646 } else {
4747 foreach ( $historyArray as $row ) {
4848 $us = htmlspecialchars( $row['ush_status'] );
@@ -55,19 +55,27 @@
5656 $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $status_id .
5757 ');"';
5858 }
59 -
 59+
 60+ $likeSymbol = '&#9829;';
 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 . ');">&#9829;</a>';
 66+ }
 67+
6068 $output .= '<tr>
6169 <td width="60" id="status-history-time">' .
6270 $wgLang->timeanddate( wfTimestamp( TS_MW, $row['ush_timestamp'] ), true ) .
6371 '</td>
6472 <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>
6675 </td>
6776 <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>
 77+ <span id="like-status-' . $status_id . '" >' . $status_likes .
 78+ '<span>' . $likeSymbol .
 79+ '</td>
7280 </tr>';
7381 }
7482 }
@@ -79,10 +87,17 @@
8088
8189 $wgAjaxExportList[] = 'wfStatusLike';
8290
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+ }
87102 }
88103
89104 $wgAjaxExportList[] = 'SpecialGetStatusByName';
@@ -101,8 +116,8 @@
102117 if ( !empty( $currentStatus ) ) {
103118 $output .="CURRENT STATUS:<br />
104119 <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 />';
107122 }
108123
109124 $output .= 'HISTORY:<br />';
@@ -113,8 +128,8 @@
114129 } else {
115130 foreach ( $userHistory as $row ) {
116131 $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 />';
119134 }
120135 }
121136 }
@@ -135,18 +150,13 @@
136151 return '';
137152 }
138153
139 -$wgHooks['MakeGlobalVariablesScript'][] = 'addJSGlobals';
 154+$wgHooks['MakeGlobalVariablesScript'][] = 'wfUserStatusAddJSGlobals';
140155
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 ) {
146157 $vars['_US_LETTERS'] = wfMsg( 'userstatus-letters-left' );
147158 return true;
148159 }
149160
150 -
151161 $wgHooks['UserProfileBeginRight'][] = 'wfUserProfileStatusOutput';
152162
153163 /**
@@ -192,11 +202,22 @@
193203 }
194204 }
195205
 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+
196216 $output = '<div id="status-box">
197217 <div id="status-box-top"></div>
198218 <div id="status-box-content">
199219 <div id="user-status-block">' .
200220 htmlspecialchars( $userStatus ) . $editLink .
 221+ $publicHistoryLink .
201222 '</div>';
202223
203224 // No need to show the editing controls to anyone else except the owner
@@ -217,9 +238,6 @@
218239 <span id="status-letter-count"></span>
219240 </div>
220241 </div><!-- #status-edit-controls -->';
221 - } else {
222 - // Public history link to the masses
223 - $output .= "<script>UserStatus.publicHistoryButton('{$user_profile->user_id}');</script>";
224242 }
225243
226244 $output .= '</div>
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js
@@ -23,11 +23,6 @@
2424 document.getElementById( 'status-letter-count' ).innerHTML = len + ' ' + _US_LETTERS;
2525 },
2626
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 -
3227 /**
3328 * Enter the edit mode by hiding the current status message and displaying
3429 * the hidden input field which allows the user to enter a new status
@@ -79,14 +74,14 @@
8075 historyBlock.id = 'status-history-block';
8176 statusBlock.appendChild( historyBlock );
8277 }
83 -
84 - if ( historyBlock.style.display == "block" ) {
85 - historyBlock.style.display = "none";
 78+
 79+ if ( historyBlock.style.display == 'block' ) {
 80+ historyBlock.style.display = 'none';
8681 } 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
8984 sajax_do_call( 'wfGetHistory', [id], historyBlock );
90 - historyBlock.style.display = "block";
 85+ historyBlock.style.display = 'block';
9186 }
9287 },
9388
@@ -101,7 +96,7 @@
10297 document.getElementById( 'user-status-input' ).value =
10398 jQuery( '#status-history-entry-' + statusId ).text();
10499 },
105 -
 100+
106101 like: function( userID, messageID ) {
107102 var div = document.getElementById( 'like-status-' + messageID );
108103 sajax_do_call( 'wfStatusLike', [userID, messageID], div );

Comments

#Comment by Nikerabbit (talk | contribs)   10:35, 21 September 2011

No i18n for that message?

Status & tagging log