Legoktm has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/327437 )
Change subject: Display count of lint errors on ?action=info ...................................................................... Display count of lint errors on ?action=info Change-Id: Ifcdfcb365e5ff6106b521d58a06df8c006772473 --- M extension.json M i18n/en.json M i18n/qqq.json M includes/Database.php M includes/Hooks.php 5 files changed, 39 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Linter refs/changes/37/327437/1 diff --git a/extension.json b/extension.json index 98fc55d..7d2c51b 100644 --- a/extension.json +++ b/extension.json @@ -28,6 +28,7 @@ "LoadExtensionSchemaUpdates": "MediaWiki\\Linter\\Hooks::onLoadExtensionSchemaUpdates", "EditFormInitialText": "MediaWiki\\Linter\\Hooks::onEditFormInitialText", "APIQuerySiteInfoGeneralInfo": "MediaWiki\\Linter\\Hooks::onAPIQuerySiteInfoGeneralInfo", + "InfoAction": "MediaWiki\\Linter\\Hooks::onInfoAction", "WikiPageDeletionUpdates": "MediaWiki\\Linter\\Hooks::onWikiPageDeletionUpdates" }, "APIModules": { diff --git a/i18n/en.json b/i18n/en.json index 5ab4f95..283dfe0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -31,6 +31,7 @@ "linker-page-edit": "edit", "linter-heading-errors": "Errors", "linter-heading-warnings": "Warnings", + "pageinfo-linter": "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-limit": "Number of results to query", diff --git a/i18n/qqq.json b/i18n/qqq.json index 750c46b..530e81d 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -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}}", "linter-heading-errors": "Heading on [[Special:LintErrors]]", "linter-heading-warnings": "Heading on [[Special:LintErrors]]", + "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-param-categories": "{{doc-apihelp-param|query+linterrors|categories}}", "apihelp-query+linterrors-param-limit": "{{doc-apihelp-param|query+linterrors|limit}}", diff --git a/includes/Database.php b/includes/Database.php index 11d61ab..471b8d7 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -199,11 +199,19 @@ /** * @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( 'linter', [ 'linter_cat', 'COUNT(*) AS count' ], - [], + $conds, __METHOD__, [ 'GROUP BY' => 'linter_cat' ] ); diff --git a/includes/Hooks.php b/includes/Hooks.php index 7f4d901..ad541da 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -24,6 +24,7 @@ use Content; use DatabaseUpdater; use EditPage; +use IContextSource; use MWCallableUpdate; use WikiPage; @@ -101,4 +102,29 @@ '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 ) ]; + } + } } -- To view, visit https://gerrit.wikimedia.org/r/327437 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifcdfcb365e5ff6106b521d58a06df8c006772473 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Linter Gerrit-Branch: master Gerrit-Owner: Legoktm <lego...@member.fsf.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits