Merge "Remove useless PHP version comparison from wfDebugBacktrace()"
[lhc/web/wiklou.git] / includes / changes / ChangesList.php
index 7eadcc8..15432da 100644 (file)
@@ -53,7 +53,7 @@ class ChangesList extends ContextSource {
                        $this->skin = $obj;
                }
                $this->preCacheMessages();
-               $this->watchMsgCache = new HashBagOStuff( array( 'maxKeys' => 50 ) );
+               $this->watchMsgCache = new HashBagOStuff( [ 'maxKeys' => 50 ] );
        }
 
        /**
@@ -67,7 +67,7 @@ class ChangesList extends ContextSource {
                $user = $context->getUser();
                $sk = $context->getSkin();
                $list = null;
-               if ( Hooks::run( 'FetchChangesList', array( $user, &$sk, &$list ) ) ) {
+               if ( Hooks::run( 'FetchChangesList', [ $user, &$sk, &$list ] ) ) {
                        $new = $context->getRequest()->getBool( 'enhanced', $user->getOption( 'usenewrc' ) );
 
                        return $new ? new EnhancedChangesList( $context ) : new OldChangesList( $context );
@@ -113,9 +113,9 @@ class ChangesList extends ContextSource {
         */
        private function preCacheMessages() {
                if ( !isset( $this->message ) ) {
-                       foreach ( array(
+                       foreach ( [
                                'cur', 'diff', 'hist', 'enhancedrc-history', 'last', 'blocklink', 'history',
-                               'semicolon-separator', 'pipe-separator' ) as $msg
+                               'semicolon-separator', 'pipe-separator' ] as $msg
                        ) {
                                $this->message[$msg] = $this->msg( $msg )->escaped();
                        }
@@ -139,6 +139,34 @@ class ChangesList extends ContextSource {
                return $f;
        }
 
+       /**
+        * Get an array of default HTML class attributes for the change.
+        *
+        * @param RecentChange|RCCacheEntry $rc
+        * @param string|bool $watched Optionally timestamp for adding watched class
+        *
+        * @return array of classes
+        */
+       protected function getHTMLClasses( $rc, $watched ) {
+               $classes = [];
+               $logType = $rc->mAttribs['rc_log_type'];
+
+               if ( $logType ) {
+                       $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $logType );
+               } else {
+                       $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' .
+                               $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
+               }
+
+               // Indicate watched status on the line to allow for more
+               // comprehensive styling.
+               $classes[] = $watched && $rc->mAttribs['rc_timestamp'] >= $watched
+                       ? 'mw-changeslist-line-watched'
+                       : 'mw-changeslist-line-not-watched';
+
+               return $classes;
+       }
+
        /**
         * Provide the "<abbr>" element appropriate to a given abbreviated flag,
         * namely the flag indicating a new page, a minor edit, a bot edit, or an
@@ -152,7 +180,7 @@ class ChangesList extends ContextSource {
                static $flagInfos = null;
                if ( is_null( $flagInfos ) ) {
                        global $wgRecentChangesFlags;
-                       $flagInfos = array();
+                       $flagInfos = [];
                        foreach ( $wgRecentChangesFlags as $key => $value ) {
                                $flagInfos[$key]['letter'] = wfMessage( $value['letter'] )->escaped();
                                $flagInfos[$key]['title'] = wfMessage( $value['title'] )->escaped();
@@ -163,10 +191,10 @@ class ChangesList extends ContextSource {
                }
 
                // Inconsistent naming, bleh, kepted for b/c
-               $map = array(
+               $map = [
                        'minoredit' => 'minor',
                        'botedit' => 'bot',
-               );
+               ];
                if ( isset( $map[$flag] ) ) {
                        $flag = $map[$flag];
                }
@@ -181,7 +209,7 @@ class ChangesList extends ContextSource {
         * @return string
         */
        public function beginRecentChangesList() {
-               $this->rc_cache = array();
+               $this->rc_cache = [];
                $this->rcMoveIndex = 0;
                $this->rcCacheIndex = 0;
                $this->lastdate = '';
@@ -195,7 +223,7 @@ class ChangesList extends ContextSource {
         * @param ResultWrapper|array $rows
         */
        public function initChangesListRows( $rows ) {
-               Hooks::run( 'ChangesListInitRows', array( $this, $rows ) );
+               Hooks::run( 'ChangesListInitRows', [ $this, $rows ] );
        }
 
        /**
@@ -217,7 +245,7 @@ class ChangesList extends ContextSource {
                $lang = $context->getLanguage();
                $config = $context->getConfig();
                $code = $lang->getCode();
-               static $fastCharDiff = array();
+               static $fastCharDiff = [];
                if ( !isset( $fastCharDiff[$code] ) ) {
                        $fastCharDiff[$code] = $config->get( 'MiserMode' )
                                || $context->msg( 'rc-change-size' )->plain() === '$1';
@@ -247,7 +275,7 @@ class ChangesList extends ContextSource {
                $formattedTotalSize = $context->msg( 'rc-change-size-new' )->numParams( $new )->text();
 
                return Html::element( $tag,
-                       array( 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ),
+                       [ 'dir' => 'ltr', 'class' => $formattedSizeClass, 'title' => $formattedTotalSize ],
                        $context->msg( 'parentheses', $formattedSize )->plain() ) . $lang->getDirMark();
        }
 
@@ -329,16 +357,16 @@ class ChangesList extends ContextSource {
                } elseif ( !self::userCan( $rc, Revision::DELETED_TEXT, $this->getUser() ) ) {
                        $diffLink = $this->message['diff'];
                } else {
-                       $query = array(
+                       $query = [
                                'curid' => $rc->mAttribs['rc_cur_id'],
                                'diff' => $rc->mAttribs['rc_this_oldid'],
                                'oldid' => $rc->mAttribs['rc_last_oldid']
-                       );
+                       ];
 
                        $diffLink = Linker::linkKnown(
                                $rc->getTitle(),
                                $this->message['diff'],
-                               array( 'tabindex' => $rc->counter ),
+                               [ 'tabindex' => $rc->counter ],
                                $query
                        );
                }
@@ -350,11 +378,11 @@ class ChangesList extends ContextSource {
                        $diffhist .= Linker::linkKnown(
                                $rc->getTitle(),
                                $this->message['hist'],
-                               array(),
-                               array(
+                               [],
+                               [
                                        'curid' => $rc->mAttribs['rc_cur_id'],
                                        'action' => 'history'
-                               )
+                               ]
                        );
                }
 
@@ -382,15 +410,15 @@ class ChangesList extends ContextSource {
         * @since 1.26
         */
        public function getArticleLink( &$rc, $unpatrolled, $watched ) {
-               $params = array();
+               $params = [];
                if ( $rc->getTitle()->isRedirect() ) {
-                       $params = array( 'redirect' => 'no' );
+                       $params = [ 'redirect' => 'no' ];
                }
 
-               $articlelink = Linker::linkKnown(
+               $articlelink = Linker::link(
                        $rc->getTitle(),
                        null,
-                       array( 'class' => 'mw-changeslist-title' ),
+                       [ 'class' => 'mw-changeslist-title' ],
                        $params
                );
                if ( $this->isDeleted( $rc, Revision::DELETED_TEXT ) ) {
@@ -404,7 +432,7 @@ class ChangesList extends ContextSource {
                # TODO: Deprecate the $s argument, it seems happily unused.
                $s = '';
                Hooks::run( 'ChangesListInsertArticleLink',
-                       array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
+                       [ &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ] );
 
                return "{$s} {$articlelink}";
        }
@@ -491,10 +519,9 @@ class ChangesList extends ContextSource {
                        return '';
                }
                $cache = $this->watchMsgCache;
-               $that = $this;
                return $cache->getWithSetCallback( $count, $cache::TTL_INDEFINITE,
-                       function () use ( $that, $count ) {
-                               return $that->msg( 'number_of_watching_users_RCview' )
+                       function () use ( $count ) {
+                               return $this->msg( 'number_of_watching_users_RCview' )
                                        ->numParams( $count )->escaped();
                        }
                );
@@ -555,13 +582,13 @@ class ChangesList extends ContextSource {
                        if ( $this->getUser()->isAllowed( 'rollback' )
                                && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid']
                        ) {
-                               $rev = new Revision( array(
+                               $rev = new Revision( [
                                        'title' => $page,
                                        'id' => $rc->mAttribs['rc_this_oldid'],
                                        'user' => $rc->mAttribs['rc_user'],
                                        'user_text' => $rc->mAttribs['rc_user_text'],
                                        'deleted' => $rc->mAttribs['rc_deleted']
-                               ) );
+                               ] );
                                $s .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
                        }
                }
@@ -590,7 +617,8 @@ class ChangesList extends ContextSource {
 
                list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
                        $rc->mAttribs['ts_tags'],
-                       'changeslist'
+                       'changeslist',
+                       $this->getContext()
                );
                $classes = array_merge( $classes, $newClasses );
                $s .= ' ' . $tagSummary;
@@ -625,9 +653,11 @@ class ChangesList extends ContextSource {
                if ( $rc instanceof RecentChange ) {
                        $isPatrolled = $rc->mAttribs['rc_patrolled'];
                        $rcType = $rc->mAttribs['rc_type'];
+                       $rcLogType = $rc->mAttribs['rc_log_type'];
                } else {
                        $isPatrolled = $rc->rc_patrolled;
                        $rcType = $rc->rc_type;
+                       $rcLogType = $rc->rc_log_type;
                }
 
                if ( !$isPatrolled ) {
@@ -637,6 +667,9 @@ class ChangesList extends ContextSource {
                        if ( $user->useNPPatrol() && $rcType == RC_NEW ) {
                                return true;
                        }
+                       if ( $user->useFilePatrol() && $rcLogType == 'upload' ) {
+                               return true;
+                       }
                }
 
                return false;