From d20ca5c22d7442c9a97df81f7999d0782b3adf64 Mon Sep 17 00:00:00 2001 From: Tim Laqua Date: Wed, 19 Dec 2007 15:45:09 +0000 Subject: [PATCH] * Added notools option to showInclude * Added nosort option to showInclude * Optimized crazy SQL query - 84% faster on a small wiki (~32000 revisions) * Added more CSS classes --- ContributionScores.css | 8 ++-- ContributionScores.php | 2 +- ContributionScores_body.php | 90 ++++++++++++++++++++++++------------- 3 files changed, 66 insertions(+), 34 deletions(-) diff --git a/ContributionScores.css b/ContributionScores.css index a9fe210..15ac229 100644 --- a/ContributionScores.css +++ b/ContributionScores.css @@ -1,5 +1,7 @@ /* ContributionScores.css */ -.contributionscores-wrapper { } -.contributionscores-title { background-color: #aaaaaa; margin-bottom: 0px;} +.contributionscores-wrapper { } +.contributionscores-title { background-color: #aaaaaa; margin-bottom: 0px; padding-left: .4em; } .contributionscores-tableheadings { background-color: #cccccc; border-bottom: 1px solid #999999; } -.contributionscores-altrow { background-color: #eeeeee; } \ No newline at end of file +.contributionscores-altrow { background-color: #eeeeee; } +.contributionscores-headercell { font-weight: bold; padding-left: .2em; padding-right: .2em; } +.contributionscores-contentcell { padding-left: .2em; padding-right: .2em; } diff --git a/ContributionScores.php b/ContributionScores.php index 0664976..6a1d53a 100644 --- a/ContributionScores.php +++ b/ContributionScores.php @@ -14,7 +14,7 @@ $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.6' + 'version'=>'1.7' ); define( 'CONTRIBUTIONSCORES_PATH', dirname( __FILE__ ) ); diff --git a/ContributionScores_body.php b/ContributionScores_body.php index 8ffb09b..c2464c5 100644 --- a/ContributionScores_body.php +++ b/ContributionScores_body.php @@ -31,59 +31,86 @@ class ContributionScores extends IncludableSpecialPage * * @return HTML Table representing the requested Contribution Scores. */ - function genContributionScoreTable( $days, $limit, $title = null ) { + function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { global $contribScoreIgnoreBots, $wgUser; + $opts = explode(',', strtolower($options)); + $dbr =& wfGetDB( DB_SLAVE ); $userTable = $dbr->tableName('user'); $userGroupTable = $dbr->tableName('user_groups'); $revTable = $dbr->tableName('revision'); - - $sql = "SELECT user_id, " . - "user_name, " . - "COUNT(DISTINCT rev_page) AS page_count, " . - "COUNT(rev_id) AS rev_count, " . - "COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank " . - "FROM $userTable userTable JOIN $revTable revTable ON (userTable.user_id=revTable.rev_user) "; - + + $sqlWhere = ""; + if ( $days > 0 ) { $date = time() - (60*60*24*$days); $dateString = $dbr->timestamp($date); - $sql .= "WHERE rev_timestamp > '$dateString' "; + $sqlWhere .= " WHERE rev_timestamp > '$dateString' "; } if ( $contribScoreIgnoreBots ) { - if (preg_match("/where/i", $sql)) { - $sql .= "AND "; + if (preg_match("/where/i", $sqlWhere)) { + $sqlWhere .= "AND "; } else { - $sql .= "WHERE "; + $sqlWhere .= "WHERE "; } - $sql .= "user_id NOT IN (SELECT ug_user FROM $userGroupTable WHERE ug_group='bot') "; + $sqlWhere .= "rev_user NOT IN (SELECT ug_user FROM {$userGroupTable} WHERE ug_group='bot') "; } - $sql .= "GROUP BY user_id, user_name " . + $sqlMostPages = "SELECT rev_user, + COUNT(DISTINCT rev_page) AS page_count, + COUNT(rev_id) AS rev_count + FROM {$revTable} + {$sqlWhere} + GROUP BY rev_user + ORDER BY page_count + LIMIT {$limit}"; + + $sqlMostRevs = "SELECT rev_user, + COUNT(DISTINCT rev_page) AS page_count, + COUNT(rev_id) AS rev_count + FROM {$revTable} + {$sqlWhere} + GROUP BY rev_user + ORDER BY rev_count + LIMIT {$limit}"; + + $sql = "SELECT user_id, " . + "user_name, " . + "page_count, " . + "rev_count, " . + "page_count+SQRT(rev_count-page_count)*2 AS wiki_rank " . + "FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " . "ORDER BY wiki_rank DESC " . "LIMIT $limit"; - + $res = $dbr->query($sql); - - $output = "\n". + + $sortable = in_array('nosort', $opts) ? '' : ' sortable'; + + $output = "
\n". "\n". - "\n" . - "\n" . - "\n" . - "\n"; + "\n" . + "\n" . + "\n" . + "\n"; $skin =& $wgUser->getSkin(); $altrow = ''; while ( $row = $dbr->fetchObject( $res ) ) { - $output .= "\n\n"; + $output .= "\n\n"; if ($altrow == '') $altrow = 'contributionscores-altrow '; @@ -128,6 +155,7 @@ class ContributionScores extends IncludableSpecialPage $days = null; $limit = null; + $options = 'none'; if ( !empty( $par ) ) { $params = explode('/', $par); @@ -136,6 +164,9 @@ class ContributionScores extends IncludableSpecialPage if ( isset( $params[1] ) ) $days = intval( $params[1] ); + + if ( isset( $params[2] ) ) + $options = $params[2]; } if ( empty( $limit ) || $limit < 1 || $limit > CONTRIBUTIONSCORES_MAXINCLUDELIMIT ) @@ -143,7 +174,6 @@ class ContributionScores extends IncludableSpecialPage if ( is_null( $days ) || $days < 0 ) $days = 7; - //$wgOut->addHtml('$par:' . $par); if ( $days > 0 ) { $reportTitle = wfMsg( 'contributionscores-days', $days ); } else { @@ -151,7 +181,7 @@ class ContributionScores extends IncludableSpecialPage } $reportTitle .= " " . wfMsg( 'contributionscores-top', $limit ); $title = "

$reportTitle

\n"; - $wgOut->addHtml( $this->genContributionScoreTable( $days, $limit, $title ) ); + $wgOut->addHtml( $this->genContributionScoreTable( $days, $limit, $title, $options ) ); } function showPage() {
" . wfMsg( 'contributionscores-score' ) . "" . wfMsg( 'contributionscores-pages' ) . "" . wfMsg( 'contributionscores-changes' ) . "" . wfMsg( 'contributionscores-username' ) . "" . wfMsg( 'contributionscores-score' ) . "" . wfMsg( 'contributionscores-pages' ) . "" . wfMsg( 'contributionscores-changes' ) . "" . wfMsg( 'contributionscores-username' ) . "
" . - 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 ) . "
" . + round($row->wiki_rank,0) . "\n" . + $row->page_count . "\n" . + $row->rev_count . "\n" . + $skin->userLink( $row->user_id, $row->user_name ); + + # Option to not display user tools + if ( !in_array( 'notools', $opts ) ) + $output .= $skin->userToolLinks( $row->user_id, $row->user_name ); + + $output .= "