X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/specials/SpecialWatchlist.php diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index bb1c194d..4f4570e3 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -18,466 +18,905 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @ingroup SpecialPage Watchlist + * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; +use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IDatabase; + /** - * Constructor + * A special page that lists last changes made to the wiki, + * limited to user-defined list of titles. * - * @param $par Parameter passed to the page + * @ingroup SpecialPage */ -function wfSpecialWatchlist( $par ) { - global $wgUser, $wgOut, $wgLang, $wgRequest; - global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; - - // Add feed links - $wlToken = $wgUser->getOption( 'watchlisttoken' ); - if (!$wlToken) { - $wlToken = sha1( mt_rand() . microtime( true ) ); - $wgUser->setOption( 'watchlisttoken', $wlToken ); - $wgUser->saveSettings(); - } - - global $wgFeedClasses; - $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev', - 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ); - $feedTemplate = wfScript('api').'?'; - - foreach( $wgFeedClasses as $format => $class ) { - $theseParams = $apiParams + array( 'feedformat' => $format ); - $url = $feedTemplate . wfArrayToCGI( $theseParams ); - $wgOut->addFeedLink( $format, $url ); +class SpecialWatchlist extends ChangesListSpecialPage { + protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries'; + + private $maxDays; + + public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) { + parent::__construct( $page, $restriction ); + + $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ); } - $skin = $wgUser->getSkin(); - $specialTitle = SpecialPage::getTitleFor( 'Watchlist' ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - - # Anons don't get a watchlist - if( $wgUser->isAnon() ) { - $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); - $llink = $skin->linkKnown( - SpecialPage::getTitleFor( 'Userlogin' ), - wfMsgHtml( 'loginreqlink' ), - array(), - array( 'returnto' => $specialTitle->getPrefixedText() ) - ); - $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) ); - return; + public function doesWrites() { + return true; } - $wgOut->setPageTitle( wfMsg( 'watchlist' ) ); + /** + * Main execution point + * + * @param string $subpage + */ + function execute( $subpage ) { + // Anons don't get a watchlist + $this->requireLogin( 'watchlistanontext' ); + + $output = $this->getOutput(); + $request = $this->getRequest(); + $this->addHelpLink( 'Help:Watching pages' ); + $output->addModules( [ + 'mediawiki.special.changeslist.visitedstatus', + 'mediawiki.special.watchlist', + ] ); + $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] ); + + $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; + } - $sub = wfMsgExt( 'watchlistfor2', array( 'parseinline', 'replaceafter' ), $wgUser->getName(), WatchlistEditor::buildTools( $wgUser->getSkin() ) ); - $wgOut->setSubtitle( $sub ); + $this->checkPermissions(); - if( ( $mode = WatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) { - $editor = new WatchlistEditor(); - $editor->execute( $wgUser, $wgOut, $wgRequest, $mode ); - return; - } + $user = $this->getUser(); + $opts = $this->getOptions(); - $uid = $wgUser->getId(); - if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) && - $wgRequest->wasPosted() ) - { - $wgUser->clearAllNotifications( $uid ); - $wgOut->redirect( $specialTitle->getFullUrl() ); - return; - } + $config = $this->getConfig(); + if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) ) + && $request->getVal( 'reset' ) + && $request->wasPosted() + && $user->matchEditToken( $request->getVal( 'token' ) ) + ) { + $user->clearAllNotifications(); + $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) ); - $defaults = array( - /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */ - /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ), - /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ), - /* bool */ 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ), - /* bool */ 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ), - /* bool */ 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ), - /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ), - /* ? */ 'namespace' => 'all', - /* ? */ 'invert' => false, - ); - - extract($defaults); - - # Extract variables from the request, falling back to user preferences or - # other default values if these don't exist - $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) ); - $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' ); - $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' ); - $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanons' ); - $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' ); - $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' ); - $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' ); - - # Get query variables - $days = $wgRequest->getVal( 'days' , $prefs['days'] ); - $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] ); - $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] ); - $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] ); - $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] ); - $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] ); - $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] ); - - # Get namespace value, if supplied, and prepare a WHERE fragment - $nameSpace = $wgRequest->getIntOrNull( 'namespace' ); - $invert = $wgRequest->getIntOrNull( 'invert' ); - if( !is_null( $nameSpace ) ) { - $nameSpace = intval( $nameSpace ); - if( $invert && $nameSpace !== 'all' ) - $nameSpaceClause = "rc_namespace != $nameSpace"; - else - $nameSpaceClause = "rc_namespace = $nameSpace"; - } else { - $nameSpace = ''; - $nameSpaceClause = ''; - } + return; + } - $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); - $recentchanges = $dbr->tableName( 'recentchanges' ); + parent::execute( $subpage ); - $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)', - array( 'wl_user' => $uid ), __METHOD__ ); - // Adjust for page X, talk:page X, which are both stored separately, - // but treated together - $nitems = floor($watchlistCount / 2); + if ( $this->isStructuredFilterUiEnabled() ) { + $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] ); - if( is_null($days) || !is_numeric($days) ) { - $big = 1000; /* The magical big */ - if($nitems > $big) { - # Set default cutoff shorter - $days = $defaults['days'] = (12.0 / 24.0); # 12 hours... - } else { - $days = $defaults['days']; # default cutoff for shortlisters + $output->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false ); + $output->addJsConfigVars( + 'wgStructuredChangeFiltersEditWatchlistUrl', + SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL() + ); } - } else { - $days = floatval($days); } - // Dump everything here - $nondefaults = array(); - - wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults ); - wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults ); - - if( $nitems == 0 ) { - $wgOut->addWikiMsg( 'nowatchlist' ); - return; + 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' ); + } + + /** + * 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', + ]; } - # Possible where conditions - $conds = array(); + /** + * @inheritDoc + */ + protected function transformFilterDefinition( array $filterDefinition ) { + if ( isset( $filterDefinition['showHideSuffix'] ) ) { + $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix']; + } - if( $days > 0 ) { - $conds[] = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'"; + return $filterDefinition; } - # If the watchlist is relatively short, it's simplest to zip - # down its entirety and then sort the results. + /** + * @inheritDoc + */ + 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 ]; + Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$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' ) ); + } - # If it's relatively long, it may be worth our while to zip - # through the time-sorted page list checking for watched items. + $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, $rc ) { + $changeTs = $rc->getAttribute( 'rc_timestamp' ); + $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' ); + return $lastVisitTs !== null && $changeTs >= $lastVisitTs; + }, + ], + [ + 'name' => 'seen', + 'label' => 'rcfilters-filter-watchlistactivity-seen-label', + 'description' => 'rcfilters-filter-watchlistactivity-seen-description', + 'cssClassSuffix' => 'watchedseen', + 'isRowApplicableCallable' => function ( $ctx, $rc ) { + $changeTs = $rc->getAttribute( 'rc_timestamp' ); + $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' ); + return $lastVisitTs === null || $changeTs < $lastVisitTs; + } + ], + ], + 'default' => ChangesListStringOptionsFilterGroup::NONE, + 'queryCallable' => function ( $specialPageClassName, $context, $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' ) ); + + $reviewStatus = $this->getFilterGroup( 'reviewStatus' ); + if ( $reviewStatus !== null ) { + // Conditional on feature being available and rights + $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' ); + $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) ); + } - # Up estimate of watched items by 15% to compensate for talk pages... + $authorship = $this->getFilterGroup( 'authorship' ); + $hideMyself = $authorship->getFilter( 'hidemyself' ); + $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) ); - # Toggles - if( $hideOwn ) { - $conds[] = "rc_user != $uid"; - } - if( $hideBots ) { - $conds[] = 'rc_bot = 0'; - } - if( $hideMinor ) { - $conds[] = 'rc_minor = 0'; - } - if( $hideLiu ) { - $conds[] = 'rc_user = 0'; - } - if( $hideAnons ) { - $conds[] = 'rc_user != 0'; + $changeType = $this->getFilterGroup( 'changeType' ); + $hideCategorization = $changeType->getFilter( 'hidecategorization' ); + if ( $hideCategorization !== null ) { + // Conditional on feature being available + $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) ); + } } - if ( $wgUser->useRCPatrol() && $hidePatrolled ) { - $conds[] = 'rc_patrolled != 1'; + + /** + * Get a FormOptions object containing the default options + * + * @return FormOptions + */ + public function getDefaultOptions() { + $opts = parent::getDefaultOptions(); + + $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT ); + $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT ); + + return $opts; } - if( $nameSpaceClause ) { - $conds[] = $nameSpaceClause; + + public function validateOptions( FormOptions $opts ) { + $opts->validateBounds( 'days', 0, $this->maxDays ); + $opts->validateIntBounds( 'limit', 0, 5000 ); + parent::validateOptions( $opts ); } - # Toggle watchlist content (all recent edits or just the latest) - if( $wgUser->getOption( 'extendwatchlist' )) { - $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) ); - $usePage = false; - } else { - # Top log Ids for a page are not stored - $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG; - $limitWatchlist = 0; - $usePage = true; + /** + * Get all custom filters + * + * @return array Map of filter URL param names to properties (msg/default) + */ + protected function getCustomFilters() { + if ( $this->customFilters === null ) { + $this->customFilters = parent::getCustomFilters(); + Hooks::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters ], '1.23' ); + } + + return $this->customFilters; } - # Show a message about slave lag, if applicable - if( ( $lag = $dbr->getLag() ) > 0 ) - $wgOut->showLagWarning( $lag ); + /** + * 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] ); + } + } - # Create output form - $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) ); + 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->filterGroups as $filterGroup ) { + if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) { + /** @var ChangesListBooleanFilter $filter */ + foreach ( $filterGroup->getFilters() as $filter ) { + if ( $filter->displaysOnUnstructuredUi() ) { + $allBooleansFalse[$filter->getName()] = false; + } + } + } + } + + $params = $params + $allBooleansFalse; + } - # Show watchlist header - $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) ); + // 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 ); - if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { - $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n"; + return $opts; } - if( $wgShowUpdatedMarker ) { - $form .= Xml::openElement( 'form', array( 'method' => 'post', - 'action' => $specialTitle->getLocalUrl(), - 'id' => 'mw-watchlist-resetbutton' ) ) . - wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' . - Xml::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) . - Html::hidden( 'reset', 'all' ) . - Xml::closeElement( 'form' ); + + /** + * @inheritDoc + */ + protected function buildQuery( &$tables, &$fields, &$conds, &$query_options, + &$join_conds, FormOptions $opts + ) { + $dbr = $this->getDB(); + parent::buildQuery( $tables, $fields, $conds, $query_options, $join_conds, + $opts ); + + // Calculate cutoff + if ( $opts['days'] > 0 ) { + $conds[] = 'rc_timestamp > ' . + $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) ); + } } - $form .= '
'; - $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' '; - $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' '; - $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' '; - $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '
'; - $form .= Html::hidden( 'days', $days ); - if( $hideMinor ) - $form .= Html::hidden( 'hideMinor', 1 ); - if( $hideBots ) - $form .= Html::hidden( 'hideBots', 1 ); - if( $hideAnons ) - $form .= Html::hidden( 'hideAnons', 1 ); - if( $hideLiu ) - $form .= Html::hidden( 'hideLiu', 1 ); - if( $hideOwn ) - $form .= Html::hidden( 'hideOwn', 1 ); - $form .= Xml::closeElement( 'form' ); - $form .= Xml::closeElement( 'fieldset' ); - $wgOut->addHTML( $form ); - - # If there's nothing to show, stop here - if( $numRows == 0 ) { - $wgOut->addWikiMsg( 'watchnochange' ); - return; - } + $s = $list->beginRecentChangesList(); - /* End bottom header */ + if ( $this->isStructuredFilterUiEnabled() ) { + $s .= $this->makeLegend(); + } - /* Do link batch query */ - $linkBatch = new LinkBatch; - foreach ( $res as $row ) { - $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text ); - if ( $row->rc_user != 0 ) { - $linkBatch->add( NS_USER, $userNameUnderscored ); + $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' ); + $counter = 1; + foreach ( $rows as $obj ) { + # Make RC entry + $rc = RecentChange::newFromRow( $obj ); + + # Skip CatWatch entries for hidden cats based on user preference + if ( + $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE && + !$userShowHiddenCats && + $rc->getParam( 'hidden-cat' ) + ) { + continue; + } + + $rc->counter = $counter++; + + if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) { + $updated = $obj->wl_notificationtimestamp; + } else { + $updated = false; + } + + if ( isset( $watchedItemStore ) ) { + $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title ); + $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue ); + } else { + $rc->numberofWatchingusers = 0; + } + + $changeLine = $list->recentChangesLine( $rc, $updated, $counter ); + if ( $changeLine !== false ) { + $s .= $changeLine; + } } - $linkBatch->add( NS_USER_TALK, $userNameUnderscored ); + $s .= $list->endRecentChangesList(); - $linkBatch->add( $row->rc_namespace, $row->rc_title ); + $output->addHTML( $s ); } - $linkBatch->execute(); - $dbr->dataSeek( $res, 0 ); - - $list = ChangesList::newFromUser( $wgUser ); - $list->setWatchlistDivs(); - - $s = $list->beginRecentChangesList(); - $counter = 1; - foreach ( $res as $obj ) { - # Make RC entry - $rc = RecentChange::newFromRow( $obj ); - $rc->counter = $counter++; - - if ( $wgShowUpdatedMarker ) { - $updated = $obj->wl_notificationtimestamp; + + /** + * Set the text to be displayed above the changes + * + * @param FormOptions $opts + * @param int $numRows Number of rows in the result to show after this header + */ + public function doHeader( $opts, $numRows ) { + $user = $this->getUser(); + $out = $this->getOutput(); + + $out->addSubtitle( + $this->msg( 'watchlistfor2', $user->getName() ) + ->rawParams( SpecialEditWatchlist::buildTools( + $this->getLanguage(), + $this->getLinkRenderer() + ) ) + ); + + $this->setTopText( $opts ); + + $form = ''; + + $form .= Xml::openElement( 'form', [ + 'method' => 'get', + 'action' => wfScript(), + 'id' => 'mw-watchlist-form' + ] ); + $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ); + $form .= Xml::openElement( + 'fieldset', + [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ] + ); + $form .= Xml::element( + 'legend', null, $this->msg( 'watchlist-options' )->text() + ); + + if ( !$this->isStructuredFilterUiEnabled() ) { + $form .= $this->makeLegend(); + } + + $lang = $this->getLanguage(); + if ( $opts['days'] > 0 ) { + $days = $opts['days']; } else { - $updated = false; + $days = $this->maxDays; + } + $timestamp = wfTimestampNow(); + $wlInfo = Html::rawElement( + 'span', + [ 'class' => 'wlinfo' ], + $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params( + $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user ) + )->parse() + ) . "