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;
151 * @suppress PhanUndeclaredMethod
153 protected function registerFilters() {
154 parent
::registerFilters();
156 // legacy 'extended' filter
157 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
158 'name' => 'extended-group',
161 'name' => 'extended',
162 'isReplacedInStructuredUi' => true,
163 'activeValue' => false,
164 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
165 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
166 &$fields, &$conds, &$query_options, &$join_conds ) {
167 $nonRevisionTypes = [ RC_LOG
];
168 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
169 if ( $nonRevisionTypes ) {
170 $conds[] = $dbr->makeList(
172 'rc_this_oldid=page_latest',
173 'rc_type' => $nonRevisionTypes,
184 if ( $this->isStructuredFilterUiEnabled() ) {
185 $this->getFilterGroup( 'lastRevision' )
186 ->getFilter( 'hidepreviousrevisions' )
187 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
190 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
191 'name' => 'watchlistactivity',
192 'title' => 'rcfilters-filtergroup-watchlistactivity',
193 'class' => ChangesListStringOptionsFilterGroup
::class,
195 'isFullCoverage' => true,
199 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
200 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
201 'cssClassSuffix' => 'watchedunseen',
202 'isRowApplicableCallable' => function ( $ctx, RecentChange
$rc ) {
203 return !$this->isChangeEffectivelySeen( $rc );
208 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
209 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
210 'cssClassSuffix' => 'watchedseen',
211 'isRowApplicableCallable' => function ( $ctx, RecentChange
$rc ) {
212 return $this->isChangeEffectivelySeen( $rc );
216 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
217 'queryCallable' => function (
218 $specialPageClassName,
228 if ( $selectedValues === [ 'seen' ] ) {
229 $conds[] = $dbr->makeList( [
230 'wl_notificationtimestamp IS NULL',
231 'rc_timestamp < wl_notificationtimestamp'
233 } elseif ( $selectedValues === [ 'unseen' ] ) {
234 $conds[] = $dbr->makeList( [
235 'wl_notificationtimestamp IS NOT NULL',
236 'rc_timestamp >= wl_notificationtimestamp'
242 $user = $this->getUser();
244 $significance = $this->getFilterGroup( 'significance' );
245 $hideMinor = $significance->getFilter( 'hideminor' );
246 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
248 $automated = $this->getFilterGroup( 'automated' );
249 $hideBots = $automated->getFilter( 'hidebots' );
250 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
252 $registration = $this->getFilterGroup( 'registration' );
253 $hideAnons = $registration->getFilter( 'hideanons' );
254 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
255 $hideLiu = $registration->getFilter( 'hideliu' );
256 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
258 // Selecting both hideanons and hideliu on watchlist preferances
259 // gives mutually exclusive filters, so those are ignored
260 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
261 !$user->getBoolOption( 'watchlisthideliu' )
263 $this->getFilterGroup( 'userExpLevel' )
264 ->setDefault( 'registered' );
267 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
268 !$user->getBoolOption( 'watchlisthideanons' )
270 $this->getFilterGroup( 'userExpLevel' )
271 ->setDefault( 'unregistered' );
274 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
275 if ( $reviewStatus !== null ) {
276 // Conditional on feature being available and rights
277 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
278 $reviewStatus->setDefault( 'unpatrolled' );
279 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
280 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
281 $legacyHidePatrolled->setDefault( true );
285 $authorship = $this->getFilterGroup( 'authorship' );
286 $hideMyself = $authorship->getFilter( 'hidemyself' );
287 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
289 $changeType = $this->getFilterGroup( 'changeType' );
290 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
291 if ( $hideCategorization !== null ) {
292 // Conditional on feature being available
293 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
298 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
300 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
301 * to the current ones.
303 * @param FormOptions $opts
304 * @return FormOptions
306 protected function fetchOptionsFromRequest( $opts ) {
307 static $compatibilityMap = [
308 'hideMinor' => 'hideminor',
309 'hideBots' => 'hidebots',
310 'hideAnons' => 'hideanons',
311 'hideLiu' => 'hideliu',
312 'hidePatrolled' => 'hidepatrolled',
313 'hideOwn' => 'hidemyself',
316 $params = $this->getRequest()->getValues();
317 foreach ( $compatibilityMap as $from => $to ) {
318 if ( isset( $params[$from] ) ) {
319 $params[$to] = $params[$from];
320 unset( $params[$from] );
324 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
325 $allBooleansFalse = [];
327 // If the user submitted the form, start with a baseline of "all
328 // booleans are false", then change the ones they checked. This
329 // means we ignore the defaults.
331 // This is how we handle the fact that HTML forms don't submit
333 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
334 $allBooleansFalse[ $filter->getName() ] = false;
337 $params = $params +
$allBooleansFalse;
340 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
341 // methods defined on WebRequest and removing this dependency would cause some code duplication.
342 $request = new DerivativeRequest( $this->getRequest(), $params );
343 $opts->fetchValuesFromRequest( $request );
351 protected function doMainQuery( $tables, $fields, $conds, $query_options,
352 $join_conds, FormOptions
$opts
354 $dbr = $this->getDB();
355 $user = $this->getUser();
357 $rcQuery = RecentChange
::getQueryInfo();
358 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
359 $fields = array_merge( $rcQuery['fields'], $fields );
361 $join_conds = array_merge(
366 'wl_user' => $user->getId(),
367 'wl_namespace=rc_namespace',
377 $fields[] = 'page_latest';
378 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
380 $fields[] = 'wl_notificationtimestamp';
382 // Log entries with DELETED_ACTION must not show up unless the user has
383 // the necessary rights.
384 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
385 if ( !$permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
386 $bitmask = LogPage
::DELETED_ACTION
;
387 } elseif ( !$permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) {
388 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
393 $conds[] = $dbr->makeList( [
394 'rc_type != ' . RC_LOG
,
395 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
399 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
400 ChangeTags
::modifyDisplayQuery(
409 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
411 if ( $this->areFiltersInConflict() ) {
416 'ORDER BY' => 'rc_timestamp DESC',
417 'LIMIT' => $opts['limit']
419 if ( in_array( 'DISTINCT', $query_options ) ) {
420 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
421 // In order to prevent DISTINCT from causing query performance problems,
422 // we have to GROUP BY the primary key. This in turn requires us to add
423 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
424 // start of the GROUP BY
425 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
426 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
428 // array_merge() is used intentionally here so that hooks can, should
429 // they so desire, override the ORDER BY / LIMIT condition(s)
430 $query_options = array_merge( $orderByAndLimit, $query_options );
443 * Return a IDatabase object for reading
447 protected function getDB() {
448 return wfGetDB( DB_REPLICA
, 'watchlist' );
454 public function outputFeedLinks() {
455 $user = $this->getUser();
456 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
458 $this->addFeedLinks( [
459 'action' => 'feedwatchlist',
461 'wlowner' => $user->getName(),
462 'wltoken' => $wlToken,
468 * Build and output the actual changes list.
470 * @param IResultWrapper $rows Database rows
471 * @param FormOptions $opts
473 public function outputChangesList( $rows, $opts ) {
474 $dbr = $this->getDB();
475 $user = $this->getUser();
476 $output = $this->getOutput();
477 $services = MediaWikiServices
::getInstance();
479 # Show a message about replica DB lag, if applicable
480 $lag = $dbr->getSessionLagStatus()['lag'];
482 $output->showLagWarning( $lag );
485 # If no rows to display, show message before try to render the list
486 if ( $rows->numRows() == 0 ) {
487 $output->wrapWikiMsg(
488 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
493 $dbr->dataSeek( $rows, 0 );
495 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
496 $list->setWatchlistDivs();
497 $list->initChangesListRows( $rows );
498 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
499 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
500 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
501 // since EnhancedChangesList groups log entries by performer rather than by target article
502 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
506 return $this->getLinkRenderer()
507 ->makeKnownLink( $rc->getTitle(),
508 $this->msg( 'watchlist-unwatch' )->text(), [
509 'class' => 'mw-unwatch-link',
510 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
511 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
515 $dbr->dataSeek( $rows, 0 );
517 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
518 && $user->getOption( 'shownumberswatching' )
520 $watchedItemStore = $services->getWatchedItemStore();
523 $s = $list->beginRecentChangesList();
525 if ( $this->isStructuredFilterUiEnabled() ) {
526 $s .= $this->makeLegend();
529 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
531 foreach ( $rows as $obj ) {
533 $rc = RecentChange
::newFromRow( $obj );
535 # Skip CatWatch entries for hidden cats based on user preference
537 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
538 !$userShowHiddenCats &&
539 $rc->getParam( 'hidden-cat' )
544 $rc->counter
= $counter++
;
546 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
547 $unseen = !$this->isChangeEffectivelySeen( $rc );
552 if ( isset( $watchedItemStore ) ) {
553 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
554 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
556 $rc->numberofWatchingusers
= 0;
559 // XXX: this treats pages with no unseen changes as "not on the watchlist" since
560 // everything is on the watchlist and it is an easy way to make pages with unseen
561 // changes appear bold. @TODO: clean this up.
562 $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
563 if ( $changeLine !== false ) {
567 $s .= $list->endRecentChangesList();
569 $output->addHTML( $s );
573 * Set the text to be displayed above the changes
575 * @param FormOptions $opts
576 * @param int $numRows Number of rows in the result to show after this header
578 public function doHeader( $opts, $numRows ) {
579 $user = $this->getUser();
580 $out = $this->getOutput();
583 $this->msg( 'watchlistfor2', $user->getName() )
584 ->rawParams( SpecialEditWatchlist
::buildTools(
585 $this->getLanguage(),
586 $this->getLinkRenderer()
590 $this->setTopText( $opts );
594 $form .= Xml
::openElement( 'form', [
596 'action' => wfScript(),
597 'id' => 'mw-watchlist-form'
599 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
600 $form .= Xml
::openElement(
602 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
604 $form .= Xml
::element(
605 'legend', null, $this->msg( 'watchlist-options' )->text()
608 if ( !$this->isStructuredFilterUiEnabled() ) {
609 $form .= $this->makeLegend();
612 $lang = $this->getLanguage();
613 $timestamp = wfTimestampNow();
614 $now = $lang->userTimeAndDate( $timestamp, $user );
615 $wlInfo = Html
::rawElement(
619 'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
621 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
622 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
626 $nondefaults = $opts->getChangedValues();
627 $cutofflinks = Html
::rawElement(
629 [ 'class' => 'cldays cloption' ],
630 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
633 # Spit out some control panel links
635 $namesOfDisplayedFilters = [];
636 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
637 $namesOfDisplayedFilters[] = $filterName;
638 $links[] = $this->showHideCheck(
640 $filter->getShowHide(),
642 $opts[ $filterName ],
643 $filter->isFeatureAvailableOnStructuredUi( $this )
647 $hiddenFields = $nondefaults;
648 $hiddenFields['action'] = 'submit';
649 unset( $hiddenFields['namespace'] );
650 unset( $hiddenFields['invert'] );
651 unset( $hiddenFields['associated'] );
652 unset( $hiddenFields['days'] );
653 foreach ( $namesOfDisplayedFilters as $filterName ) {
654 unset( $hiddenFields[$filterName] );
657 # Namespace filter and put the whole form together.
659 $form .= $cutofflinks;
660 $form .= Html
::rawElement(
662 [ 'class' => 'clshowhide' ],
663 $this->msg( 'watchlist-hide' ) .
664 $this->msg( 'colon-separator' )->escaped() .
665 implode( ' ', $links )
667 $form .= "\n<br />\n";
669 $namespaceForm = Html
::namespaceSelector(
671 'selected' => $opts['namespace'],
673 'label' => $this->msg( 'namespace' )->text(),
674 'in-user-lang' => true,
676 'name' => 'namespace',
678 'class' => 'namespaceselector',
681 $hidden = $opts['namespace'] === '' ?
' mw-input-hidden' : '';
682 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
683 $this->msg( 'invert' )->text(),
687 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
689 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
690 $this->msg( 'namespace_association' )->text(),
694 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
696 $form .= Html
::rawElement(
698 [ 'class' => 'namespaceForm cloption' ],
702 $form .= Xml
::submitButton(
703 $this->msg( 'watchlist-submit' )->text(),
704 [ 'class' => 'cloption-submit' ]
706 foreach ( $hiddenFields as $key => $value ) {
707 $form .= Html
::hidden( $key, $value ) . "\n";
709 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
710 $form .= Xml
::closeElement( 'form' ) . "\n";
712 // Insert a placeholder for RCFilters
713 if ( $this->isStructuredFilterUiEnabled() ) {
714 $rcfilterContainer = Html
::element(
716 // TODO: Remove deprecated rcfilters-container class
717 [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
720 $loadingContainer = Html
::rawElement(
722 [ 'class' => 'mw-rcfilters-spinner' ],
725 [ 'class' => 'mw-rcfilters-spinner-bounce' ]
729 // Wrap both with rcfilters-head
730 $this->getOutput()->addHTML(
733 // TODO: Remove deprecated rcfilters-head class
734 [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
735 $rcfilterContainer . $form
740 $this->getOutput()->addHTML( $loadingContainer );
742 $this->getOutput()->addHTML( $form );
745 $this->setBottomText( $opts );
748 function cutoffselector( $options ) {
749 $selected = (float)$options['days'];
750 if ( $selected <= 0 ) {
751 $selected = $this->maxDays
;
754 $selectedHours = round( $selected * 24 );
756 $hours = array_unique( array_filter( [
764 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
770 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
772 foreach ( $hours as $value ) {
774 $name = $this->msg( 'hours' )->numParams( $value )->text();
776 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
778 $select->addOption( $name, (float)( $value / 24 ) );
781 return $select->getHTML() . "\n<br />\n";
784 function setTopText( FormOptions
$opts ) {
785 $nondefaults = $opts->getChangedValues();
787 $user = $this->getUser();
789 $numItems = $this->countItems();
790 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
792 // Show watchlist header
793 $watchlistHeader = '';
794 if ( $numItems == 0 ) {
795 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
797 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
798 if ( $this->getConfig()->get( 'EnotifWatchlist' )
799 && $user->getOption( 'enotifwatchlistpages' )
801 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
803 if ( $showUpdatedMarker ) {
804 $watchlistHeader .= $this->msg(
805 $this->isStructuredFilterUiEnabled() ?
806 'rcfilters-watchlist-showupdated' :
807 'wlheader-showupdated'
811 $form .= Html
::rawElement(
813 [ 'class' => 'watchlistDetails' ],
817 if ( $numItems > 0 && $showUpdatedMarker ) {
818 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
819 'action' => $this->getPageTitle()->getLocalURL(),
820 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
821 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
822 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
823 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
824 Html
::hidden( 'reset', 'all' ) . "\n";
825 foreach ( $nondefaults as $key => $value ) {
826 $form .= Html
::hidden( $key, $value ) . "\n";
828 $form .= Xml
::closeElement( 'form' ) . "\n";
831 $this->getOutput()->addHTML( $form );
834 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
835 $options[$name] = 1 - (int)$value;
837 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
838 if ( $inStructuredUi ) {
839 $attribs[ 'data-feature-in-structured-ui' ] = true;
842 return Html
::rawElement(
845 // not using Html::checkLabel because that would escape the contents
846 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
848 $attribs +
[ 'for' => $name ],
849 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
850 $this->msg( $message, '<nowiki/>' )->parse()
856 * Count the number of paired items on a user's watchlist.
857 * The assumption made here is that when a subject page is watched a talk page is also watched.
858 * Hence the number of individual items is halved.
862 protected function countItems() {
863 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
864 $count = $store->countWatchedItems( $this->getUser() );
865 return floor( $count / 2 );
869 * @param RecentChange $rc
870 * @return bool User viewed the revision or a newer one
872 protected function isChangeEffectivelySeen( RecentChange
$rc ) {
873 $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
875 return ( $firstUnseen === null ||
$firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
879 * @param RecentChange $rc
880 * @return string|null TS_MW timestamp of first unseen revision or null if there isn't one
882 private function getLatestNotificationTimestamp( RecentChange
$rc ) {
883 return $this->watchStore
->getLatestNotificationTimestamp(
884 $rc->getAttribute( 'wl_notificationtimestamp' ),