From 163df20f43b19edc2a4243c85c367867f5196e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Tue, 1 Sep 2020 20:32:15 +0200 Subject: [PATCH 1/8] Fix typo --- i18n/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 522504c..13eac42 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6,7 +6,7 @@ }, "contributiontable": "Contribution tables", "contributiontable-desc": "Polls the wiki database for highest [[Special:ContributionTable|user contribution volume]]", - "contributiontable-info": "Tables of contribution ammounts by users.", + "contributiontable-info": "Tables of contribution amounts by users.", "contributiontable-top": "(Top $1)", "contributiontable-days": "Last {{PLURAL:$1|day|$1 days}}", "contributiontable-allrevisions": "All time", @@ -18,4 +18,4 @@ "contributiontable-username": "Username", "contributiontable-invalidusername": "Invalid username", "contributiontable-invalidmetric": "Invalid metric" -} \ No newline at end of file +} From d53bf36d0653ff69c971beb2087876a4a3ed55e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Tue, 1 Sep 2020 20:32:30 +0200 Subject: [PATCH 2/8] Include page creations in contributions --- ContributionTable_body.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index 5546d4a..41ee750 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -1,7 +1,7 @@ 'revision', 's' => 'revision', ], [ 'diff_id' => 'r.rev_id', - 'diff_size' => '( CAST( r.rev_len AS SIGNED ) - CAST( s.rev_len AS SIGNED ) )', + 'diff_size' => '( CAST( r.rev_len AS SIGNED ) - IFNULL( CAST( s.rev_len AS SIGNED ), 0 ) )', ], [], __METHOD__, [], - [ 's' => [ 'JOIN', 's.rev_id = r.rev_parent_id', ], ] + [ 's' => [ 'LEFT JOIN', 's.rev_id = r.rev_parent_id', ], ] ); # most of this query is provided by getQueryInfo @@ -64,7 +64,7 @@ function GetContribs( $days, $limit = 50) { __METHOD__, $revs['order'], $revs['joins'] - ); + ); # create parts of the outer query $tables = [ @@ -128,7 +128,7 @@ function genContributionScoreTable( $days, $limit = 50, $title = null, $options Html::element('th', [], $this->msg( 'contributiontable-add' ) ) . Html::element('th', [], $this->msg( 'contributiontable-sub' ) ) . Html::element('th', ['style' => 'width: 100%;'], $this->msg( 'contributiontable-username' ) ) - ); + ); $output .= $row; $altrow = ''; @@ -153,7 +153,7 @@ function genContributionScoreTable( $days, $limit = 50, $title = null, $options Html::element('td', $attr, $lang->formatNum( $row->diff_add ) ) . Html::element('td', $attr, $lang->formatNum( $row->diff_sub ) ) . Html::rawElement('td', [], $userLink ) - ); + ); if ( $altrow == '' && empty( $sortable ) ) { $altrow = 'odd'; @@ -175,10 +175,10 @@ function genContributionScoreTable( $days, $limit = 50, $title = null, $options ), Html::rawElement('tr', [], Html::rawElement('td', [ 'style' => 'padding: 0px;'], $title) - ) . + ) . Html::rawElement('tr', [], Html::rawElement('td', [ 'style' => 'padding: 0px;'], $output) - ) + ) ); } From 4b242621d84e5195b7387b4e732fe5b4e860f71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Tue, 1 Sep 2020 20:32:56 +0200 Subject: [PATCH 3/8] Only include pages in root namespace in contributions --- ContributionTable_body.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index 41ee750..b308b01 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -44,10 +44,12 @@ function GetContribs( $days, $limit = 50) { $revs = Revision::getQueryInfo(); # wire up the 'diffs' query to it $revs['tables']['diffs'] = new Wikimedia\Rdbms\Subquery($diffs); + $revs['tables']['page'] = 'page'; $revs['joins']['diffs'] = ['JOIN', 'diff_id = rev_id']; + $revs['joins']['page'] = ['JOIN', 'page.page_id = rev_page']; $revs['fields'][] = 'diffs.diff_size'; - # clear out any possible conditions or orders - $revs['conds'] = []; + # only include pages in root namespace + $revs['conds'] = ['page.page_namespace = 0']; $revs['order'] = []; # configure the @days limits if ($days > 1) { From d4ee1c15f3acacc9cc33cf6a1a69335463064be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Tue, 1 Sep 2020 22:03:34 +0200 Subject: [PATCH 4/8] Fix table alias handling for pages table --- ContributionTable_body.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index b308b01..01cf0ee 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -44,12 +44,12 @@ function GetContribs( $days, $limit = 50) { $revs = Revision::getQueryInfo(); # wire up the 'diffs' query to it $revs['tables']['diffs'] = new Wikimedia\Rdbms\Subquery($diffs); - $revs['tables']['page'] = 'page'; + $revs['tables']['pages'] = 'page'; $revs['joins']['diffs'] = ['JOIN', 'diff_id = rev_id']; - $revs['joins']['page'] = ['JOIN', 'page.page_id = rev_page']; + $revs['joins']['pages'] = ['JOIN', 'page_id = rev_page']; $revs['fields'][] = 'diffs.diff_size'; # only include pages in root namespace - $revs['conds'] = ['page.page_namespace = 0']; + $revs['conds'] = ['pages.page_namespace = 0']; $revs['order'] = []; # configure the @days limits if ($days > 1) { From 6a4e788373066eabdfe6bb0f346f51f7b6f5dde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Wed, 2 Sep 2020 19:58:15 +0200 Subject: [PATCH 5/8] Change namespace filter to exclusions --- ContributionTable_body.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index 01cf0ee..33b2444 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -49,7 +49,7 @@ function GetContribs( $days, $limit = 50) { $revs['joins']['pages'] = ['JOIN', 'page_id = rev_page']; $revs['fields'][] = 'diffs.diff_size'; # only include pages in root namespace - $revs['conds'] = ['pages.page_namespace = 0']; + $revs['conds'] = ['MOD(pages.page_namespace, 2) = 0', 'pages.page_namespace NOT IN (2, 3002)']; $revs['order'] = []; # configure the @days limits if ($days > 1) { From 491760f430733ad840ac6fd304479843c09985d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Wed, 2 Sep 2020 20:06:58 +0200 Subject: [PATCH 6/8] Include user namespace for short-term results --- ContributionTable_body.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index 33b2444..01b51af 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -23,9 +23,10 @@ public function __construct() { * * @param $days int Days in the past to run report for * @param $limit int Maximum number of users to return (default 50) + * @param $includeUserNamespace bool Whether to include edits on pages in the user namespace (default false) * @return table of data */ - function GetContribs( $days, $limit = 50) { + function GetContribs( $days, $limit = 50, $includeUserNamespace = false) { $dbr = wfGetDB( DB_REPLICA ); @@ -48,8 +49,15 @@ function GetContribs( $days, $limit = 50) { $revs['joins']['diffs'] = ['JOIN', 'diff_id = rev_id']; $revs['joins']['pages'] = ['JOIN', 'page_id = rev_page']; $revs['fields'][] = 'diffs.diff_size'; - # only include pages in root namespace - $revs['conds'] = ['MOD(pages.page_namespace, 2) = 0', 'pages.page_namespace NOT IN (2, 3002)']; + # Exclude pages in talk, user and site namespaces, unless user should explicitly be included + $excludedNamespaces = [3002]; + if (!$includeUserNamespace) { + $excludedNamespaces[] = 2; + } + $revs['conds'] = [ + 'MOD(pages.page_namespace, 2) = 0', + sprintf('pages.page_namespace NOT IN (%s)', implode(',', $excludedNamespaces)) + ]; $revs['order'] = []; # configure the @days limits if ($days > 1) { @@ -112,12 +120,13 @@ function GetContribs( $days, $limit = 50) { * @param $limit int Maximum number of users to return (default 50) * @param $title Title (default null) * @param $options array of options (default none; nosort/notools) + * @param $includeUserNamespace bool Whether to include edits on pages in the user namespace (default false) * @return Html Table representing the requested Contribution Table. */ - function genContributionScoreTable( $days, $limit = 50, $title = null, $options = 'none' ) { + function genContributionScoreTable( $days, $limit = 50, $title = null, $options = 'none', $includeUserNamespace = false ) { $opts = explode( ',', strtolower( $options ) ); - $res = $this->GetContribs($days, $limit); + $res = $this->GetContribs($days, $limit, $includeUserNamespace); $sortable = in_array( 'nosort', $opts ) ? '' : 'sortable'; @@ -241,7 +250,9 @@ function showInclude( $par ) { $title = Html::element('h4', array( 'class' => 'contributiontable-title' ), $title ); } - $this->getOutput()->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options ) ); + $includeUserNamespace = $days > 0; + + $this->getOutput()->addHTML( $this->genContributionScoreTable( $days, $limit, $title, $options, $includeUserNamespace ) ); } /** @@ -270,7 +281,10 @@ function showPage() { } $title = Html::element('h2', array( 'class' => 'contributiontable-title' ), $title); $out->addHTML( $title ); - $out->addHTML( $this->genContributionScoreTable( $days, $limit ) ); + + $includeUserNamespace = $days > 0; + + $out->addHTML( $this->genContributionScoreTable( $days, $limit, null, 'none', $includeUserNamespace ) ); } } From 388131462535ae72be7c12b711b0b9a7a79d1574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Wed, 2 Sep 2020 20:14:16 +0200 Subject: [PATCH 7/8] Add note about user namespace --- i18n/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i18n/en.json b/i18n/en.json index 13eac42..bfb44c0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -6,7 +6,7 @@ }, "contributiontable": "Contribution tables", "contributiontable-desc": "Polls the wiki database for highest [[Special:ContributionTable|user contribution volume]]", - "contributiontable-info": "Tables of contribution amounts by users.", + "contributiontable-info": "Tables of contribution amounts by users. All time contributions exclude user pages.", "contributiontable-top": "(Top $1)", "contributiontable-days": "Last {{PLURAL:$1|day|$1 days}}", "contributiontable-allrevisions": "All time", From dfe0dbb00f18c512103b81068b804366ba156262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Wed, 2 Sep 2020 20:32:53 +0200 Subject: [PATCH 8/8] Detect page creations correctly --- ContributionTable_body.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ContributionTable_body.php b/ContributionTable_body.php index 01b51af..ddcda56 100644 --- a/ContributionTable_body.php +++ b/ContributionTable_body.php @@ -35,7 +35,7 @@ function GetContribs( $days, $limit = 50, $includeUserNamespace = false) { [ 'r' => 'revision', 's' => 'revision', ], [ 'diff_id' => 'r.rev_id', - 'diff_size' => '( CAST( r.rev_len AS SIGNED ) - IFNULL( CAST( s.rev_len AS SIGNED ), 0 ) )', + 'diff_size' => '( CAST( r.rev_len AS SIGNED ) - IF( r.rev_parent_id = 0, 0, CAST( s.rev_len AS SIGNED ) ) )', ], [], __METHOD__, [], [ 's' => [ 'LEFT JOIN', 's.rev_id = r.rev_parent_id', ], ]