Display count of lint errors on ?action=info

Change-Id: Ifcdfcb365e5ff6106b521d58a06df8c006772473
This commit is contained in:
Kunal Mehta 2016-12-14 19:58:18 -08:00
parent 8b8c50e9d8
commit 5c606fca03
5 changed files with 39 additions and 2 deletions

View file

@ -28,6 +28,7 @@
"LoadExtensionSchemaUpdates": "MediaWiki\\Linter\\Hooks::onLoadExtensionSchemaUpdates", "LoadExtensionSchemaUpdates": "MediaWiki\\Linter\\Hooks::onLoadExtensionSchemaUpdates",
"EditFormInitialText": "MediaWiki\\Linter\\Hooks::onEditFormInitialText", "EditFormInitialText": "MediaWiki\\Linter\\Hooks::onEditFormInitialText",
"APIQuerySiteInfoGeneralInfo": "MediaWiki\\Linter\\Hooks::onAPIQuerySiteInfoGeneralInfo", "APIQuerySiteInfoGeneralInfo": "MediaWiki\\Linter\\Hooks::onAPIQuerySiteInfoGeneralInfo",
"InfoAction": "MediaWiki\\Linter\\Hooks::onInfoAction",
"WikiPageDeletionUpdates": "MediaWiki\\Linter\\Hooks::onWikiPageDeletionUpdates" "WikiPageDeletionUpdates": "MediaWiki\\Linter\\Hooks::onWikiPageDeletionUpdates"
}, },
"APIModules": { "APIModules": {

View file

@ -31,6 +31,7 @@
"linker-page-edit": "edit", "linker-page-edit": "edit",
"linter-heading-errors": "Errors", "linter-heading-errors": "Errors",
"linter-heading-warnings": "Warnings", "linter-heading-warnings": "Warnings",
"pageinfo-linter": "Lint errors",
"apihelp-query+linterrors-description": "Get a list of lint errors", "apihelp-query+linterrors-description": "Get a list of lint errors",
"apihelp-query+linterrors-param-categories": "Categories of lint errors", "apihelp-query+linterrors-param-categories": "Categories of lint errors",
"apihelp-query+linterrors-param-limit": "Number of results to query", "apihelp-query+linterrors-param-limit": "Number of results to query",

View file

@ -33,6 +33,7 @@
"linker-page-edit": "Link text for edit link in {{msg-mw|linker-page-title-edit}} and {{msg-mw|linker-page-title-edit-template}}\n{{Identical|Edit}}", "linker-page-edit": "Link text for edit link in {{msg-mw|linker-page-title-edit}} and {{msg-mw|linker-page-title-edit-template}}\n{{Identical|Edit}}",
"linter-heading-errors": "Heading on [[Special:LintErrors]]\n{{Identical|Error}}", "linter-heading-errors": "Heading on [[Special:LintErrors]]\n{{Identical|Error}}",
"linter-heading-warnings": "Heading on [[Special:LintErrors]]\n{{Identical|Warning}}", "linter-heading-warnings": "Heading on [[Special:LintErrors]]\n{{Identical|Warning}}",
"pageinfo-linter": "Heading on ?action=info for a page if it has lint errors",
"apihelp-query+linterrors-description": "{{doc-apihelp-description|query+linterrors}}", "apihelp-query+linterrors-description": "{{doc-apihelp-description|query+linterrors}}",
"apihelp-query+linterrors-param-categories": "{{doc-apihelp-param|query+linterrors|categories}}", "apihelp-query+linterrors-param-categories": "{{doc-apihelp-param|query+linterrors|categories}}",
"apihelp-query+linterrors-param-limit": "{{doc-apihelp-param|query+linterrors|limit}}", "apihelp-query+linterrors-param-limit": "{{doc-apihelp-param|query+linterrors|limit}}",

View file

@ -199,11 +199,19 @@ class Database {
/** /**
* @return int[] * @return int[]
*/ */
public function getTotals() { public function getTotalsForPage() {
return $this->getTotals( [ 'linter_page' => $this->pageId ] );
}
/**
* @param array $conds Query conditions
* @return int[]
*/
public function getTotals( $conds = [] ) {
$rows = wfGetDB( DB_SLAVE )->select( $rows = wfGetDB( DB_SLAVE )->select(
'linter', 'linter',
[ 'linter_cat', 'COUNT(*) AS count' ], [ 'linter_cat', 'COUNT(*) AS count' ],
[], $conds,
__METHOD__, __METHOD__,
[ 'GROUP BY' => 'linter_cat' ] [ 'GROUP BY' => 'linter_cat' ]
); );

View file

@ -24,6 +24,7 @@ use ApiQuerySiteInfo;
use Content; use Content;
use DatabaseUpdater; use DatabaseUpdater;
use EditPage; use EditPage;
use IContextSource;
use MWCallableUpdate; use MWCallableUpdate;
use WikiPage; use WikiPage;
@ -101,4 +102,29 @@ class Hooks {
'warnings' => $catManager->getWarnings(), 'warnings' => $catManager->getWarnings(),
]; ];
} }
/**
* Hook: InfoAction
*
* Display quick summary of errors for this page on ?action=info
*
* @param IContextSource $context
* @param array &$pageInfo
*/
public static function onInfoAction( IContextSource $context, array &$pageInfo ) {
$pageId = $context->getTitle()->getArticleID();
if ( !$pageId ) {
return;
}
$database = new Database( $pageId );
$totals = array_filter( $database->getTotalsForPage() );
if ( !$totals ) {
// No errors, yay!
return;
}
foreach ( $totals as $name => $count ) {
$pageInfo['linter'][] = [ $context->msg( "linter-category-$name" ), htmlspecialchars( $count ) ];
}
}
} }