Index: trunk/extensions/SocialProfile/UserBoard/SpecialUserBoard.php |
— | — | @@ -0,0 +1,328 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + die(); |
| 5 | +} |
| 6 | +/** |
| 7 | + * Display User Board messages for a user |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
| 11 | + * @author David Pean <david.pean@gmail.com> |
| 12 | + * @copyright Copyright © 2007, Wikia Inc. |
| 13 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 14 | + */ |
| 15 | + |
| 16 | +class SpecialViewUserBoard extends SpecialPage { |
| 17 | + |
| 18 | + /** |
| 19 | + * Constructor |
| 20 | + */ |
| 21 | + public function __construct() { |
| 22 | + parent::__construct( 'UserBoard' ); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Show the special page |
| 27 | + * |
| 28 | + * @param $params Mixed: parameter(s) passed to the page or null |
| 29 | + */ |
| 30 | + public function execute( $params ) { |
| 31 | + global $wgUser, $wgOut, $wgRequest, $wgScriptPath, $wgUserBoardScripts; |
| 32 | + |
| 33 | + // Add CSS |
| 34 | + $wgOut->addExtensionStyle( $wgUserBoardScripts . '/UserBoard.css' ); |
| 35 | + |
| 36 | + $ub_messages_show = 25; |
| 37 | + $user_name = $wgRequest->getVal( 'user' ); |
| 38 | + $user_name_2 = $wgRequest->getVal( 'conv' ); |
| 39 | + $user_id_2 = ''; // Prevent E_NOTICE |
| 40 | + $page = $wgRequest->getVal( 'page' ); |
| 41 | + |
| 42 | + /** |
| 43 | + * Redirect Non-logged in users to Login Page |
| 44 | + * It will automatically return them to the UserBoard page |
| 45 | + */ |
| 46 | + if ( $wgUser->getID() == 0 && $user_name == '' ) { |
| 47 | + $login = SpecialPage::getTitleFor( 'Userlogin' ); |
| 48 | + $wgOut->redirect( $login->getFullURL( 'returnto=Special:UserBoard' ) ); |
| 49 | + return false; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * If no user is set in the URL, we assume its the current user |
| 54 | + */ |
| 55 | + if ( !$user_name ) { |
| 56 | + $user_name = $wgUser->getName(); |
| 57 | + } |
| 58 | + $user_id = User::idFromName( $user_name ); |
| 59 | + $user = Title::makeTitle( NS_USER, $user_name ); |
| 60 | + $user_safe = str_replace( '&', '%26', $user_name ); |
| 61 | + |
| 62 | + if ( $user_name_2 ) { |
| 63 | + $user_id_2 = User::idFromName( $user_name_2 ); |
| 64 | + $user_2 = Title::makeTitle( NS_USER, $user_name ); |
| 65 | + $user_safe_2 = urlencode( $user_name_2 ); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Error message for username that does not exist (from URL) |
| 70 | + */ |
| 71 | + if ( $user_id == 0 ) { |
| 72 | + $wgOut->showErrorPage( 'error', 'userboard_noexist' ); |
| 73 | + return false; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Config for the page |
| 78 | + */ |
| 79 | + $per_page = $ub_messages_show; |
| 80 | + if ( !$page || !is_numeric( $page ) ) { |
| 81 | + $page = 1; |
| 82 | + } |
| 83 | + |
| 84 | + $b = new UserBoard(); |
| 85 | + $ub_messages = $b->getUserBoardMessages( $user_id, $user_id_2, $ub_messages_show, $page ); |
| 86 | + |
| 87 | + if ( !$user_id_2 ) { |
| 88 | + $stats = new UserStats( $user_id, $user_name ); |
| 89 | + $stats_data = $stats->getUserStats(); |
| 90 | + $total = $stats_data['user_board']; |
| 91 | + // If user is viewing their own board or is allowed to delete |
| 92 | + // others' board messages, show the total count of board messages |
| 93 | + // to them (public + private messages) |
| 94 | + if ( $wgUser->getName() == $user_name || $wgUser->isAllowed( 'userboard-delete' ) ) { |
| 95 | + $total = $total + $stats_data['user_board_priv']; |
| 96 | + } |
| 97 | + } else { |
| 98 | + $total = $b->getUserBoardToBoardCount( $user_id, $user_id_2 ); |
| 99 | + } |
| 100 | + |
| 101 | + if ( !$user_id_2 ) { |
| 102 | + if ( !( $wgUser->getName() == $user_name ) ) { |
| 103 | + $wgOut->setPageTitle( wfMsg( 'userboard_owner', $user_name ) ); |
| 104 | + } else { |
| 105 | + $b->clearNewMessageCount( $wgUser->getID() ); |
| 106 | + $wgOut->setPageTitle( wfMsg( 'userboard_yourboard' ) ); |
| 107 | + } |
| 108 | + } else { |
| 109 | + if ( $wgUser->getName() == $user_name ) { |
| 110 | + $wgOut->setPageTitle( wfMsg( 'userboard_yourboardwith', $user_name_2 ) ); |
| 111 | + } else { |
| 112 | + $wgOut->setPageTitle( wfMsg( 'userboard_otherboardwith', $user_name, $user_name_2 ) ); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + $output = '<div class="user-board-top-links">'; |
| 117 | + $output .= '<a href="' . $user->escapeFullURL() . '">< ' . wfMsg( 'userboard_backprofile', $user_name ) . '</a>'; |
| 118 | + $output .= '</div>'; |
| 119 | + $output .= "<script type=\"text/javascript\">/*<![CDATA[*/ |
| 120 | + var _DELETE_CONFIRM = \"" . wfMsg( 'userboard_confirmdelete' ) . "\"; |
| 121 | + var posted = 0; |
| 122 | + function send_message() { |
| 123 | + if( document.getElementById('message').value && !posted ) { |
| 124 | + posted = 1; |
| 125 | + encodedName = encodeURIComponent( document.getElementById('user_name_to').value ); |
| 126 | + encodedMsg = encodeURIComponent( document.getElementById('message').value ); |
| 127 | + messageType = document.getElementById('message_type').value; |
| 128 | + sajax_request_type = 'POST'; |
| 129 | + sajax_do_call( 'wfSendBoardMessage', [ encodedName, encodedMsg, messageType, {$per_page} ], function( originalRequest ) { |
| 130 | + posted = 0; |
| 131 | + if( document.getElementById('user_name_from').value ) { // its a board to board |
| 132 | + user_1 = document.getElementById('user_name_from').value; |
| 133 | + user_2 = document.getElementById('user_name_to').value; |
| 134 | + } else { |
| 135 | + user_1 = document.getElementById('user_name_to').value; |
| 136 | + user_2 = ''; |
| 137 | + } |
| 138 | + var params = ( user_2 ) ? '&conv=' + user_2 : ''; |
| 139 | + var url = wgScriptPath + '/index.php?title=Special:UserBoard&user=' + user_1 + params; |
| 140 | + window.location = url; |
| 141 | + } |
| 142 | + ); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + function delete_message( id ) { |
| 147 | + if( confirm( _DELETE_CONFIRM ) ) { |
| 148 | + sajax_request_type = 'POST'; |
| 149 | + sajax_do_call( 'wfDeleteBoardMessage', [ id ], function( originalRequest ) { |
| 150 | + window.location.reload(); |
| 151 | + }); |
| 152 | + } |
| 153 | + } |
| 154 | + /*]]>*/</script>"; |
| 155 | + |
| 156 | + $board_to_board = ''; // Prevent E_NOTICE |
| 157 | + |
| 158 | + if ( $page == 1 ) { |
| 159 | + $start = 1; |
| 160 | + } else { |
| 161 | + $start = ( $page - 1 ) * $per_page + 1; |
| 162 | + } |
| 163 | + $end = $start + ( count( $ub_messages ) ) - 1; |
| 164 | + |
| 165 | + if ( $wgUser->getName() != $user_name ) { |
| 166 | + $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL( $wgUser->getName(), $user_name ) . '">' . wfMsg( 'userboard_boardtoboard' ) . '</a>'; |
| 167 | + } |
| 168 | + |
| 169 | + if ( $total ) { |
| 170 | + $output .= '<div class="user-page-message-top"> |
| 171 | + <span class="user-page-message-count" style="font-size:11px;color:#666666;">' |
| 172 | + . wfMsg( 'userboard_showingmessages', $total, $start, $end, $end - $start + 1 ) . |
| 173 | + ".</span> {$board_to_board}</span> |
| 174 | + </div>"; |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Build next/prev nav |
| 179 | + */ |
| 180 | + if ( $user_id_2 ) { |
| 181 | + $qs = "&conv={$user_safe_2}"; |
| 182 | + } |
| 183 | + $numofpages = $total / $per_page; |
| 184 | + |
| 185 | + if ( $numofpages > 1 ) { |
| 186 | + $output .= '<div class="page-nav">'; |
| 187 | + if ( $page > 1 ) { |
| 188 | + $output .= '<a href="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page=" . ( $page - 1 ) . "{$qs}\">" . wfMsg( 'userboard_prevpage' ) . '</a>'; |
| 189 | + } |
| 190 | + |
| 191 | + if ( ( $total % $per_page ) != 0 ) { |
| 192 | + $numofpages++; |
| 193 | + } |
| 194 | + if ( $numofpages >= 9 && $page < $total ) { |
| 195 | + $numofpages = 9 + $page; |
| 196 | + if ( $numofpages >= ( $total / $per_page ) ) { |
| 197 | + $numofpages = ( $total / $per_page ) + 1; |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + for ( $i = 1; $i <= $numofpages; $i++ ) { |
| 202 | + if ( $i == $page ) { |
| 203 | + $output .= ( $i . ' ' ); |
| 204 | + } else { |
| 205 | + $output .= '<a href="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page=$i{$qs}\">$i</a> "; |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + if ( ( $total - ( $per_page * $page ) ) > 0 ) { |
| 210 | + $output .= ' <a href="' . $wgScriptPath . "/index.php?title=Special:UserBoard&user={$user_safe}&page=" . ( $page + 1 ) . "{$qs}\">" . wfMsg( 'userboard_nextpage' ) . '</a>'; |
| 211 | + } |
| 212 | + $output .= '</div><p>'; |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Build next/prev nav |
| 217 | + */ |
| 218 | + $can_post = false; |
| 219 | + $user_name_from = ''; // Prevent E_NOTICE |
| 220 | + |
| 221 | + if ( !$user_id_2 ) { |
| 222 | + if ( $wgUser->getName() != $user_name ) { |
| 223 | + $can_post = true; |
| 224 | + $user_name_to = htmlspecialchars( $user_name, ENT_QUOTES ); |
| 225 | + } |
| 226 | + } else { |
| 227 | + if ( $wgUser->getName() == $user_name ) { |
| 228 | + $can_post = true; |
| 229 | + $user_name_to = htmlspecialchars( $user_name_2, ENT_QUOTES ); |
| 230 | + $user_name_from = htmlspecialchars( $user_name, ENT_QUOTES ); |
| 231 | + } |
| 232 | + } |
| 233 | + if ( $wgUser->isBlocked() ) { |
| 234 | + // only let them post to admins |
| 235 | + $user_to = User::newFromId( $user_id ); |
| 236 | + $user_to->loadFromId(); |
| 237 | + // if( !$user_to->isAllowed( 'delete' ) ) { |
| 238 | + $can_post = false; |
| 239 | + // } |
| 240 | + } |
| 241 | + |
| 242 | + if ( $can_post ) { |
| 243 | + if ( $wgUser->isLoggedIn() && !$wgUser->isBlocked() ) { |
| 244 | + $output .= '<div class="user-page-message-form"> |
| 245 | + <input type="hidden" id="user_name_to" name="user_name_to" value="' . $user_name_to . '"/> |
| 246 | + <input type="hidden" id="user_name_from" name="user_name_from" value="' . $user_name_from . '"/> |
| 247 | + <span style="color:#797979;">' . wfMsg( 'userboard_messagetype' ) . ' </span> |
| 248 | + <select id="message_type"> |
| 249 | + <option value="0">' . wfMsg( 'userboard_public' ) . '</option> |
| 250 | + <option value="1">' . wfMsg( 'userboard_private' ) . '</option> |
| 251 | + </select> |
| 252 | + <p> |
| 253 | + <textarea name="message" id="message" cols="63" rows="4"></textarea> |
| 254 | + |
| 255 | + <div class="user-page-message-box-button"> |
| 256 | + <input type="button" value="' . wfMsg( 'userboard_sendbutton' ) . '" class="site-button" onclick="javascript:send_message();" /> |
| 257 | + </div> |
| 258 | + |
| 259 | + </div>'; |
| 260 | + } else { |
| 261 | + $login_link = SpecialPage::getTitleFor( 'Userlogin' ); |
| 262 | + $output .= '<div class="user-page-message-form">' |
| 263 | + . wfMsg( 'userboard_loggedout', $login_link->escapeFullURL() ) . |
| 264 | + '</div>'; |
| 265 | + } |
| 266 | + } |
| 267 | + $output .= '<div id="user-page-board">'; |
| 268 | + |
| 269 | + if ( $ub_messages ) { |
| 270 | + foreach ( $ub_messages as $ub_message ) { |
| 271 | + $user = Title::makeTitle( NS_USER, $ub_message['user_name_from'] ); |
| 272 | + $avatar = new wAvatar( $ub_message['user_id_from'], 'm' ); |
| 273 | + |
| 274 | + $board_to_board = ''; |
| 275 | + $board_link = ''; |
| 276 | + $ub_message_type_label = ''; |
| 277 | + $delete_link = ''; |
| 278 | + if ( $wgUser->getName() != $ub_message['user_name_from'] ) { |
| 279 | + $board_to_board = '<a href="' . UserBoard::getUserBoardToBoardURL( $user_name, $ub_message['user_name_from'] ) . '">' . wfMsg( 'userboard_boardtoboard' ) . '</a>'; |
| 280 | + $board_link = '<a href="' . UserBoard::getUserBoardURL( $ub_message['user_name_from'] ) . '">' . wfMsg( 'userboard_sendmessage', $ub_message['user_name_from'] ) . '</a>'; |
| 281 | + } else { |
| 282 | + $board_link = '<a href="' . UserBoard::getUserBoardURL( $ub_message['user_name_from'] ) . '">' . wfMsg( 'userboard_myboard' ) . '</a>'; |
| 283 | + } |
| 284 | + if ( $wgUser->getName() == $ub_message['user_name'] || $wgUser->isAllowed( 'userboard-delete' ) ) { |
| 285 | + $delete_link = "<span class=\"user-board-red\"> |
| 286 | + <a href=\"javascript:void(0);\" onclick=\"javascript:delete_message({$ub_message['id']})\">" . wfMsg( 'userboard_delete' ) . '</a> |
| 287 | + </span>'; |
| 288 | + } |
| 289 | + if ( $ub_message['type'] == 1 ) { |
| 290 | + $ub_message_type_label = '(' . wfMsg( 'userboard_private' ) . ')'; |
| 291 | + } |
| 292 | + |
| 293 | + // had global function to cut link text if too long and no breaks |
| 294 | + // $ub_message_text = preg_replace_callback( "/(<a[^>]*>)(.*?)(<\/a>)/i", 'cut_link_text', $ub_message['message_text'] ); |
| 295 | + $ub_message_text = $ub_message['message_text']; |
| 296 | + |
| 297 | + $output .= "<div class=\"user-board-message\" style=\"width:550px\"> |
| 298 | + <div class=\"user-board-message-from\"> |
| 299 | + <a href=\"{$user->escapeFullURL()}\" title=\"{$ub_message['user_name_from']}}\">{$ub_message['user_name_from']} </a> {$ub_message_type_label} |
| 300 | + </div> |
| 301 | + <div class=\"user-board-message-time\">" |
| 302 | + . wfMsgHtml( 'userboard_posted_ago', $b->getTimeAgo( $ub_message['timestamp'] ) ) . |
| 303 | + "</div> |
| 304 | + <div class=\"user-board-message-content\"> |
| 305 | + <div class=\"user-board-message-image\"> |
| 306 | + <a href=\"{$user->escapeFullURL()}\" title=\"{$ub_message['user_name_from']}\">{$avatar->getAvatarURL()}</a> |
| 307 | + </div> |
| 308 | + <div class=\"user-board-message-body\"> |
| 309 | + {$ub_message_text} |
| 310 | + </div> |
| 311 | + <div class=\"cleared\"></div> |
| 312 | + </div> |
| 313 | + <div class=\"user-board-message-links\"> |
| 314 | + {$board_link} |
| 315 | + {$board_to_board} |
| 316 | + {$delete_link} |
| 317 | + </div> |
| 318 | + </div>"; |
| 319 | + } |
| 320 | + } else { |
| 321 | + $invite_title = SpecialPage::getTitleFor( 'InviteContacts' ); |
| 322 | + $output .= '<p>' . wfMsg( 'userboard_nomessages', $invite_title->escapeFullURL() ) . '</p>'; |
| 323 | + } |
| 324 | + |
| 325 | + $output .= '</div>'; |
| 326 | + |
| 327 | + $wgOut->addHTML( $output ); |
| 328 | + } |
| 329 | +} |
Property changes on: trunk/extensions/SocialProfile/UserBoard/SpecialUserBoard.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 330 | + native |