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( 'wgStructuredChangeFiltersLiveUpdateSupported', false );
105 $output->addJsConfigVars(
106 'wgStructuredChangeFiltersEditWatchlistUrl',
107 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
112 public function isStructuredFilterUiEnabled() {
113 return $this->getRequest()->getBool( 'rcfilters' ) ||
(
114 $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
115 $this->getUser()->getOption( 'rcenhancedfilters' )
119 public function isStructuredFilterUiEnabledByDefault() {
120 return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
121 $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
125 * Return an array of subpages that this special page will accept.
127 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
128 * @return string[] subpages
130 public function getSubpagesForPrefixSearch() {
141 protected function transformFilterDefinition( array $filterDefinition ) {
142 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
143 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
146 return $filterDefinition;
152 protected function registerFilters() {
153 parent
::registerFilters();
155 // legacy 'extended' filter
156 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
157 'name' => 'extended-group',
160 'name' => 'extended',
161 'isReplacedInStructuredUi' => true,
162 'activeValue' => false,
163 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
164 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
165 &$fields, &$conds, &$query_options, &$join_conds ) {
166 $nonRevisionTypes = [ RC_LOG
];
167 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
168 if ( $nonRevisionTypes ) {
169 $conds[] = $dbr->makeList(
171 'rc_this_oldid=page_latest',
172 'rc_type' => $nonRevisionTypes,
183 if ( $this->isStructuredFilterUiEnabled() ) {
184 $this->getFilterGroup( 'lastRevision' )
185 ->getFilter( 'hidepreviousrevisions' )
186 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
189 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
190 'name' => 'watchlistactivity',
191 'title' => 'rcfilters-filtergroup-watchlistactivity',
192 'class' => ChangesListStringOptionsFilterGroup
::class,
194 'isFullCoverage' => true,
198 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
199 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
200 'cssClassSuffix' => 'watchedunseen',
201 'isRowApplicableCallable' => function ( $ctx, $rc ) {
202 $changeTs = $rc->getAttribute( 'rc_timestamp' );
203 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
204 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
209 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
210 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
211 'cssClassSuffix' => 'watchedseen',
212 'isRowApplicableCallable' => function ( $ctx, $rc ) {
213 $changeTs = $rc->getAttribute( 'rc_timestamp' );
214 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
215 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
219 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
220 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
221 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
222 if ( $selectedValues === [ 'seen' ] ) {
223 $conds[] = $dbr->makeList( [
224 'wl_notificationtimestamp IS NULL',
225 'rc_timestamp < wl_notificationtimestamp'
227 } elseif ( $selectedValues === [ 'unseen' ] ) {
228 $conds[] = $dbr->makeList( [
229 'wl_notificationtimestamp IS NOT NULL',
230 'rc_timestamp >= wl_notificationtimestamp'
236 $user = $this->getUser();
238 $significance = $this->getFilterGroup( 'significance' );
239 $hideMinor = $significance->getFilter( 'hideminor' );
240 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
242 $automated = $this->getFilterGroup( 'automated' );
243 $hideBots = $automated->getFilter( 'hidebots' );
244 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
246 $registration = $this->getFilterGroup( 'registration' );
247 $hideAnons = $registration->getFilter( 'hideanons' );
248 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
249 $hideLiu = $registration->getFilter( 'hideliu' );
250 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
252 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
253 if ( $reviewStatus !== null ) {
254 // Conditional on feature being available and rights
255 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
256 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
259 $authorship = $this->getFilterGroup( 'authorship' );
260 $hideMyself = $authorship->getFilter( 'hidemyself' );
261 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
263 $changeType = $this->getFilterGroup( 'changeType' );
264 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
265 if ( $hideCategorization !== null ) {
266 // Conditional on feature being available
267 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
272 * Get a FormOptions object containing the default options
274 * @return FormOptions
276 public function getDefaultOptions() {
277 $opts = parent
::getDefaultOptions();
279 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
280 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
285 public function validateOptions( FormOptions
$opts ) {
286 $opts->validateBounds( 'days', 0, $this->maxDays
);
287 $opts->validateIntBounds( 'limit', 0, 5000 );
288 parent
::validateOptions( $opts );
292 * Get all custom filters
294 * @return array Map of filter URL param names to properties (msg/default)
296 protected function getCustomFilters() {
297 if ( $this->customFilters
=== null ) {
298 $this->customFilters
= parent
::getCustomFilters();
299 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
302 return $this->customFilters
;
306 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
308 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
309 * to the current ones.
311 * @param FormOptions $opts
312 * @return FormOptions
314 protected function fetchOptionsFromRequest( $opts ) {
315 static $compatibilityMap = [
316 'hideMinor' => 'hideminor',
317 'hideBots' => 'hidebots',
318 'hideAnons' => 'hideanons',
319 'hideLiu' => 'hideliu',
320 'hidePatrolled' => 'hidepatrolled',
321 'hideOwn' => 'hidemyself',
324 $params = $this->getRequest()->getValues();
325 foreach ( $compatibilityMap as $from => $to ) {
326 if ( isset( $params[$from] ) ) {
327 $params[$to] = $params[$from];
328 unset( $params[$from] );
332 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
333 $allBooleansFalse = [];
335 // If the user submitted the form, start with a baseline of "all
336 // booleans are false", then change the ones they checked. This
337 // means we ignore the defaults.
339 // This is how we handle the fact that HTML forms don't submit
341 foreach ( $this->filterGroups
as $filterGroup ) {
342 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
343 /** @var ChangesListBooleanFilter $filter */
344 foreach ( $filterGroup->getFilters() as $filter ) {
345 if ( $filter->displaysOnUnstructuredUi() ) {
346 $allBooleansFalse[$filter->getName()] = false;
352 $params = $params +
$allBooleansFalse;
355 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
356 // methods defined on WebRequest and removing this dependency would cause some code duplication.
357 $request = new DerivativeRequest( $this->getRequest(), $params );
358 $opts->fetchValuesFromRequest( $request );
366 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
367 &$join_conds, FormOptions
$opts
369 $dbr = $this->getDB();
370 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
374 if ( $opts['days'] > 0 ) {
375 $conds[] = 'rc_timestamp > ' .
376 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
383 protected function doMainQuery( $tables, $fields, $conds, $query_options,
384 $join_conds, FormOptions
$opts
386 $dbr = $this->getDB();
387 $user = $this->getUser();
389 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
390 $fields = array_merge( RecentChange
::selectFields(), $fields );
392 $join_conds = array_merge(
397 'wl_user' => $user->getId(),
398 'wl_namespace=rc_namespace',
407 $fields[] = 'page_latest';
408 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
410 $fields[] = 'wl_notificationtimestamp';
412 // Log entries with DELETED_ACTION must not show up unless the user has
413 // the necessary rights.
414 if ( !$user->isAllowed( 'deletedhistory' ) ) {
415 $bitmask = LogPage
::DELETED_ACTION
;
416 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
417 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
422 $conds[] = $dbr->makeList( [
423 'rc_type != ' . RC_LOG
,
424 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
428 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
429 ChangeTags
::modifyDisplayQuery(
438 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
440 if ( $this->areFiltersInConflict() ) {
445 'ORDER BY' => 'rc_timestamp DESC',
446 'LIMIT' => $opts['limit']
448 if ( in_array( 'DISTINCT', $query_options ) ) {
449 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
450 // In order to prevent DISTINCT from causing query performance problems,
451 // we have to GROUP BY the primary key. This in turn requires us to add
452 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
453 // start of the GROUP BY
454 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
455 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
457 // array_merge() is used intentionally here so that hooks can, should
458 // they so desire, override the ORDER BY / LIMIT condition(s)
459 $query_options = array_merge( $orderByAndLimit, $query_options );
471 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
474 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
476 'SpecialWatchlistQuery',
477 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
483 * Return a IDatabase object for reading
487 protected function getDB() {
488 return wfGetDB( DB_REPLICA
, 'watchlist' );
494 public function outputFeedLinks() {
495 $user = $this->getUser();
496 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
498 $this->addFeedLinks( [
499 'action' => 'feedwatchlist',
501 'wlowner' => $user->getName(),
502 'wltoken' => $wlToken,
508 * Build and output the actual changes list.
510 * @param ResultWrapper $rows Database rows
511 * @param FormOptions $opts
513 public function outputChangesList( $rows, $opts ) {
514 $dbr = $this->getDB();
515 $user = $this->getUser();
516 $output = $this->getOutput();
518 # Show a message about replica DB lag, if applicable
519 $lag = wfGetLB()->safeGetLag( $dbr );
521 $output->showLagWarning( $lag );
524 # If no rows to display, show message before try to render the list
525 if ( $rows->numRows() == 0 ) {
526 $output->wrapWikiMsg(
527 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
532 $dbr->dataSeek( $rows, 0 );
534 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
535 $list->setWatchlistDivs();
536 $list->initChangesListRows( $rows );
537 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
538 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
539 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
540 // since EnhancedChangesList groups log entries by performer rather than by target article
541 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
545 return $this->getLinkRenderer()
546 ->makeKnownLink( $rc->getTitle(),
547 $this->msg( 'watchlist-unwatch' )->text(), [
548 'class' => 'mw-unwatch-link',
549 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
550 ], [ 'action' => 'unwatch' ] ) . ' ';
554 $dbr->dataSeek( $rows, 0 );
556 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
557 && $user->getOption( 'shownumberswatching' )
559 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
562 $s = $list->beginRecentChangesList();
564 if ( $this->isStructuredFilterUiEnabled() ) {
565 $s .= $this->makeLegend();
568 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
570 foreach ( $rows as $obj ) {
572 $rc = RecentChange
::newFromRow( $obj );
574 # Skip CatWatch entries for hidden cats based on user preference
576 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
577 !$userShowHiddenCats &&
578 $rc->getParam( 'hidden-cat' )
583 $rc->counter
= $counter++
;
585 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
586 $updated = $obj->wl_notificationtimestamp
;
591 if ( isset( $watchedItemStore ) ) {
592 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
593 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
595 $rc->numberofWatchingusers
= 0;
598 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
599 if ( $changeLine !== false ) {
603 $s .= $list->endRecentChangesList();
605 $output->addHTML( $s );
609 * Set the text to be displayed above the changes
611 * @param FormOptions $opts
612 * @param int $numRows Number of rows in the result to show after this header
614 public function doHeader( $opts, $numRows ) {
615 $user = $this->getUser();
616 $out = $this->getOutput();
619 $this->msg( 'watchlistfor2', $user->getName() )
620 ->rawParams( SpecialEditWatchlist
::buildTools(
621 $this->getLanguage(),
622 $this->getLinkRenderer()
626 $this->setTopText( $opts );
630 $form .= Xml
::openElement( 'form', [
632 'action' => wfScript(),
633 'id' => 'mw-watchlist-form'
635 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
636 $form .= Xml
::openElement(
638 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
640 $form .= Xml
::element(
641 'legend', null, $this->msg( 'watchlist-options' )->text()
644 if ( !$this->isStructuredFilterUiEnabled() ) {
645 $form .= $this->makeLegend();
648 $lang = $this->getLanguage();
649 if ( $opts['days'] > 0 ) {
650 $days = $opts['days'];
652 $days = $this->maxDays
;
654 $timestamp = wfTimestampNow();
655 $wlInfo = Html
::rawElement(
657 [ 'class' => 'wlinfo' ],
658 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
659 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
663 $nondefaults = $opts->getChangedValues();
664 $cutofflinks = Html
::rawElement(
666 [ 'class' => 'cldays cloption' ],
667 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
670 # Spit out some control panel links
672 $namesOfDisplayedFilters = [];
673 foreach ( $this->getFilterGroups() as $groupName => $group ) {
674 if ( !$group->isPerGroupRequestParameter() ) {
675 foreach ( $group->getFilters() as $filterName => $filter ) {
676 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
677 $namesOfDisplayedFilters[] = $filterName;
678 $links[] = $this->showHideCheck(
680 $filter->getShowHide(),
683 $filter->isFeatureAvailableOnStructuredUi( $this )
690 $hiddenFields = $nondefaults;
691 $hiddenFields['action'] = 'submit';
692 unset( $hiddenFields['namespace'] );
693 unset( $hiddenFields['invert'] );
694 unset( $hiddenFields['associated'] );
695 unset( $hiddenFields['days'] );
696 foreach ( $namesOfDisplayedFilters as $filterName ) {
697 unset( $hiddenFields[$filterName] );
700 # Namespace filter and put the whole form together.
702 $form .= $cutofflinks;
703 $form .= Html
::rawElement(
705 [ 'class' => 'clshowhide' ],
706 $this->msg( 'watchlist-hide' ) .
707 $this->msg( 'colon-separator' )->escaped() .
708 implode( ' ', $links )
710 $form .= "\n<br />\n";
712 $namespaceForm = Html
::namespaceSelector(
714 'selected' => $opts['namespace'],
716 'label' => $this->msg( 'namespace' )->text()
718 'name' => 'namespace',
720 'class' => 'namespaceselector',
723 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
724 $this->msg( 'invert' )->text(),
728 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
730 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
731 $this->msg( 'namespace_association' )->text(),
735 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
737 $form .= Html
::rawElement(
739 [ 'class' => 'namespaceForm cloption' ],
743 $form .= Xml
::submitButton(
744 $this->msg( 'watchlist-submit' )->text(),
745 [ 'class' => 'cloption-submit' ]
747 foreach ( $hiddenFields as $key => $value ) {
748 $form .= Html
::hidden( $key, $value ) . "\n";
750 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
751 $form .= Xml
::closeElement( 'form' ) . "\n";
753 // Insert a placeholder for RCFilters
754 if ( $this->isStructuredFilterUiEnabled() ) {
755 $rcfilterContainer = Html
::element(
757 [ 'class' => 'rcfilters-container' ]
760 $loadingContainer = Html
::rawElement(
762 [ 'class' => 'rcfilters-spinner' ],
765 [ 'class' => 'rcfilters-spinner-bounce' ]
769 // Wrap both with rcfilters-head
770 $this->getOutput()->addHTML(
773 [ 'class' => 'rcfilters-head' ],
774 $rcfilterContainer . $form
779 $this->getOutput()->addHTML( $loadingContainer );
781 $this->getOutput()->addHTML( $form );
784 $this->setBottomText( $opts );
787 function cutoffselector( $options ) {
788 // Cast everything to strings immediately, so that we know all of the values have the same
789 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
790 // default string representation, for example, and would confuse comparisons.
792 // Misleadingly, the 'days' option supports hours too.
793 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
795 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
796 // add the user preference, if it isn't available already
797 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
798 $days[] = $userWatchlistOption;
801 $maxDays = (string)$this->maxDays
;
802 // add the maximum possible value, if it isn't available already
803 if ( !in_array( $maxDays, $days ) ) {
807 $selected = (string)$options['days'];
808 if ( $selected <= 0 ) {
809 $selected = $maxDays;
812 // add the currently selected value, if it isn't available already
813 if ( !in_array( $selected, $days ) ) {
817 $select = new XmlSelect( 'days', 'days', $selected );
820 foreach ( $days as $value ) {
822 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
824 $name = $this->msg( 'days' )->numParams( $value )->text();
826 $select->addOption( $name, $value );
829 return $select->getHTML() . "\n<br />\n";
832 function setTopText( FormOptions
$opts ) {
833 $nondefaults = $opts->getChangedValues();
835 $user = $this->getUser();
837 $numItems = $this->countItems();
838 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
840 // Show watchlist header
841 $watchlistHeader = '';
842 if ( $numItems == 0 ) {
843 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
845 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
846 if ( $this->getConfig()->get( 'EnotifWatchlist' )
847 && $user->getOption( 'enotifwatchlistpages' )
849 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
851 if ( $showUpdatedMarker ) {
852 $watchlistHeader .= $this->msg(
853 $this->isStructuredFilterUiEnabled() ?
854 'rcfilters-watchlist-showupdated' :
855 'wlheader-showupdated'
859 $form .= Html
::rawElement(
861 [ 'class' => 'watchlistDetails' ],
865 if ( $numItems > 0 && $showUpdatedMarker ) {
866 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
867 'action' => $this->getPageTitle()->getLocalURL(),
868 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
869 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
870 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
871 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
872 Html
::hidden( 'reset', 'all' ) . "\n";
873 foreach ( $nondefaults as $key => $value ) {
874 $form .= Html
::hidden( $key, $value ) . "\n";
876 $form .= Xml
::closeElement( 'form' ) . "\n";
879 $this->getOutput()->addHTML( $form );
882 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
883 $options[$name] = 1 - (int)$value;
885 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
886 if ( $inStructuredUi ) {
887 $attribs[ 'data-feature-in-structured-ui' ] = true;
890 return Html
::rawElement(
894 $this->msg( $message, '' )->text(),
903 * Count the number of paired items on a user's watchlist.
904 * The assumption made here is that when a subject page is watched a talk page is also watched.
905 * Hence the number of individual items is halved.
909 protected function countItems() {
910 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
911 $count = $store->countWatchedItems( $this->getUser() );
912 return floor( $count / 2 );
915 function getDefaultLimit() {
916 return $this->getUser()->getIntOption( 'wllimit' );
919 function getDefaultDays() {
920 return floatval( $this->getUser()->getOption( 'watchlistdays' ) );