3 * Implements Special:Watchlist
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 use MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\IResultWrapper
;
26 use Wikimedia\Rdbms\IDatabase
;
29 * A special page that lists last changes made to the wiki,
30 * limited to user-defined list of titles.
32 * @ingroup SpecialPage
34 class SpecialWatchlist
extends ChangesListSpecialPage
{
35 protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
36 protected static $daysPreferenceName = 'watchlistdays';
37 protected static $limitPreferenceName = 'wllimit';
38 protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
42 /** WatchedItemStore */
45 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
46 parent
::__construct( $page, $restriction );
48 $this->maxDays
= $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
49 $this->watchStore
= MediaWikiServices
::getInstance()->getWatchedItemStore();
52 public function doesWrites() {
57 * Main execution point
59 * @param string $subpage
61 function execute( $subpage ) {
62 // Anons don't get a watchlist
63 $this->requireLogin( 'watchlistanontext' );
65 $output = $this->getOutput();
66 $request = $this->getRequest();
67 $this->addHelpLink( 'Help:Watching pages' );
68 $output->addModuleStyles( [ 'mediawiki.special' ] );
69 $output->addModules( [
70 'mediawiki.special.recentchanges',
71 'mediawiki.special.watchlist',
74 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
75 if ( $mode !== false ) {
76 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
77 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
78 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
79 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
81 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
84 $output->redirect( $title->getLocalURL() );
89 $this->checkPermissions();
91 $user = $this->getUser();
92 $opts = $this->getOptions();
94 $config = $this->getConfig();
95 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
96 && $request->getVal( 'reset' )
97 && $request->wasPosted()
98 && $user->matchEditToken( $request->getVal( 'token' ) )
100 $user->clearAllNotifications();
101 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
106 parent
::execute( $subpage );
108 if ( $this->isStructuredFilterUiEnabled() ) {
109 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
114 * @see ChangesListSpecialPage::checkStructuredFilterUiEnabled
116 public static function checkStructuredFilterUiEnabled( $user ) {
117 if ( $user instanceof Config
) {
118 wfDeprecated( __METHOD__
. ' with Config argument', '1.34' );
119 $user = func_get_arg( 1 );
121 return !$user->getOption( 'wlenhancedfilters-disable' );
125 * Return an array of subpages that this special page will accept.
127 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
128 * @return string[] subpages
130 public function getSubpagesForPrefixSearch() {
141 protected function transformFilterDefinition( array $filterDefinition ) {
142 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
143 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
146 return $filterDefinition;
152 protected function registerFilters() {
153 parent
::registerFilters();
155 // legacy 'extended' filter
156 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
157 'name' => 'extended-group',
160 'name' => 'extended',
161 'isReplacedInStructuredUi' => true,
162 'activeValue' => false,
163 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
164 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
165 &$fields, &$conds, &$query_options, &$join_conds ) {
166 $nonRevisionTypes = [ RC_LOG
];
167 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
168 if ( $nonRevisionTypes ) {
169 $conds[] = $dbr->makeList(
171 'rc_this_oldid=page_latest',
172 'rc_type' => $nonRevisionTypes,
183 if ( $this->isStructuredFilterUiEnabled() ) {
184 $this->getFilterGroup( 'lastRevision' )
185 ->getFilter( 'hidepreviousrevisions' )
186 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
189 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
190 'name' => 'watchlistactivity',
191 'title' => 'rcfilters-filtergroup-watchlistactivity',
192 'class' => ChangesListStringOptionsFilterGroup
::class,
194 'isFullCoverage' => true,
198 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
199 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
200 'cssClassSuffix' => 'watchedunseen',
201 'isRowApplicableCallable' => function ( $ctx, RecentChange
$rc ) {
202 return !$this->isChangeEffectivelySeen( $rc );
207 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
208 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
209 'cssClassSuffix' => 'watchedseen',
210 'isRowApplicableCallable' => function ( $ctx, RecentChange
$rc ) {
211 return $this->isChangeEffectivelySeen( $rc );
215 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
216 'queryCallable' => function (
217 $specialPageClassName,
227 if ( $selectedValues === [ 'seen' ] ) {
228 $conds[] = $dbr->makeList( [
229 'wl_notificationtimestamp IS NULL',
230 'rc_timestamp < wl_notificationtimestamp'
232 } elseif ( $selectedValues === [ 'unseen' ] ) {
233 $conds[] = $dbr->makeList( [
234 'wl_notificationtimestamp IS NOT NULL',
235 'rc_timestamp >= wl_notificationtimestamp'
241 $user = $this->getUser();
243 $significance = $this->getFilterGroup( 'significance' );
244 $hideMinor = $significance->getFilter( 'hideminor' );
245 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
247 $automated = $this->getFilterGroup( 'automated' );
248 $hideBots = $automated->getFilter( 'hidebots' );
249 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
251 $registration = $this->getFilterGroup( 'registration' );
252 $hideAnons = $registration->getFilter( 'hideanons' );
253 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
254 $hideLiu = $registration->getFilter( 'hideliu' );
255 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
257 // Selecting both hideanons and hideliu on watchlist preferances
258 // gives mutually exclusive filters, so those are ignored
259 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
260 !$user->getBoolOption( 'watchlisthideliu' )
262 $this->getFilterGroup( 'userExpLevel' )
263 ->setDefault( 'registered' );
266 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
267 !$user->getBoolOption( 'watchlisthideanons' )
269 $this->getFilterGroup( 'userExpLevel' )
270 ->setDefault( 'unregistered' );
273 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
274 if ( $reviewStatus !== null ) {
275 // Conditional on feature being available and rights
276 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
277 $reviewStatus->setDefault( 'unpatrolled' );
278 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
279 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
280 $legacyHidePatrolled->setDefault( true );
284 $authorship = $this->getFilterGroup( 'authorship' );
285 $hideMyself = $authorship->getFilter( 'hidemyself' );
286 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
288 $changeType = $this->getFilterGroup( 'changeType' );
289 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
290 if ( $hideCategorization !== null ) {
291 // Conditional on feature being available
292 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
297 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
299 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
300 * to the current ones.
302 * @param FormOptions $opts
303 * @return FormOptions
305 protected function fetchOptionsFromRequest( $opts ) {
306 static $compatibilityMap = [
307 'hideMinor' => 'hideminor',
308 'hideBots' => 'hidebots',
309 'hideAnons' => 'hideanons',
310 'hideLiu' => 'hideliu',
311 'hidePatrolled' => 'hidepatrolled',
312 'hideOwn' => 'hidemyself',
315 $params = $this->getRequest()->getValues();
316 foreach ( $compatibilityMap as $from => $to ) {
317 if ( isset( $params[$from] ) ) {
318 $params[$to] = $params[$from];
319 unset( $params[$from] );
323 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
324 $allBooleansFalse = [];
326 // If the user submitted the form, start with a baseline of "all
327 // booleans are false", then change the ones they checked. This
328 // means we ignore the defaults.
330 // This is how we handle the fact that HTML forms don't submit
332 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
333 $allBooleansFalse[ $filter->getName() ] = false;
336 $params = $params +
$allBooleansFalse;
339 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
340 // methods defined on WebRequest and removing this dependency would cause some code duplication.
341 $request = new DerivativeRequest( $this->getRequest(), $params );
342 $opts->fetchValuesFromRequest( $request );
350 protected function doMainQuery( $tables, $fields, $conds, $query_options,
351 $join_conds, FormOptions
$opts
353 $dbr = $this->getDB();
354 $user = $this->getUser();
356 $rcQuery = RecentChange
::getQueryInfo();
357 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
358 $fields = array_merge( $rcQuery['fields'], $fields );
360 $join_conds = array_merge(
365 'wl_user' => $user->getId(),
366 'wl_namespace=rc_namespace',
376 $fields[] = 'page_latest';
377 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
379 $fields[] = 'wl_notificationtimestamp';
381 // Log entries with DELETED_ACTION must not show up unless the user has
382 // the necessary rights.
383 if ( !$user->isAllowed( 'deletedhistory' ) ) {
384 $bitmask = LogPage
::DELETED_ACTION
;
385 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
386 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
391 $conds[] = $dbr->makeList( [
392 'rc_type != ' . RC_LOG
,
393 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
397 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
398 ChangeTags
::modifyDisplayQuery(
407 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
409 if ( $this->areFiltersInConflict() ) {
414 'ORDER BY' => 'rc_timestamp DESC',
415 'LIMIT' => $opts['limit']
417 if ( in_array( 'DISTINCT', $query_options ) ) {
418 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
419 // In order to prevent DISTINCT from causing query performance problems,
420 // we have to GROUP BY the primary key. This in turn requires us to add
421 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
422 // start of the GROUP BY
423 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
424 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
426 // array_merge() is used intentionally here so that hooks can, should
427 // they so desire, override the ORDER BY / LIMIT condition(s)
428 $query_options = array_merge( $orderByAndLimit, $query_options );
441 * Return a IDatabase object for reading
445 protected function getDB() {
446 return wfGetDB( DB_REPLICA
, 'watchlist' );
452 public function outputFeedLinks() {
453 $user = $this->getUser();
454 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
456 $this->addFeedLinks( [
457 'action' => 'feedwatchlist',
459 'wlowner' => $user->getName(),
460 'wltoken' => $wlToken,
466 * Build and output the actual changes list.
468 * @param IResultWrapper $rows Database rows
469 * @param FormOptions $opts
471 public function outputChangesList( $rows, $opts ) {
472 $dbr = $this->getDB();
473 $user = $this->getUser();
474 $output = $this->getOutput();
475 $services = MediaWikiServices
::getInstance();
477 # Show a message about replica DB lag, if applicable
478 $lag = $dbr->getSessionLagStatus()['lag'];
480 $output->showLagWarning( $lag );
483 # If no rows to display, show message before try to render the list
484 if ( $rows->numRows() == 0 ) {
485 $output->wrapWikiMsg(
486 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
491 $dbr->dataSeek( $rows, 0 );
493 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
494 $list->setWatchlistDivs();
495 $list->initChangesListRows( $rows );
496 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
497 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
498 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
499 // since EnhancedChangesList groups log entries by performer rather than by target article
500 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
504 return $this->getLinkRenderer()
505 ->makeKnownLink( $rc->getTitle(),
506 $this->msg( 'watchlist-unwatch' )->text(), [
507 'class' => 'mw-unwatch-link',
508 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
509 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
513 $dbr->dataSeek( $rows, 0 );
515 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
516 && $user->getOption( 'shownumberswatching' )
518 $watchedItemStore = $services->getWatchedItemStore();
521 $s = $list->beginRecentChangesList();
523 if ( $this->isStructuredFilterUiEnabled() ) {
524 $s .= $this->makeLegend();
527 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
529 foreach ( $rows as $obj ) {
531 $rc = RecentChange
::newFromRow( $obj );
533 # Skip CatWatch entries for hidden cats based on user preference
535 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
536 !$userShowHiddenCats &&
537 $rc->getParam( 'hidden-cat' )
542 $rc->counter
= $counter++
;
544 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
545 $unseen = !$this->isChangeEffectivelySeen( $rc );
550 if ( isset( $watchedItemStore ) ) {
551 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
552 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
554 $rc->numberofWatchingusers
= 0;
557 // XXX: this treats pages with no unseen changes as "not on the watchlist" since
558 // everything is on the watchlist and it is an easy way to make pages with unseen
559 // changes appear bold. @TODO: clean this up.
560 $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
561 if ( $changeLine !== false ) {
565 $s .= $list->endRecentChangesList();
567 $output->addHTML( $s );
571 * Set the text to be displayed above the changes
573 * @param FormOptions $opts
574 * @param int $numRows Number of rows in the result to show after this header
576 public function doHeader( $opts, $numRows ) {
577 $user = $this->getUser();
578 $out = $this->getOutput();
581 $this->msg( 'watchlistfor2', $user->getName() )
582 ->rawParams( SpecialEditWatchlist
::buildTools(
583 $this->getLanguage(),
584 $this->getLinkRenderer()
588 $this->setTopText( $opts );
592 $form .= Xml
::openElement( 'form', [
594 'action' => wfScript(),
595 'id' => 'mw-watchlist-form'
597 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
598 $form .= Xml
::openElement(
600 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
602 $form .= Xml
::element(
603 'legend', null, $this->msg( 'watchlist-options' )->text()
606 if ( !$this->isStructuredFilterUiEnabled() ) {
607 $form .= $this->makeLegend();
610 $lang = $this->getLanguage();
611 $timestamp = wfTimestampNow();
612 $now = $lang->userTimeAndDate( $timestamp, $user );
613 $wlInfo = Html
::rawElement(
617 'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
619 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
620 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
624 $nondefaults = $opts->getChangedValues();
625 $cutofflinks = Html
::rawElement(
627 [ 'class' => 'cldays cloption' ],
628 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
631 # Spit out some control panel links
633 $namesOfDisplayedFilters = [];
634 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
635 $namesOfDisplayedFilters[] = $filterName;
636 $links[] = $this->showHideCheck(
638 $filter->getShowHide(),
640 $opts[ $filterName ],
641 $filter->isFeatureAvailableOnStructuredUi( $this )
645 $hiddenFields = $nondefaults;
646 $hiddenFields['action'] = 'submit';
647 unset( $hiddenFields['namespace'] );
648 unset( $hiddenFields['invert'] );
649 unset( $hiddenFields['associated'] );
650 unset( $hiddenFields['days'] );
651 foreach ( $namesOfDisplayedFilters as $filterName ) {
652 unset( $hiddenFields[$filterName] );
655 # Namespace filter and put the whole form together.
657 $form .= $cutofflinks;
658 $form .= Html
::rawElement(
660 [ 'class' => 'clshowhide' ],
661 $this->msg( 'watchlist-hide' ) .
662 $this->msg( 'colon-separator' )->escaped() .
663 implode( ' ', $links )
665 $form .= "\n<br />\n";
667 $namespaceForm = Html
::namespaceSelector(
669 'selected' => $opts['namespace'],
671 'label' => $this->msg( 'namespace' )->text(),
672 'in-user-lang' => true,
674 'name' => 'namespace',
676 'class' => 'namespaceselector',
679 $hidden = $opts['namespace'] === '' ?
' mw-input-hidden' : '';
680 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
681 $this->msg( 'invert' )->text(),
685 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
687 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
688 $this->msg( 'namespace_association' )->text(),
692 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
694 $form .= Html
::rawElement(
696 [ 'class' => 'namespaceForm cloption' ],
700 $form .= Xml
::submitButton(
701 $this->msg( 'watchlist-submit' )->text(),
702 [ 'class' => 'cloption-submit' ]
704 foreach ( $hiddenFields as $key => $value ) {
705 $form .= Html
::hidden( $key, $value ) . "\n";
707 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
708 $form .= Xml
::closeElement( 'form' ) . "\n";
710 // Insert a placeholder for RCFilters
711 if ( $this->isStructuredFilterUiEnabled() ) {
712 $rcfilterContainer = Html
::element(
714 // TODO: Remove deprecated rcfilters-container class
715 [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
718 $loadingContainer = Html
::rawElement(
720 [ 'class' => 'mw-rcfilters-spinner' ],
723 [ 'class' => 'mw-rcfilters-spinner-bounce' ]
727 // Wrap both with rcfilters-head
728 $this->getOutput()->addHTML(
731 // TODO: Remove deprecated rcfilters-head class
732 [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
733 $rcfilterContainer . $form
738 $this->getOutput()->addHTML( $loadingContainer );
740 $this->getOutput()->addHTML( $form );
743 $this->setBottomText( $opts );
746 function cutoffselector( $options ) {
747 $selected = (float)$options['days'];
748 if ( $selected <= 0 ) {
749 $selected = $this->maxDays
;
752 $selectedHours = round( $selected * 24 );
754 $hours = array_unique( array_filter( [
762 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
768 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
770 foreach ( $hours as $value ) {
772 $name = $this->msg( 'hours' )->numParams( $value )->text();
774 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
776 $select->addOption( $name, (float)( $value / 24 ) );
779 return $select->getHTML() . "\n<br />\n";
782 function setTopText( FormOptions
$opts ) {
783 $nondefaults = $opts->getChangedValues();
785 $user = $this->getUser();
787 $numItems = $this->countItems();
788 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
790 // Show watchlist header
791 $watchlistHeader = '';
792 if ( $numItems == 0 ) {
793 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
795 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
796 if ( $this->getConfig()->get( 'EnotifWatchlist' )
797 && $user->getOption( 'enotifwatchlistpages' )
799 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
801 if ( $showUpdatedMarker ) {
802 $watchlistHeader .= $this->msg(
803 $this->isStructuredFilterUiEnabled() ?
804 'rcfilters-watchlist-showupdated' :
805 'wlheader-showupdated'
809 $form .= Html
::rawElement(
811 [ 'class' => 'watchlistDetails' ],
815 if ( $numItems > 0 && $showUpdatedMarker ) {
816 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
817 'action' => $this->getPageTitle()->getLocalURL(),
818 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
819 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
820 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
821 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
822 Html
::hidden( 'reset', 'all' ) . "\n";
823 foreach ( $nondefaults as $key => $value ) {
824 $form .= Html
::hidden( $key, $value ) . "\n";
826 $form .= Xml
::closeElement( 'form' ) . "\n";
829 $this->getOutput()->addHTML( $form );
832 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
833 $options[$name] = 1 - (int)$value;
835 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
836 if ( $inStructuredUi ) {
837 $attribs[ 'data-feature-in-structured-ui' ] = true;
840 return Html
::rawElement(
843 // not using Html::checkLabel because that would escape the contents
844 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
846 $attribs +
[ 'for' => $name ],
847 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
848 $this->msg( $message, '<nowiki/>' )->parse()
854 * Count the number of paired items on a user's watchlist.
855 * The assumption made here is that when a subject page is watched a talk page is also watched.
856 * Hence the number of individual items is halved.
860 protected function countItems() {
861 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
862 $count = $store->countWatchedItems( $this->getUser() );
863 return floor( $count / 2 );
867 * @param RecentChange $rc
868 * @return bool User viewed the revision or a newer one
870 protected function isChangeEffectivelySeen( RecentChange
$rc ) {
871 $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
873 return ( $firstUnseen === null ||
$firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
877 * @param RecentChange $rc
878 * @return string|null TS_MW timestamp of first unseen revision or null if there isn't one
880 private function getLatestNotificationTimestamp( RecentChange
$rc ) {
881 return $this->watchStore
->getLatestNotificationTimestamp(
882 $rc->getAttribute( 'wl_notificationtimestamp' ),