Merge "Add severity for error categories"

This commit is contained in:
jenkins-bot 2016-12-20 01:11:13 +00:00 committed by Gerrit Code Review
commit 2f179e3851
6 changed files with 98 additions and 18 deletions

View file

@ -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

View file

@ -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",

View file

@ -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}}",

View file

@ -25,6 +25,9 @@ namespace MediaWiki\Linter;
*/
class CategoryManager {
const ERROR = 'error';
const WARNING = 'warning';
/**
* Map of category names to their hardcoded
* numerical ids for use in the database
@ -40,14 +43,52 @@ class CategoryManager {
'self-closed-tag' => 6,
];
/**
* @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 );
}
/**

View file

@ -41,9 +41,11 @@ class LintErrorsPager extends TablePager {
*/
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 );
}

View file

@ -34,14 +34,14 @@ class SpecialLintErrors extends SpecialPage {
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 @@ class SpecialLintErrors extends SpecialPage {
$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 @@ class SpecialLintErrors extends SpecialPage {
) . ' ' . $this->msg( "linter-numerrors" )->numParams( $totals[$cat] )->escaped() ) . "\n";
}
$html .= Html::closeElement( 'ul' );
$this->getOutput()->addHTML( $html );
return $html;
}
public function getGroupName() {