(bug 18487) Another fix for r48379: move up getMemcKey() as well
[lhc/web/wiklou.git] / includes / ChangeTags.php
index f83edbf..de804c5 100644 (file)
@@ -90,8 +90,9 @@ class ChangeTags {
         * Handles selecting tags, and filtering.
         * Needs $tables to be set up properly, so we can figure out which join conditions to use.
        */
-       static function modifyDisplayQuery( &$tables, &$fields,  &$conds, &$join_conds, $filter_tag = false ) {
-               global $wgRequest;
+       static function modifyDisplayQuery( &$tables, &$fields,  &$conds,
+                                                                               &$join_conds, &$options, $filter_tag = false ) {
+               global $wgRequest, $wgUseTagFilter;
                
                if ($filter_tag === false) {
                        $filter_tag = $wgRequest->getVal( 'tagfilter' );
@@ -114,10 +115,13 @@ class ChangeTags {
                $join_conds['tag_summary'] = array( 'LEFT JOIN', "ts_$join_cond=$join_cond" );
                $fields[] = 'ts_tags';
                
-               if ($filter_tag) {
+               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;
@@ -129,6 +133,11 @@ class ChangeTags {
         * If $fullForm is true, it returns an entire form.
         */
        static function buildTagFilterSelector( $selected='', $fullForm = false /* used to put a full form around the selector */ ) {
+               global $wgUseTagFilter;
+               
+               if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) )
+                       return $fullForm ? '' : array();
+       
                global $wgTitle;
                
                $data = array( wfMsgExt( 'tag-filter', 'parseinline' ), Xml::input( 'tagfilter', 20, $selected ) );
@@ -147,6 +156,13 @@ class ChangeTags {
 
        /** Basically lists defined tags which count even if they aren't applied to anything */
        static function listDefinedTags() {
+               // Caching...
+               global $wgMemc;
+               $key = wfMemcKey( 'valid-tags' );
+
+               if ($tags = $wgMemc->get( $key ))
+                       return $tags;
+       
                $emptyTags = array();
 
                // Some DB stuff
@@ -158,6 +174,10 @@ class ChangeTags {
                
                wfRunHooks( 'ListDefinedTags', array(&$emptyTags) );
 
-               return array_filter( array_unique( $emptyTags ) );
+               $emptyTags = array_filter( array_unique( $emptyTags ) );
+
+               // Short-term caching.
+               $wgMemc->set( $key, $emptyTags, 300 );
+               return $emptyTags;
        }
-}
\ No newline at end of file
+}