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\ResultWrapper
;
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
{
37 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
38 parent
::__construct( $page, $restriction );
40 $this->maxDays
= $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
43 public function doesWrites() {
48 * Main execution point
50 * @param string $subpage
52 function execute( $subpage ) {
53 // Anons don't get a watchlist
54 $this->requireLogin( 'watchlistanontext' );
56 $output = $this->getOutput();
57 $request = $this->getRequest();
58 $this->addHelpLink( 'Help:Watching pages' );
59 $output->addModules( [
60 'mediawiki.special.changeslist.visitedstatus',
61 'mediawiki.special.watchlist',
63 $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] );
65 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
66 if ( $mode !== false ) {
67 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
68 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
69 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
70 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
72 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
75 $output->redirect( $title->getLocalURL() );
80 $this->checkPermissions();
82 $user = $this->getUser();
83 $opts = $this->getOptions();
85 $config = $this->getConfig();
86 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
87 && $request->getVal( 'reset' )
88 && $request->wasPosted()
89 && $user->matchEditToken( $request->getVal( 'token' ) )
91 $user->clearAllNotifications();
92 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
97 parent
::execute( $subpage );
99 if ( $this->isStructuredFilterUiEnabled() ) {
100 $output->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false );
101 $output->addJsConfigVars(
102 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
103 'rcfilters-wl-saved-queries'
108 protected function isStructuredFilterUiEnabled() {
109 return parent
::isStructuredFilterUiEnabled()
110 && ( $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' )
111 ||
$this->getRequest()->getBool( 'rcfilters' ) );
115 * Return an array of subpages that this special page will accept.
117 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
118 * @return string[] subpages
120 public function getSubpagesForPrefixSearch() {
131 protected function transformFilterDefinition( array $filterDefinition ) {
132 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
133 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
136 return $filterDefinition;
142 protected function registerFilters() {
143 parent
::registerFilters();
145 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
146 'name' => 'watchlistactivity',
147 'title' => 'rcfilters-filtergroup-watchlistactivity',
148 'class' => ChangesListStringOptionsFilterGroup
::class,
150 'isFullCoverage' => true,
154 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
155 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
156 'cssClassSuffix' => 'watchedunseen',
157 'isRowApplicableCallable' => function ( $ctx, $rc ) {
158 $changeTs = $rc->getAttribute( 'rc_timestamp' );
159 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
160 return $changeTs >= $lastVisitTs;
165 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
166 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
167 'cssClassSuffix' => 'watchedseen',
168 'isRowApplicableCallable' => function ( $ctx, $rc ) {
169 $changeTs = $rc->getAttribute( 'rc_timestamp' );
170 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
171 return $changeTs < $lastVisitTs;
175 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
176 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
177 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
178 if ( $selectedValues === [ 'seen' ] ) {
179 $conds[] = 'rc_timestamp < wl_notificationtimestamp';
180 } elseif ( $selectedValues === [ 'unseen' ] ) {
181 $conds[] = 'rc_timestamp >= wl_notificationtimestamp';
186 $user = $this->getUser();
188 $significance = $this->getFilterGroup( 'significance' );
189 $hideMinor = $significance->getFilter( 'hideminor' );
190 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
192 $automated = $this->getFilterGroup( 'automated' );
193 $hideBots = $automated->getFilter( 'hidebots' );
194 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
196 $registration = $this->getFilterGroup( 'registration' );
197 $hideAnons = $registration->getFilter( 'hideanons' );
198 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
199 $hideLiu = $registration->getFilter( 'hideliu' );
200 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
202 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
203 if ( $reviewStatus !== null ) {
204 // Conditional on feature being available and rights
205 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
206 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
209 $authorship = $this->getFilterGroup( 'authorship' );
210 $hideMyself = $authorship->getFilter( 'hidemyself' );
211 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
213 $changeType = $this->getFilterGroup( 'changeType' );
214 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
215 if ( $hideCategorization !== null ) {
216 // Conditional on feature being available
217 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
222 * Get a FormOptions object containing the default options
224 * @return FormOptions
226 public function getDefaultOptions() {
227 $opts = parent
::getDefaultOptions();
228 $user = $this->getUser();
230 $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions
::FLOAT );
231 $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
232 $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions
::INT );
237 public function validateOptions( FormOptions
$opts ) {
238 $opts->validateBounds( 'days', 0, $this->maxDays
);
239 $opts->validateIntBounds( 'limit', 0, 5000 );
240 parent
::validateOptions( $opts );
244 * Get all custom filters
246 * @return array Map of filter URL param names to properties (msg/default)
248 protected function getCustomFilters() {
249 if ( $this->customFilters
=== null ) {
250 $this->customFilters
= parent
::getCustomFilters();
251 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
254 return $this->customFilters
;
258 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
260 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
261 * to the current ones.
263 * @param FormOptions $opts
264 * @return FormOptions
266 protected function fetchOptionsFromRequest( $opts ) {
267 static $compatibilityMap = [
268 'hideMinor' => 'hideminor',
269 'hideBots' => 'hidebots',
270 'hideAnons' => 'hideanons',
271 'hideLiu' => 'hideliu',
272 'hidePatrolled' => 'hidepatrolled',
273 'hideOwn' => 'hidemyself',
276 $params = $this->getRequest()->getValues();
277 foreach ( $compatibilityMap as $from => $to ) {
278 if ( isset( $params[$from] ) ) {
279 $params[$to] = $params[$from];
280 unset( $params[$from] );
284 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
285 $allBooleansFalse = [];
287 // If the user submitted the form, start with a baseline of "all
288 // booleans are false", then change the ones they checked. This
289 // means we ignore the defaults.
291 // This is how we handle the fact that HTML forms don't submit
293 foreach ( $this->filterGroups
as $filterGroup ) {
294 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
295 foreach ( $filterGroup->getFilters() as $filter ) {
296 $allBooleansFalse[$filter->getName()] = false;
301 $params = $params +
$allBooleansFalse;
304 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
305 // methods defined on WebRequest and removing this dependency would cause some code duplication.
306 $request = new DerivativeRequest( $this->getRequest(), $params );
307 $opts->fetchValuesFromRequest( $request );
315 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
316 &$join_conds, FormOptions
$opts
318 $dbr = $this->getDB();
319 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
323 if ( $opts['days'] > 0 ) {
324 $conds[] = 'rc_timestamp > ' .
325 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
332 protected function doMainQuery( $tables, $fields, $conds, $query_options,
333 $join_conds, FormOptions
$opts
335 $dbr = $this->getDB();
336 $user = $this->getUser();
338 # Toggle watchlist content (all recent edits or just the latest)
339 if ( $opts['extended'] ) {
342 # Top log Ids for a page are not stored
343 $nonRevisionTypes = [ RC_LOG
];
344 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
345 if ( $nonRevisionTypes ) {
346 $conds[] = $dbr->makeList(
348 'rc_this_oldid=page_latest',
349 'rc_type' => $nonRevisionTypes,
357 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
358 $fields = array_merge( RecentChange
::selectFields(), $fields );
360 $query_options = array_merge( [
361 'ORDER BY' => 'rc_timestamp DESC',
362 'LIMIT' => $opts['limit']
364 $join_conds = array_merge(
369 'wl_user' => $user->getId(),
370 'wl_namespace=rc_namespace',
378 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
379 $fields[] = 'wl_notificationtimestamp';
382 $rollbacker = $user->isAllowed( 'rollback' );
383 if ( $usePage ||
$rollbacker ) {
385 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
387 $fields[] = 'page_latest';
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 ChangeTags
::modifyDisplayQuery(
416 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
428 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
431 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
433 'SpecialWatchlistQuery',
434 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
440 * Return a IDatabase object for reading
444 protected function getDB() {
445 return wfGetDB( DB_REPLICA
, 'watchlist' );
451 public function outputFeedLinks() {
452 $user = $this->getUser();
453 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
455 $this->addFeedLinks( [
456 'action' => 'feedwatchlist',
458 'wlowner' => $user->getName(),
459 'wltoken' => $wlToken,
465 * Build and output the actual changes list.
467 * @param ResultWrapper $rows Database rows
468 * @param FormOptions $opts
470 public function outputChangesList( $rows, $opts ) {
471 $dbr = $this->getDB();
472 $user = $this->getUser();
473 $output = $this->getOutput();
475 # Show a message about replica DB lag, if applicable
476 $lag = wfGetLB()->safeGetLag( $dbr );
478 $output->showLagWarning( $lag );
481 # If no rows to display, show message before try to render the list
482 if ( $rows->numRows() == 0 ) {
483 $output->wrapWikiMsg(
484 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
489 $dbr->dataSeek( $rows, 0 );
491 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
492 $list->setWatchlistDivs();
493 $list->initChangesListRows( $rows );
494 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
495 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
496 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
497 // since EnhancedChangesList groups log entries by performer rather than by target article
498 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
502 return $this->getLinkRenderer()
503 ->makeKnownLink( $rc->getTitle(),
504 $this->msg( 'watchlist-unwatch' )->text(), [
505 'class' => 'mw-unwatch-link',
506 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
507 ], [ 'action' => 'unwatch' ] ) . ' ';
511 $dbr->dataSeek( $rows, 0 );
513 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
514 && $user->getOption( 'shownumberswatching' )
516 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
519 $s = $list->beginRecentChangesList();
521 if ( $this->isStructuredFilterUiEnabled() ) {
522 $s .= $this->makeLegend();
525 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
527 foreach ( $rows as $obj ) {
529 $rc = RecentChange
::newFromRow( $obj );
531 # Skip CatWatch entries for hidden cats based on user preference
533 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
534 !$userShowHiddenCats &&
535 $rc->getParam( 'hidden-cat' )
540 $rc->counter
= $counter++
;
542 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
543 $updated = $obj->wl_notificationtimestamp
;
548 if ( isset( $watchedItemStore ) ) {
549 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
550 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
552 $rc->numberofWatchingusers
= 0;
555 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
556 if ( $changeLine !== false ) {
560 $s .= $list->endRecentChangesList();
562 $output->addHTML( $s );
566 * Set the text to be displayed above the changes
568 * @param FormOptions $opts
569 * @param int $numRows Number of rows in the result to show after this header
571 public function doHeader( $opts, $numRows ) {
572 $user = $this->getUser();
573 $out = $this->getOutput();
576 $this->msg( 'watchlistfor2', $user->getName() )
577 ->rawParams( SpecialEditWatchlist
::buildTools(
578 $this->getLanguage(),
579 $this->getLinkRenderer()
583 $this->setTopText( $opts );
587 $form .= Xml
::openElement( 'form', [
589 'action' => wfScript(),
590 'id' => 'mw-watchlist-form'
592 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
593 $form .= Xml
::fieldset(
594 $this->msg( 'watchlist-options' )->text(),
596 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
599 if ( !$this->isStructuredFilterUiEnabled() ) {
600 $form .= $this->makeLegend();
603 $lang = $this->getLanguage();
604 if ( $opts['days'] > 0 ) {
605 $days = $opts['days'];
607 $days = $this->maxDays
;
609 $timestamp = wfTimestampNow();
610 $wlInfo = Html
::rawElement(
612 [ 'class' => 'wlinfo' ],
613 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
614 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
618 $nondefaults = $opts->getChangedValues();
619 $cutofflinks = Html
::rawElement(
621 [ 'class' => 'cldays cloption' ],
622 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
625 # Spit out some control panel links
627 $namesOfDisplayedFilters = [];
628 foreach ( $this->getFilterGroups() as $groupName => $group ) {
629 if ( !$group->isPerGroupRequestParameter() ) {
630 foreach ( $group->getFilters() as $filterName => $filter ) {
631 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
632 $namesOfDisplayedFilters[] = $filterName;
633 $links[] = $this->showHideCheck(
635 $filter->getShowHide(),
638 $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()
673 'name' => 'namespace',
675 'class' => 'namespaceselector',
678 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
679 $this->msg( 'invert' )->text(),
683 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
685 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
686 $this->msg( 'namespace_association' )->text(),
690 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
692 $form .= Html
::rawElement(
694 [ 'class' => 'namespaceForm cloption' ],
698 $form .= Xml
::submitButton(
699 $this->msg( 'watchlist-submit' )->text(),
700 [ 'class' => 'cloption-submit' ]
702 foreach ( $hiddenFields as $key => $value ) {
703 $form .= Html
::hidden( $key, $value ) . "\n";
705 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
706 $form .= Xml
::closeElement( 'form' ) . "\n";
708 // Insert a placeholder for RCFilters
709 if ( $this->isStructuredFilterUiEnabled() ) {
710 $rcfilterContainer = Html
::element(
712 [ 'class' => 'rcfilters-container' ]
715 $loadingContainer = Html
::rawElement(
717 [ 'class' => 'rcfilters-spinner' ],
720 [ 'class' => 'rcfilters-spinner-bounce' ]
724 // Wrap both with rcfilters-head
725 $this->getOutput()->addHTML(
728 [ 'class' => 'rcfilters-head' ],
729 $rcfilterContainer . $form
734 $this->getOutput()->addHTML( $loadingContainer );
736 $this->getOutput()->addHTML( $form );
739 $this->setBottomText( $opts );
742 function cutoffselector( $options ) {
743 // Cast everything to strings immediately, so that we know all of the values have the same
744 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
745 // default string representation, for example, and would confuse comparisons.
747 // Misleadingly, the 'days' option supports hours too.
748 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
750 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
751 // add the user preference, if it isn't available already
752 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
753 $days[] = $userWatchlistOption;
756 $maxDays = (string)$this->maxDays
;
757 // add the maximum possible value, if it isn't available already
758 if ( !in_array( $maxDays, $days ) ) {
762 $selected = (string)$options['days'];
763 if ( $selected <= 0 ) {
764 $selected = $maxDays;
767 // add the currently selected value, if it isn't available already
768 if ( !in_array( $selected, $days ) ) {
772 $select = new XmlSelect( 'days', 'days', $selected );
775 foreach ( $days as $value ) {
777 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
779 $name = $this->msg( 'days' )->numParams( $value )->text();
781 $select->addOption( $name, $value );
784 return $select->getHTML() . "\n<br />\n";
787 function setTopText( FormOptions
$opts ) {
788 $nondefaults = $opts->getChangedValues();
790 $user = $this->getUser();
792 $numItems = $this->countItems();
793 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
795 // Show watchlist header
797 if ( $numItems == 0 ) {
798 $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
800 $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
801 if ( $this->getConfig()->get( 'EnotifWatchlist' )
802 && $user->getOption( 'enotifwatchlistpages' )
804 $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
806 if ( $showUpdatedMarker ) {
807 $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
812 if ( $numItems > 0 && $showUpdatedMarker ) {
813 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
814 'action' => $this->getPageTitle()->getLocalURL(),
815 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
816 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
817 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
818 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
819 Html
::hidden( 'reset', 'all' ) . "\n";
820 foreach ( $nondefaults as $key => $value ) {
821 $form .= Html
::hidden( $key, $value ) . "\n";
823 $form .= Xml
::closeElement( 'form' ) . "\n";
826 $this->getOutput()->addHTML( $form );
829 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
830 $options[$name] = 1 - (int)$value;
832 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
833 if ( $inStructuredUi ) {
834 $attribs[ 'data-feature-in-structured-ui' ] = true;
837 return Html
::rawElement(
841 $this->msg( $message, '' )->text(),
850 * Count the number of paired items on a user's watchlist.
851 * The assumption made here is that when a subject page is watched a talk page is also watched.
852 * Hence the number of individual items is halved.
856 protected function countItems() {
857 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
858 $count = $store->countWatchedItems( $this->getUser() );
859 return floor( $count / 2 );