Compare commits

..

6 commits

Author SHA1 Message Date
libraryupgrader
57d5f6fb03 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 35.0.0 → 38.0.0

npm:
* grunt: 1.4.0 → 1.5.3

Change-Id: Iab00b73563a2593ed784d0d66c26af0def8fd24f
2022-05-22 14:21:24 +00:00
libraryupgrader
fbc8e60ecd build: Updating async to 3.2.3
* https://github.com/advisories/GHSA-fwr7-v2mv-hh25

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

Change-Id: I160a2a7bfe58894dd80771e30acb638df2d45f4f
2022-04-15 01:40:37 +00:00
libraryupgrader
e670dbf619 build: Updating ansi-regex to 5.0.1
* https://npmjs.com/advisories/1002401 (CVE-2021-3807)

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

Change-Id: Iceeb35bed0d562699c1e8d30822c813dd2e728ae
2021-10-07 11:56:44 +00:00
libraryupgrader
c5d33dca4a build: Updating path-parse to 1.0.7
* https://npmjs.com/advisories/1773 (CVE-2021-23343)

Change-Id: I0bbd21cb51d282db2444ba0dc1f254d8a206f852
2021-09-02 16:31:05 +00:00
libraryupgrader
8a1e44e442 build: Updating browserslist to 4.16.6
* https://npmjs.com/advisories/1747 (CVE-2021-23364)

Change-Id: Id2f4f803b1716b4e5397f3b2e8ae6abbda364ea0
2021-05-27 02:25:20 +00:00
libraryupgrader
1c2bf57eec build: Updating npm dependencies
* grunt: 1.3.0 → 1.4.0
* lodash: 4.17.19 → 4.17.21
  * https://npmjs.com/advisories/1673 (CVE-2021-23337)

Change-Id: I95b8168d2062515b1b1badc02d9935e1b20f1e99
2021-05-09 10:21:36 +00:00
10 changed files with 1566 additions and 3299 deletions

16
ContributionScores.php Normal file
View file

@ -0,0 +1,16 @@
<?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": "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"
"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"
},
"scripts": {
"fix": [
@ -16,10 +16,5 @@
"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.1",
"version": "1.26.0",
"type": "specialpage",
"requires": {
"MediaWiki": ">= 1.34.0"
"MediaWiki": ">= 1.33.0"
},
"SpecialPages": {
"ContributionScores": "ContributionScores"
@ -39,10 +39,6 @@
"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."
@ -50,14 +46,6 @@
"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

8
i18n/ext.json Normal file
View file

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

View file

@ -6,12 +6,11 @@
},
"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": "Li calcul primarimen mesura págines unic redactet, considerant li alt volume de redactiones.",
"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-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,8 +5,6 @@
]
},
"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": "ም ተጠቃሚ"
}

4636
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.28.2",
"grunt": "1.6.1",
"grunt-banana-checker": "0.13.0",
"grunt-eslint": "24.3.0"
"eslint-config-wikimedia": "0.19.0",
"grunt": "1.5.3",
"grunt-banana-checker": "0.9.0",
"grunt-eslint": "23.0.0"
}
}

View file

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