r91841 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91840‎ | r91841 | r91842 >
Date:18:03, 10 July 2011
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: remove some unused globals, shorten some lines and do not show MediaWiki:Top-fans-by-category-nav-header on Special:TopFansByStat unless MediaWiki:Topfans-by-category message has some content. Follow-up to r84801
Modified paths:
  • /trunk/extensions/SocialProfile/UserStats/TopFansByStat.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/TopFansRecent.php (modified) (history)
  • /trunk/extensions/SocialProfile/UserStats/TopUsers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStats/TopFansRecent.php
@@ -15,8 +15,7 @@
1616 * @param $par Mixed: parameter passed to the page or null
1717 */
1818 public function execute( $par ) {
19 - global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly,
20 - $wgUserLevels, $wgUploadPath, $wgScriptPath;
 19+ global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath;
2120
2221 // Load CSS
2322 $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
@@ -78,35 +77,41 @@
7978
8079 $out = '<div class="top-fan-nav">
8180 <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1>
82 - <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
 81+ <p><a href="' . $top_title->escapeFullURL() . '">' .
 82+ wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
8383
8484 if ( $period == 'weekly' ) {
85 - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>
 85+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' .
 86+ wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>
8687 <p><b>' . wfMsg( 'top-fans-weekly-points-link' ) . '</b></p>';
8788 } else {
8889 $out .= '<p><b>' . wfMsg( 'top-fans-monthly-points-link' ) . '</b><p>
89 - <p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
 90+ <p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' .
 91+ wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
9092 }
9193
9294 // Build nav of stats by category based on MediaWiki:Topfans-by-category
9395 $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' );
94 - $nav = array();
 96+ $message = wfMsgForContent( 'topfans-by-category' );
9597
96 - $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) );
97 - if ( count( $lines ) > 0 ) {
98 - $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
99 - }
 98+ if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) {
 99+ $out .= '<h1 style="margin-top:15px !important;">' .
 100+ wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
100101
101 - foreach ( $lines as $line ) {
102 - if ( strpos( $line, '*' ) !== 0 ) {
103 - continue;
104 - } else {
105 - $line = explode( '|', trim( $line, '* ' ), 2 );
106 - $stat = $line[0];
107 - $link_text = $line[1];
108 - $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>';
 102+ $lines = explode( "\n", $message );
 103+ foreach ( $lines as $line ) {
 104+ if ( strpos( $line, '*' ) !== 0 ) {
 105+ continue;
 106+ } else {
 107+ $line = explode( '|', trim( $line, '* ' ), 2 );
 108+ $stat = $line[0];
 109+ $link_text = $line[1];
 110+ $statURL = $by_category_title->escapeFullURL( "stat={$stat}" );
 111+ $out .= '<p><a href="' . $statURL . '">' . $link_text . '</a></p>';
 112+ }
109113 }
110114 }
 115+
111116 $out .= '</div>';
112117
113118 $x = 1;
@@ -115,20 +120,23 @@
116121 foreach ( $user_list as $user ) {
117122 $user_title = Title::makeTitle( NS_USER, $user['user_name'] );
118123 $avatar = new wAvatar( $user['user_id'], 'm' );
119 - $commentIcon = $avatar->getAvatarImage();
 124+ $avatarImage = $avatar->getAvatarImage();
120125
121126 $out .= '<div class="top-fan-row">
122127 <span class="top-fan-num">' . $x . '.</span>
123128 <span class="top-fan">
124 - <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" />
 129+ <img src="' . $wgUploadPath . '/avatars/' . $avatarImage . '" alt="" border="" />
125130 <a href="' . $user_title->escapeFullURL() . '" >' . $user['user_name'] . '</a>
126131 </span>';
127132
128 - $out .= '<span class="top-fan-points"><b>' . number_format( $user['points'] ) . '</b> ' . wfMsg( 'top-fans-points' ) . '</span>';
 133+ $out .= '<span class="top-fan-points"><b>' .
 134+ number_format( $user['points'] ) . '</b> ' .
 135+ wfMsg( 'top-fans-points' ) . '</span>';
129136 $out .= '<div class="cleared"></div>';
130137 $out .= '</div>';
131138 $x++;
132139 }
 140+
133141 $out .= '</div><div class="cleared"></div>';
134142 $wgOut->addHTML( $out );
135143 }
Index: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
@@ -15,8 +15,8 @@
1616 * @param $par Mixed: parameter passed to the page or null
1717 */
1818 public function execute( $par ) {
19 - global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly,
20 - $wgUserLevels, $wgUploadPath, $wgScriptPath;
 19+ global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath;
 20+ global $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
2121
2222 // Load CSS
2323 $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' );
@@ -26,7 +26,7 @@
2727 $statistic = $dbr->strencode( trim( $wgRequest->getVal( 'stat' ) ) );
2828 $column = "stats_{$statistic}";
2929
30 - // Error if the querystring value does not match our stat column
 30+ // Error if the query string value does not match our stat column
3131 if ( !$dbr->fieldExists( 'user_stats', $column ) ) {
3232 $wgOut->setPageTitle( wfMsg( 'top-fans-bad-field-title' ) );
3333 $wgOut->addHTML( wfMsg( 'top-fans-bad-field-message' ) );
@@ -35,6 +35,7 @@
3636
3737 // Fix i18n message key
3838 $fixedStatistic = str_replace( '_', '-', $statistic );
 39+
3940 // Set page title
4041 $wgOut->setPageTitle( wfMsg( 'top-fans-by-category-title-' . $fixedStatistic ) );
4142
@@ -79,34 +80,40 @@
8081
8182 $out = '<div class="top-fan-nav">
8283 <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1>
83 - <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
 84+ <p><a href="' . $top_title->escapeFullURL() . '">' .
 85+ wfMsg( 'top-fans-total-points-link' ) . '</a></p>';
8486
8587 if ( $wgUserStatsTrackWeekly ) {
86 - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>';
 88+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' .
 89+ wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>';
8790 }
8891 if ( $wgUserStatsTrackMonthly ) {
89 - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
 92+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' .
 93+ wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
9094 }
9195
9296 // 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>';
 97+ $message = wfMsgForContent( 'topfans-by-category' );
9498
95 - $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' );
96 - $nav = array();
 99+ if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) {
 100+ $out .= '<h1 style="margin-top:15px !important;">' .
 101+ wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
97102
98 - $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) );
99 - foreach ( $lines as $line ) {
100 - if ( strpos( $line, '*' ) !== 0 ) {
101 - continue;
102 - } else {
103 - $line = explode( '|', trim( $line, '* ' ), 2 );
104 - $stat = $line[0];
105 - $link_text = $line[1];
106 - $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>';
 103+ $lines = explode( "\n", $message );
 104+ foreach ( $lines as $line ) {
 105+ if ( strpos( $line, '*' ) !== 0 ) {
 106+ continue;
 107+ } else {
 108+ $line = explode( '|', trim( $line, '* ' ), 2 );
 109+ $stat = $line[0];
 110+ $link_text = $line[1];
 111+ $statURL = $this->getTitle()->escapeFullURL( "stat={$stat}" );
 112+ $out .= '<p><a href="' . $statURL . '">' . $link_text . '</a></p>';
 113+ }
107114 }
108115 }
 116+
109117 $out .= '</div>';
110 -
111118 $x = 1;
112119 $out .= '<div class="top-users">';
113120
@@ -128,7 +135,11 @@
129136 } else {
130137 global $wgLang;
131138 $statistics_row = number_format( $user['stat'] );
132 - $lowercase_statistics_name = $wgLang->lc( wfMsgExt( "top-fans-stats-{$fixedStatistic}", 'parsemag', $user['stat'] ) );
 139+ $lowercase_statistics_name = $wgLang->lc( wfMsgExt(
 140+ "top-fans-stats-{$fixedStatistic}",
 141+ 'parsemag',
 142+ $user['stat']
 143+ ) );
133144 }
134145
135146 $out .= '<div class="top-fan-row">
@@ -142,6 +153,7 @@
143154 </div>';
144155 $x++;
145156 }
 157+
