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';
36 protected static $daysPreferenceName = 'watchlistdays';
37 protected static $limitPreferenceName = 'wllimit';
41 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
42 parent
::__construct( $page, $restriction );
44 $this->maxDays
= $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
47 public function doesWrites() {
52 * Main execution point
54 * @param string $subpage
56 function execute( $subpage ) {
57 // Anons don't get a watchlist
58 $this->requireLogin( 'watchlistanontext' );
60 $output = $this->getOutput();
61 $request = $this->getRequest();
62 $this->addHelpLink( 'Help:Watching pages' );
63 $output->addModules( [
64 'mediawiki.special.changeslist.visitedstatus',
65 'mediawiki.special.watchlist',
67 $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] );
69 $mode = SpecialEditWatchlist
::getMode( $request, $subpage );
70 if ( $mode !== false ) {
71 if ( $mode === SpecialEditWatchlist
::EDIT_RAW
) {
72 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'raw' );
73 } elseif ( $mode === SpecialEditWatchlist
::EDIT_CLEAR
) {
74 $title = SpecialPage
::getTitleFor( 'EditWatchlist', 'clear' );
76 $title = SpecialPage
::getTitleFor( 'EditWatchlist' );
79 $output->redirect( $title->getLocalURL() );
84 $this->checkPermissions();
86 $user = $this->getUser();
87 $opts = $this->getOptions();
89 $config = $this->getConfig();
90 if ( ( $config->get( 'EnotifWatchlist' ) ||
$config->get( 'ShowUpdatedMarker' ) )
91 && $request->getVal( 'reset' )
92 && $request->wasPosted()
93 && $user->matchEditToken( $request->getVal( 'token' ) )
95 $user->clearAllNotifications();
96 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
101 parent
::execute( $subpage );
103 if ( $this->isStructuredFilterUiEnabled() ) {
104 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
106 $output->addJsConfigVars(
107 'wgStructuredChangeFiltersEditWatchlistUrl',
108 SpecialPage
::getTitleFor( 'EditWatchlist' )->getLocalURL()
113 public static function checkStructuredFilterUiEnabled( Config
$config, User
$user ) {
115 $config->get( 'StructuredChangeFiltersOnWatchlist' ) &&
116 $user->getOption( 'rcenhancedfilters' )
120 public function isStructuredFilterUiEnabledByDefault() {
121 return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
122 $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
126 * Return an array of subpages that this special page will accept.
128 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
129 * @return string[] subpages
131 public function getSubpagesForPrefixSearch() {
142 protected function transformFilterDefinition( array $filterDefinition ) {
143 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
144 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
147 return $filterDefinition;
153 protected function registerFilters() {
154 parent
::registerFilters();
156 // legacy 'extended' filter
157 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
158 'name' => 'extended-group',
161 'name' => 'extended',
162 'isReplacedInStructuredUi' => true,
163 'activeValue' => false,
164 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
165 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
166 &$fields, &$conds, &$query_options, &$join_conds ) {
167 $nonRevisionTypes = [ RC_LOG
];
168 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
169 if ( $nonRevisionTypes ) {
170 $conds[] = $dbr->makeList(
172 'rc_this_oldid=page_latest',
173 'rc_type' => $nonRevisionTypes,
184 if ( $this->isStructuredFilterUiEnabled() ) {
185 $this->getFilterGroup( 'lastRevision' )
186 ->getFilter( 'hidepreviousrevisions' )
187 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
190 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
191 'name' => 'watchlistactivity',
192 'title' => 'rcfilters-filtergroup-watchlistactivity',
193 'class' => ChangesListStringOptionsFilterGroup
::class,
195 'isFullCoverage' => true,
199 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
200 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
201 'cssClassSuffix' => 'watchedunseen',
202 'isRowApplicableCallable' => function ( $ctx, $rc ) {
203 $changeTs = $rc->getAttribute( 'rc_timestamp' );
204 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
205 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
210 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
211 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
212 'cssClassSuffix' => 'watchedseen',
213 'isRowApplicableCallable' => function ( $ctx, $rc ) {
214 $changeTs = $rc->getAttribute( 'rc_timestamp' );
215 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
216 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
220 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
221 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
222 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
223 if ( $selectedValues === [ 'seen' ] ) {
224 $conds[] = $dbr->makeList( [
225 'wl_notificationtimestamp IS NULL',
226 'rc_timestamp < wl_notificationtimestamp'
228 } elseif ( $selectedValues === [ 'unseen' ] ) {
229 $conds[] = $dbr->makeList( [
230 'wl_notificationtimestamp IS NOT NULL',
231 'rc_timestamp >= wl_notificationtimestamp'
237 $user = $this->getUser();
239 $significance = $this->getFilterGroup( 'significance' );
240 $hideMinor = $significance->getFilter( 'hideminor' );
241 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
243 $automated = $this->getFilterGroup( 'automated' );
244 $hideBots = $automated->getFilter( 'hidebots' );
245 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
247 $registration = $this->getFilterGroup( 'registration' );
248 $hideAnons = $registration->getFilter( 'hideanons' );
249 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
250 $hideLiu = $registration->getFilter( 'hideliu' );
251 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
253 // Selecting both hideanons and hideliu on watchlist preferances
254 // gives mutually exclusive filters, so those are ignored
255 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
256 !$user->getBoolOption( 'watchlisthideliu' )
258 $this->getFilterGroup( 'userExpLevel' )
259 ->setDefault( 'registered' );
262 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
263 !$user->getBoolOption( 'watchlisthideanons' )
265 $this->getFilterGroup( 'userExpLevel' )
266 ->setDefault( 'unregistered' );
269 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
270 if ( $reviewStatus !== null ) {
271 // Conditional on feature being available and rights
272 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
273 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
276 $authorship = $this->getFilterGroup( 'authorship' );
277 $hideMyself = $authorship->getFilter( 'hidemyself' );
278 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
280 $changeType = $this->getFilterGroup( 'changeType' );
281 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
282 if ( $hideCategorization !== null ) {
283 // Conditional on feature being available
284 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
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->getLegacyShowHideFilters() as $filter ) {
339 $allBooleansFalse[ $filter->getName() ] = false;
342 $params = $params +
$allBooleansFalse;
345 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
346 // methods defined on WebRequest and removing this dependency would cause some code duplication.
347 $request = new DerivativeRequest( $this->getRequest(), $params );
348 $opts->fetchValuesFromRequest( $request );
356 protected function doMainQuery( $tables, $fields, $conds, $query_options,
357 $join_conds, FormOptions
$opts
359 $dbr = $this->getDB();
360 $user = $this->getUser();
362 $rcQuery = RecentChange
::getQueryInfo();
363 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
364 $fields = array_merge( $rcQuery['fields'], $fields );
366 $join_conds = array_merge(
371 'wl_user' => $user->getId(),
372 'wl_namespace=rc_namespace',
382 $fields[] = 'page_latest';
383 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
385 $fields[] = 'wl_notificationtimestamp';
387 // Log entries with DELETED_ACTION must not show up unless the user has
388 // the necessary rights.
389 if ( !$user->isAllowed( 'deletedhistory' ) ) {
390 $bitmask = LogPage
::DELETED_ACTION
;
391 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
392 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
397 $conds[] = $dbr->makeList( [
398 'rc_type != ' . RC_LOG
,
399 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
403 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
404 ChangeTags
::modifyDisplayQuery(
413 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
415 if ( $this->areFiltersInConflict() ) {
420 'ORDER BY' => 'rc_timestamp DESC',
421 'LIMIT' => $opts['limit']
423 if ( in_array( 'DISTINCT', $query_options ) ) {
424 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
425 // In order to prevent DISTINCT from causing query performance problems,
426 // we have to GROUP BY the primary key. This in turn requires us to add
427 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
428 // start of the GROUP BY
429 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
430 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
432 // array_merge() is used intentionally here so that hooks can, should
433 // they so desire, override the ORDER BY / LIMIT condition(s)
434 $query_options = array_merge( $orderByAndLimit, $query_options );
446 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
449 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
451 'SpecialWatchlistQuery',
452 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
458 * Return a IDatabase object for reading
462 protected function getDB() {
463 return wfGetDB( DB_REPLICA
, 'watchlist' );
469 public function outputFeedLinks() {
470 $user = $this->getUser();
471 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
473 $this->addFeedLinks( [
474 'action' => 'feedwatchlist',
476 'wlowner' => $user->getName(),
477 'wltoken' => $wlToken,
483 * Build and output the actual changes list.
485 * @param ResultWrapper $rows Database rows
486 * @param FormOptions $opts
488 public function outputChangesList( $rows, $opts ) {
489 $dbr = $this->getDB();
490 $user = $this->getUser();
491 $output = $this->getOutput();
493 # Show a message about replica DB lag, if applicable
494 $lag = wfGetLB()->safeGetLag( $dbr );
496 $output->showLagWarning( $lag );
499 # If no rows to display, show message before try to render the list
500 if ( $rows->numRows() == 0 ) {
501 $output->wrapWikiMsg(
502 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
507 $dbr->dataSeek( $rows, 0 );
509 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
510 $list->setWatchlistDivs();
511 $list->initChangesListRows( $rows );
512 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
513 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
514 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
515 // since EnhancedChangesList groups log entries by performer rather than by target article
516 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
520 return $this->getLinkRenderer()
521 ->makeKnownLink( $rc->getTitle(),
522 $this->msg( 'watchlist-unwatch' )->text(), [
523 'class' => 'mw-unwatch-link',
524 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
525 ], [ 'action' => 'unwatch' ] ) . ' ';
529 $dbr->dataSeek( $rows, 0 );
531 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
532 && $user->getOption( 'shownumberswatching' )
534 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
537 $s = $list->beginRecentChangesList();
539 if ( $this->isStructuredFilterUiEnabled() ) {
540 $s .= $this->makeLegend();
543 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
545 foreach ( $rows as $obj ) {
547 $rc = RecentChange
::newFromRow( $obj );
549 # Skip CatWatch entries for hidden cats based on user preference
551 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
552 !$userShowHiddenCats &&
553 $rc->getParam( 'hidden-cat' )
558 $rc->counter
= $counter++
;
560 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
561 $updated = $obj->wl_notificationtimestamp
;
566 if ( isset( $watchedItemStore ) ) {
567 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
568 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
570 $rc->numberofWatchingusers
= 0;
573 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
574 if ( $changeLine !== false ) {
578 $s .= $list->endRecentChangesList();
580 $output->addHTML( $s );
584 * Set the text to be displayed above the changes
586 * @param FormOptions $opts
587 * @param int $numRows Number of rows in the result to show after this header
589 public function doHeader( $opts, $numRows ) {
590 $user = $this->getUser();
591 $out = $this->getOutput();
594 $this->msg( 'watchlistfor2', $user->getName() )
595 ->rawParams( SpecialEditWatchlist
::buildTools(
596 $this->getLanguage(),
597 $this->getLinkRenderer()
601 $this->setTopText( $opts );
605 $form .= Xml
::openElement( 'form', [
607 'action' => wfScript(),
608 'id' => 'mw-watchlist-form'
610 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
611 $form .= Xml
::openElement(
613 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
615 $form .= Xml
::element(
616 'legend', null, $this->msg( 'watchlist-options' )->text()
619 if ( !$this->isStructuredFilterUiEnabled() ) {
620 $form .= $this->makeLegend();
623 $lang = $this->getLanguage();
624 $timestamp = wfTimestampNow();
625 $wlInfo = Html
::rawElement(
629 'data-params' => json_encode( [ 'from' => $timestamp ] ),
631 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
632 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
636 $nondefaults = $opts->getChangedValues();
637 $cutofflinks = Html
::rawElement(
639 [ 'class' => 'cldays cloption' ],
640 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
643 # Spit out some control panel links
645 $namesOfDisplayedFilters = [];
646 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
647 $namesOfDisplayedFilters[] = $filterName;
648 $links[] = $this->showHideCheck(
650 $filter->getShowHide(),
652 $opts[ $filterName ],
653 $filter->isFeatureAvailableOnStructuredUi( $this )
657 $hiddenFields = $nondefaults;
658 $hiddenFields['action'] = 'submit';
659 unset( $hiddenFields['namespace'] );
660 unset( $hiddenFields['invert'] );
661 unset( $hiddenFields['associated'] );
662 unset( $hiddenFields['days'] );
663 foreach ( $namesOfDisplayedFilters as $filterName ) {
664 unset( $hiddenFields[$filterName] );
667 # Namespace filter and put the whole form together.
669 $form .= $cutofflinks;
670 $form .= Html
::rawElement(
672 [ 'class' => 'clshowhide' ],
673 $this->msg( 'watchlist-hide' ) .
674 $this->msg( 'colon-separator' )->escaped() .
675 implode( ' ', $links )
677 $form .= "\n<br />\n";
679 $namespaceForm = Html
::namespaceSelector(
681 'selected' => $opts['namespace'],
683 'label' => $this->msg( 'namespace' )->text()
685 'name' => 'namespace',
687 'class' => 'namespaceselector',
690 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
691 $this->msg( 'invert' )->text(),
695 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
697 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
698 $this->msg( 'namespace_association' )->text(),
702 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
704 $form .= Html
::rawElement(
706 [ 'class' => 'namespaceForm cloption' ],
710 $form .= Xml
::submitButton(
711 $this->msg( 'watchlist-submit' )->text(),
712 [ 'class' => 'cloption-submit' ]
714 foreach ( $hiddenFields as $key => $value ) {
715 $form .= Html
::hidden( $key, $value ) . "\n";
717 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
718 $form .= Xml
::closeElement( 'form' ) . "\n";
720 // Insert a placeholder for RCFilters
721 if ( $this->isStructuredFilterUiEnabled() ) {
722 $rcfilterContainer = Html
::element(
724 [ 'class' => 'rcfilters-container' ]
727 $loadingContainer = Html
::rawElement(
729 [ 'class' => 'rcfilters-spinner' ],
732 [ 'class' => 'rcfilters-spinner-bounce' ]
736 // Wrap both with rcfilters-head
737 $this->getOutput()->addHTML(
740 [ 'class' => 'rcfilters-head' ],
741 $rcfilterContainer . $form
746 $this->getOutput()->addHTML( $loadingContainer );
748 $this->getOutput()->addHTML( $form );
751 $this->setBottomText( $opts );
754 function cutoffselector( $options ) {
755 // Cast everything to strings immediately, so that we know all of the values have the same
756 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
757 // default string representation, for example, and would confuse comparisons.
759 // Misleadingly, the 'days' option supports hours too.
760 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
762 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
763 // add the user preference, if it isn't available already
764 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
765 $days[] = $userWatchlistOption;
768 $maxDays = (string)$this->maxDays
;
769 // add the maximum possible value, if it isn't available already
770 if ( !in_array( $maxDays, $days ) ) {
774 $selected = (string)$options['days'];
775 if ( $selected <= 0 ) {
776 $selected = $maxDays;
779 // add the currently selected value, if it isn't available already
780 if ( !in_array( $selected, $days ) ) {
784 $select = new XmlSelect( 'days', 'days', $selected );
787 foreach ( $days as $value ) {
789 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
791 $name = $this->msg( 'days' )->numParams( $value )->text();
793 $select->addOption( $name, $value );
796 return $select->getHTML() . "\n<br />\n";
799 function setTopText( FormOptions
$opts ) {
800 $nondefaults = $opts->getChangedValues();
802 $user = $this->getUser();
804 $numItems = $this->countItems();
805 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
807 // Show watchlist header
808 $watchlistHeader = '';
809 if ( $numItems == 0 ) {
810 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
812 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
813 if ( $this->getConfig()->get( 'EnotifWatchlist' )
814 && $user->getOption( 'enotifwatchlistpages' )
816 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
818 if ( $showUpdatedMarker ) {
819 $watchlistHeader .= $this->msg(
820 $this->isStructuredFilterUiEnabled() ?
821 'rcfilters-watchlist-showupdated' :
822 'wlheader-showupdated'
826 $form .= Html
::rawElement(
828 [ 'class' => 'watchlistDetails' ],
832 if ( $numItems > 0 && $showUpdatedMarker ) {
833 $form .= Xml
::openElement( 'form', [ 'method' => 'post',
834 'action' => $this->getPageTitle()->getLocalURL(),
835 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
836 Xml
::submitButton( $this->msg( 'enotif_reset' )->text(),
837 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
838 Html
::hidden( 'token', $user->getEditToken() ) . "\n" .
839 Html
::hidden( 'reset', 'all' ) . "\n";
840 foreach ( $nondefaults as $key => $value ) {
841 $form .= Html
::hidden( $key, $value ) . "\n";
843 $form .= Xml
::closeElement( 'form' ) . "\n";
846 $this->getOutput()->addHTML( $form );
849 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
850 $options[$name] = 1 - (int)$value;
852 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
853 if ( $inStructuredUi ) {
854 $attribs[ 'data-feature-in-structured-ui' ] = true;
857 return Html
::rawElement(
860 // not using Html::checkLabel because that would escape the contents
861 Html
::check( $name, (int)$value, [ 'id' => $name ] ) . Html
::rawElement(
863 $attribs +
[ 'for' => $name ],
864 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
865 $this->msg( $message, '<nowiki/>' )->parse()
871 * Count the number of paired items on a user's watchlist.
872 * The assumption made here is that when a subject page is watched a talk page is also watched.
873 * Hence the number of individual items is halved.
877 protected function countItems() {
878 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
879 $count = $store->countWatchedItems( $this->getUser() );
880 return floor( $count / 2 );