Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php |
— | — | @@ -57,6 +57,24 @@ |
58 | 58 | This will also delete it from users who may have received it.', |
59 | 59 | 'ga-remove-success-title' => 'You have successfully removed the gift "$1"', |
60 | 60 | 'ga-remove-success-message' => 'The gift "$1" has been removed.', |
| 61 | + 'topawards' => 'Top Awards', |
| 62 | + 'topawards-edit-title' => 'Top Awards - Edit Milestones', |
| 63 | + 'topawards-vote-title' => 'Top Awards - Vote Milestones', |
| 64 | + 'topawards-comment-title' => 'Top Awards - Comment Milestones', |
| 65 | + 'topawards-recruit-title' => 'Top Awards - Recruit Milestones', |
| 66 | + 'topawards-friend-title' => 'Top Awards - Friend Milestones', |
| 67 | + 'topawards-award-categories' => 'Award Categories', |
| 68 | + 'topawards-edits' => 'Edits', |
| 69 | + 'topawards-votes' => 'Votes', |
| 70 | + 'topawards-comments' => 'Comments', |
| 71 | + 'topawards-recruits' => 'Recruits', |
| 72 | + 'topawards-friends' => 'Friends', |
| 73 | + 'topawards-edit-milestone' => '{{PLURAL:$1|$1 Edit|$1 Edits}} Milestone', |
| 74 | + 'topawards-vote-milestone' => '{{PLURAL:$1|$1 Vote|$1 Votes}} Milestone', |
| 75 | + 'topawards-comment-milestone' => '{{PLURAL:$1|$1 Comment|$1 Comments}} Milestone', |
| 76 | + 'topawards-recruit-milestone' => '{{PLURAL:$1|$1 Recruit|$1 Recruit}} Milestone', |
| 77 | + 'topawards-friend-milestone' => '{{PLURAL:$1|$1 Friend|$1 Friend}} Milestone', |
| 78 | + 'topawards-empty' => 'Either there are no configured awards for this award category, or then nobody has gotten those awards yet.', |
61 | 79 | 'system_gift_received_subject' => 'You have received the $1 award on {{SITENAME}}!', |
62 | 80 | 'system_gift_received_body' => 'Hi $1. |
63 | 81 | |
Index: trunk/extensions/SocialProfile/SystemGifts/TopAwards.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * @param $par Mixed: parameter passed to the page or null |
24 | 24 | */ |
25 | 25 | public function execute( $par ) { |
26 | | - global $wgRequest, $wgOut, $wgUser, $wgUploadPath, $wgScriptPath, $wgSystemGiftsScripts; |
| 26 | + global $wgRequest, $wgOut, $wgUser, $wgSystemGiftsScripts, $wgUserStatsPointValues; |
27 | 27 | |
28 | 28 | // Variables |
29 | 29 | $gift_name_check = ''; |
— | — | @@ -30,14 +30,63 @@ |
31 | 31 | $category_number = $wgRequest->getInt( 'category' ); |
32 | 32 | |
33 | 33 | // System gift class array |
| 34 | + // The 'category_name' key is used to build the appropriate i18n |
| 35 | + // message keys later on in the code; 'category_id' corresponds to |
| 36 | + // system_gift.gift_category. Valid categories and their numbers are |
| 37 | + // the same that are shown on Special:SystemGiftManager, which are: |
| 38 | + // 1: edit, 2: vote, 3: comment, 4: comment_plus, 5: opinions_created, |
| 39 | + // 6: opinions_pub, 7: referral_complete, 8: friend, 9: foe, |
| 40 | + // 10: challenges_won, 11: gift_rec, 12: points_winner_weekly, |
| 41 | + // 13: points_winner_monthly, 14: quiz_points |
| 42 | + // |
| 43 | + // @todo I really think that this should be configurable, the way the |
| 44 | + // navigation bar (MediaWiki:Topfans-by-category) shown on |
| 45 | + // Special:TopUsers and related special pages is...this is ugly and |
| 46 | + // far from flexible, since the thresholds are all hard-coded in |
34 | 47 | $categories = array( |
35 | | - array( 'category_name' => 'Edit', 'category_threshold' => '500', 'category_id' => 1 ), |
36 | | - array( 'category_name' => 'Vote', 'category_threshold' => '2000', 'category_id' => 2 ), |
37 | | - array( 'category_name' => 'Comment', 'category_threshold' => '1000', 'category_id' => 3 ), |
38 | | - array( 'category_name' => 'Recruit', 'category_threshold' => '0', 'category_id' => 7 ), |
39 | | - array( 'category_name' => 'Friend', 'category_threshold' => '25', 'category_id' => 8 ) |
| 48 | + array( |
| 49 | + 'category_name' => 'Edit', |
| 50 | + 'category_threshold' => '500', |
| 51 | + 'category_id' => 1 |
| 52 | + ), |
| 53 | + array( |
| 54 | + 'category_name' => 'Friend', |
| 55 | + 'category_threshold' => '25', |
| 56 | + 'category_id' => 8 |
| 57 | + ) |
40 | 58 | ); |
41 | 59 | |
| 60 | + // VoteStars is unique to the VoteNY extension, while there are a bunch |
| 61 | + // of other voting extensions where the main class is named "Vote" |
| 62 | + if ( class_exists( 'VoteStars' ) ) { |
| 63 | + $categories[] = array( |
| 64 | + 'category_name' => 'Vote', |
| 65 | + 'category_threshold' => '2000', |
| 66 | + 'category_id' => 2 |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + // Show the "Comments" category only if the Comments extension is |
| 71 | + // installed |
| 72 | + if ( class_exists( 'Comment' ) ) { |
| 73 | + $categories[] = array( |
| 74 | + 'category_name' => 'Comment', |
| 75 | + 'category_threshold' => '1000', |
| 76 | + 'category_id' => 3 |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + // Well, we could test for the existence of the extension which allows |
| 81 | + // for referring users to the wiki so that you get points for it, but |
| 82 | + // this seems like a better thing to check for. |
| 83 | + if ( $wgUserStatsPointValues['referral_complete'] > 0 ) { |
| 84 | + $categories[] = array( |
| 85 | + 'category_name' => 'Recruit', |
| 86 | + 'category_threshold' => '0', |
| 87 | + 'category_id' => 7 |
| 88 | + ); |
| 89 | + } |
| 90 | + |
42 | 91 | // Set title |
43 | 92 | if ( !( $category_number ) || $category_number > 4 ) { |
44 | 93 | $category_number = 0; |
— | — | @@ -64,21 +113,34 @@ |
65 | 114 | ); |
66 | 115 | |
67 | 116 | // Page title |
68 | | - $wgOut->setPageTitle( "Top Awards - {$page_category} Milestones" ); |
| 117 | + // for grep: topawards-edit-title, topawards-vote-title, |
| 118 | + // topawards-comment-title, topawards-recruit-title, |
| 119 | + // topawards-friend-title |
| 120 | + $wgOut->setPageTitle( |
| 121 | + wfMsg( 'topawards-' . strtolower( $page_category ) . '-title' ) |
| 122 | + ); |
69 | 123 | |
70 | 124 | // Add CSS |
71 | 125 | $wgOut->addExtensionStyle( $wgSystemGiftsScripts . '/SystemGift.css' ); |
72 | 126 | |
73 | 127 | $output = '<div class="top-awards-navigation"> |
74 | | - <h1>Award Categories</h1>'; |
| 128 | + <h1>' . wfMsg( 'topawards-award-categories' ) . '</h1>'; |
75 | 129 | |
76 | 130 | $nav_x = 0; |
77 | 131 | |
78 | | - foreach ( $categories as $award_type ) { |
| 132 | + // Build the award categories menu on the right side of the page |
| 133 | + foreach ( $categories as $awardType ) { |
| 134 | + // for grep: topawards-edits, topawards-votes, |
| 135 | + // topawards-comments, topawards-recruits, topawards-friends |
| 136 | + $msg = wfMsg( |
| 137 | + 'topawards-' . |
| 138 | + strtolower( $awardType['category_name'] ) . 's' |
| 139 | + ); |
79 | 140 | if ( $nav_x == $category_number ) { |
80 | | - $output .= "<p><b>{$award_type['category_name']}s</b></p>"; |
| 141 | + $output .= "<p><b>{$msg}</b></p>"; |
81 | 142 | } else { |
82 | | - $output .= "<p><a href=\"" . $wgScriptPath . "/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type['category_name']}s</a></p>"; |
| 143 | + $output .= '<p><a href="' . $this->getTitle()->escapeFullURL( |
| 144 | + "category={$nav_x}" ) . "\">{$msg}</a></p>"; |
83 | 145 | } |
84 | 146 | $nav_x++; |
85 | 147 | } |
— | — | @@ -86,35 +148,47 @@ |
87 | 149 | $output .= '</div>'; |
88 | 150 | $output .= '<div class="top-awards">'; |
89 | 151 | |
90 | | - foreach ( $res as $row ) { |
91 | | - $user_name = $row->sg_user_name; |
92 | | - $user_id = $row->sg_user_id; |
93 | | - $avatar = new wAvatar( $user_id, 'm' ); |
94 | | - $top_gift = $row->top_gift; |
95 | | - $gift_name = number_format( $top_gift ) . |
96 | | - " {$categories[$category_number][category_name]}" . |
97 | | - ( ( $top_gift > 1 ) ? 's' : '' ) . " Milestone"; |
| 152 | + // Display a "no results" message if we got no results -- because it's |
| 153 | + // a lot nicer to display something rather than a half-empty page |
| 154 | + if ( $dbr->numRows( $res ) <= 0 ) { |
| 155 | + $output .= wfMsg( 'topawards-empty' ); |
| 156 | + } else { |
| 157 | + foreach ( $res as $row ) { |
| 158 | + $user_name = $row->sg_user_name; |
| 159 | + $user_id = $row->sg_user_id; |
| 160 | + $avatar = new wAvatar( $user_id, 'm' ); |
| 161 | + $top_gift = $row->top_gift; |
| 162 | + $lower = strtolower( $categories[$category_number]['category_name'] ); |
| 163 | + // for grep: topawards-edit-milestone, topawards-vote-milestone, |
| 164 | + // topawards-comment-milestone, topawards-recruit-milestone, |
| 165 | + // topawards-friend-milestone |
| 166 | + $gift_name = wfMsgExt( |
| 167 | + 'topawards-' . $lower . '-milestone', |
| 168 | + 'parsemag', |
| 169 | + $top_gift |
| 170 | + ); |
98 | 171 | |
99 | | - if ( $gift_name !== $gift_name_check ) { |
100 | | - $x = 1; |
101 | | - $output .= "<div class=\"top-award-title\"> |
| 172 | + if ( $gift_name !== $gift_name_check ) { |
| 173 | + $x = 1; |
| 174 | + $output .= "<div class=\"top-award-title\"> |
102 | 175 | {$gift_name} |
103 | 176 | </div>"; |
104 | | - } else { |
105 | | - $x++; |
106 | | - } |
| 177 | + } else { |
| 178 | + $x++; |
| 179 | + } |
107 | 180 | |
108 | | - $userLink = $wgUser->getSkin()->link( |
109 | | - Title::makeTitle( NS_USER, $row->sg_user_name ), |
110 | | - $user_name |
111 | | - ); |
112 | | - $output .= "<div class=\"top-award\"> |
| 181 | + $userLink = $wgUser->getSkin()->link( |
| 182 | + Title::makeTitle( NS_USER, $row->sg_user_name ), |
| 183 | + $user_name |
| 184 | + ); |
| 185 | + $output .= "<div class=\"top-award\"> |
113 | 186 | <span class=\"top-award-number\">{$x}.</span> |
114 | 187 | {$avatar->getAvatarURL()} |
115 | 188 | {$userLink} |
116 | 189 | </div>"; |
117 | 190 | |
118 | | - $gift_name_check = $gift_name; |
| 191 | + $gift_name_check = $gift_name; |
| 192 | + } |
119 | 193 | } |
120 | 194 | |
121 | 195 | $output .= '</div> |
— | — | @@ -122,4 +196,4 @@ |
123 | 197 | |
124 | 198 | $wgOut->addHTML( $output ); |
125 | 199 | } |
126 | | -} |
| 200 | +} |
\ No newline at end of file |