Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/405327 )
Change subject: WIP: Display count of linter errors in the main namespace
......................................................................
WIP: Display count of linter errors in the main namespace
* This gives wikis a better sense of scope of work to be ready
for Tidy replacement.
Bug: T173943
Change-Id: I80da94f3bf903d9144c542d9836b6d06ba03ec65
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiQueryLinterStats.php
M includes/RecordLintJob.php
M includes/SpecialLintErrors.php
M includes/TotalsLookup.php
6 files changed, 41 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Linter
refs/changes/27/405327/1
diff --git a/i18n/en.json b/i18n/en.json
index 2ef9756..cb22c80 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -61,6 +61,7 @@
"linter-category-misc-tidy-replacement-issues": "Miscellaneous Tidy
replacement issues",
"linter-category-misc-tidy-replacement-issues-desc": "These pages have
other issues that affect rendering when Tidy is replaced",
"linter-numerrors": "($1 {{PLURAL:$1|error|errors}})",
+ "linter-ns0-numerrors": "($1 {{PLURAL:$1|error|errors}} in Main
namespace)",
"linter-page-title-edit": "$1 ($2)",
"linter-page-edit": "edit",
"linter-page-viewsource": "view source",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a650798..2db23e4 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -64,6 +64,7 @@
"linter-category-multiline-html-table-in-list-desc": "Description of
category",
"linter-category-misc-tidy-replacement-issues": "Name of lint error
category. See [[:mw:Help:Extension:Linter/misc-tidy-replacement-issues]]",
"linter-category-misc-tidy-replacement-issues-desc": "Description of
category",
+ "linter-ns0-numerrors": "Shown after a category link to indicate how
many errors are in that category in the Main namespace. $1 is the number of
errors, and can be used for PLURAL.\n{{Identical|Error}}",
"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}}",
"linter-page-title-edit": "Used in a table cell. $1 is a link to the
page, $2 is pipe separated links to the edit and history pages, the link text
is {{msg-mw|linter-page-edit}} and {{msg-mw|linter-page-history}}",
"linter-page-edit": "Link text for edit link in
{{msg-mw|linter-page-title-edit}}\n{{Identical|Edit}}",
diff --git a/includes/ApiQueryLinterStats.php b/includes/ApiQueryLinterStats.php
index 6f716ed..560e625 100644
--- a/includes/ApiQueryLinterStats.php
+++ b/includes/ApiQueryLinterStats.php
@@ -38,7 +38,7 @@
MediaWikiServices::getInstance()->getMainWANObjectCache()
);
- $totals = $totalsLookup->getTotals();
+ $totals = $totalsLookup->getTotals( null );
ApiResult::setArrayType( $totals, 'assoc' );
$this->getResult()->addValue( [ 'query', 'linterstats' ],
'totals', $totals );
}
diff --git a/includes/RecordLintJob.php b/includes/RecordLintJob.php
index 7063169..d484c10 100644
--- a/includes/RecordLintJob.php
+++ b/includes/RecordLintJob.php
@@ -107,7 +107,7 @@
return;
}
- $totals = $lintDb->getTotals();
+ $totals = $lintDb->getTotals( null );
$wiki = wfWikiID();
$stats = $mwServices->getStatsdDataFactory();
diff --git a/includes/SpecialLintErrors.php b/includes/SpecialLintErrors.php
index 2f33fab..4ac0ff5 100644
--- a/includes/SpecialLintErrors.php
+++ b/includes/SpecialLintErrors.php
@@ -87,11 +87,11 @@
* @param int[] $totals name => count
* @param string[] $categories
*/
- private function displayList( $priority, $totals, array $categories ) {
+ private function displayList( $priority, $totals, $ns0Totals, array
$categories ) {
$out = $this->getOutput();
$msgName = 'linter-heading-' . $priority . '-priority';
$out->addHTML( Html::element( 'h2', [], $this->msg( $msgName
)->text() ) );
- $out->addHTML( $this->buildCategoryList( $categories, $totals )
);
+ $out->addHTML( $this->buildCategoryList( $categories, $totals,
$ns0Totals ) );
}
private function showCategoryListings( CategoryManager $catManager ) {
@@ -99,12 +99,13 @@
$catManager,
MediaWikiServices::getInstance()->getMainWANObjectCache()
);
- $totals = $lookup->getTotals();
+ $totals = $lookup->getTotals( null );
+ $ns0Totals = $lookup->getTotals( 0 );
// Display lint issues by priority
- $this->displayList( 'high', $totals,
$catManager->getHighPriority() );
- $this->displayList( 'medium', $totals,
$catManager->getMediumPriority() );
- $this->displayList( 'low', $totals,
$catManager->getLowPriority() );
+ $this->displayList( 'high', $totals, $ns0Totals,
$catManager->getHighPriority() );
+ $this->displayList( 'medium', $totals, $ns0Totals,
$catManager->getMediumPriority() );
+ $this->displayList( 'low', $totals, $ns0Totals,
$catManager->getLowPriority() );
}
/**
@@ -112,7 +113,7 @@
* @param int[] $totals name => count
* @return string
*/
- private function buildCategoryList( array $cats, array $totals ) {
+ private function buildCategoryList( array $cats, array $totals, array
$ns0Totals ) {
$linkRenderer = $this->getLinkRenderer();
$html = Html::openElement( 'ul' ) . "\n";
foreach ( $cats as $cat ) {
@@ -121,6 +122,8 @@
$this->msg( "linter-category-$cat" )->text()
) . ' ' . Html::element( 'bdi', [],
$this->msg( "linter-numerrors" )->numParams(
$totals[$cat] )->text()
+ ) . ' ' . Html::element( 'bdi', [],
+ $this->msg( "linter-ns0-numerrors"
)->numParams( $ns0totals[$cat] )->text()
) ) . "\n";
}
$html .= Html::closeElement( 'ul' );
diff --git a/includes/TotalsLookup.php b/includes/TotalsLookup.php
index 386b3ee..4e15fd1 100644
--- a/includes/TotalsLookup.php
+++ b/includes/TotalsLookup.php
@@ -45,38 +45,52 @@
}
/**
+ * @param integer or null $namespace
* @param string $cat
* @return string
*/
- private function makeKey( $cat ) {
- return $this->cache->makeKey( 'linter', 'total', $cat );
+ private function makeKey( $namespace, $cat ) {
+ if ( $namespace !== null) {
+ return $this->cache->makeKey( 'linter', 'total', $cat,
'ns:', $namespace );
+ } else {
+ return $this->cache->makeKey( 'linter', 'total', $cat );
+ }
+ }
+
+ private function makeTotalsCacheKey( $namespace ) {
+ if ( $namespace !== null) {
+ return $this->cache->makeKey( 'linter', 'total', 'ns:',
$namespace );
+ } else {
+ return $this->cache->makeKey( 'linter', 'total' );
+ }
}
/**
* Get the totals for every category in the database
*
+ * @param integer or null $namespace
* @return array
*/
- public function getTotals() {
+ public function getTotals( $namespace ) {
$cats = $this->catManager->getVisibleCategories();
$fetchedTotals = false;
$totals = [];
foreach ( $cats as $cat ) {
$totals[$cat] = $this->cache->getWithSetCallback(
- $this->makeKey( $cat ),
+ $this->makeKey( $namespace, $cat ),
WANObjectCache::TTL_INDEFINITE,
function ( $oldValue, &$ttl, &$setOpts,
$oldAsOf ) use ( $cat, &$fetchedTotals ) {
$setOpts +=
MWDatabase::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
if ( $fetchedTotals === false ) {
- $fetchedTotals = ( new
Database( 0 ) )->getTotals();
+ $fetchedTotals = ( new
Database( 0 ) )->getTotals( $namespace );
}
return $fetchedTotals[$cat];
},
[
'checkKeys' => [
- $this->cache->makeKey(
'linter', 'totals' ),
- $this->makeKey( $cat ),
+ $this->makeTotalsCacheKey(
$namespace )
+ $this->makeKey( $namespace,
$cat ),
],
'lockTSE' => 30,
]
@@ -92,13 +106,17 @@
* @param string $cat category name
*/
public function touchCategoryCache( $cat ) {
- $this->cache->touchCheckKey( $this->makeKey( $cat ) );
+ $this->cache->touchCheckKey( $this->makeKey( null, $cat ) );
+ // Right now, we only maintain a separate total for ns0
+ $this->cache->touchCheckKey( $this->makeKey( 0, $cat ) );
}
/**
* Have all categories be recalculated
*/
public function touchAllCategoriesCache() {
- $this->cache->touchCheckKey( $this->cache->makeKey( 'linter',
'totals' ) );
+ $this->cache->touchCheckKey( $this->makeTotalsCacheKey( null )
);
+ // Right now, we only maintain a separate total for ns0
+ $this->cache->touchCheckKey( $this->makeTotalsCacheKey( 0 ) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/405327
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I80da94f3bf903d9144c542d9836b6d06ba03ec65
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Linter
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits