WLFilters: Live update and View newest
authorStephane Bisson <sbisson@wikimedia.org>
Thu, 21 Sep 2017 19:44:02 +0000 (15:44 -0400)
committerStephane Bisson <sbisson@wikimedia.org>
Mon, 25 Sep 2017 12:49:07 +0000 (08:49 -0400)
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

includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialWatchlist.php
resources/src/mediawiki.rcfilters/dm/mw.rcfilters.dm.ChangesListViewModel.js

index d7519d3..6fd33a7 100644 (file)
@@ -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 );
        }
 
        /**
index 34a7714..522a0a6 100644 (file)
@@ -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
         */
index 4f4570e..531184b 100644 (file)
@@ -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()
index 0155a58..debe0b9 100644 (file)
         * @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;
        };