r92631 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92630‎ | r92631 | r92632 >
Date:12:34, 20 July 2011
Author:ashley
Status:ok
Tags:
Comment:
SocialProfile: make Special:TopAwards internationally compatible, add documentation and only show the edits and friends links in the right-side sidebar; votes link will be shown in the VoteNY extension is installed, Comments link will be shown if the Comments extension is installed and the recruits link will be shown if you can get points from recruiting users.
Modified paths:
  • /trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php (modified) (history)
  • /trunk/extensions/SocialProfile/SystemGifts/TopAwards.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
@@ -57,6 +57,24 @@
5858 This will also delete it from users who may have received it.',
5959 'ga-remove-success-title' => 'You have successfully removed the gift "$1"',
6060 '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.',
6179 'system_gift_received_subject' => 'You have received the $1 award on {{SITENAME}}!',
6280 'system_gift_received_body' => 'Hi $1.
6381
Index: trunk/extensions/SocialProfile/SystemGifts/TopAwards.php
@@ -22,7 +22,7 @@
2323 * @param $par Mixed: parameter passed to the page or null
2424 */
2525 public function execute( $par ) {
26 - global $wgRequest, $wgOut, $wgUser, $wgUploadPath, $wgScriptPath, $wgSystemGiftsScripts;
 26+ global $wgRequest, $wgOut, $wgUser, $wgSystemGiftsScripts, $wgUserStatsPointValues;
2727
2828 // Variables
2929 $gift_name_check = '';
@@ -30,14 +30,63 @@
3131 $category_number = $wgRequest->getInt( 'category' );
3232
3333 // 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
3447 $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+ )
4058 );
4159
 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+
4291 // Set title
4392 if ( !( $category_number ) || $category_number > 4 ) {
4493 $category_number = 0;
@@ -64,21 +113,34 @@
65114 );
66115
67116 // 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+ );
69123
70124 // Add CSS
71125 $wgOut->addExtensionStyle( $wgSystemGiftsScripts . '/SystemGift.css' );
72126
73127 $output = '<div class="top-awards-navigation">
74 - <h1>Award Categories</h1>';
 128+ <h1>' . wfMsg( 'topawards-award-categories' ) . '</h1>';
75129
76130 $nav_x = 0;
77131
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+ );
79140 if ( $nav_x == $category_number ) {
80 - $output .= "<p><b>{$award_type['category_name']}s</b></p>";
 141+ $output .= "<p><b>{$msg}</b></p>";
81142 } 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>";
83145 }
84146 $nav_x++;
85147 }
@@ -86,35 +148,47 @@
87149 $output .= '</div>';
88150 $output .= '<div class="top-awards">';
89151
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+ );
98171
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\">
102175 {$gift_name}
103176 </div>";
104 - } else {
105 - $x++;
106 - }
 177+ } else {
 178+ $x++;
 179+ }
107180
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\">
113186 <span class=\"top-award-number\">{$x}.</span>
114187 {$avatar->getAvatarURL()}
115188 {$userLink}
116189 </div>";
117190
118 - $gift_name_check = $gift_name;
 191+ $gift_name_check = $gift_name;
 192+ }
119193 }
120194
121195 $output .= '</div>
@@ -122,4 +196,4 @@
123197
124198 $wgOut->addHTML( $output );
125199 }
126 -}
 200+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r94631Follow-up r92631: correct plural.siebrand12:54, 16 August 2011

Status & tagging log