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 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
43 parent
::__construct( $page, $restriction );
45 $this->maxDays
= $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
48 public function doesWrites() {
53 * Main execution point
55 * @param string $subpage
57 function execute( $subpage ) {
58 // Anons don't get a watchlist
59 $this->requireLogin( 'watchlistanontext' );
61 $output = $this->getOutput();
62 $request = $this->getRequest();
63 $this->addHelpLink( 'Help:Watching pages' );
64 $output->addModuleStyles( [ 'mediawiki.special' ] );
65 $output->addModules( [
66 'mediawiki.special.watchlist',
69 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
70 if ( $mode !== false ) {
71 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
72 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
73 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
74 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
76 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
79 $output->redirect( $title->getLocalURL() );
84 $this->checkPermissions();
86 $user = $this->getUser();
87 $opts = $this->getOptions();
89 $config = $this->getConfig();
90 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
91 && $request->getVal( 'reset' )
92 && $request->wasPosted()
93 && $user->matchEditToken( $request->getVal( 'token' ) )
95 $user->clearAllNotifications();
96 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
101 parent
::execute( $subpage );
103 if ( $this->isStructuredFilterUiEnabled() ) {
104 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
106 $output->addJsConfigVars(
107 'wgStructuredChangeFiltersEditWatchlistUrl',
108 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
113 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
114 if ( !$config->get( 'StructuredChangeFiltersOnWatchlist' ) ) {
118 if ( $config->get( 'StructuredChangeFiltersShowWatchlistPreference' ) ) {
119 return !$user->getOption( 'wlenhancedfilters-disable' );
121 return $user->getOption( 'rcenhancedfilters' );
126 * Return an array of subpages that this special page will accept.
128 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
129 * @return string[] subpages
131 public function getSubpagesForPrefixSearch() {
142 protected function transformFilterDefinition( array $filterDefinition ) {
143 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
144 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
147 return $filterDefinition;
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, $rc ) {
203 $changeTs = $rc->getAttribute( 'rc_timestamp' );
204 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
205 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
210 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
211 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
212 'cssClassSuffix' => 'watchedseen',
213 'isRowApplicableCallable' => function ( $ctx, $rc ) {
214 $changeTs = $rc->getAttribute( 'rc_timestamp' );
215 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
216 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
220 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
221 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
222 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
223 if ( $selectedValues === [ 'seen' ] ) {
224 $conds[] = $dbr->makeList( [
225 'wl_notificationtimestamp IS NULL',
226 'rc_timestamp < wl_notificationtimestamp'
228 } elseif ( $selectedValues === [ 'unseen' ] ) {
229 $conds[] = $dbr->makeList( [
230 'wl_notificationtimestamp IS NOT NULL',
231 'rc_timestamp >= wl_notificationtimestamp'
237 $user = $this->getUser();
239 $significance = $this->getFilterGroup( 'significance' );
240 $hideMinor = $significance->getFilter( 'hideminor' );
241 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
243 $automated = $this->getFilterGroup( 'automated' );
244 $hideBots = $automated->getFilter( 'hidebots' );
245 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
247 $registration = $this->getFilterGroup( 'registration' );
248 $hideAnons = $registration->getFilter( 'hideanons' );
249 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
250 $hideLiu = $registration->getFilter( 'hideliu' );
251 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
253 // Selecting both hideanons and hideliu on watchlist preferances
254 // gives mutually exclusive filters, so those are ignored
255 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
256 !$user->getBoolOption( 'watchlisthideliu' )
258 $this->getFilterGroup( 'userExpLevel' )
259 ->setDefault( 'registered' );
262 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
263 !$user->getBoolOption( 'watchlisthideanons' )
265 $this->getFilterGroup( 'userExpLevel' )
266 ->setDefault( 'unregistered' );
269 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
270 if ( $reviewStatus !== null ) {
271 // Conditional on feature being available and rights
272 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
273 $reviewStatus->setDefault( 'unpatrolled' );
274 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
275 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
276 $legacyHidePatrolled->setDefault( true );
280 $authorship = $this->getFilterGroup( 'authorship' );
281 $hideMyself = $authorship->getFilter( 'hidemyself' );
282 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
284 $changeType = $this->getFilterGroup( 'changeType' );
285 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
286 if ( $hideCategorization !== null ) {
287 // Conditional on feature being available
288 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
293 * Get all custom filters
295 * @return array Map of filter URL param names to properties (msg/default)
297 protected function getCustomFilters() {
298 if ( $this->customFilters
=== null ) {
299 $this->customFilters
= parent
::getCustomFilters();
300 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
303 return $this->customFilters
;
307 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
309 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
310 * to the current ones.
312 * @param FormOptions $opts
313 * @return FormOptions
315 protected function fetchOptionsFromRequest( $opts ) {
316 static $compatibilityMap = [
317 'hideMinor' => 'hideminor',
318 'hideBots' => 'hidebots',
319 'hideAnons' => 'hideanons',
320 'hideLiu' => 'hideliu',
321 'hidePatrolled' => 'hidepatrolled',
322 'hideOwn' => 'hidemyself',
325 $params = $this->getRequest()->getValues();
326 foreach ( $compatibilityMap as $from => $to ) {
327 if ( isset( $params[$from] ) ) {
328 $params[$to] = $params[$from];
329 unset( $params[$from] );
333 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
334 $allBooleansFalse = [];
336 // If the user submitted the form, start with a baseline of "all
337 // booleans are false", then change the ones they checked. This
338 // means we ignore the defaults.
340 // This is how we handle the fact that HTML forms don't submit
342 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
343 $allBooleansFalse[ $filter->getName() ] = false;
346 $params = $params +
$allBooleansFalse;
349 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
350 // methods defined on WebRequest and removing this dependency would cause some code duplication.
351 $request = new DerivativeRequest( $this->getRequest(), $params );
352 $opts->fetchValuesFromRequest( $request );
360 protected function doMainQuery( $tables, $fields, $conds, $query_options,
361 $join_conds, FormOptions
$opts
363 $dbr = $this->getDB();
364 $user = $this->getUser();
366 $rcQuery = RecentChange
::getQueryInfo();
367 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
368 $fields = array_merge( $rcQuery['fields'], $fields );
370 $join_conds = array_merge(
375 'wl_user' => $user->getId(),
376 'wl_namespace=rc_namespace',
386 $fields[] = 'page_latest';
387 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
389 $fields[] = 'wl_notificationtimestamp';
391 // Log entries with DELETED_ACTION must not show up unless the user has
392 // the necessary rights.
393 if ( !$user->isAllowed( 'deletedhistory' ) ) {
394 $bitmask = LogPage
::DELETED_ACTION
;
395 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
396 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
401 $conds[] = $dbr->makeList( [
402 'rc_type != ' . RC_LOG
,
403 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
407 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
408 ChangeTags
::modifyDisplayQuery(
417 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
419 if ( $this->areFiltersInConflict() ) {
424 'ORDER BY' => 'rc_timestamp DESC',
425 'LIMIT' => $opts['limit']
427 if ( in_array( 'DISTINCT', $query_options ) ) {
428 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
429 // In order to prevent DISTINCT from causing query performance problems,
430 // we have to GROUP BY the primary key. This in turn requires us to add
431 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
432 // start of the GROUP BY
433 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
434 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
436 // array_merge() is used intentionally here so that hooks can, should
437 // they so desire, override the ORDER BY / LIMIT condition(s)
438 $query_options = array_merge( $orderByAndLimit, $query_options );
450 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
453 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
455 'SpecialWatchlistQuery',
456 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
462 * Return a IDatabase object for reading
466 protected function getDB() {
467 return wfGetDB( DB_REPLICA
, 'watchlist' );
473 public function outputFeedLinks() {
474 $user = $this->getUser();
475 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
477 $this->addFeedLinks( [
478 'action' => 'feedwatchlist',
480 'wlowner' => $user->getName(),
481 'wltoken' => $wlToken,
487 * Build and output the actual changes list.
489 * @param IResultWrapper $rows Database rows
490 * @param FormOptions $opts
492 public function outputChangesList( $rows, $opts ) {
493 $dbr = $this->getDB();
494 $user = $this->getUser();
495 $output = $this->getOutput();
497 # Show a message about replica DB lag, if applicable
498 $lag = MediaWikiServices
::getInstance()->getDBLoadBalancer()->safeGetLag( $dbr );
500 $output->showLagWarning( $lag );
503 # If no rows to display, show message before try to render the list
504 if ( $rows->numRows() == 0 ) {
505 $output->wrapWikiMsg(
506 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
511 $dbr->dataSeek( $rows, 0 );
513 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
514 $list->setWatchlistDivs();
515 $list->initChangesListRows( $rows );
516 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
517 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
518 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
519 // since EnhancedChangesList groups log entries by performer rather than by target article
520 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
524 return $this->getLinkRenderer()
525 ->makeKnownLink( $rc->getTitle(),
526 $this->msg( 'watchlist-unwatch' )->text(), [
527 'class' => 'mw-unwatch-link',
528 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
529 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
533 $dbr->dataSeek( $rows, 0 );
535 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
536 && $user->getOption( 'shownumberswatching' )
538 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
541 $s = $list->beginRecentChangesList();
543 if ( $this->isStructuredFilterUiEnabled() ) {
544 $s .= $this->makeLegend();
547 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
549 foreach ( $rows as $obj ) {
551 $rc = RecentChange
::newFromRow( $obj );
553 # Skip CatWatch entries for hidden cats based on user preference
555 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
556 !$userShowHiddenCats &&
557 $rc->getParam( 'hidden-cat' )
562 $rc->counter
= $counter++
;
564 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
565 $updated = $obj->wl_notificationtimestamp
;
570 if ( isset( $watchedItemStore ) ) {
571 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
572 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
574 $rc->numberofWatchingusers
= 0;
577 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
578 if ( $changeLine !== false ) {
582 $s .= $list->endRecentChangesList();
584 $output->addHTML( $s );
588 * Set the text to be displayed above the changes
590 * @param FormOptions $opts
591 * @param int $numRows Number of rows in the result to show after this header
593 public function doHeader( $opts, $numRows ) {
594 $user = $this->getUser();
595 $out = $this->getOutput();
598 $this->msg( 'watchlistfor2', $user->getName() )
599 ->rawParams( SpecialEditWatchlist
::buildTools(
600 $this->getLanguage(),
601 $this->getLinkRenderer()
605 $this->setTopText( $opts );
609 $form .= Xml
::openElement( 'form', [
611 'action' => wfScript(),
612 'id' => 'mw-watchlist-form'
614 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
615 $form .= Xml
::openElement(
617 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
619 $form .= Xml
::element(
620 'legend', null, $this->msg( 'watchlist-options' )->text()
623 if ( !$this->isStructuredFilterUiEnabled() ) {
624 $form .= $this->makeLegend();
627 $lang = $this->getLanguage();
628 $timestamp = wfTimestampNow();
629 $wlInfo = Html
::rawElement(
633 'data-params' => json_encode( [ 'from' => $timestamp ] ),
635 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
636 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
640 $nondefaults = $opts->getChangedValues();
641 $cutofflinks = Html
::rawElement(
643 [ 'class' => 'cldays cloption' ],
644 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
647 # Spit out some control panel links
649 $namesOfDisplayedFilters = [];
650 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
651 $namesOfDisplayedFilters[] = $filterName;
652 $links[] = $this->showHideCheck(
654 $filter->getShowHide(),
656 $opts[ $filterName ],
657 $filter->isFeatureAvailableOnStructuredUi( $this )
661 $hiddenFields = $nondefaults;
662 $hiddenFields['action'] = 'submit';
663 unset( $hiddenFields['namespace'] );
664 unset( $hiddenFields['invert'] );
665 unset( $hiddenFields['associated'] );
666 unset( $hiddenFields['days'] );
667 foreach ( $namesOfDisplayedFilters as $filterName ) {
668 unset( $hiddenFields[$filterName] );
671 # Namespace filter and put the whole form together.
673 $form .= $cutofflinks;
674 $form .= Html
::rawElement(
676 [ 'class' => 'clshowhide' ],
677 $this->msg( 'watchlist-hide' ) .
678 $this->msg( 'colon-separator' )->escaped() .
679 implode( ' ', $links )
681 $form .= "\n<br />\n";
683 $namespaceForm = Html
::namespaceSelector(
685 'selected' => $opts['namespace'],
687 'label' => $this->msg( 'namespace' )->text()
689 'name' => 'namespace',
691 'class' => 'namespaceselector',
694 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
695 $this->msg( 'invert' )->text(),
699 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
701 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
702 $this->msg( 'namespace_association' )->text(),
706 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
708 $form .= Html
::rawElement(
710 [ 'class' => 'namespaceForm cloption' ],
714 $form .= Xml
::submitButton(
715 $this->msg( 'watchlist-submit' )->text(),
716 [ 'class' => 'cloption-submit' ]
718 foreach ( $hiddenFields as $key => $value ) {
719 $form .= Html
::hidden( $key, $value ) . "\n";
721 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
722 $form .= Xml
::closeElement( 'form' ) . "\n";
724 // Insert a placeholder for RCFilters
725 if ( $this->isStructuredFilterUiEnabled() ) {
726 $rcfilterContainer = Html
::element(
728 [ 'class' => 'rcfilters-container' ]
731 $loadingContainer = Html
::rawElement(
733 [ 'class' => 'rcfilters-spinner' ],
736 [ 'class' => 'rcfilters-spinner-bounce' ]
740 // Wrap both with rcfilters-head
741 $this->getOutput()->addHTML(
744 [ 'class' => 'rcfilters-head' ],
745 $rcfilterContainer . $form
750 $this->getOutput()->addHTML( $loadingContainer );
752 $this->getOutput()->addHTML( $form );
755 $this->setBottomText( $opts );
758 function cutoffselector( $options ) {
759 $selected = (float)$options['days'];
760 if ( $selected <= 0 ) {
761 $selected = $this->maxDays
;
764 $selectedHours = round( $selected * 24 );
766 $hours = array_unique( array_filter( [
774 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
780 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
782 foreach ( $hours as $value ) {
784 $name = $this->msg( 'hours' )->numParams( $value )->text();
786 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
788 $select->addOption( $name, (float)( $value / 24 ) );
791 return $select->getHTML() . "\n<br />\n";
794 function setTopText( FormOptions
$opts ) {
795 $nondefaults = $opts->getChangedValues();
797 $user = $this->getUser();
799 $numItems = $this->countItems();
800 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
802 // Show watchlist header
803 $watchlistHeader = '';
804 if ( $numItems == 0 ) {
805 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
807 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
808 if ( $this->getConfig()->get( 'EnotifWatchlist' )
809 && $user->getOption( 'enotifwatchlistpages' )
811 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
813 if ( $showUpdatedMarker ) {
814 $watchlistHeader .= $this->msg(
815 $this->isStructuredFilterUiEnabled() ?
816 'rcfilters-watchlist-showupdated' :
817 'wlheader-showupdated'
821 $form .= Html
::rawElement(
823 [ 'class' => 'watchlistDetails' ],
827 if ( $numItems > 0 && $showUpdatedMarker ) {
828 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
829 'action' => $this->getPageTitle()->getLocalURL(),
830 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
831 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
832 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
833 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
834 Html
::hidden( 'reset', 'all' ) . "\n";
835 foreach ( $nondefaults as $key => $value ) {
836 $form .= Html
::hidden( $key, $value ) . "\n";
838 $form .= Xml
::closeElement( 'form' ) . "\n";
841 $this->getOutput()->addHTML( $form );
844 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
845 $options[$name] = 1 - (int)$value;
847 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
848 if ( $inStructuredUi ) {
849 $attribs[ 'data-feature-in-structured-ui' ] = true;
852 return Html
::rawElement(
855 // not using Html::checkLabel because that would escape the contents
856 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
858 $attribs +
[ 'for' => $name ],
859 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
860 $this->msg( $message, '<nowiki/>' )->parse()
866 * Count the number of paired items on a user's watchlist.
867 * The assumption made here is that when a subject page is watched a talk page is also watched.
868 * Hence the number of individual items is halved.
872 protected function countItems() {
873 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
874 $count = $store->countWatchedItems( $this->getUser() );
875 return floor( $count / 2 );