maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ); $this->watchStore = MediaWikiServices::getInstance()->getWatchedItemStore(); $this->isWatchlistExpiryEnabled = $this->getConfig()->get( 'WatchlistExpiry' ); } public function doesWrites() { return true; } /** * Main execution point * * @param string $subpage */ public function execute( $subpage ) { // Anons don't get a watchlist $this->requireLogin( 'watchlistanontext' ); $output = $this->getOutput(); $request = $this->getRequest(); $this->addHelpLink( 'Help:Watching pages' ); $output->addModuleStyles( [ 'mediawiki.special' ] ); $output->addModules( [ 'mediawiki.special.recentchanges', 'mediawiki.special.watchlist', ] ); $mode = SpecialEditWatchlist::getMode( $request, $subpage ); if ( $mode !== false ) { if ( $mode === SpecialEditWatchlist::EDIT_RAW ) { $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' ); } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) { $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' ); } else { $title = SpecialPage::getTitleFor( 'EditWatchlist' ); } $output->redirect( $title->getLocalURL() ); return; } $this->checkPermissions(); $user = $this->getUser(); $opts = $this->getOptions(); $config = $this->getConfig(); if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) && $request->getVal( 'reset' ) && $request->wasPosted() && $user->matchEditToken( $request->getVal( 'token' ) ) ) { MediaWikiServices::getInstance() ->getWatchlistNotificationManager() ->clearAllUserNotifications( $user ); $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) ); return; } parent::execute( $subpage ); if ( $this->isStructuredFilterUiEnabled() ) { $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] ); } } /** * @inheritDoc */ public static function checkStructuredFilterUiEnabled( $user ) { if ( $user instanceof Config ) { wfDeprecated( __METHOD__ . ' with Config argument', '1.34' ); $user = func_get_arg( 1 ); } return !$user->getOption( 'wlenhancedfilters-disable' ); } /** * Return an array of subpages that this special page will accept. * * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch * @return string[] subpages */ public function getSubpagesForPrefixSearch() { return [ 'clear', 'edit', 'raw', ]; } /** * @inheritDoc */ protected function transformFilterDefinition( array $filterDefinition ) { if ( isset( $filterDefinition['showHideSuffix'] ) ) { $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix']; } return $filterDefinition; } /** * @inheritDoc * @suppress PhanUndeclaredMethod */ protected function registerFilters() { parent::registerFilters(); // legacy 'extended' filter $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [ 'name' => 'extended-group', 'filters' => [ [ 'name' => 'extended', 'isReplacedInStructuredUi' => true, 'activeValue' => false, 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ), 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds ) { $nonRevisionTypes = [ RC_LOG ]; $this->getHookRunner()->onSpecialWatchlistGetNonRevisionTypes( $nonRevisionTypes ); if ( $nonRevisionTypes ) { $conds[] = $dbr->makeList( [ 'rc_this_oldid=page_latest', 'rc_type' => $nonRevisionTypes, ], LIST_OR ); } }, ] ], ] ) ); if ( $this->isStructuredFilterUiEnabled() ) { $this->getFilterGroup( 'lastRevision' ) ->getFilter( 'hidepreviousrevisions' ) ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) ); } $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [ 'name' => 'watchlistactivity', 'title' => 'rcfilters-filtergroup-watchlistactivity', 'class' => ChangesListStringOptionsFilterGroup::class, 'priority' => 3, 'isFullCoverage' => true, 'filters' => [ [ 'name' => 'unseen', 'label' => 'rcfilters-filter-watchlistactivity-unseen-label', 'description' => 'rcfilters-filter-watchlistactivity-unseen-description', 'cssClassSuffix' => 'watchedunseen', 'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) { return !$this->isChangeEffectivelySeen( $rc ); }, ], [ 'name' => 'seen', 'label' => 'rcfilters-filter-watchlistactivity-seen-label', 'description' => 'rcfilters-filter-watchlistactivity-seen-description', 'cssClassSuffix' => 'watchedseen', 'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) { return $this->isChangeEffectivelySeen( $rc ); } ], ], 'default' => ChangesListStringOptionsFilterGroup::NONE, 'queryCallable' => function ( $specialPageClassName, $context, IDatabase $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) { if ( $selectedValues === [ 'seen' ] ) { $conds[] = $dbr->makeList( [ 'wl_notificationtimestamp IS NULL', 'rc_timestamp < wl_notificationtimestamp' ], LIST_OR ); } elseif ( $selectedValues === [ 'unseen' ] ) { $conds[] = $dbr->makeList( [ 'wl_notificationtimestamp IS NOT NULL', 'rc_timestamp >= wl_notificationtimestamp' ], LIST_AND ); } } ] ) ); $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' ) ); // Selecting both hideanons and hideliu on watchlist preferances // gives mutually exclusive filters, so those are ignored if ( $user->getBoolOption( 'watchlisthideanons' ) && !$user->getBoolOption( 'watchlisthideliu' ) ) { $this->getFilterGroup( 'userExpLevel' ) ->setDefault( 'registered' ); } if ( $user->getBoolOption( 'watchlisthideliu' ) && !$user->getBoolOption( 'watchlisthideanons' ) ) { $this->getFilterGroup( 'userExpLevel' ) ->setDefault( 'unregistered' ); } $reviewStatus = $this->getFilterGroup( 'reviewStatus' ); if ( $reviewStatus !== null ) { // Conditional on feature being available and rights if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) { $reviewStatus->setDefault( 'unpatrolled' ); $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' ); $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' ); $legacyHidePatrolled->setDefault( true ); } } $authorship = $this->getFilterGroup( 'authorship' ); $hideMyself = $authorship->getFilter( 'hidemyself' ); $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) ); $changeType = $this->getFilterGroup( 'changeType' ); $hideCategorization = $changeType->getFilter( 'hidecategorization' ); if ( $hideCategorization !== null ) { // Conditional on feature being available $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) ); } } /** * Fetch values for a FormOptions object from the WebRequest associated with this instance. * * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones) * to the current ones. * * @param FormOptions $opts * @return FormOptions */ protected function fetchOptionsFromRequest( $opts ) { static $compatibilityMap = [ 'hideMinor' => 'hideminor', 'hideBots' => 'hidebots', 'hideAnons' => 'hideanons', 'hideLiu' => 'hideliu', 'hidePatrolled' => 'hidepatrolled', 'hideOwn' => 'hidemyself', ]; $params = $this->getRequest()->getValues(); foreach ( $compatibilityMap as $from => $to ) { if ( isset( $params[$from] ) ) { $params[$to] = $params[$from]; unset( $params[$from] ); } } if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) { $allBooleansFalse = []; // If the user submitted the form, start with a baseline of "all // booleans are false", then change the ones they checked. This // means we ignore the defaults. // This is how we handle the fact that HTML forms don't submit // unchecked boxes. foreach ( $this->getLegacyShowHideFilters() as $filter ) { $allBooleansFalse[ $filter->getName() ] = false; } $params = $params + $allBooleansFalse; } // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization // methods defined on WebRequest and removing this dependency would cause some code duplication. $request = new DerivativeRequest( $this->getRequest(), $params ); $opts->fetchValuesFromRequest( $request ); return $opts; } /** * @inheritDoc */ protected function doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts ) { $dbr = $this->getDB(); $user = $this->getUser(); $rcQuery = RecentChange::getQueryInfo(); $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] ); $fields = array_merge( $rcQuery['fields'], $fields ); $join_conds = array_merge( [ 'watchlist' => [ 'JOIN', [ 'wl_user' => $user->getId(), 'wl_namespace=rc_namespace', 'wl_title=rc_title' ], ], ], $rcQuery['joins'], $join_conds ); if ( $this->isWatchlistExpiryEnabled ) { $tables[] = 'watchlist_expiry'; $fields[] = 'we_expiry'; $join_conds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ]; $conds[] = 'we_expiry IS NULL OR we_expiry > ' . $dbr->addQuotes( $dbr->timestamp() ); } $tables[] = 'page'; $fields[] = 'page_latest'; $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ]; $fields[] = 'wl_notificationtimestamp'; // Log entries with DELETED_ACTION must not show up unless the user has // the necessary rights. $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); if ( !$permissionManager->userHasRight( $user, 'deletedhistory' ) ) { $bitmask = LogPage::DELETED_ACTION; } elseif ( !$permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) { $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED; } else { $bitmask = 0; } if ( $bitmask ) { $conds[] = $dbr->makeList( [ 'rc_type != ' . RC_LOG, $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask", ], LIST_OR ); } $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : []; ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $query_options, $tagFilter ); $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts ); if ( $this->areFiltersInConflict() ) { return false; } $orderByAndLimit = [ 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $opts['limit'] ]; if ( in_array( 'DISTINCT', $query_options ) ) { // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags. // In order to prevent DISTINCT from causing query performance problems, // we have to GROUP BY the primary key. This in turn requires us to add // the primary key to the end of the ORDER BY, and the old ORDER BY to the // start of the GROUP BY $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC'; $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id'; } // array_merge() is used intentionally here so that hooks can, should // they so desire, override the ORDER BY / LIMIT condition(s) $query_options = array_merge( $orderByAndLimit, $query_options ); return $dbr->select( $tables, $fields, $conds, __METHOD__, $query_options, $join_conds ); } /** * Return a IDatabase object for reading * * @return IDatabase */ protected function getDB() { return wfGetDB( DB_REPLICA, 'watchlist' ); } /** * Output feed links. */ public function outputFeedLinks() { $user = $this->getUser(); $wlToken = $user->getTokenFromOption( 'watchlisttoken' ); if ( $wlToken ) { $this->addFeedLinks( [ 'action' => 'feedwatchlist', 'allrev' => 1, 'wlowner' => $user->getName(), 'wltoken' => $wlToken, ] ); } } /** * Build and output the actual changes list. * * @param IResultWrapper $rows Database rows * @param FormOptions $opts */ public function outputChangesList( $rows, $opts ) { $dbr = $this->getDB(); $user = $this->getUser(); $output = $this->getOutput(); // Show a message about replica DB lag, if applicable $lag = $dbr->getSessionLagStatus()['lag']; if ( $lag > 0 ) { $output->showLagWarning( $lag ); } // If there are no rows to display, show message before trying to render the list if ( $rows->numRows() == 0 ) { $output->wrapWikiMsg( "