Compare commits

..

46 commits

Author SHA1 Message Date
0d0
384fdfa2bf Patch ContributionScores for newer tables 2025-01-23 20:21:52 +01:00
libraryupgrader
7f40072416 build: Updating mediawiki/mediawiki-codesniffer to 45.0.0
Change-Id: Ia8f9b33e935bf4f6f2ede29eeabf9acb10c15cb9
2024-11-02 05:55:26 +00:00
libraryupgrader
e00a3b1c57 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 43.0.0 → 44.0.0

npm:
* eslint-config-wikimedia: 0.27.0 → 0.28.2
* braces: 3.0.2 → 3.0.3
  * https://github.com/advisories/GHSA-grv7-fg5c-xmjg
* micromatch: 4.0.5 → 4.0.8
  * https://github.com/advisories/GHSA-952p-6rrq-rcjv

Change-Id: I039053dadabb9bc16cdf7c40cd523745d3e4116f
2024-09-29 02:48:39 +00:00
Umherirrender
95976e0082 Merge "build: Updating grunt-banana-checker to 0.13.0" 2024-09-28 22:24:05 +00:00
ZoruaFox
00af3f2598 Fix wfGetDB deprecated on 1.39 and later versions.
The global function wfGetDB() has been deprecated since 1.39,
use LoadBalancer::getConnection() instead of old function.

Bug: T369145
Change-Id: Ided5ed8d1e54428541f067c75fbe7fdfeefc460f
2024-07-03 22:17:33 +00:00
libraryupgrader
2b415b36b5 build: Updating grunt-banana-checker to 0.13.0
Change-Id: Ibbdc718ea757b24ed4585f5f6e8a77bbb4f5f24f
2024-05-18 05:11:57 +00:00
libraryupgrader
1cf9ae8247 build: Updating dependencies
composer:
* mediawiki/minus-x: 1.1.1 → 1.1.3

npm:
* grunt-banana-checker: 0.11.1 → 0.12.0

Change-Id: I7c6aa5e4e1c0c2c7c6410a0745febb443eceebe7
2024-05-10 03:07:37 +00:00
libraryupgrader
548a1f177c build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 41.0.0 → 43.0.0
* php-parallel-lint/php-parallel-lint: 1.3.2 → 1.4.0

npm:
* eslint-config-wikimedia: 0.25.0 → 0.27.0
* grunt-banana-checker: 0.10.0 → 0.11.1
* grunt-eslint: 24.0.1 → 24.3.0

Change-Id: Iee9ef20b4984ad7459d77cc77c59394667954370
2024-04-22 02:10:29 +00:00
Umherirrender
645c945994 Merge "Fix "Cannot access non-public property Parser::$mStripState"" 2023-09-03 18:06:37 +00:00
Luca Mauri
4212d24b49 Fix "Cannot access non-public property Parser::$mStripState"
Discussed under https://www.mediawiki.org/wiki/Topic:Xc6c9apmxydt7817

Bug: T333675
Change-Id: Ifd38878edfd6481de85efd716e4f954cd1e449bb
2023-09-03 18:04:04 +00:00
libraryupgrader
7d145662fa build: Updating npm dependencies
* eslint-config-wikimedia: 0.24.0 → 0.25.0
* grunt-eslint: 24.0.0 → 24.0.1

Change-Id: I3a7cc1836a78f282f900b3405a9e7215803d6e38
2023-05-04 01:44:08 +00:00
libraryupgrader
7cc5575eaa build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 40.0.1 → 41.0.0

npm:
* eslint-config-wikimedia: 0.22.1 → 0.24.0
* grunt: 1.5.3 → 1.6.1

Change-Id: Ic11909141e1d3be2b5100878ff7bcec5acdf48e9
2023-03-15 04:15:54 +00:00
libraryupgrader
945f54a773 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 39.0.0 → 40.0.1

