jenkins-bot has submitted this change and it was merged.
Change subject: Factor out ChangeTags::tagUsageStatistics() from SpecialTags
......................................................................
Factor out ChangeTags::tagUsageStatistics() from SpecialTags
It's prettier if we keep all explicit DB queries to those tables
in one place.
Change-Id: I85b6854e26ffc656b990079d463a085ba39556df
---
M includes/ChangeTags.php
M includes/specials/SpecialTags.php
2 files changed, 32 insertions(+), 17 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php
index 029911f..3fc27f9 100644
--- a/includes/ChangeTags.php
+++ b/includes/ChangeTags.php
@@ -281,4 +281,34 @@
$wgMemc->set( $key, $emptyTags, 300 );
return $emptyTags;
}
+
+ /**
+ * Returns a map of any tags used on the wiki to number of edits
+ * tagged with them, ordered descending by the hitcount.
+ *
+ * @return array Array of string => int
+ */
+ public static function tagUsageStatistics() {
+ $out = array();
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select(
+ 'change_tag',
+ array( 'ct_tag', 'hitcount' => 'count(*)' ),
+ array(),
+ __METHOD__,
+ array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount
DESC' )
+ );
+
+ foreach ( $res as $row ) {
+ $out[$row->ct_tag] = $row->hitcount;
+ }
+ foreach ( self::listDefinedTags() as $tag ) {
+ if ( !isset( $out[$tag] ) ) {
+ $out[$tag] = 0;
+ }
+ }
+
+ return $out;
+ }
}
diff --git a/includes/specials/SpecialTags.php
b/includes/specials/SpecialTags.php
index 6a282c9..80c38d5 100644
--- a/includes/specials/SpecialTags.php
+++ b/includes/specials/SpecialTags.php
@@ -46,28 +46,15 @@
Xml::tags( 'th', null, $this->msg(
'tags-description-header' )->parse() ) .
Xml::tags( 'th', null, $this->msg(
'tags-hitcount-header' )->parse() )
);
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'change_tag', array( 'ct_tag', 'hitcount'
=> 'count(*)' ),
- array(), __METHOD__, array( 'GROUP BY' => 'ct_tag',
'ORDER BY' => 'hitcount DESC' ) );
- foreach ( $res as $row ) {
- $html .= $this->doTagRow( $row->ct_tag, $row->hitcount
);
- }
-
- foreach ( ChangeTags::listDefinedTags() as $tag ) {
- $html .= $this->doTagRow( $tag, 0 );
+ foreach ( ChangeTags::tagUsageStatistics() as $tag => $hitcount
) {
+ $html .= $this->doTagRow( $tag, $hitcount );
}
$out->addHTML( Xml::tags( 'table', array( 'class' => 'wikitable
sortable mw-tags-table' ), $html ) );
}
function doTagRow( $tag, $hitcount ) {
- static $doneTags = array();
-
- if ( in_array( $tag, $doneTags ) ) {
- return '';
- }
-
$user = $this->getUser();
$newRow = '';
$newRow .= Xml::tags( 'td', null, Xml::element( 'code', null,
$tag ) );
@@ -93,8 +80,6 @@
$hitcountLink = Linker::link( SpecialPage::getTitleFor(
'Recentchanges' ), $hitcountLabel, array(), array( 'tagfilter' => $tag ) );
// add raw $hitcount for sorting, because tags-hitcount
contains numbers and letters
$newRow .= Xml::tags( 'td', array( 'data-sort-value' =>
$hitcount ), $hitcountLink );
-
- $doneTags[] = $tag;
return Xml::tags( 'tr', null, $newRow ) . "\n";
}
--
To view, visit https://gerrit.wikimedia.org/r/81221
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I85b6854e26ffc656b990079d463a085ba39556df
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz DziewoĆski <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits