From b747307a2002c0c86fd6bbd1e0d96f5a717df8f2 Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Thu, 21 Sep 2017 15:44:02 -0400 Subject: [PATCH] WLFilters: Live update and View newest Moved handling for 'from', 'days' and 'limit' to base class (ChangesListSpecialPage) I moved 'days' because its implementation is related to 'from'. I moved 'limit' because it was getting lonely and it's identical in all cases. Bug: T176348 Change-Id: If6280ad6fbad65909e1d0b2a48344e24d485aca2 --- .../specialpage/ChangesListSpecialPage.php | 21 +++++++++ includes/specials/SpecialRecentchanges.php | 38 ---------------- includes/specials/SpecialWatchlist.php | 43 ++----------------- .../mw.rcfilters.dm.ChangesListViewModel.js | 2 +- 4 files changed, 26 insertions(+), 78 deletions(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index d7519d3c17..6fd33a7ced 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -957,6 +957,11 @@ abstract class ChangesListSpecialPage extends SpecialPage { $opts->add( 'urlversion', 1 ); $opts->add( 'tagfilter', '' ); + $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT ); + $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT ); + + $opts->add( 'from', '' ); + return $opts; } @@ -1110,6 +1115,9 @@ abstract class ChangesListSpecialPage extends SpecialPage { $query = wfArrayToCgi( $this->convertParamsForLink( $opts->getChangedValues() ) ); $this->getOutput()->redirect( $this->getPageTitle()->getCanonicalURL( $query ) ); } + + $opts->validateIntBounds( 'limit', 0, 5000 ); + $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) ); } /** @@ -1249,6 +1257,19 @@ abstract class ChangesListSpecialPage extends SpecialPage { } $conds[] = "rc_namespace $operator $value"; } + + // Calculate cutoff + $cutoff_unixtime = time() - $opts['days'] * 3600 * 24; + $cutoff = $dbr->timestamp( $cutoff_unixtime ); + + $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] ); + if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) { + $cutoff = $dbr->timestamp( $opts['from'] ); + } else { + $opts->reset( 'from' ); + } + + $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ); } /** diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 34a7714de2..522a0a69d3 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -164,10 +164,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage { true ); parent::execute( $subpage ); - - if ( $this->isStructuredFilterUiEnabled() ) { - $out->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', true ); - } } /** @@ -232,10 +228,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage { public function getDefaultOptions() { $opts = parent::getDefaultOptions(); - $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT ); - $opts->add( 'limit', $this->getDefaultLimit() ); - $opts->add( 'from', '' ); - $opts->add( 'categories', '' ); $opts->add( 'categories_any', false ); @@ -287,36 +279,6 @@ class SpecialRecentChanges extends ChangesListSpecialPage { } } - public function validateOptions( FormOptions $opts ) { - $opts->validateIntBounds( 'limit', 0, 5000 ); - $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) ); - parent::validateOptions( $opts ); - } - - /** - * @inheritDoc - */ - protected function buildQuery( &$tables, &$fields, &$conds, - &$query_options, &$join_conds, FormOptions $opts - ) { - $dbr = $this->getDB(); - parent::buildQuery( $tables, $fields, $conds, - $query_options, $join_conds, $opts ); - - // Calculate cutoff - $cutoff_unixtime = time() - $opts['days'] * 3600 * 24; - $cutoff = $dbr->timestamp( $cutoff_unixtime ); - - $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] ); - if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW, $cutoff ) ) { - $cutoff = $dbr->timestamp( $opts['from'] ); - } else { - $opts->reset( 'from' ); - } - - $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ); - } - /** * @inheritDoc */ diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 4f4570e3f8..531184b65f 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -101,7 +101,6 @@ class SpecialWatchlist extends ChangesListSpecialPage { if ( $this->isStructuredFilterUiEnabled() ) { $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] ); - $output->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false ); $output->addJsConfigVars( 'wgStructuredChangeFiltersEditWatchlistUrl', SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL() @@ -268,26 +267,6 @@ class SpecialWatchlist extends ChangesListSpecialPage { } } - /** - * Get a FormOptions object containing the default options - * - * @return FormOptions - */ - public function getDefaultOptions() { - $opts = parent::getDefaultOptions(); - - $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT ); - $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT ); - - return $opts; - } - - public function validateOptions( FormOptions $opts ) { - $opts->validateBounds( 'days', 0, $this->maxDays ); - $opts->validateIntBounds( 'limit', 0, 5000 ); - parent::validateOptions( $opts ); - } - /** * Get all custom filters * @@ -360,23 +339,6 @@ class SpecialWatchlist extends ChangesListSpecialPage { return $opts; } - /** - * @inheritDoc - */ - protected function buildQuery( &$tables, &$fields, &$conds, &$query_options, - &$join_conds, FormOptions $opts - ) { - $dbr = $this->getDB(); - parent::buildQuery( $tables, $fields, $conds, $query_options, $join_conds, - $opts ); - - // Calculate cutoff - if ( $opts['days'] > 0 ) { - $conds[] = 'rc_timestamp > ' . - $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) ); - } - } - /** * @inheritDoc */ @@ -654,7 +616,10 @@ class SpecialWatchlist extends ChangesListSpecialPage { $timestamp = wfTimestampNow(); $wlInfo = Html::rawElement( 'span', - [ 'class' => 'wlinfo' ], + [ + 'class' => 'wlinfo', + 'data-params' => json_encode( [ 'from' => $timestamp ] ), + ], $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params( $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) )->parse() diff --git a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js index 0155a587fd..debe0b904d 100644 --- a/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js +++ b/resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js @@ -110,7 +110,7 @@ * @param {jQuery} $fieldset */ mw.rcfilters.dm.ChangesListViewModel.prototype.extractNextFrom = function ( $fieldset ) { - var data = $fieldset.find( '.rclistfrom > a' ).data( 'params' ); + var data = $fieldset.find( '.rclistfrom > a, .wlinfo' ).data( 'params' ); this.nextFrom = data ? data.from : null; }; -- 2.20.1