Merge "Replace User::isAllowed with PermissionManager."
[lhc/web/wiklou.git] / includes / changes / EnhancedChangesList.php
index 3e98f65..62cf39e 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+use MediaWiki\Storage\RevisionRecord;
+
 /**
  * Generates a list of changes using an Enhanced system (uses javascript).
  *
@@ -184,9 +187,7 @@ class EnhancedChangesList extends ChangesList {
                        $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
                                . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
                }
-               if ( $block[0]->watched
-                       && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
-               ) {
+               if ( $block[0]->watched ) {
                        $tableClasses[] = 'mw-changeslist-line-watched';
                } else {
                        $tableClasses[] = 'mw-changeslist-line-not-watched';
@@ -219,7 +220,7 @@ class EnhancedChangesList extends ChangesList {
                foreach ( $block as $rcObj ) {
                        // If all log actions to this page were hidden, then don't
                        // give the name of the affected page for this block!
-                       if ( !$this->isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
+                       if ( !static::isDeleted( $rcObj, LogPage::DELETED_ACTION ) ) {
                                $namehidden = false;
                        }
                        $u = $rcObj->userlink;
@@ -260,7 +261,8 @@ class EnhancedChangesList extends ChangesList {
                } elseif ( $allLogs ) {
                        $articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
                } else {
-                       $articleLink = $this->getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
+                       $articleLink = $this->getArticleLink(
+                               $block[0], $block[0]->unpatrolled, $block[0]->watched );
                }
 
                $queryParams['curid'] = $curId;
@@ -386,14 +388,12 @@ class EnhancedChangesList extends ChangesList {
                $lineParams = [ 'targetTitle' => $rcObj->getTitle() ];
 
                $classes = [ 'mw-enhanced-rc' ];
-               if ( $rcObj->watched
-                       && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
-               ) {
+               if ( $rcObj->watched ) {
                        $classes[] = 'mw-enhanced-watched';
                }
                $classes = array_merge( $classes, $this->getHTMLClasses( $rcObj, $rcObj->watched ) );
 
-               $separator = ' <span class="mw-changeslist-separator">. .</span> ';
+               $separator = ' <span class="mw-changeslist-separator"></span> ';
 
                $data['recentChangesFlags'] = [
                        'newpage' => $type == RC_NEW,
@@ -412,7 +412,7 @@ class EnhancedChangesList extends ChangesList {
                if ( $type == RC_LOG ) {
                        $link = htmlspecialchars( $rcObj->timestamp );
                        # Revision link
-               } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
+               } elseif ( !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getUser() ) ) {
                        $link = Html::element( 'span', [ 'class' => 'history-deleted' ], $rcObj->timestamp );
                } else {
                        $link = $this->linkRenderer->makeKnownLink(
@@ -421,7 +421,7 @@ class EnhancedChangesList extends ChangesList {
                                [],
                                $params
                        );
-                       if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
+                       if ( static::isDeleted( $rcObj, RevisionRecord::DELETED_TEXT ) ) {
                                $link = '<span class="history-deleted">' . $link . '</span> ';
                        }
                }
@@ -503,7 +503,7 @@ class EnhancedChangesList extends ChangesList {
        /**
         * Generates amount of changes (linking to diff ) & link to history.
         *
-        * @param array $block
+        * @param RCCacheEntry[] $block
         * @param array $queryParams
         * @param bool $allLogs
         * @param bool $isnew
@@ -529,7 +529,7 @@ class EnhancedChangesList extends ChangesList {
                /** @var RCCacheEntry $rcObj */
                foreach ( $block as $rcObj ) {
                        // Same logic as below inside main foreach
-                       if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) {
+                       if ( $rcObj->watched ) {
                                $sinceLast++;
                                $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid'];
                        }
@@ -552,32 +552,42 @@ class EnhancedChangesList extends ChangesList {
                $block0 = $block[0];
                $last = $block[count( $block ) - 1];
                if ( !$allLogs ) {
-                       if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ||
+                       if (
                                $isnew ||
-                               $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE
+                               $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ||
+                               !ChangesList::userCan( $rcObj, RevisionRecord::DELETED_TEXT, $this->getUser() )
                        ) {
-                               $links['total-changes'] = $nchanges[$n];
+                               $links['total-changes'] = Html::rawElement( 'span', [], $nchanges[$n] );
                        } else {
-                               $links['total-changes'] = $this->linkRenderer->makeKnownLink(
-                                       $block0->getTitle(),
-                                       new HtmlArmor( $nchanges[$n] ),
-                                       [ 'class' => 'mw-changeslist-groupdiff' ],
-                                       $queryParams + [
-                                               'diff' => $currentRevision,
-                                               'oldid' => $last->mAttribs['rc_last_oldid'],
-                                       ]
+                               $links['total-changes'] = Html::rawElement( 'span', [],
+                                       $this->linkRenderer->makeKnownLink(
+                                               $block0->getTitle(),
+                                               new HtmlArmor( $nchanges[$n] ),
+                                               [ 'class' => 'mw-changeslist-groupdiff' ],
+                                               $queryParams + [
+                                                       'diff' => $currentRevision,
+                                                       'oldid' => $last->mAttribs['rc_last_oldid'],
+                                               ]
+                                       )
+                               );
+                       }
+
+                       if (
+                               $rcObj->mAttribs['rc_type'] != RC_CATEGORIZE &&
+                               $sinceLast > 0 &&
+                               $sinceLast < $n
+                       ) {
+                               $links['total-changes-since-last'] = Html::rawElement( 'span', [],
+                                       $this->linkRenderer->makeKnownLink(
+                                               $block0->getTitle(),
+                                               new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
+                                               [ 'class' => 'mw-changeslist-groupdiff' ],
+                                               $queryParams + [
+                                                       'diff' => $currentRevision,
+                                                       'oldid' => $unvisitedOldid,
+                                               ]
+                                       )
                                );
-                               if ( $sinceLast > 0 && $sinceLast < $n ) {
-                                       $links['total-changes-since-last'] = $this->linkRenderer->makeKnownLink(
-                                                       $block0->getTitle(),
-                                                       new HtmlArmor( $sinceLastVisitMsg[$sinceLast] ),
-                                                       [ 'class' => 'mw-changeslist-groupdiff' ],
-                                                       $queryParams + [
-                                                               'diff' => $currentRevision,
-                                                               'oldid' => $unvisitedOldid,
-                                                       ]
-                                               );
-                               }
                        }
                }
 
@@ -585,17 +595,19 @@ class EnhancedChangesList extends ChangesList {
                if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) {
                        // don't show history link for logs
                } elseif ( $namehidden || !$block0->getTitle()->exists() ) {
-                       $links['history'] = $this->message['enhancedrc-history'];
+                       $links['history'] = Html::rawElement( 'span', [], $this->message['enhancedrc-history'] );
                } else {
                        $params = $queryParams;
                        $params['action'] = 'history';
 
-                       $links['history'] = $this->linkRenderer->makeKnownLink(
+                       $links['history'] = Html::rawElement( 'span', [],
+                               $this->linkRenderer->makeKnownLink(
                                        $block0->getTitle(),
                                        new HtmlArmor( $this->message['enhancedrc-history'] ),
                                        [ 'class' => 'mw-changeslist-history' ],
                                        $params
-                               );
+                               )
+                       );
                }
 
                # Allow others to alter, remove or add to these links
@@ -606,8 +618,8 @@ class EnhancedChangesList extends ChangesList {
                        return '';
                }
 
-               $logtext = implode( $this->message['pipe-separator'], $links );
-               $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped();
+               $logtext = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                       implode( ' ', $links ) );
                return ' ' . $logtext;
        }
 
@@ -653,10 +665,9 @@ class EnhancedChangesList extends ChangesList {
                        $logPage = new LogPage( $logType );
                        $logTitle = SpecialPage::getTitleFor( 'Log', $logType );
                        $logName = $logPage->getName()->text();
-                       $data['logLink'] = $this->msg( 'parentheses' )
-                               ->rawParams(
-                                       $this->linkRenderer->makeKnownLink( $logTitle, $logName )
-                               )->escaped();
+                       $data['logLink'] = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                               $this->linkRenderer->makeKnownLink( $logTitle, $logName )
+                       );
                } else {
                        $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
                }
