From dd44f2dcedaad4743d304b33fba7a405d9f85b57 Mon Sep 17 00:00:00 2001 From: Rob Moen Date: Fri, 13 Jan 2012 21:24:38 +0000 Subject: [PATCH] patch from MrBlueSky, resloves bug 25909. Add dropdown list for tags in recent changes and new pages --- RELEASE-NOTES-1.19 | 1 + includes/ChangeTags.php | 46 +++++++++++++++++++++- includes/actions/HistoryAction.php | 24 +++++++++-- includes/specials/SpecialContributions.php | 10 ++++- includes/specials/SpecialNewpages.php | 14 +++++-- includes/specials/SpecialRecentchanges.php | 11 +++--- languages/messages/MessagesEn.php | 3 ++ languages/messages/MessagesQqq.php | 6 +++ 8 files changed, 100 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 4b005bd470..66e854f6b5 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -119,6 +119,7 @@ production. * mediawiki.js Message object constructor is now publicly available as mw.Message. * (bug 29309) allow CSS class per tooltip (tipsy) * (bug 33565) Add accesskey/tooltip to submit buttons on Special:EditWatchlist. +* (bug 25909) Add a drop-down list for the tags in Recentchanges and Newpages === Bug fixes in 1.19 === * $wgUploadNavigationUrl should be used for file redlinks if. diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php index c8e522dfec..97d12a4237 100644 --- a/includes/ChangeTags.php +++ b/includes/ChangeTags.php @@ -26,7 +26,7 @@ class ChangeTags { static function tagDescription( $tag ) { $msg = wfMessage( "tag-$tag" ); - return $msg->exists() ? $msg->parse() : htmlspecialchars( $tag ); + return $msg->exists() ? $msg->parse() : htmlspecialchars( $tag ); } ## Basic utility method to add tags to a particular change, given its rc_id, rev_id and/or log_id. @@ -109,7 +109,10 @@ class ChangeTags { global $wgRequest, $wgUseTagFilter; if( $filter_tag === false ) { - $filter_tag = $wgRequest->getVal( 'tagfilter' ); + $filter_tag = $wgRequest->getVal( 'tagfilterdropdown', '' ); + if ( $filter_tag === '' || $filter_tag === 'other' ) { + $filter_tag = $wgRequest->getVal( 'tagfilter' ); + } } // Figure out which conditions can be done. @@ -177,6 +180,45 @@ class ChangeTags { return $html; } + /** + * Build a text box and a dropdown list to select a change tag + * + * @param $msgkey String: message key for the message where a (newline delimited) + * list of tags can be specified. These tags will be put in the dropdown list. + * If the specified message is empty, only the text field will be returned. + * @param $selectedtxt String: tag to put in text box + * @param $selecteddropdown String: tag to select in dropdown + * @return Array of html fragments of which the first element is the label + * If $wgUseTagFilter is false or there are no defined tags, an empty array is returned + */ + public static function buildTagFilterWithDropdown( $msgkey, $selectedtxt = '', $selecteddropdown = 'other' ) { + + global $wgUseTagFilter; + + $definedtags = self::listDefinedTags(); + + if ( !$wgUseTagFilter || !count( $definedtags ) ) { + // no tag filter if there are no tags defined or $wgUseTagFilter is false + return array(); + } + + // Extract tags from message: one tag per line + $tags = preg_split( "/\n/", wfMsgForContent( $msgkey ), -1, PREG_SPLIT_NO_EMPTY); + + $data[] = Html::rawElement( 'label', array( 'for' => 'tagfilter' ), wfMsgExt( 'tag-filter', 'parseinline' ) ); + + if ( count( $tags ) ) { + // Add dropdown list only when message $msgkey contains at least one tag + $data[] = Xml::listDropDown( 'tagfilterdropdown', implode( "\n", $tags ), + wfMsgForContent( 'tag-filter-dropdown-other' ), $selecteddropdown ); + } + + $data[] = Xml::input( 'tagfilter', 20, $selectedtxt ); + + return $data; + + } + /** *Basically lists defined tags which count even if they aren't applied to anything * diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index c463eed248..29b4eb93db 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -136,7 +136,13 @@ class HistoryAction extends FormlessAction { $year = $request->getInt( 'year' ); $month = $request->getInt( 'month' ); $tagFilter = $request->getVal( 'tagfilter' ); - $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); + $tagFilterDropdown = $request->getVal( 'tagfilterdropdown' ); + $tagSelector = ChangeTags::buildTagFilterWithDropdown( + 'tag-filter-dropdown-list', + $tagFilter, + $tagFilterDropdown + ); + $tagSelector = implode( ' ', $tagSelector ); /** * Option to show only revisions that have been (partially) hidden via RevisionDelete @@ -161,14 +167,26 @@ class HistoryAction extends FormlessAction { Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() ) . "\n" . Html::hidden( 'action', 'history' ) . "\n" . Xml::dateMenu( $year, $month ) . ' ' . - ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . - $checkDeleted . + Html::rawElement( + 'span', + array( 'style' => 'white-space: nowrap' ), + ( $tagSelector ? ( $tagSelector . ' ' ) : '' ) + ) . + Html::rawElement( + 'span', + array( 'style' => 'white-space: nowrap' ), + $checkDeleted + ) . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" . '' ); wfRunHooks( 'PageHistoryBeforeList', array( &$this->page ) ); + if ( $tagFilterDropdown !== '' && $tagFilterDropdown !== 'other' ) { + $tagFilter = $tagFilterDropdown; + } + // Create and output the list. $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds ); $out->addHTML( diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 865295bfff..a0482045e6 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -103,6 +103,7 @@ class SpecialContributions extends SpecialPage { $this->opts['nsInvert'] = (bool) $request->getVal( 'nsInvert' ); $this->opts['tagfilter'] = (string) $request->getVal( 'tagfilter' ); + $this->opts['tagfilterdropdown'] = (string) $request->getVal( 'tagfilterdropdown' ); // Allows reverts to have the bot flag in recent changes. It is just here to // be passed in the form at the top of the page @@ -138,6 +139,9 @@ class SpecialContributions extends SpecialPage { if ( $this->opts['tagfilter'] !== '' ) { $apiParams['tagfilter'] = $this->opts['tagfilter']; } + if ( $this->opts['tagfilterdropdown'] !== '' && $this->opts['tagfilterdropdown'] !== 'other' ) { + $apiParams['tagfilter'] = $this->opts['tagfilterdropdown']; + } if ( $this->opts['namespace'] !== '' ) { $apiParams['namespace'] = $this->opts['namespace']; } @@ -399,7 +403,11 @@ class SpecialContributions extends SpecialPage { $form .= "\t" . Html::hidden( $name, $value ) . "\n"; } - $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); + $tagFilter = ChangeTags::buildTagFilterWithDropdown( + 'tag-filter-dropdown-list', + $this->opts['tagfilter'], + $this->opts['tagfilterdropdown'] + ); if ( $tagFilter ) { $filterSelection = diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index ecec87de53..8fa0501835 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -59,6 +59,7 @@ class SpecialNewpages extends IncludableSpecialPage { $opts->add( 'username', '' ); $opts->add( 'feed', '' ); $opts->add( 'tagfilter', '' ); + $opts->add( 'tagfilterdropdown', '' ); $this->customFilters = array(); wfRunHooks( 'SpecialNewPagesFilters', array( $this, &$this->customFilters ) ); @@ -211,6 +212,7 @@ class SpecialNewpages extends IncludableSpecialPage { $namespace = $this->opts->consumeValue( 'namespace' ); $username = $this->opts->consumeValue( 'username' ); $tagFilterVal = $this->opts->consumeValue( 'tagfilter' ); + $tagFilterDropdownVal = $this->opts->consumeValue( 'tagfilterdropdown' ); // Check username input validity $ut = Title::makeTitleSafe( NS_USER, $username ); @@ -223,9 +225,14 @@ class SpecialNewpages extends IncludableSpecialPage { } $hidden = implode( "\n", $hidden ); - $tagFilter = ChangeTags::buildTagFilterSelector( $tagFilterVal ); + $tagFilter = ChangeTags::buildTagFilterWithDropdown( + 'tag-filter-newpages-dropdown-list', + $tagFilterVal, + $tagFilterDropdownVal + ); if ( $tagFilter ) { - list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter; + $tagFilterLabel = array_shift( $tagFilter ); + $tagFilterSelector = implode( ' ', $tagFilter ); } $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) . @@ -533,8 +540,7 @@ class NewPagesPager extends ReverseChronologicalPager { $fields, $info['conds'], $info['join_conds'], - $info['options'], - $this->opts['tagfilter'] + $info['options'] ); return $info; diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 067a95644f..19c1bd93f5 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -60,6 +60,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $opts->add( 'categories', '' ); $opts->add( 'categories_any', false ); $opts->add( 'tagfilter', '' ); + $opts->add( 'tagfilterdropdown', '' ); return $opts; } @@ -400,8 +401,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { // Tag stuff. // Doesn't work when transcluding. See bug 23293 ChangeTags::modifyDisplayQuery( - $tables, $fields, $conds, $join_conds, $query_options, - $opts['tagfilter'] + $tables, $fields, $conds, $join_conds, $query_options ); } @@ -554,7 +554,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $nondefaults = $opts->getChangedValues(); $opts->consumeValues( array( 'namespace', 'invert', 'associated', 'tagfilter', - 'categories', 'categories_any' + 'categories', 'categories_any', 'tagfilterdropdown' ) ); $panel = array(); @@ -616,9 +616,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { $extraOpts['category'] = $this->categoryFilterForm( $opts ); } - $tagFilter = ChangeTags::buildTagFilterSelector( $opts['tagfilter'] ); + $tagFilter = ChangeTags::buildTagFilterWithDropdown( 'tag-filter-dropdown-list', + $opts['tagfilter'], $opts['tagfilterdropdown'] ); if ( count( $tagFilter ) ) { - $extraOpts['tagfilter'] = $tagFilter; + $extraOpts['tagfilter'] = implode( ' ', $tagFilter ); } wfRunHooks( 'SpecialRecentChangesPanel', array( &$extraOpts, $opts ) ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 2309e2c2d7..a4ba0ce3a7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -4634,6 +4634,9 @@ Images are shown in full resolution, other file types are started with their ass 'tags-hitcount-header' => 'Tagged changes', 'tags-edit' => 'edit', 'tags-hitcount' => '$1 {{PLURAL:$1|change|changes}}', +'tag-filter-dropdown-other' => 'Other:', +'tag-filter-dropdown-list' => '', +'tag-filter-newpages-dropdown-list' => '', # Special:ComparePages 'comparepages' => 'Compare pages', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index c1e574454c..afe8df16f8 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -4428,6 +4428,12 @@ Used on [[Special:Tags]]. Verb. Used as display text on a link to create/edit a 'tags-hitcount' => 'Shown in the “Tagged changes” column in [[Special:Tags]]. For more information on tags see [//www.mediawiki.org/wiki/Manual:Tags Mediawiki]. * $1 is the number of changes marked with the tag', +'tag-filter-dropdown-list' => 'A list of change tags to put in a dropdown list for selecting a tag to filter by.', +'tag-filter-newpages-dropdown-list' => 'A list of change tags to put in a dropdown list for selecting a tag to filter by on [[Special:NewPages]].', +'tag-filter-dropdown-other' => 'The "other" option in the dropdown list for selecting a tag to filter by. When a user selects this, he can type any tag in the text field next to it. + +{{Identical|Other}} +', # Special:ComparePages 'comparepages' => 'The title of [[Special:ComparePages]]', -- 2.20.1