Index: trunk/extensions/SocialProfile/UserProfile/UserProfile.i18n.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | 'user-time-ago' => '$1 ago', |
20 | 20 | 'user-awards-title' => 'Awards', |
21 | 21 | 'user-gifts-title' => 'Gifts', |
| 22 | + 'user-fanbox-title' => 'Fanboxes', |
22 | 23 | 'user-count-separator' => '$1 of $2', |
23 | 24 | 'user-view-all' => 'View all', |
24 | 25 | 'user-upload-image' => 'Upload image', |
— | — | @@ -42,6 +43,10 @@ |
43 | 44 | 'user-stats-picture-game-votes' => 'Picture game {{PLURAL:$1|vote|votes}}', |
44 | 45 | 'user-stats-quiz-points' => 'Quiz {{PLURAL:$1|point|points}}', |
45 | 46 | 'user-stats-pick-points' => 'Pick \'em {{PLURAL:$1|point|points}}', |
| 47 | + 'casual-games-title' => 'Casual Games', |
| 48 | + 'casual-game-quiz' => 'Quiz', |
| 49 | + 'casual-game-poll' => 'Poll', |
| 50 | + 'casual-game-picture-game' => 'Picture Game', |
46 | 51 | 'other-info-title' => 'Other information', |
47 | 52 | 'user-friends-title' => 'Friends', |
48 | 53 | 'user-foes-title' => 'Foes', |
Index: trunk/extensions/SocialProfile/UserProfile/UserProfilePage.php |
— | — | @@ -94,6 +94,7 @@ |
95 | 95 | |
96 | 96 | $wgOut->addHTML( $this->getPersonalInfo( $this->user_id, $this->user_name ) ); |
97 | 97 | $wgOut->addHTML( $this->getActivity( $this->user_name ) ); |
| 98 | + $wgOut->addHTML( $this->getCasualGames( $this->user_id, $this->user_name ) ); |
98 | 99 | $wgOut->addHTML( $this->getUserBoard( $this->user_id, $this->user_name ) ); |
99 | 100 | |
100 | 101 | if ( !wfRunHooks( 'UserProfileEndRight', array( &$this ) ) ) { |
— | — | @@ -188,6 +189,287 @@ |
189 | 190 | return $output; |
190 | 191 | } |
191 | 192 | |
| 193 | + /** |
| 194 | + * Get three of the polls the user has created and cache the data in |
| 195 | + * memcached. |
| 196 | + * |
| 197 | + * @return Array |
| 198 | + */ |
| 199 | + function getUserPolls() { |
| 200 | + global $wgMemc; |
| 201 | + |
| 202 | + $polls = array(); |
| 203 | + |
| 204 | + // Try cache |
| 205 | + $key = wfMemcKey( 'user', 'profile', 'polls', $this->user_id ); |
| 206 | + $data = $wgMemc->get( $key ); |
| 207 | + |
| 208 | + if( $data ) { |
| 209 | + wfDebug( "Got profile polls for user {$this->user_id} from cache\n" ); |
| 210 | + $polls = $data; |
| 211 | + } else { |
| 212 | + wfDebug( "Got profile polls for user {$this->user_id} from DB\n" ); |
| 213 | + $dbr = wfGetDB( DB_SLAVE ); |
| 214 | + $res = $dbr->select( |
| 215 | + array( 'poll_question', 'page' ), |
| 216 | + array( |
| 217 | + 'page_title', 'UNIX_TIMESTAMP(poll_date) AS poll_date' |
| 218 | + ), |
| 219 | + /*where*/ array( 'poll_user_id' => $this->user_id ), |
| 220 | + __METHOD__, |
| 221 | + array( 'ORDER BY' => 'poll_id DESC', 'LIMIT' => 3 ), |
| 222 | + array( 'page' => array( 'INNER JOIN', 'page_id = poll_page_id' ) ) |
| 223 | + ); |
| 224 | + foreach( $res as $row ) { |
| 225 | + $polls[] = array( |
| 226 | + 'title' => $row->page_title, |
| 227 | + 'timestamp' => $row->poll_date |
| 228 | + ); |
| 229 | + } |
| 230 | + $wgMemc->set( $key, $polls ); |
| 231 | + } |
| 232 | + return $polls; |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Get three of the quiz games the user has created and cache the data in |
| 237 | + * memcached. |
| 238 | + * |
| 239 | + * @return Array |
| 240 | + */ |
| 241 | + function getUserQuiz() { |
| 242 | + global $wgMemc; |
| 243 | + |
| 244 | + $quiz = array(); |
| 245 | + |
| 246 | + // Try cache |
| 247 | + $key = wfMemcKey( 'user', 'profile', 'quiz', $this->user_id ); |
| 248 | + $data = $wgMemc->get( $key ); |
| 249 | + |
| 250 | + if( $data ) { |
| 251 | + wfDebug( "Got profile quizzes for user {$this->user_id} from cache\n" ); |
| 252 | + $quiz = $data; |
| 253 | + } else { |
| 254 | + wfDebug( "Got profile quizzes for user {$this->user_id} from DB\n" ); |
| 255 | + $dbr = wfGetDB( DB_SLAVE ); |
| 256 | + $res = $dbr->select( |
| 257 | + 'quizgame_questions', |
| 258 | + array( |
| 259 | + 'q_id', 'q_text', 'UNIX_TIMESTAMP(q_date) AS quiz_date' |
| 260 | + ), |
| 261 | + array( |
| 262 | + 'q_user_id' => $this->user_id, |
| 263 | + 'q_flag' => 0 // the same as QUIZGAME_FLAG_NONE |
| 264 | + ), |
| 265 | + __METHOD__, |
| 266 | + array( |
| 267 | + 'ORDER BY' => 'q_id DESC', |
| 268 | + 'LIMIT' => 3 |
| 269 | + ) |
| 270 | + ); |
| 271 | + foreach( $res as $row ) { |
| 272 | + $quiz[] = array( |
| 273 | + 'id' => $row->q_id, |
| 274 | + 'text' => $row->q_text, |
| 275 | + 'timestamp' => $row->quiz_date |
| 276 | + ); |
| 277 | + } |
| 278 | + $wgMemc->set( $key, $quiz ); |
| 279 | + } |
| 280 | + |
| 281 | + return $quiz; |
| 282 | + } |
| 283 | + |
| 284 | + /** |
| 285 | + * Get three of the picture games the user has created and cache the data |
| 286 | + * in memcached. |
| 287 | + * |
| 288 | + * @return Array |
| 289 | + */ |
| 290 | + function getUserPicGames() { |
| 291 | + global $wgMemc; |
| 292 | + |
| 293 | + $pics = array(); |
| 294 | + |
| 295 | + // Try cache |
| 296 | + $key = wfMemcKey( 'user', 'profile', 'picgame', $this->user_id ); |
| 297 | + $data = $wgMemc->get( $key ); |
| 298 | + if( $data ) { |
| 299 | + wfDebug( "Got profile picgames for user {$this->user_id} from cache\n" ); |
| 300 | + $pics = $data; |
| 301 | + } else { |
| 302 | + wfDebug( "Got profile picgames for user {$this->user_id} from DB\n" ); |
| 303 | + $dbr = wfGetDB( DB_SLAVE ); |
| 304 | + $res = $dbr->select( |
| 305 | + 'picturegame_images', |
| 306 | + array( |
| 307 | + 'id', 'title', 'img1', 'img2', |
| 308 | + 'UNIX_TIMESTAMP(pg_date) AS pic_game_date' |
| 309 | + ), |
| 310 | + array( |
| 311 | + 'userid' => $this->user_id, |
| 312 | + 'flag' => 0 // PICTUREGAME_FLAG_NONE |
| 313 | + ), |
| 314 | + __METHOD__, |
| 315 | + array( |
| 316 | + 'ORDER BY' => 'id DESC', |
| 317 | + 'LIMIT' => 3 |
| 318 | + ) |
| 319 | + ); |
| 320 | + foreach( $res as $row ) { |
| 321 | + $pics[] = array( |
| 322 | + 'id' => $row->id, |
| 323 | + 'title' => $row->title, |
| 324 | + 'img1' => $row->img1, |
| 325 | + 'img2' => $row->img2, |
| 326 | + 'timestamp' => $row->pic_game_date |
| 327 | + ); |
| 328 | + } |
| 329 | + $wgMemc->set( $key, $pics ); |
| 330 | + } |
| 331 | + |
| 332 | + return $pics; |
| 333 | + } |
| 334 | + |
| 335 | + /** |
| 336 | + * Get the casual games (polls, quizzes and picture games) that the user |
| 337 | + * has created if $wgUserProfileDisplay['games'] is set to true and the |
| 338 | + * PictureGame, PollNY and QuizGame extensions have been installed. |
| 339 | + * |
| 340 | + * @param $user_id Integer: user ID number |
| 341 | + * @param $user_name String: user name |
| 342 | + * @return String: HTML or nothing if this feature isn't enabled |
| 343 | + */ |
| 344 | + function getCasualGames( $user_id, $user_name ) { |
| 345 | + global $wgUser, $wgTitle, $wgOut, $wgUserProfileDisplay; |
| 346 | + |
| 347 | + if ( $wgUserProfileDisplay['games'] == false ) { |
| 348 | + return ''; |
| 349 | + } |
| 350 | + |
| 351 | + $output = ''; |
| 352 | + |
| 353 | + // Safe titles |
| 354 | + $quiz_title = SpecialPage::getTitleFor( 'QuizGameHome' ); |
| 355 | + $pic_game_title = SpecialPage::getTitleFor( 'PictureGameHome' ); |
| 356 | + |
| 357 | + // Combine the queries |
| 358 | + $combined_array = array(); |
| 359 | + |
| 360 | + $quizzes = $this->getUserQuiz(); |
| 361 | + foreach( $quizzes as $quiz ) { |
| 362 | + $combined_array[] = array( |
| 363 | + 'type' => 'Quiz', |
| 364 | + 'id' => $quiz['id'], |
| 365 | + 'text' => $quiz['text'], |
| 366 | + 'timestamp' => $quiz['timestamp'] |
| 367 | + ); |
| 368 | + } |
| 369 | + |
| 370 | + $polls = $this->getUserPolls(); |
| 371 | + foreach( $polls as $poll ) { |
| 372 | + $combined_array[] = array( |
| 373 | + 'type' => 'Poll', |
| 374 | + 'title' => $poll['title'], |
| 375 | + 'timestamp' => $poll['timestamp'] |
| 376 | + ); |
| 377 | + } |
| 378 | + |
| 379 | + $pics = $this->getUserPicGames(); |
| 380 | + foreach( $pics as $pic ) { |
| 381 | + $combined_array[] = array( |
| 382 | + 'type' => 'Picture Game', |
| 383 | + 'id' => $pic['id'], |
| 384 | + 'title' => $pic['title'], |
| 385 | + 'img1' => $pic['img1'], |
| 386 | + 'img2' => $pic['img2'], |
| 387 | + 'timestamp' => $pic['timestamp'] |
| 388 | + ); |
| 389 | + } |
| 390 | + |
| 391 | + usort( $combined_array, array( 'UserProfilePage', 'sortItems' ) ); |
| 392 | + |
| 393 | + if ( count( $combined_array ) > 0 ) { |
| 394 | + $output .= '<div class="user-section-heading"> |
| 395 | + <div class="user-section-title">' . |
| 396 | + wfMsg('casual-games-title').' |
| 397 | + </div> |
| 398 | + <div class="user-section-actions"> |
| 399 | + <div class="action-right"> |
| 400 | + </div> |
| 401 | + <div class="action-left"> |
| 402 | + </div> |
| 403 | + <div class="cleared"></div> |
| 404 | + </div> |
| 405 | + </div> |
| 406 | + <div class="cleared"></div> |
| 407 | + <div class="casual-game-container">'; |
| 408 | + |
| 409 | + $x = 1; |
| 410 | + |
| 411 | + foreach( $combined_array as $item ) { |
| 412 | + $output .= ( ( $x == 1 ) ? '<p class="item-top">' : '<p>' ); |
| 413 | + |
| 414 | + if ( $item['type'] == 'Poll' ) { |
| 415 | + $ns = ( defined( 'NS_POLL' ) ? NS_POLL : 300 ); |
| 416 | + $poll_title = Title::makeTitle( $ns, $item['title'] ); |
| 417 | + $casual_game_title = wfMsg( 'casual-game-poll' ); |
| 418 | + $output .= '<a href="' . $poll_title->escapeFullURL() . |
| 419 | + "\" rel=\"nofollow\"> |
| 420 | + {$poll_title->getText()} |
| 421 | + </a> |
| 422 | + <span class=\"item-small\">{$casual_game_title}</span>"; |
| 423 | + } |
| 424 | + |
| 425 | + if ( $item['type'] == 'Quiz' ) { |
| 426 | + $casual_game_title = wfMsg( 'casual-game-quiz' ); |
| 427 | + $output .= '<a href="' . |
| 428 | + $quiz_title->escapeFullURL( 'questionGameAction=renderPermalink&permalinkID=' . $item['id'] ) . |
| 429 | + "\" rel=\"nofollow\"> |
| 430 | + {$item['text']} |
| 431 | + </a> |
| 432 | + <span class=\"item-small\">{$casual_game_title}</span>"; |
| 433 | + } |
| 434 | + |
| 435 | + if ( $item['type'] == 'Picture Game' ) { |
| 436 | + if( $item['img1'] != '' && $item['img2'] != '' ) { |
| 437 | + $image_1 = $image_2 = ''; |
| 438 | + $render_1 = wfFindFile( $item['img1'] ); |
| 439 | + if ( is_object( $render_1 ) ) { |
| 440 | + $thumb_1 = $render_1->getThumbnail( 25 ); |
| 441 | + $image_1 = $thumb_1->toHtml(); |
| 442 | + } |
| 443 | + |
| 444 | + $render_2 = wfFindFile( $item['img2'] ); |
| 445 | + if ( is_object( $render_2 ) ) { |
| 446 | + $thumb_2 = $render_2->getThumbnail( 25 ); |
| 447 | + $image_2 = $thumb_2->toHtml(); |
| 448 | + } |
| 449 | + |
| 450 | + $casual_game_title = wfMsg( 'casual-game-picture-game' ); |
| 451 | + |
| 452 | + $output .= '<a href="' . |
| 453 | + $pic_game_title->escapeFullURL( 'picGameAction=renderPermalink&id=' . $item['id'] ) . |
| 454 | + "\" rel=\"nofollow\"> |
| 455 | + {$image_1} |
| 456 | + {$image_2} |
| 457 | + {$item['title']} |
| 458 | + </a> |
| 459 | + <span class=\"item-small\">{$casual_game_title}</span>"; |
| 460 | + } |
| 461 | + } |
| 462 | + |
| 463 | + $output .= '</p>'; |
| 464 | + |
| 465 | + $x++; |
| 466 | + } |
| 467 | + |
| 468 | + $output .= '</div>'; |
| 469 | + } |
| 470 | + |
| 471 | + return $output; |
| 472 | + } |
| 473 | + |
192 | 474 | function sortItems( $x, $y ) { |
193 | 475 | if ( $x['timestamp'] == $y['timestamp'] ) { |
194 | 476 | return 0; |
Index: trunk/extensions/SocialProfile/UserProfile/UserProfile.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | $wgUserProfileDisplay['personal'] = true; |
20 | 20 | $wgUserProfileDisplay['activity'] = false; // Display recent social activity? |
21 | 21 | $wgUserProfileDisplay['userboxes'] = false; // If FanBoxes extension is installed, setting this to true will display the user's fanboxes on their profile page |
| 22 | +$wgUserProfileDisplay['games'] = false; // Display casual games created by the user on their profile? This requires three separate social extensions: PictureGame, PollNY and QuizGame |
22 | 23 | |
23 | 24 | $wgUpdateProfileInRecentChanges = false; // Show a log entry in recent changes whenever a user updates their profile? |
24 | 25 | $wgUploadAvatarInRecentChanges = false; // Same as above, but for avatar uploading |