@@ -664,16 +675,16 @@ class EnhancedChangesList extends ChangesList {
                # Diff and hist links
                if ( $type != RC_LOG && $type != RC_CATEGORIZE ) {
                        $query['action'] = 'history';
-                       $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
+                       $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query, false );
                }
-               $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
+               $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator"></span> ';
 
                # Character diff
                if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
                        $cd = $this->formatCharacterDifference( $rcObj );
                        if ( $cd !== '' ) {
                                $data['characterDiff'] = $cd;
-                               $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
+                               $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator"></span> ';
                        }
                }
 
@@ -686,7 +697,7 @@ class EnhancedChangesList extends ChangesList {
                        $data['userTalkLink'] = $rcObj->usertalklink;
                        $data['comment'] = $this->insertComment( $rcObj );
                        if ( $type == RC_CATEGORIZE ) {
-                               $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query );
+                               $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query, false );
                        }
                        $data['rollback'] = $this->getRollback( $rcObj );
                }
@@ -744,7 +755,11 @@ class EnhancedChangesList extends ChangesList {
                ] );
 
                // everything else: makes it easier for extensions to add or remove data
-               $line .= implode( '', $data );
+               foreach ( $data as $key => $dataItem ) {
+                       $line .= Html::rawElement( 'span', [
+                               'class' => 'mw-changeslist-line-inner-' . $key,
+                       ], $dataItem );
+               }
 
                $line .= "</td></tr></table>\n";
 