npm:
* grunt-banana-checker: 0.9.0 → 0.10.0
* minimatch: 3.0.4 → 3.0.8
  * https://github.com/advisories/GHSA-f8q6-p94x-37v3

Change-Id: I55d1c7498aea0581127daa4c09cf44f846f34f7e
2022-12-30 01:11:43 +00:00
Vedmaka
d4dae78b27 Make $wgContribScoreCacheTTL affect caching of embedded Special:ContributionScores page
Change-Id: I526362c422f611e3f8882be5575618f530b868b2
2022-12-11 10:43:17 +00:00
libraryupgrader
e307850555 build: Updating grunt to 1.5.3
Change-Id: I0fe9a27b6b821d9960553f487cd9bcf30ebd7a5b
2022-05-26 09:21:33 +00:00
libraryupgrader
790e23f9bb build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 38.0.0 → 39.0.0
* php-parallel-lint/php-console-highlighter: 0.5.0 → 1.0.0
* php-parallel-lint/php-parallel-lint: 1.3.1 → 1.3.2

npm:
* grunt-eslint: 23.0.0 → 24.0.0

Change-Id: I426c1f103cbfce83d09ceefc71eb87c3691818eb
2022-05-21 02:08:18 +00:00
libraryupgrader
7fa71f5e78 build: Updating grunt to 1.5.2
Change-Id: I58cfa3b96a1c508aef987523df9bb2985dc0c6c0
2022-04-27 09:04:20 +00:00
libraryupgrader
6666f47f3b build: Updating npm dependencies
* eslint-config-wikimedia: 0.21.0 → 0.22.1
* async: 3.2.0 → 3.2.3
  * https://github.com/advisories/GHSA-fwr7-v2mv-hh25

Change-Id: I10969887274d014e0273eda8828ec1c6b7b3f9af
2022-04-15 01:45:18 +00:00
libraryupgrader
46ebf43828 build: Updating npm dependencies
* eslint-config-wikimedia: 0.20.0 → 0.21.0
* grunt: 1.4.0 → 1.4.1

Additional changes:
* Set `name` in package.json.

Change-Id: I2bccb381a68affd8a8fe33f6b3948c75e72d1be5
2022-02-06 08:43:55 +00:00
Umherirrender
c68abe1641 Replace deprecated IDatabase::fetchObject
Bug: T286694
Change-Id: I78ae801c9fec3de0495f355b90edaac703faa169
2022-02-04 23:16:47 +01:00
Umherirrender
f9aa4a74b3 Remove PHP entry point
Change-Id: I1d6b3a1f2078b0e2db844d1334dcafc3794c9f74
2021-12-04 16:22:55 +01:00
libraryupgrader
d4132dab01 build: Updating mediawiki/mediawiki-codesniffer to 38.0.0
Change-Id: I71c9a24b73892aae722bda6a50ecfe9a735a377c
2021-10-24 01:34:43 +00:00
jenkins-bot
228317e7c6 Merge "Use MainWANObjectCache to improve performance" 2021-10-13 12:51:46 +00:00
Translation updater bot
c1d095e381 Localisation updates from https://translatewiki.net.
Change-Id: I8ab537624f7ddbd1af32a8acd3c4781686b23663
2021-10-07 09:02:42 +02:00
jenkins-bot
120ae2bac0 Use MainWANObjectCache to improve performance
Bug: T278030
Change-Id: I7e8487ff9b2e7c9038bd058aa11cd844450b165a
2021-10-06 04:50:00 +00:00
jenkins-bot
fb464fbd13 Merge "Adds configuration directive to filter specified usernames from the contribution scores tables." 2021-10-05 14:38:02 +00:00
libraryupgrader
6a8d6116e1 build: Updating dependencies
composer:
* php-parallel-lint/php-parallel-lint: 1.3.0 → 1.3.1

npm:
* ansi-regex: 5.0.0 → 5.0.1
  * https://npmjs.com/advisories/5197 (CVE-2021-3807)

