Merge "Localisation updates from https://translatewiki.net."
[lhc/web/wiklou.git] / includes / ChangeTags.php
index 029911f..fd94bea 100644 (file)
@@ -193,18 +193,14 @@ class ChangeTags {
                        throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
                }
 
-               // JOIN on tag_summary
-               $tables[] = 'tag_summary';
-               $join_conds['tag_summary'] = array( 'LEFT JOIN', "ts_$join_cond=$join_cond" );
-               $fields[] = 'ts_tags';
+               $fields['ts_tags'] = wfGetDB( DB_SLAVE )->buildGroupConcatField(
+                       ',', 'change_tag', 'ct_tag', "ct_$join_cond=$join_cond"
+               );
 
                if ( $wgUseTagFilter && $filter_tag ) {
                        // Somebody wants to filter on a tag.
                        // Add an INNER JOIN on change_tag
 
-                       // FORCE INDEX -- change_tags will almost ALWAYS be the correct query plan.
-                       $options['USE INDEX'] = array( 'change_tag' => 'change_tag_tag_id' );
-                       unset( $options['FORCE INDEX'] );
                        $tables[] = 'change_tag';
                        $join_conds['change_tag'] = array( 'INNER JOIN', "ct_$join_cond=$join_cond" );
                        $conds['ct_tag'] = $filter_tag;
@@ -232,7 +228,7 @@ class ChangeTags {
                }
 
                $data = array( Html::rawElement( 'label', array( 'for' => 'tagfilter' ), wfMessage( 'tag-filter' )->parse() ),
-                       Xml::input( 'tagfilter', 20, $selected, array( 'class' => 'mw-tagfilter-input' ) ) );
+                       Xml::input( 'tagfilter', 20, $selected, array( 'class' => 'mw-tagfilter-input', 'id' => 'tagfilter' ) ) );
 
                if ( !$fullForm ) {
                        return $data;
@@ -281,4 +277,34 @@ class ChangeTags {
                $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;
+       }
 }