Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/327410 )

Change subject: Add severity for error categories
......................................................................

Add severity for error categories

Categories can now have a severity level of "error" or "warning"
designated, which places them in a different heading on
Special:LintErrors.

Bug: T152822
Change-Id: I1276b9502d90765e88dcb8ea78569dee910c5d88
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/CategoryManager.php
M includes/LintErrorsPager.php
M includes/SpecialLintErrors.php
6 files changed, 98 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Linter 
refs/changes/10/327410/1

diff --git a/extension.json b/extension.json
index 42b7614..0996932 100644
--- a/extension.json
+++ b/extension.json
@@ -55,12 +55,30 @@
        },
        "config": {
                "LinterCategories": {
-                       "fostered": true,
-                       "obsolete-tag": true,
-                       "bogus-image-options": true,
-                       "missing-end-tag": true,
-                       "stripped-tag": true,
-                       "self-closed-tag": true
+                       "fostered": {
+                               "severity": "error",
+                               "enabled": true
+                       },
+                       "obsolete-tag": {
+                               "severity": "warning",
+                               "enabled": true
+                       },
+                       "bogus-image-options": {
+                               "severity": "error",
+                               "enabled": true
+                       },
+                       "missing-end-tag": {
+                               "severity": "error",
+                               "enabled": true
+                       },
+                       "stripped-tag": {
+                               "severity": "error",
+                               "enabled": true
+                       },
+                       "self-closed-tag": {
+                               "severity": "warning",
+                               "enabled": true
+                       }
                },
                "LinterSubmitterWhitelist": {
                        "127.0.0.1": true
diff --git a/i18n/en.json b/i18n/en.json
index bc784f9..5ab4f95 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -29,6 +29,8 @@
        "linter-numerrors": "($1 {{PLURAL:$1|error|errors}})",
        "linker-page-title-edit": "$1 ($2)",
        "linker-page-edit": "edit",
+       "linter-heading-errors": "Errors",
+       "linter-heading-warnings": "Warnings",
        "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 be13a9d..750c46b 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -31,6 +31,8 @@
        "linter-numerrors": "Shown after a category link to indicate how many 
errors are in that category. $1 is the number of errors, and can be used for 
PLURAL.\n{{Identical|Error}}",
        "linker-page-title-edit": "Used in a table cell. $1 is a link to the 
page, $2 is a link to edit that page, the link text is 
{{msg-mw|linker-page-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]]",
+       "linter-heading-warnings": "Heading on [[Special: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-limit": 
"{{doc-apihelp-param|query+linterrors|limit}}",
diff --git a/includes/CategoryManager.php b/includes/CategoryManager.php
index 97c30c9..ac3107c 100644
--- a/includes/CategoryManager.php
+++ b/includes/CategoryManager.php
@@ -25,6 +25,9 @@
  */
 class CategoryManager {
 
+       const ERROR = 'error';
+       const WARNING = 'warning';
+
        /**
         * Map of category names to their hardcoded
         * numerical ids for use in the database
@@ -41,13 +44,51 @@
        ];
 
        /**
+        * @var string[]
+        */
+       private $errors = [];
+
+       /**
+        * @var string[]
+        */
+       private $warnings = [];
+
+       public function __construct() {
+               global $wgLinterCategories;
+               foreach ( $wgLinterCategories as $name => $info ) {
+                       if ( $info['enabled'] ) {
+                               if ( $info['severity'] === self::ERROR ) {
+                                       $this->errors[] = $name;
+                               } elseif ( $info['severity'] === self::WARNING 
) {
+                                       $this->warnings[] = $name;
+                               }
+                       }
+               }
+               sort( $this->errors );
+               sort( $this->warnings );
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getErrors() {
+               return $this->errors;
+       }
+
+       /**
+        * @return string[]
+        */
+       public function getWarnings() {
+               return $this->warnings;
+       }
+
+       /**
         * Categories that are configure to be displayed to users
         *
         * @return string[]
         */
        public function getVisibleCategories() {
-               global $wgLinterCategories;
-               return array_keys( array_filter( $wgLinterCategories ) );
+               return array_merge( $this->errors, $this->warnings );
        }
 
        /**
diff --git a/includes/LintErrorsPager.php b/includes/LintErrorsPager.php
index e4c447c..e4b49f1 100644
--- a/includes/LintErrorsPager.php
+++ b/includes/LintErrorsPager.php
@@ -41,9 +41,11 @@
         */
        private $linkRenderer;
 
-       public function __construct( IContextSource $context, $category, 
LinkRenderer $linkRenderer ) {
+       public function __construct( IContextSource $context, $category, 
LinkRenderer $linkRenderer,
+               CategoryManager $catManager
+       ) {
                $this->category = $category;
-               $this->categoryId = ( new CategoryManager() )->getCategoryId( 
$this->category );
+               $this->categoryId = $catManager->getCategoryId( $this->category 
);
                $this->linkRenderer = $linkRenderer;
                parent::__construct( $context );
        }
diff --git a/includes/SpecialLintErrors.php b/includes/SpecialLintErrors.php
index b2695a8..f13e765 100644
--- a/includes/SpecialLintErrors.php
+++ b/includes/SpecialLintErrors.php
@@ -34,14 +34,14 @@
        public function execute( $par ) {
                $this->setHeaders();
                $this->outputHeader();
-               $cats = ( new CategoryManager() )->getVisibleCategories();
-               if ( in_array( $par, $cats ) ) {
+               $catManager = new CategoryManager();
+               if ( in_array( $par, $catManager->getVisibleCategories() ) ) {
                        $this->category = $par;
                }
 
                if ( !$this->category ) {
                        $this->addHelpLink( 'Help:Extension:Linter' );
-                       $this->showCategoryList( $cats );
+                       $this->showCategoryListings( $catManager );
                } else {
                        $this->addHelpLink( 
"Help:Extension:Linter/{$this->category}" );
                        $out = $this->getOutput();
@@ -53,17 +53,31 @@
                        $out->addBacklinkSubtitle( $this->getPageTitle() );
                        $out->addWikiMsg( 
"linter-category-{$this->category}-desc" );
                        $pager = new LintErrorsPager(
-                               $this->getContext(), $this->category, 
$this->getLinkRenderer()
+                               $this->getContext(), $this->category, 
$this->getLinkRenderer(),
+                               $catManager
                        );
                        $out->addParserOutput( $pager->getFullOutput() );
                }
        }
 
-       private function showCategoryList( array $cats ) {
+       private function showCategoryListings( CategoryManager $catManager ) {
+               $totals = ( new Database( 0 ) )->getTotals();
+
+               $out = $this->getOutput();
+               $out->addHTML( Html::element( 'h2', [], $this->msg( 
'linter-heading-errors' )->text() ) );
+               $out->addHTML( $this->buildCategoryList( 
$catManager->getErrors(), $totals ) );
+               $out->addHTML( Html::element( 'h2', [], $this->msg( 
'linter-heading-warnings' )->text() ) );
+               $out->addHTML( $this->buildCategoryList( 
$catManager->getWarnings(), $totals ) );
+       }
+
+       /**
+        * @param string[] $cats
+        * @param int[] $totals name => count
+        * @return string
+        */
+       private function buildCategoryList( array $cats, array $totals ) {
                $linkRenderer = $this->getLinkRenderer();
                $html = Html::openElement( 'ul' ) . "\n";
-               sort( $cats );
-               $totals = ( new Database( 0 ) )->getTotals();
                foreach ( $cats as $cat ) {
                        $html .= Html::rawElement( 'li', [], 
$linkRenderer->makeKnownLink(
                                $this->getPageTitle( $cat ),
@@ -71,7 +85,8 @@
                        ) . ' ' . $this->msg( "linter-numerrors" )->numParams( 
$totals[$cat] )->escaped() ) . "\n";
                }
                $html .= Html::closeElement( 'ul' );
-               $this->getOutput()->addHTML( $html );
+
+               return $html;
        }
 
        public function getGroupName() {

-- 
To view, visit https://gerrit.wikimedia.org/r/327410
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1276b9502d90765e88dcb8ea78569dee910c5d88
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

Reply via email to