146158 $out .= '</div><div class="cleared"></div>';
147159 $wgOut->addHTML( $out );
148160 }
Index: trunk/extensions/SocialProfile/UserStats/TopUsers.php
@@ -71,36 +71,35 @@
7272 <p><b>' . wfMsg( 'top-fans-total-points-link' ) . '</b></p>';
7373
7474 if ( $wgUserStatsTrackWeekly ) {
75 - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a></p>';
 75+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' .
 76+ wfMsg( 'top-fans-monthly-points-link' ) . '</a></p>';
7677 }
7778
7879 if ( $wgUserStatsTrackMonthly ) {
79 - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
 80+ $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' .
 81+ wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>';
8082 }
8183
8284 // Build nav of stats by category based on MediaWiki:Topfans-by-category
8385 $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' );
8486
8587 $byCategoryMessage = wfMsgForContent( 'topfans-by-category' );
86 - $lines = explode( "\n", $byCategoryMessage );
8788
88 - if (
89 - count( $lines ) > 0 &&
90 - !wfEmptyMsg( 'topfans-by-category', $byCategoryMessage )
91 - )
92 - {
 89+ if ( !wfEmptyMsg( 'topfans-by-category', $byCategoryMessage ) ) {
9390 $out .= '<h1 style="margin-top:15px !important;">' .
9491 wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>';
95 - }
9692
97 - foreach ( $lines as $line ) {
98 - if ( strpos( $line, '*' ) !== 0 ) {
99 - continue;
100 - } else {
101 - $line = explode( '|' , trim( $line, '* ' ), 2 );
102 - $stat = $line[0];
103 - $link_text = $line[1];
104 - $out .= '<p> <a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . "\">{$link_text}</a></p>";
 93+ $lines = explode( "\n", $byCategoryMessage );
 94+ foreach ( $lines as $line ) {
 95+ if ( strpos( $line, '*' ) !== 0 ) {
 96+ continue;
 97+ } else {
 98+ $line = explode( '|' , trim( $line, '* ' ), 2 );
 99+ $stat = $line[0];
 100+ $link_text = $line[1];
 101+ $statURL = $by_category_title->escapeFullURL( "stat={$stat}" );
 102+ $out .= '<p> <a href="' . $statURL . "\">{$link_text}</a></p>";
 103+ }
105104 }
106105 }
107106

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84801SocialProfile: do not display the "Top by category" header in Special:TopUser...ashley15:37, 26 March 2011

Status & tagging log