Merge "Add version to ChronologyProtector key"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 993f0b7..d2239eb 100644 (file)
@@ -397,7 +397,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'applychangetags' ) ) {
                                return Status::newFatal( 'tags-apply-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-apply-blocked' );
+                               return Status::newFatal( 'tags-apply-blocked', $user->getName() );
                        }
                }
 
@@ -468,7 +468,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'changetags' ) ) {
                                return Status::newFatal( 'tags-update-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-update-blocked' );
+                               return Status::newFatal( 'tags-update-blocked', $user->getName() );
                        }
                }
 
@@ -668,12 +668,20 @@ class ChangeTags {
         * @param string $selected Tag to select by default
         * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
         *        You need to call OutputPage::enableOOUI() yourself.
+        * @param IContextSource|null $context
+        * @note Even though it takes null as a valid argument, an IContextSource is preferred
+        *       in a new code, as the null value can change in the future
         * @return array an array of (label, selector)
         */
-       public static function buildTagFilterSelector( $selected = '', $ooui = false ) {
-               global $wgUseTagFilter;
+       public static function buildTagFilterSelector(
+               $selected = '', $ooui = false, IContextSource $context = null
+       ) {
+               if ( !$context ) {
+                       $context = RequestContext::getMain();
+               }
 
-               if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) ) {
+               $config = $context->getConfig();
+               if ( !$config->get( 'UseTagFilter' ) || !count( self::listDefinedTags() ) ) {
                        return [];
                }
 
@@ -681,7 +689,7 @@ class ChangeTags {
                        Html::rawElement(
                                'label',
                                [ 'for' => 'tagfilter' ],
-                               wfMessage( 'tag-filter' )->parse()
+                               $context->msg( 'tag-filter' )->parse()
                        )
                ];
 
@@ -749,11 +757,13 @@ class ChangeTags {
         * @param User $user Who to attribute the action to
         * @param int $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
         * @return int ID of the inserted log entry
         * @since 1.25
         */
        protected static function logTagManagementAction( $action, $tag, $reason,
-               User $user, $tagCount = null ) {
+               User $user, $tagCount = null, array $logEntryTags = [] ) {
 
                $dbw = wfGetDB( DB_MASTER );
 
@@ -770,6 +780,7 @@ class ChangeTags {
                }
                $logEntry->setParameters( $params );
                $logEntry->setRelations( [ 'Tag' => $tag ] );
+               $logEntry->setTags( $logEntryTags );
 
                $logId = $logEntry->insert( $dbw );
                $logEntry->publish( $logId );
@@ -790,7 +801,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'managechangetags' ) ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-manage-blocked' );
+                               return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
 
@@ -822,12 +833,14 @@ class ChangeTags {
         * @param string $reason
         * @param User $user Who to give credit for the action
         * @param bool $ignoreWarnings Can be used for API interaction, default false
+        * @param array $logEntryTags Change tags to apply to the entry
+        * that will be created in the tag management log
         * @return Status If successful, the Status contains the ID of the added log
         * entry as its value
         * @since 1.25
         */
        public static function activateTagWithChecks( $tag, $reason, User $user,
-               $ignoreWarnings = false ) {
+               $ignoreWarnings = false, array $logEntryTags = [] ) {
 
                // are we allowed to do this?
                $result = self::canActivateTag( $tag, $user );
@@ -840,7 +853,9 @@ class ChangeTags {
                self::defineTag( $tag );
 
                // log it
-               $logId = self::logTagManagementAction( 'activate', $tag, $reason, $user );
+               $logId = self::logTagManagementAction( 'activate', $tag, $reason, $user,
+                       null, $logEntryTags );
+
                return Status::newGood( $logId );
        }
 
@@ -858,7 +873,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'managechangetags' ) ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-manage-blocked' );
+                               return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
 
@@ -881,12 +896,14 @@ class ChangeTags {
         * @param string $reason
         * @param User $user Who to give credit for the action
         * @param bool $ignoreWarnings Can be used for API interaction, default false
+        * @param array $logEntryTags Change tags to apply to the entry
+        * that will be created in the tag management log
         * @return Status If successful, the Status contains the ID of the added log
         * entry as its value
         * @since 1.25
         */
        public static function deactivateTagWithChecks( $tag, $reason, User $user,
-               $ignoreWarnings = false ) {
+               $ignoreWarnings = false, array $logEntryTags = [] ) {
 
                // are we allowed to do this?
                $result = self::canDeactivateTag( $tag, $user );
@@ -899,7 +916,9 @@ class ChangeTags {
                self::undefineTag( $tag );
 
                // log it
-               $logId = self::logTagManagementAction( 'deactivate', $tag, $reason, $user );
+               $logId = self::logTagManagementAction( 'deactivate', $tag, $reason, $user,
+                       null, $logEntryTags );
+
                return Status::newGood( $logId );
        }
 
@@ -917,7 +936,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'managechangetags' ) ) {
                                return Status::newFatal( 'tags-manage-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-manage-blocked' );
+                               return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
 
@@ -960,12 +979,14 @@ class ChangeTags {
         * @param string $reason
         * @param User $user Who to give credit for the action
         * @param bool $ignoreWarnings Can be used for API interaction, default false
+        * @param array $logEntryTags Change tags to apply to the entry
+        * that will be created in the tag management log
         * @return Status If successful, the Status contains the ID of the added log
         * entry as its value
         * @since 1.25
         */
        public static function createTagWithChecks( $tag, $reason, User $user,
-               $ignoreWarnings = false ) {
+               $ignoreWarnings = false, array $logEntryTags = [] ) {
 
                // are we allowed to do this?
                $result = self::canCreateTag( $tag, $user );
@@ -978,7 +999,9 @@ class ChangeTags {
                self::defineTag( $tag );
 
                // log it
-               $logId = self::logTagManagementAction( 'create', $tag, $reason, $user );
+               $logId = self::logTagManagementAction( 'create', $tag, $reason, $user,
+                       null, $logEntryTags );
+
                return Status::newGood( $logId );
        }
 
@@ -1050,7 +1073,7 @@ class ChangeTags {
                        if ( !$user->isAllowed( 'deletechangetags' ) ) {
                                return Status::newFatal( 'tags-delete-no-permission' );
                        } elseif ( $user->isBlocked() ) {
-                               return Status::newFatal( 'tags-manage-blocked' );
+                               return Status::newFatal( 'tags-manage-blocked', $user->getName() );
                        }
                }
 
@@ -1087,12 +1110,14 @@ class ChangeTags {
         * @param string $reason
         * @param User $user Who to give credit for the action
         * @param bool $ignoreWarnings Can be used for API interaction, default false
+        * @param array $logEntryTags Change tags to apply to the entry
+        * that will be created in the tag management log
         * @return Status If successful, the Status contains the ID of the added log
         * entry as its value
         * @since 1.25
         */
        public static function deleteTagWithChecks( $tag, $reason, User $user,
-               $ignoreWarnings = false ) {
+               $ignoreWarnings = false, array $logEntryTags = [] ) {
 
                // are we allowed to do this?
                $result = self::canDeleteTag( $tag, $user );
@@ -1112,7 +1137,9 @@ class ChangeTags {
                }
 
                // log it
-               $logId = self::logTagManagementAction( 'delete', $tag, $reason, $user, $hitcount );
+               $logId = self::logTagManagementAction( 'delete', $tag, $reason, $user,
+                       $hitcount, $logEntryTags );
+
                $deleteResult->value = $logId;
                return $deleteResult;
        }