From 21da2d00f6b36e2bb3e9d1f3066a39625611d227 Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Mon, 28 Nov 2011 16:34:58 +0000 Subject: [PATCH] * Improve i18n (use formatNum for all numbers, add dir & lang attribute) * Change td to th elements for titles (this also makes the sort script work again) * General whitespace fixes --- ContributionScores.i18n.php | 4 +- ContributionScores.php | 8 ++-- ContributionScores_body.php | 96 +++++++++++++++++++++---------------- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/ContributionScores.i18n.php b/ContributionScores.i18n.php index 8b582aa..7b3dc9e 100644 --- a/ContributionScores.i18n.php +++ b/ContributionScores.i18n.php @@ -17,7 +17,7 @@ $messages['en'] = array( Scores calculated in this manner weight edit diversity over edit volume. Basically, this score measures primarily unique pages edited, with consideration for high edit volume - assumed to be a higher quality page.", 'contributionscores-top' => '(Top $1)', - 'contributionscores-days' => 'Last {{PLURAL:$1|day|$1 days}}', + 'contributionscores-days' => 'Last {{PLURAL:$1|day|$2 days}}', 'contributionscores-allrevisions' => 'All time', 'contributionscores-score' => 'Score', 'contributionscores-pages' => 'Pages', @@ -42,7 +42,7 @@ $messages['qqq'] = array( :COUNT(rev_id) AS rev_count :page_count+SQRT(rev_count-page_count)*2 AS wiki_rank', 'contributionscores-top' => 'Second part of the headings of [[Special:ContributionScores]]. PLURAL is supported but not used by the English original message.', - 'contributionscores-days' => 'Heading of [[Special:ContributionScores]].', + 'contributionscores-days' => 'Heading of [[Special:ContributionScores]]. Parameter $1 is the number of days for PLURAL use; $2 is a localized number.', 'contributionscores-allrevisions' => 'Used as a header of [[Special:ContributionScores]]', 'contributionscores-pages' => '{{Identical|Pages}}', 'contributionscores-username' => '{{Identical|Username}}', diff --git a/ContributionScores.php b/ContributionScores.php index f7e6622..a5ea96c 100644 --- a/ContributionScores.php +++ b/ContributionScores.php @@ -11,11 +11,11 @@ if (!defined('MEDIAWIKI')) { $wgExtensionCredits['specialpage'][] = array( 'path' => __FILE__, - 'name'=>'Contribution Scores', - 'url'=>'http://www.mediawiki.org/wiki/Extension:Contribution_Scores', - 'author'=>'Tim Laqua', + 'name' => 'Contribution Scores', + 'url' => 'http://www.mediawiki.org/wiki/Extension:Contribution_Scores', + 'author' => 'Tim Laqua', 'descriptionmsg' => 'contributionscores-desc', - 'version'=>'1.11' + 'version' => '1.12' ); define( 'CONTRIBUTIONSCORES_PATH', dirname( __FILE__ ) ); diff --git a/ContributionScores_body.php b/ContributionScores_body.php index bceeab1..110806f 100644 --- a/ContributionScores_body.php +++ b/ContributionScores_body.php @@ -31,9 +31,9 @@ class ContributionScores extends IncludableSpecialPage { * @return HTML Table representing the requested Contribution Scores. */ function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { - global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgUser; + global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgUser, $wgLang; - $opts = explode(',', strtolower($options)); + $opts = explode( ',', strtolower( $options ) ); $dbr = wfGetDB( DB_SLAVE ); @@ -89,24 +89,24 @@ class ContributionScores extends IncludableSpecialPage { "ORDER BY wiki_rank DESC " . "LIMIT $limit"; - $res = $dbr->query($sql); + $res = $dbr->query( $sql ); - $sortable = in_array('nosort', $opts) ? '' : ' sortable'; + $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable'; $output = "\n". "\n". - "\n" . - "\n" . - "\n" . - "\n"; + "\n" . + "\n" . + "\n" . + "\n"; $skin = $wgUser->getSkin(); $altrow = ''; foreach ( $res as $row ) { $output .= "\n\n"; - if ( $altrow == '' && empty($sortable) ) + if ( $altrow == '' && empty( $sortable ) ) $altrow = 'odd '; else $altrow = ''; @@ -124,14 +124,15 @@ class ContributionScores extends IncludableSpecialPage { $dbr->freeResult( $res ); if ( !empty( $title ) ) - $output = "
" . wfMsgHtml( 'contributionscores-score' ) . "" . wfMsgHtml( 'contributionscores-pages' ) . "" . wfMsgHtml( 'contributionscores-changes' ) . "" . wfMsgHtml( 'contributionscores-username' ) . "" . wfMsgHtml( 'contributionscores-score' ) . "" . wfMsgHtml( 'contributionscores-pages' ) . "" . wfMsgHtml( 'contributionscores-changes' ) . "" . wfMsgHtml( 'contributionscores-username' ) . "
" . - round($row->wiki_rank,0) . "\n" . - $row->page_count . "\n" . - $row->rev_count . "\n" . + $wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n" . + $wgLang->formatNum( $row->page_count ) . "\n" . + $wgLang->formatNum( $row->rev_count ) . "\n" . $skin->userLink( $row->user_id, $row->user_name ); # Option to not display user tools @@ -115,7 +115,7 @@ class ContributionScores extends IncludableSpecialPage { $output .= "
\n". + $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0, + 'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), + "\n". "\n". "\n". "\n". "\n". "\n". - "\n". - "
{$title}
{$output}
"; + "\n" ); return $output; } @@ -147,62 +148,77 @@ class ContributionScores extends IncludableSpecialPage { return true; } + /** + * Called when being included on a normal wiki page. + * Cache is disabled so it can depend on the user language. + * @param $par + */ function showInclude( $par ) { - global $wgOut; + global $wgOut, $wgLang; $days = null; $limit = null; $options = 'none'; - + if ( !empty( $par ) ) { - $params = explode('/', $par); - + $params = explode('/', $par ); + $limit = intval( $params[0] ); - - if ( isset( $params[1] ) ) + + if ( isset( $params[1] ) ) { $days = intval( $params[1] ); - - if ( isset( $params[2] ) ) + } + + if ( isset( $params[2] ) ) { $options = $params[2]; + } } - - if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT ) + + if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT ) { $limit = 10; - if ( is_null( $days ) || $days < 0 ) + } + if ( is_null( $days ) || $days < 0 ) { $days = 7; + } if ( $days > 0 ) { - $reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $days ); + $reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $days, $wgLang->formatNum( $days ) ); } else { $reportTitle = wfMsg( 'contributionscores-allrevisions' ); } - $reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $limit ); + $reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $wgLang->formatNum( $limit ) ); $title = Xml::element( 'h4', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n"; $wgOut->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options ) ); } - + + /** + * Show the special page + */ function showPage() { - global $wgOut, $wgContribScoreReports; - - if (!is_array($wgContribScoreReports)) { + global $wgOut, $wgLang, $wgContribScoreReports; + + if ( !is_array( $wgContribScoreReports ) ) { $wgContribScoreReports = array( - array(7,50), - array(30,50), - array(0,50)); + array( 7, 50 ), + array( 30, 50 ), + array( 0, 50 ) + ); } $wgOut->addWikiMsg( 'contributionscores-info' ); - foreach ( $wgContribScoreReports as $scoreReport) { - if ( $scoreReport[0] > 0 ) { - $reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $scoreReport[0] ); + foreach ( $wgContribScoreReports as $scoreReport ) { + $days = $scoreReport[0]; + $revs = $scoreReport[1]; + if ( $days > 0 ) { + $reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $days, $wgLang->formatNum( $days ) ); } else { $reportTitle = wfMsg( 'contributionscores-allrevisions' ); } - $reportTitle .= " " . wfMsgExt('contributionscores-top', 'parsemag', $scoreReport[1] ); + $reportTitle .= " " . wfMsgExt('contributionscores-top', 'parsemag', $wgLang->formatNum( $revs ) ); $title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n"; $wgOut->addHTML( $title ); - $wgOut->addHTML( $this->genContributionScoreTable( $scoreReport[0], $scoreReport[1] ) ); + $wgOut->addHTML( $this->genContributionScoreTable( $days, $revs ) ); } } }