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 $lastVisitTs !== null && $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 $lastVisitTs === null ||
$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[] = $dbr->makeList( [
180 'wl_notificationtimestamp IS NULL',
181 'rc_timestamp < wl_notificationtimestamp'
183 } elseif ( $selectedValues === [ 'unseen' ] ) {
184 $conds[] = $dbr->makeList( [
185 'wl_notificationtimestamp IS NOT NULL',
186 'rc_timestamp >= wl_notificationtimestamp'
192 $user = $this->getUser();
194 $significance = $this->getFilterGroup( 'significance' );
195 $hideMinor = $significance->getFilter( 'hideminor' );
196 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
198 $automated = $this->getFilterGroup( 'automated' );
199 $hideBots = $automated->getFilter( 'hidebots' );
200 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
202 $registration = $this->getFilterGroup( 'registration' );
203 $hideAnons = $registration->getFilter( 'hideanons' );
204 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
205 $hideLiu = $registration->getFilter( 'hideliu' );
206 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
208 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
209 if ( $reviewStatus !== null ) {
210 // Conditional on feature being available and rights
211 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
212 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
215 $authorship = $this->getFilterGroup( 'authorship' );
216 $hideMyself = $authorship->getFilter( 'hidemyself' );
217 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
219 $changeType = $this->getFilterGroup( 'changeType' );
220 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
221 if ( $hideCategorization !== null ) {
222 // Conditional on feature being available
223 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
228 * Get a FormOptions object containing the default options
230 * @return FormOptions
232 public function getDefaultOptions() {
233 $opts = parent
::getDefaultOptions();
234 $user = $this->getUser();
236 $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions
::FLOAT );
237 $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
238 $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions
::INT );
243 public function validateOptions( FormOptions
$opts ) {
244 $opts->validateBounds( 'days', 0, $this->maxDays
);
245 $opts->validateIntBounds( 'limit', 0, 5000 );
246 parent
::validateOptions( $opts );
250 * Get all custom filters
252 * @return array Map of filter URL param names to properties (msg/default)
254 protected function getCustomFilters() {
255 if ( $this->customFilters
=== null ) {
256 $this->customFilters
= parent
::getCustomFilters();
257 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
260 return $this->customFilters
;
264 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
266 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
267 * to the current ones.
269 * @param FormOptions $opts
270 * @return FormOptions
272 protected function fetchOptionsFromRequest( $opts ) {
273 static $compatibilityMap = [
274 'hideMinor' => 'hideminor',
275 'hideBots' => 'hidebots',
276 'hideAnons' => 'hideanons',
277 'hideLiu' => 'hideliu',
278 'hidePatrolled' => 'hidepatrolled',
279 'hideOwn' => 'hidemyself',
282 $params = $this->getRequest()->getValues();
283 foreach ( $compatibilityMap as $from => $to ) {
284 if ( isset( $params[$from] ) ) {
285 $params[$to] = $params[$from];
286 unset( $params[$from] );
290 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
291 $allBooleansFalse = [];
293 // If the user submitted the form, start with a baseline of "all
294 // booleans are false", then change the ones they checked. This
295 // means we ignore the defaults.
297 // This is how we handle the fact that HTML forms don't submit
299 foreach ( $this->filterGroups
as $filterGroup ) {
300 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
301 foreach ( $filterGroup->getFilters() as $filter ) {
302 $allBooleansFalse[$filter->getName()] = false;
307 $params = $params +
$allBooleansFalse;
310 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
311 // methods defined on WebRequest and removing this dependency would cause some code duplication.
312 $request = new DerivativeRequest( $this->getRequest(), $params );
313 $opts->fetchValuesFromRequest( $request );
321 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
322 &$join_conds, FormOptions
$opts
324 $dbr = $this->getDB();
325 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
329 if ( $opts['days'] > 0 ) {
330 $conds[] = 'rc_timestamp > ' .
331 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
338 protected function doMainQuery( $tables, $fields, $conds, $query_options,
339 $join_conds, FormOptions
$opts
341 $dbr = $this->getDB();
342 $user = $this->getUser();
344 # Toggle watchlist content (all recent edits or just the latest)
345 if ( !$opts['extended'] ) {
346 # Top log Ids for a page are not stored
347 $nonRevisionTypes = [ RC_LOG
];
348 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
349 if ( $nonRevisionTypes ) {
350 $conds[] = $dbr->makeList(
352 'rc_this_oldid=page_latest',
353 'rc_type' => $nonRevisionTypes,
360 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
361 $fields = array_merge( RecentChange
::selectFields(), $fields );
363 $query_options = array_merge( [
364 'ORDER BY' => 'rc_timestamp DESC',
365 'LIMIT' => $opts['limit']
367 $join_conds = array_merge(
372 'wl_user' => $user->getId(),
373 'wl_namespace=rc_namespace',
382 $fields[] = 'page_latest';
383 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
385 $fields[] = 'wl_notificationtimestamp';
387 // Log entries with DELETED_ACTION must not show up unless the user has
388 // the necessary rights.
389 if ( !$user->isAllowed( 'deletedhistory' ) ) {
390 $bitmask = LogPage
::DELETED_ACTION
;
391 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
392 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
397 $conds[] = $dbr->makeList( [
398 'rc_type != ' . RC_LOG
,
399 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
403 ChangeTags
::modifyDisplayQuery(
412 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
424 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
427 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
429 'SpecialWatchlistQuery',
430 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
436 * Return a IDatabase object for reading
440 protected function getDB() {
441 return wfGetDB( DB_REPLICA
, 'watchlist' );
447 public function outputFeedLinks() {
448 $user = $this->getUser();
449 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
451 $this->addFeedLinks( [
452 'action' => 'feedwatchlist',
454 'wlowner' => $user->getName(),
455 'wltoken' => $wlToken,
461 * Build and output the actual changes list.
463 * @param ResultWrapper $rows Database rows
464 * @param FormOptions $opts
466 public function outputChangesList( $rows, $opts ) {
467 $dbr = $this->getDB();
468 $user = $this->getUser();
469 $output = $this->getOutput();
471 # Show a message about replica DB lag, if applicable
472 $lag = wfGetLB()->safeGetLag( $dbr );
474 $output->showLagWarning( $lag );
477 # If no rows to display, show message before try to render the list
478 if ( $rows->numRows() == 0 ) {
479 $output->wrapWikiMsg(
480 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
485 $dbr->dataSeek( $rows, 0 );
487 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
488 $list->setWatchlistDivs();
489 $list->initChangesListRows( $rows );
490 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
491 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
492 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
493 // since EnhancedChangesList groups log entries by performer rather than by target article
494 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
498 return $this->getLinkRenderer()
499 ->makeKnownLink( $rc->getTitle(),
500 $this->msg( 'watchlist-unwatch' )->text(), [
501 'class' => 'mw-unwatch-link',
502 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
503 ], [ 'action' => 'unwatch' ] ) . ' ';
507 $dbr->dataSeek( $rows, 0 );
509 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
510 && $user->getOption( 'shownumberswatching' )
512 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
515 $s = $list->beginRecentChangesList();
517 if ( $this->isStructuredFilterUiEnabled() ) {
518 $s .= $this->makeLegend();
521 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
523 foreach ( $rows as $obj ) {
525 $rc = RecentChange
::newFromRow( $obj );
527 # Skip CatWatch entries for hidden cats based on user preference
529 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
530 !$userShowHiddenCats &&
531 $rc->getParam( 'hidden-cat' )
536 $rc->counter
= $counter++
;
538 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
539 $updated = $obj->wl_notificationtimestamp
;
544 if ( isset( $watchedItemStore ) ) {
545 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
546 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
548 $rc->numberofWatchingusers
= 0;
551 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
552 if ( $changeLine !== false ) {
556 $s .= $list->endRecentChangesList();
558 $output->addHTML( $s );
562 * Set the text to be displayed above the changes
564 * @param FormOptions $opts
565 * @param int $numRows Number of rows in the result to show after this header
567 public function doHeader( $opts, $numRows ) {
568 $user = $this->getUser();
569 $out = $this->getOutput();
572 $this->msg( 'watchlistfor2', $user->getName() )
573 ->rawParams( SpecialEditWatchlist
::buildTools(
574 $this->getLanguage(),
575 $this->getLinkRenderer()
579 $this->setTopText( $opts );
583 $form .= Xml
::openElement( 'form', [
585 'action' => wfScript(),
586 'id' => 'mw-watchlist-form'
588 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
589 $form .= Xml
::fieldset(
590 $this->msg( 'watchlist-options' )->text(),
592 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
595 if ( !$this->isStructuredFilterUiEnabled() ) {
596 $form .= $this->makeLegend();
599 $lang = $this->getLanguage();
600 if ( $opts['days'] > 0 ) {
601 $days = $opts['days'];
603 $days = $this->maxDays
;
605 $timestamp = wfTimestampNow();
606 $wlInfo = Html
::rawElement(
608 [ 'class' => 'wlinfo' ],
609 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
610 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
614 $nondefaults = $opts->getChangedValues();
615 $cutofflinks = Html
::rawElement(
617 [ 'class' => 'cldays cloption' ],
618 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
621 # Spit out some control panel links
623 $namesOfDisplayedFilters = [];
624 foreach ( $this->getFilterGroups() as $groupName => $group ) {
625 if ( !$group->isPerGroupRequestParameter() ) {
626 foreach ( $group->getFilters() as $filterName => $filter ) {
627 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
628 $namesOfDisplayedFilters[] = $filterName;
629 $links[] = $this->showHideCheck(
631 $filter->getShowHide(),
634 $filter->isFeatureAvailableOnStructuredUi( $this )
641 $hiddenFields = $nondefaults;
642 $hiddenFields['action'] = 'submit';
643 unset( $hiddenFields['namespace'] );
644 unset( $hiddenFields['invert'] );
645 unset( $hiddenFields['associated'] );
646 unset( $hiddenFields['days'] );
647 foreach ( $namesOfDisplayedFilters as $filterName ) {
648 unset( $hiddenFields[$filterName] );
651 # Namespace filter and put the whole form together.
653 $form .= $cutofflinks;
654 $form .= Html
::rawElement(
656 [ 'class' => 'clshowhide' ],
657 $this->msg( 'watchlist-hide' ) .
658 $this->msg( 'colon-separator' )->escaped() .
659 implode( ' ', $links )
661 $form .= "\n<br />\n";
663 $namespaceForm = Html
::namespaceSelector(
665 'selected' => $opts['namespace'],
667 'label' => $this->msg( 'namespace' )->text()
669 'name' => 'namespace',
671 'class' => 'namespaceselector',
674 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
675 $this->msg( 'invert' )->text(),
679 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
681 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
682 $this->msg( 'namespace_association' )->text(),
686 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
688 $form .= Html
::rawElement(
690 [ 'class' => 'namespaceForm cloption' ],
694 $form .= Xml
::submitButton(
695 $this->msg( 'watchlist-submit' )->text(),
696 [ 'class' => 'cloption-submit' ]
698 foreach ( $hiddenFields as $key => $value ) {
699 $form .= Html
::hidden( $key, $value ) . "\n";
701 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
702 $form .= Xml
::closeElement( 'form' ) . "\n";
704 // Insert a placeholder for RCFilters
705 if ( $this->isStructuredFilterUiEnabled() ) {
706 $rcfilterContainer = Html
::element(
708 [ 'class' => 'rcfilters-container' ]
711 $loadingContainer = Html
::rawElement(
713 [ 'class' => 'rcfilters-spinner' ],
716 [ 'class' => 'rcfilters-spinner-bounce' ]
720 // Wrap both with rcfilters-head
721 $this->getOutput()->addHTML(
724 [ 'class' => 'rcfilters-head' ],
725 $rcfilterContainer . $form
730 $this->getOutput()->addHTML( $loadingContainer );
732 $this->getOutput()->addHTML( $form );
735 $this->setBottomText( $opts );
738 function cutoffselector( $options ) {
739 // Cast everything to strings immediately, so that we know all of the values have the same
740 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
741 // default string representation, for example, and would confuse comparisons.
743 // Misleadingly, the 'days' option supports hours too.
744 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
746 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
747 // add the user preference, if it isn't available already
748 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
749 $days[] = $userWatchlistOption;
752 $maxDays = (string)$this->maxDays
;
753 // add the maximum possible value, if it isn't available already
754 if ( !in_array( $maxDays, $days ) ) {
758 $selected = (string)$options['days'];
759 if ( $selected <= 0 ) {
760 $selected = $maxDays;
763 // add the currently selected value, if it isn't available already
764 if ( !in_array( $selected, $days ) ) {
768 $select = new XmlSelect( 'days', 'days', $selected );
771 foreach ( $days as $value ) {
773 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
775 $name = $this->msg( 'days' )->numParams( $value )->text();
777 $select->addOption( $name, $value );
780 return $select->getHTML() . "\n<br />\n";
783 function setTopText( FormOptions
$opts ) {
784 $nondefaults = $opts->getChangedValues();
786 $user = $this->getUser();
788 $numItems = $this->countItems();
789 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
791 // Show watchlist header
793 if ( $numItems == 0 ) {
794 $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
796 $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
797 if ( $this->getConfig()->get( 'EnotifWatchlist' )
798 && $user->getOption( 'enotifwatchlistpages' )
800 $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
802 if ( $showUpdatedMarker ) {
803 $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
808 if ( $numItems > 0 && $showUpdatedMarker ) {
809 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
810 'action' => $this->getPageTitle()->getLocalURL(),
811 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
812 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
813 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
814 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
815 Html
::hidden( 'reset', 'all' ) . "\n";
816 foreach ( $nondefaults as $key => $value ) {
817 $form .= Html
::hidden( $key, $value ) . "\n";
819 $form .= Xml
::closeElement( 'form' ) . "\n";
822 $this->getOutput()->addHTML( $form );
825 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
826 $options[$name] = 1 - (int)$value;
828 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
829 if ( $inStructuredUi ) {
830 $attribs[ 'data-feature-in-structured-ui' ] = true;
833 return Html
::rawElement(
837 $this->msg( $message, '' )->text(),
846 * Count the number of paired items on a user's watchlist.
847 * The assumption made here is that when a subject page is watched a talk page is also watched.
848 * Hence the number of individual items is halved.
852 protected function countItems() {
853 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
854 $count = $store->countWatchedItems( $this->getUser() );
855 return floor( $count / 2 );