Additional changes:
* composer.json: Updated phpcs command in composer test (T280592).
* composer.json: Added phpcs command to scripts (T280592).

Change-Id: Id67c2545f7d06ca94a8ca68c3196534cfaf1addc
2021-10-04 15:47:44 +00:00
Chris Rishel
35ea80cb36 Adds configuration directive to filter specified usernames from the contribution scores tables.
Bug: T292266
Change-Id: I641fbd3d8b088132cba4f142ee99a8837a02afb3
2021-10-04 08:17:14 +00:00
jenkins-bot
b7bf249857 Merge "Introduce a config, to use the rough number of edits in user table" 2021-09-28 08:43:42 +00:00
libraryupgrader
0a533b36f5 build: Updating path-parse to 1.0.7
* https://npmjs.com/advisories/1773 (CVE-2021-23343)

Change-Id: I6470d91980875027c16f172ca7d8bc4806c30c7b
2021-08-11 16:34:14 +00:00
Translation updater bot
5be2c8ed72 Localisation updates from https://translatewiki.net.
Change-Id: I10e4d8f6ee64b19de0da79a06e9e432cab34ab58
2021-07-26 08:12:02 +02:00
libraryupgrader
71ace6a83c build: Updating mediawiki/mediawiki-codesniffer to 37.0.0
Change-Id: I6c7f39e6c29ddee30e5f5885e92564f212068431
2021-07-22 15:28:36 +00:00
Func
6024bfd83b Introduce a config, to use the rough number of edits in user table
Bug: T278030
Change-Id: Ibd6d0380cc091e4720fb038bd8c663a6ebb4a6ea
2021-07-01 08:34:58 +00:00
jenkins-bot
5ade4bf529 Merge "Minor cleanups on ContributionScores extension" 2021-06-22 07:48:23 +00:00
Translation updater bot
81fe64aea5 Localisation updates from https://translatewiki.net.
Change-Id: I930be97a774bd7933400a25625db751bcad862fc
2021-05-27 12:05:05 +02:00
libraryupgrader
32d5ef59fa build: Updating browserslist to 4.16.6
* https://npmjs.com/advisories/1747 (CVE-2021-23364)

Change-Id: I6e74e9f54e2d24910830797007e035d39b96f58d
2021-05-25 09:43:35 +00:00
Func
b0e2a7c59a Minor cleanups on ContributionScores extension
Change-Id: If35b44623ce27fa80c44f6bd18ceffdf9d9811b9
2021-05-15 14:31:22 +00:00
jenkins-bot
89e7ebc584 Merge "Use User->isRegistered(), not deprecated isLoggedIn()" 2021-05-11 14:08:12 +00:00
libraryupgrader
908d2f68a2 build: Updating grunt to 1.4.0
Change-Id: Ic8eb79e109e0d82ff0e335cb55176fefe2183c0b
2021-05-09 10:24:41 +00:00
libraryupgrader
95800b51f3 build: Updating lodash to 4.17.21
* https://npmjs.com/advisories/1673 (CVE-2021-23337)

Change-Id: I5aafa6c6e11e2e47f1e3fe6ab089aa8416711632
2021-05-07 18:43:26 +00:00
ZabeMath
bb3429ecff Use User->isRegistered(), not deprecated isLoggedIn()
Bug: T270450
Change-Id: I1018c6a76af5685026d956f5c010b5537cf3011e
2021-05-06 17:57:17 +02:00
libraryupgrader
e5d96719d8 build: Updating composer dependencies
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0
* php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0

