Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManager.php |
— | — | @@ -1,9 +1,16 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Special:SystemGiftManager -- a special page to create new system gifts |
| 5 | + * (awards) |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
3 | 10 | |
4 | 11 | class SystemGiftManager extends SpecialPage { |
5 | 12 | |
6 | 13 | /** |
7 | | - * Constructor |
| 14 | + * Constructor -- set up the new special page |
8 | 15 | */ |
9 | 16 | public function __construct() { |
10 | 17 | parent::__construct( 'SystemGiftManager'/*class*/, 'awardsmanage'/*restriction*/ ); |
— | — | @@ -19,19 +26,19 @@ |
20 | 27 | |
21 | 28 | $wgOut->setPageTitle( wfMsg( 'systemgiftmanager' ) ); |
22 | 29 | |
23 | | - # If the user doesn't have the required 'awardsmanage' permission, display an error |
| 30 | + // If the user doesn't have the required 'awardsmanage' permission, display an error |
24 | 31 | if ( !$wgUser->isAllowed( 'awardsmanage' ) ) { |
25 | 32 | $wgOut->permissionRequired( 'awardsmanage' ); |
26 | 33 | return; |
27 | 34 | } |
28 | 35 | |
29 | | - # Show a message if the database is in read-only mode |
| 36 | + // Show a message if the database is in read-only mode |
30 | 37 | if ( wfReadOnly() ) { |
31 | 38 | $wgOut->readOnlyPage(); |
32 | 39 | return; |
33 | 40 | } |
34 | 41 | |
35 | | - # If user is blocked, s/he doesn't need to access this page |
| 42 | + // If user is blocked, s/he doesn't need to access this page |
36 | 43 | if ( $wgUser->isBlocked() ) { |
37 | 44 | $wgOut->blockedPage(); |
38 | 45 | return; |
— | — | @@ -43,14 +50,18 @@ |
44 | 51 | if ( $wgRequest->wasPosted() ) { |
45 | 52 | $g = new SystemGifts(); |
46 | 53 | |
47 | | - if ( !( $_POST['id'] ) ) { |
| 54 | + if ( !( $_POST['id'] ) ) { // @todo FIXME/CHECKME: why $_POST? Why not $wgRequest? |
| 55 | + // Add the new system gift to the database |
48 | 56 | $gift_id = $g->addGift( |
49 | 57 | $wgRequest->getVal( 'gift_name' ), |
50 | 58 | $wgRequest->getVal( 'gift_description' ), |
51 | 59 | $wgRequest->getVal( 'gift_category' ), |
52 | 60 | $wgRequest->getVal( 'gift_threshold' ) |
53 | 61 | ); |
54 | | - $wgOut->addHTML( '<span class="view-status">' . wfMsg( 'ga-created' ) . '</span><br /><br />' ); |
| 62 | + $wgOut->addHTML( |
| 63 | + '<span class="view-status">' . wfMsg( 'ga-created' ) . |
| 64 | + '</span><br /><br />' |
| 65 | + ); |
55 | 66 | } else { |
56 | 67 | $gift_id = $wgRequest->getVal( 'id' ); |
57 | 68 | $g->updateGift( |
— | — | @@ -60,7 +71,10 @@ |
61 | 72 | $wgRequest->getVal( 'gift_category' ), |
62 | 73 | $wgRequest->getVal( 'gift_threshold' ) |
63 | 74 | ); |
64 | | - $wgOut->addHTML( '<span class="view-status">' . wfMsg( 'ga-saved' ) . '</span><br /><br />' ); |
| 75 | + $wgOut->addHTML( |
| 76 | + '<span class="view-status">' . wfMsg( 'ga-saved' ) . |
| 77 | + '</span><br /><br />' |
| 78 | + ); |
65 | 79 | } |
66 | 80 | $g->update_system_gifts(); |
67 | 81 | $wgOut->addHTML( $this->displayForm( $gift_id ) ); |
— | — | @@ -69,7 +83,11 @@ |
70 | 84 | if ( $gift_id || $wgRequest->getVal( 'method' ) == 'edit' ) { |
71 | 85 | $wgOut->addHTML( $this->displayForm( $gift_id ) ); |
72 | 86 | } else { |
73 | | - $wgOut->addHTML( '<div><b><a href="' . $wgScriptPath . '/index.php?title=Special:SystemGiftManager&method=edit">' . wfMsg( 'ga-addnew' ) . '</a></b></div>' ); |
| 87 | + $wgOut->addHTML( |
| 88 | + '<div><b><a href="' . $wgScriptPath . |
| 89 | + '/index.php?title=Special:SystemGiftManager&method=edit">' . |
| 90 | + wfMsg( 'ga-addnew' ) . '</a></b></div>' |
| 91 | + ); |
74 | 92 | $wgOut->addHTML( $this->displayGiftList() ); |
75 | 93 | } |
76 | 94 | } |
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGift.php |
— | — | @@ -1,9 +1,15 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * A special page to view an individual system gift (award). |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
3 | 9 | |
4 | 10 | class ViewSystemGift extends UnlistedSpecialPage { |
5 | 11 | |
6 | 12 | /** |
7 | | - * Constructor |
| 13 | + * Constructor -- set up the new special page |
8 | 14 | */ |
9 | 15 | public function __construct() { |
10 | 16 | parent::__construct( 'ViewSystemGift' ); |
— | — | @@ -22,6 +28,8 @@ |
23 | 29 | $output = ''; // Prevent E_NOTICE |
24 | 30 | $user_name = ''; // Prevent E_NOTICE |
25 | 31 | |
| 32 | + // If gift ID wasn't passed in the URL parameters or if it's not |
| 33 | + // numeric, display an error message |
26 | 34 | $gift_id = $wgRequest->getVal( 'gift_id' ); |
27 | 35 | if ( !$gift_id || !is_numeric( $gift_id ) ) { |
28 | 36 | $wgOut->setPageTitle( wfMsg( 'ga-error-title' ) ); |
— | — | @@ -29,14 +37,14 @@ |
30 | 38 | return false; |
31 | 39 | } |
32 | 40 | |
| 41 | + // We assume the current user by default |
33 | 42 | if ( !$user_name ) { |
34 | 43 | $user_name = $wgUser->getName(); |
35 | 44 | } |
| 45 | + |
36 | 46 | $gift = UserSystemGifts::getUserGift( $gift_id ); |
37 | 47 | $id = User::idFromName( $user_name ); |
38 | 48 | |
39 | | - $user_safe = urlencode( $gift['user_name'] ); |
40 | | - |
41 | 49 | if ( $gift ) { |
42 | 50 | if ( $gift['status'] == 1 ) { |
43 | 51 | if ( $gift['user_name'] == $wgUser->getName() ) { |
— | — | @@ -68,14 +76,17 @@ |
69 | 77 | |
70 | 78 | $output .= $wgOut->setPageTitle( wfMsg( 'ga-gift-title', $gift['user_name'], $gift['name'] ) ); |
71 | 79 | |
| 80 | + $profileURL = Title::makeTitle( NS_USER, $gift['user_name'] )->escapeFullURL(); |
72 | 81 | $output .= '<div class="back-links">' |
73 | | - . wfMsg( 'ga-back-link', Title::makeTitle( NS_USER, $gift['user_name'] )->escapeFullURL(), $gift['user_name'] ) . |
| 82 | + . wfMsg( 'ga-back-link', $profileURL, $gift['user_name'] ) . |
74 | 83 | '</div>'; |
75 | 84 | |
76 | 85 | $message = $wgOut->parse( trim( $gift['description'] ), false ); |
77 | 86 | $output .= '<div class="ga-description-container">'; |
78 | 87 | |
79 | | - $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage( $gift['gift_id'], 'l' ) . '" border="0" alt=""/>'; |
| 88 | + $gift_image = "<img src=\"{$wgUploadPath}/awards/" . |
| 89 | + SystemGifts::getGiftImage( $gift['gift_id'], 'l' ) . |
| 90 | + '" border="0" alt=""/>'; |
80 | 91 | |
81 | 92 | $output .= "<div class=\"ga-description\"> |
82 | 93 | {$gift_image} |
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialSystemGiftManagerLogo.php |
— | — | @@ -1,4 +1,12 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * A special page to upload images for system gifts (awards). |
| 5 | + * This is mostly copied from an old version of Special:Upload and changed a |
| 6 | + * bit. |
| 7 | + * |
| 8 | + * @file |
| 9 | + * @ingroup Extensions |
| 10 | + */ |
3 | 11 | |
4 | 12 | class SystemGiftManagerLogo extends UnlistedSpecialPage { |
5 | 13 | |
— | — | @@ -11,7 +19,7 @@ |
12 | 20 | var $gift_id; |
13 | 21 | |
14 | 22 | /** |
15 | | - * Constructor |
| 23 | + * Constructor -- set up the new special page |
16 | 24 | */ |
17 | 25 | public function __construct() { |
18 | 26 | parent::__construct( 'SystemGiftManagerLogo' ); |
— | — | @@ -25,19 +33,19 @@ |
26 | 34 | public function execute( $par ) { |
27 | 35 | global $wgRequest, $wgOut, $wgUser; |
28 | 36 | |
29 | | - # If the user doesn't have the required 'awardsmanage' permission, display an error |
| 37 | + // If the user doesn't have the required 'awardsmanage' permission, display an error |
30 | 38 | if ( !$wgUser->isAllowed( 'awardsmanage' ) ) { |
31 | 39 | $wgOut->permissionRequired( 'awardsmanage' ); |
32 | 40 | return; |
33 | 41 | } |
34 | 42 | |
35 | | - # Show a message if the database is in read-only mode |
| 43 | + // Show a message if the database is in read-only mode |
36 | 44 | if ( wfReadOnly() ) { |
37 | 45 | $wgOut->readOnlyPage(); |
38 | 46 | return; |
39 | 47 | } |
40 | 48 | |
41 | | - # If user is blocked, s/he doesn't need to access this page |
| 49 | + // If user is blocked, s/he doesn't need to access this page |
42 | 50 | if ( $wgUser->isBlocked() ) { |
43 | 51 | $wgOut->blockedPage(); |
44 | 52 | return; |
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialPopulateAwards.php |
— | — | @@ -1,9 +1,16 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Special:PopulateAwards -- basically just a special page that calls |
| 5 | + * SystemGifts' update_system_gifts() function and does nothing else |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
3 | 10 | |
4 | 11 | class PopulateAwards extends UnlistedSpecialPage { |
5 | 12 | |
6 | 13 | /** |
7 | | - * Constructor |
| 14 | + * Constructor -- set up the new special page |
8 | 15 | */ |
9 | 16 | public function __construct() { |
10 | 17 | parent::__construct( 'PopulateAwards'/*class*/, 'awardsmanage' /*restriction*/ ); |
— | — | @@ -17,19 +24,19 @@ |
18 | 25 | public function execute( $gift_category ) { |
19 | 26 | global $wgUser, $wgOut, $wgUserLevels; |
20 | 27 | |
21 | | - # If the user doesn't have the required 'awardsmanage' permission, display an error |
| 28 | + // If the user doesn't have the required 'awardsmanage' permission, display an error |
22 | 29 | if ( !$wgUser->isAllowed( 'awardsmanage' ) ) { |
23 | 30 | $wgOut->permissionRequired( 'awardsmanage' ); |
24 | 31 | return; |
25 | 32 | } |
26 | 33 | |
27 | | - # Show a message if the database is in read-only mode |
| 34 | + // Show a message if the database is in read-only mode |
28 | 35 | if ( wfReadOnly() ) { |
29 | 36 | $wgOut->readOnlyPage(); |
30 | 37 | return; |
31 | 38 | } |
32 | 39 | |
33 | | - # If user is blocked, s/he doesn't need to access this page |
| 40 | + // If user is blocked, s/he doesn't need to access this page |
34 | 41 | if ( $wgUser->isBlocked() ) { |
35 | 42 | $wgOut->blockedPage(); |
36 | 43 | return; |
Index: trunk/extensions/SocialProfile/SystemGifts/SpecialViewSystemGifts.php |
— | — | @@ -1,9 +1,15 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * A special page to view the list of system gifts (awards) a user has. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
3 | 9 | |
4 | 10 | class ViewSystemGifts extends SpecialPage { |
5 | 11 | |
6 | 12 | /** |
7 | | - * Constructor |
| 13 | + * Constructor -- set up the new special page |
8 | 14 | */ |
9 | 15 | public function __construct() { |
10 | 16 | parent::__construct( 'ViewSystemGifts' ); |
— | — | @@ -91,21 +97,26 @@ |
92 | 98 | if ( $gifts ) { |
93 | 99 | $x = 1; |
94 | 100 | foreach ( $gifts as $gift ) { |
95 | | - $gift_image = "<img src=\"{$wgUploadPath}/awards/" . SystemGifts::getGiftImage( $gift['gift_id'], 'ml' ) . "\" border=\"0\" alt=\"\" />"; |
| 101 | + $gift_image = "<img src=\"{$wgUploadPath}/awards/" . |
| 102 | + SystemGifts::getGiftImage( $gift['gift_id'], 'ml' ) . |
| 103 | + '" border="0" alt="" />'; |
96 | 104 | |
97 | 105 | $output .= "<div class=\"ga-item\"> |
98 | 106 | {$gift_image} |
99 | | - <a href=\"" . $view_system_gift_link->escapeFullURL( 'gift_id=' . $gift['id'] ) . "\">{$gift["gift_name"]}</a>"; |
| 107 | + <a href=\"" . |
| 108 | + $view_system_gift_link->escapeFullURL( 'gift_id=' . $gift['id'] ) . |
| 109 | + "\">{$gift['gift_name']}</a>"; |
100 | 110 | |
101 | | - if ( $gift['status'] == 1 ) { |
102 | | - if ( $user_name == $wgUser->getName() ) { |
103 | | - $rel->clearUserGiftStatus( $gift['id'] ); |
104 | | - $rel->decNewSystemGiftCount( $wgUser->getID() ); |
105 | | - } |
106 | | - $output .= '<span class="ga-new">' . wfMsg( 'ga-new' ) . '</span>'; |
| 111 | + if ( $gift['status'] == 1 ) { |
| 112 | + if ( $user_name == $wgUser->getName() ) { |
| 113 | + $rel->clearUserGiftStatus( $gift['id'] ); |
| 114 | + $rel->decNewSystemGiftCount( $wgUser->getID() ); |
107 | 115 | } |
| 116 | + $output .= '<span class="ga-new">' . |
| 117 | + wfMsg( 'ga-new' ) . '</span>'; |
| 118 | + } |
108 | 119 | |
109 | | - $output .= '<div class="cleared"></div> |
| 120 | + $output .= '<div class="cleared"></div> |
110 | 121 | </div>'; |
111 | 122 | if ( $x == count( $gifts ) || $x != 1 && $x % $per_row == 0 ) { |
112 | 123 | $output .= '<div class="cleared"></div>'; |
— | — | @@ -125,7 +136,10 @@ |
126 | 137 | if ( $numofpages > 1 ) { |
127 | 138 | $output .= '<div class="page-nav">'; |
128 | 139 | if ( $page > 1 ) { |
129 | | - $output .= '<a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page - 1 ) ) . '">' . wfMsg( 'ga-previous' ) . '</a> '; |
| 140 | + $output .= '<a href="' . $page_link->escapeFullURL( |
| 141 | + 'user=' . $user_name . '&rel_type=' . $rel_type . |
| 142 | + '&page=' . ( $page - 1 ) ) . '">' . |
| 143 | + wfMsg( 'ga-previous' ) . '</a> '; |
130 | 144 | } |
131 | 145 | |
132 | 146 | if ( ( $total % $per_page ) != 0 ) { |
— | — | @@ -142,12 +156,17 @@ |
143 | 157 | if ( $i == $page ) { |
144 | 158 | $output .= ( $i . ' ' ); |
145 | 159 | } else { |
146 | | - $output .= '<a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . $i ) . "\">$i</a> "; |
| 160 | + $output .= '<a href="' . $page_link->escapeFullURL( |
| 161 | + 'user=' . $user_name . '&rel_type=' . $rel_type . |
| 162 | + '&page=' . $i ) . "\">$i</a> "; |
147 | 163 | } |
148 | 164 | } |
149 | 165 | |
150 | 166 | if ( ( $total - ( $per_page * $page ) ) > 0 ) { |
151 | | - $output .= ' <a href="' . $page_link->escapeFullURL( 'user=' . $user_name . '&rel_type=' . $rel_type . '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ga-next' ) . '</a>'; |
| 167 | + $output .= ' <a href="' . $page_link->escapeFullURL( |
| 168 | + 'user=' . $user_name . '&rel_type=' . $rel_type . |
| 169 | + '&page=' . ( $page + 1 ) ) . '">' . wfMsg( 'ga-next' ) . |
| 170 | + '</a>'; |
152 | 171 | } |
153 | 172 | $output .= '</div>'; |
154 | 173 | } |
Index: trunk/extensions/SocialProfile/SystemGifts/TopAwards.php |
— | — | @@ -1,9 +1,16 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Special:TopAwards -- a special page to show the awards with the most |
| 5 | + * recipients (I think) |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + */ |
3 | 10 | |
4 | 11 | class TopAwards extends UnlistedSpecialPage { |
5 | 12 | |
6 | 13 | /** |
7 | | - * Constructor |
| 14 | + * Constructor -- set up the new special page |
8 | 15 | */ |
9 | 16 | public function __construct() { |
10 | 17 | parent::__construct( 'TopAwards' ); |
— | — | @@ -32,7 +39,7 @@ |
33 | 40 | ); |
34 | 41 | |
35 | 42 | // Set title |
36 | | - if ( !( $category_number ) or $category_number > 4 ) { |
| 43 | + if ( !( $category_number ) || $category_number > 4 ) { |
37 | 44 | $category_number = 0; |
38 | 45 | $page_category = $categories[$category_number]['category_name']; |
39 | 46 | } else { |
— | — | @@ -43,8 +50,11 @@ |
44 | 51 | $dbr = wfGetDB( DB_SLAVE ); |
45 | 52 | $res = $dbr->select( |
46 | 53 | array( 'user_system_gift', 'system_gift' ), |
47 | | - array( 'sg_user_name', 'sg_user_id', 'gift_category', 'MAX(gift_threshold) AS top_gift' ), |
48 | 54 | array( |
| 55 | + 'sg_user_name', 'sg_user_id', 'gift_category', |
| 56 | + 'MAX(gift_threshold) AS top_gift' |
| 57 | + ), |
| 58 | + array( |
49 | 59 | "gift_category = {$categories[$category_number]['category_id']}", |
50 | 60 | "gift_threshold > {$categories[$category_number]['category_threshold']}" |
51 | 61 | ), |
— | — | @@ -62,17 +72,16 @@ |
63 | 73 | $output = '<div class="top-awards-navigation"> |
64 | 74 | <h1>Award Categories</h1>'; |
65 | 75 | |
66 | | - $nav_x = 0; |
| 76 | + $nav_x = 0; |
67 | 77 | |
68 | | - foreach ( $categories as $award_type ) { |
69 | | - |
70 | | - if ( $nav_x == $category_number ) { |
71 | | - $output .= "<p><b>{$award_type['category_name']}s</b></p>"; |
72 | | - } else { |
73 | | - $output .= "<p><a href=\"" . $wgScriptPath . "/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type['category_name']}s</a></p>"; |
74 | | - } |
75 | | - $nav_x++; |
| 78 | + foreach ( $categories as $award_type ) { |
| 79 | + if ( $nav_x == $category_number ) { |
| 80 | + $output .= "<p><b>{$award_type['category_name']}s</b></p>"; |
| 81 | + } else { |
| 82 | + $output .= "<p><a href=\"" . $wgScriptPath . "/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type['category_name']}s</a></p>"; |
76 | 83 | } |
| 84 | + $nav_x++; |
| 85 | + } |
77 | 86 | |
78 | 87 | $output .= '</div>'; |
79 | 88 | $output .= '<div class="top-awards">'; |
— | — | @@ -82,7 +91,9 @@ |
83 | 92 | $user_id = $row->sg_user_id; |
84 | 93 | $avatar = new wAvatar( $user_id, 'm' ); |
85 | 94 | $top_gift = $row->top_gift; |
86 | | - $gift_name = number_format( $top_gift ) . " {$categories[$category_number][category_name]}" . ( ( $top_gift > 1 ) ? 's' : '' ) . " Milestone"; |
| 95 | + $gift_name = number_format( $top_gift ) . |
| 96 | + " {$categories[$category_number][category_name]}" . |
| 97 | + ( ( $top_gift > 1 ) ? 's' : '' ) . " Milestone"; |
87 | 98 | |
88 | 99 | if ( $gift_name !== $gift_name_check ) { |
89 | 100 | $x = 1; |
— | — | @@ -93,10 +104,14 @@ |
94 | 105 | $x++; |
95 | 106 | } |
96 | 107 | |
| 108 | + $userLink = $wgUser->getSkin()->link( |
| 109 | + Title::makeTitle( NS_USER, $row->sg_user_name ), |
| 110 | + $user_name |
| 111 | + ); |
97 | 112 | $output .= "<div class=\"top-award\"> |
98 | 113 | <span class=\"top-award-number\">{$x}.</span> |
99 | 114 | {$avatar->getAvatarURL()} |
100 | | - <a href=\"" . $wgScriptPath . "/index.php?title=User:{$row->sg_user_name}\">{$user_name}</a> |
| 115 | + {$userLink} |
101 | 116 | </div>"; |
102 | 117 | |
103 | 118 | $gift_name_check = $gift_name; |
Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php |
— | — | @@ -65,6 +65,15 @@ |
66 | 66 | return $sg_gift_id; |
67 | 67 | } |
68 | 68 | |
| 69 | + /** |
| 70 | + * Sends notification e-mail to the user with the ID $user_id_to whenever |
| 71 | + * they get a new system gift (award) if their e-mail address is confirmed |
| 72 | + * and they have opted in to these notifications on their social |
| 73 | + * preferences. |
| 74 | + * |
| 75 | + * @param $user_id_to Integer: user ID of the recipient |
| 76 | + * @param $gift_id Integer: system gift ID number |
| 77 | + */ |
69 | 78 | public function sendGiftNotificationEmail( $user_id_to, $gift_id ) { |
70 | 79 | $gift = SystemGifts::getGift( $gift_id ); |
71 | 80 | $user = User::newFromId( $user_id_to ); |
— | — | @@ -75,8 +84,13 @@ |
76 | 85 | $subject = wfMsgExt( 'system_gift_received_subject', 'parsemag', |
77 | 86 | $gift['gift_name'] |
78 | 87 | ); |
| 88 | + if ( trim( $user->getRealName() ) ) { |
| 89 | + $name = $user->getRealName(); |
| 90 | + } else { |
| 91 | + $name = $user->getName(); |
| 92 | + } |
79 | 93 | $body = wfMsgExt( 'system_gift_received_body', 'parsemag', |
80 | | - ( ( trim( $user->getRealName() ) ) ? $user->getRealName() : $user->getName() ), |
| 94 | + $name, |
81 | 95 | $gift['gift_name'], |
82 | 96 | $gift['gift_description'], |
83 | 97 | $gifts_link->getFullURL(), |
— | — | @@ -87,6 +101,14 @@ |
88 | 102 | } |
89 | 103 | } |
90 | 104 | |
| 105 | + /** |
| 106 | + * Checks if the user with the ID $user_id has the system gift with the ID |
| 107 | + * $gift_id by querying the user_system_gift table. |
| 108 | + * |
| 109 | + * @param $user_id Integer: user ID |
| 110 | + * @param $gift_id Integer: system gift ID |
| 111 | + * @return Boolean: true if the user has the gift, otherwise false |
| 112 | + */ |
91 | 113 | public function doesUserHaveGift( $user_id, $gift_id ) { |
92 | 114 | $dbr = wfGetDB( DB_SLAVE ); |
93 | 115 | $s = $dbr->selectRow( |
— | — | @@ -305,14 +327,21 @@ |
306 | 328 | return $new_gift_count; |
307 | 329 | } |
308 | 330 | |
| 331 | + /** |
| 332 | + * Get the list of this user's system gifts. |
| 333 | + * |
| 334 | + * @param $type Unused |
| 335 | + * @param $limit Integer: LIMIT for the SQL query |
| 336 | + * @param $page Integer: if greater than 0, used to build the OFFSET for |
| 337 | + * the SQL query |
| 338 | + * @return Array: array of system gift information |
| 339 | + */ |
309 | 340 | public function getUserGiftList( $type, $limit = 0, $page = 0 ) { |
310 | 341 | $dbr = wfGetDB( DB_SLAVE ); |
311 | 342 | |
312 | 343 | $limitvalue = 0; |
313 | | - if ( $limit > 0 ) { |
314 | | - if ( $page ) { |
315 | | - $limitvalue = $page * $limit - ( $limit ); |
316 | | - } |
| 344 | + if ( $limit > 0 && $page ) { |
| 345 | + $limitvalue = $page * $limit - ( $limit ); |
317 | 346 | } |
318 | 347 | |
319 | 348 | $res = $dbr->select( |
Index: trunk/extensions/SocialProfile/SystemGifts/SystemGiftsClass.php |
— | — | @@ -30,11 +30,11 @@ |
31 | 31 | * @private |
32 | 32 | */ |
33 | 33 | /* private */ function __construct() { |
34 | | - |
35 | 34 | } |
36 | 35 | |
37 | 36 | /** |
38 | | - * Adds awards for all registered users |
| 37 | + * Adds awards for all registered users, updates statistics and purges |
| 38 | + * caches. |
39 | 39 | * Special:PopulateAwards calls this function |
40 | 40 | */ |
41 | 41 | public function update_system_gifts() { |
— | — | @@ -92,6 +92,15 @@ |
93 | 93 | $wgOut->addHTML( "{$x} awards were given out" ); |
94 | 94 | } |
95 | 95 | |
| 96 | + /** |
| 97 | + * Checks if the given user has then given award (system gift) via their ID |
| 98 | + * numbers. |
| 99 | + * |
| 100 | + * @param $user_id Integer: user ID number |
| 101 | + * @param $gift_id Integer: award (system gift) ID number |
| 102 | + * @return Boolean|Integer: false if the user doesn't have the specified |
| 103 | + * gift, else the gift's ID number |
| 104 | + */ |
96 | 105 | public function doesUserHaveGift( $user_id, $gift_id ) { |
97 | 106 | $dbr = wfGetDB( DB_SLAVE ); |
98 | 107 | $s = $dbr->selectRow( |
— | — | @@ -108,11 +117,13 @@ |
109 | 118 | } |
110 | 119 | |
111 | 120 | /** |
112 | | - * Adds a new system gift to the database |
| 121 | + * Adds a new system gift to the database. |
| 122 | + * |
113 | 123 | * @param $name Mixed: gift name |
114 | 124 | * @param $description Mixed: gift description |
115 | | - * @param $category |
116 | | - * @param $threshold |
| 125 | + * @param $category Integer: see the $categories class member variable |
| 126 | + * @param $threshold Integer: threshold number (i.e. 50 or 100 or whatever) |
| 127 | + * @return Integer: the inserted gift's ID number |
117 | 128 | */ |
118 | 129 | public function addGift( $name, $description, $category, $threshold ) { |
119 | 130 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -131,7 +142,8 @@ |
132 | 143 | } |
133 | 144 | |
134 | 145 | /** |
135 | | - * Updates data for a system gift |
| 146 | + * Updates the data for a system gift. |
| 147 | + * |
136 | 148 | * @param $id Integer: system gift unique ID number |
137 | 149 | * @param $name Mixed: gift name |
138 | 150 | * @param $description Mixed: gift description |
— | — | @@ -179,6 +191,8 @@ |
180 | 192 | /** |
181 | 193 | * Fetches the system gift with the ID $id from the database |
182 | 194 | * @param $id Integer: ID number of the system gift to be fetched |
| 195 | + * @return Array: array of gift information, including, but not limited to, |
| 196 | + * the gift ID, its name, description, category, threshold |
183 | 197 | */ |
184 | 198 | static function getGift( $id ) { |
185 | 199 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -204,7 +218,8 @@ |
205 | 219 | } |
206 | 220 | |
207 | 221 | /** |
208 | | - * Gets the associated image for a system gift |
| 222 | + * Gets the associated image for a system gift. |
| 223 | + * |
209 | 224 | * @param $id Integer: system gift ID number |
210 | 225 | * @param $size String: image size (s, m, ml or l) |
211 | 226 | * @return String: gift image filename (following the format |
— | — | @@ -267,12 +282,14 @@ |
268 | 283 | 'gift_given_count' => $row->gift_given_count |
269 | 284 | ); |
270 | 285 | } |
| 286 | + |
271 | 287 | return $gifts; |
272 | 288 | } |
273 | 289 | |
274 | 290 | /** |
275 | 291 | * Gets the amount of available system gifts from the database. |
276 | | - * @return integer |
| 292 | + * |
| 293 | + * @return Integer: the amount of all system gifts on the database |
277 | 294 | */ |
278 | 295 | static function getGiftCount() { |
279 | 296 | $dbr = wfGetDB( DB_SLAVE ); |
Index: trunk/extensions/SocialProfile/UserActivity/UserActivityClass.php |
— | — | @@ -28,6 +28,12 @@ |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Constructor |
| 32 | + * |
| 33 | + * @param $username String: username (usually $wgUser's username) |
| 34 | + * @param $filter String: passed to setFilter(); can be either 'user', |
| 35 | + * 'friends', 'foes' or 'all', depending on what |
| 36 | + * kind of information is wanted |
| 37 | + * @param $item_max Integer: maximum amount of items to display in the feed |
32 | 38 | */ |
33 | 39 | public function __construct( $username, $filter, $item_max ) { |
34 | 40 | if ( $username ) { |
— | — | @@ -64,6 +70,10 @@ |
65 | 71 | $this->$name = $value; |
66 | 72 | } |
67 | 73 | |
| 74 | + /** |
| 75 | + * Get recent edits from the recentchanges table and set them in the |
| 76 | + * appropriate class member variables. |
| 77 | + */ |
68 | 78 | private function setEdits() { |
69 | 79 | $dbr = wfGetDB( DB_SLAVE ); |
70 | 80 | |
— | — | @@ -147,6 +157,10 @@ |
148 | 158 | } |
149 | 159 | } |
150 | 160 | |
| 161 | + /** |
| 162 | + * Get recent votes from the Vote table (provided by VoteNY extension) and |
| 163 | + * set them in the appropriate class member variables. |
| 164 | + */ |
151 | 165 | private function setVotes() { |
152 | 166 | $dbr = wfGetDB( DB_SLAVE ); |
153 | 167 | |
— | — | @@ -212,6 +226,10 @@ |
213 | 227 | } |
214 | 228 | } |
215 | 229 | |
| 230 | + /** |
| 231 | + * Get recent comments from the Comments table (provided by the Comments |
| 232 | + * extension) and set them in the appropriate class member variables. |
| 233 | + */ |
216 | 234 | private function setComments() { |
217 | 235 | $dbr = wfGetDB( DB_SLAVE ); |
218 | 236 | |
— | — | @@ -306,6 +324,10 @@ |
307 | 325 | } |
308 | 326 | } |
309 | 327 | |
| 328 | + /** |
| 329 | + * Get recently sent user-to-user gifts from the user_gift and gift tables |
| 330 | + * and set them in the appropriate class member variables. |
| 331 | + */ |
310 | 332 | private function setGiftsSent() { |
311 | 333 | $dbr = wfGetDB( DB_SLAVE ); |
312 | 334 | |
— | — | @@ -366,6 +388,10 @@ |
367 | 389 | } |
368 | 390 | } |
369 | 391 | |
| 392 | + /** |
| 393 | + * Get recently received user-to-user gifts from the user_gift and gift |
| 394 | + * tables and set them in the appropriate class member variables. |
| 395 | + */ |
370 | 396 | private function setGiftsRec() { |
371 | 397 | $dbr = wfGetDB( DB_SLAVE ); |
372 | 398 | |
— | — | @@ -452,6 +478,11 @@ |
453 | 479 | } |
454 | 480 | } |
455 | 481 | |
| 482 | + /** |
| 483 | + * Get recently received system gifts (awards) from the user_system_gift |
| 484 | + * and system_gift tables and set them in the appropriate class member |
| 485 | + * variables. |
| 486 | + */ |
456 | 487 | private function setSystemGiftsRec() { |
457 | 488 | $dbr = wfGetDB( DB_SLAVE ); |
458 | 489 | |
— | — | @@ -532,6 +563,10 @@ |
533 | 564 | } |
534 | 565 | } |
535 | 566 | |
| 567 | + /** |
| 568 | + * Get recent changes in user relationships from the user_relationship |
| 569 | + * table and set them in the appropriate class member variables. |
| 570 | + */ |
536 | 571 | private function setRelationships() { |
537 | 572 | $dbr = wfGetDB( DB_SLAVE ); |
538 | 573 | |
— | — | @@ -618,6 +653,10 @@ |
619 | 654 | } |
620 | 655 | } |
621 | 656 | |
| 657 | + /** |
| 658 | + * Get recently sent public user board messages from the user_board table |
| 659 | + * and set them in the appropriate class member variables. |
| 660 | + */ |
622 | 661 | private function setMessagesSent() { |
623 | 662 | $dbr = wfGetDB( DB_SLAVE ); |
624 | 663 | |
— | — | @@ -703,6 +742,11 @@ |
704 | 743 | } |
705 | 744 | } |
706 | 745 | |
| 746 | + /** |
| 747 | + * Get recent system messages (i.e. "User Foo advanced to level Bar") from |
| 748 | + * the user_system_messages table and set them in the appropriate class |
| 749 | + * member variables. |
| 750 | + */ |
707 | 751 | private function setSystemMessages() { |
708 | 752 | $dbr = wfGetDB( DB_SLAVE ); |
709 | 753 | |
— | — | @@ -880,6 +924,10 @@ |
881 | 925 | return $this->activityLines; |
882 | 926 | } |
883 | 927 | |
| 928 | + /** |
| 929 | + * @param $type String: activity type, such as 'friend' or 'foe' or 'edit' |
| 930 | + * @param $has_page Boolean: true by default |
| 931 | + */ |
884 | 932 | function simplifyPageActivity( $type, $has_page = true ) { |
885 | 933 | if ( !isset( $this->items_grouped[$type] ) || !is_array( $this->items_grouped[$type] ) ) { |
886 | 934 | return ''; |
— | — | @@ -1000,6 +1048,13 @@ |
1001 | 1049 | } |
1002 | 1050 | } |
1003 | 1051 | |
| 1052 | + /** |
| 1053 | + * Get the correct icon for the given activity type. |
| 1054 | + * |
| 1055 | + * @param $type String: activity type, such as 'edit' or 'friend' (etc.) |
| 1056 | + * @return String: image file name (images are located in SocialProfile's |
| 1057 | + * images/ directory) |
| 1058 | + */ |
1004 | 1059 | static function getTypeIcon( $type ) { |
1005 | 1060 | switch( $type ) { |
1006 | 1061 | case 'edit': |
— | — | @@ -1025,6 +1080,15 @@ |
1026 | 1081 | } |
1027 | 1082 | } |
1028 | 1083 | |
| 1084 | + /** |
| 1085 | + * "Fixes" a comment (such as a recent changes edit summary) by converting |
| 1086 | + * certain characters (such as the ampersand) into their encoded |
| 1087 | + * equivalents and, if necessary, truncates the comment and finally applies |
| 1088 | + * stripslashes() to the comment. |
| 1089 | + * |
| 1090 | + * @param $comment String: comment to "fix" |
| 1091 | + * @return String: "fixed" comment |
| 1092 | + */ |
1029 | 1093 | function fixItemComment( $comment ) { |
1030 | 1094 | if ( !$comment ) { |
1031 | 1095 | return ''; |
— | — | @@ -1041,11 +1105,20 @@ |
1042 | 1106 | return stripslashes( $preview ); |
1043 | 1107 | } |
1044 | 1108 | |
| 1109 | + /** |
| 1110 | + * Compares the timestamps of two given objects to decide how to sort them. |
| 1111 | + * Called by getActivityList() and getActivityListGrouped(). |
| 1112 | + * |
| 1113 | + * @param $x Object |
| 1114 | + * @param $y Object |
| 1115 | + * @return Integer: 0 if the timestamps are the same, -1 if $x's timestamp |
| 1116 | + * is greater than $y's, else 1 |
| 1117 | + */ |
1045 | 1118 | private static function sortItems( $x, $y ) { |
1046 | 1119 | if( $x['timestamp'] == $y['timestamp'] ) { |
1047 | 1120 | return 0; |
1048 | 1121 | } elseif ( $x['timestamp'] > $y['timestamp'] ) { |
1049 | | - return - 1; |
| 1122 | + return -1; |
1050 | 1123 | } else { |
1051 | 1124 | return 1; |
1052 | 1125 | } |
Index: trunk/extensions/SocialProfile/UserActivity/UserActivity.body.php |
— | — | @@ -1,8 +1,16 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Special:UserActivity - a special page for showing recent social activity |
| 5 | + * The class is called "UserHome" because the "UserActivity" class is at |
| 6 | + * UserActivityClass.php. |
| 7 | + * |
| 8 | + * @file |
| 9 | + * @ingroup Extensions |
| 10 | + */ |
3 | 11 | |
4 | 12 | class UserHome extends SpecialPage { |
5 | 13 | /** |
6 | | - * Constructor |
| 14 | + * Constructor -- set up the new special page |
7 | 15 | */ |
8 | 16 | public function __construct() { |
9 | 17 | parent::__construct( 'UserActivity' ); |
— | — | @@ -32,6 +40,7 @@ |
33 | 41 | $item_type = 'all'; |
34 | 42 | } |
35 | 43 | |
| 44 | + // If not otherwise specified, display everything but votes in the feed |
36 | 45 | if ( $item_type == 'edits' || $item_type == 'all' ) { |
37 | 46 | $edits = 1; |
38 | 47 | } |