Matmarex has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80781


Change subject: Add a dropdown list for the tag selector
......................................................................

Add a dropdown list for the tag selector

* Factor out a new method, ChangeTags::tagUsageStatistics(), from
  SpecialTags. Use it there.
* Change ChangeTags::buildTagFilterSelector() to output a <select>
  list instead of an <input>.

Bug: 25909
Change-Id: I34aa2bab5f8db5eed3dbd2826532f2d724fdea30
---
M includes/ChangeTags.php
M includes/specials/SpecialTags.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
5 files changed, 46 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/81/80781/1

diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php
index 029911f..5184dd9 100644
--- a/includes/ChangeTags.php
+++ b/includes/ChangeTags.php
@@ -231,8 +231,18 @@
                        return $fullForm ? '' : array();
                }
 
-               $data = array( Html::rawElement( 'label', array( 'for' => 
'tagfilter' ), wfMessage( 'tag-filter' )->parse() ),
-                       Xml::input( 'tagfilter', 20, $selected, array( 'class' 
=> 'mw-tagfilter-input' ) ) );
+               $select = new XmlSelect( 'tagfilter', false, $selected );
+               $select->addOption( wfMessage( 'tag-filter-none' )->text(), '' 
);
+               foreach ( self::tagUsageStatistics() as $tag => $unused ) {
+                       // Can't use self::tagDescription because it returns 
HTML
+                       $select->addOption( $tag );
+               }
+               $select->setAttribute( 'class', 'mw-tagfilter-input' );
+
+               $data = array(
+                       Html::rawElement( 'label', array( 'for' => 'tagfilter' 
), wfMessage( 'tag-filter' )->parse() ),
+                       $select->getHTML()
+               );
 
                if ( !$fullForm ) {
                        return $data;
@@ -281,4 +291,33 @@
                $wgMemc->set( $key, $emptyTags, 300 );
                return $emptyTags;
        }
+
+       /**
+        * Returns a map of valid tags 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";
        }
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 8834078..1ea97ca 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -4928,6 +4928,7 @@
 'tags'                    => 'Valid change tags',
 'tags-summary'            => '', # do not translate or duplicate this message 
to other languages
 'tag-filter'              => '[[Special:Tags|Tag]] filter:',
+'tag-filter-none'         => '(none)',
 'tag-filter-submit'       => 'Filter',
 'tag-list-wrapper'        => '([[Special:Tags|{{PLURAL:$1|Tag|Tags}}]]: $2)',
 'tags-title'              => 'Tags',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index fa3d317..a04ef0a 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -9524,6 +9524,7 @@
 
 It appears that the word 'valid' describes 'tags', not 'change'. It also 
appears that you could use the term 'defined' instead of 'valid', or perhaps 
use a phrase meaning 'Change tags in use'.",
 'tag-filter' => 'Caption of a filter shown on lists of changes (e.g. 
[[Special:Log]], [[Special:Contributions]], [[Special:Newpages]], 
[[Special:Recentchanges]], [[Special:Recentchangeslinked]], page histories)',
+'tag-filter-none' => 'First element of dropdown list of tags, to indicate that 
no tag is selected.',
 'tag-filter-submit' => 'Caption of the submit button displayed next to the tag 
filter on lists of changes (e.g. [[Special:Log]], [[Special:Contributions]], 
[[Special:Newpages]], [[Special:Recentchanges]], 
[[Special:Recentchangeslinked]], page histories)
 
 {{Identical|Filter}}',
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 68b2d17..bf603b6 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -3760,6 +3760,7 @@
                'tags',
                'tags-summary',
                'tag-filter',
+               'tag-filter-none',
                'tag-filter-submit',
                'tag-list-wrapper',
                'tags-title',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34aa2bab5f8db5eed3dbd2826532f2d724fdea30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Matmarex <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to