Add <body> class marking whether RCFilters is enabled
[lhc/web/wiklou.git] / includes / specialpage / ChangesListSpecialPage.php
index 52db51a..7f6fdf7 100644 (file)
@@ -519,16 +519,25 @@ abstract class ChangesListSpecialPage extends SpecialPage {
        public function execute( $subpage ) {
                $this->rcSubpage = $subpage;
 
-               $this->setHeaders();
-               $this->outputHeader();
-               $this->addModules();
-
                $rows = $this->getRows();
                $opts = $this->getOptions();
                if ( $rows === false ) {
                        $rows = new FakeResultWrapper( [] );
                }
 
+               // Used by Structured UI app to get results without MW chrome
+               if ( $this->getRequest()->getVal( 'action' ) === 'render' ) {
+                       $this->getOutput()->setArticleBodyOnly( true );
+               }
+
+               // 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;
+                       $this->getOutput()->setStatusCode( $code );
+                       return;
+               }
+
                $batch = new LinkBatch;
                foreach ( $rows as $row ) {
                        $batch->add( NS_USER, $row->rc_user_text );
@@ -542,6 +551,10 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                        }
                }
                $batch->execute();
+
+               $this->setHeaders();
+               $this->outputHeader();
+               $this->addModules();
                $this->webOutput( $rows, $opts );
 
                $rows->free();
@@ -560,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 = [];
@@ -571,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,9 +615,13 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                [
                                        'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days
                                        'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ),
+                                       'limitDefault' => $this->getDefaultLimit(),
                                        'daysArray' => $this->getConfig()->get( 'RCLinkDays' ),
+                                       'daysDefault' => $this->getDefaultDays(),
                                ]
                        );
+               } else {
+                       $out->addBodyClasses( 'mw-rcfilters-disabled' );
                }
        }
 
@@ -793,6 +814,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;
@@ -902,6 +924,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                $opts->add( 'invert', false );
                $opts->add( 'associated', false );
                $opts->add( 'urlversion', 1 );
+               $opts->add( 'tagfilter', '' );
 
                return $opts;
        }
@@ -1153,6 +1176,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                &$join_conds, FormOptions $opts
        ) {
                $dbr = $this->getDB();
+               $isStructuredUI = $this->isStructuredFilterUiEnabled();
 
                foreach ( $this->filterGroups as $filterGroup ) {
                        // URL parameters can be per-group, like 'userExpLevel',
@@ -1162,7 +1186,7 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                                        $query_options, $join_conds, $opts[$filterGroup->getName()] );
                        } else {
                                foreach ( $filterGroup->getFilters() as $filter ) {
-                                       if ( $opts[$filter->getName()] ) {
+                                       if ( $filter->isActive( $opts, $isStructuredUI ) ) {
                                                $filter->modifyQuery( $dbr, $this, $tables, $fields, $conds,
                                                        $query_options, $join_conds );
                                        }
@@ -1532,7 +1556,11 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         *
         * @return bool
         */
-       protected function isStructuredFilterUiEnabled() {
+       public function isStructuredFilterUiEnabled() {
                return $this->getUser()->getOption( 'rcenhancedfilters' );
        }
+
+       abstract function getDefaultLimit();
+
+       abstract function getDefaultDays();
 }