Merge "Add IContextSource as parameter to ChangeTags::formatSummaryRow"
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
index 5c70c99..305eeab 100644 (file)
@@ -35,16 +35,20 @@ class ChangeTags {
         * @param string $tags Comma-separated list of tags
         * @param string $page A label for the type of action which is being displayed,
         *   for example: 'history', 'contributions' or 'newpages'
+        * @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 is subject to change in the future
         * @return array Array with two items: (html, classes)
         *   - html: String: HTML for displaying the tags (empty string when param $tags is empty)
         *   - classes: Array of strings: CSS classes used in the generated html, one class for each tag
         */
-       public static function formatSummaryRow( $tags, $page ) {
-               global $wgLang;
-
+       public static function formatSummaryRow( $tags, $page, IContextSource $context = null ) {
                if ( !$tags ) {
                        return array( '', array() );
                }
+               if ( !$context ) {
+                       $context = RequestContext::getMain();
+               }
 
                $classes = array();
 
@@ -71,9 +75,9 @@ class ChangeTags {
                        return array( '', array() );
                }
 
-               $markers = wfMessage( 'tag-list-wrapper' )
+               $markers = $context->msg( 'tag-list-wrapper' )
                        ->numParams( count( $displayTags ) )
-                       ->rawParams( $wgLang->commaList( $displayTags ) )
+                       ->rawParams( $context->getLanguage()->commaList( $displayTags ) )
                        ->parse();
                $markers = Xml::tags( 'span', array( 'class' => 'mw-tag-markers' ), $markers );
 
@@ -212,6 +216,22 @@ class ChangeTags {
                        );
                }
 
+               if ( $log_id && !$rev_id ) {
+                       $rev_id = $dbw->selectField(
+                               'log_search',
+                               'ls_value',
+                               array( 'ls_field' => 'associated_rev_id', 'ls_log_id' => $log_id ),
+                               __METHOD__
+                       );
+               } elseif ( !$log_id && $rev_id ) {
+                       $log_id = $dbw->selectField(
+                               'log_search',
+                               'ls_log_id',
+                               array( 'ls_field' => 'associated_rev_id', 'ls_value' => $rev_id ),
+                               __METHOD__
+                       );
+               }
+
                // update the tag_summary row
                $prevTags = array();
                if ( !self::updateTagSummaryRow( $tagsToAdd, $tagsToRemove, $rc_id, $rev_id,
@@ -358,8 +378,12 @@ class ChangeTags {
        public static function canAddTagsAccompanyingChange( array $tags,
                User $user = null ) {
 
-               if ( !is_null( $user ) && !$user->isAllowed( 'applychangetags' ) ) {
-                       return Status::newFatal( 'tags-apply-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'applychangetags' ) ) {
+                               return Status::newFatal( 'tags-apply-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-apply-blocked' );
+                       }
                }
 
                // to be applied, a tag has to be explicitly defined
@@ -425,8 +449,12 @@ class ChangeTags {
        public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove,
                User $user = null ) {
 
-               if ( !is_null( $user ) && !$user->isAllowed( 'changetags' ) ) {
-                       return Status::newFatal( 'tags-update-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'changetags' ) ) {
+                               return Status::newFatal( 'tags-update-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-update-blocked' );
+                       }
                }
 
                if ( $tagsToAdd ) {
@@ -766,8 +794,12 @@ class ChangeTags {
         * @since 1.25
         */
        public static function canActivateTag( $tag, User $user = null ) {
-               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) {
-                       return Status::newFatal( 'tags-manage-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                               return Status::newFatal( 'tags-manage-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-manage-blocked' );
+                       }
                }
 
                // defined tags cannot be activated (a defined tag is either extension-
@@ -830,8 +862,12 @@ class ChangeTags {
         * @since 1.25
         */
        public static function canDeactivateTag( $tag, User $user = null ) {
-               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) {
-                       return Status::newFatal( 'tags-manage-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                               return Status::newFatal( 'tags-manage-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-manage-blocked' );
+                       }
                }
 
                // only explicitly-defined tags can be deactivated
@@ -885,8 +921,12 @@ class ChangeTags {
         * @since 1.25
         */
        public static function canCreateTag( $tag, User $user = null ) {
-               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) {
-                       return Status::newFatal( 'tags-manage-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                               return Status::newFatal( 'tags-manage-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-manage-blocked' );
+                       }
                }
 
                // no empty tags
@@ -1014,8 +1054,12 @@ class ChangeTags {
        public static function canDeleteTag( $tag, User $user = null ) {
                $tagUsage = self::tagUsageStatistics();
 
-               if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) {
-                       return Status::newFatal( 'tags-manage-no-permission' );
+               if ( !is_null( $user ) ) {
+                       if ( !$user->isAllowed( 'managechangetags' ) ) {
+                               return Status::newFatal( 'tags-manage-no-permission' );
+                       } elseif ( $user->isBlocked() ) {
+                               return Status::newFatal( 'tags-manage-blocked' );
+                       }
                }
 
                if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self::listDefinedTags() ) ) {
@@ -1101,7 +1145,7 @@ class ChangeTags {
                        },
                        array(
                                'checkKeys' => array( wfMemcKey( 'active-tags' ) ),
-                               'lockTSE' => INF,
+                               'lockTSE' => 300,
                                'pcTTL' => 30
                        )
                );
@@ -1147,7 +1191,7 @@ class ChangeTags {
                        },
                        array(
                                'checkKeys' => array( wfMemcKey( 'valid-tags-db' ) ),
-                               'lockTSE' => INF,
+                               'lockTSE' => 300,
                                'pcTTL' => 30
                        )
                );
@@ -1175,7 +1219,7 @@ class ChangeTags {
                        },
                        array(
                                'checkKeys' => array( wfMemcKey( 'valid-tags-hook' ) ),
-                               'lockTSE' => INF,
+                               'lockTSE' => 300,
                                'pcTTL' => 30
                        )
                );
@@ -1243,7 +1287,7 @@ class ChangeTags {
                        },
                        array(
                                'checkKeys' => array( wfMemcKey( 'change-tag-statistics' ) ),
-                               'lockTSE' => INF,
+                               'lockTSE' => 300,
                                'pcTTL' => 30
                        )
                );