r50595 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50594‎ | r50595 | r50596 >
Date:18:07, 14 May 2009
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: some tweaks for UserStats stuff
Modified paths:
  • /trunk/extensions/SocialProfile/UserStats/TopFansByStat.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/TopFansRecent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStats/TopFansRecent.php
@@ -6,7 +6,7 @@
77 * Constructor
88 */
99 public function __construct(){
10 - parent::__construct('TopUsersRecent');
 10+ parent::__construct( 'TopUsersRecent' );
1111 }
1212
1313 /**
@@ -19,18 +19,18 @@
2020 $wgUserLevels, $wgUploadPath, $wgScriptPath;
2121
2222 // Read in localisation messages
23 - wfLoadExtensionMessages('SocialProfileUserStats');
 23+ wfLoadExtensionMessages( 'SocialProfileUserStats' );
2424
2525 // Load CSS
26 - $wgOut->addStyle( '../..' . $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
 26+ $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
2727 $period = $wgRequest->getVal( 'period' );
2828
2929 if( !$period ) $period = 'weekly';
3030
3131 if( $period == 'weekly' ){
32 - $wgOut->setPagetitle( wfMsg('user-stats-weekly-title') );
 32+ $wgOut->setPageTitle( wfMsg( 'user-stats-weekly-title' ) );
3333 } else {
34 - $wgOut->setPagetitle( wfMsg('user-stats-monthly-title') );
 34+ $wgOut->setPageTitle( wfMsg( 'user-stats-monthly-title' ) );
3535 }
3636
3737 $count = 50;
@@ -51,18 +51,19 @@
5252
5353 $dbr = wfGetDB( DB_SLAVE );
5454 $res = $dbr->select( "user_points_{$period}",
55 - array('up_user_id','up_user_name','up_points'),
56 - array('up_user_id <> 0'), __METHOD__,
 55+ array( 'up_user_id', 'up_user_name', 'up_points' ),
 56+ array( 'up_user_id <> 0' ),
 57+ __METHOD__,
5758 $params
5859 );
59 - while( $row = $dbr->fetchObject($res) ){
 60+ while( $row = $dbr->fetchObject( $res ) ){
6061 $user_list[] = array(
6162 'user_id' => $row->up_user_id,
6263 'user_name' => $row->up_user_name,
6364 'points' => $row->up_points
6465 );
6566 }
66 - $wgMemc->set( $key, $user_list, 60 * 5);
 67+ $wgMemc->set( $key, $user_list, 60 * 5 );
6768 }
6869
6970 // Top nav bar
@@ -70,35 +71,34 @@
7172 $recent_title = Title::makeTitle( NS_SPECIAL, 'TopUsersRecent' );
7273
7374 $out .= '<div class="top-fan-nav">
74 - <h1>' . wfMsg('top-fans-by-points-nav-header') . '</h1>
75 - <p><a href="'.$top_title->escapeFullURL().'">' . wfMsg('top-fans-total-points-link') . '</a></p>';
 75+ <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1>
 76+ <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
7677
7778 if( $period == 'weekly' ) {
78 - $out .= '<p><a href="' . $recent_title->escapeFullURL("period=monthly") . '">' .wfMsg('top-fans-monthly-points-link') . '</a><p>
79 - <p><b>' . wfMsg('top-fans-weekly-points-link') . '</b></p>';
 79+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>
 80+ <p><b>' . wfMsg( 'top-fans-weekly-points-link' ) . '</b></p>';
8081 } else {
81 - $out .= '<p><b>' .wfMsg('top-fans-monthly-points-link') . '</b><p>
82 - <p><a href="' . $recent_title->escapeFullURL("period=weekly") . '">' .wfMsg('top-fans-weekly-points-link') . '</a></p>';
 82+ $out .= '<p><b>' . wfMsg( 'top-fans-monthly-points-link' ) . '</b><p>
 83+ <p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
8384 }
8485
8586 // Build nav of stats by category based on MediaWiki:Topfans-by-category
86 - if( count( $lines ) > 0 ) {
87 - $out .= '<h1 style="margin-top:15px !important;">' . wfMsg('top-fans-by-category-nav-header') . '</h1>';
88 - }
89 -
90 - $by_category_title = Title::makeTitle( NS_SPECIAL, 'TopFansByStatistic' );
 87+ $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' );
9188 $nav = array();
9289
9390 $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) );
 91+ if( count( $lines ) > 0 ) {
 92+ $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
 93+ }
9494 foreach( $lines as $line ) {
9595
96 - if( strpos($line, '*') !== 0 ){
 96+ if( strpos( $line, '*' ) !== 0 ){
9797 continue;
9898 } else {
99 - $line = explode( '|' , trim($line, '* '), 2 );
 99+ $line = explode( '|', trim( $line, '* ' ), 2 );
100100 $stat = $line[0];
101101 $link_text = $line[1];
102 - $out .= '<p><a href="' . $by_category_title->escapeFullURL("stat={$stat}") . '">'.$link_text.'</a></p>';
 102+ $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>';
103103 }
104104 }
105105 $out .= '</div>';
@@ -109,21 +109,21 @@
110110 foreach( $user_list as $user ){
111111 $user_title = Title::makeTitle( NS_USER, $user['user_name'] );
112112 $avatar = new wAvatar( $user['user_id'], 'm' );
113 - $CommentIcon = $avatar->getAvatarImage();
 113+ $commentIcon = $avatar->getAvatarImage();
114114
115115 $out .= '<div class="top-fan-row">
116 - <span class="top-fan-num">'.$x.'.</span>
 116+ <span class="top-fan-num">' . $x . '.</span>
117117 <span class="top-fan">
118 - <img src="'.$wgUploadPath.'/avatars/' . $CommentIcon . '" alt="" border="">
 118+ <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" />
119119 <a href="' . $user_title->escapeFullURL() . '" >' . $user['user_name'] . '</a>
120120 </span>';
121121
122 - $out .= '<span class="top-fan-points"><b>' . number_format( $user['points'] ) . '</b> ' . wfMsg('top-fans-points') . '</span>';
 122+ $out .= '<span class="top-fan-points"><b>' . number_format( $user['points'] ) . '</b> ' . wfMsg( 'top-fans-points' ) . '</span>';
123123 $out .= '<div class="cleared"></div>';
124124 $out .= '</div>';
125125 $x++;
126126 }
127127 $out .= '</div><div class="cleared"></div>';
128 - $wgOut->addHTML($out);
 128+ $wgOut->addHTML( $out );
129129 }
130130 }
\ No newline at end of file
Index: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
@@ -6,7 +6,7 @@
77 * Constructor
88 */
99 public function __construct(){
10 - parent::__construct('TopFansByStatistic');
 10+ parent::__construct( 'TopFansByStatistic' );
1111 }
1212
1313 /**
@@ -16,13 +16,13 @@
1717 */
1818 public function execute( $par ){
1919 global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly,
20 - $wgUserLevels, $wgOut, $wgUploadPath, $wgScriptPath;
 20+ $wgUserLevels, $wgUploadPath, $wgScriptPath;
2121
2222 // Read in localisation messages
23 - wfLoadExtensionMessages('SocialProfileUserStats');
 23+ wfLoadExtensionMessages( 'SocialProfileUserStats' );
2424
2525 // Load CSS
26 - $wgOut->addStyle( '../..' . $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
 26+ $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
2727
2828 $statistic = $wgRequest->getVal( 'stat' );
2929 $column = "stats_{$statistic}";
@@ -32,13 +32,13 @@
3333
3434 // Error if the querystring value does not match our stat column
3535 if( !$dbr->fieldExists( 'user_stats', $column ) ){
36 - $wgOut->setPagetitle( wfMsg('top-fans-bad-field-title') );
37 - $wgOut->addHTML( wfMsg('top-fans-bad-field-message') );
 36+ $wgOut->setPageTitle( wfMsg( 'top-fans-bad-field-title' ) );
 37+ $wgOut->addHTML( wfMsg( 'top-fans-bad-field-message' ) );
3838 return false;
3939 }
4040
4141 // Set page title
42 - $wgOut->setPagetitle( wfMsg( 'top-fans-by-category-title', $stat_name_friendly ) );
 42+ $wgOut->setPageTitle( wfMsg( 'top-fans-by-category-title', $stat_name_friendly ) );
4343
4444 $count = 50;
4545
@@ -59,11 +59,12 @@
6060
6161 $dbr = wfGetDB( DB_SLAVE );
6262 $res = $dbr->select( 'user_stats',
63 - array('stats_user_id', 'stats_user_name', $column),
64 - array('stats_user_id <> 0', "{$column} > 0" ), __METHOD__,
 63+ array( 'stats_user_id', 'stats_user_name', $column ),
 64+ array( 'stats_user_id <> 0', "{$column} > 0" ),
 65+ __METHOD__,
6566 $params
6667 );
67 - while( $row = $dbr->fetchObject($res) ){
 68+ while( $row = $dbr->fetchObject( $res ) ){
6869 $user_list[] = array(
6970 'user_id' => $row->stats_user_id,
7071 'user_name' => $row->stats_user_name,
@@ -74,35 +75,35 @@
7576 }
7677
7778 // Top nav bar
78 - $top_title = Title::makeTitle( NS_SPECIAL, 'TopFans' );
79 - $recent_title = Title::makeTitle( NS_SPECIAL, 'TopFansRecent' );
 79+ $top_title = SpecialPage::getTitleFor( 'TopUsers' );
 80+ $recent_title = SpecialPage::getTitleFor( 'TopUsersRecent' );
8081
81 - $out .= '<div class="top-fan-nav">
82 - <h1>' . wfMsg('top-fans-by-points-nav-header') . '</h1>
83 - <p><a href="'.$top_title->escapeFullURL().'">' . wfMsg('top-fans-total-points-link') . '</a></p>';
 82+ $out = '<div class="top-fan-nav">
 83+ <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1>
 84+ <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
8485
8586 if( $wgUserStatsTrackWeekly ){
86 - $out .= '<p><a href="' . $recent_title->escapeFullURL("period=monthly") . '">' . wfMsg('top-fans-monthly-points-link') . '</a><p>';
 87+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>';
8788 }
8889 if( $wgUserStatsTrackMonthly ){
89 - $out .= '<p><a href="' . $recent_title->escapeFullURL("period=weekly") . '">' . wfMsg('top-fans-weekly-points-link') . '</a></p>';
 90+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
9091 }
9192
9293 // Build nav of stats by category based on MediaWiki:Topfans-by-category
93 - $out .= '<h1 style="margin-top:15px !important;">' . wfMsg('top-fans-by-category-nav-header') . '</h1>';
 94+ $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
9495
95 - $by_category_title = Title::makeTitle( NS_SPECIAL, 'TopFansByStatistic' );
 96+ $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' );
9697 $nav = array();
9798
9899 $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) );
99100 foreach( $lines as $line ) {
100 - if( strpos($line, '*') !== 0 ){
 101+ if( strpos( $line, '*' ) !== 0 ){
101102 continue;
102103 } else {
103 - $line = explode( '|' , trim($line, '* '), 2 );
 104+ $line = explode( '|', trim( $line, '* ' ), 2 );
104105 $stat = $line[0];
105106 $link_text = $line[1];
106 - $out .= '<p><a href="' . $by_category_title->escapeFullURL("stat={$stat}") . '">'.$link_text.'</a></p>';
 107+ $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>';
107108 }
108109 }
109110 $out .= '</div>';
@@ -111,15 +112,15 @@
112113 $out .= '<div class="top-users">';
113114
114115 foreach( $user_list as $user ){
115 - $user_name = ( $user['user_name'] == substr( $user['user_name'] , 0, 22) ) ? $user['user_name'] : ( substr( $user['user_name'] , 0, 22) . "...");
 116+ $user_name = ( $user['user_name'] == substr( $user['user_name'] , 0, 22) ) ? $user['user_name'] : ( substr( $user['user_name'] , 0, 22 ) . '...' );
116117 $user_title = Title::makeTitle( NS_USER, $user['user_name'] );
117118 $avatar = new wAvatar( $user['user_id'], 'm' );
118 - $CommentIcon = $avatar->getAvatarImage();
 119+ $commentIcon = $avatar->getAvatarImage();
119120
120121 // Stats row
121 - // TODO: opinion_average isn't currently working, so its not enabled in menus
122 - if( $statistic == "opinion_average" ) {
123 - $statistics_row = number_format($row->opinion_average, 2);
 122+ // TODO: opinion_average isn't currently working, so it's not enabled in menus
 123+ if( $statistic == 'opinion_average' ) {
 124+ $statistics_row = number_format( $row->opinion_average, 2 );
124125 $lowercase_statistics_name = 'percent';
125126 } else {
126127 $statistics_row = number_format( $user['stat'] );
@@ -127,17 +128,17 @@
128129 }
129130
130131 $out .= '<div class="top-fan-row">
131 - <span class="top-fan-num">'.$x.'.</span>
 132+ <span class="top-fan-num">' . $x . '.</span>
132133 <span class="top-fan">
133 - <img src="'.$wgUploadPath.'/avatars/' . $CommentIcon . '" alt="" border="">
134 - <a href="' . $user_title->escapeFullURL() . '" >'.$user_name.'</a>
 134+ <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" />
 135+ <a href="' . $user_title->escapeFullURL() . '">' . $user_name . '</a>
135136 </span>
136 - <span class="top-fan-points"><b>' . $statistics_row . '</b> '.$lowercase_statistics_name.'</span>';
 137+ <span class="top-fan-points"><b>' . $statistics_row . '</b> ' . $lowercase_statistics_name . '</span>';
137138 $out .= '<div class="cleared"></div>';
138139 $out .= '</div>';
139140 $x++;
140141 }
141142 $out .= '</div><div class="cleared"></div>';
142 - $wgOut->addHTML($out);
 143+ $wgOut->addHTML( $out );
143144 }
144145 }
\ No newline at end of file

Status & tagging log