Merge "Drop index oi_name_archive_name on table oldimage"
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
index 4824961..5d7fa5d 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\ResultWrapper;
 
 /**
  * A special page that lists last changes made to the wiki,
@@ -52,6 +53,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $this->addHelpLink( 'Help:Watching pages' );
                $output->addModules( [
                        'mediawiki.special.changeslist.visitedstatus',
+                       'mediawiki.special.watchlist',
                ] );
 
                $mode = SpecialEditWatchlist::getMode( $request, $subpage );
@@ -102,6 +104,56 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                ];
        }
 
+       /**
+        * @inheritdoc
+        */
+       protected function registerFiltersFromDefinitions( array $definition ) {
+               foreach ( $definition as $groupName => &$groupDefinition ) {
+                       foreach ( $groupDefinition['filters'] as &$filterDefinition ) {
+                               if ( isset( $filterDefinition['showHideSuffix'] ) ) {
+                                       $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
+                               }
+                       }
+               }
+
+               parent::registerFiltersFromDefinitions( $definition );
+       }
+
+       /**
+        * @inheritdoc
+        */
+       protected function registerFilters() {
+               parent::registerFilters();
+
+               $user = $this->getUser();
+
+               $significance = $this->getFilterGroup( 'significance' );
+               $hideMinor = $significance->getFilter( 'hideminor' );
+               $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
+
+               $automated = $this->getFilterGroup( 'automated' );
+               $hideBots = $automated->getFilter( 'hidebots' );
+               $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
+
+               $registration = $this->getFilterGroup( 'registration' );
+               $hideAnons = $registration->getFilter( 'hideanons' );
+               $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
+               $hideLiu = $registration->getFilter( 'hideliu' );
+               $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
+
+               $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
+               $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
+               $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
+
+               $authorship = $this->getFilterGroup( 'authorship' );
+               $hideMyself = $authorship->getFilter( 'hidemyself' );
+               $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
+
+               $changeType = $this->getFilterGroup( 'changeType' );
+               $hideCategorization = $changeType->getFilter( 'hidecategorization' );
+               $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
+       }
+
        /**
         * Get a FormOptions object containing the default options
         *
@@ -118,19 +170,11 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                        return $opts;
                }
 
-               $opts->add( 'hideminor', $user->getBoolOption( 'watchlisthideminor' ) );
-               $opts->add( 'hidebots', $user->getBoolOption( 'watchlisthidebots' ) );
-               $opts->add( 'hideanons', $user->getBoolOption( 'watchlisthideanons' ) );
-               $opts->add( 'hideliu', $user->getBoolOption( 'watchlisthideliu' ) );
-               $opts->add( 'hidepatrolled', $user->getBoolOption( 'watchlisthidepatrolled' ) );
-               $opts->add( 'hidemyself', $user->getBoolOption( 'watchlisthideown' ) );
-               $opts->add( 'hidecategorization', $user->getBoolOption( 'watchlisthidecategorization' ) );
-
                return $opts;
        }
 
        /**
-        * Get custom show/hide filters
+        * Get all custom filters
         *
         * @return array Map of filter URL param names to properties (msg/default)
         */
@@ -179,32 +223,28 @@ class SpecialWatchlist extends ChangesListSpecialPage {
        }
 
        /**
-        * Return an array of conditions depending of options set in $opts
-        *
-        * @param FormOptions $opts
-        * @return array
+        * @inheritdoc
         */
-       public function buildMainQueryConds( FormOptions $opts ) {
+       protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
+               &$join_conds, FormOptions $opts ) {
+
                $dbr = $this->getDB();
-               $conds = parent::buildMainQueryConds( $opts );
+               parent::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
+                       $opts );
 
                // Calculate cutoff
                if ( $opts['days'] > 0 ) {
                        $conds[] = 'rc_timestamp > ' .
                                $dbr->addQuotes( $dbr->timestamp( time() - intval( $opts['days'] * 86400 ) ) );
                }
-
-               return $conds;
        }
 
        /**
-        * Process the query
-        *
-        * @param array $conds
-        * @param FormOptions $opts
-        * @return bool|ResultWrapper Result or false (for Recentchangeslinked only)
+        * @inheritdoc
         */
