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->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false );
101 $output->addJsConfigVars(
102 'wgStructuredChangeFiltersSavedQueriesPreferenceName',
103 'rcfilters-wl-saved-queries'
108 protected function isStructuredFilterUiEnabled() {
109 return parent
::isStructuredFilterUiEnabled()
110 && ( $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' )
111 ||
$this->getRequest()->getBool( 'rcfilters' ) );
115 * Return an array of subpages that this special page will accept.
117 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
118 * @return string[] subpages
120 public function getSubpagesForPrefixSearch() {
131 protected function transformFilterDefinition( array $filterDefinition ) {
132 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
133 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
136 return $filterDefinition;
142 protected function registerFilters() {
143 parent
::registerFilters();
145 // legacy 'extended' filter
146 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
147 'name' => 'extended-group',
150 'name' => 'extended',
151 'isReplacedInStructuredUi' => true,
152 'isVisible' => false,
153 'activeValue' => false,
154 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
155 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
156 &$fields, &$conds, &$query_options, &$join_conds ) {
157 $nonRevisionTypes = [ RC_LOG
];
158 Hooks
::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
159 if ( $nonRevisionTypes ) {
160 $conds[] = $dbr->makeList(
162 'rc_this_oldid=page_latest',
163 'rc_type' => $nonRevisionTypes,
174 if ( $this->isStructuredFilterUiEnabled() ) {
175 $this->getFilterGroup( 'lastRevision' )
176 ->getFilter( 'hidepreviousrevisions' )
177 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
180 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
181 'name' => 'watchlistactivity',
182 'title' => 'rcfilters-filtergroup-watchlistactivity',
183 'class' => ChangesListStringOptionsFilterGroup
::class,
185 'isFullCoverage' => true,
189 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
190 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
191 'cssClassSuffix' => 'watchedunseen',
192 'isRowApplicableCallable' => function ( $ctx, $rc ) {
193 $changeTs = $rc->getAttribute( 'rc_timestamp' );
194 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
195 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
200 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
201 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
202 'cssClassSuffix' => 'watchedseen',
203 'isRowApplicableCallable' => function ( $ctx, $rc ) {
204 $changeTs = $rc->getAttribute( 'rc_timestamp' );
205 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
206 return $lastVisitTs === null ||
$changeTs < $lastVisitTs;
210 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
211 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
212 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
213 if ( $selectedValues === [ 'seen' ] ) {
214 $conds[] = $dbr->makeList( [
215 'wl_notificationtimestamp IS NULL',
216 'rc_timestamp < wl_notificationtimestamp'
218 } elseif ( $selectedValues === [ 'unseen' ] ) {
219 $conds[] = $dbr->makeList( [
220 'wl_notificationtimestamp IS NOT NULL',
221 'rc_timestamp >= wl_notificationtimestamp'
227 $user = $this->getUser();
229 $significance = $this->getFilterGroup( 'significance' );
230 $hideMinor = $significance->getFilter( 'hideminor' );
231 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
233 $automated = $this->getFilterGroup( 'automated' );
234 $hideBots = $automated->getFilter( 'hidebots' );
235 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
237 $registration = $this->getFilterGroup( 'registration' );
238 $hideAnons = $registration->getFilter( 'hideanons' );
239 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
240 $hideLiu = $registration->getFilter( 'hideliu' );
241 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
243 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
244 if ( $reviewStatus !== null ) {
245 // Conditional on feature being available and rights
246 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
247 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
250 $authorship = $this->getFilterGroup( 'authorship' );
251 $hideMyself = $authorship->getFilter( 'hidemyself' );
252 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
254 $changeType = $this->getFilterGroup( 'changeType' );
255 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
256 if ( $hideCategorization !== null ) {
257 // Conditional on feature being available
258 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
263 * Get a FormOptions object containing the default options
265 * @return FormOptions
267 public function getDefaultOptions() {
268 $opts = parent
::getDefaultOptions();
269 $user = $this->getUser();
271 $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions
::FLOAT );
272 $opts->add( 'limit', $user->getIntOption( 'wllimit' ), FormOptions
::INT );
277 public function validateOptions( FormOptions
$opts ) {
278 $opts->validateBounds( 'days', 0, $this->maxDays
);
279 $opts->validateIntBounds( 'limit', 0, 5000 );
280 parent
::validateOptions( $opts );
284 * Get all custom filters
286 * @return array Map of filter URL param names to properties (msg/default)
288 protected function getCustomFilters() {
289 if ( $this->customFilters
=== null ) {
290 $this->customFilters
= parent
::getCustomFilters();
291 Hooks
::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters
], '1.23' );
294 return $this->customFilters
;
298 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
300 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
301 * to the current ones.
303 * @param FormOptions $opts
304 * @return FormOptions
306 protected function fetchOptionsFromRequest( $opts ) {
307 static $compatibilityMap = [
308 'hideMinor' => 'hideminor',
309 'hideBots' => 'hidebots',
310 'hideAnons' => 'hideanons',
311 'hideLiu' => 'hideliu',
312 'hidePatrolled' => 'hidepatrolled',
313 'hideOwn' => 'hidemyself',
316 $params = $this->getRequest()->getValues();
317 foreach ( $compatibilityMap as $from => $to ) {
318 if ( isset( $params[$from] ) ) {
319 $params[$to] = $params[$from];
320 unset( $params[$from] );
324 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
325 $allBooleansFalse = [];
327 // If the user submitted the form, start with a baseline of "all
328 // booleans are false", then change the ones they checked. This
329 // means we ignore the defaults.
331 // This is how we handle the fact that HTML forms don't submit
333 foreach ( $this->filterGroups
as $filterGroup ) {
334 if ( $filterGroup instanceof ChangesListBooleanFilterGroup
) {
335 foreach ( $filterGroup->getFilters() as $filter ) {
336 if ( $filter->isVisible() ) {
337 $allBooleansFalse[$filter->getName()] = false;
343 $params = $params +
$allBooleansFalse;
346 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
347 // methods defined on WebRequest and removing this dependency would cause some code duplication.
348 $request = new DerivativeRequest( $this->getRequest(), $params );
349 $opts->fetchValuesFromRequest( $request );
357 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
358 &$join_conds, FormOptions
$opts
360 $dbr = $this->getDB();
361 parent
::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
365 if ( $opts['days'] > 0 ) {
366 $conds[] = 'rc_timestamp > ' .
367 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
374 protected function doMainQuery( $tables, $fields, $conds, $query_options,
375 $join_conds, FormOptions
$opts
377 $dbr = $this->getDB();
378 $user = $this->getUser();
380 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
381 $fields = array_merge( RecentChange
::selectFields(), $fields );
383 $query_options = array_merge( [
384 'ORDER BY' => 'rc_timestamp DESC',
385 'LIMIT' => $opts['limit']
387 $join_conds = array_merge(
392 'wl_user' => $user->getId(),
393 'wl_namespace=rc_namespace',
402 $fields[] = 'page_latest';
403 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
405 $fields[] = 'wl_notificationtimestamp';
407 // Log entries with DELETED_ACTION must not show up unless the user has
408 // the necessary rights.
409 if ( !$user->isAllowed( 'deletedhistory' ) ) {
410 $bitmask = LogPage
::DELETED_ACTION
;
411 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
412 $bitmask = LogPage
::DELETED_ACTION | LogPage
::DELETED_RESTRICTED
;
417 $conds[] = $dbr->makeList( [
418 'rc_type != ' . RC_LOG
,
419 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
423 ChangeTags
::modifyDisplayQuery(
432 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
434 if ( $this->areFiltersInConflict() ) {
448 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
451 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
453 'SpecialWatchlistQuery',
454 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
460 * Return a IDatabase object for reading
464 protected function getDB() {
465 return wfGetDB( DB_REPLICA
, 'watchlist' );
471 public function outputFeedLinks() {
472 $user = $this->getUser();
473 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
475 $this->addFeedLinks( [
476 'action' => 'feedwatchlist',
478 'wlowner' => $user->getName(),
479 'wltoken' => $wlToken,
485 * Build and output the actual changes list.
487 * @param ResultWrapper $rows Database rows
488 * @param FormOptions $opts
490 public function outputChangesList( $rows, $opts ) {
491 $dbr = $this->getDB();
492 $user = $this->getUser();
493 $output = $this->getOutput();
495 # Show a message about replica DB lag, if applicable
496 $lag = wfGetLB()->safeGetLag( $dbr );
498 $output->showLagWarning( $lag );
501 # If no rows to display, show message before try to render the list
502 if ( $rows->numRows() == 0 ) {
503 $output->wrapWikiMsg(
504 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
509 $dbr->dataSeek( $rows, 0 );
511 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
512 $list->setWatchlistDivs();
513 $list->initChangesListRows( $rows );
514 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
515 $list->setChangeLinePrefixer( function ( RecentChange
$rc, ChangesList
$cl, $grouped ) {
516 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
517 // since EnhancedChangesList groups log entries by performer rather than by target article
518 if ( $rc->mAttribs
['rc_type'] == RC_LOG
&& $cl instanceof EnhancedChangesList
&&
522 return $this->getLinkRenderer()
523 ->makeKnownLink( $rc->getTitle(),
524 $this->msg( 'watchlist-unwatch' )->text(), [
525 'class' => 'mw-unwatch-link',
526 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
527 ], [ 'action' => 'unwatch' ] ) . ' ';
531 $dbr->dataSeek( $rows, 0 );
533 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
534 && $user->getOption( 'shownumberswatching' )
536 $watchedItemStore = MediaWikiServices
::getInstance()->getWatchedItemStore();
539 $s = $list->beginRecentChangesList();
541 if ( $this->isStructuredFilterUiEnabled() ) {
542 $s .= $this->makeLegend();
545 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
547 foreach ( $rows as $obj ) {
549 $rc = RecentChange
::newFromRow( $obj );
551 # Skip CatWatch entries for hidden cats based on user preference
553 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
554 !$userShowHiddenCats &&
555 $rc->getParam( 'hidden-cat' )
560 $rc->counter
= $counter++
;
562 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
563 $updated = $obj->wl_notificationtimestamp
;
568 if ( isset( $watchedItemStore ) ) {
569 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
);
570 $rc->numberofWatchingusers
= $watchedItemStore->countWatchers( $rcTitleValue );
572 $rc->numberofWatchingusers
= 0;
575 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
576 if ( $changeLine !== false ) {
580 $s .= $list->endRecentChangesList();
582 $output->addHTML( $s );
586 * Set the text to be displayed above the changes
588 * @param FormOptions $opts
589 * @param int $numRows Number of rows in the result to show after this header
591 public function doHeader( $opts, $numRows ) {
592 $user = $this->getUser();
593 $out = $this->getOutput();
596 $this->msg( 'watchlistfor2', $user->getName() )
597 ->rawParams( SpecialEditWatchlist
::buildTools(
598 $this->getLanguage(),
599 $this->getLinkRenderer()
603 $this->setTopText( $opts );
607 $form .= Xml
::openElement( 'form', [
609 'action' => wfScript(),
610 'id' => 'mw-watchlist-form'
612 $form .= Html
::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
613 $form .= Xml
::fieldset(
614 $this->msg( 'watchlist-options' )->text(),
616 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
619 if ( !$this->isStructuredFilterUiEnabled() ) {
620 $form .= $this->makeLegend();
623 $lang = $this->getLanguage();
624 if ( $opts['days'] > 0 ) {
625 $days = $opts['days'];
627 $days = $this->maxDays
;
629 $timestamp = wfTimestampNow();
630 $wlInfo = Html
::rawElement(
632 [ 'class' => 'wlinfo' ],
633 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
634 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
638 $nondefaults = $opts->getChangedValues();
639 $cutofflinks = Html
::rawElement(
641 [ 'class' => 'cldays cloption' ],
642 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
645 # Spit out some control panel links
647 $namesOfDisplayedFilters = [];
648 foreach ( $this->getFilterGroups() as $groupName => $group ) {
649 if ( !$group->isPerGroupRequestParameter() ) {
650 foreach ( $group->getFilters() as $filterName => $filter ) {
651 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
652 $namesOfDisplayedFilters[] = $filterName;
653 $links[] = $this->showHideCheck(
655 $filter->getShowHide(),
658 $filter->isFeatureAvailableOnStructuredUi( $this )
665 $hiddenFields = $nondefaults;
666 $hiddenFields['action'] = 'submit';
667 unset( $hiddenFields['namespace'] );
668 unset( $hiddenFields['invert'] );
669 unset( $hiddenFields['associated'] );
670 unset( $hiddenFields['days'] );
671 foreach ( $namesOfDisplayedFilters as $filterName ) {
672 unset( $hiddenFields[$filterName] );
675 # Namespace filter and put the whole form together.
677 $form .= $cutofflinks;
678 $form .= Html
::rawElement(
680 [ 'class' => 'clshowhide' ],
681 $this->msg( 'watchlist-hide' ) .
682 $this->msg( 'colon-separator' )->escaped() .
683 implode( ' ', $links )
685 $form .= "\n<br />\n";
687 $namespaceForm = Html
::namespaceSelector(
689 'selected' => $opts['namespace'],
691 'label' => $this->msg( 'namespace' )->text()
693 'name' => 'namespace',
695 'class' => 'namespaceselector',
698 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
699 $this->msg( 'invert' )->text(),
703 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
705 $namespaceForm .= '<span class="mw-input-with-label">' . Xml
::checkLabel(
706 $this->msg( 'namespace_association' )->text(),
710 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
712 $form .= Html
::rawElement(
714 [ 'class' => 'namespaceForm cloption' ],
718 $form .= Xml
::submitButton(
719 $this->msg( 'watchlist-submit' )->text(),
720 [ 'class' => 'cloption-submit' ]
722 foreach ( $hiddenFields as $key => $value ) {
723 $form .= Html
::hidden( $key, $value ) . "\n";
725 $form .= Xml
::closeElement( 'fieldset' ) . "\n";
726 $form .= Xml
::closeElement( 'form' ) . "\n";
728 // Insert a placeholder for RCFilters
729 if ( $this->isStructuredFilterUiEnabled() ) {
730 $rcfilterContainer = Html
::element(
732 [ 'class' => 'rcfilters-container' ]
735 $loadingContainer = Html
::rawElement(
737 [ 'class' => 'rcfilters-spinner' ],
740 [ 'class' => 'rcfilters-spinner-bounce' ]
744 // Wrap both with rcfilters-head
745 $this->getOutput()->addHTML(
748 [ 'class' => 'rcfilters-head' ],
749 $rcfilterContainer . $form
754 $this->getOutput()->addHTML( $loadingContainer );
756 $this->getOutput()->addHTML( $form );
759 $this->setBottomText( $opts );
762 function cutoffselector( $options ) {
763 // Cast everything to strings immediately, so that we know all of the values have the same
764 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
765 // default string representation, for example, and would confuse comparisons.
767 // Misleadingly, the 'days' option supports hours too.
768 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
770 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
771 // add the user preference, if it isn't available already
772 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
773 $days[] = $userWatchlistOption;
776 $maxDays = (string)$this->maxDays
;
777 // add the maximum possible value, if it isn't available already
778 if ( !in_array( $maxDays, $days ) ) {
782 $selected = (string)$options['days'];
783 if ( $selected <= 0 ) {
784 $selected = $maxDays;
787 // add the currently selected value, if it isn't available already
788 if ( !in_array( $selected, $days ) ) {
792 $select = new XmlSelect( 'days', 'days', $selected );
795 foreach ( $days as $value ) {
797 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
799 $name = $this->msg( 'days' )->numParams( $value )->text();
801 $select->addOption( $name, $value );
804 return $select->getHTML() . "\n<br />\n";
807 function setTopText( FormOptions
$opts ) {
808 $nondefaults = $opts->getChangedValues();
810 $user = $this->getUser();
812 $numItems = $this->countItems();
813 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
815 // Show watchlist header
817 if ( $numItems == 0 ) {
818 $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
820 $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
821 if ( $this->getConfig()->get( 'EnotifWatchlist' )
822 && $user->getOption( 'enotifwatchlistpages' )
824 $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
826 if ( $showUpdatedMarker ) {
827 $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
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(
861 $this->msg( $message, '' )->text(),
870 * Count the number of paired items on a user's watchlist.
871 * The assumption made here is that when a subject page is watched a talk page is also watched.
872 * Hence the number of individual items is halved.
876 protected function countItems() {
877 $store = MediaWikiServices
::getInstance()->getWatchedItemStore();
878 $count = $store->countWatchedItems( $this->getUser() );
879 return floor( $count / 2 );
882 function getDefaultLimit() {
883 return $this->getUser()->getIntOption( 'wllimit' );
886 function getDefaultDays() {
887 return $this->getUser()->getIntOption( 'watchlistdays' );