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.recentchanges',
67 'mediawiki.special.watchlist',
70 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
71 if ( $mode !== false ) {
72 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
73 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
74 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
75 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
77 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
80 $output->redirect( $title->getLocalURL() );
85 $this->checkPermissions();
87 $user = $this->getUser();
88 $opts = $this->getOptions();
90 $config = $this->getConfig();
91 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
92 && $request->getVal( 'reset' )
93 && $request->wasPosted()
94 && $user->matchEditToken( $request->getVal( 'token' ) )
96 $user->clearAllNotifications();
97 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
102 parent
::execute( $subpage );
104 if ( $this->isStructuredFilterUiEnabled() ) {
105 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
109 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
110 return !$user->getOption( 'wlenhancedfilters-disable' );
114 * Return an array of subpages that this special page will accept.
116 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
117 * @return string[] subpages
119 public function getSubpagesForPrefixSearch() {
130 protected function transformFilterDefinition( array $filterDefinition ) {
131 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
132 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
135 return $filterDefinition;
141 protected function registerFilters() {
142 parent
::registerFilters();
144 // legacy 'extended' filter
145 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
146 'name' => 'extended-group',
149 'name' => 'extended',
150 'isReplacedInStructuredUi' => true,
151 'activeValue' => false,
152 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
153 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
154 &$fields, &$conds, &$query_options, &$join_conds ) {
155 $nonRevisionTypes = [ RC_LOG
];
156 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
157 if ( $nonRevisionTypes ) {
158 $conds[] = $dbr->makeList(
160 'rc_this_oldid=page_latest',
161 'rc_type' => $nonRevisionTypes,
172 if ( $this->isStructuredFilterUiEnabled() ) {
173 $this->getFilterGroup( 'lastRevision' )
174 ->getFilter( 'hidepreviousrevisions' )
175 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
178 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
179 'name' => 'watchlistactivity',
180 'title' => 'rcfilters-filtergroup-watchlistactivity',
181 'class' => ChangesListStringOptionsFilterGroup
::class,
183 'isFullCoverage' => true,
187 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
188 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
189 'cssClassSuffix' => 'watchedunseen',
190 'isRowApplicableCallable' => function ( $ctx, $rc ) {
191 $changeTs = $rc->getAttribute( 'rc_timestamp' );
192 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
193 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
198 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
199 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
200 'cssClassSuffix' => 'watchedseen',
201 'isRowApplicableCallable' => function ( $ctx, $rc ) {
202 $changeTs = $rc->getAttribute( 'rc_timestamp' );
203 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
204 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
208 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
209 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
210 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
211 if ( $selectedValues === [ 'seen' ] ) {
212 $conds[] = $dbr->makeList( [
213 'wl_notificationtimestamp IS NULL',
214 'rc_timestamp < wl_notificationtimestamp'
216 } elseif ( $selectedValues === [ 'unseen' ] ) {
217 $conds[] = $dbr->makeList( [
218 'wl_notificationtimestamp IS NOT NULL',
219 'rc_timestamp >= wl_notificationtimestamp'
225 $user = $this->getUser();
227 $significance = $this->getFilterGroup( 'significance' );
228 $hideMinor = $significance->getFilter( 'hideminor' );
229 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
231 $automated = $this->getFilterGroup( 'automated' );
232 $hideBots = $automated->getFilter( 'hidebots' );
233 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
235 $registration = $this->getFilterGroup( 'registration' );
236 $hideAnons = $registration->getFilter( 'hideanons' );
237 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
238 $hideLiu = $registration->getFilter( 'hideliu' );
239 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
241 // Selecting both hideanons and hideliu on watchlist preferances
242 // gives mutually exclusive filters, so those are ignored
243 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
244 !$user->getBoolOption( 'watchlisthideliu' )
246 $this->getFilterGroup( 'userExpLevel' )
247 ->setDefault( 'registered' );
250 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
251 !$user->getBoolOption( 'watchlisthideanons' )
253 $this->getFilterGroup( 'userExpLevel' )
254 ->setDefault( 'unregistered' );
257 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
258 if ( $reviewStatus !== null ) {
259 // Conditional on feature being available and rights
260 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
261 $reviewStatus->setDefault( 'unpatrolled' );
262 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
263 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
264 $legacyHidePatrolled->setDefault( true );
268 $authorship = $this->getFilterGroup( 'authorship' );
269 $hideMyself = $authorship->getFilter( 'hidemyself' );
270 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
272 $changeType = $this->getFilterGroup( 'changeType' );
273 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
274 if ( $hideCategorization !== null ) {
275 // Conditional on feature being available
276 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
281 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
283 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
284 * to the current ones.
286 * @param FormOptions $opts
287 * @return FormOptions
289 protected function fetchOptionsFromRequest( $opts ) {
290 static $compatibilityMap = [
291 'hideMinor' => 'hideminor',
292 'hideBots' => 'hidebots',
293 'hideAnons' => 'hideanons',
294 'hideLiu' => 'hideliu',
295 'hidePatrolled' => 'hidepatrolled',
296 'hideOwn' => 'hidemyself',
299 $params = $this->getRequest()->getValues();
300 foreach ( $compatibilityMap as $from => $to ) {
301 if ( isset( $params[$from] ) ) {
302 $params[$to] = $params[$from];
303 unset( $params[$from] );
307 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
308 $allBooleansFalse = [];
310 // If the user submitted the form, start with a baseline of "all
311 // booleans are false", then change the ones they checked. This
312 // means we ignore the defaults.
314 // This is how we handle the fact that HTML forms don't submit
316 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
317 $allBooleansFalse[ $filter->getName() ] = false;
320 $params = $params +
$allBooleansFalse;
323 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
324 // methods defined on WebRequest and removing this dependency would cause some code duplication.
325 $request = new DerivativeRequest( $this->getRequest(), $params );
326 $opts->fetchValuesFromRequest( $request );
334 protected function doMainQuery( $tables, $fields, $conds, $query_options,
335 $join_conds, FormOptions
$opts
337 $dbr = $this->getDB();
338 $user = $this->getUser();
340 $rcQuery = RecentChange
::getQueryInfo();
341 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
342 $fields = array_merge( $rcQuery['fields'], $fields );
344 $join_conds = array_merge(
349 'wl_user' => $user->getId(),
350 'wl_namespace=rc_namespace',
360 $fields[] = 'page_latest';
361 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
363 $fields[] = 'wl_notificationtimestamp';
365 // Log entries with DELETED_ACTION must not show up unless the user has
366 // the necessary rights.
367 if ( !$user->isAllowed( 'deletedhistory' ) ) {
368 $bitmask = LogPage
::DELETED_ACTION
;
369 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
370 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
375 $conds[] = $dbr->makeList( [
376 'rc_type != ' . RC_LOG
,
377 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
381 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
382 ChangeTags
::modifyDisplayQuery(
391 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
393 if ( $this->areFiltersInConflict() ) {
398 'ORDER BY' => 'rc_timestamp DESC',
399 'LIMIT' => $opts['limit']
401 if ( in_array( 'DISTINCT', $query_options ) ) {
402 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
403 // In order to prevent DISTINCT from causing query performance problems,
404 // we have to GROUP BY the primary key. This in turn requires us to add
405 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
406 // start of the GROUP BY
407 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
408 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
410 // array_merge() is used intentionally here so that hooks can, should
411 // they so desire, override the ORDER BY / LIMIT condition(s)
412 $query_options = array_merge( $orderByAndLimit, $query_options );
425 * Return a IDatabase object for reading
429 protected function getDB() {
430 return wfGetDB( DB_REPLICA
, 'watchlist' );
436 public function outputFeedLinks() {
437 $user = $this->getUser();
438 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
440 $this->addFeedLinks( [
441 'action' => 'feedwatchlist',
443 'wlowner' => $user->getName(),
444 'wltoken' => $wlToken,
450 * Build and output the actual changes list.
452 * @param IResultWrapper $rows Database rows
453 * @param FormOptions $opts
455 public function outputChangesList( $rows, $opts ) {
456 $dbr = $this->getDB();
457 $user = $this->getUser();
458 $output = $this->getOutput();
459 $services = MediaWikiServices
::getInstance();
461 # Show a message about replica DB lag, if applicable
462 $lag = $dbr->getSessionLagStatus()['lag'];
464 $output->showLagWarning( $lag );
467 # If no rows to display, show message before try to render the list
468 if ( $rows->numRows() == 0 ) {
469 $output->wrapWikiMsg(
470 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
475 $dbr->dataSeek( $rows, 0 );
477 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
478 $list->setWatchlistDivs();
479 $list->initChangesListRows( $rows );
480 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
481 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
482 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
483 // since EnhancedChangesList groups log entries by performer rather than by target article
484 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
488 return $this->getLinkRenderer()
489 ->makeKnownLink( $rc->getTitle(),
490 $this->msg( 'watchlist-unwatch' )->text(), [
491 'class' => 'mw-unwatch-link',
492 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
493 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
497 $dbr->dataSeek( $rows, 0 );
499 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
500 && $user->getOption( 'shownumberswatching' )
502 $watchedItemStore = $services->getWatchedItemStore();
505 $s = $list->beginRecentChangesList();
507 if ( $this->isStructuredFilterUiEnabled() ) {
508 $s .= $this->makeLegend();
511 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
513 foreach ( $rows as $obj ) {
515 $rc = RecentChange
::newFromRow( $obj );
517 # Skip CatWatch entries for hidden cats based on user preference
519 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
520 !$userShowHiddenCats &&
521 $rc->getParam( 'hidden-cat' )
526 $rc->counter
= $counter++
;
528 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
529 $updated = $obj->wl_notificationtimestamp
;
534 if ( isset( $watchedItemStore ) ) {
535 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
536 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
538 $rc->numberofWatchingusers
= 0;
541 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
542 if ( $changeLine !== false ) {
546 $s .= $list->endRecentChangesList();
548 $output->addHTML( $s );
552 * Set the text to be displayed above the changes
554 * @param FormOptions $opts
555 * @param int $numRows Number of rows in the result to show after this header
557 public function doHeader( $opts, $numRows ) {
558 $user = $this->getUser();
559 $out = $this->getOutput();
562 $this->msg( 'watchlistfor2', $user->getName() )
563 ->rawParams( SpecialEditWatchlist
::buildTools(
564 $this->getLanguage(),
565 $this->getLinkRenderer()
569 $this->setTopText( $opts );
573 $form .= Xml
::openElement( 'form', [
575 'action' => wfScript(),
576 'id' => 'mw-watchlist-form'
578 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
579 $form .= Xml
::openElement(
581 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
583 $form .= Xml
::element(
584 'legend', null, $this->msg( 'watchlist-options' )->text()
587 if ( !$this->isStructuredFilterUiEnabled() ) {
588 $form .= $this->makeLegend();
591 $lang = $this->getLanguage();
592 $timestamp = wfTimestampNow();
593 $wlInfo = Html
::rawElement(
597 'data-params' => json_encode( [ 'from' => $timestamp ] ),
599 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
600 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
604 $nondefaults = $opts->getChangedValues();
605 $cutofflinks = Html
::rawElement(
607 [ 'class' => 'cldays cloption' ],
608 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
611 # Spit out some control panel links
613 $namesOfDisplayedFilters = [];
614 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
615 $namesOfDisplayedFilters[] = $filterName;
616 $links[] = $this->showHideCheck(
618 $filter->getShowHide(),
620 $opts[ $filterName ],
621 $filter->isFeatureAvailableOnStructuredUi( $this )
625 $hiddenFields = $nondefaults;
626 $hiddenFields['action'] = 'submit';
627 unset( $hiddenFields['namespace'] );
628 unset( $hiddenFields['invert'] );
629 unset( $hiddenFields['associated'] );
630 unset( $hiddenFields['days'] );
631 foreach ( $namesOfDisplayedFilters as $filterName ) {
632 unset( $hiddenFields[$filterName] );
635 # Namespace filter and put the whole form together.
637 $form .= $cutofflinks;
638 $form .= Html
::rawElement(
640 [ 'class' => 'clshowhide' ],
641 $this->msg( 'watchlist-hide' ) .
642 $this->msg( 'colon-separator' )->escaped() .
643 implode( ' ', $links )
645 $form .= "\n<br />\n";
647 $namespaceForm = Html
::namespaceSelector(
649 'selected' => $opts['namespace'],
651 'label' => $this->msg( 'namespace' )->text(),
652 'in-user-lang' => true,
654 'name' => 'namespace',
656 'class' => 'namespaceselector',
659 $hidden = $opts['namespace'] === '' ?
' mw-input-hidden' : '';
660 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
661 $this->msg( 'invert' )->text(),
665 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
667 $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml
::checkLabel(
668 $this->msg( 'namespace_association' )->text(),
672 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
674 $form .= Html
::rawElement(
676 [ 'class' => 'namespaceForm cloption' ],
680 $form .= Xml
::submitButton(
681 $this->msg( 'watchlist-submit' )->text(),
682 [ 'class' => 'cloption-submit' ]
684 foreach ( $hiddenFields as $key => $value ) {
685 $form .= Html
::hidden( $key, $value ) . "\n";
687 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
688 $form .= Xml
::closeElement( 'form' ) . "\n";
690 // Insert a placeholder for RCFilters
691 if ( $this->isStructuredFilterUiEnabled() ) {
692 $rcfilterContainer = Html
::element(
694 [ 'class' => 'rcfilters-container' ]
697 $loadingContainer = Html
::rawElement(
699 [ 'class' => 'rcfilters-spinner' ],
702 [ 'class' => 'rcfilters-spinner-bounce' ]
706 // Wrap both with rcfilters-head
707 $this->getOutput()->addHTML(
710 [ 'class' => 'rcfilters-head' ],
711 $rcfilterContainer . $form
716 $this->getOutput()->addHTML( $loadingContainer );
718 $this->getOutput()->addHTML( $form );
721 $this->setBottomText( $opts );
724 function cutoffselector( $options ) {
725 $selected = (float)$options['days'];
726 if ( $selected <= 0 ) {
727 $selected = $this->maxDays
;
730 $selectedHours = round( $selected * 24 );
732 $hours = array_unique( array_filter( [
740 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
746 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
748 foreach ( $hours as $value ) {
750 $name = $this->msg( 'hours' )->numParams( $value )->text();
752 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
754 $select->addOption( $name, (float)( $value / 24 ) );
757 return $select->getHTML() . "\n<br />\n";
760 function setTopText( FormOptions
$opts ) {
761 $nondefaults = $opts->getChangedValues();
763 $user = $this->getUser();
765 $numItems = $this->countItems();
766 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
768 // Show watchlist header
769 $watchlistHeader = '';
770 if ( $numItems == 0 ) {
771 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
773 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
774 if ( $this->getConfig()->get( 'EnotifWatchlist' )
775 && $user->getOption( 'enotifwatchlistpages' )
777 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
779 if ( $showUpdatedMarker ) {
780 $watchlistHeader .= $this->msg(
781 $this->isStructuredFilterUiEnabled() ?
782 'rcfilters-watchlist-showupdated' :
783 'wlheader-showupdated'
787 $form .= Html
::rawElement(
789 [ 'class' => 'watchlistDetails' ],
793 if ( $numItems > 0 && $showUpdatedMarker ) {
794 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
795 'action' => $this->getPageTitle()->getLocalURL(),
796 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
797 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
798 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
799 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
800 Html
::hidden( 'reset', 'all' ) . "\n";
801 foreach ( $nondefaults as $key => $value ) {
802 $form .= Html
::hidden( $key, $value ) . "\n";
804 $form .= Xml
::closeElement( 'form' ) . "\n";
807 $this->getOutput()->addHTML( $form );
810 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
811 $options[$name] = 1 - (int)$value;
813 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
814 if ( $inStructuredUi ) {
815 $attribs[ 'data-feature-in-structured-ui' ] = true;
818 return Html
::rawElement(
821 // not using Html::checkLabel because that would escape the contents
822 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
824 $attribs +
[ 'for' => $name ],
825 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
826 $this->msg( $message, '<nowiki/>' )->parse()
832 * Count the number of paired items on a user's watchlist.
833 * The assumption made here is that when a subject page is watched a talk page is also watched.
834 * Hence the number of individual items is halved.
838 protected function countItems() {
839 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
840 $count = $store->countWatchedItems( $this->getUser() );
841 return floor( $count / 2 );