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
{
35 protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
39 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
40 parent
::__construct( $page, $restriction );
42 $this->maxDays
= $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
45 public function doesWrites() {
50 * Main execution point
52 * @param string $subpage
54 function execute( $subpage ) {
55 // Anons don't get a watchlist
56 $this->requireLogin( 'watchlistanontext' );
58 $output = $this->getOutput();
59 $request = $this->getRequest();
60 $this->addHelpLink( 'Help:Watching pages' );
61 $output->addModules( [
62 'mediawiki.special.changeslist.visitedstatus',
63 'mediawiki.special.watchlist',
65 $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] );
67 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
68 if ( $mode !== false ) {
69 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
70 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
71 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
72 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
74 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
77 $output->redirect( $title->getLocalURL() );
82 $this->checkPermissions();
84 $user = $this->getUser();
85 $opts = $this->getOptions();
87 $config = $this->getConfig();
88 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
89 && $request->getVal( 'reset' )
90 && $request->wasPosted()
91 && $user->matchEditToken( $request->getVal( 'token' ) )
93 $user->clearAllNotifications();
94 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
99 parent
::execute( $subpage );
101 if ( $this->isStructuredFilterUiEnabled() ) {
102 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
104 $output->addJsConfigVars(
105 'wgStructuredChangeFiltersEditWatchlistUrl',
106 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
111 public function isStructuredFilterUiEnabled() {
112 return $this->getRequest()->getBool( 'rcfilters' ) ||
(
113 $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
114 $this->getUser()->getOption( 'rcenhancedfilters' )
118 public function isStructuredFilterUiEnabledByDefault() {
119 return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
120 $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
124 * Return an array of subpages that this special page will accept.
126 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
127 * @return string[] subpages
129 public function getSubpagesForPrefixSearch() {
140 protected function transformFilterDefinition( array $filterDefinition ) {
141 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
142 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
145 return $filterDefinition;
151 protected function registerFilters() {
152 parent
::registerFilters();
154 // legacy 'extended' filter
155 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
156 'name' => 'extended-group',
159 'name' => 'extended',
160 'isReplacedInStructuredUi' => true,
161 'activeValue' => false,
162 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
163 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
164 &$fields, &$conds, &$query_options, &$join_conds ) {
165 $nonRevisionTypes = [ RC_LOG
];
166 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
167 if ( $nonRevisionTypes ) {
168 $conds[] = $dbr->makeList(
170 'rc_this_oldid=page_latest',
171 'rc_type' => $nonRevisionTypes,
182 if ( $this->isStructuredFilterUiEnabled() ) {
183 $this->getFilterGroup( 'lastRevision' )
184 ->getFilter( 'hidepreviousrevisions' )
185 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
188 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
189 'name' => 'watchlistactivity',
190 'title' => 'rcfilters-filtergroup-watchlistactivity',
191 'class' => ChangesListStringOptionsFilterGroup
::class,
193 'isFullCoverage' => true,
197 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
198 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
199 'cssClassSuffix' => 'watchedunseen',
200 'isRowApplicableCallable' => function ( $ctx, $rc ) {
201 $changeTs = $rc->getAttribute( 'rc_timestamp' );
202 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
203 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
208 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
209 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
210 'cssClassSuffix' => 'watchedseen',
211 'isRowApplicableCallable' => function ( $ctx, $rc ) {
212 $changeTs = $rc->getAttribute( 'rc_timestamp' );
213 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
214 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
218 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
219 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
220 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
221 if ( $selectedValues === [ 'seen' ] ) {
222 $conds[] = $dbr->makeList( [
223 'wl_notificationtimestamp IS NULL',
224 'rc_timestamp < wl_notificationtimestamp'
226 } elseif ( $selectedValues === [ 'unseen' ] ) {
227 $conds[] = $dbr->makeList( [
228 'wl_notificationtimestamp IS NOT NULL',
229 'rc_timestamp >= wl_notificationtimestamp'
235 $user = $this->getUser();
237 $significance = $this->getFilterGroup( 'significance' );
238 $hideMinor = $significance->getFilter( 'hideminor' );
239 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
241 $automated = $this->getFilterGroup( 'automated' );
242 $hideBots = $automated->getFilter( 'hidebots' );
243 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
245 $registration = $this->getFilterGroup( 'registration' );
246 $hideAnons = $registration->getFilter( 'hideanons' );
247 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
248 $hideLiu = $registration->getFilter( 'hideliu' );
249 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
251 // Selecting both hideanons and hideliu on watchlist preferances
252 // gives mutually exclusive filters, so those are ignored
253 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
254 !$user->getBoolOption( 'watchlisthideliu' )
256 $this->getFilterGroup( 'userExpLevel' )
257 ->setDefault( 'registered' );
260 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
261 !$user->getBoolOption( 'watchlisthideanons' )
263 $this->getFilterGroup( 'userExpLevel' )
264 ->setDefault( 'unregistered' );
267 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
268 if ( $reviewStatus !== null ) {
269 // Conditional on feature being available and rights
270 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
271 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
274 $authorship = $this->getFilterGroup( 'authorship' );
275 $hideMyself = $authorship->getFilter( 'hidemyself' );
276 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
278 $changeType = $this->getFilterGroup( 'changeType' );
279 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
280 if ( $hideCategorization !== null ) {
281 // Conditional on feature being available
282 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
287 * Get all custom filters
289 * @return array Map of filter URL param names to properties (msg/default)
291 protected function getCustomFilters() {
292 if ( $this->customFilters
=== null ) {
293 $this->customFilters
= parent
::getCustomFilters();
294 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
297 return $this->customFilters
;
301 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
303 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
304 * to the current ones.
306 * @param FormOptions $opts
307 * @return FormOptions
309 protected function fetchOptionsFromRequest( $opts ) {
310 static $compatibilityMap = [
311 'hideMinor' => 'hideminor',
312 'hideBots' => 'hidebots',
313 'hideAnons' => 'hideanons',
314 'hideLiu' => 'hideliu',
315 'hidePatrolled' => 'hidepatrolled',
316 'hideOwn' => 'hidemyself',
319 $params = $this->getRequest()->getValues();
320 foreach ( $compatibilityMap as $from => $to ) {
321 if ( isset( $params[$from] ) ) {
322 $params[$to] = $params[$from];
323 unset( $params[$from] );
327 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
328 $allBooleansFalse = [];
330 // If the user submitted the form, start with a baseline of "all
331 // booleans are false", then change the ones they checked. This
332 // means we ignore the defaults.
334 // This is how we handle the fact that HTML forms don't submit
336 foreach ( $this->filterGroups
as $filterGroup ) {
337 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
338 /** @var ChangesListBooleanFilter $filter */
339 foreach ( $filterGroup->getFilters() as $filter ) {
340 if ( $filter->displaysOnUnstructuredUi() ) {
341 $allBooleansFalse[$filter->getName()] = false;
347 $params = $params +
$allBooleansFalse;
350 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
351 // methods defined on WebRequest and removing this dependency would cause some code duplication.
352 $request = new DerivativeRequest( $this->getRequest(), $params );
353 $opts->fetchValuesFromRequest( $request );
361 protected function doMainQuery( $tables, $fields, $conds, $query_options,
362 $join_conds, FormOptions
$opts
364 $dbr = $this->getDB();
365 $user = $this->getUser();
367 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
368 $fields = array_merge( RecentChange
::selectFields(), $fields );
370 $join_conds = array_merge(
375 'wl_user' => $user->getId(),
376 'wl_namespace=rc_namespace',
385 $fields[] = 'page_latest';
386 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
388 $fields[] = 'wl_notificationtimestamp';
390 // Log entries with DELETED_ACTION must not show up unless the user has
391 // the necessary rights.
392 if ( !$user->isAllowed( 'deletedhistory' ) ) {
393 $bitmask = LogPage
::DELETED_ACTION
;
394 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
395 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
400 $conds[] = $dbr->makeList( [
401 'rc_type != ' . RC_LOG
,
402 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
406 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
407 ChangeTags
::modifyDisplayQuery(
416 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
418 if ( $this->areFiltersInConflict() ) {
423 'ORDER BY' => 'rc_timestamp DESC',
424 'LIMIT' => $opts['limit']
426 if ( in_array( 'DISTINCT', $query_options ) ) {
427 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
428 // In order to prevent DISTINCT from causing query performance problems,
429 // we have to GROUP BY the primary key. This in turn requires us to add
430 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
431 // start of the GROUP BY
432 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
433 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
435 // array_merge() is used intentionally here so that hooks can, should
436 // they so desire, override the ORDER BY / LIMIT condition(s)
437 $query_options = array_merge( $orderByAndLimit, $query_options );
449 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
452 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
454 'SpecialWatchlistQuery',
455 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
461 * Return a IDatabase object for reading
465 protected function getDB() {
466 return wfGetDB( DB_REPLICA
, 'watchlist' );
472 public function outputFeedLinks() {
473 $user = $this->getUser();
474 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
476 $this->addFeedLinks( [
477 'action' => 'feedwatchlist',
479 'wlowner' => $user->getName(),
480 'wltoken' => $wlToken,
486 * Build and output the actual changes list.
488 * @param ResultWrapper $rows Database rows
489 * @param FormOptions $opts
491 public function outputChangesList( $rows, $opts ) {
492 $dbr = $this->getDB();
493 $user = $this->getUser();
494 $output = $this->getOutput();
496 # Show a message about replica DB lag, if applicable
497 $lag = wfGetLB()->safeGetLag( $dbr );
499 $output->showLagWarning( $lag );
502 # If no rows to display, show message before try to render the list
503 if ( $rows->numRows() == 0 ) {
504 $output->wrapWikiMsg(
505 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
510 $dbr->dataSeek( $rows, 0 );
512 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
513 $list->setWatchlistDivs();
514 $list->initChangesListRows( $rows );
515 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
516 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
517 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
518 // since EnhancedChangesList groups log entries by performer rather than by target article
519 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
523 return $this->getLinkRenderer()
524 ->makeKnownLink( $rc->getTitle(),
525 $this->msg( 'watchlist-unwatch' )->text(), [
526 'class' => 'mw-unwatch-link',
527 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
528 ], [ 'action' => 'unwatch' ] ) . ' ';
532 $dbr->dataSeek( $rows, 0 );
534 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
535 && $user->getOption( 'shownumberswatching' )
537 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
540 $s = $list->beginRecentChangesList();
542 if ( $this->isStructuredFilterUiEnabled() ) {
543 $s .= $this->makeLegend();
546 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
548 foreach ( $rows as $obj ) {
550 $rc = RecentChange
::newFromRow( $obj );
552 # Skip CatWatch entries for hidden cats based on user preference
554 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
555 !$userShowHiddenCats &&
556 $rc->getParam( 'hidden-cat' )
561 $rc->counter
= $counter++
;
563 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
564 $updated = $obj->wl_notificationtimestamp
;
569 if ( isset( $watchedItemStore ) ) {
570 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
571 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
573 $rc->numberofWatchingusers
= 0;
576 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
577 if ( $changeLine !== false ) {
581 $s .= $list->endRecentChangesList();
583 $output->addHTML( $s );
587 * Set the text to be displayed above the changes
589 * @param FormOptions $opts
590 * @param int $numRows Number of rows in the result to show after this header
592 public function doHeader( $opts, $numRows ) {
593 $user = $this->getUser();
594 $out = $this->getOutput();
597 $this->msg( 'watchlistfor2', $user->getName() )
598 ->rawParams( SpecialEditWatchlist
::buildTools(
599 $this->getLanguage(),
600 $this->getLinkRenderer()
604 $this->setTopText( $opts );
608 $form .= Xml
::openElement( 'form', [
610 'action' => wfScript(),
611 'id' => 'mw-watchlist-form'
613 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
614 $form .= Xml
::openElement(
616 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
618 $form .= Xml
::element(
619 'legend', null, $this->msg( 'watchlist-options' )->text()
622 if ( !$this->isStructuredFilterUiEnabled() ) {
623 $form .= $this->makeLegend();
626 $lang = $this->getLanguage();
627 $timestamp = wfTimestampNow();
628 $wlInfo = Html
::rawElement(
632 'data-params' => json_encode( [ 'from' => $timestamp ] ),
634 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
635 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
639 $nondefaults = $opts->getChangedValues();
640 $cutofflinks = Html
::rawElement(
642 [ 'class' => 'cldays cloption' ],
643 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
646 # Spit out some control panel links
648 $namesOfDisplayedFilters = [];
649 foreach ( $this->getFilterGroups() as $groupName => $group ) {
650 if ( !$group->isPerGroupRequestParameter() ) {
651 foreach ( $group->getFilters() as $filterName => $filter ) {
652 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
653 $namesOfDisplayedFilters[] = $filterName;
654 $links[] = $this->showHideCheck(
656 $filter->getShowHide(),
659 $filter->isFeatureAvailableOnStructuredUi( $this )
666 $hiddenFields = $nondefaults;
667 $hiddenFields['action'] = 'submit';
668 unset( $hiddenFields['namespace'] );
669 unset( $hiddenFields['invert'] );
670 unset( $hiddenFields['associated'] );
671 unset( $hiddenFields['days'] );
672 foreach ( $namesOfDisplayedFilters as $filterName ) {
673 unset( $hiddenFields[$filterName] );
676 # Namespace filter and put the whole form together.
678 $form .= $cutofflinks;
679 $form .= Html
::rawElement(
681 [ 'class' => 'clshowhide' ],
682 $this->msg( 'watchlist-hide' ) .
683 $this->msg( 'colon-separator' )->escaped() .
684 implode( ' ', $links )
686 $form .= "\n<br />\n";
688 $namespaceForm = Html
::namespaceSelector(
690 'selected' => $opts['namespace'],
692 'label' => $this->msg( 'namespace' )->text()
694 'name' => 'namespace',
696 'class' => 'namespaceselector',
699 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
700 $this->msg( 'invert' )->text(),
704 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
706 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
707 $this->msg( 'namespace_association' )->text(),
711 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
713 $form .= Html
::rawElement(
715 [ 'class' => 'namespaceForm cloption' ],
719 $form .= Xml
::submitButton(
720 $this->msg( 'watchlist-submit' )->text(),
721 [ 'class' => 'cloption-submit' ]
723 foreach ( $hiddenFields as $key => $value ) {
724 $form .= Html
::hidden( $key, $value ) . "\n";
726 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
727 $form .= Xml
::closeElement( 'form' ) . "\n";
729 // Insert a placeholder for RCFilters
730 if ( $this->isStructuredFilterUiEnabled() ) {
731 $rcfilterContainer = Html
::element(
733 [ 'class' => 'rcfilters-container' ]
736 $loadingContainer = Html
::rawElement(
738 [ 'class' => 'rcfilters-spinner' ],
741 [ 'class' => 'rcfilters-spinner-bounce' ]
745 // Wrap both with rcfilters-head
746 $this->getOutput()->addHTML(
749 [ 'class' => 'rcfilters-head' ],
750 $rcfilterContainer . $form
755 $this->getOutput()->addHTML( $loadingContainer );
757 $this->getOutput()->addHTML( $form );
760 $this->setBottomText( $opts );
763 function cutoffselector( $options ) {
764 // Cast everything to strings immediately, so that we know all of the values have the same
765 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
766 // default string representation, for example, and would confuse comparisons.
768 // Misleadingly, the 'days' option supports hours too.
769 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
771 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
772 // add the user preference, if it isn't available already
773 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
774 $days[] = $userWatchlistOption;
777 $maxDays = (string)$this->maxDays
;
778 // add the maximum possible value, if it isn't available already
779 if ( !in_array( $maxDays, $days ) ) {
783 $selected = (string)$options['days'];
784 if ( $selected <= 0 ) {
785 $selected = $maxDays;
788 // add the currently selected value, if it isn't available already
789 if ( !in_array( $selected, $days ) ) {
793 $select = new XmlSelect( 'days', 'days', $selected );
796 foreach ( $days as $value ) {
798 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
800 $name = $this->msg( 'days' )->numParams( $value )->text();
802 $select->addOption( $name, $value );
805 return $select->getHTML() . "\n<br />\n";
808 function setTopText( FormOptions
$opts ) {
809 $nondefaults = $opts->getChangedValues();
811 $user = $this->getUser();
813 $numItems = $this->countItems();
814 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
816 // Show watchlist header
817 $watchlistHeader = '';
818 if ( $numItems == 0 ) {
819 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
821 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
822 if ( $this->getConfig()->get( 'EnotifWatchlist' )
823 && $user->getOption( 'enotifwatchlistpages' )
825 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
827 if ( $showUpdatedMarker ) {
828 $watchlistHeader .= $this->msg(
829 $this->isStructuredFilterUiEnabled() ?
830 'rcfilters-watchlist-showupdated' :
831 'wlheader-showupdated'
835 $form .= Html
::rawElement(
837 [ 'class' => 'watchlistDetails' ],
841 if ( $numItems > 0 && $showUpdatedMarker ) {
842 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
843 'action' => $this->getPageTitle()->getLocalURL(),
844 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
845 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
846 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
847 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
848 Html
::hidden( 'reset', 'all' ) . "\n";
849 foreach ( $nondefaults as $key => $value ) {
850 $form .= Html
::hidden( $key, $value ) . "\n";
852 $form .= Xml
::closeElement( 'form' ) . "\n";
855 $this->getOutput()->addHTML( $form );
858 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
859 $options[$name] = 1 - (int)$value;
861 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
862 if ( $inStructuredUi ) {
863 $attribs[ 'data-feature-in-structured-ui' ] = true;
866 return Html
::rawElement(
870 $this->msg( $message, '' )->text(),
879 * Count the number of paired items on a user's watchlist.
880 * The assumption made here is that when a subject page is watched a talk page is also watched.
881 * Hence the number of individual items is halved.
885 protected function countItems() {
886 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
887 $count = $store->countWatchedItems( $this->getUser() );
888 return floor( $count / 2 );
891 function getDefaultLimit() {
892 return $this->getUser()->getIntOption( 'wllimit' );
895 function getDefaultDays() {
896 return floatval( $this->getUser()->getOption( 'watchlistdays' ) );