From dc77abf2864bfd00a75c7fa5aae739fa8e4228e2 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 30 Jan 2009 23:24:29 +0000 Subject: [PATCH] Don't show tag filter boxes if no tags are defined. To support this change without bringing down servers, cache the list of valid tags in the object cache. --- includes/ChangeTags.php | 17 ++++++++++++++++- includes/LogEventsList.php | 4 +++- includes/PageHistory.php | 3 ++- includes/specials/SpecialContributions.php | 8 +++----- includes/specials/SpecialNewpages.php | 8 +++++--- includes/specials/SpecialRecentchanges.php | 4 +++- .../specials/SpecialRecentchangeslinked.php | 4 +++- 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php index f83edbf3da..cbbe67ef8a 100644 --- a/includes/ChangeTags.php +++ b/includes/ChangeTags.php @@ -129,6 +129,10 @@ 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 */ ) { + + if ( !count( self::listDefinedTags() ) ) + return $fullForm ? '' : array(); + global $wgTitle; $data = array( wfMsgExt( 'tag-filter', 'parseinline' ), Xml::input( 'tagfilter', 20, $selected ) ); @@ -147,6 +151,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 +169,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 diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 1cae3c7946..c8ddd07092 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -75,6 +75,8 @@ class LogEventsList { $title = SpecialPage::getTitleFor( 'Log' ); $special = htmlspecialchars( $title->getPrefixedDBkey() ); + $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); + $this->out->addHTML( "
" . Xml::element( 'legend', array(), wfMsg( 'log' ) ) . Xml::hidden( 'title', $special ) . "\n" . @@ -83,7 +85,7 @@ class LogEventsList { $this->getTitleInput( $page ) . "\n" . ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) . "

" . $this->getDateMenu( $year, $month ) . "\n" . - Xml::tags( 'p', null, implode( ' ', ChangeTags::buildTagFilterSelector( $tagFilter ) ) ) . "\n" . + ( $tagSelector ? Xml::tags( 'p', null, implode( ' ', $tagSelector ) ) :'' ). "\n" . ( $filter ? "

".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "

\n" . "
" diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 0441cf2d52..f1e23e31b6 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -113,6 +113,7 @@ class PageHistory { $year = $wgRequest->getInt( 'year' ); $month = $wgRequest->getInt( 'month' ); $tagFilter = $wgRequest->getVal( 'tagfilter' ); + $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); $action = htmlspecialchars( $wgScript ); $wgOut->addHTML( @@ -121,7 +122,7 @@ class PageHistory { Xml::hidden( 'title', $this->mTitle->getPrefixedDBKey() ) . "\n" . Xml::hidden( 'action', 'history' ) . "\n" . $this->getDateMenu( $year, $month ) . ' ' . - implode( ' ', ChangeTags::buildTagFilterSelector( $tagFilter ) ) . ' ' . + ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . '' ); diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index aa4187c058..3ce55223f6 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -233,10 +233,6 @@ class SpecialContributions extends SpecialPage { if( !isset( $this->opts['month'] ) ) { $this->opts['month'] = ''; } - - if( !isset( $this->opts['tagfilter'] ) ) { - $this->opts['tagfilter'] = ''; - } if( $this->opts['contribs'] == 'newbie' ) { $this->opts['target'] = ''; @@ -250,6 +246,8 @@ class SpecialContributions extends SpecialPage { } $f .= "\t" . Xml::hidden( $name, $value ) . "\n"; } + + $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); $f .= '
' . Xml::element( 'legend', array(), wfMsg( 'sp-contributions-search' ) ) . @@ -262,7 +260,7 @@ class SpecialContributions extends SpecialPage { Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' . Xml::namespaceSelector( $this->opts['namespace'], '' ) . '' . - Xml::tags( 'p', null, implode( ' ', ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ) ) ) . + ( $tagFilter ? Xml::tags( 'p', null, implode( ' ', $tagFilter ) ) : '' ) . Xml::openElement( 'p' ) . '' . Xml::label( wfMsg( 'year' ), 'year' ) . ' '. diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index 6f1a69c8ce..597d43a674 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -177,7 +177,9 @@ class SpecialNewpages extends SpecialPage { } $hidden = implode( "\n", $hidden ); - list( $tagFilterLabel, $tagFilterSelector ) = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); + $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); + if ($tagFilter) + list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter; $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . @@ -190,7 +192,7 @@ class SpecialNewpages extends SpecialPage { " . Xml::namespaceSelector( $namespace, 'all' ) . " - " . + " . ( $tagFilter ? ( " " . $tagFilterLabel . @@ -198,7 +200,7 @@ class SpecialNewpages extends SpecialPage { " . $tagFilterSelector . " - " . + " ) : '' ) . ($wgEnableNewpagesUserFilter ? " " . diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 9d91a4a452..79f00bc90f 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -462,7 +462,9 @@ class SpecialRecentChanges extends SpecialPage { $extraOpts['category'] = $this->categoryFilterForm( $opts ); } - $extraOpts['tagfilter'] = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); + $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); + if ( count($tagFilter) ) + $extraOpts['tagfilter'] = $tagFilter; wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) ); return $extraOpts; diff --git a/includes/specials/SpecialRecentchangeslinked.php b/includes/specials/SpecialRecentchangeslinked.php index fb7eb3a641..1812eb6836 100644 --- a/includes/specials/SpecialRecentchangeslinked.php +++ b/includes/specials/SpecialRecentchangeslinked.php @@ -172,7 +172,9 @@ class SpecialRecentchangeslinked extends SpecialRecentchanges { Xml::input( 'target', 40, str_replace('_',' ',$opts['target']) ) . Xml::check( 'showlinkedto', $opts['showlinkedto'], array('id' => 'showlinkedto') ) . ' ' . Xml::label( wfMsg("recentchangeslinked-to"), 'showlinkedto' ) ); - $extraOpts['tagfilter'] = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); + $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); + if ($tagFilter) + $extraOpts['tagfilter'] = $tagFilter; return $extraOpts; } -- 2.20.1