ContributionScores extension maintenance.

* Reduce usage of globals.
* Use Message class where possible.
* Update .gitignore.
* Broke some long lines.
* Updated documentation for a method.

Change-Id: Ic4c49dbcdabce2667ab140321d8618f62fe72fe8
This commit is contained in:
Siebrand Mazeland 2012-08-16 14:19:19 +02:00
parent 4bceabbff7
commit 3d4fd708bb
3 changed files with 30 additions and 28 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
*~ *~
*.kate-swp *.kate-swp
.*.swp .*.swp
.idea

View file

@ -15,7 +15,7 @@ $wgExtensionCredits['specialpage'][] = array(
'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores', 'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
'author' => 'Tim Laqua', 'author' => 'Tim Laqua',
'descriptionmsg' => 'contributionscores-desc', 'descriptionmsg' => 'contributionscores-desc',
'version' => '1.15' 'version' => '1.16'
); );
$dir = dirname( __FILE__ ) . '/'; $dir = dirname( __FILE__ ) . '/';
@ -77,10 +77,10 @@ function efContributionScores_Render( &$parser, $usertext, $metric = 'score' ) {
$row = $dbr->fetchObject( $res ); $row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->page_count ); $output = $wgLang->formatNum( $row->page_count );
} else { } else {
$output = wfMsg( 'contributionscores-invalidmetric' ); $output = wfMessage( 'contributionscores-invalidmetric' )->text();
} }
} else { } else {
$output = wfMsg( 'contributionscores-invalidusername' ); $output = wfMessage( 'contributionscores-invalidusername' )->text();
} }
return $parser->insertStripItem( $output, $parser->mStripState ); return $parser->insertStripItem( $output, $parser->mStripState );

View file

@ -23,11 +23,12 @@ class ContributionScores extends IncludableSpecialPage {
* *
* @param $days int Days in the past to run report for * @param $days int Days in the past to run report for
* @param $limit int Maximum number of users to return (default 50) * @param $limit int Maximum number of users to return (default 50)
* * @param $title Title (default null)
* @return HTML Table representing the requested Contribution Scores. * @param $options array of options (default none; nosort/notools)
* @return Html Table representing the requested Contribution Scores.
*/ */
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName, $wgLang; global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName;
$opts = explode( ',', strtolower( $options ) ); $opts = explode( ',', strtolower( $options ) );
@ -55,7 +56,6 @@ class ContributionScores extends IncludableSpecialPage {
if ( $wgContribScoreIgnoreBots ) { if ( $wgContribScoreIgnoreBots ) {
$sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')"; $sqlWhere .= " {$nextPrefix} rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot')";
$nextPrefix = "AND";
} }
$sqlMostPages = "SELECT rev_user, $sqlMostPages = "SELECT rev_user,
@ -92,10 +92,10 @@ class ContributionScores extends IncludableSpecialPage {
$output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n" . $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n" .
"<tr class='header'>\n" . "<tr class='header'>\n" .
Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) . Html::element( 'th', array(), $this->msg( 'contributionscores-score' )->text() ) .
Html::element( 'th', array(), wfMsg( 'contributionscores-pages' ) ) . Html::element( 'th', array(), $this->msg( 'contributionscores-pages' )->text() ) .
Html::element( 'th', array(), wfMsg( 'contributionscores-changes' ) ) . Html::element( 'th', array(), $this->msg( 'contributionscores-changes' )->text() ) .
Html::element( 'th', array(), wfMsg( 'contributionscores-username' ) ); Html::element( 'th', array(), $this->msg( 'contributionscores-username' )->text() );
$altrow = ''; $altrow = '';
@ -114,11 +114,12 @@ class ContributionScores extends IncludableSpecialPage {
); );
} }
$lang = $this->getLanguage();
$output .= Html::closeElement( 'tr' ); $output .= Html::closeElement( 'tr' );
$output .= "<tr class='{$altrow}'>\n<td class='content'>" . $output .= "<tr class='{$altrow}'>\n<td class='content'>" .
$wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" . $lang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" .
$wgLang->formatNum( $row->page_count ) . "\n</td><td class='content'>" . $lang->formatNum( $row->page_count ) . "\n</td><td class='content'>" .
$wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" . $lang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
$userLink; $userLink;
# Option to not display user tools # Option to not display user tools
@ -141,7 +142,8 @@ class ContributionScores extends IncludableSpecialPage {
if ( !empty( $title ) ) if ( !empty( $title ) )
$output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0, $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0,
'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), 'class' => 'contributionscores-wrapper', 'lang' => $lang->getCode(),
'dir' => $lang->getDir() ),
"\n" . "\n" .
"<tr>\n" . "<tr>\n" .
"<td style='padding: 0px;'>{$title}</td>\n" . "<td style='padding: 0px;'>{$title}</td>\n" .
@ -171,8 +173,6 @@ class ContributionScores extends IncludableSpecialPage {
* @param $par * @param $par
*/ */
function showInclude( $par ) { function showInclude( $par ) {
global $wgOut, $wgLang;
$days = null; $days = null;
$limit = null; $limit = null;
$options = 'none'; $options = 'none';
@ -199,20 +199,20 @@ class ContributionScores extends IncludableSpecialPage {
} }
if ( $days > 0 ) { if ( $days > 0 ) {
$reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $wgLang->formatNum( $days ) ); $reportTitle = $this->msg( 'contributionscores-days' )->numParams( $days )->text();
} else { } else {
$reportTitle = wfMsg( 'contributionscores-allrevisions' ); $reportTitle = $this->msg( 'contributionscores-allrevisions' )->text();
} }
$reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $wgLang->formatNum( $limit ) ); $reportTitle .= " " . $this->msg( 'contributionscores-top' )->numParams( $limit )->text();
$title = Xml::element( 'h4', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n"; $title = Xml::element( 'h4', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
$wgOut->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options ) ); $this->getOutput()->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options ) );
} }
/** /**
* Show the special page * Show the special page
*/ */
function showPage() { function showPage() {
global $wgOut, $wgLang, $wgContribScoreReports; global $wgContribScoreReports;
if ( !is_array( $wgContribScoreReports ) ) { if ( !is_array( $wgContribScoreReports ) ) {
$wgContribScoreReports = array( $wgContribScoreReports = array(
@ -222,19 +222,20 @@ class ContributionScores extends IncludableSpecialPage {
); );
} }
$wgOut->addWikiMsg( 'contributionscores-info' ); $out = $this->getOutput();
$out->addWikiMsg( 'contributionscores-info' );
foreach ( $wgContribScoreReports as $scoreReport ) { foreach ( $wgContribScoreReports as $scoreReport ) {
list( $days, $revs ) = $scoreReport; list( $days, $revs ) = $scoreReport;
if ( $days > 0 ) { if ( $days > 0 ) {
$reportTitle = wfMsgExt( 'contributionscores-days', 'parsemag', $wgLang->formatNum( $days ) ); $reportTitle = $this->msg( 'contributionscores-days' )->numParams( $days )->text();
} else { } else {
$reportTitle = wfMsg( 'contributionscores-allrevisions' ); $reportTitle = $this->msg( 'contributionscores-allrevisions' )->text();
} }
$reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $wgLang->formatNum( $revs ) ); $reportTitle .= " " . $this->msg( 'contributionscores-top' )->numParams( $revs )->text();
$title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n"; $title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
$wgOut->addHTML( $title ); $out->addHTML( $title );
$wgOut->addHTML( $this->genContributionScoreTable( $days, $revs ) ); $out->addHTML( $this->genContributionScoreTable( $days, $revs ) );
} }
} }
} }