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->getLegacyShowHideFilters() as $filter ) {
337 $allBooleansFalse[ $filter->getName() ] = false;
340 $params = $params +
$allBooleansFalse;
343 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
344 // methods defined on WebRequest and removing this dependency would cause some code duplication.
345 $request = new DerivativeRequest( $this->getRequest(), $params );
346 $opts->fetchValuesFromRequest( $request );
354 protected function doMainQuery( $tables, $fields, $conds, $query_options,
355 $join_conds, FormOptions
$opts
357 $dbr = $this->getDB();
358 $user = $this->getUser();
360 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
361 $fields = array_merge( RecentChange
::selectFields(), $fields );
363 $join_conds = array_merge(
368 'wl_user' => $user->getId(),
369 'wl_namespace=rc_namespace',
378 $fields[] = 'page_latest';
379 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
381 $fields[] = 'wl_notificationtimestamp';
383 // Log entries with DELETED_ACTION must not show up unless the user has
384 // the necessary rights.
385 if ( !$user->isAllowed( 'deletedhistory' ) ) {
386 $bitmask = LogPage
::DELETED_ACTION
;
387 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
388 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
393 $conds[] = $dbr->makeList( [
394 'rc_type != ' . RC_LOG
,
395 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
399 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
400 ChangeTags
::modifyDisplayQuery(
409 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
411 if ( $this->areFiltersInConflict() ) {
416 'ORDER BY' => 'rc_timestamp DESC',
417 'LIMIT' => $opts['limit']
419 if ( in_array( 'DISTINCT', $query_options ) ) {
420 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
421 // In order to prevent DISTINCT from causing query performance problems,
422 // we have to GROUP BY the primary key. This in turn requires us to add
423 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
424 // start of the GROUP BY
425 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
426 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
428 // array_merge() is used intentionally here so that hooks can, should
429 // they so desire, override the ORDER BY / LIMIT condition(s)
430 $query_options = array_merge( $orderByAndLimit, $query_options );
442 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
445 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
447 'SpecialWatchlistQuery',
448 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
454 * Return a IDatabase object for reading
458 protected function getDB() {
459 return wfGetDB( DB_REPLICA
, 'watchlist' );
465 public function outputFeedLinks() {
466 $user = $this->getUser();
467 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
469 $this->addFeedLinks( [
470 'action' => 'feedwatchlist',
472 'wlowner' => $user->getName(),
473 'wltoken' => $wlToken,
479 * Build and output the actual changes list.
481 * @param ResultWrapper $rows Database rows
482 * @param FormOptions $opts
484 public function outputChangesList( $rows, $opts ) {
485 $dbr = $this->getDB();
486 $user = $this->getUser();
487 $output = $this->getOutput();
489 # Show a message about replica DB lag, if applicable
490 $lag = wfGetLB()->safeGetLag( $dbr );
492 $output->showLagWarning( $lag );
495 # If no rows to display, show message before try to render the list
496 if ( $rows->numRows() == 0 ) {
497 $output->wrapWikiMsg(
498 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
503 $dbr->dataSeek( $rows, 0 );
505 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
506 $list->setWatchlistDivs();
507 $list->initChangesListRows( $rows );
508 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
509 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
510 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
511 // since EnhancedChangesList groups log entries by performer rather than by target article
512 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
516 return $this->getLinkRenderer()
517 ->makeKnownLink( $rc->getTitle(),
518 $this->msg( 'watchlist-unwatch' )->text(), [
519 'class' => 'mw-unwatch-link',
520 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
521 ], [ 'action' => 'unwatch' ] ) . ' ';
525 $dbr->dataSeek( $rows, 0 );
527 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
528 && $user->getOption( 'shownumberswatching' )
530 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
533 $s = $list->beginRecentChangesList();
535 if ( $this->isStructuredFilterUiEnabled() ) {
536 $s .= $this->makeLegend();
539 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
541 foreach ( $rows as $obj ) {
543 $rc = RecentChange
::newFromRow( $obj );
545 # Skip CatWatch entries for hidden cats based on user preference
547 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
548 !$userShowHiddenCats &&
549 $rc->getParam( 'hidden-cat' )
554 $rc->counter
= $counter++
;
556 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
557 $updated = $obj->wl_notificationtimestamp
;
562 if ( isset( $watchedItemStore ) ) {
563 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
564 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
566 $rc->numberofWatchingusers
= 0;
569 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
570 if ( $changeLine !== false ) {
574 $s .= $list->endRecentChangesList();
576 $output->addHTML( $s );
580 * Set the text to be displayed above the changes
582 * @param FormOptions $opts
583 * @param int $numRows Number of rows in the result to show after this header
585 public function doHeader( $opts, $numRows ) {
586 $user = $this->getUser();
587 $out = $this->getOutput();
590 $this->msg( 'watchlistfor2', $user->getName() )
591 ->rawParams( SpecialEditWatchlist
::buildTools(
592 $this->getLanguage(),
593 $this->getLinkRenderer()
597 $this->setTopText( $opts );
601 $form .= Xml
::openElement( 'form', [
603 'action' => wfScript(),
604 'id' => 'mw-watchlist-form'
606 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
607 $form .= Xml
::openElement(
609 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
611 $form .= Xml
::element(
612 'legend', null, $this->msg( 'watchlist-options' )->text()
615 if ( !$this->isStructuredFilterUiEnabled() ) {
616 $form .= $this->makeLegend();
619 $lang = $this->getLanguage();
620 $timestamp = wfTimestampNow();
621 $wlInfo = Html
::rawElement(
625 'data-params' => json_encode( [ 'from' => $timestamp ] ),
627 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
628 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
632 $nondefaults = $opts->getChangedValues();
633 $cutofflinks = Html
::rawElement(
635 [ 'class' => 'cldays cloption' ],
636 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
639 # Spit out some control panel links
641 $namesOfDisplayedFilters = [];
642 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
643 $namesOfDisplayedFilters[] = $filterName;
644 $links[] = $this->showHideCheck(
646 $filter->getShowHide(),
648 $opts[ $filterName ],
649 $filter->isFeatureAvailableOnStructuredUi( $this )
653 $hiddenFields = $nondefaults;
654 $hiddenFields['action'] = 'submit';
655 unset( $hiddenFields['namespace'] );
656 unset( $hiddenFields['invert'] );
657 unset( $hiddenFields['associated'] );
658 unset( $hiddenFields['days'] );
659 foreach ( $namesOfDisplayedFilters as $filterName ) {
660 unset( $hiddenFields[$filterName] );
663 # Namespace filter and put the whole form together.
665 $form .= $cutofflinks;
666 $form .= Html
::rawElement(
668 [ 'class' => 'clshowhide' ],
669 $this->msg( 'watchlist-hide' ) .
670 $this->msg( 'colon-separator' )->escaped() .
671 implode( ' ', $links )
673 $form .= "\n<br />\n";
675 $namespaceForm = Html
::namespaceSelector(
677 'selected' => $opts['namespace'],
679 'label' => $this->msg( 'namespace' )->text()
681 'name' => 'namespace',
683 'class' => 'namespaceselector',
686 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
687 $this->msg( 'invert' )->text(),
691 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
693 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
694 $this->msg( 'namespace_association' )->text(),
698 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
700 $form .= Html
::rawElement(
702 [ 'class' => 'namespaceForm cloption' ],
706 $form .= Xml
::submitButton(
707 $this->msg( 'watchlist-submit' )->text(),
708 [ 'class' => 'cloption-submit' ]
710 foreach ( $hiddenFields as $key => $value ) {
711 $form .= Html
::hidden( $key, $value ) . "\n";
713 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
714 $form .= Xml
::closeElement( 'form' ) . "\n";
716 // Insert a placeholder for RCFilters
717 if ( $this->isStructuredFilterUiEnabled() ) {
718 $rcfilterContainer = Html
::element(
720 [ 'class' => 'rcfilters-container' ]
723 $loadingContainer = Html
::rawElement(
725 [ 'class' => 'rcfilters-spinner' ],
728 [ 'class' => 'rcfilters-spinner-bounce' ]
732 // Wrap both with rcfilters-head
733 $this->getOutput()->addHTML(
736 [ 'class' => 'rcfilters-head' ],
737 $rcfilterContainer . $form
742 $this->getOutput()->addHTML( $loadingContainer );
744 $this->getOutput()->addHTML( $form );
747 $this->setBottomText( $opts );
750 function cutoffselector( $options ) {
751 // Cast everything to strings immediately, so that we know all of the values have the same
752 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
753 // default string representation, for example, and would confuse comparisons.
755 // Misleadingly, the 'days' option supports hours too.
756 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
758 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
759 // add the user preference, if it isn't available already
760 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
761 $days[] = $userWatchlistOption;
764 $maxDays = (string)$this->maxDays
;
765 // add the maximum possible value, if it isn't available already
766 if ( !in_array( $maxDays, $days ) ) {
770 $selected = (string)$options['days'];
771 if ( $selected <= 0 ) {
772 $selected = $maxDays;
775 // add the currently selected value, if it isn't available already
776 if ( !in_array( $selected, $days ) ) {
780 $select = new XmlSelect( 'days', 'days', $selected );
783 foreach ( $days as $value ) {
785 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
787 $name = $this->msg( 'days' )->numParams( $value )->text();
789 $select->addOption( $name, $value );
792 return $select->getHTML() . "\n<br />\n";
795 function setTopText( FormOptions
$opts ) {
796 $nondefaults = $opts->getChangedValues();
798 $user = $this->getUser();
800 $numItems = $this->countItems();
801 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
803 // Show watchlist header
804 $watchlistHeader = '';
805 if ( $numItems == 0 ) {
806 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
808 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
809 if ( $this->getConfig()->get( 'EnotifWatchlist' )
810 && $user->getOption( 'enotifwatchlistpages' )
812 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
814 if ( $showUpdatedMarker ) {
815 $watchlistHeader .= $this->msg(
816 $this->isStructuredFilterUiEnabled() ?
817 'rcfilters-watchlist-showupdated' :
818 'wlheader-showupdated'
822 $form .= Html
::rawElement(
824 [ 'class' => 'watchlistDetails' ],
828 if ( $numItems > 0 && $showUpdatedMarker ) {
829 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
830 'action' => $this->getPageTitle()->getLocalURL(),
831 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
832 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
833 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
834 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
835 Html
::hidden( 'reset', 'all' ) . "\n";
836 foreach ( $nondefaults as $key => $value ) {
837 $form .= Html
::hidden( $key, $value ) . "\n";
839 $form .= Xml
::closeElement( 'form' ) . "\n";
842 $this->getOutput()->addHTML( $form );
845 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
846 $options[$name] = 1 - (int)$value;
848 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
849 if ( $inStructuredUi ) {
850 $attribs[ 'data-feature-in-structured-ui' ] = true;
853 return Html
::rawElement(
857 $this->msg( $message, '' )->text(),
866 * Count the number of paired items on a user's watchlist.
867 * The assumption made here is that when a subject page is watched a talk page is also watched.
868 * Hence the number of individual items is halved.
872 protected function countItems() {
873 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
874 $count = $store->countWatchedItems( $this->getUser() );
875 return floor( $count / 2 );
878 function getDefaultLimit() {
879 return $this->getUser()->getIntOption( 'wllimit' );
882 function getDefaultDays() {
883 return floatval( $this->getUser()->getOption( 'watchlistdays' ) );