Merge "output: Narrow Title type hint to LinkTarget"
[lhc/web/wiklou.git] / includes / actions / HistoryAction.php
index 4df2f56..db874f2 100644 (file)
@@ -95,6 +95,7 @@ class HistoryAction extends FormlessAction {
        private function preCacheMessages() {
                // Precache various messages
                if ( !isset( $this->message ) ) {
+                       $this->message = [];
                        $msgs = [ 'cur', 'last', 'pipe-separator' ];
                        foreach ( $msgs as $msg ) {
                                $this->message[$msg] = $this->msg( $msg )->escaped();
@@ -148,10 +149,17 @@ class HistoryAction extends FormlessAction {
                $out = $this->getOutput();
                $request = $this->getRequest();
 
-               /**
-                * Allow client caching.
-                */
-               if ( $out->checkLastModified( $this->page->getTouched() ) ) {
+               // Allow client-side HTTP caching of the history page.
+               // But, always ignore this cache if the (logged-in) user has this page on their watchlist
+               // and has one or more unseen revisions. Otherwise, we might be showing stale update markers.
+               // The Last-Modified for the history page does not change when user's markers are cleared,
+               // so going from "some unseen" to "all seen" would not clear the cache.
+               // But, when all of the revisions are marked as seen, then only way for new unseen revision
+               // markers to appear, is for the page to be edited, which updates page_touched/Last-Modified.
+               if (
+                       !$this->hasUnseenRevisionMarkers() &&
+                       $out->checkLastModified( $this->page->getTouched() )
+               ) {
                        return null; // Client cache fresh and headers sent, nothing more to do.
                }
 
@@ -258,7 +266,8 @@ class HistoryAction extends FormlessAction {
                                'value' => $tagFilter,
                        ]
                ];
-               if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+               if ( $permissionManager->userHasRight( $this->getUser(), 'deletedhistory' ) ) {
                        $fields[] = [
                                'type' => 'check',
                                'label' => $this->msg( 'history-show-deleted' )->text(),
@@ -305,6 +314,16 @@ class HistoryAction extends FormlessAction {
                return null;
        }
 
+       /**
+        * @return bool Page is watched by and has unseen revision for the user
+        */
+       private function hasUnseenRevisionMarkers() {
+               return (
+                       $this->getContext()->getConfig()->get( 'ShowUpdatedMarker' ) &&
+                       $this->getTitle()->getNotificationTimestamp( $this->getUser() )
+               );
+       }
+
        /**
         * Fetch an array of revisions, specified by a given limit, offset and
         * direction. This is now only used by the feeds. It was previously