http://www.mediawiki.org/wiki/Special:Code/MediaWiki/92631

Revision: 92631
Author:   ashley
Date:     2011-07-20 12:34:55 +0000 (Wed, 20 Jul 2011)
Log Message:
-----------
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
    trunk/extensions/SocialProfile/SystemGifts/TopAwards.php

Modified: trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php      
2011-07-20 12:16:24 UTC (rev 92630)
+++ trunk/extensions/SocialProfile/SystemGifts/SystemGift.i18n.php      
2011-07-20 12:34:55 UTC (rev 92631)
@@ -57,6 +57,24 @@
 This will also delete it from users who may have received it.',
        'ga-remove-success-title' => 'You have successfully removed the gift 
"$1"',
        'ga-remove-success-message' => 'The gift "$1" has been removed.',
+       'topawards' => 'Top Awards',
+       'topawards-edit-title' => 'Top Awards - Edit Milestones',
+       'topawards-vote-title' => 'Top Awards - Vote Milestones',
+       'topawards-comment-title' => 'Top Awards - Comment Milestones',
+       'topawards-recruit-title' => 'Top Awards - Recruit Milestones',
+       'topawards-friend-title' => 'Top Awards - Friend Milestones',
+       'topawards-award-categories' => 'Award Categories',
+       'topawards-edits' => 'Edits',
+       'topawards-votes' => 'Votes',
+       'topawards-comments' => 'Comments',
+       'topawards-recruits' => 'Recruits',
+       'topawards-friends' => 'Friends',
+       'topawards-edit-milestone' => '{{PLURAL:$1|$1 Edit|$1 Edits}} 
Milestone',
+       'topawards-vote-milestone' => '{{PLURAL:$1|$1 Vote|$1 Votes}} 
Milestone',
+       'topawards-comment-milestone' => '{{PLURAL:$1|$1 Comment|$1 Comments}} 
Milestone',
+       'topawards-recruit-milestone' => '{{PLURAL:$1|$1 Recruit|$1 Recruit}} 
Milestone',
+       'topawards-friend-milestone' => '{{PLURAL:$1|$1 Friend|$1 Friend}} 
Milestone',
+       'topawards-empty' => 'Either there are no configured awards for this 
award category, or then nobody has gotten those awards yet.',
        'system_gift_received_subject' => 'You have received the $1 award on 
{{SITENAME}}!',
        'system_gift_received_body' => 'Hi $1.
 

Modified: trunk/extensions/SocialProfile/SystemGifts/TopAwards.php
===================================================================
--- trunk/extensions/SocialProfile/SystemGifts/TopAwards.php    2011-07-20 
12:16:24 UTC (rev 92630)
+++ trunk/extensions/SocialProfile/SystemGifts/TopAwards.php    2011-07-20 
12:34:55 UTC (rev 92631)
@@ -22,7 +22,7 @@
         * @param $par Mixed: parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgRequest, $wgOut, $wgUser, $wgUploadPath, 
$wgScriptPath, $wgSystemGiftsScripts;
+               global $wgRequest, $wgOut, $wgUser, $wgSystemGiftsScripts, 
$wgUserStatsPointValues;
 
                // Variables
                $gift_name_check = '';
@@ -30,14 +30,63 @@
                $category_number = $wgRequest->getInt( 'category' );
 
                // System gift class array
+               // The 'category_name' key is used to build the appropriate i18n
+               // message keys later on in the code; 'category_id' corresponds 
to
+               // system_gift.gift_category. Valid categories and their 
numbers are
+               // the same that are shown on Special:SystemGiftManager, which 
are:
+               // 1: edit, 2: vote, 3: comment, 4: comment_plus, 5: 
opinions_created,
+               // 6: opinions_pub, 7: referral_complete, 8: friend, 9: foe,
+               // 10: challenges_won, 11: gift_rec, 12: points_winner_weekly,
+               // 13: points_winner_monthly, 14: quiz_points
+               //
+               // @todo I really think that this should be configurable, the 
way the
+               // navigation bar (MediaWiki:Topfans-by-category) shown on
+               // Special:TopUsers and related special pages is...this is ugly 
and
+               // far from flexible, since the thresholds are all hard-coded in
                $categories = array(
-                       array( 'category_name' => 'Edit', 'category_threshold' 
=> '500', 'category_id' => 1 ),
-                       array( 'category_name' => 'Vote', 'category_threshold' 
=> '2000', 'category_id' => 2 ),
-                       array( 'category_name' => 'Comment', 
'category_threshold' => '1000', 'category_id' => 3 ),
-                       array( 'category_name' => 'Recruit', 
'category_threshold' => '0', 'category_id' => 7 ),
-                       array( 'category_name' => 'Friend', 
'category_threshold' => '25', 'category_id' => 8 )
+                       array(
+                               'category_name' => 'Edit',
+                               'category_threshold' => '500',
+                               'category_id' => 1
+                       ),
+                       array(
+                               'category_name' => 'Friend',
+                               'category_threshold' => '25',
+                               'category_id' => 8
+                       )
                );
 
