Index: trunk/extensions/SocialProfile/UserStatus/UserStatus_AjaxFunctions.php |
— | — | @@ -5,63 +5,104 @@ |
6 | 6 | $wgAjaxExportList[] = 'wfSaveStatus'; |
7 | 7 | |
8 | 8 | function wfSaveStatus( $u_id, $status ) { |
9 | | - $us_class = new UserStatusClass(); |
10 | | - $us_class->setStatus( $u_id, $status ); |
11 | | - $user_status_array = $us_class->getStatus( $u_id ); |
12 | | - $us = htmlspecialchars($us_class->usHTMLcharacters($user_status_array['us_status'])); |
13 | | - $us .= "<br> <a id=\"us-link\" href=\"javascript:UserStatus.toEditMode('".($user_status_array['us_status'])."','$u_id');\">".wfMsg('userstatus-edit')."</a>"; |
| 9 | + global $wgUser; |
| 10 | + |
| 11 | + $us = ''; |
| 12 | + |
| 13 | + // Would probably be best to pass an edit token here, like most other MW |
| 14 | + // forms do |
| 15 | + if ( $u_id == $wgUser->getId() ) { |
| 16 | + // Decode what we encoded in JS, UserStatus.saveStatus; this is safe |
| 17 | + // because the Database class that UserStatusClass uses for its DB queries |
| 18 | + // will do all the escaping for us. |
| 19 | + $status = urldecode( $status ); |
| 20 | + |
| 21 | + $us_class = new UserStatusClass(); |
| 22 | + $us_class->setStatus( $u_id, $status ); |
| 23 | + |
| 24 | + $user_status_array = $us_class->getStatus( $u_id ); |
| 25 | + |
| 26 | + $us = htmlspecialchars( $user_status_array['us_status'] ); |
| 27 | + $us .= '<br /> <a class="us-link" href="javascript:UserStatus.toEditMode();">' . |
| 28 | + wfMsg( 'userstatus-edit' ) . '</a>'; |
| 29 | + } |
| 30 | + |
14 | 31 | return $us; |
15 | 32 | } |
16 | 33 | |
17 | 34 | $wgAjaxExportList[] = 'wfGetHistory'; |
18 | 35 | |
19 | 36 | function wfGetHistory( $u_id ) { |
| 37 | + global $wgLang, $wgUser; |
| 38 | + |
20 | 39 | $us_class = new UserStatusClass(); |
21 | | - $historyArray = $us_class->useStatusHistory('select', $u_id); |
22 | | - $output='<table id="user-status-history">'; |
23 | | - foreach ($historyArray as $row ) { |
24 | | - $time = DateTime::createFromFormat('Y-m-d H:i:s',$row['ush_timestamp']); |
25 | | - $us = htmlspecialchars($us_class->usHTMLcharacters($row['ush_status'])); |
26 | | - |
27 | | - $output .= '<tr><td width="60" id="status-history-time">'.date_format($time, 'j M G:i').' </td>'; |
28 | | - $output .= '<td width="360"><a href="javascript:UserStatus.fromHistoryToStatus(\''.$us.'\');">' |
29 | | - .$us.'</a></td>'; |
| 40 | + $historyArray = $us_class->useStatusHistory( 'select', $u_id ); |
| 41 | + |
| 42 | + $output = '<table id="user-status-history">'; |
| 43 | + |
| 44 | + if ( empty( $historyArray ) ) { |
| 45 | + $output .= 'No status history.'; |
| 46 | + } else { |
| 47 | + foreach ( $historyArray as $row ) { |
| 48 | + $us = htmlspecialchars( $row['ush_status'] ); |
| 49 | + $statusId = intval( $row['ush_id'] ); |
| 50 | + |
| 51 | + $href = ''; |
| 52 | + // We can only *view* other user's past status updates, we cannot |
| 53 | + // do anything with them...so don't bother generating the href |
| 54 | + // attribute when we're not viewing our own profile |
| 55 | + if ( $u_id == $wgUser->getId() ) { |
| 56 | + $href = ' href="javascript:UserStatus.insertStatusFromHistory(' . $statusId . |
| 57 | + ');"'; |
| 58 | + } |
| 59 | + |
| 60 | + $output .= '<tr> |
| 61 | + <td width="60" id="status-history-time">' . |
| 62 | + $wgLang->timeanddate( wfTimestamp( TS_MW, $row['ush_timestamp'] ), true ) . |
| 63 | + '</td> |
| 64 | + <td width="360"> |
| 65 | + <a id="status-history-entry-' . $statusId . '"' . $href . '>'. |
| 66 | + $us . '</a> |
| 67 | + </td> |
| 68 | + </tr>'; |
30 | 69 | } |
31 | | - $output.='</table>'; |
| 70 | + } |
| 71 | + |
| 72 | + $output .= '</table>'; |
| 73 | + |
32 | 74 | return $output; |
33 | 75 | } |
34 | 76 | |
35 | 77 | $wgAjaxExportList[] = 'SpecialGetStatusByName'; |
36 | 78 | |
37 | 79 | function SpecialGetStatusByName( $user_name ) { |
38 | | - global $wgUser; |
39 | | - $output=""; |
40 | | - $user_id = $wgUser->idFromName($user_name); |
| 80 | + $output = ''; |
| 81 | + $user_id = User::idFromName( $user_name ); |
41 | 82 | |
42 | | - if (empty ($user_id)) { |
43 | | - $output.="<div>Wrong name or user does not exist</div>"; |
| 83 | + if ( empty( $user_id ) ) { |
| 84 | + $output .= '<div>Wrong name or user does not exist</div>'; |
44 | 85 | } else { |
45 | 86 | $us_class = new UserStatusClass(); |
46 | | - $currentStatus = $us_class->getStatus($user_id); |
47 | | - $output .="<br><div>USER ID: $user_id, USERNAME: $user_name</div><br>"; |
| 87 | + $currentStatus = $us_class->getStatus( $user_id ); |
| 88 | + $output .= "<br /><div>USER ID: $user_id, USERNAME: $user_name</div><br>"; |
48 | 89 | |
49 | | - if (!empty ($currentStatus)) { |
50 | | - $output .="CURRENT STATUS:<br> |
51 | | - <input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
| 90 | + if ( !empty( $currentStatus ) ) { |
| 91 | + $output .="CURRENT STATUS:<br /> |
| 92 | + <input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
52 | 93 | onclick=\"javascript:UserStatus.specialStatusDelete('".$currentStatus['us_id']."');\">" |
53 | | - .$currentStatus['us_status']."<br><br>"; |
| 94 | + .$currentStatus['us_status'] . '<br /><br />'; |
54 | 95 | } |
55 | 96 | |
56 | | - $output .="HISTORY:<br>"; |
| 97 | + $output .= 'HISTORY:<br />'; |
57 | 98 | |
58 | | - $userHistory = $us_class->useStatusHistory('select', $user_id); |
59 | | - if(empty ($userHistory)) { |
60 | | - $output .= "No history"; |
| 99 | + $userHistory = $us_class->useStatusHistory( 'select', $user_id ); |
| 100 | + if( empty( $userHistory ) ) { |
| 101 | + $output .= 'No history'; |
61 | 102 | } else { |
62 | 103 | foreach ( $userHistory as $row ) { |
63 | | - $output .= "<input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
| 104 | + $output .= "<input id=\"ush_delete\" type=\"button\" value=\"Delete\" |
64 | 105 | onclick=\"javascript:UserStatus.specialHistoryDelete('".$row['ush_id']."');\">" |
65 | | - .$row['ush_timestamp']." - ".$row['ush_status']." <br>"; |
| 106 | + .$row['ush_timestamp']." - ".$row['ush_status']." <br />"; |
66 | 107 | } |
67 | 108 | } |
68 | 109 | } |
— | — | @@ -71,15 +112,15 @@ |
72 | 113 | $wgAjaxExportList[] = 'SpecialHistoryDelete'; |
73 | 114 | function SpecialHistoryDelete( $id ) { |
74 | 115 | $us_class = new UserStatusClass(); |
75 | | - $us_class->removeHistoryStatus($id); |
76 | | - return ""; |
| 116 | + $us_class->removeHistoryStatus( $id ); |
| 117 | + return ''; |
77 | 118 | } |
78 | 119 | |
79 | 120 | $wgAjaxExportList[] = 'SpecialStatusDelete'; |
80 | 121 | function SpecialStatusDelete( $id ) { |
81 | 122 | $us_class = new UserStatusClass(); |
82 | | - $us_class->removeStatus($id); |
83 | | - return ""; |
| 123 | + $us_class->removeStatus( $id ); |
| 124 | + return ''; |
84 | 125 | } |
85 | 126 | |
86 | 127 | $wgHooks['MakeGlobalVariablesScript'][] = 'addJSGlobals'; |
— | — | @@ -96,17 +137,83 @@ |
97 | 138 | |
98 | 139 | $wgHooks['UserProfileBeginRight'][] = 'wfUserProfileStatusOutput'; |
99 | 140 | |
| 141 | +/** |
| 142 | + * Show status updates in user profiles if this feature is enabled. |
| 143 | + * |
| 144 | + * @param $user_profile UserProfile: instance of UserProfile |
| 145 | + * @return Boolean: true |
| 146 | + */ |
100 | 147 | function wfUserProfileStatusOutput( $user_profile ) { |
101 | | - global $wgOut , $wgEnableUserStatus; |
| 148 | + global $wgOut, $wgUser, $wgEnableUserStatus; |
| 149 | + |
102 | 150 | if ( $wgEnableUserStatus ) { |
103 | | - $userStatus = $user_profile->getStatus( $user_profile->user_id ); |
| 151 | + $us_class = new UserStatusClass(); |
| 152 | + $user_status_array = $us_class->getStatus( $user_profile->user_id ); |
| 153 | + |
| 154 | + if ( empty( $user_status_array ) ) { |
| 155 | + $userStatus = ''; |
| 156 | + } else { |
| 157 | + $userStatus = $user_status_array['us_status']; |
| 158 | + } |
| 159 | + |
| 160 | + $editLink = ''; |
| 161 | + // This is the version of the status message that we can safely use in |
| 162 | + // JavaScript |
| 163 | + $jsEncodedStatusMsg = Xml::escapeJsString( htmlspecialchars( $userStatus ) ); |
| 164 | + |
| 165 | + // If the user is viewing their own profile, we can show the "edit" |
| 166 | + // link, provided that the user isn't blocked and that the database is |
| 167 | + // writable |
| 168 | + if ( $user_profile->user_id == $wgUser->getId() ) { |
| 169 | + if ( $wgUser->isBlocked() ) { |
| 170 | + $userStatus = wfMsg( 'userstatus-blocked' ); |
| 171 | + } |
| 172 | + |
| 173 | + // Database operations require write mode |
| 174 | + if ( wfReadOnly() ) { |
| 175 | + $userStatus = wfMsg( 'userstatus-readonly' ); |
| 176 | + } |
| 177 | + |
| 178 | + if ( !$wgUser->isBlocked() && !wfReadOnly() ) { |
| 179 | + $editLink = '<br /><a class="us-link" href="javascript:UserStatus.toEditMode();">' . |
| 180 | + wfMsg( 'userstatus-edit' ) . '</a>'; |
| 181 | + } |
| 182 | + } |
| 183 | + |
104 | 184 | $output = '<div id="status-box"> |
105 | 185 | <div id="status-box-top"></div> |
106 | 186 | <div id="status-box-content"> |
107 | | - <div id="user-status-block">' . $userStatus . '</div> |
108 | | - </div> |
| 187 | + <div id="user-status-block">' . |
| 188 | + htmlspecialchars( $userStatus ) . $editLink . |
| 189 | + '</div>'; |
| 190 | + |
| 191 | + // No need to show the editing controls to anyone else except the owner |
| 192 | + // of the profile |
| 193 | + if ( $user_profile->user_id == $wgUser->getId() ) { |
| 194 | + $output .= '<div id="status-edit-controls" style="display: none;"> |
| 195 | + <input id="user-status-input" type="text" size="50" value="' . |
| 196 | + htmlspecialchars( $userStatus ) . |
| 197 | + '" onkeyup="javascript:UserStatus.usLettersLeft();" /> |
| 198 | + <br /> |
| 199 | + <div id="status-bar"> |
| 200 | + <a class="us-link" href="javascript:UserStatus.saveStatus(\'' . $user_profile->user_id . '\');">' . |
| 201 | + wfMsg( 'userstatus-save' ) . '</a> |
| 202 | + <a class="us-link" href="javascript:UserStatus.useHistory(\'' . $user_profile->user_id . '\');">' . |
| 203 | + wfMsg( 'userstatus-history' ) . '</a> |
| 204 | + <a class="us-link" href="javascript:UserStatus.toShowMode();">' . |
| 205 | + wfMsg( 'userstatus-cancel' ) . '</a> |
| 206 | + <span id="status-letter-count"></span> |
| 207 | + </div> |
| 208 | + </div><!-- #status-edit-controls -->'; |
| 209 | + } else { |
| 210 | + // Public history link to the masses |
| 211 | + $output .= "<script>UserStatus.publicHistoryButton('{$user_profile->user_id}');</script>"; |
| 212 | + } |
| 213 | + |
| 214 | + $output .= '</div> |
109 | 215 | </div>'; |
110 | | - $wgOut->addHTML($output); |
| 216 | + $wgOut->addHTML( $output ); |
111 | 217 | } |
| 218 | + |
112 | 219 | return true; |
113 | 220 | } |
\ No newline at end of file |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.css |
— | — | @@ -1,31 +1,31 @@ |
2 | 2 | #status-box { |
3 | | - width : 440px; |
| 3 | + width: 440px; |
4 | 4 | padding: 0px; |
5 | 5 | margin: 0px; |
6 | 6 | } |
7 | 7 | |
8 | 8 | #status-box-top { |
9 | | - overflow:visible; |
| 9 | + overflow: visible; |
10 | 10 | margin-left: 34px; |
11 | 11 | width: 30px; |
12 | | - height:24px; |
13 | | - background-color:orange; |
| 12 | + height: 24px; |
| 13 | + background-color: orange; |
14 | 14 | background-image: url('../images/status-corner.png'); |
15 | 15 | } |
16 | 16 | |
17 | 17 | #status-box-content { |
18 | | - background-color:orange; |
19 | | - padding:10px; |
| 18 | + background-color: orange; |
| 19 | + padding: 10px; |
20 | 20 | border-radius: 22px; |
21 | 21 | /*height: 38px;*/ |
22 | 22 | } |
23 | 23 | |
24 | | -#user-status-block { |
| 24 | +#user-status-block, #status-edit-controls { |
25 | 25 | text-align: center; |
26 | 26 | color: white; |
27 | 27 | } |
28 | 28 | |
29 | | -#us-link { |
| 29 | +.us-link { |
30 | 30 | color: white; |
31 | 31 | font-size: 8pt; |
32 | 32 | text-decoration: underline; |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | #status-letter-count { |
51 | | - float:right; |
| 51 | + float: right; |
52 | 52 | margin-right: 20px; |
53 | 53 | font-size: 8pt; |
54 | 54 | } |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatus.js |
— | — | @@ -1,106 +1,115 @@ |
2 | 2 | var UserStatus = { |
3 | 3 | maxStatusLength : 70, |
4 | | - |
5 | | - toShowMode: function( status, id ) { |
6 | | - var textNode = document.createTextNode (this.returnJS(status)); |
7 | | - var textContainer = document.getElementById( 'user-status-block' ); |
8 | | - textContainer.innerHTML = ""; |
9 | | - textContainer.appendChild (textNode); |
10 | | - textContainer.innerHTML += '<br> <a id="us-link" href="javascript:UserStatus.toEditMode(\'' + |
11 | | - status + '\',' + id + ');">'+_US_EDIT+'</a>'; |
| 4 | + |
| 5 | + /** |
| 6 | + * Go back to viewing the status update from the editing mode. |
| 7 | + */ |
| 8 | + toShowMode: function() { |
| 9 | + jQuery( '#status-edit-controls' ).hide(); |
| 10 | + jQuery( '#user-status-block' ).show(); |
12 | 11 | }, |
13 | | - |
14 | | - usLettersLeft: function() { |
15 | | - var len = this.maxStatusLength - document.getElementById('user-status-input').value.length; |
16 | | - if ( len < 0 ) { |
17 | | - var usBlock = document.getElementById('user-status-input'); |
18 | | - document.getElementById('user-status-input').value = usBlock.value.slice(0,this.maxStatusLength); |
| 12 | + |
| 13 | + /** |
| 14 | + * Show the "X letters left" message when the user is typing a status |
| 15 | + * update. |
| 16 | + */ |
| 17 | + usLettersLeft: function() { |
| 18 | + var len = this.maxStatusLength - document.getElementById( 'user-status-input' ).value.length; |
| 19 | + if ( len < 0 ) { |
| 20 | + var usBlock = document.getElementById( 'user-status-input' ); |
| 21 | + document.getElementById( 'user-status-input' ).value = usBlock.value.slice( 0, this.maxStatusLength ); |
19 | 22 | len++; |
20 | 23 | } |
21 | | - document.getElementById('status-letter-count').innerHTML =len + " "+_US_LETTERS; |
| 24 | + document.getElementById( 'status-letter-count' ).innerHTML = len + ' ' + _US_LETTERS; |
22 | 25 | }, |
23 | | - |
| 26 | + |
24 | 27 | publicHistoryButton: function( id ) { |
25 | | - document.getElementById( 'user-status-block' ).innerHTML += '<br> <a id="us-link" href="javascript:UserStatus.useHistory(' + id + ');">'+_US_HISTORY+'</a>'; |
| 28 | + document.getElementById( 'user-status-block' ).innerHTML += |
| 29 | + '<br /> <a id="us-link" href="javascript:UserStatus.useHistory(' + id + ');">' + _US_HISTORY + '</a>'; |
26 | 30 | }, |
27 | | - |
28 | | - toEditMode: function( status, id ) { |
29 | | - var editbar = '<input id="user-status-input" type="text" size="50" value="' + |
30 | | - this.returnJS(status) + '" onkeyup="javascript:UserStatus.usLettersLeft();">'; |
31 | | - editbar += '<br> <div id="status-bar">'; |
32 | | - editbar += '<a id="us-link" href="javascript:UserStatus.saveStatus(' + id + ');">'+_US_SAVE+'</a>'; |
33 | | - editbar += ' <a id="us-link" href="javascript:UserStatus.useHistory(' + id + ');">'+_US_HISTORY+'</a>'; |
34 | | - editbar += ' <a id="us-link" href="javascript:UserStatus.toShowMode(\'' + status + '\',' + id + ');">'+_US_CANCEL+'</a>'; |
35 | | - editbar += '<span id="status-letter-count"></span></div>'; |
36 | | - document.getElementById( 'user-status-block' ).innerHTML = editbar; |
| 31 | + |
| 32 | + /** |
| 33 | + * Enter the edit mode by hiding the current status message and displaying |
| 34 | + * the hidden input field which allows the user to enter a new status |
| 35 | + * update + some other editing tools. |
| 36 | + */ |
| 37 | + toEditMode: function() { |
| 38 | + jQuery( '#user-status-block' ).hide(); |
| 39 | + jQuery( '#status-edit-controls' ).show(); |
37 | 40 | }, |
38 | | - |
39 | | - parseJS:function ( str ) { |
40 | | - var chars = Array( "<", ">", "\"", "'"); |
41 | | - var replacements = Array( "@l;", "@r;", "@dq;", "@q;"); |
42 | | - for (var i=0; i<chars.length; i++) { |
43 | | - var reg = new RegExp(chars[i], "gi"); |
44 | | - if(reg.test(str)) { |
45 | | - str = str.replace(reg, replacements[i]); |
46 | | - } |
47 | | - } |
48 | | - return str; |
49 | | - }, |
50 | | - |
51 | | - returnJS:function ( str ) { |
52 | | - var chars = Array( "<", ">", "\"", "'"); |
53 | | - var replacements = Array( "@l;", "@r;", "@dq;", "@q;"); |
54 | | - for (var i=0; i<chars.length; i++) { |
55 | | - var reg = new RegExp(replacements[i], "gi"); |
56 | | - if(reg.test(str)) { |
57 | | - str = str.replace(reg, chars[i]); |
58 | | - } |
59 | | - } |
60 | | - return str; |
61 | | - }, |
62 | 41 | |
| 42 | + /** |
| 43 | + * Save a status message into the database. |
| 44 | + * |
| 45 | + * @param id Integer: user ID number |
| 46 | + */ |
63 | 47 | saveStatus: function( id ) { |
64 | 48 | var div = document.getElementById( 'user-status-block' ); |
65 | | - var ustext = document.getElementById( 'user-status-input' ).value; |
66 | | - var ust = this.parseJS(ustext); |
67 | | - sajax_do_call( 'wfSaveStatus', [id, ust], div ); |
| 49 | + var ustext = encodeURIComponent( document.getElementById( 'user-status-input' ).value ); |
| 50 | + sajax_do_call( 'wfSaveStatus', [id, ustext], function( r ) { |
| 51 | + div.innerHTML = r.responseText; |
| 52 | + jQuery( '#status-edit-controls' ).hide(); |
| 53 | + jQuery( '#user-status-block' ).show(); |
| 54 | + }); |
68 | 55 | }, |
69 | 56 | |
70 | | - useHistory: function( id ){ |
71 | | - var historyBlock = document.getElementById('status-history-block'); |
72 | | - if(historyBlock===null) { |
73 | | - var statusBlock = document.getElementById('user-status-block'); |
74 | | - historyBlock = document.createElement('div'); |
| 57 | + /** |
| 58 | + * Show the user's past status messages when they click on the "history" |
| 59 | + * link on their profile. |
| 60 | + * |
| 61 | + * @param id Integer: user ID number |
| 62 | + */ |
| 63 | + useHistory: function( id ) { |
| 64 | + var historyBlock = document.getElementById( 'status-history-block' ); |
| 65 | + if( historyBlock === null ) { |
| 66 | + var statusBlock; |
| 67 | + if ( document.getElementById( 'status-edit-controls' ) ) { |
| 68 | + // This div is present only when you're viewing your own |
| 69 | + // profile, it doesn't exist when you're viewing other people's |
| 70 | + // profiles |
| 71 | + statusBlock = document.getElementById( 'status-edit-controls' ); |
| 72 | + } else { |
| 73 | + statusBlock = document.getElementById( 'user-status-block' ); |
| 74 | + } |
| 75 | + historyBlock = document.createElement( 'div' ); |
75 | 76 | historyBlock.id = 'status-history-block'; |
76 | | - statusBlock.appendChild(historyBlock); |
| 77 | + statusBlock.appendChild( historyBlock ); |
77 | 78 | sajax_do_call( 'wfGetHistory', [id], historyBlock ); |
78 | 79 | } |
79 | | - |
80 | | - if (historyBlock.style.display == "block") { |
81 | | - historyBlock.style.display = "none"; |
| 80 | + |
| 81 | + if ( jQuery( '#status-history-block' ).is( 'visible' ) ) { |
| 82 | + jQuery( '#status-history-block' ).hide(); |
82 | 83 | } else { |
83 | | - historyBlock.style.display = "block"; |
| 84 | + jQuery( '#status-history-block' ).show(); |
84 | 85 | } |
85 | 86 | }, |
86 | 87 | |
87 | | - fromHistoryToStatus: function( str ) { |
88 | | - document.getElementById('user-status-input').value = this.returnJS(str); |
| 88 | + /** |
| 89 | + * Insert a previously used status message from the history list into the |
| 90 | + * editing <input> whenever the user clicks on an archived status message. |
| 91 | + * |
| 92 | + * @param statusId Integer: status message ID, used in the HTML element as |
| 93 | + * an ID |
| 94 | + */ |
| 95 | + insertStatusFromHistory: function( statusId ) { |
| 96 | + document.getElementById( 'user-status-input' ).value = |
| 97 | + jQuery( '#status-history-entry-' + statusId ).text(); |
89 | 98 | }, |
90 | | - |
| 99 | + |
91 | 100 | specialGetHistory: function() { |
92 | | - var us_name = document.getElementById("us-name-input").value; |
93 | | - var block = document.getElementById("us-special"); |
| 101 | + var us_name = document.getElementById( 'us-name-input' ).value; |
| 102 | + var block = document.getElementById( 'us-special' ); |
94 | 103 | sajax_do_call( 'SpecialGetStatusByName', [us_name], block ); |
95 | 104 | }, |
96 | | - |
97 | | - specialHistoryDelete: function(id) { |
98 | | - var block = document.getElementById("us-special"); |
| 105 | + |
| 106 | + specialHistoryDelete: function( id ) { |
| 107 | + var block = document.getElementById( 'us-special' ); |
99 | 108 | sajax_do_call( 'SpecialHistoryDelete', [id], block ); |
100 | 109 | this.specialGetHistory(); |
101 | 110 | }, |
102 | | - |
103 | | - specialStatusDelete: function(id) { |
104 | | - var block = document.getElementById("us-special"); |
| 111 | + |
| 112 | + specialStatusDelete: function( id ) { |
| 113 | + var block = document.getElementById( 'us-special' ); |
105 | 114 | sajax_do_call( 'SpecialStatusDelete', [id], block ); |
106 | 115 | this.specialGetHistory(); |
107 | 116 | } |
Index: trunk/extensions/SocialProfile/UserStatus/UserStatusClass.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Class to manipulate user-specific status messages. |
5 | | - * |
| 5 | + * |
6 | 6 | * @file |
7 | 7 | */ |
8 | 8 | class UserStatusClass { |
— | — | @@ -30,17 +30,21 @@ |
31 | 31 | $message = array( |
32 | 32 | 'us_id' => $row->us_id, |
33 | 33 | 'us_user_id' => $row->us_user_id, |
34 | | - 'us_status' => htmlspecialchars( $row->us_status ), |
| 34 | + 'us_status' => $row->us_status, |
35 | 35 | ); |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
39 | 39 | return $message; |
40 | 40 | } |
41 | | - |
| 41 | + |
42 | 42 | public function removeStatus( $status_id ) { |
43 | | - $dbr = wfGetDB( DB_MASTER ); |
44 | | - $dbr->delete('user_status', array( 'us_id' => $status_id ), __METHOD__); |
| 43 | + $dbw = wfGetDB( DB_MASTER ); |
| 44 | + $dbw->delete( |
| 45 | + 'user_status', |
| 46 | + array( 'us_id' => $status_id ), |
| 47 | + __METHOD__ |
| 48 | + ); |
45 | 49 | return; |
46 | 50 | } |
47 | 51 | |
— | — | @@ -51,8 +55,8 @@ |
52 | 56 | * @param $message String: user-supplied status message |
53 | 57 | */ |
54 | 58 | public function setStatus( $u_id, $message ) { |
55 | | - $message = trim($message); |
56 | | - if (( mb_strlen( $message ) > 90 ) || ( mb_strlen( $message ) < 1 )) { |
| 59 | + $message = trim( $message ); |
| 60 | + if ( ( mb_strlen( $message ) > 90 ) || ( mb_strlen( $message ) < 1 ) ) { |
57 | 61 | // INFO. Letter limit is 70, but here is 90, for special characters. |
58 | 62 | // ERROR. Message length is too long |
59 | 63 | return; |
— | — | @@ -122,7 +126,7 @@ |
123 | 127 | 'ush_user_id' => $row->ush_user_id, |
124 | 128 | 'ush_timestamp' => $row->ush_timestamp, |
125 | 129 | 'ush_status' => $row->ush_status, |
126 | | - 'ush_likes' => $row->ush_likes, |
| 130 | + 'ush_likes' => ( isset( $row->ush_likes ) ? $row->ush_likes : 0 ), |
127 | 131 | ); |
128 | 132 | } |
129 | 133 | |
— | — | @@ -132,7 +136,7 @@ |
133 | 137 | |
134 | 138 | if ( $mode == 'insert' ) { |
135 | 139 | $currentStatus = $this->getStatus( $u_id ); |
136 | | - |
| 140 | + |
137 | 141 | if ( $i < 4 ) { |
138 | 142 | $dbw->insert( |
139 | 143 | 'user_status_history', |
— | — | @@ -158,22 +162,14 @@ |
159 | 163 | return; |
160 | 164 | } |
161 | 165 | } |
162 | | - |
| 166 | + |
163 | 167 | public function removeHistoryStatus( $status_id ) { |
164 | | - $dbr = wfGetDB( DB_MASTER ); |
165 | | - $dbr->delete('user_status_history', array( 'ush_id' => $status_id ), __METHOD__); |
| 168 | + $dbw = wfGetDB( DB_MASTER ); |
| 169 | + $dbw->delete( |
| 170 | + 'user_status_history', |
| 171 | + array( 'ush_id' => $status_id ), |
| 172 | + __METHOD__ |
| 173 | + ); |
166 | 174 | return; |
167 | 175 | } |
168 | | - |
169 | | - public function usHTMLcharacters( $str ) { |
170 | | - $regexp = array( "@q;", "@dq;", "@l;", "@r;" ); |
171 | | - $replacement = array ("'", "\"", "<", ">" ); |
172 | | - |
173 | | - $newstr=$str; |
174 | | - for ($i=0; $i<count($regexp);$i++) { |
175 | | - $newstr = str_replace($regexp[$i],$replacement[$i],$newstr); |
176 | | - } |
177 | | - |
178 | | - return $newstr; |
179 | | - } |
180 | 176 | } |
\ No newline at end of file |
Index: trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php |
— | — | @@ -1782,32 +1782,4 @@ |
1783 | 1783 | return $output; |
1784 | 1784 | } |
1785 | 1785 | |
1786 | | - function getStatus( $userId ) { |
1787 | | - global $wgUser; |
1788 | | - |
1789 | | - $us_class = new UserStatusClass(); |
1790 | | - $user_status_array = $us_class->getStatus( $userId ); |
1791 | | - if ( empty( $user_status_array ) ) { |
1792 | | - $buf = ''; |
1793 | | - } else { |
1794 | | - $buf = $user_status_array['us_status']; |
1795 | | - } |
1796 | | - |
1797 | | - // Only owners of the page can change statuses |
1798 | | - if ( $wgUser->getId() == $userId ) { |
1799 | | - if ( $wgUser->isBlocked() ) { |
1800 | | - return wfMsg( 'userstatus-blocked' ); |
1801 | | - } |
1802 | | - |
1803 | | - // Database operations require write mode |
1804 | | - if ( wfReadOnly() ) { |
1805 | | - return wfMsg( 'userstatus-readonly' ); |
1806 | | - } |
1807 | | - |
1808 | | - return "<script>UserStatus.toShowMode('$buf','$userId');</script>"; |
1809 | | - } else { |
1810 | | - return $buf."<script>UserStatus.publicHistoryButton('$userId');</script>"; |
1811 | | - } |
1812 | | - } |
1813 | | - |
1814 | 1786 | } |