Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 955e972..bfabd51 100644 (file)
@@ -63,7 +63,7 @@ class ChangeTags {
                        if ( !$tag ) {
                                continue;
                        }
-                       $description = self::tagDescription( $tag );
+                       $description = self::tagDescription( $tag, $context );
                        if ( $description === false ) {
                                continue;
                        }
@@ -98,11 +98,12 @@ class ChangeTags {
         * we consider the tag hidden, and return false.
         *
         * @param string $tag Tag
+        * @param IContextSource $context
         * @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" );
+       public static function tagDescription( $tag, IContextSource $context ) {
+               $msg = $context->msg( "tag-$tag" );
                if ( !$msg->exists() ) {
                        // No such message, so return the HTML-escaped tag name.
                        return htmlspecialchars( $tag );
@@ -124,14 +125,16 @@ class ChangeTags {
         * @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 RecentChange|null $rc Recent change, in case the tagging accompanies the action
+        * (this should normally be the case)
         *
         * @throws MWException
         * @return bool False if no changes are made, otherwise true
         */
        public static function addTags( $tags, $rc_id = null, $rev_id = null,
-               $log_id = null, $params = null
+               $log_id = null, $params = null, RecentChange $rc = null
        ) {
-               $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params );
+               $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params, $rc );
                return (bool)$result[0];
        }
 
@@ -154,6 +157,9 @@ class ChangeTags {
         * 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
         * 'change_tag' when adding tags
+        * @param RecentChange|null $rc Recent change being tagged, in case the tagging accompanies
+        * the action
+        * @param User|null $user Tagging user, in case the tagging is subsequent to the tagged action
         *
         * @throws MWException When $rc_id, $rev_id and $log_id are all null
         * @return array Index 0 is an array of tags actually added, index 1 is an
@@ -162,9 +168,9 @@ class ChangeTags {
         *
         * @since 1.25
         */
-       public static function updateTags(
-               $tagsToAdd, $tagsToRemove,
-               &$rc_id = null, &$rev_id = null, &$log_id = null, $params = null
+       public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null,
+               &$rev_id = null, &$log_id = null, $params = null, RecentChange $rc = null,
+               User $user = null
        ) {
 
                $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
@@ -284,6 +290,10 @@ class ChangeTags {
                }
 
                self::purgeTagUsageCache();
+
+               Hooks::run( 'ChangeTagsAfterUpdateTags', [ $tagsToAdd, $tagsToRemove, $prevTags,
+                       $rc_id, $rev_id, $log_id, $params, $rc, $user ] );
+
                return [ $tagsToAdd, $tagsToRemove, $prevTags ];
        }
 
@@ -387,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() );
                        }
                }
 
@@ -458,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() );
                        }
                }
 
@@ -546,7 +556,7 @@ class ChangeTags {
 
                // do it!
                list( $tagsAdded, $tagsRemoved, $initialTags ) = self::updateTags( $tagsToAdd,
-                       $tagsToRemove, $rc_id, $rev_id, $log_id, $params );
+                       $tagsToRemove, $rc_id, $rev_id, $log_id, $params, null, $user );
                if ( !$tagsAdded && !$tagsRemoved ) {
                        // no-op, don't log it
                        return Status::newGood( (object)[
@@ -656,28 +666,30 @@ class ChangeTags {
         * Build a text box to select a change tag
         *
         * @param string $selected Tag to select by default
-        * @param bool $fullForm Affects return value, see below
-        * @param Title $title Title object to send the form to. Used only if $fullForm is true.
         * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
         *        You need to call OutputPage::enableOOUI() yourself.
-        * @return string|array
-        *        - if $fullForm is false: an array of (label, selector).
-        *        - if $fullForm is true: HTML of entire form built around the selector.
+        * @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 = '',
-               $fullForm = false, Title $title = null, $ooui = false
+       public static function buildTagFilterSelector(
+               $selected = '', $ooui = false, IContextSource $context = null
        ) {
-               global $wgUseTagFilter;
+               if ( !$context ) {
+                       $context = RequestContext::getMain();
+               }
 
-               if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) ) {
-                       return $fullForm ? '' : [];
+               $config = $context->getConfig();
+               if ( !$config->get( 'UseTagFilter' ) || !count( self::listDefinedTags() ) ) {
+                       return [];
                }
 
                $data = [
                        Html::rawElement(
                                'label',
                                [ 'for' => 'tagfilter' ],
-                               wfMessage( 'tag-filter' )->parse()
+                               $context->msg( 'tag-filter' )->parse()
                        )
                ];
 
@@ -697,24 +709,7 @@ class ChangeTags {
                        );
                }
 
-               if ( !$fullForm ) {
-                       return $data;
-               }
-
-               $html = implode( ' ', $data );
-               $html .= "\n" .
-                       Xml::element(
-                               'input',
-                               [ 'type' => 'submit', 'value' => wfMessage( 'tag-filter-submit' )->text() ]
-                       );
-               $html .= "\n" . Html::hidden( 'title', $title->getPrefixedText() );
-               $html = Xml::tags(
-                       'form',
-                       [ 'action' => $title->getLocalURL(), 'class' => 'mw-tagfilter-form', 'method' => 'get' ],
-                       $html
-               );
-
-               return $html;
+               return $data;
        }
 
        /**
@@ -803,7 +798,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() );
                        }
                }
 
@@ -871,7 +866,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() );
                        }
                }
 
@@ -930,7 +925,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() );
                        }
                }
 
@@ -1063,7 +1058,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() );
                        }
                }