From 708f1cdfba1c4e621a4c6532e810a8aef0fd156f Mon Sep 17 00:00:00 2001 From: petarpetkovic Date: Wed, 13 Dec 2017 22:16:16 +0100 Subject: [PATCH] Fix how "Live updates" behave when user logs out If user enables "Live updates" on one tab/browser and logs out from different tab/browser, reload the page. Bug: T177717 Change-Id: Ifeeb7d50eaec8f733a94a36711f1c4541af1cef9 --- .../specialpage/ChangesListSpecialPage.php | 9 ++++- .../mw.rcfilters.Controller.js | 39 +++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index b6d1028778..eab5940de6 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -570,8 +570,15 @@ abstract class ChangesListSpecialPage extends SpecialPage { // Used by "live update" and "view newest" to check // if there's new changes with minimal data transfer if ( $this->getRequest()->getBool( 'peek' ) ) { - $code = $rows->numRows() > 0 ? 200 : 204; + $code = $rows->numRows() > 0 ? 200 : 204; $this->getOutput()->setStatusCode( $code ); + + if ( $this->getUser()->isAnon() !== + $this->getRequest()->getFuzzyBool( 'isAnon' ) + ) { + $this->getOutput()->setStatusCode( 205 ); + } + return; } diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index 7b5e11528c..79546b46d4 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -281,6 +281,7 @@ * Extracts information from the changes list DOM * * @param {jQuery} $root Root DOM to find children from + * @param {boolean} [statusCode] Server response status code * @return {Object} Information about changes list * @return {Object|string} return.changes Changes list, or 'NO_RESULTS' if there are no results * (either normally or as an error) @@ -288,10 +289,21 @@ * 'NO_RESULTS_TIMEOUT' for no results due to a timeout, or omitted for more than 0 results * @return {jQuery} return.fieldset Fieldset */ - mw.rcfilters.Controller.prototype._extractChangesListInfo = function ( $root ) { + mw.rcfilters.Controller.prototype._extractChangesListInfo = function ( $root, statusCode ) { var info, $changesListContents = $root.find( '.mw-changeslist' ).first().contents(), - areResults = !!$changesListContents.length; + areResults = !!$changesListContents.length, + checkForLogout = !areResults && statusCode === 200; + + // We check if user logged out on different tab/browser or the session has expired. + // 205 status code returned from the server, which indicates that we need to reload the page + // is not usable on WL page, because we get redirected to login page, which gives 200 OK + // status code (if everything else goes well). + // Bug: T177717 + if ( checkForLogout && !!$root.find( '#wpName1' ).length ) { + location.reload( false ); + return; + } info = { changes: $changesListContents.length ? $changesListContents : 'NO_RESULTS', @@ -611,13 +623,26 @@ } this._checkForNewChanges() - .then( function ( newChanges ) { + .then( function ( statusCode ) { + // no result is 204 with the 'peek' param + // logged out is 205 + var newChanges = statusCode === 200; + if ( !this._shouldCheckForNewChanges() ) { // by the time the response is received, // it may not be appropriate anymore return; } + // 205 is the status code returned from server when user's logged in/out + // status is not matching while fetching live update changes. + // This works only on Recent Changes page. For WL, look _extractChangesListInfo. + // Bug: T177717 + if ( statusCode === 205 ) { + location.reload( false ); + return; + } + if ( newChanges ) { if ( this.changesListModel.getLiveUpdate() ) { return this.updateChangesList( null, this.LIVE_UPDATE ); @@ -653,12 +678,12 @@ var params = { limit: 1, peek: 1, // bypasses ChangesList specific UI - from: this.changesListModel.getNextFrom() + from: this.changesListModel.getNextFrom(), + isAnon: mw.user.isAnon() }; return this._queryChangesList( 'liveUpdate', params ).then( function ( data ) { - // no result is 204 with the 'peek' param - return data.status === 200; + return data.status; } ); }; @@ -1041,7 +1066,7 @@ data ? data.content : '' ) ) ); - return this._extractChangesListInfo( $parsed ); + return this._extractChangesListInfo( $parsed, data.status ); }.bind( this ) ); }; -- 2.20.1