Change-Id: I99b71bd05c86f67e2af45f8b055c956b9515c831
2021-05-04 02:52:03 +00:00
Translation updater bot
fcb9c19544 Localisation updates from https://translatewiki.net.
Change-Id: Ib231bfa7ce8c0d1d639e38bf2eec872031eb518a
2021-05-03 08:36:37 +02:00
jenkins-bot
20f33b07f3 Merge "Query for array of join with ActorMigration::getJoin() to improve performance" 2021-04-21 11:48:18 +00:00
libraryupgrader
309914b267 build: Updating eslint-config-wikimedia to 0.20.0
Change-Id: Iaa507a243cfe7bde4987bd77239a9391faf9e76d
2021-04-16 07:15:21 +00:00
Func
571a707b3b Query for array of join with ActorMigration::getJoin() to improve performance
There is no need for comment text, RevisionStore::getQueryInfo() is overkill, and will cause more time in database query.

Bug: T278030
Change-Id: I9c062cd66677aa7d473a3283f29b0e39c5b4ea02
2021-04-02 15:40:27 +00:00
10 changed files with 3261 additions and 1528 deletions

View file

@ -1,16 +0,0 @@
<?php
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'ContributionScores' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessageDirs['ContributionScores'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['ContributionScoresAlias'] = __DIR__ . '/ContributionScores.alias.php';
$wgExtensionMessagesFiles['ContributionScoresMagic'] = __DIR__ . '/ContributionScores.i18n.magic.php';
wfWarn(
'Deprecated PHP entry point used for ContributionScores extension. ' .
'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
} else {
die( 'This version of the ContributionScores extension requires MediaWiki 1.29+' );
}

View file

@ -1,9 +1,9 @@
{
"require-dev": {
"mediawiki/mediawiki-codesniffer": "38.0.0",
"mediawiki/minus-x": "1.1.1",
"php-parallel-lint/php-console-highlighter": "0.5.0",
"php-parallel-lint/php-parallel-lint": "1.2.0"
"mediawiki/mediawiki-codesniffer": "45.0.0",
"mediawiki/minus-x": "1.1.3",
"php-parallel-lint/php-console-highlighter": "1.0.0",
"php-parallel-lint/php-parallel-lint": "1.4.0"
},
"scripts": {
"fix": [
@ -16,5 +16,10 @@
"minus-x check ."
],
"phpcs": "phpcs -sp --cache"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}

View file

@ -3,10 +3,10 @@
"author": "Tim Laqua",
"url": "https://www.mediawiki.org/wiki/Extension:Contribution_Scores",
"descriptionmsg": "contributionscores-desc",
"version": "1.26.0",
"version": "1.26.1",
"type": "specialpage",
"requires": {
"MediaWiki": ">= 1.33.0"
"MediaWiki": ">= 1.34.0"
},
"SpecialPages": {
"ContributionScores": "ContributionScores"
@ -39,6 +39,10 @@
"value": false,
"description": "Set to true to exclude bots users from the reporting."
},
"ContribScoreIgnoreUsernames": {
"value": [],
"description": "Array of usernames to exclude from the reporting."
},
"ContribScoresUseRealName": {
"value": false,
"description": "Set to true to use real user names when available."
@ -46,6 +50,14 @@
"ContribScoreDisableCache": {
"value": false,
"description": "Set to true to disable cache for parser function and inclusion of table."
},
"ContribScoreUseRoughEditCount": {
"value": false,
"description": "Set to true to use the rough number of edits in user table, for performance issue."
},
"ContribScoreCacheTTL": {
"value": 30,
"description": "Cache the contribution scores data, in minutes."
}
},
"manifest_version": 2

View file

@ -1,8 +0,0 @@
{
"@metadata": {
"authors": [
"Better"
]
},
"contributionscores-days": "Úrtimus $1 dias"
}

View file

@ -6,11 +6,12 @@
},
"contributionscores": "Contes de contribution",
"contributionscores-desc": "Calcula li funde de data del wiki por max alt [[Special:ContributionScores|volúmine de contribution de usator]]",
"contributionscores-info": "Contes es calculat quam seque:\n*Un (1) punctu por chascun págine unic redactet\n*Fonte de quadrat de (total de redactiones fat) - (total unique pages) * 2\nContes calculat in ti diversitá de redaction in pesa maniere súper de volúmine de redaction.\nBasicmen, ti conte mesura primarimen págines unic redactet, che consideration por alt volúmine de redaction - suposit esser un págine de alt qualitá.",
"contributionscores-info": "Li calcul primarimen mesura págines unic redactet, considerant li alt volume de redactiones.",
"contributionscores-top": "(Prim $1)",
"contributionscores-days": "Ultim {{PLURAL:$1|die|$1 dies}}",
"contributionscores-allrevisions": "Omni témpor",
"contributionscores-score": "Conte",
"contributionscores-rank": "Classification",
"contributionscores-pages": "Págines",
"contributionscores-changes": "Changes",
"contributionscores-username": "Nómine de usator",

View file

@ -5,6 +5,8 @@
]
},
"contributionscores-days": "Lasta {{PLURAL:$1|dio|$1 dii}}",
"contributionscores-score": "Nombro di punti",
"contributionscores-pages": "Pagini",
"contributionscores-changes": "Modifikuri",
"contributionscores-username": "Uzeronomo"
}

