(bug 19004) Added support for tags to the API. Patch by Matthew Britton.
[lhc/web/wiklou.git] / includes / ChangeTags.php
index 23329c4..25c68df 100644 (file)
@@ -14,7 +14,8 @@ class ChangeTags {
                $displayTags = array();
                foreach( $tags as $tag ) {
                        $displayTags[] = Xml::tags( 'span',
-                                                               array( 'class' => "mw-tag-marker mw-tag-marker-$tag" ),
+                                                               array( 'class' => "mw-tag-marker ".
+                                                                                       Sanitizer::escapeClass("mw-tag-marker-$tag") ),
                                                                self::tagDescription( $tag ) );
                        $classes[] = Sanitizer::escapeClass( "mw-tag-$tag" );
                }
@@ -184,4 +185,35 @@ class ChangeTags {
                $wgMemc->set( $key, $emptyTags, 300 );
                return $emptyTags;
        }
+       
+       /** Returns associative array of tag names and hitcounts */
+       static function getHitCounts() {
+       
+               global $wgMemc;
+               $key = wfMemcKey( 'hitcounts' );
+               
+               if ($hitcounts = $wgMemc->get( $key ))
+                       return $hitcounts;
+               
+               $dbr = wfGetDB( DB_SLAVE );
+               $hitcounts = array();
+               
+               // Fetch defined tags
+               $res = $dbr->select( 'valid_tag', 'vt_tag', array(), __METHOD__ );
+               while( $row = $res->fetchObject() ) {
+                       $hitcounts[$row->vt_tag] = 0;
+               }
+               
+               // Fetch hit counts
+               $res = $dbr->select( 'change_tag', array('ct_tag', 'count(*) AS hitcount'),     array(), __METHOD__, array('GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC') );
+               
+               while( $row = $res->fetchObject() ) {
+                       $hitcounts[$row->ct_tag] = $row->hitcount;
+               }
+               
+               // Short-term caching
+               $wgMemc->set( $key, $hitcounts, 300 );
+               return $hitcounts;
+       }
+       
 }