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 $join_conds = array_merge(
394 'wl_user' => $user->getId(),
395 'wl_namespace=rc_namespace',
404 $fields[] = 'page_latest';
405 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
407 $fields[] = 'wl_notificationtimestamp';
409 // Log entries with DELETED_ACTION must not show up unless the user has
410 // the necessary rights.
411 if ( !$user->isAllowed( 'deletedhistory' ) ) {
412 $bitmask = LogPage
::DELETED_ACTION
;
413 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
414 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
419 $conds[] = $dbr->makeList( [
420 'rc_type != ' . RC_LOG
,
421 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
425 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
426 ChangeTags
::modifyDisplayQuery(
435 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
437 if ( $this->areFiltersInConflict() ) {
442 'ORDER BY' => 'rc_timestamp DESC',
443 'LIMIT' => $opts['limit']
445 if ( in_array( 'DISTINCT', $query_options ) ) {
446 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
447 // In order to prevent DISTINCT from causing query performance problems,
448 // we have to GROUP BY the primary key. This in turn requires us to add
449 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
450 // start of the GROUP BY
451 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
452 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
454 // array_merge() is used intentionally here so that hooks can, should
455 // they so desire, override the ORDER BY / LIMIT condition(s)
456 $query_options = array_merge( $orderByAndLimit, $query_options );
468 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
471 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
473 'SpecialWatchlistQuery',
474 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
480 * Return a IDatabase object for reading
484 protected function getDB() {
485 return wfGetDB( DB_REPLICA
, 'watchlist' );
491 public function outputFeedLinks() {
492 $user = $this->getUser();
493 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
495 $this->addFeedLinks( [
496 'action' => 'feedwatchlist',
498 'wlowner' => $user->getName(),
499 'wltoken' => $wlToken,
505 * Build and output the actual changes list.
507 * @param ResultWrapper $rows Database rows
508 * @param FormOptions $opts
510 public function outputChangesList( $rows, $opts ) {
511 $dbr = $this->getDB();
512 $user = $this->getUser();
513 $output = $this->getOutput();
515 # Show a message about replica DB lag, if applicable
516 $lag = wfGetLB()->safeGetLag( $dbr );
518 $output->showLagWarning( $lag );
521 # If no rows to display, show message before try to render the list
522 if ( $rows->numRows() == 0 ) {
523 $output->wrapWikiMsg(
524 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
529 $dbr->dataSeek( $rows, 0 );
531 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
532 $list->setWatchlistDivs();
533 $list->initChangesListRows( $rows );
534 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
535 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
536 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
537 // since EnhancedChangesList groups log entries by performer rather than by target article
538 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
542 return $this->getLinkRenderer()
543 ->makeKnownLink( $rc->getTitle(),
544 $this->msg( 'watchlist-unwatch' )->text(), [
545 'class' => 'mw-unwatch-link',
546 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
547 ], [ 'action' => 'unwatch' ] ) . ' ';
551 $dbr->dataSeek( $rows, 0 );
553 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
554 && $user->getOption( 'shownumberswatching' )
556 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
559 $s = $list->beginRecentChangesList();
561 if ( $this->isStructuredFilterUiEnabled() ) {
562 $s .= $this->makeLegend();
565 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
567 foreach ( $rows as $obj ) {
569 $rc = RecentChange
::newFromRow( $obj );
571 # Skip CatWatch entries for hidden cats based on user preference
573 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
574 !$userShowHiddenCats &&
575 $rc->getParam( 'hidden-cat' )
580 $rc->counter
= $counter++
;
582 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
583 $updated = $obj->wl_notificationtimestamp
;
588 if ( isset( $watchedItemStore ) ) {
589 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
590 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
592 $rc->numberofWatchingusers
= 0;
595 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
596 if ( $changeLine !== false ) {
600 $s .= $list->endRecentChangesList();
602 $output->addHTML( $s );
606 * Set the text to be displayed above the changes
608 * @param FormOptions $opts
609 * @param int $numRows Number of rows in the result to show after this header
611 public function doHeader( $opts, $numRows ) {
612 $user = $this->getUser();
613 $out = $this->getOutput();
616 $this->msg( 'watchlistfor2', $user->getName() )
617 ->rawParams( SpecialEditWatchlist
::buildTools(
618 $this->getLanguage(),
619 $this->getLinkRenderer()
623 $this->setTopText( $opts );
627 $form .= Xml
::openElement( 'form', [
629 'action' => wfScript(),
630 'id' => 'mw-watchlist-form'
632 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
633 $form .= Xml
::fieldset(
634 $this->msg( 'watchlist-options' )->text(),
636 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
639 if ( !$this->isStructuredFilterUiEnabled() ) {
640 $form .= $this->makeLegend();
643 $lang = $this->getLanguage();
644 if ( $opts['days'] > 0 ) {
645 $days = $opts['days'];
647 $days = $this->maxDays
;
649 $timestamp = wfTimestampNow();
650 $wlInfo = Html
::rawElement(
652 [ 'class' => 'wlinfo' ],
653 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
654 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
658 $nondefaults = $opts->getChangedValues();
659 $cutofflinks = Html
::rawElement(
661 [ 'class' => 'cldays cloption' ],
662 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
665 # Spit out some control panel links
667 $namesOfDisplayedFilters = [];
668 foreach ( $this->getFilterGroups() as $groupName => $group ) {
669 if ( !$group->isPerGroupRequestParameter() ) {
670 foreach ( $group->getFilters() as $filterName => $filter ) {
671 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
672 $namesOfDisplayedFilters[] = $filterName;
673 $links[] = $this->showHideCheck(
675 $filter->getShowHide(),
678 $filter->isFeatureAvailableOnStructuredUi( $this )
685 $hiddenFields = $nondefaults;
686 $hiddenFields['action'] = 'submit';
687 unset( $hiddenFields['namespace'] );
688 unset( $hiddenFields['invert'] );
689 unset( $hiddenFields['associated'] );
690 unset( $hiddenFields['days'] );
691 foreach ( $namesOfDisplayedFilters as $filterName ) {
692 unset( $hiddenFields[$filterName] );
695 # Namespace filter and put the whole form together.
697 $form .= $cutofflinks;
698 $form .= Html
::rawElement(
700 [ 'class' => 'clshowhide' ],
701 $this->msg( 'watchlist-hide' ) .
702 $this->msg( 'colon-separator' )->escaped() .
703 implode( ' ', $links )
705 $form .= "\n<br />\n";
707 $namespaceForm = Html
::namespaceSelector(
709 'selected' => $opts['namespace'],
711 'label' => $this->msg( 'namespace' )->text()
713 'name' => 'namespace',
715 'class' => 'namespaceselector',
718 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
719 $this->msg( 'invert' )->text(),
723 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
725 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
726 $this->msg( 'namespace_association' )->text(),
730 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
732 $form .= Html
::rawElement(
734 [ 'class' => 'namespaceForm cloption' ],
738 $form .= Xml
::submitButton(
739 $this->msg( 'watchlist-submit' )->text(),
740 [ 'class' => 'cloption-submit' ]
742 foreach ( $hiddenFields as $key => $value ) {
743 $form .= Html
::hidden( $key, $value ) . "\n";
745 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
746 $form .= Xml
::closeElement( 'form' ) . "\n";
748 // Insert a placeholder for RCFilters
749 if ( $this->isStructuredFilterUiEnabled() ) {
750 $rcfilterContainer = Html
::element(
752 [ 'class' => 'rcfilters-container' ]
755 $loadingContainer = Html
::rawElement(
757 [ 'class' => 'rcfilters-spinner' ],
760 [ 'class' => 'rcfilters-spinner-bounce' ]
764 // Wrap both with rcfilters-head
765 $this->getOutput()->addHTML(
768 [ 'class' => 'rcfilters-head' ],
769 $rcfilterContainer . $form
774 $this->getOutput()->addHTML( $loadingContainer );
776 $this->getOutput()->addHTML( $form );
779 $this->setBottomText( $opts );
782 function cutoffselector( $options ) {
783 // Cast everything to strings immediately, so that we know all of the values have the same
784 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
785 // default string representation, for example, and would confuse comparisons.
787 // Misleadingly, the 'days' option supports hours too.
788 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
790 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
791 // add the user preference, if it isn't available already
792 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
793 $days[] = $userWatchlistOption;
796 $maxDays = (string)$this->maxDays
;
797 // add the maximum possible value, if it isn't available already
798 if ( !in_array( $maxDays, $days ) ) {
802 $selected = (string)$options['days'];
803 if ( $selected <= 0 ) {
804 $selected = $maxDays;
807 // add the currently selected value, if it isn't available already
808 if ( !in_array( $selected, $days ) ) {
812 $select = new XmlSelect( 'days', 'days', $selected );
815 foreach ( $days as $value ) {
817 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
819 $name = $this->msg( 'days' )->numParams( $value )->text();
821 $select->addOption( $name, $value );
824 return $select->getHTML() . "\n<br />\n";
827 function setTopText( FormOptions
$opts ) {
828 $nondefaults = $opts->getChangedValues();
830 $user = $this->getUser();
832 $numItems = $this->countItems();
833 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
835 // Show watchlist header
836 $watchlistHeader = '';
837 if ( $numItems == 0 ) {
838 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
840 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
841 if ( $this->getConfig()->get( 'EnotifWatchlist' )
842 && $user->getOption( 'enotifwatchlistpages' )
844 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
846 if ( $showUpdatedMarker ) {
847 $watchlistHeader .= $this->msg(
848 $this->isStructuredFilterUiEnabled() ?
849 'rcfilters-watchlist-showupdated' :
850 'wlheader-showupdated'
854 $form .= Html
::rawElement(
856 [ 'class' => 'watchlistDetails' ],
860 if ( $numItems > 0 && $showUpdatedMarker ) {
861 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
862 'action' => $this->getPageTitle()->getLocalURL(),
863 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
864 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
865 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
866 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
867 Html
::hidden( 'reset', 'all' ) . "\n";
868 foreach ( $nondefaults as $key => $value ) {
869 $form .= Html
::hidden( $key, $value ) . "\n";
871 $form .= Xml
::closeElement( 'form' ) . "\n";
874 $this->getOutput()->addHTML( $form );
877 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
878 $options[$name] = 1 - (int)$value;
880 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
881 if ( $inStructuredUi ) {
882 $attribs[ 'data-feature-in-structured-ui' ] = true;
885 return Html
::rawElement(
889 $this->msg( $message, '' )->text(),
898 * Count the number of paired items on a user's watchlist.
899 * The assumption made here is that when a subject page is watched a talk page is also watched.
900 * Hence the number of individual items is halved.
904 protected function countItems() {
905 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
906 $count = $store->countWatchedItems( $this->getUser() );
907 return floor( $count / 2 );
910 function getDefaultLimit() {
911 return $this->getUser()->getIntOption( 'wllimit' );
914 function getDefaultDays() {
915 return $this->getUser()->getIntOption( 'watchlistdays' );