Remove deprecated functions from ChangeTags class
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 95848ea..5b6088d 100644 (file)
@@ -181,6 +181,28 @@ class ChangeTags {
                return $msg;
        }
 
+       /**
+        * Get truncated message for the tag's long description.
+        *
+        * @param string $tag Tag name.
+        * @param int $length Maximum length of truncated message, including ellipsis.
+        * @param IContextSource $context
+        *
+        * @return string Truncated long tag description.
+        */
+       public static function truncateTagDescription( $tag, $length, IContextSource $context ) {
+               $originalDesc = self::tagLongDescriptionMessage( $tag, $context );
+               // If there is no tag description, return empty string
+               if ( !$originalDesc ) {
+                       return '';
+               }
+
+               $taglessDesc = Sanitizer::stripAllTags( $originalDesc->parse() );
+               $escapedDesc = Sanitizer::escapeHtmlAllowEntities( $taglessDesc );
+
+               return $context->getLanguage()->truncateForVisual( $escapedDesc, $length );
+       }
+
        /**
         * Add tags to a change given its rc_id, rev_id and/or log_id
         *
@@ -408,19 +430,24 @@ class ChangeTags {
                sort( $prevTags );
                sort( $newTags );
                if ( $prevTags == $newTags ) {
-                       // No change.
                        return false;
                }
 
                if ( !$newTags ) {
-                       // no tags left, so delete the row altogether
+                       // No tags left, so delete the row altogether
                        $dbw->delete( 'tag_summary', $tsConds, __METHOD__ );
                } else {
-                       $dbw->replace( 'tag_summary',
-                               [ 'ts_rev_id', 'ts_rc_id', 'ts_log_id' ],
-                               array_filter( array_merge( $tsConds, [ 'ts_tags' => implode( ',', $newTags ) ] ) ),
-                               __METHOD__
-                       );
+                       // Specify the non-DEFAULT value columns in the INSERT/REPLACE clause
+                       $row = array_filter( [ 'ts_tags' => implode( ',', $newTags ) ] + $tsConds );
+                       // Check the unique keys for conflicts, ignoring any NULL *_id values
+                       $uniqueKeys = [];
+                       foreach ( [ 'ts_rev_id', 'ts_rc_id', 'ts_log_id' ] as $uniqueColumn ) {
+                               if ( isset( $row[$uniqueColumn] ) ) {
+                                       $uniqueKeys[] = [ $uniqueColumn ];
+                               }
+                       }
+
+                       $dbw->replace( 'tag_summary', $uniqueKeys, $row, __METHOD__ );
                }
 
                return true;
@@ -1268,20 +1295,9 @@ class ChangeTags {
                );
        }
 
-       /**
-        * @see listSoftwareActivatedTags
-        * @deprecated since 1.28 call listSoftwareActivatedTags directly
-        * @return array
-        */
-       public static function listExtensionActivatedTags() {
-               wfDeprecated( __METHOD__, '1.28' );
-               return self::listSoftwareActivatedTags();
-       }
-
        /**
         * Basically lists defined tags which count even if they aren't applied to anything.
-        * It returns a union of the results of listExplicitlyDefinedTags() and
-        * listExtensionDefinedTags().
+        * It returns a union of the results of listExplicitlyDefinedTags()
         *
         * @return string[] Array of strings: tags
         */
@@ -1358,18 +1374,6 @@ class ChangeTags {
                );
        }
 
-       /**
-        * Call listSoftwareDefinedTags directly
-        *
-        * @see listSoftwareDefinedTags
-        * @deprecated since 1.28
-        * @return array
-        */
-       public static function listExtensionDefinedTags() {
-               wfDeprecated( __METHOD__, '1.28' );
-               return self::listSoftwareDefinedTags();
-       }
-
        /**
         * Invalidates the short-term cache of defined tags used by the
         * list*DefinedTags functions, as well as the tag statistics cache.