jenkins-bot has submitted this change and it was merged.
Change subject: Add category count to Special:TrackingCategories
......................................................................
Add category count to Special:TrackingCategories
Add the category count to the core special page
Special:TrackingCategories to see at one view, if such categories
contains pages which maybe needs attention.
Depends on a hook addition in core.
Depends On: If195fb55dee1350a6de095892ce89e6565287cd9
Change-Id: If3815586c2a280b4e8958c13010c9f7436b8723d
---
M CategoryTree.hooks.php
M CategoryTreeFunctions.php
M extension.json
3 files changed, 118 insertions(+), 49 deletions(-)
Approvals:
Florianschmidtwelzow: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CategoryTree.hooks.php b/CategoryTree.hooks.php
index d5c05ce..45d3693 100644
--- a/CategoryTree.hooks.php
+++ b/CategoryTree.hooks.php
@@ -247,4 +247,55 @@
$vars['wgCategoryTreePageCategoryOptions'] =
$ct->getOptionsAsJsStructure();
return true;
}
+
+ /**
+ * Hook handler for the SpecialTrackingCategories::preprocess hook
+ * @param SpecialPage $specialPage SpecialTrackingCategories object
+ * @param array $trackingCategories [ 'msg' => Title, 'cats' => Title[]
]
+ */
+ public static function onSpecialTrackingCategoriesPreprocess(
+ $specialPage, $trackingCategories
+ ) {
+ $categoryDbKeys = [];
+ foreach ( $trackingCategories as $catMsg => $data ) {
+ foreach ( $data['cats'] as $catTitle ) {
+ $categoryDbKeys[] = $catTitle->getDbKey();
+ }
+ }
+ $categories = [];
+ if ( $categoryDbKeys ) {
+ $dbr = wfGetDB( DB_REPLICA );
+ $res = $dbr->select(
+ 'category',
+ [ 'cat_id', 'cat_title', 'cat_pages',
'cat_subcats', 'cat_files' ],
+ [ 'cat_title' => array_unique( $categoryDbKeys
) ],
+ __METHOD__
+ );
+ foreach ( $res as $row ) {
+ $categories[$row->cat_title] =
Category::newFromRow( $row );
+ }
+ }
+ $specialPage->categoryTreeCategories = $categories;
+ }
+
+ /**
+ * Hook handler for the SpecialTrackingCategories::generateCatLink hook
+ * @param SpecialPage $specialPage SpecialTrackingCategories object
+ * @param Title $catTitle Title object of the linked category
+ * @param string &$html Result html
+ */
+ public static function onSpecialTrackingCategoriesGenerateCatLink(
+ $specialPage, $catTitle, &$html
+ ) {
+ if ( !isset( $specialPage->categoryTreeCategories ) ) {
+ return;
+ }
+
+ $cat = null;
+ if ( isset(
$specialPage->categoryTreeCategories[$catTitle->getDbKey()] ) ) {
+ $cat =
$specialPage->categoryTreeCategories[$catTitle->getDbKey()];
+ }
+
+ $html .= CategoryTree::createCountString(
$specialPage->getContext(), $cat, 0 );
+ }
}
diff --git a/CategoryTreeFunctions.php b/CategoryTreeFunctions.php
index 48c6410..a321e3e 100644
--- a/CategoryTreeFunctions.php
+++ b/CategoryTreeFunctions.php
@@ -583,22 +583,14 @@
$attr = [ 'class' => 'CategoryTreeBullet' ];
- # Get counts, with conversion to integer so === works
- # Note: $allCount is the total number of cat members,
- # not the count of how many members are normal pages.
- $allCount = $cat ? intval( $cat->getPageCount() ) : 0;
- $subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
- $fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
-
if ( $ns == NS_CATEGORY ) {
-
if ( $cat ) {
if ( $mode == CategoryTreeMode::CATEGORIES ) {
- $count = $subcatCount;
+ $count = intval( $cat->getSubcatCount()
);
} elseif ( $mode == CategoryTreeMode::PAGES ) {
- $count = $allCount - $fileCount;
+ $count = intval( $cat->getPageCount() )
- intval( $cat->getFileCount() );
} else {
- $count = $allCount;
+ $count = intval( $cat->getPageCount() );
}
}
if ( $count === 0 ) {
@@ -634,44 +626,7 @@
. $label . Xml::closeElement( 'a' );
if ( $count !== false && $this->getOption( 'showcount' ) ) {
- $pages = $allCount - $subcatCount - $fileCount;
-
- global $wgContLang, $wgLang;
- $attr = [
- 'title' => wfMessage(
'categorytree-member-counts' )
- ->numParams( $subcatCount, $pages ,
$fileCount, $allCount, $count )->text(),
- 'dir' => $wgLang->getDir() # numbers and commas
get messed up in a mixed dir env
- ];
-
- $s .= $wgContLang->getDirMark() . ' ';
-
- # Create a list of category members with only non-zero
member counts
- $memberNums = [];
- if ( $subcatCount ) {
- $memberNums[] = wfMessage(
'categorytree-num-categories' )
- ->numParams( $subcatCount )->text();
- }
- if ( $pages ) {
- $memberNums[] = wfMessage(
'categorytree-num-pages' )->numParams( $pages )->text();
- }
- if ( $fileCount ) {
- $memberNums[] = wfMessage(
'categorytree-num-files' )
- ->numParams( $fileCount )->text();
- }
- $memberNumsShort = $memberNums
- ? $wgLang->commaList( $memberNums )
- : wfMessage( 'categorytree-num-empty' )->text();
-
- # Only $5 is actually used in the default message.
- # Other arguments can be used in a customized message.
- $s .= Xml::tags(
- 'span',
- $attr,
- wfMessage( 'categorytree-member-num' )
- // Do not use numParams on params 1-4,
as they are only used for customisation.
- ->params( $subcatCount, $pages,
$fileCount, $allCount, $memberNumsShort )
- ->escaped()
- );
+ $s .= CategoryTree::createCountString(
RequestContext::getMain(), $cat, $count );
}
$s .= Xml::closeElement( 'div' );
@@ -712,6 +667,63 @@
}
/**
+ * Create a string which format the page, subcat and file counts of a
category
+ * @param IContextSource $context
+ * @param Category|null $cat
+ * @param int $countMode
+ * @return string
+ */
+ public static function createCountString( IContextSource $context,
$cat, $countMode ) {
+ global $wgContLang;
+
+ # Get counts, with conversion to integer so === works
+ # Note: $allCount is the total number of cat members,
+ # not the count of how many members are normal pages.
+ $allCount = $cat ? intval( $cat->getPageCount() ) : 0;
+ $subcatCount = $cat ? intval( $cat->getSubcatCount() ) : 0;
+ $fileCount = $cat ? intval( $cat->getFileCount() ) : 0;
+ $pages = $allCount - $subcatCount - $fileCount;
+
+ $attr = [
+ 'title' => $context->msg( 'categorytree-member-counts' )
+ ->numParams( $subcatCount, $pages , $fileCount,
$allCount, $countMode )->text(),
+ 'dir' => $context->getLanguage()->getDir() # numbers
and commas get messed up in a mixed dir env
+ ];
+
+ $s = $wgContLang->getDirMark() . ' ';
+
+ # Create a list of category members with only non-zero member
counts
+ $memberNums = [];
+ if ( $subcatCount ) {
+ $memberNums[] = $context->msg(
'categorytree-num-categories' )
+ ->numParams( $subcatCount )->text();
+ }
+ if ( $pages ) {
+ $memberNums[] = $context->msg( 'categorytree-num-pages'
)->numParams( $pages )->text();
+ }
+ if ( $fileCount ) {
+ $memberNums[] = $context->msg( 'categorytree-num-files'
)
+ ->numParams( $fileCount )->text();
+ }
+ $memberNumsShort = $memberNums
+ ? $context->getLanguage()->commaList( $memberNums )
+ : $context->msg( 'categorytree-num-empty' )->text();
+
+ # Only $5 is actually used in the default message.
+ # Other arguments can be used in a customized message.
+ $s .= Xml::tags(
+ 'span',
+ $attr,
+ $context->msg( 'categorytree-member-num' )
+ // Do not use numParams on params 1-4, as they
are only used for customisation.
+ ->params( $subcatCount, $pages, $fileCount,
$allCount, $memberNumsShort )
+ ->escaped()
+ );
+
+ return $s;
+ }
+
+ /**
* Creates a Title object from a user provided (and thus unsafe) string
* @param $title string
* @return null|Title
diff --git a/extension.json b/extension.json
index c8139bf..d713793 100644
--- a/extension.json
+++ b/extension.json
@@ -66,6 +66,12 @@
"Hooks": {
"ArticleFromTitle": [
"CategoryTreeHooks::articleFromTitle"
+ ],
+ "SpecialTrackingCategories::preprocess": [
+
"CategoryTreeHooks::onSpecialTrackingCategoriesPreprocess"
+ ],
+ "SpecialTrackingCategories::generateCatLink": [
+
"CategoryTreeHooks::onSpecialTrackingCategoriesGenerateCatLink"
]
},
"config": {
--
To view, visit https://gerrit.wikimedia.org/r/321225
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If3815586c2a280b4e8958c13010c9f7436b8723d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CategoryTree
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits