ChangeTags: Hide tags whose description messages are disabled
authorOri Livneh <ori@wikimedia.org>
Sun, 9 Nov 2014 03:13:05 +0000 (19:13 -0800)
committerKrinkle <krinklemail@gmail.com>
Thu, 16 Apr 2015 01:14:03 +0000 (01:14 +0000)
If an interface message describing the given tag exists, check if it has been
disabled. If so, take that as an indication that the tag should not be
displayed.

This amounts to an adequate (if somewhat low-level) interface for managing
which edit tags are shown in change list views like Special:RecentChanges and
Special:Contributions.

This patch is based on a suggestion made by jackmcbarn in a review comment on
commit 494989772cf. I did it in a separate change because I'd be interested in
hiding the HHVM tag even if we end up deciding against a generic mechanism for
hiding tags.

Change-Id: I515cf2118ab929da985d6b40481325640e800dcd

RELEASE-NOTES-1.26
includes/ChangeTags.php

index 46509be..89dad11 100644 (file)
@@ -11,12 +11,16 @@ production.
 === Configuration changes in 1.26 ===
 
 === New features in 1.26 ===
+* Change tags can now be hidden in the interface by disabling the associated
+  "tag-<id>" interface message.
 
 ==== External libraries ====
 
 === Bug fixes in 1.26 ===
 
 === Action API changes in 1.26 ===
+* API action=query&list=tags: The displayname can now be boolean false if the
+  tag is meant to be hidden from user interfaces.
 
 === Action API internal changes in 1.26 ===
 
@@ -28,7 +32,8 @@ changes to languages because of Bugzilla reports.
 
 
 === Other changes in 1.26 ===
-
+* ChangeTags::tagDescription() will return false if the interface message
+  for the tag is disabled.
 
 == Compatibility ==
 
index 3103edd..e2ef75e 100644 (file)
@@ -51,14 +51,26 @@ class ChangeTags {
                $tags = explode( ',', $tags );
                $displayTags = array();
                foreach ( $tags as $tag ) {
+                       if ( !$tag ) {
+                               continue;
+                       }
+                       $description = self::tagDescription( $tag );
+                       if ( $description === false ) {
+                               continue;
+                       }
                        $displayTags[] = Xml::tags(
                                'span',
                                array( 'class' => 'mw-tag-marker ' .
                                                                Sanitizer::escapeClass( "mw-tag-marker-$tag" ) ),
-                               self::tagDescription( $tag )
+                               $description
                        );
                        $classes[] = Sanitizer::escapeClass( "mw-tag-$tag" );
                }
+
+               if ( !$displayTags ) {
+                       return array( '', array() );
+               }
+
                $markers = wfMessage( 'tag-list-wrapper' )
                        ->numParams( count( $displayTags ) )
                        ->rawParams( $wgLang->commaList( $displayTags ) )
@@ -69,16 +81,30 @@ class ChangeTags {
        }
 
        /**
-        * Get a short description for a tag
+        * Get a short description for a tag.
         *
-        * @param string $tag Tag
+        * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
+        * returns the HTML-escaped tag name. Uses the message if the message
+        * exists, provided it is not disabled. If the message is disabled,
+        * we consider the tag hidden, and return false.
         *
-        * @return string Short description of the tag from "mediawiki:tag-$tag" if this message exists,
-        *   html-escaped version of $tag otherwise
+        * @param string $tag Tag
+        * @return string|bool Tag description or false if tag is to be hidden.
+        * @since 1.25 Returns false if tag is to be hidden.
         */
        public static function tagDescription( $tag ) {
                $msg = wfMessage( "tag-$tag" );
-               return $msg->exists() ? $msg->parse() : htmlspecialchars( $tag );
+               if ( !$msg->exists() ) {
+                       // No such message, so return the HTML-escaped tag name.
+                       return htmlspecialchars( $tag );
+               }
+               if ( $msg->isDisabled() ) {
+                       // The message exists but is disabled, hide the tag.
+                       return false;
+               }
+
+               // Message exists and isn't disabled, use it.
+               return $msg->parse();
        }
 
        /**