+               // VoteStars is unique to the VoteNY extension, while there are 
a bunch
+               // of other voting extensions where the main class is named 
"Vote"
+               if ( class_exists( 'VoteStars' ) ) {
+                       $categories[] = array(
+                               'category_name' => 'Vote',
+                               'category_threshold' => '2000',
+                               'category_id' => 2
+                       );
+               }
+
+               // Show the "Comments" category only if the Comments extension 
is
+               // installed
+               if ( class_exists( 'Comment' ) ) {
+                       $categories[] = array(
+                               'category_name' => 'Comment',
+                               'category_threshold' => '1000',
+                               'category_id' => 3
+                       );
+               }
+
+               // Well, we could test for the existence of the extension which 
allows
+               // for referring users to the wiki so that you get points for 
it, but
+               // this seems like a better thing to check for.
+               if ( $wgUserStatsPointValues['referral_complete'] > 0 ) {
+                       $categories[] = array(
+                               'category_name' => 'Recruit',
+                               'category_threshold' => '0',
+                               'category_id' => 7
+                       );
+               }
+
                // Set title
                if ( !( $category_number ) || $category_number > 4 ) {
                        $category_number = 0;
@@ -64,21 +113,34 @@
                );
 
                // Page title
-               $wgOut->setPageTitle( "Top Awards - {$page_category} 
Milestones" );
+               // for grep: topawards-edit-title, topawards-vote-title,
+               // topawards-comment-title, topawards-recruit-title,
+               // topawards-friend-title
+               $wgOut->setPageTitle(
+                       wfMsg( 'topawards-' . strtolower( $page_category ) . 
'-title' )
+               );
 
                // Add CSS
                $wgOut->addExtensionStyle( $wgSystemGiftsScripts . 
'/SystemGift.css' );
 
                $output = '<div class="top-awards-navigation">
-                       <h1>Award Categories</h1>';
+                       <h1>' . wfMsg( 'topawards-award-categories' ) . '</h1>';
 
                $nav_x = 0;
 
-               foreach ( $categories as $award_type ) {
+               // Build the award categories menu on the right side of the page
+               foreach ( $categories as $awardType ) {
+                       // for grep: topawards-edits, topawards-votes,
+                       // topawards-comments, topawards-recruits, 
topawards-friends
+                       $msg = wfMsg(
+                               'topawards-' .
+                               strtolower( $awardType['category_name'] ) . 's'
+                       );
                        if ( $nav_x == $category_number ) {
-                               $output .= 
"<p><b>{$award_type['category_name']}s</b></p>";
+                               $output .= "<p><b>{$msg}</b></p>";
                        } else {
-                               $output .= "<p><a href=\"" . $wgScriptPath . 
"/index.php?title=Special:TopAwards&category={$nav_x}\">{$award_type['category_name']}s</a></p>";
+                               $output .= '<p><a href="' . 
$this->getTitle()->escapeFullURL(
+                                       "category={$nav_x}" ) . 
"\">{$msg}</a></p>";
                        }
                        $nav_x++;
                }
@@ -86,35 +148,47 @@
                $output .= '</div>';
                $output .= '<div class="top-awards">';
 
-               foreach ( $res as $row ) {
-                       $user_name = $row->sg_user_name;
-                       $user_id = $row->sg_user_id;
-                       $avatar = new wAvatar( $user_id, 'm' );
-                       $top_gift = $row->top_gift;
-                       $gift_name = number_format( $top_gift ) .
-                               " 
{$categories[$category_number][category_name]}" .
-                               ( ( $top_gift > 1 ) ? 's' : '' ) . " Milestone";
+               // Display a "no results" message if we got no results -- 
because it's
+               // a lot nicer to display something rather than a half-empty 
page
+               if ( $dbr->numRows( $res ) <= 0 ) {
+                       $output .= wfMsg( 'topawards-empty' );
+               } else {
+                       foreach ( $res as $row ) {
+                               $user_name = $row->sg_user_name;
+                               $user_id = $row->sg_user_id;
+                               $avatar = new wAvatar( $user_id, 'm' );
+                               $top_gift = $row->top_gift;
+                               $lower = strtolower( 
$categories[$category_number]['category_name'] );
+                               // for grep: topawards-edit-milestone, 
topawards-vote-milestone,
+                               // topawards-comment-milestone, 
topawards-recruit-milestone,
+                               // topawards-friend-milestone
+                               $gift_name = wfMsgExt(
+                                       'topawards-' . $lower . '-milestone',
+                                       'parsemag',
+                                       $top_gift
+                               );
 
-                       if ( $gift_name !== $gift_name_check ) {
-                               $x = 1;
-                               $output .= "<div class=\"top-award-title\">
+                               if ( $gift_name !== $gift_name_check ) {
+                                       $x = 1;
+                                       $output .= "<div 
class=\"top-award-title\">
                                        {$gift_name}
                                </div>";
-                       } else {
-                               $x++;
-                       }
+                               } else {
+                                       $x++;
+                               }
 
-                       $userLink = $wgUser->getSkin()->link(
-                               Title::makeTitle( NS_USER, $row->sg_user_name ),
-                               $user_name
-                       );
-                       $output .= "<div class=\"top-award\">
+                               $userLink = $wgUser->getSkin()->link(
+                                       Title::makeTitle( NS_USER, 
$row->sg_user_name ),
+                                       $user_name
+                               );
+                               $output .= "<div class=\"top-award\">
                                        <span 
class=\"top-award-number\">{$x}.</span>
                                        {$avatar->getAvatarURL()}
                                        {$userLink}
                                </div>";
 
-                       $gift_name_check = $gift_name;
+                               $gift_name_check = $gift_name;
+                       }
                }
 
                $output .= '</div>
@@ -122,4 +196,4 @@
 
                $wgOut->addHTML( $output );
        }
-}
+}
\ No newline at end of file


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to