@@ -759,9 +774,10 @@ class EnhancedChangesList extends ChangesList {
         *
         * @param RCCacheEntry $rc
         * @param array $query array of key/value pairs to append as a query string
+        * @param bool $useParentheses (optional) Wrap comments in parentheses where needed
         * @return string HTML
         */
-       public function getDiffHistLinks( RCCacheEntry $rc, array $query ) {
+       public function getDiffHistLinks( RCCacheEntry $rc, array $query, $useParentheses = true ) {
                $pageTitle = $rc->getTitle();
                if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) {
                        // For categorizations we must swap the category title with the page title!
@@ -773,15 +789,23 @@ class EnhancedChangesList extends ChangesList {
                        }
                }
 
-               $retVal = ' ' . $this->msg( 'parentheses' )
-                               ->rawParams( $rc->difflink . $this->message['pipe-separator']
-                                       . $this->linkRenderer->makeKnownLink(
-                                               $pageTitle,
-                                               new HtmlArmor( $this->message['hist'] ),
-                                               [ 'class' => 'mw-changeslist-history' ],
-                                               $query
-                                       ) )->escaped();
-               return $retVal;
+               $histLink = $this->linkRenderer->makeKnownLink(
+                       $pageTitle,
+                       new HtmlArmor( $this->message['hist'] ),
+                       [ 'class' => 'mw-changeslist-history' ],
+                       $query
+               );
+               if ( $useParentheses ) {
+                       $retVal = $this->msg( 'parentheses' )
+                       ->rawParams( $rc->difflink . $this->message['pipe-separator']
+                               . $histLink )->escaped();
+               } else {
+                       $retVal = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-links' ],
+                               Html::rawElement( 'span', [], $rc->difflink ) .
+                               Html::rawElement( 'span', [], $histLink )
+                       );
+               }
+               return ' ' . $retVal;
        }
 
        /**