diff --git a/ContributionScores.css b/ContributionScores.css new file mode 100644 index 0000000..a9fe210 --- /dev/null +++ b/ContributionScores.css @@ -0,0 +1,5 @@ +/* ContributionScores.css */ +.contributionscores-wrapper { } +.contributionscores-title { background-color: #aaaaaa; margin-bottom: 0px;} +.contributionscores-tableheadings { background-color: #cccccc; border-bottom: 1px solid #999999; } +.contributionscores-altrow { background-color: #eeeeee; } \ No newline at end of file diff --git a/ContributionScores.php b/ContributionScores.php index 4372954..7555cae 100644 --- a/ContributionScores.php +++ b/ContributionScores.php @@ -14,14 +14,20 @@ $wgExtensionCredits['specialpage'][] = array( 'url'=>'http://www.mediawiki.org/wiki/Extension:Contribution_Scores', 'author'=>'Tim Laqua', 'description'=>'Polls wiki database for highest user contribution volume', - 'version'=>'1.5' + 'version'=>'1.6' ); -$wgAutoloadClasses['ContributionScores'] = dirname( __FILE__ ) . '/ContributionScores_body.php'; +define( 'CONTRIBUTIONSCORES_PATH', dirname( __FILE__ ) ); +define( 'CONTRIBUTIONSCORES_EXTPATH', str_replace( $_SERVER['DOCUMENT_ROOT'], '/', CONTRIBUTIONSCORES_PATH ) ); +define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 ); +$contribScoreReports = null; + +$wgAutoloadClasses['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores_body.php'; $wgSpecialPages['ContributionScores'] = 'ContributionScores'; +$wgHooks['BeforePageDisplay'][] = 'efContributionScores_addHeadScripts'; if( version_compare( $wgVersion, '1.11', '>=' ) ) { - $wgExtensionMessagesFiles['ContributionScores'] = dirname(__FILE__) . '/ContributionScores.i18n.php'; + $wgExtensionMessagesFiles['ContributionScores'] = CONTRIBUTIONSCORES_PATH . '/ContributionScores.i18n.php'; } else { $wgExtensionFunctions[] = 'efContributionScores'; } @@ -31,8 +37,13 @@ function efContributionScores() { global $wgMessageCache; #Add Messages - require( dirname( __FILE__ ) . '/ContributionScores.i18n.php' ); + require( CONTRIBUTIONSCORES_PATH . '/ContributionScores.i18n.php' ); foreach( $messages as $key => $value ) { $wgMessageCache->addMessages( $messages[$key], $key ); - } -} + } +} + +function efContributionScores_addHeadScripts(&$out) { + $out->addScript( '' . "\n" ); + return true; +} diff --git a/ContributionScores_body.php b/ContributionScores_body.php index 4ebad51..d454c65 100644 --- a/ContributionScores_body.php +++ b/ContributionScores_body.php @@ -11,12 +11,11 @@ * * @addtogroup Extensions * @author Tim Laqua - * @author Siebrand Mazeland */ -class ContributionScores extends SpecialPage +class ContributionScores extends IncludableSpecialPage { public function __construct() { - SpecialPage::SpecialPage( 'ContributionScores' ); + parent::__construct( 'ContributionScores' ); } function getDescription() { @@ -32,7 +31,7 @@ class ContributionScores extends SpecialPage * * @return HTML Table representing the requested Contribution Scores. */ - function genContributionScoreTable( $days, $limit ) { + function genContributionScoreTable( $days, $limit, $title = null ) { global $contribScoreIgnoreBots, $wgUser; $dbr =& wfGetDB( DB_SLAVE ); @@ -69,39 +68,93 @@ class ContributionScores extends SpecialPage $res = $dbr->query($sql); - $output = "\n". - "\n". + $output = "
\n". + "\n". "\n" . "\n" . "\n" . "\n"; $skin =& $wgUser->getSkin(); + $altrow = ''; while ( $row = $dbr->fetchObject( $res ) ) { - $output .= "\n\n\n"; + + if ($altrow == '') + $altrow = 'contributionscores-altrow '; + else + $altrow = ''; } $output .= "
" . wfMsg( 'contributionscores-score' ) . "" . wfMsg( 'contributionscores-pages' ) . "" . wfMsg( 'contributionscores-changes' ) . "" . wfMsg( 'contributionscores-username' ) . "
" . + $output .= "
" . round($row->wiki_rank,0) . "\n" . $row->page_count . "\n" . $row->rev_count . "\n" . $skin->userLink( $row->user_id, $row->user_name ) . $skin->userToolLinks( $row->user_id, $row->user_name ) . "
"; $dbr->freeResult( $res ); - + + if ( !empty( $title ) ) + $output = "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "\n". + "
{$title}
{$output}
"; + return $output; } function execute( $par ) { - global $wgRequest, $wgOut, $contribScoreReports, $wgVersion; + global $wgRequest, $wgVersion, $wgOut; if( version_compare( $wgVersion, '1.11', '>=' ) ) wfLoadExtensionMessages( 'ContributionScores' ); $this->setHeaders(); - # Get request data from, e.g. - $param = $wgRequest->getText('param'); + if( $this->including() ) { + $this->showInclude( $par ); + } else { + $this->showPage(); + } + return true; + } + function showInclude( $par ) { + global $wgOut; + $days = null; + $limit = null; + + if ( !empty( $par ) ) { + $params = explode('/', $par); + + $limit = intval( $params[0] ); + + if ( isset( $params[1] ) ) + $days = intval( $params[1] ); + } + + if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT ) + $limit = 10; + if ( is_null( $days ) || $days < 0 ) + $days = 7; + + //$wgOut->addHtml('$par:' . $par); + if ( $days > 0 ) { + $reportTitle = wfMsg( 'contributionscores-days', $days ); + } else { + $reportTitle = wfMsg( 'contributionscores-allrevisions' ); + } + $reportTitle .= " " . wfMsg( 'contributionscores-top', $limit ); + $title = "

$reportTitle

\n"; + $wgOut->addHtml( $this->genContributionScoreTable( $days, $limit, $title ) ); + } + + function showPage() { + global $wgOut, $contribScoreReports; + if (!is_array($contribScoreReports)) { $contribScoreReports = array( array(7,50), @@ -118,7 +171,7 @@ class ContributionScores extends SpecialPage $reportTitle = wfMsg('contributionscores-allrevisions'); } $reportTitle .= " " . wfMsg('contributionscores-top', $scoreReport[1]); - $wgOut->addWikiText ("== $reportTitle ==\n"); + $wgOut->addHtml ("

$reportTitle

\n"); $wgOut->addHtml( $this->genContributionScoreTable($scoreReport[0],$scoreReport[1])); } }