From 35a2ba9a6c4de7af111f22f08707943c119a4eaf Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 29 May 2017 08:04:57 -0700 Subject: [PATCH] Add API meta=linterstats module This module just exposes the number of lint errors in each category for tools that want to collect statistics and stuff. It's currently under a 'totals' key to give us more flexibility if we want to add other information in the future. Change-Id: Iad5136a6a5989ce5bcb1a00a4f82f49a397e0170 --- extension.json | 4 +++ i18n/en.json | 4 ++- i18n/qqq.json | 5 ++- includes/ApiQueryLinterStats.php | 52 ++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 includes/ApiQueryLinterStats.php diff --git a/extension.json b/extension.json index 5178a929..b04fcf1b 100644 --- a/extension.json +++ b/extension.json @@ -14,6 +14,7 @@ "MediaWiki\\Linter\\LintError": "includes/LintError.php", "MediaWiki\\Linter\\ApiRecordLint": "includes/ApiRecordLint.php", "MediaWiki\\Linter\\ApiQueryLintErrors": "includes/ApiQueryLintErrors.php", + "MediaWiki\\Linter\\ApiQueryLinterStats": "includes/ApiQueryLinterStats.php", "MediaWiki\\Linter\\RecordLintJob": "includes/RecordLintJob.php", "MediaWiki\\Linter\\SpecialLintErrors": "includes/SpecialLintErrors.php", "MediaWiki\\Linter\\LintErrorsPager": "includes/LintErrorsPager.php", @@ -38,6 +39,9 @@ "APIListModules": { "linterrors": "MediaWiki\\Linter\\ApiQueryLintErrors" }, + "APIMetaModules": { + "linterstats": "MediaWiki\\Linter\\ApiQueryLinterStats" + }, "SpecialPages": { "LintErrors": "MediaWiki\\Linter\\SpecialLintErrors" }, diff --git a/i18n/en.json b/i18n/en.json index 253dafce..abb3c32a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -53,5 +53,7 @@ "apihelp-record-lint-description": "Record a lint error in the database", "apihelp-record-lint-param-data": "JSON encoded data about the error", "apihelp-record-lint-param-page": "Page title", - "apihelp-record-lint-param-revision": "Revision ID that the error was found in" + "apihelp-record-lint-param-revision": "Revision ID that the error was found in", + "apihelp-query+linterstats-description": "Get number of lint errors in each category", + "apihelp-query+linterstats-example-1": "Get number of lint errors in each category" } diff --git a/i18n/qqq.json b/i18n/qqq.json index de4b2553..90bc8999 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -56,5 +56,8 @@ "apihelp-record-lint-description": "{{doc-apihelp-description|record-lint}}", "apihelp-record-lint-param-data": "{{doc-apihelp-param|record-lint|data}}", "apihelp-record-lint-param-page": "{{doc-apihelp-param|record-lint|page}}\n{{Identical|Page title}}", - "apihelp-record-lint-param-revision": "{{doc-apihelp-param|record-lint|revision}}" + "apihelp-record-lint-param-revision": "{{doc-apihelp-param|record-lint|revision}}", + "apihelp-query+linterstats-description": "{{doc-apihelp-description|query+linterstats}}", + "apihelp-query+linterstats-example-1": "{{doc-apihelp-example|query+linterstats}}" + } diff --git a/includes/ApiQueryLinterStats.php b/includes/ApiQueryLinterStats.php new file mode 100644 index 00000000..6f716ed3 --- /dev/null +++ b/includes/ApiQueryLinterStats.php @@ -0,0 +1,52 @@ +getMainWANObjectCache() + ); + + $totals = $totalsLookup->getTotals(); + ApiResult::setArrayType( $totals, 'assoc' ); + $this->getResult()->addValue( [ 'query', 'linterstats' ], 'totals', $totals ); + } + + public function getExamplesMessages() { + return [ + 'action=query&meta=linterstats' => + 'apihelp-query+linterstats-example-1', + ]; + } +}