Merge "mw.loader: Use Object.create() instead of $.extend() where possible"
[lhc/web/wiklou.git] / includes / specialpage / ChangesListSpecialPage.php
index 04d03f5..98b7aa1 100644 (file)
@@ -533,7 +533,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;
                }
@@ -573,10 +573,12 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        /**
         * Include the modules and configuration for the RCFilters app.
         * Conditional on the user having the feature enabled.
+        *
+        * If it is disabled, add a <body> class marking that
         */
        protected function includeRcFiltersApp() {
+               $out = $this->getOutput();
                if ( $this->isStructuredFilterUiEnabled() ) {
-                       $out = $this->getOutput();
                        $jsData = $this->getStructuredFilterJsData();
 
                        $messages = [];
@@ -584,6 +586,8 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                $messages[$key] = $this->msg( $key )->plain();
                        }
 
+                       $out->addBodyClasses( 'mw-rcfilters-enabled' );
+
                        $out->addHTML(
                                ResourceLoader::makeInlineScript(
                                        ResourceLoader::makeMessageSetScript( $messages )
@@ -598,10 +602,6 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                'wgStructuredChangeFiltersEnableExperimentalViews',
                                $experimentalStructuredChangeFilters
                        );
-                       $out->addJsConfigVars(
-                               'wgStructuredChangeFiltersEnableLiveUpdate',
-                               $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
-                       );
                        $out->addJsConfigVars(
                                'wgRCFiltersChangeTags',
                                $this->buildChangeTagList()
@@ -616,6 +616,8 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                        'daysDefault' => $this->getDefaultDays(),
                                ]
                        );
+               } else {
+                       $out->addBodyClasses( 'mw-rcfilters-disabled' );
                }
        }
 
@@ -808,6 +810,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         * ChangesListFilterGroup constructors.
         *
         * There is light processing to simplify core maintenance.
+        * @param array $definition
         */
        protected function registerFiltersFromDefinitions( array $definition ) {
                $autoFillPriority = -1;
@@ -1550,10 +1553,39 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         * @return bool
         */
        public function isStructuredFilterUiEnabled() {
-               return $this->getUser()->getOption( 'rcenhancedfilters' );
+               if ( $this->getRequest()->getBool( 'rcfilters' ) ) {
+                       return true;
+               }
+
+               if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
+                       return !$this->getUser()->getOption( 'rcenhancedfilters-disable' );
+               } else {
+                       return $this->getUser()->getOption( 'rcenhancedfilters' );
+               }
+       }
+
+       /**
+        * Check whether the structured filter UI is enabled by default (regardless of
+        * this particular user's setting)
+        *
+        * @return bool
+        */
+       public function isStructuredFilterUiEnabledByDefault() {
+               if ( $this->getConfig()->get( 'StructuredChangeFiltersShowPreference' ) ) {
+                       return !$this->getUser()->getDefaultOption( 'rcenhancedfilters-disable' );
+               } else {
+                       return $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
+               }
        }
 
        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();
 }