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 public function isStructuredFilterUiEnabled() {
115 return $this->getRequest()->getBool( 'rcfilters' ) ||
(
116 $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
117 $this->getUser()->getOption( 'rcenhancedfilters' )
121 public function isStructuredFilterUiEnabledByDefault() {
122 return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
123 $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
127 * Return an array of subpages that this special page will accept.
129 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
130 * @return string[] subpages
132 public function getSubpagesForPrefixSearch() {
143 protected function transformFilterDefinition( array $filterDefinition ) {
144 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
145 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
148 return $filterDefinition;
154 protected function registerFilters() {
155 parent
::registerFilters();
157 // legacy 'extended' filter
158 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
159 'name' => 'extended-group',
162 'name' => 'extended',
163 'isReplacedInStructuredUi' => true,
164 'activeValue' => false,
165 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
166 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
167 &$fields, &$conds, &$query_options, &$join_conds ) {
168 $nonRevisionTypes = [ RC_LOG
];
169 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
170 if ( $nonRevisionTypes ) {
171 $conds[] = $dbr->makeList(
173 'rc_this_oldid=page_latest',
174 'rc_type' => $nonRevisionTypes,
185 if ( $this->isStructuredFilterUiEnabled() ) {
186 $this->getFilterGroup( 'lastRevision' )
187 ->getFilter( 'hidepreviousrevisions' )
188 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
191 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
192 'name' => 'watchlistactivity',
193 'title' => 'rcfilters-filtergroup-watchlistactivity',
194 'class' => ChangesListStringOptionsFilterGroup
::class,
196 'isFullCoverage' => true,
200 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
201 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
202 'cssClassSuffix' => 'watchedunseen',
203 'isRowApplicableCallable' => function ( $ctx, $rc ) {
204 $changeTs = $rc->getAttribute( 'rc_timestamp' );
205 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
206 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
211 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
212 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
213 'cssClassSuffix' => 'watchedseen',
214 'isRowApplicableCallable' => function ( $ctx, $rc ) {
215 $changeTs = $rc->getAttribute( 'rc_timestamp' );
216 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
217 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
221 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
222 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
223 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
224 if ( $selectedValues === [ 'seen' ] ) {
225 $conds[] = $dbr->makeList( [
226 'wl_notificationtimestamp IS NULL',
227 'rc_timestamp < wl_notificationtimestamp'
229 } elseif ( $selectedValues === [ 'unseen' ] ) {
230 $conds[] = $dbr->makeList( [
231 'wl_notificationtimestamp IS NOT NULL',
232 'rc_timestamp >= wl_notificationtimestamp'
238 $user = $this->getUser();
240 $significance = $this->getFilterGroup( 'significance' );
241 $hideMinor = $significance->getFilter( 'hideminor' );
242 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
244 $automated = $this->getFilterGroup( 'automated' );
245 $hideBots = $automated->getFilter( 'hidebots' );
246 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
248 $registration = $this->getFilterGroup( 'registration' );
249 $hideAnons = $registration->getFilter( 'hideanons' );
250 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
251 $hideLiu = $registration->getFilter( 'hideliu' );
252 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
254 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
255 if ( $reviewStatus !== null ) {
256 // Conditional on feature being available and rights
257 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
258 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
261 $authorship = $this->getFilterGroup( 'authorship' );
262 $hideMyself = $authorship->getFilter( 'hidemyself' );
263 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
265 $changeType = $this->getFilterGroup( 'changeType' );
266 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
267 if ( $hideCategorization !== null ) {
268 // Conditional on feature being available
269 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
274 * Get a FormOptions object containing the default options
276 * @return FormOptions
278 public function getDefaultOptions() {
279 $opts = parent
::getDefaultOptions();
281 $opts->add( 'days', $this->getDefaultDays(), FormOptions
::FLOAT );
282 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions
::INT );
287 public function validateOptions( FormOptions
$opts ) {
288 $opts->validateBounds( 'days', 0, $this->maxDays
);
289 $opts->validateIntBounds( 'limit', 0, 5000 );
290 parent
::validateOptions( $opts );
294 * Get all custom filters
296 * @return array Map of filter URL param names to properties (msg/default)
298 protected function getCustomFilters() {
299 if ( $this->customFilters
=== null ) {
300 $this->customFilters
= parent
::getCustomFilters();
301 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
304 return $this->customFilters
;
308 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
310 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
311 * to the current ones.
313 * @param FormOptions $opts
314 * @return FormOptions
316 protected function fetchOptionsFromRequest( $opts ) {
317 static $compatibilityMap = [
318 'hideMinor' => 'hideminor',
319 'hideBots' => 'hidebots',
320 'hideAnons' => 'hideanons',
321 'hideLiu' => 'hideliu',
322 'hidePatrolled' => 'hidepatrolled',
323 'hideOwn' => 'hidemyself',
326 $params = $this->getRequest()->getValues();
327 foreach ( $compatibilityMap as $from => $to ) {
328 if ( isset( $params[$from] ) ) {
329 $params[$to] = $params[$from];
330 unset( $params[$from] );
334 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
335 $allBooleansFalse = [];
337 // If the user submitted the form, start with a baseline of "all
338 // booleans are false", then change the ones they checked. This
339 // means we ignore the defaults.
341 // This is how we handle the fact that HTML forms don't submit
343 foreach ( $this->filterGroups
as $filterGroup ) {
344 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
345 /** @var ChangesListBooleanFilter $filter */
346 foreach ( $filterGroup->getFilters() as $filter ) {
347 if ( $filter->displaysOnUnstructuredUi() ) {
348 $allBooleansFalse[$filter->getName()] = false;
354 $params = $params +
$allBooleansFalse;
357 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
358 // methods defined on WebRequest and removing this dependency would cause some code duplication.
359 $request = new DerivativeRequest( $this->getRequest(), $params );
360 $opts->fetchValuesFromRequest( $request );
368 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
369 &$join_conds, FormOptions
$opts
371 $dbr = $this->getDB();
372 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
376 if ( $opts['days'] > 0 ) {
377 $conds[] = 'rc_timestamp > ' .
378 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
385 protected function doMainQuery( $tables, $fields, $conds, $query_options,
386 $join_conds, FormOptions
$opts
388 $dbr = $this->getDB();
389 $user = $this->getUser();
391 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
392 $fields = array_merge( RecentChange
::selectFields(), $fields );
394 $join_conds = array_merge(
399 'wl_user' => $user->getId(),
400 'wl_namespace=rc_namespace',
409 $fields[] = 'page_latest';
410 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
412 $fields[] = 'wl_notificationtimestamp';
414 // Log entries with DELETED_ACTION must not show up unless the user has
415 // the necessary rights.
416 if ( !$user->isAllowed( 'deletedhistory' ) ) {
417 $bitmask = LogPage
::DELETED_ACTION
;
418 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
419 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
424 $conds[] = $dbr->makeList( [
425 'rc_type != ' . RC_LOG
,
426 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
430 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
431 ChangeTags
::modifyDisplayQuery(
440 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
442 if ( $this->areFiltersInConflict() ) {
447 'ORDER BY' => 'rc_timestamp DESC',
448 'LIMIT' => $opts['limit']
450 if ( in_array( 'DISTINCT', $query_options ) ) {
451 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
452 // In order to prevent DISTINCT from causing query performance problems,
453 // we have to GROUP BY the primary key. This in turn requires us to add
454 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
455 // start of the GROUP BY
456 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
457 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
459 // array_merge() is used intentionally here so that hooks can, should
460 // they so desire, override the ORDER BY / LIMIT condition(s)
461 $query_options = array_merge( $orderByAndLimit, $query_options );
473 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
476 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
478 'SpecialWatchlistQuery',
479 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
485 * Return a IDatabase object for reading
489 protected function getDB() {
490 return wfGetDB( DB_REPLICA
, 'watchlist' );
496 public function outputFeedLinks() {
497 $user = $this->getUser();
498 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
500 $this->addFeedLinks( [
501 'action' => 'feedwatchlist',
503 'wlowner' => $user->getName(),
504 'wltoken' => $wlToken,
510 * Build and output the actual changes list.
512 * @param ResultWrapper $rows Database rows
513 * @param FormOptions $opts
515 public function outputChangesList( $rows, $opts ) {
516 $dbr = $this->getDB();
517 $user = $this->getUser();
518 $output = $this->getOutput();
520 # Show a message about replica DB lag, if applicable
521 $lag = wfGetLB()->safeGetLag( $dbr );
523 $output->showLagWarning( $lag );
526 # If no rows to display, show message before try to render the list
527 if ( $rows->numRows() == 0 ) {
528 $output->wrapWikiMsg(
529 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
534 $dbr->dataSeek( $rows, 0 );
536 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
537 $list->setWatchlistDivs();
538 $list->initChangesListRows( $rows );
539 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
540 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
541 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
542 // since EnhancedChangesList groups log entries by performer rather than by target article
543 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
547 return $this->getLinkRenderer()
548 ->makeKnownLink( $rc->getTitle(),
549 $this->msg( 'watchlist-unwatch' )->text(), [
550 'class' => 'mw-unwatch-link',
551 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
552 ], [ 'action' => 'unwatch' ] ) . ' ';
556 $dbr->dataSeek( $rows, 0 );
558 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
559 && $user->getOption( 'shownumberswatching' )
561 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
564 $s = $list->beginRecentChangesList();
566 if ( $this->isStructuredFilterUiEnabled() ) {
567 $s .= $this->makeLegend();
570 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
572 foreach ( $rows as $obj ) {
574 $rc = RecentChange
::newFromRow( $obj );
576 # Skip CatWatch entries for hidden cats based on user preference
578 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
579 !$userShowHiddenCats &&
580 $rc->getParam( 'hidden-cat' )
585 $rc->counter
= $counter++
;
587 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
588 $updated = $obj->wl_notificationtimestamp
;
593 if ( isset( $watchedItemStore ) ) {
594 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
595 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
597 $rc->numberofWatchingusers
= 0;
600 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
601 if ( $changeLine !== false ) {
605 $s .= $list->endRecentChangesList();
607 $output->addHTML( $s );
611 * Set the text to be displayed above the changes
613 * @param FormOptions $opts
614 * @param int $numRows Number of rows in the result to show after this header
616 public function doHeader( $opts, $numRows ) {
617 $user = $this->getUser();
618 $out = $this->getOutput();
621 $this->msg( 'watchlistfor2', $user->getName() )
622 ->rawParams( SpecialEditWatchlist
::buildTools(
623 $this->getLanguage(),
624 $this->getLinkRenderer()
628 $this->setTopText( $opts );
632 $form .= Xml
::openElement( 'form', [
634 'action' => wfScript(),
635 'id' => 'mw-watchlist-form'
637 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
638 $form .= Xml
::openElement(
640 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
642 $form .= Xml
::element(
643 'legend', null, $this->msg( 'watchlist-options' )->text()
646 if ( !$this->isStructuredFilterUiEnabled() ) {
647 $form .= $this->makeLegend();
650 $lang = $this->getLanguage();
651 if ( $opts['days'] > 0 ) {
652 $days = $opts['days'];
654 $days = $this->maxDays
;
656 $timestamp = wfTimestampNow();
657 $wlInfo = Html
::rawElement(
659 [ 'class' => 'wlinfo' ],
660 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
661 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
665 $nondefaults = $opts->getChangedValues();
666 $cutofflinks = Html
::rawElement(
668 [ 'class' => 'cldays cloption' ],
669 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
672 # Spit out some control panel links
674 $namesOfDisplayedFilters = [];
675 foreach ( $this->getFilterGroups() as $groupName => $group ) {
676 if ( !$group->isPerGroupRequestParameter() ) {
677 foreach ( $group->getFilters() as $filterName => $filter ) {
678 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
679 $namesOfDisplayedFilters[] = $filterName;
680 $links[] = $this->showHideCheck(
682 $filter->getShowHide(),
685 $filter->isFeatureAvailableOnStructuredUi( $this )
692 $hiddenFields = $nondefaults;
693 $hiddenFields['action'] = 'submit';
694 unset( $hiddenFields['namespace'] );
695 unset( $hiddenFields['invert'] );
696 unset( $hiddenFields['associated'] );
697 unset( $hiddenFields['days'] );
698 foreach ( $namesOfDisplayedFilters as $filterName ) {
699 unset( $hiddenFields[$filterName] );
702 # Namespace filter and put the whole form together.
704 $form .= $cutofflinks;
705 $form .= Html
::rawElement(
707 [ 'class' => 'clshowhide' ],
708 $this->msg( 'watchlist-hide' ) .
709 $this->msg( 'colon-separator' )->escaped() .
710 implode( ' ', $links )
712 $form .= "\n<br />\n";
714 $namespaceForm = Html
::namespaceSelector(
716 'selected' => $opts['namespace'],
718 'label' => $this->msg( 'namespace' )->text()
720 'name' => 'namespace',
722 'class' => 'namespaceselector',
725 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
726 $this->msg( 'invert' )->text(),
730 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
732 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
733 $this->msg( 'namespace_association' )->text(),
737 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
739 $form .= Html
::rawElement(
741 [ 'class' => 'namespaceForm cloption' ],
745 $form .= Xml
::submitButton(
746 $this->msg( 'watchlist-submit' )->text(),
747 [ 'class' => 'cloption-submit' ]
749 foreach ( $hiddenFields as $key => $value ) {
750 $form .= Html
::hidden( $key, $value ) . "\n";
752 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
753 $form .= Xml
::closeElement( 'form' ) . "\n";
755 // Insert a placeholder for RCFilters
756 if ( $this->isStructuredFilterUiEnabled() ) {
757 $rcfilterContainer = Html
::element(
759 [ 'class' => 'rcfilters-container' ]
762 $loadingContainer = Html
::rawElement(
764 [ 'class' => 'rcfilters-spinner' ],
767 [ 'class' => 'rcfilters-spinner-bounce' ]
771 // Wrap both with rcfilters-head
772 $this->getOutput()->addHTML(
775 [ 'class' => 'rcfilters-head' ],
776 $rcfilterContainer . $form
781 $this->getOutput()->addHTML( $loadingContainer );
783 $this->getOutput()->addHTML( $form );
786 $this->setBottomText( $opts );
789 function cutoffselector( $options ) {
790 // Cast everything to strings immediately, so that we know all of the values have the same
791 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
792 // default string representation, for example, and would confuse comparisons.
794 // Misleadingly, the 'days' option supports hours too.
795 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
797 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
798 // add the user preference, if it isn't available already
799 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
800 $days[] = $userWatchlistOption;
803 $maxDays = (string)$this->maxDays
;
804 // add the maximum possible value, if it isn't available already
805 if ( !in_array( $maxDays, $days ) ) {
809 $selected = (string)$options['days'];
810 if ( $selected <= 0 ) {
811 $selected = $maxDays;
814 // add the currently selected value, if it isn't available already
815 if ( !in_array( $selected, $days ) ) {
819 $select = new XmlSelect( 'days', 'days', $selected );
822 foreach ( $days as $value ) {
824 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
826 $name = $this->msg( 'days' )->numParams( $value )->text();
828 $select->addOption( $name, $value );
831 return $select->getHTML() . "\n<br />\n";
834 function setTopText( FormOptions
$opts ) {
835 $nondefaults = $opts->getChangedValues();
837 $user = $this->getUser();
839 $numItems = $this->countItems();
840 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
842 // Show watchlist header
843 $watchlistHeader = '';
844 if ( $numItems == 0 ) {
845 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
847 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
848 if ( $this->getConfig()->get( 'EnotifWatchlist' )
849 && $user->getOption( 'enotifwatchlistpages' )
851 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
853 if ( $showUpdatedMarker ) {
854 $watchlistHeader .= $this->msg(
855 $this->isStructuredFilterUiEnabled() ?
856 'rcfilters-watchlist-showupdated' :
857 'wlheader-showupdated'
861 $form .= Html
::rawElement(
863 [ 'class' => 'watchlistDetails' ],
867 if ( $numItems > 0 && $showUpdatedMarker ) {
868 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
869 'action' => $this->getPageTitle()->getLocalURL(),
870 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
871 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
872 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
873 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
874 Html
::hidden( 'reset', 'all' ) . "\n";
875 foreach ( $nondefaults as $key => $value ) {
876 $form .= Html
::hidden( $key, $value ) . "\n";
878 $form .= Xml
::closeElement( 'form' ) . "\n";
881 $this->getOutput()->addHTML( $form );
884 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
885 $options[$name] = 1 - (int)$value;
887 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
888 if ( $inStructuredUi ) {
889 $attribs[ 'data-feature-in-structured-ui' ] = true;
892 return Html
::rawElement(
896 $this->msg( $message, '' )->text(),
905 * Count the number of paired items on a user's watchlist.
906 * The assumption made here is that when a subject page is watched a talk page is also watched.
907 * Hence the number of individual items is halved.
911 protected function countItems() {
912 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
913 $count = $store->countWatchedItems( $this->getUser() );
914 return floor( $count / 2 );
917 function getDefaultLimit() {
918 return $this->getUser()->getIntOption( 'wllimit' );
921 function getDefaultDays() {
922 return floatval( $this->getUser()->getOption( 'watchlistdays' ) );