X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fmw.rcfilters.Controller.js;h=ed2a73f34398cdc2ec8a6db6e45fec5d462f4160;hb=8de793cb5e58ea711e11fabb84336587dfc6fa29;hp=81bfb477f034cdc92c689a379feac7d0cefa85b2;hpb=b6b8526a04c072ed8a4b283f2c4ece8f4edda861;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index 81bfb477f0..ed2a73f343 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -263,7 +263,10 @@ this.initializing = false; this.switchView( 'default' ); - this._scheduleLiveUpdate(); + this.pollingRate = mw.config.get( 'StructuredChangeFiltersLiveUpdatePollingRate' ); + if ( this.pollingRate ) { + this._scheduleLiveUpdate(); + } }; /** @@ -366,6 +369,22 @@ this.updateChangesList(); }; + /** + * Check whether the default values of the filters are all false. + * + * @return {boolean} Defaults are all false + */ + mw.rcfilters.Controller.prototype.areDefaultsEmpty = function () { + var defaultFilters = this.filtersModel.getFiltersFromParameters( this._getDefaultParams() ); + + this._deleteExcludedValuesFromFilterState( defaultFilters ); + + // Defaults can change in a session, so we need to do this every time + return Object.keys( defaultFilters ).every( function ( filterName ) { + return !defaultFilters[ filterName ]; + } ); + }; + /** * Empty all selected filters */ @@ -503,7 +522,7 @@ * @private */ mw.rcfilters.Controller.prototype._scheduleLiveUpdate = function () { - setTimeout( this._doLiveUpdate.bind( this ), 3000 ); + setTimeout( this._doLiveUpdate.bind( this ), this.pollingRate * 1000 ); }; /** @@ -518,14 +537,14 @@ } this._checkForNewChanges() - .then( function ( data ) { + .then( function ( newChanges ) { if ( !this._shouldCheckForNewChanges() ) { // by the time the response is received, // it may not be appropriate anymore return; } - if ( data.changes !== 'NO_RESULTS' ) { + if ( newChanges ) { if ( this.changesListModel.getLiveUpdate() ) { return this.updateChangesList( null, this.LIVE_UPDATE ); } else { @@ -551,17 +570,21 @@ /** * Check if new changes, newer than those currently shown, are available * - * @return {jQuery.Promise} Promise object that resolves after trying - * to fetch 1 change newer than the last known 'from' parameter value + * @return {jQuery.Promise} Promise object that resolves with a bool + * specifying if there are new changes or not * * @private */ mw.rcfilters.Controller.prototype._checkForNewChanges = function () { - return this._fetchChangesList( - 'liveUpdate', - { - limit: 1, - from: this.changesListModel.getNextFrom() + var params = { + limit: 1, + peek: 1, // bypasses ChangesList specific UI + from: this.changesListModel.getNextFrom() + }; + return this._queryChangesList( 'liveUpdate', params ).then( + function ( data ) { + // no result is 204 with the 'peek' param + return data.status === 200; } ); }; @@ -861,7 +884,7 @@ // Stringify state stringified = JSON.stringify( state ); - if ( stringified.length > 65535 ) { + if ( $.byteLength( stringified ) > 65535 ) { // Sanity check, since the preference can only hold that. return; } @@ -1043,7 +1066,6 @@ queryHighlights = data.highlights || {}; savedParams = this.filtersModel.getParametersFromFilters( - // Merge filters with sticky values $.extend( true, {}, data.filters, this.filtersModel.getStickyFiltersState() ) ); @@ -1113,23 +1135,22 @@ }; /** - * Fetch the list of changes from the server for the current filters + * Query the list of changes from the server for the current filters * - * @param {string} [counterId='updateChangesList'] Id for this request. To allow concurrent requests + * @param {string} counterId Id for this request. To allow concurrent requests * not to invalidate each other. * @param {Object} [params={}] Parameters to add to the query * - * @return {jQuery.Promise} Promise object that will resolve with the changes list - * or with a string denoting no results. + * @return {jQuery.Promise} Promise object resolved with { content, status } */ - mw.rcfilters.Controller.prototype._fetchChangesList = function ( counterId, params ) { + mw.rcfilters.Controller.prototype._queryChangesList = function ( counterId, params ) { var uri = this._getUpdatedUri(), stickyParams = this.filtersModel.getStickyParams(), requestId, latestRequest; - counterId = counterId || 'updateChangesList'; params = params || {}; + params.action = 'render'; // bypasses MW chrome uri.extend( params ); @@ -1149,45 +1170,52 @@ return $.ajax( uri.toString(), { contentType: 'html' } ) .then( - function ( html ) { - var $parsed, - pieces; - + function ( content, message, jqXHR ) { if ( !latestRequest() ) { return $.Deferred().reject(); } - - $parsed = $( $.parseHTML( html ) ); - - pieces = { - // Changes list - changes: $parsed.find( '.mw-changeslist' ).first().contents(), - // Fieldset - fieldset: $parsed.find( 'fieldset.cloptions' ).first() + return { + content: content, + status: jqXHR.status }; + }, + // RC returns 404 when there is no results + function ( jqXHR ) { + if ( latestRequest() ) { + return $.Deferred().resolve( + { + content: jqXHR.responseText, + status: jqXHR.status + } + ).promise(); + } + } + ); + }; + + /** + * Fetch the list of changes from the server for the current filters + * + * @return {jQuery.Promise} Promise object that will resolve with the changes list + * and the fieldset. + */ + mw.rcfilters.Controller.prototype._fetchChangesList = function () { + return this._queryChangesList( 'updateChangesList' ) + .then( + function ( data ) { + var $parsed = $( '
' ).append( $( $.parseHTML( data.content ) ) ), + pieces = { + // Changes list + changes: $parsed.find( '.mw-changeslist' ).first().contents(), + // Fieldset + fieldset: $parsed.find( 'fieldset.cloptions' ).first() + }; - // Watchlist returns 200 when there is no results if ( pieces.changes.length === 0 ) { pieces.changes = 'NO_RESULTS'; } return pieces; - }, - // RC returns 404 when there is no results - function ( responseObj ) { - var $parsed; - - if ( !latestRequest() ) { - return $.Deferred().reject(); - } - - $parsed = $( $.parseHTML( responseObj.responseText ) ); - - // Force a resolve state to this promise - return $.Deferred().resolve( { - changes: 'NO_RESULTS', - fieldset: $parsed.find( 'fieldset.cloptions' ).first() - } ).promise(); } ); };