ChangeTag::createTagWithChecks calls ChangeTag::canCreateTag()
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 97f124b..dd29c10 100644 (file)
@@ -201,9 +201,8 @@ class ChangeTags {
                }
 
                $taglessDesc = Sanitizer::stripAllTags( $originalDesc->parse() );
-               $escapedDesc = Sanitizer::escapeHtmlAllowEntities( $taglessDesc );
 
-               return $context->getLanguage()->truncateForVisual( $escapedDesc, $length );
+               return $context->getLanguage()->truncateForVisual( $taglessDesc, $length );
        }
 
        /**
@@ -213,7 +212,7 @@ class ChangeTags {
         * @param int|null $rc_id The rc_id of the change to add the tags to
         * @param int|null $rev_id The rev_id of the change to add the tags to
         * @param int|null $log_id The log_id of the change to add the tags to
-        * @param string $params Params to put in the ct_params field of table 'change_tag'
+        * @param string|null $params Params to put in the ct_params field of table 'change_tag'
         * @param RecentChange|null $rc Recent change, in case the tagging accompanies the action
         * (this should normally be the case)
         *
@@ -244,7 +243,7 @@ class ChangeTags {
         * Pass a variable whose value is null if the rev_id is not relevant or unknown.
         * @param int|null &$log_id The log_id of the change to add the tags to.
         * Pass a variable whose value is null if the log_id is not relevant or unknown.
-        * @param string $params Params to put in the ct_params field of table
+        * @param string|null $params Params to put in the ct_params field of table
         * 'change_tag' when adding tags
         * @param RecentChange|null $rc Recent change being tagged, in case the tagging accompanies
         * the action
@@ -916,8 +915,8 @@ class ChangeTags {
                if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD ) {
                        $dbw->update(
                                'change_tag_def',
-                               [ 'ctd_name' => $tag ],
                                [ 'ctd_user_defined' => 0 ],
+                               [ 'ctd_name' => $tag ],
                                __METHOD__
                        );
 
@@ -941,7 +940,7 @@ class ChangeTags {
         * @param string $tag
         * @param string $reason
         * @param User $user Who to attribute the action to
-        * @param int $tagCount For deletion only, how many usages the tag had before
+        * @param int|null $tagCount For deletion only, how many usages the tag had before
         * it was deleted.
         * @param array $logEntryTags Change tags to apply to the entry
         * that will be created in the tag management log
@@ -1184,7 +1183,7 @@ class ChangeTags {
         * Extensions should NOT use this function; they can use the ListDefinedTags
         * hook instead.
         *
-        * Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to
+        * Includes a call to ChangeTag::canCreateTag(), so your code doesn't need to
         * do that.
         *
         * @param string $tag
@@ -1507,6 +1506,13 @@ class ChangeTags {
         * @return array Array of string => int
         */
        public static function tagUsageStatistics() {
+               global $wgChangeTagsSchemaMigrationStage, $wgTagStatisticsNewTable;
+               if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ||
+                       ( $wgTagStatisticsNewTable && $wgChangeTagsSchemaMigrationStage > MIGRATION_OLD )
+               ) {
+                       return self::newTagUsageStatistics();
+               }
+
                $fname = __METHOD__;
                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
@@ -1540,6 +1546,29 @@ class ChangeTags {
                );
        }
 
+       /**
+        * Same self::tagUsageStatistics() but uses change_tag_def.
+        *
+        * @return array Array of string => int
+        */
+       private static function newTagUsageStatistics() {
+               $dbr = wfGetDB( DB_REPLICA );
+               $res = $dbr->select(
+                       'change_tag_def',
+                       [ 'ctd_name', 'ctd_count' ],
+                       [],
+                       __METHOD__,
+                       [ 'ORDER BY' => 'ctd_count DESC' ]
+               );
+
+               $out = [];
+               foreach ( $res as $row ) {
+                       $out[$row->ctd_name] = $row->ctd_count;
+               }
+
+               return $out;
+       }
+
        /**
         * Indicate whether change tag editing UI is relevant
         *