View file

@ -6,5 +6,5 @@
},
"contributionscores-pages": "ገጻት",
"contributionscores-changes": "ለውጥታት",
"contributionscores-username": "ም ተጠቃሚ"
"contributionscores-username": "ም ተጠቃሚ"
}

4576
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,9 +5,9 @@
"test": "grunt test"
},
"devDependencies": {
"eslint-config-wikimedia": "0.19.0",
"grunt": "1.5.3",
"grunt-banana-checker": "0.9.0",
"grunt-eslint": "23.0.0"
"eslint-config-wikimedia": "0.28.2",
"grunt": "1.6.1",
"grunt-banana-checker": "0.13.0",
"grunt-eslint": "24.3.0"
}
}

View file

@ -26,51 +26,50 @@ class ContributionScores extends IncludableSpecialPage {
}
public static function efContributionScoresRender( $parser, $usertext, $metric = 'score' ) {
global $wgContribScoreDisableCache;
global $wgContribScoreDisableCache, $wgContribScoreUseRoughEditCount;
if ( $wgContribScoreDisableCache ) {
$parser->getOutput()->updateCacheExpiry( 0 );
}
$user = User::newFromName( $usertext );
$dbr = wfGetDB( DB_REPLICA );
$loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA );
if ( $user instanceof User && $user->isLoggedIn() ) {
if ( $user instanceof User && $user->isRegistered() ) {
global $wgLang;
$revVar = $wgContribScoreUseRoughEditCount ? 'user_editcount' : 'COUNT(rev_id)';
$revWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
if ( $metric == 'score' ) {
$res = $dbr->select(
$row = $dbr->selectRow(
[ 'revision' ] + $revWhere['tables'],
'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
[ 'wiki_rank' => "COUNT(DISTINCT rev_page)+SQRT($revVar-COUNT(DISTINCT rev_page))*2" ],
$revWhere['conds'],
__METHOD__,
[],
$revWhere['joins']
);
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( round( $row->wiki_rank, 0 ) );
} elseif ( $metric == 'changes' ) {
$res = $dbr->select(
$row = $dbr->selectRow(
[ 'revision' ] + $revWhere['tables'],
'COUNT(rev_id) AS rev_count',
[ 'rev_count' => $revVar ],
$revWhere['conds'],
__METHOD__,
[],
$revWhere['joins']
);
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->rev_count );
} elseif ( $metric == 'pages' ) {
$res = $dbr->select(
$row = $dbr->selectRow(
[ 'revision' ] + $revWhere['tables'],
'COUNT(DISTINCT rev_page) AS page_count',
[ 'page_count' => 'COUNT(DISTINCT rev_page)' ],
$revWhere['conds'],
__METHOD__,
[],
$revWhere['joins']
);
$row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->page_count );
} else {
$output = wfMessage( 'contributionscores-invalidmetric' )->text();
@ -78,45 +77,65 @@ class ContributionScores extends IncludableSpecialPage {
} else {
$output = wfMessage( 'contributionscores-invalidusername' )->text();
}
return $parser->insertStripItem( $output, $parser->mStripState );
return $parser->insertStripItem( $output, $parser->getStripState() );
}
/// Generates a "Contribution Scores" table for a given LIMIT and date range
/**
* Function generates Contribution Scores tables in HTML format (not wikiText)
* Function fetch Contribution Scores data from database
*
* @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.
* @return array Data including the requested Contribution Scores.
*/
function genContributionScoreTable( $days, $limit, $title = null, $options = 'none' ) {
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoresUseRealName;
public static function getContributionScoreData( $days, $limit ) {
global $wgContribScoreIgnoreBots, $wgContribScoreIgnoreBlockedUsers, $wgContribScoreIgnoreUsernames,
$wgContribScoreUseRoughEditCount;
$opts = explode( ',', strtolower( $options ) );
$loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA );
$dbr = wfGetDB( DB_REPLICA );
$store = MediaWikiServices::getInstance()
->getRevisionStoreFactory()
->getRevisionStore();
$revQuery = $store->getQueryInfo();
$revQuery = ActorMigration::newMigration()->getJoin( 'rev_user' );
$revQuery['tables'] = array_merge( [ 'revision' ], $revQuery['tables'] );
$revUser = $revQuery['fields']['rev_user'];
$revUsername = $revQuery['fields']['rev_user_text'];
$sqlWhere = [];
if ( $days > 0 ) {
$date = time() - ( 60 * 60 * 24 * $days );
$dateString = $dbr->timestamp( $date );
$sqlWhere[] = "rev_timestamp > '$dateString'";
$sqlWhere[] = 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $date ) );
}
$sqlVars = [
'rev_user' => $revUser,
'page_count' => 'COUNT(DISTINCT rev_page)'
];
if ( $wgContribScoreUseRoughEditCount ) {
$revQuery['tables'][] = 'user';
$revQuery['joins']['user'] = [ 'LEFT JOIN', [ "$revUser != 0", "user_id = $revUser" ] ];
$sqlVars['rev_count'] = 'user_editcount';
} else {
$sqlVars['rev_count'] = 'COUNT(rev_id)';
}
if ( $wgContribScoreIgnoreBlockedUsers ) {
$sqlWhere[] = "{$revUser} NOT IN " .
$dbr->buildSelectSubquery( 'ipblocks', 'ipb_user', 'ipb_user <> 0', __METHOD__ );
$dbr->buildSelectSubquery( [
'block',
'block_target'
],
'bt_user',
'bt_user <> 0',
__METHOD__,
[],
[
'block_target' => [ 'JOIN', [
'bl_target=bt_id'
] ]
]
);
}
if ( $wgContribScoreIgnoreBots ) {
@ -127,23 +146,24 @@ class ContributionScores extends IncludableSpecialPage {
], __METHOD__ );
}
if ( count( $wgContribScoreIgnoreUsernames ) ) {
$listIgnoredUsernames = $dbr->makeList( $wgContribScoreIgnoreUsernames );
$sqlWhere[] = "{$revUsername} NOT IN ($listIgnoredUsernames)";
}
if ( $dbr->unionSupportsOrderAndLimit() ) {
$order = [
'GROUP BY' => $revUser,
'GROUP BY' => 'rev_user',
'ORDER BY' => 'page_count DESC',
'LIMIT' => $limit
];
} else {
$order = [ 'GROUP BY' => $revUser ];
$order = [ 'GROUP BY' => 'rev_user' ];
}
$sqlMostPages = $dbr->selectSQLText(
$revQuery['tables'],
[
'rev_user' => $revUser,
'page_count' => 'COUNT(DISTINCT rev_page)',
'rev_count' => 'COUNT(rev_id)',
],
$sqlVars,
$sqlWhere,
__METHOD__,
$order,
@ -151,22 +171,12 @@ class ContributionScores extends IncludableSpecialPage {
);
if ( $dbr->unionSupportsOrderAndLimit() ) {
$order = [
'GROUP BY' => 'rev_user',
'ORDER BY' => 'rev_count DESC',
'LIMIT' => $limit
];
} else {
$order = [ 'GROUP BY' => 'rev_user' ];
$order['ORDER BY'] = 'rev_count DESC';
}
$sqlMostRevs = $dbr->selectSQLText(
$revQuery['tables'],
[
'rev_user' => $revUser,
'page_count' => 'COUNT(DISTINCT rev_page)',
'rev_count' => 'COUNT(rev_id)',
],
$sqlVars,
$sqlWhere,
__METHOD__,
$order,
@ -191,7 +201,6 @@ class ContributionScores extends IncludableSpecialPage {
__METHOD__,
[
'ORDER BY' => 'wiki_rank DESC',
'GROUP BY' => 'user_name',
'LIMIT' => $limit,
],
[
@ -201,6 +210,25 @@ class ContributionScores extends IncludableSpecialPage {
]
]
);
$ret = iterator_to_array( $res );
return $ret;
}
/// 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 $wgContribScoresUseRealName, $wgContribScoreCacheTTL;
$opts = explode( ',', strtolower( $options ) );
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
@ -212,11 +240,26 @@ class ContributionScores extends IncludableSpecialPage {
Html::element( 'th', [], $this->msg( 'contributionscores-changes' )->text() ) .
Html::element( 'th', [], $this->msg( 'contributionscores-username' )->text() );
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
$data = $cache->getWithSetCallback(
$cache->makeKey( 'contributionscores', 'data-' . (string)$days ),
$wgContribScoreCacheTTL * 60,
function () use ( $days ) {
// Use max limit, as limit doesn't matter with performance.
// Avoid purge multiple times since limit on transclusion can be vary.
return self::getContributionScoreData( $days, self::CONTRIBUTIONSCORES_MAXINCLUDELIMIT );
} );
$lang = $this->getLanguage();
$altrow = '';
$user_rank = 1;
$lang = $this->getLanguage();
foreach ( $res as $row ) {
foreach ( $data as $row ) {
if ( $user_rank > $limit ) {
break;
}
// Use real name if option used and real name present.
if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
$userLink = Linker::userLink(
@ -234,7 +277,7 @@ class ContributionScores extends IncludableSpecialPage {
$output .= Html::closeElement( 'tr' );
$output .= "<tr class='{$altrow}'>\n" .
"<td class='content' style='padding-right:10px;text-align:right;'>" .
$lang->formatNum( round( $user_rank, 0 ) ) .
$lang->formatNum( $user_rank ) .
"\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
$lang->formatNum( round( $row->wiki_rank, 0 ) ) .
"\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
@ -262,8 +305,7 @@ class ContributionScores extends IncludableSpecialPage {
$output .= Html::closeElement( 'tr' );
$output .= Html::closeElement( 'table' );
$dbr->freeResult( $res );
// Transcluded on a normal wiki page.
if ( !empty( $title ) ) {
$output = Html::rawElement( 'table',
[
@ -364,7 +406,7 @@ class ContributionScores extends IncludableSpecialPage {
$out->addWikiMsg( 'contributionscores-info' );
foreach ( $wgContribScoreReports as $scoreReport ) {
list( $days, $revs ) = $scoreReport;
[ $days, $revs ] = $scoreReport;
if ( $days > 0 ) {
$reportTitle = $this->msg( 'contributionscores-days' )->numParams( $days )->text();
} else {
@ -380,6 +422,11 @@ class ContributionScores extends IncludableSpecialPage {
}
}
public function maxIncludeCacheTime() {
global $wgContribScoreDisableCache, $wgContribScoreCacheTTL;
return $wgContribScoreDisableCache ? 0 : $wgContribScoreCacheTTL;
}
/**
* @inheritDoc
*/