Merge "RCFilters: Allow empty saved query"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 07889b7..2750551 100644 (file)
@@ -104,13 +104,23 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                                'wgStructuredChangeFiltersSavedQueriesPreferenceName',
                                'rcfilters-wl-saved-queries'
                        );
+                       $output->addJsConfigVars(
+                               'wgStructuredChangeFiltersEditWatchlistUrl',
+                               SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
+                       );
                }
        }
 
-       protected function isStructuredFilterUiEnabled() {
-               return parent::isStructuredFilterUiEnabled()
-                       && ( $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' )
-                               || $this->getRequest()->getBool( 'rcfilters' ) );
+       public function isStructuredFilterUiEnabled() {
+               return $this->getRequest()->getBool( 'rcfilters' ) || (
+                       $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
+                       $this->getUser()->getOption( 'rcenhancedfilters' )
+               );
+       }
+
+       public function isStructuredFilterUiEnabledByDefault() {
+               return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
+                       $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
        }
 
        /**
@@ -267,10 +277,9 @@ class SpecialWatchlist extends ChangesListSpecialPage {
         */
        public function getDefaultOptions() {
                $opts = parent::getDefaultOptions();
-               $user = $this->getUser();
 
-               $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions::FLOAT );
-               $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions::INT );
+               $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT );
+               $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT );
 
                return $opts;
        }
@@ -829,21 +838,29 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
 
                // Show watchlist header
-               $form .= "<p>";
+               $watchlistHeader = '';
                if ( $numItems == 0 ) {
-                       $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
+                       $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
                } else {
-                       $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
+                       $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
                        if ( $this->getConfig()->get( 'EnotifWatchlist' )
                                && $user->getOption( 'enotifwatchlistpages' )
                        ) {
-                               $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
+                               $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
                        }
                        if ( $showUpdatedMarker ) {
-                               $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
+                               $watchlistHeader .= $this->msg(
+                                       $this->isStructuredFilterUiEnabled() ?
+                                               'rcfilters-watchlist-showupdated' :
+                                               'wlheader-showupdated'
+                               )->parse() . "\n";
                        }
                }
-               $form .= "</p>";
+               $form .= Html::rawElement(
+                       'div',
+                       [ 'class' => 'watchlistDetails' ],
+                       $watchlistHeader
+               );
 
                if ( $numItems > 0 && $showUpdatedMarker ) {
                        $form .= Xml::openElement( 'form', [ 'method' => 'post',
@@ -900,6 +917,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        function getDefaultDays() {
-               return $this->getUser()->getIntOption( 'watchlistdays' );
+               return floatval( $this->getUser()->getOption( 'watchlistdays' ) );
        }
 }