Merge "Ensure whether user can rollback page in ChangesList"
[lhc/web/wiklou.git] / includes / changes / ChangesList.php
index 703acd6..c0822c3 100644 (file)
@@ -107,7 +107,7 @@ class ChangesList extends ContextSource {
         *
         * @param RecentChange &$rc Passed by reference
         * @param bool $watched (default false)
-        * @param int $linenumber (default null)
+        * @param int|null $linenumber (default null)
         *
         * @return string|bool
         */
@@ -115,6 +115,31 @@ class ChangesList extends ContextSource {
                throw new RuntimeException( 'recentChangesLine should be implemented' );
        }
 
+       /**
+        * Get the container for highlights that are used in the new StructuredFilters
+        * system
+        *
+        * @return string HTML structure of the highlight container div
+        */
+       protected function getHighlightsContainerDiv() {
+               $highlightColorDivs = '';
+               foreach ( [ 'none', 'c1', 'c2', 'c3', 'c4', 'c5' ] as $color ) {
+                       $highlightColorDivs .= Html::rawElement(
+                               'div',
+                               [
+                                       'class' => 'mw-rcfilters-ui-highlights-color-' . $color,
+                                       'data-color' => $color
+                               ]
+                       );
+               }
+
+               return Html::rawElement(
+                       'div',
+                       [ 'class' => 'mw-rcfilters-ui-highlights' ],
+                       $highlightColorDivs
+               );
+       }
+
        /**
         * Sets the list to use a "<li class='watchlist-(namespace)-(page)'>" tag
         * @param bool $value
@@ -183,8 +208,6 @@ class ChangesList extends ContextSource {
                        $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns' .
                                $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
                }
-               $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
-                       $rc->mAttribs['rc_namespace'] );
 
                // Indicate watched status on the line to allow for more
                // comprehensive styling.
@@ -198,7 +221,8 @@ class ChangesList extends ContextSource {
        }
 
        /**
-        * Get an array of CSS classes attributed to filters for this row
+        * Get an array of CSS classes attributed to filters for this row. Used for highlighting
+        * in the front-end.
         *
         * @param RecentChange $rc
         * @return array Array of CSS classes
@@ -206,6 +230,9 @@ class ChangesList extends ContextSource {
        protected function getHTMLClassesForFilters( $rc ) {
                $classes = [];
 
+               $classes[] = Sanitizer::escapeClass( self::CSS_CLASS_PREFIX . 'ns-' .
+                       $rc->mAttribs['rc_namespace'] );
+
                if ( $this->filterGroups !== null ) {
                        foreach ( $this->filterGroups as $filterGroup ) {
                                foreach ( $filterGroup->getFilters() as $filter ) {
@@ -222,7 +249,7 @@ class ChangesList extends ContextSource {
         * bot edit, or unpatrolled edit. In English it typically contains "N", "m", "b", or "!".
         *
         * @param string $flag One key of $wgRecentChangesFlags
-        * @param IContextSource $context
+        * @param IContextSource|null $context
         * @return string HTML
         */
        public static function flag( $flag, IContextSource $context = null ) {
@@ -283,7 +310,7 @@ class ChangesList extends ContextSource {
         *
         * @param int $old Number of bytes
         * @param int $new Number of bytes
-        * @param IContextSource $context
+        * @param IContextSource|null $context
         * @return string
         */
        public static function showCharacterDifference( $old, $new, IContextSource $context = null ) {
@@ -336,7 +363,7 @@ class ChangesList extends ContextSource {
         * Format the character difference of one or several changes.
         *
         * @param RecentChange $old
-        * @param RecentChange $new Last change to use, if not provided, $old will be used
+        * @param RecentChange|null $new Last change to use, if not provided, $old will be used
         * @return string HTML fragment
         */
        public function formatCharacterDifference( RecentChange $old, RecentChange $new = null ) {
@@ -601,7 +628,7 @@ class ChangesList extends ContextSource {
         * field of this revision, if it's marked as deleted.
         * @param RCCacheEntry|RecentChange $rc
         * @param int $field
-        * @param User $user User object to check, or null to use $wgUser
+        * @param User|null $user User object to check, or null to use $wgUser
         * @return bool
         */
        public static function userCan( $rc, $field, User $user = null ) {
@@ -625,7 +652,8 @@ class ChangesList extends ContextSource {
                }
        }
 
-       /** Inserts a rollback link
+       /**
+        * Insert a rollback link
         *
         * @param string &$s
         * @param RecentChange &$rc
@@ -634,15 +662,14 @@ class ChangesList extends ContextSource {
                if ( $rc->mAttribs['rc_type'] == RC_EDIT
                        && $rc->mAttribs['rc_this_oldid']
                        && $rc->mAttribs['rc_cur_id']
+                       && $rc->getAttribute( 'page_latest' ) == $rc->mAttribs['rc_this_oldid']
                ) {
-                       $page = $rc->getTitle();
-                       /** Check for rollback and edit permissions, disallow special pages, and only
+                       $title = $rc->getTitle();
+                       /** Check for rollback permissions, disallow special pages, and only
                         * show a link on the top-most revision */
-                       if ( $this->getUser()->isAllowed( 'rollback' )
-                               && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']
-                       ) {
+                       if ( $title->quickUserCan( 'rollback', $this->getUser() ) ) {
                                $rev = new Revision( [
-                                       'title' => $page,
+                                       'title' => $title,
                                        'id' => $rc->mAttribs['rc_this_oldid'],
                                        'user' => $rc->mAttribs['rc_user'],
                                        'user_text' => $rc->mAttribs['rc_user_text'],