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 return !$user->getOption( 'wlenhancedfilters-disable' );
118 * Return an array of subpages that this special page will accept.
120 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
121 * @return string[] subpages
123 public function getSubpagesForPrefixSearch() {
134 protected function transformFilterDefinition( array $filterDefinition ) {
135 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
136 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
139 return $filterDefinition;
145 protected function registerFilters() {
146 parent
::registerFilters();
148 // legacy 'extended' filter
149 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
150 'name' => 'extended-group',
153 'name' => 'extended',
154 'isReplacedInStructuredUi' => true,
155 'activeValue' => false,
156 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
157 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
158 &$fields, &$conds, &$query_options, &$join_conds ) {
159 $nonRevisionTypes = [ RC_LOG
];
160 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
161 if ( $nonRevisionTypes ) {
162 $conds[] = $dbr->makeList(
164 'rc_this_oldid=page_latest',
165 'rc_type' => $nonRevisionTypes,
176 if ( $this->isStructuredFilterUiEnabled() ) {
177 $this->getFilterGroup( 'lastRevision' )
178 ->getFilter( 'hidepreviousrevisions' )
179 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
182 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
183 'name' => 'watchlistactivity',
184 'title' => 'rcfilters-filtergroup-watchlistactivity',
185 'class' => ChangesListStringOptionsFilterGroup
::class,
187 'isFullCoverage' => true,
191 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
192 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
193 'cssClassSuffix' => 'watchedunseen',
194 'isRowApplicableCallable' => function ( $ctx, $rc ) {
195 $changeTs = $rc->getAttribute( 'rc_timestamp' );
196 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
197 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
202 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
203 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
204 'cssClassSuffix' => 'watchedseen',
205 'isRowApplicableCallable' => function ( $ctx, $rc ) {
206 $changeTs = $rc->getAttribute( 'rc_timestamp' );
207 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
208 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
212 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
213 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
214 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
215 if ( $selectedValues === [ 'seen' ] ) {
216 $conds[] = $dbr->makeList( [
217 'wl_notificationtimestamp IS NULL',
218 'rc_timestamp < wl_notificationtimestamp'
220 } elseif ( $selectedValues === [ 'unseen' ] ) {
221 $conds[] = $dbr->makeList( [
222 'wl_notificationtimestamp IS NOT NULL',
223 'rc_timestamp >= wl_notificationtimestamp'
229 $user = $this->getUser();
231 $significance = $this->getFilterGroup( 'significance' );
232 $hideMinor = $significance->getFilter( 'hideminor' );
233 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
235 $automated = $this->getFilterGroup( 'automated' );
236 $hideBots = $automated->getFilter( 'hidebots' );
237 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
239 $registration = $this->getFilterGroup( 'registration' );
240 $hideAnons = $registration->getFilter( 'hideanons' );
241 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
242 $hideLiu = $registration->getFilter( 'hideliu' );
243 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
245 // Selecting both hideanons and hideliu on watchlist preferances
246 // gives mutually exclusive filters, so those are ignored
247 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
248 !$user->getBoolOption( 'watchlisthideliu' )
250 $this->getFilterGroup( 'userExpLevel' )
251 ->setDefault( 'registered' );
254 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
255 !$user->getBoolOption( 'watchlisthideanons' )
257 $this->getFilterGroup( 'userExpLevel' )
258 ->setDefault( 'unregistered' );
261 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
262 if ( $reviewStatus !== null ) {
263 // Conditional on feature being available and rights
264 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
265 $reviewStatus->setDefault( 'unpatrolled' );
266 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
267 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
268 $legacyHidePatrolled->setDefault( true );
272 $authorship = $this->getFilterGroup( 'authorship' );
273 $hideMyself = $authorship->getFilter( 'hidemyself' );
274 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
276 $changeType = $this->getFilterGroup( 'changeType' );
277 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
278 if ( $hideCategorization !== null ) {
279 // Conditional on feature being available
280 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
285 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
287 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
288 * to the current ones.
290 * @param FormOptions $opts
291 * @return FormOptions
293 protected function fetchOptionsFromRequest( $opts ) {
294 static $compatibilityMap = [
295 'hideMinor' => 'hideminor',
296 'hideBots' => 'hidebots',
297 'hideAnons' => 'hideanons',
298 'hideLiu' => 'hideliu',
299 'hidePatrolled' => 'hidepatrolled',
300 'hideOwn' => 'hidemyself',
303 $params = $this->getRequest()->getValues();
304 foreach ( $compatibilityMap as $from => $to ) {
305 if ( isset( $params[$from] ) ) {
306 $params[$to] = $params[$from];
307 unset( $params[$from] );
311 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
312 $allBooleansFalse = [];
314 // If the user submitted the form, start with a baseline of "all
315 // booleans are false", then change the ones they checked. This
316 // means we ignore the defaults.
318 // This is how we handle the fact that HTML forms don't submit
320 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
321 $allBooleansFalse[ $filter->getName() ] = false;
324 $params = $params +
$allBooleansFalse;
327 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
328 // methods defined on WebRequest and removing this dependency would cause some code duplication.
329 $request = new DerivativeRequest( $this->getRequest(), $params );
330 $opts->fetchValuesFromRequest( $request );
338 protected function doMainQuery( $tables, $fields, $conds, $query_options,
339 $join_conds, FormOptions
$opts
341 $dbr = $this->getDB();
342 $user = $this->getUser();
344 $rcQuery = RecentChange
::getQueryInfo();
345 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
346 $fields = array_merge( $rcQuery['fields'], $fields );
348 $join_conds = array_merge(
353 'wl_user' => $user->getId(),
354 'wl_namespace=rc_namespace',
364 $fields[] = 'page_latest';
365 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
367 $fields[] = 'wl_notificationtimestamp';
369 // Log entries with DELETED_ACTION must not show up unless the user has
370 // the necessary rights.
371 if ( !$user->isAllowed( 'deletedhistory' ) ) {
372 $bitmask = LogPage
::DELETED_ACTION
;
373 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
374 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
379 $conds[] = $dbr->makeList( [
380 'rc_type != ' . RC_LOG
,
381 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
385 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
386 ChangeTags
::modifyDisplayQuery(
395 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
397 if ( $this->areFiltersInConflict() ) {
402 'ORDER BY' => 'rc_timestamp DESC',
403 'LIMIT' => $opts['limit']
405 if ( in_array( 'DISTINCT', $query_options ) ) {
406 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
407 // In order to prevent DISTINCT from causing query performance problems,
408 // we have to GROUP BY the primary key. This in turn requires us to add
409 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
410 // start of the GROUP BY
411 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
412 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
414 // array_merge() is used intentionally here so that hooks can, should
415 // they so desire, override the ORDER BY / LIMIT condition(s)
416 $query_options = array_merge( $orderByAndLimit, $query_options );
429 * Return a IDatabase object for reading
433 protected function getDB() {
434 return wfGetDB( DB_REPLICA
, 'watchlist' );
440 public function outputFeedLinks() {
441 $user = $this->getUser();
442 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
444 $this->addFeedLinks( [
445 'action' => 'feedwatchlist',
447 'wlowner' => $user->getName(),
448 'wltoken' => $wlToken,
454 * Build and output the actual changes list.
456 * @param IResultWrapper $rows Database rows
457 * @param FormOptions $opts
459 public function outputChangesList( $rows, $opts ) {
460 $dbr = $this->getDB();
461 $user = $this->getUser();
462 $output = $this->getOutput();
463 $services = MediaWikiServices
::getInstance();
465 # Show a message about replica DB lag, if applicable
466 $lag = $services->getDBLoadBalancer()->safeGetLag( $dbr );
468 $output->showLagWarning( $lag );
471 # If no rows to display, show message before try to render the list
472 if ( $rows->numRows() == 0 ) {
473 $output->wrapWikiMsg(
474 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
479 $dbr->dataSeek( $rows, 0 );
481 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
482 $list->setWatchlistDivs();
483 $list->initChangesListRows( $rows );
484 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
485 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
486 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
487 // since EnhancedChangesList groups log entries by performer rather than by target article
488 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
492 return $this->getLinkRenderer()
493 ->makeKnownLink( $rc->getTitle(),
494 $this->msg( 'watchlist-unwatch' )->text(), [
495 'class' => 'mw-unwatch-link',
496 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
497 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
501 $dbr->dataSeek( $rows, 0 );
503 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
504 && $user->getOption( 'shownumberswatching' )
506 $watchedItemStore = $services->getWatchedItemStore();
509 $s = $list->beginRecentChangesList();
511 if ( $this->isStructuredFilterUiEnabled() ) {
512 $s .= $this->makeLegend();
515 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
517 foreach ( $rows as $obj ) {
519 $rc = RecentChange
::newFromRow( $obj );
521 # Skip CatWatch entries for hidden cats based on user preference
523 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
524 !$userShowHiddenCats &&
525 $rc->getParam( 'hidden-cat' )
530 $rc->counter
= $counter++
;
532 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
533 $updated = $obj->wl_notificationtimestamp
;
538 if ( isset( $watchedItemStore ) ) {
539 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
540 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
542 $rc->numberofWatchingusers
= 0;
545 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
546 if ( $changeLine !== false ) {
550 $s .= $list->endRecentChangesList();
552 $output->addHTML( $s );
556 * Set the text to be displayed above the changes
558 * @param FormOptions $opts
559 * @param int $numRows Number of rows in the result to show after this header
561 public function doHeader( $opts, $numRows ) {
562 $user = $this->getUser();
563 $out = $this->getOutput();
566 $this->msg( 'watchlistfor2', $user->getName() )
567 ->rawParams( SpecialEditWatchlist
::buildTools(
568 $this->getLanguage(),
569 $this->getLinkRenderer()
573 $this->setTopText( $opts );
577 $form .= Xml
::openElement( 'form', [
579 'action' => wfScript(),
580 'id' => 'mw-watchlist-form'
582 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
583 $form .= Xml
::openElement(
585 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
587 $form .= Xml
::element(
588 'legend', null, $this->msg( 'watchlist-options' )->text()
591 if ( !$this->isStructuredFilterUiEnabled() ) {
592 $form .= $this->makeLegend();
595 $lang = $this->getLanguage();
596 $timestamp = wfTimestampNow();
597 $wlInfo = Html
::rawElement(
601 'data-params' => json_encode( [ 'from' => $timestamp ] ),
603 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
604 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
608 $nondefaults = $opts->getChangedValues();
609 $cutofflinks = Html
::rawElement(
611 [ 'class' => 'cldays cloption' ],
612 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
615 # Spit out some control panel links
617 $namesOfDisplayedFilters = [];
618 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
619 $namesOfDisplayedFilters[] = $filterName;
620 $links[] = $this->showHideCheck(
622 $filter->getShowHide(),
624 $opts[ $filterName ],
625 $filter->isFeatureAvailableOnStructuredUi( $this )
629 $hiddenFields = $nondefaults;
630 $hiddenFields['action'] = 'submit';
631 unset( $hiddenFields['namespace'] );
632 unset( $hiddenFields['invert'] );
633 unset( $hiddenFields['associated'] );
634 unset( $hiddenFields['days'] );
635 foreach ( $namesOfDisplayedFilters as $filterName ) {
636 unset( $hiddenFields[$filterName] );
639 # Namespace filter and put the whole form together.
641 $form .= $cutofflinks;
642 $form .= Html
::rawElement(
644 [ 'class' => 'clshowhide' ],
645 $this->msg( 'watchlist-hide' ) .
646 $this->msg( 'colon-separator' )->escaped() .
647 implode( ' ', $links )
649 $form .= "\n<br />\n";
651 $namespaceForm = Html
::namespaceSelector(
653 'selected' => $opts['namespace'],
655 'label' => $this->msg( 'namespace' )->text(),
656 'in-user-lang' => true,
658 'name' => 'namespace',
660 'class' => 'namespaceselector',
663 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
664 $this->msg( 'invert' )->text(),
668 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
670 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
671 $this->msg( 'namespace_association' )->text(),
675 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
677 $form .= Html
::rawElement(
679 [ 'class' => 'namespaceForm cloption' ],
683 $form .= Xml
::submitButton(
684 $this->msg( 'watchlist-submit' )->text(),
685 [ 'class' => 'cloption-submit' ]
687 foreach ( $hiddenFields as $key => $value ) {
688 $form .= Html
::hidden( $key, $value ) . "\n";
690 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
691 $form .= Xml
::closeElement( 'form' ) . "\n";
693 // Insert a placeholder for RCFilters
694 if ( $this->isStructuredFilterUiEnabled() ) {
695 $rcfilterContainer = Html
::element(
697 [ 'class' => 'rcfilters-container' ]
700 $loadingContainer = Html
::rawElement(
702 [ 'class' => 'rcfilters-spinner' ],
705 [ 'class' => 'rcfilters-spinner-bounce' ]
709 // Wrap both with rcfilters-head
710 $this->getOutput()->addHTML(
713 [ 'class' => 'rcfilters-head' ],
714 $rcfilterContainer . $form
719 $this->getOutput()->addHTML( $loadingContainer );
721 $this->getOutput()->addHTML( $form );
724 $this->setBottomText( $opts );
727 function cutoffselector( $options ) {
728 $selected = (float)$options['days'];
729 if ( $selected <= 0 ) {
730 $selected = $this->maxDays
;
733 $selectedHours = round( $selected * 24 );
735 $hours = array_unique( array_filter( [
743 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
749 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
751 foreach ( $hours as $value ) {
753 $name = $this->msg( 'hours' )->numParams( $value )->text();
755 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
757 $select->addOption( $name, (float)( $value / 24 ) );
760 return $select->getHTML() . "\n<br />\n";
763 function setTopText( FormOptions
$opts ) {
764 $nondefaults = $opts->getChangedValues();
766 $user = $this->getUser();
768 $numItems = $this->countItems();
769 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
771 // Show watchlist header
772 $watchlistHeader = '';
773 if ( $numItems == 0 ) {
774 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
776 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
777 if ( $this->getConfig()->get( 'EnotifWatchlist' )
778 && $user->getOption( 'enotifwatchlistpages' )
780 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
782 if ( $showUpdatedMarker ) {
783 $watchlistHeader .= $this->msg(
784 $this->isStructuredFilterUiEnabled() ?
785 'rcfilters-watchlist-showupdated' :
786 'wlheader-showupdated'
790 $form .= Html
::rawElement(
792 [ 'class' => 'watchlistDetails' ],
796 if ( $numItems > 0 && $showUpdatedMarker ) {
797 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
798 'action' => $this->getPageTitle()->getLocalURL(),
799 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
800 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
801 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
802 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
803 Html
::hidden( 'reset', 'all' ) . "\n";
804 foreach ( $nondefaults as $key => $value ) {
805 $form .= Html
::hidden( $key, $value ) . "\n";
807 $form .= Xml
::closeElement( 'form' ) . "\n";
810 $this->getOutput()->addHTML( $form );
813 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
814 $options[$name] = 1 - (int)$value;
816 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
817 if ( $inStructuredUi ) {
818 $attribs[ 'data-feature-in-structured-ui' ] = true;
821 return Html
::rawElement(
824 // not using Html::checkLabel because that would escape the contents
825 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
827 $attribs +
[ 'for' => $name ],
828 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
829 $this->msg( $message, '<nowiki/>' )->parse()
835 * Count the number of paired items on a user's watchlist.
836 * The assumption made here is that when a subject page is watched a talk page is also watched.
837 * Hence the number of individual items is halved.
841 protected function countItems() {
842 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
843 $count = $store->countWatchedItems( $this->getUser() );
844 return floor( $count / 2 );