-       public function doMainQuery( $conds, $opts ) {
+       protected function doMainQuery( $tables, $fields, $conds, $query_options,
+               $join_conds, FormOptions $opts ) {
+
                $dbr = $this->getDB();
                $user = $this->getUser();
 
@@ -229,19 +269,23 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                        $usePage = true;
                }
 
-               $tables = [ 'recentchanges', 'watchlist' ];
-               $fields = RecentChange::selectFields();
-               $query_options = [ 'ORDER BY' => 'rc_timestamp DESC' ];
-               $join_conds = [
-                       'watchlist' => [
-                               'INNER JOIN',
-                               [
-                                       'wl_user' => $user->getId(),
-                                       'wl_namespace=rc_namespace',
-                                       'wl_title=rc_title'
+               $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
+               $fields = array_merge( RecentChange::selectFields(), $fields );
+
+               $query_options = array_merge( [ 'ORDER BY' => 'rc_timestamp DESC' ], $query_options );
+               $join_conds = array_merge(
+                       [
+                               'watchlist' => [
+                                       'INNER JOIN',
+                                       [
+                                               'wl_user' => $user->getId(),
+                                               'wl_namespace=rc_namespace',
+                                               'wl_title=rc_title'
+                                       ],
                                ],
                        ],
-               ];
+                       $join_conds
+               );
 
                if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
                        $fields[] = 'wl_notificationtimestamp';
@@ -359,7 +403,7 @@ class SpecialWatchlist extends ChangesListSpecialPage {
 
                $dbr->dataSeek( $rows, 0 );
 
-               $list = ChangesList::newFromContext( $this->getContext() );
+               $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
                $list->setWatchlistDivs();
                $list->initChangesListRows( $rows );
                $dbr->dataSeek( $rows, 0 );
@@ -421,12 +465,6 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $user = $this->getUser();
                $out = $this->getOutput();
 
-               // if the user wishes, that the watchlist is reloaded, whenever a filter changes,
-               // add the module for that
-               if ( $user->getBoolOption( 'watchlistreloadautomatically' ) ) {
-                       $out->addModules( [ 'mediawiki.special.watchlist' ] );
-               }
-
                $out->addSubtitle(
                        $this->msg( 'watchlistfor2', $user->getName() )
                                ->rawParams( SpecialEditWatchlist::buildTools(
@@ -452,30 +490,23 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                $cutofflinks = $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts );
 
                # Spit out some control panel links
-               $filters = [
-                       'hideminor' => 'wlshowhideminor',
-                       'hidebots' => 'wlshowhidebots',
-                       'hideanons' => 'wlshowhideanons',
-                       'hideliu' => 'wlshowhideliu',
-                       'hidemyself' => 'wlshowhidemine',
-                       'hidepatrolled' => 'wlshowhidepatr'
-               ];
-
-               if ( $this->getConfig()->get( 'RCWatchCategoryMembership' ) ) {
-                       $filters['hidecategorization'] = 'wlshowhidecategorization';
-               }
-
-               foreach ( $this->getCustomFilters() as $key => $params ) {
-                       $filters[$key] = $params['msg'];
-               }
-               // Disable some if needed
-               if ( !$user->useRCPatrol() ) {
-                       unset( $filters['hidepatrolled'] );
-               }
-
                $links = [];
-               foreach ( $filters as $name => $msg ) {
-                       $links[] = $this->showHideCheck( $nondefaults, $msg, $name, $opts[$name] );
+               $context = $this->getContext();
+               $namesOfDisplayedFilters = [];
+               foreach ( $this->getFilterGroups() as $groupName => $group ) {
+                       if ( !$group->isPerGroupRequestParameter() ) {
+                               foreach ( $group->getFilters() as $filterName => $filter ) {
+                                       if ( $filter->displaysOnUnstructuredUi( $this ) ) {
+                                               $namesOfDisplayedFilters[] = $filterName;
+                                               $links[] = $this->showHideCheck(
+                                                       $nondefaults,
+                                                       $filter->getShowHide(),
+                                                       $filterName,
+                                                       $opts[$filterName]
+                                               );
+                                       }
+                               }
+                       }
                }
 
                $hiddenFields = $nondefaults;
@@ -484,8 +515,8 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                unset( $hiddenFields['invert'] );
                unset( $hiddenFields['associated'] );
                unset( $hiddenFields['days'] );
-               foreach ( $filters as $key => $value ) {
-                       unset( $hiddenFields[$key] );
+               foreach ( $namesOfDisplayedFilters as $filterName ) {
+                       unset( $hiddenFields[$filterName] );
                }
 
                # Create output
@@ -608,7 +639,8 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                        $form .= Xml::openElement( 'form', [ 'method' => 'post',
                                'action' => $this->getPageTitle()->getLocalURL(),
                                'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
-                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(), [ 'name' => 'dummy' ] ) . "\n" .
+                       Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
+                               [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
                        Html::hidden( 'reset', 'all' ) . "\n";
                        foreach ( $nondefaults as $key => $value ) {
                                $form .= Html::hidden( $key, $value ) . "\n";