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->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
102 $output->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false );
103 $output->addJsConfigVars(
104 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
105 'rcfilters-wl-saved-queries'
107 $output->addJsConfigVars(
108 'wgStructuredChangeFiltersEditWatchlistUrl',
109 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
114 protected function isStructuredFilterUiEnabled() {
115 return parent
::isStructuredFilterUiEnabled()
116 && ( $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' )
117 ||
$this->getRequest()->getBool( 'rcfilters' ) );
121 * Return an array of subpages that this special page will accept.
123 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
124 * @return string[] subpages
126 public function getSubpagesForPrefixSearch() {
137 protected function transformFilterDefinition( array $filterDefinition ) {
138 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
139 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
142 return $filterDefinition;
148 protected function registerFilters() {
149 parent
::registerFilters();
151 // legacy 'extended' filter
152 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
153 'name' => 'extended-group',
156 'name' => 'extended',
157 'isReplacedInStructuredUi' => true,
158 'activeValue' => false,
159 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
160 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
161 &$fields, &$conds, &$query_options, &$join_conds ) {
162 $nonRevisionTypes = [ RC_LOG
];
163 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
164 if ( $nonRevisionTypes ) {
165 $conds[] = $dbr->makeList(
167 'rc_this_oldid=page_latest',
168 'rc_type' => $nonRevisionTypes,
179 if ( $this->isStructuredFilterUiEnabled() ) {
180 $this->getFilterGroup( 'lastRevision' )
181 ->getFilter( 'hidepreviousrevisions' )
182 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
185 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
186 'name' => 'watchlistactivity',
187 'title' => 'rcfilters-filtergroup-watchlistactivity',
188 'class' => ChangesListStringOptionsFilterGroup
::class,
190 'isFullCoverage' => true,
194 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
195 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
196 'cssClassSuffix' => 'watchedunseen',
197 'isRowApplicableCallable' => function ( $ctx, $rc ) {
198 $changeTs = $rc->getAttribute( 'rc_timestamp' );
199 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
200 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
205 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
206 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
207 'cssClassSuffix' => 'watchedseen',
208 'isRowApplicableCallable' => function ( $ctx, $rc ) {
209 $changeTs = $rc->getAttribute( 'rc_timestamp' );
210 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
211 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
215 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
216 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
217 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
218 if ( $selectedValues === [ 'seen' ] ) {
219 $conds[] = $dbr->makeList( [
220 'wl_notificationtimestamp IS NULL',
221 'rc_timestamp < wl_notificationtimestamp'
223 } elseif ( $selectedValues === [ 'unseen' ] ) {
224 $conds[] = $dbr->makeList( [
225 'wl_notificationtimestamp IS NOT NULL',
226 'rc_timestamp >= wl_notificationtimestamp'
232 $user = $this->getUser();
234 $significance = $this->getFilterGroup( 'significance' );
235 $hideMinor = $significance->getFilter( 'hideminor' );
236 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
238 $automated = $this->getFilterGroup( 'automated' );
239 $hideBots = $automated->getFilter( 'hidebots' );
240 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
242 $registration = $this->getFilterGroup( 'registration' );
243 $hideAnons = $registration->getFilter( 'hideanons' );
244 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
245 $hideLiu = $registration->getFilter( 'hideliu' );
246 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
248 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
249 if ( $reviewStatus !== null ) {
250 // Conditional on feature being available and rights
251 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
252 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
255 $authorship = $this->getFilterGroup( 'authorship' );
256 $hideMyself = $authorship->getFilter( 'hidemyself' );
257 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
259 $changeType = $this->getFilterGroup( 'changeType' );
260 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
261 if ( $hideCategorization !== null ) {
262 // Conditional on feature being available
263 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
268 * Get a FormOptions object containing the default options
270 * @return FormOptions
272 public function getDefaultOptions() {
273 $opts = parent
::getDefaultOptions();
274 $user = $this->getUser();
276 $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions
::FLOAT );
277 $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions
::INT );
282 public function validateOptions( FormOptions
$opts ) {
283 $opts->validateBounds( 'days', 0, $this->maxDays
);
284 $opts->validateIntBounds( 'limit', 0, 5000 );
285 parent
::validateOptions( $opts );
289 * Get all custom filters
291 * @return array Map of filter URL param names to properties (msg/default)
293 protected function getCustomFilters() {
294 if ( $this->customFilters
=== null ) {
295 $this->customFilters
= parent
::getCustomFilters();
296 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
299 return $this->customFilters
;
303 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
305 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
306 * to the current ones.
308 * @param FormOptions $opts
309 * @return FormOptions
311 protected function fetchOptionsFromRequest( $opts ) {
312 static $compatibilityMap = [
313 'hideMinor' => 'hideminor',
314 'hideBots' => 'hidebots',
315 'hideAnons' => 'hideanons',
316 'hideLiu' => 'hideliu',
317 'hidePatrolled' => 'hidepatrolled',
318 'hideOwn' => 'hidemyself',
321 $params = $this->getRequest()->getValues();
322 foreach ( $compatibilityMap as $from => $to ) {
323 if ( isset( $params[$from] ) ) {
324 $params[$to] = $params[$from];
325 unset( $params[$from] );
329 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
330 $allBooleansFalse = [];
332 // If the user submitted the form, start with a baseline of "all
333 // booleans are false", then change the ones they checked. This
334 // means we ignore the defaults.
336 // This is how we handle the fact that HTML forms don't submit
338 foreach ( $this->filterGroups
as $filterGroup ) {
339 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
340 /** @var ChangesListBooleanFilter $filter */
341 foreach ( $filterGroup->getFilters() as $filter ) {
342 if ( $filter->displaysOnUnstructuredUi() ) {
343 $allBooleansFalse[$filter->getName()] = false;
349 $params = $params +
$allBooleansFalse;
352 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
353 // methods defined on WebRequest and removing this dependency would cause some code duplication.
354 $request = new DerivativeRequest( $this->getRequest(), $params );
355 $opts->fetchValuesFromRequest( $request );
363 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
364 &$join_conds, FormOptions
$opts
366 $dbr = $this->getDB();
367 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
371 if ( $opts['days'] > 0 ) {
372 $conds[] = 'rc_timestamp > ' .
373 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
380 protected function doMainQuery( $tables, $fields, $conds, $query_options,
381 $join_conds, FormOptions
$opts
383 $dbr = $this->getDB();
384 $user = $this->getUser();
386 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
387 $fields = array_merge( RecentChange
::selectFields(), $fields );
389 $query_options = array_merge( [
390 'ORDER BY' => 'rc_timestamp DESC',
391 'LIMIT' => $opts['limit']
393 $join_conds = array_merge(
398 'wl_user' => $user->getId(),
399 'wl_namespace=rc_namespace',
408 $fields[] = 'page_latest';
409 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
411 $fields[] = 'wl_notificationtimestamp';
413 // Log entries with DELETED_ACTION must not show up unless the user has
414 // the necessary rights.
415 if ( !$user->isAllowed( 'deletedhistory' ) ) {
416 $bitmask = LogPage
::DELETED_ACTION
;
417 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
418 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
423 $conds[] = $dbr->makeList( [
424 'rc_type != ' . RC_LOG
,
425 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
429 ChangeTags
::modifyDisplayQuery(
438 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
440 if ( $this->areFiltersInConflict() ) {
454 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
457 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
459 'SpecialWatchlistQuery',
460 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
466 * Return a IDatabase object for reading
470 protected function getDB() {
471 return wfGetDB( DB_REPLICA
, 'watchlist' );
477 public function outputFeedLinks() {
478 $user = $this->getUser();
479 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
481 $this->addFeedLinks( [
482 'action' => 'feedwatchlist',
484 'wlowner' => $user->getName(),
485 'wltoken' => $wlToken,
491 * Build and output the actual changes list.
493 * @param ResultWrapper $rows Database rows
494 * @param FormOptions $opts
496 public function outputChangesList( $rows, $opts ) {
497 $dbr = $this->getDB();
498 $user = $this->getUser();
499 $output = $this->getOutput();
501 # Show a message about replica DB lag, if applicable
502 $lag = wfGetLB()->safeGetLag( $dbr );
504 $output->showLagWarning( $lag );
507 # If no rows to display, show message before try to render the list
508 if ( $rows->numRows() == 0 ) {
509 $output->wrapWikiMsg(
510 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
515 $dbr->dataSeek( $rows, 0 );
517 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
518 $list->setWatchlistDivs();
519 $list->initChangesListRows( $rows );
520 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
521 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
522 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
523 // since EnhancedChangesList groups log entries by performer rather than by target article
524 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
528 return $this->getLinkRenderer()
529 ->makeKnownLink( $rc->getTitle(),
530 $this->msg( 'watchlist-unwatch' )->text(), [
531 'class' => 'mw-unwatch-link',
532 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
533 ], [ 'action' => 'unwatch' ] ) . ' ';
537 $dbr->dataSeek( $rows, 0 );
539 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
540 && $user->getOption( 'shownumberswatching' )
542 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
545 $s = $list->beginRecentChangesList();
547 if ( $this->isStructuredFilterUiEnabled() ) {
548 $s .= $this->makeLegend();
551 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
553 foreach ( $rows as $obj ) {
555 $rc = RecentChange
::newFromRow( $obj );
557 # Skip CatWatch entries for hidden cats based on user preference
559 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
560 !$userShowHiddenCats &&
561 $rc->getParam( 'hidden-cat' )
566 $rc->counter
= $counter++
;
568 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
569 $updated = $obj->wl_notificationtimestamp
;
574 if ( isset( $watchedItemStore ) ) {
575 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
576 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
578 $rc->numberofWatchingusers
= 0;
581 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
582 if ( $changeLine !== false ) {
586 $s .= $list->endRecentChangesList();
588 $output->addHTML( $s );
592 * Set the text to be displayed above the changes
594 * @param FormOptions $opts
595 * @param int $numRows Number of rows in the result to show after this header
597 public function doHeader( $opts, $numRows ) {
598 $user = $this->getUser();
599 $out = $this->getOutput();
602 $this->msg( 'watchlistfor2', $user->getName() )
603 ->rawParams( SpecialEditWatchlist
::buildTools(
604 $this->getLanguage(),
605 $this->getLinkRenderer()
609 $this->setTopText( $opts );
613 $form .= Xml
::openElement( 'form', [
615 'action' => wfScript(),
616 'id' => 'mw-watchlist-form'
618 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
619 $form .= Xml
::fieldset(
620 $this->msg( 'watchlist-options' )->text(),
622 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
625 if ( !$this->isStructuredFilterUiEnabled() ) {
626 $form .= $this->makeLegend();
629 $lang = $this->getLanguage();
630 if ( $opts['days'] > 0 ) {
631 $days = $opts['days'];
633 $days = $this->maxDays
;
635 $timestamp = wfTimestampNow();
636 $wlInfo = Html
::rawElement(
638 [ 'class' => 'wlinfo' ],
639 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
640 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
644 $nondefaults = $opts->getChangedValues();
645 $cutofflinks = Html
::rawElement(
647 [ 'class' => 'cldays cloption' ],
648 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
651 # Spit out some control panel links
653 $namesOfDisplayedFilters = [];
654 foreach ( $this->getFilterGroups() as $groupName => $group ) {
655 if ( !$group->isPerGroupRequestParameter() ) {
656 foreach ( $group->getFilters() as $filterName => $filter ) {
657 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
658 $namesOfDisplayedFilters[] = $filterName;
659 $links[] = $this->showHideCheck(
661 $filter->getShowHide(),
664 $filter->isFeatureAvailableOnStructuredUi( $this )
671 $hiddenFields = $nondefaults;
672 $hiddenFields['action'] = 'submit';
673 unset( $hiddenFields['namespace'] );
674 unset( $hiddenFields['invert'] );
675 unset( $hiddenFields['associated'] );
676 unset( $hiddenFields['days'] );
677 foreach ( $namesOfDisplayedFilters as $filterName ) {
678 unset( $hiddenFields[$filterName] );
681 # Namespace filter and put the whole form together.
683 $form .= $cutofflinks;
684 $form .= Html
::rawElement(
686 [ 'class' => 'clshowhide' ],
687 $this->msg( 'watchlist-hide' ) .
688 $this->msg( 'colon-separator' )->escaped() .
689 implode( ' ', $links )
691 $form .= "\n<br />\n";
693 $namespaceForm = Html
::namespaceSelector(
695 'selected' => $opts['namespace'],
697 'label' => $this->msg( 'namespace' )->text()
699 'name' => 'namespace',
701 'class' => 'namespaceselector',
704 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
705 $this->msg( 'invert' )->text(),
709 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
711 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
712 $this->msg( 'namespace_association' )->text(),
716 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
718 $form .= Html
::rawElement(
720 [ 'class' => 'namespaceForm cloption' ],
724 $form .= Xml
::submitButton(
725 $this->msg( 'watchlist-submit' )->text(),
726 [ 'class' => 'cloption-submit' ]
728 foreach ( $hiddenFields as $key => $value ) {
729 $form .= Html
::hidden( $key, $value ) . "\n";
731 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
732 $form .= Xml
::closeElement( 'form' ) . "\n";
734 // Insert a placeholder for RCFilters
735 if ( $this->isStructuredFilterUiEnabled() ) {
736 $rcfilterContainer = Html
::element(
738 [ 'class' => 'rcfilters-container' ]
741 $loadingContainer = Html
::rawElement(
743 [ 'class' => 'rcfilters-spinner' ],
746 [ 'class' => 'rcfilters-spinner-bounce' ]
750 // Wrap both with rcfilters-head
751 $this->getOutput()->addHTML(
754 [ 'class' => 'rcfilters-head' ],
755 $rcfilterContainer . $form
760 $this->getOutput()->addHTML( $loadingContainer );
762 $this->getOutput()->addHTML( $form );
765 $this->setBottomText( $opts );
768 function cutoffselector( $options ) {
769 // Cast everything to strings immediately, so that we know all of the values have the same
770 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
771 // default string representation, for example, and would confuse comparisons.
773 // Misleadingly, the 'days' option supports hours too.
774 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
776 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
777 // add the user preference, if it isn't available already
778 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
779 $days[] = $userWatchlistOption;
782 $maxDays = (string)$this->maxDays
;
783 // add the maximum possible value, if it isn't available already
784 if ( !in_array( $maxDays, $days ) ) {
788 $selected = (string)$options['days'];
789 if ( $selected <= 0 ) {
790 $selected = $maxDays;
793 // add the currently selected value, if it isn't available already
794 if ( !in_array( $selected, $days ) ) {
798 $select = new XmlSelect( 'days', 'days', $selected );
801 foreach ( $days as $value ) {
803 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
805 $name = $this->msg( 'days' )->numParams( $value )->text();
807 $select->addOption( $name, $value );
810 return $select->getHTML() . "\n<br />\n";
813 function setTopText( FormOptions
$opts ) {
814 $nondefaults = $opts->getChangedValues();
816 $user = $this->getUser();
818 $numItems = $this->countItems();
819 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
821 // Show watchlist header
822 $watchlistHeader = '';
823 if ( $numItems == 0 ) {
824 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
826 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
827 if ( $this->getConfig()->get( 'EnotifWatchlist' )
828 && $user->getOption( 'enotifwatchlistpages' )
830 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
832 if ( $showUpdatedMarker ) {
833 $watchlistHeader .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
836 $form .= Html
::rawElement(
838 [ 'class' => 'watchlistDetails' ],
842 if ( $numItems > 0 && $showUpdatedMarker ) {
843 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
844 'action' => $this->getPageTitle()->getLocalURL(),
845 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
846 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
847 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
848 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
849 Html
::hidden( 'reset', 'all' ) . "\n";
850 foreach ( $nondefaults as $key => $value ) {
851 $form .= Html
::hidden( $key, $value ) . "\n";
853 $form .= Xml
::closeElement( 'form' ) . "\n";
856 $this->getOutput()->addHTML( $form );
859 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
860 $options[$name] = 1 - (int)$value;
862 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
863 if ( $inStructuredUi ) {
864 $attribs[ 'data-feature-in-structured-ui' ] = true;
867 return Html
::rawElement(
871 $this->msg( $message, '' )->text(),
880 * Count the number of paired items on a user's watchlist.
881 * The assumption made here is that when a subject page is watched a talk page is also watched.
882 * Hence the number of individual items is halved.
886 protected function countItems() {
887 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
888 $count = $store->countWatchedItems( $this->getUser() );
889 return floor( $count / 2 );
892 function getDefaultLimit() {
893 return $this->getUser()->getIntOption( 'wllimit' );
896 function getDefaultDays() {
897 return $this->getUser()->getIntOption( 'watchlistdays' );