http://www.mediawiki.org/wiki/Special:Code/MediaWiki/91841
Revision: 91841 Author: ashley Date: 2011-07-10 18:03:09 +0000 (Sun, 10 Jul 2011) Log Message: ----------- 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 trunk/extensions/SocialProfile/UserStats/TopFansRecent.php trunk/extensions/SocialProfile/UserStats/TopUsers.php Modified: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php =================================================================== --- trunk/extensions/SocialProfile/UserStats/TopFansByStat.php 2011-07-10 17:59:06 UTC (rev 91840) +++ trunk/extensions/SocialProfile/UserStats/TopFansByStat.php 2011-07-10 18:03:09 UTC (rev 91841) @@ -15,8 +15,8 @@ * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { - global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, - $wgUserLevels, $wgUploadPath, $wgScriptPath; + global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath; + global $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly; // Load CSS $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' ); @@ -26,7 +26,7 @@ $statistic = $dbr->strencode( trim( $wgRequest->getVal( 'stat' ) ) ); $column = "stats_{$statistic}"; - // Error if the querystring value does not match our stat column + // Error if the query string value does not match our stat column if ( !$dbr->fieldExists( 'user_stats', $column ) ) { $wgOut->setPageTitle( wfMsg( 'top-fans-bad-field-title' ) ); $wgOut->addHTML( wfMsg( 'top-fans-bad-field-message' ) ); @@ -35,6 +35,7 @@ // Fix i18n message key $fixedStatistic = str_replace( '_', '-', $statistic ); + // Set page title $wgOut->setPageTitle( wfMsg( 'top-fans-by-category-title-' . $fixedStatistic ) ); @@ -79,34 +80,40 @@ $out = '<div class="top-fan-nav"> <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1> - <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>'; + <p><a href="' . $top_title->escapeFullURL() . '">' . + wfMsg( 'top-fans-total-points-link' ) . '</a></p>'; if ( $wgUserStatsTrackWeekly ) { - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>'; + $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . + wfMsg( 'top-fans-monthly-points-link' ) . '</a><p>'; } if ( $wgUserStatsTrackMonthly ) { - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; + $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . + wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category - $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>'; + $message = wfMsgForContent( 'topfans-by-category' ); - $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' ); - $nav = array(); + if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) { + $out .= '<h1 style="margin-top:15px !important;">' . + wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>'; - $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) ); - foreach ( $lines as $line ) { - if ( strpos( $line, '*' ) !== 0 ) { - continue; - } else { - $line = explode( '|', trim( $line, '* ' ), 2 ); - $stat = $line[0]; - $link_text = $line[1]; - $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>'; + $lines = explode( "\n", $message ); + foreach ( $lines as $line ) { + if ( strpos( $line, '*' ) !== 0 ) { + continue; + } else { + $line = explode( '|', trim( $line, '* ' ), 2 ); + $stat = $line[0]; + $link_text = $line[1]; + $statURL = $this->getTitle()->escapeFullURL( "stat={$stat}" ); + $out .= '<p><a href="' . $statURL . '">' . $link_text . '</a></p>'; + } } } + $out .= '</div>'; - $x = 1; $out .= '<div class="top-users">'; @@ -128,7 +135,11 @@ } else { global $wgLang; $statistics_row = number_format( $user['stat'] ); - $lowercase_statistics_name = $wgLang->lc( wfMsgExt( "top-fans-stats-{$fixedStatistic}", 'parsemag', $user['stat'] ) ); + $lowercase_statistics_name = $wgLang->lc( wfMsgExt( + "top-fans-stats-{$fixedStatistic}", + 'parsemag', + $user['stat'] + ) ); } $out .= '<div class="top-fan-row"> @@ -142,6 +153,7 @@ </div>'; $x++; } + $out .= '</div><div class="cleared"></div>'; $wgOut->addHTML( $out ); } Modified: trunk/extensions/SocialProfile/UserStats/TopFansRecent.php =================================================================== --- trunk/extensions/SocialProfile/UserStats/TopFansRecent.php 2011-07-10 17:59:06 UTC (rev 91840) +++ trunk/extensions/SocialProfile/UserStats/TopFansRecent.php 2011-07-10 18:03:09 UTC (rev 91841) @@ -15,8 +15,7 @@ * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { - global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly, - $wgUserLevels, $wgUploadPath, $wgScriptPath; + global $wgRequest, $wgUser, $wgOut, $wgMemc, $wgUploadPath, $wgScriptPath; // Load CSS $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SocialProfile/UserStats/TopList.css' ); @@ -78,35 +77,41 @@ $out = '<div class="top-fan-nav"> <h1>' . wfMsg( 'top-fans-by-points-nav-header' ) . '</h1> - <p><a href="' . $top_title->escapeFullURL() . '">' . wfMsg( 'top-fans-total-points-link' ) . '</a></p>'; + <p><a href="' . $top_title->escapeFullURL() . '">' . + wfMsg( 'top-fans-total-points-link' ) . '</a></p>'; if ( $period == 'weekly' ) { - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a><p> + $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . + wfMsg( 'top-fans-monthly-points-link' ) . '</a><p> <p><b>' . wfMsg( 'top-fans-weekly-points-link' ) . '</b></p>'; } else { $out .= '<p><b>' . wfMsg( 'top-fans-monthly-points-link' ) . '</b><p> - <p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; + <p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . + wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' ); - $nav = array(); + $message = wfMsgForContent( 'topfans-by-category' ); - $lines = explode( "\n", wfMsgForContent( 'topfans-by-category' ) ); - if ( count( $lines ) > 0 ) { - $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>'; - } + if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) { + $out .= '<h1 style="margin-top:15px !important;">' . + wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>'; - foreach ( $lines as $line ) { - if ( strpos( $line, '*' ) !== 0 ) { - continue; - } else { - $line = explode( '|', trim( $line, '* ' ), 2 ); - $stat = $line[0]; - $link_text = $line[1]; - $out .= '<p><a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . '">' . $link_text . '</a></p>'; + $lines = explode( "\n", $message ); + foreach ( $lines as $line ) { + if ( strpos( $line, '*' ) !== 0 ) { + continue; + } else { + $line = explode( '|', trim( $line, '* ' ), 2 ); + $stat = $line[0]; + $link_text = $line[1]; + $statURL = $by_category_title->escapeFullURL( "stat={$stat}" ); + $out .= '<p><a href="' . $statURL . '">' . $link_text . '</a></p>'; + } } } + $out .= '</div>'; $x = 1; @@ -115,20 +120,23 @@ foreach ( $user_list as $user ) { $user_title = Title::makeTitle( NS_USER, $user['user_name'] ); $avatar = new wAvatar( $user['user_id'], 'm' ); - $commentIcon = $avatar->getAvatarImage(); + $avatarImage = $avatar->getAvatarImage(); $out .= '<div class="top-fan-row"> <span class="top-fan-num">' . $x . '.</span> <span class="top-fan"> - <img src="' . $wgUploadPath . '/avatars/' . $commentIcon . '" alt="" border="" /> + <img src="' . $wgUploadPath . '/avatars/' . $avatarImage . '" alt="" border="" /> <a href="' . $user_title->escapeFullURL() . '" >' . $user['user_name'] . '</a> </span>'; - $out .= '<span class="top-fan-points"><b>' . number_format( $user['points'] ) . '</b> ' . wfMsg( 'top-fans-points' ) . '</span>'; + $out .= '<span class="top-fan-points"><b>' . + number_format( $user['points'] ) . '</b> ' . + wfMsg( 'top-fans-points' ) . '</span>'; $out .= '<div class="cleared"></div>'; $out .= '</div>'; $x++; } + $out .= '</div><div class="cleared"></div>'; $wgOut->addHTML( $out ); } Modified: trunk/extensions/SocialProfile/UserStats/TopUsers.php =================================================================== --- trunk/extensions/SocialProfile/UserStats/TopUsers.php 2011-07-10 17:59:06 UTC (rev 91840) +++ trunk/extensions/SocialProfile/UserStats/TopUsers.php 2011-07-10 18:03:09 UTC (rev 91841) @@ -71,36 +71,35 @@ <p><b>' . wfMsg( 'top-fans-total-points-link' ) . '</b></p>'; if ( $wgUserStatsTrackWeekly ) { - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . wfMsg( 'top-fans-monthly-points-link' ) . '</a></p>'; + $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=monthly' ) . '">' . + wfMsg( 'top-fans-monthly-points-link' ) . '</a></p>'; } if ( $wgUserStatsTrackMonthly ) { - $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; + $out .= '<p><a href="' . $recent_title->escapeFullURL( 'period=weekly' ) . '">' . + wfMsg( 'top-fans-weekly-points-link' ) . '</a></p>'; } // Build nav of stats by category based on MediaWiki:Topfans-by-category $by_category_title = SpecialPage::getTitleFor( 'TopFansByStatistic' ); $byCategoryMessage = wfMsgForContent( 'topfans-by-category' ); - $lines = explode( "\n", $byCategoryMessage ); - if ( - count( $lines ) > 0 && - !wfEmptyMsg( 'topfans-by-category', $byCategoryMessage ) - ) - { + if ( !wfEmptyMsg( 'topfans-by-category', $byCategoryMessage ) ) { $out .= '<h1 style="margin-top:15px !important;">' . wfMsg( 'top-fans-by-category-nav-header' ) . '</h1>'; - } - foreach ( $lines as $line ) { - if ( strpos( $line, '*' ) !== 0 ) { - continue; - } else { - $line = explode( '|' , trim( $line, '* ' ), 2 ); - $stat = $line[0]; - $link_text = $line[1]; - $out .= '<p> <a href="' . $by_category_title->escapeFullURL( "stat={$stat}" ) . "\">{$link_text}</a></p>"; + $lines = explode( "\n", $byCategoryMessage ); + foreach ( $lines as $line ) { + if ( strpos( $line, '*' ) !== 0 ) { + continue; + } else { + $line = explode( '|' , trim( $line, '* ' ), 2 ); + $stat = $line[0]; + $link_text = $line[1]; + $statURL = $by_category_title->escapeFullURL( "stat={$stat}" ); + $out .= '<p> <a href="' . $statURL . "\">{$link_text}</a></p>"; + } } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs