*/ class ContributionScores extends IncludableSpecialPage { public function __construct() { parent::__construct( 'ContributionScores' ); } /// Generates a "Contribution Scores" table for a given LIMIT and date range /** * Function generates Contribution Scores tables in HTML format (not wikiText) * * @param int $days Days in the past to run report for * @param int $limit Maximum number of users to return (default 50) * @param string|null $title The title of the table * @param array $options array of options (default none; nosort/notools) * @return string Html Table representing the requested Contribution Scores. */ function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) { global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName; $opts = explode( ',', strtolower( $options ) ); $dbr = wfGetDB( DB_REPLICA ); $store = MediaWikiServices::getInstance() ->getRevisionStoreFactory() ->getRevisionStore(); $revQuery = $store->getQueryInfo(); $revUser = $revQuery['fields']['rev_user']; $sqlWhere = []; if ( $days > 0 ) { $date = time() - ( 60 * 60 * 24 * $days ); $dateString = $dbr->timestamp( $date ); $sqlWhere[] = "rev_timestamp > '$dateString'"; } if ( $wgContribScoreIgnoreBlockedUsers ) { $sqlWhere[] = "{$revUser} NOT IN " . $dbr->buildSelectSubquery( 'ipblocks', 'ipb_user', 'ipb_user <> 0', __METHOD__ ); } if ( $wgContribScoreIgnoreBots ) { $sqlWhere[] = "{$revUser} NOT IN " . $dbr->buildSelectSubquery( 'user_groups', 'ug_user', [ 'ug_group' => 'bot' ], __METHOD__ ); } if ( $dbr->unionSupportsOrderAndLimit() ) { $order = [ 'GROUP BY' => $revUser, 'ORDER BY' => 'page_count DESC', 'LIMIT' => $limit ]; } else { $order = [ 'GROUP BY' => $revUser ]; } $sqlMostPages = $dbr->selectSQLText( $revQuery['tables'], [ 'rev_user' => $revUser, 'page_count' => 'COUNT(DISTINCT rev_page)', 'rev_count' => 'COUNT(rev_id)', ], $sqlWhere, __METHOD__, $order, $revQuery['joins'] ); if ( $dbr->unionSupportsOrderAndLimit() ) { $order = [ 'GROUP BY' => 'rev_user', 'ORDER BY' => 'rev_count DESC', 'LIMIT' => $limit ]; } else { $order = [ 'GROUP BY' => 'rev_user' ]; } $sqlMostRevs = $dbr->selectSQLText( $revQuery['tables'], [ 'rev_user' => $revUser, 'page_count' => 'COUNT(DISTINCT rev_page)', 'rev_count' => 'COUNT(rev_id)', ], $sqlWhere, __METHOD__, $order, $revQuery['joins'] ); $sqlMostPagesOrRevs = $dbr->unionQueries( [ $sqlMostPages, $sqlMostRevs ], false ); $res = $dbr->select( [ 'u' => 'user', 's' => new Wikimedia\Rdbms\Subquery( $sqlMostPagesOrRevs ), ], [ 'user_id', 'user_name', 'user_real_name', 'page_count', 'rev_count', 'wiki_rank' => 'page_count+SQRT(rev_count-page_count)*2', ], [], __METHOD__, [ 'ORDER BY' => 'wiki_rank DESC', 'GROUP BY' => 'user_name', 'LIMIT' => $limit, ], [ 's' => [ 'JOIN', 'user_id=rev_user' ] ] ); $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable'; $output = "
" . $lang->formatNum( round( $user_rank, 0 ) ) . "\n | " . $lang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n | " . $lang->formatNum( $row->page_count ) . "\n | " . $lang->formatNum( $row->rev_count ) . "\n | " . $userLink; # Option to not display user tools if ( !in_array( 'notools', $opts ) ) { $output .= Linker::userToolLinks( $row->user_id, $row->user_name ); } $output .= Html::closeElement( 'td' ) . "\n"; if ( $altrow == '' && empty( $sortable ) ) { $altrow = 'odd '; } else { $altrow = ''; } $user_rank++; } $output .= Html::closeElement( 'tr' ); $output .= Html::closeElement( 'table' ); $dbr->freeResult( $res ); if ( !empty( $title ) ) { $output = Html::rawElement( 'table', [ 'style' => 'border-spacing: 0; padding: 0', 'class' => 'contributionscores-wrapper', 'lang' => htmlspecialchars( $lang->getCode() ), 'dir' => $lang->getDir() ], "\n" . " |
{$title} | \n" . "||||
{$output} | \n" . "