Merge "getConfiguration: Don't bail when a valid variable is set null"
[lhc/web/wiklou.git] / includes / specialpage / ChangesListSpecialPage.php
index 0762bf7..d7519d3 100644 (file)
@@ -32,6 +32,12 @@ use Wikimedia\Rdbms\IDatabase;
  * @ingroup SpecialPage
  */
 abstract class ChangesListSpecialPage extends SpecialPage {
+       /**
+        * Preference name for saved queries. Subclasses that use saved queries should override this.
+        * @var string
+        */
+       protected static $savedQueriesPreferenceName;
+
        /** @var string */
        protected $rcSubpage;
 
@@ -78,6 +84,9 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        public function __construct( $name, $restriction ) {
                parent::__construct( $name, $restriction );
 
+               $nonRevisionTypes = [ RC_LOG ];
+               Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
+
                $this->filterGroupDefinitions = [
                        [
                                'name' => 'registration',
@@ -316,8 +325,14 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                                'description' => 'rcfilters-filter-lastrevision-description',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
-                                                       &$query_options, &$join_conds ) {
-                                                       $conds[] = 'rc_this_oldid <> page_latest';
+                                                       &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
+                                                       $conds[] = $dbr->makeList(
+                                                               [
+                                                                       'rc_this_oldid <> page_latest',
+                                                                       'rc_type' => $nonRevisionTypes,
+                                                               ],
+                                                               LIST_OR
+                                                       );
                                                },
                                                'cssClassSuffix' => 'last',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
@@ -330,8 +345,14 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                                'description' => 'rcfilters-filter-previousrevision-description',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
-                                                       &$query_options, &$join_conds ) {
-                                                       $conds[] = 'rc_this_oldid = page_latest';
+                                                       &$query_options, &$join_conds ) use ( $nonRevisionTypes ) {
+                                                       $conds[] = $dbr->makeList(
+                                                               [
+                                                                       'rc_this_oldid = page_latest',
+                                                                       'rc_type' => $nonRevisionTypes,
+                                                               ],
+                                                               LIST_OR
+                                                       );
                                                },
                                                'cssClassSuffix' => 'previous',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
@@ -533,7 +554,7 @@ 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 : 304;
+                       $code = $rows->numRows() > 0 ? 200 : 204;
                        $this->getOutput()->setStatusCode( $code );
                        return;
                }
@@ -594,18 +615,8 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                )
                        );
 
-                       $experimentalStructuredChangeFilters =
-                               $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
-
                        $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
-                       $out->addJsConfigVars(
-                               'wgStructuredChangeFiltersEnableExperimentalViews',
-                               $experimentalStructuredChangeFilters
-                       );
-                       $out->addJsConfigVars(
-                               'wgStructuredChangeFiltersEnableLiveUpdate',
-                               $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
-                       );
+
                        $out->addJsConfigVars(
                                'wgRCFiltersChangeTags',
                                $this->buildChangeTagList()
@@ -620,6 +631,26 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                        'daysDefault' => $this->getDefaultDays(),
                                ]
                        );
+
+                       $out->addJsConfigVars(
+                               'StructuredChangeFiltersLiveUpdatePollingRate',
+                               $this->getConfig()->get( 'StructuredChangeFiltersLiveUpdatePollingRate' )
+                       );
+
+                       if ( static::$savedQueriesPreferenceName ) {
+                               $savedQueries = FormatJson::decode(
+                                       $this->getUser()->getOption( static::$savedQueriesPreferenceName )
+                               );
+                               if ( $savedQueries && isset( $savedQueries->default ) ) {
+                                       // If there is a default saved query, show a loading spinner,
+                                       // since the frontend is going to reload the results
+                                       $out->addBodyClasses( 'mw-rcfilters-ui-loading' );
+                               }
+                               $out->addJsConfigVars(
+                                       'wgStructuredChangeFiltersSavedQueriesPreferenceName',
+                                       static::$savedQueriesPreferenceName
+                               );
+                       }
                } else {
                        $out->addBodyClasses( 'mw-rcfilters-disabled' );
                }
@@ -1584,5 +1615,12 @@ abstract class ChangesListSpecialPage extends SpecialPage {
 
        abstract function getDefaultLimit();
 
+       /**
+        * Get the default value of the number of days to display when loading
+        * the result set.
+        * Supports fractional values, and should be cast to a float.
+        *
+        * @return float
+        */
        abstract function getDefaultDays();
 }