Don't hard-code Preferences page name
[lhc/web/wiklou.git] / includes / specials / SpecialWatchlist.php
1 <?php
2 /**
3 * Implements Special:Watchlist
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 use MediaWiki\MediaWikiServices;
25 use Wikimedia\Rdbms\ResultWrapper;
26 use Wikimedia\Rdbms\IDatabase;
27
28 /**
29 * A special page that lists last changes made to the wiki,
30 * limited to user-defined list of titles.
31 *
32 * @ingroup SpecialPage
33 */
34 class SpecialWatchlist extends ChangesListSpecialPage {
35 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
36 parent::__construct( $page, $restriction );
37
38 $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
39 }
40
41 public function doesWrites() {
42 return true;
43 }
44
45 /**
46 * Main execution point
47 *
48 * @param string $subpage
49 */
50 function execute( $subpage ) {
51 // Anons don't get a watchlist
52 $this->requireLogin( 'watchlistanontext' );
53
54 $output = $this->getOutput();
55 $request = $this->getRequest();
56 $this->addHelpLink( 'Help:Watching pages' );
57 $output->addModules( [
58 'mediawiki.special.changeslist.visitedstatus',
59 'mediawiki.special.watchlist',
60 ] );
61 $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] );
62
63 $mode = SpecialEditWatchlist::getMode( $request, $subpage );
64 if ( $mode !== false ) {
65 if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
66 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
67 } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
68 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
69 } else {
70 $title = SpecialPage::getTitleFor( 'EditWatchlist' );
71 }
72
73 $output->redirect( $title->getLocalURL() );
74
75 return;
76 }
77
78 $this->checkPermissions();
79
80 $user = $this->getUser();
81 $opts = $this->getOptions();
82
83 $config = $this->getConfig();
84 if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
85 && $request->getVal( 'reset' )
86 && $request->wasPosted()
87 && $user->matchEditToken( $request->getVal( 'token' ) )
88 ) {
89 $user->clearAllNotifications();
90 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
91
92 return;
93 }
94
95 parent::execute( $subpage );
96 }
97
98 /**
99 * Return an array of subpages that this special page will accept.
100 *
101 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
102 * @return string[] subpages
103 */
104 public function getSubpagesForPrefixSearch() {
105 return [
106 'clear',
107 'edit',
108 'raw',
109 ];
110 }
111
112 /**
113 * @inheritDoc
114 */
115 protected function transformFilterDefinition( array $filterDefinition ) {
116 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
117 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
118 }
119
120 return $filterDefinition;
121 }
122
123 /**
124 * @inheritDoc
125 */
126 protected function registerFilters() {
127 parent::registerFilters();
128
129 $user = $this->getUser();
130
131 $significance = $this->getFilterGroup( 'significance' );
132 $hideMinor = $significance->getFilter( 'hideminor' );
133 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
134
135 $automated = $this->getFilterGroup( 'automated' );
136 $hideBots = $automated->getFilter( 'hidebots' );
137 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
138
139 $registration = $this->getFilterGroup( 'registration' );
140 $hideAnons = $registration->getFilter( 'hideanons' );
141 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
142 $hideLiu = $registration->getFilter( 'hideliu' );
143 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
144
145 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
146 if ( $reviewStatus !== null ) {
147 // Conditional on feature being available and rights
148 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
149 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
150 }
151
152 $authorship = $this->getFilterGroup( 'authorship' );
153 $hideMyself = $authorship->getFilter( 'hidemyself' );
154 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
155
156 $changeType = $this->getFilterGroup( 'changeType' );
157 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
158 if ( $hideCategorization !== null ) {
159 // Conditional on feature being available
160 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
161 }
162 }
163
164 /**
165 * Get a FormOptions object containing the default options
166 *
167 * @return FormOptions
168 */
169 public function getDefaultOptions() {
170 $opts = parent::getDefaultOptions();
171 $user = $this->getUser();
172
173 $opts->add( 'days', $user->getOption( 'watchlistdays' ), FormOptions::FLOAT );
174 $opts->add( 'extended', $user->getBoolOption( 'extendwatchlist' ) );
175
176 return $opts;
177 }
178
179 public function validateOptions( FormOptions $opts ) {
180 $opts->validateBounds( 'days', 0, $this->maxDays );
181 parent::validateOptions( $opts );
182 }
183
184 /**
185 * Get all custom filters
186 *
187 * @return array Map of filter URL param names to properties (msg/default)
188 */
189 protected function getCustomFilters() {
190 if ( $this->customFilters === null ) {
191 $this->customFilters = parent::getCustomFilters();
192 Hooks::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters ], '1.23' );
193 }
194
195 return $this->customFilters;
196 }
197
198 /**
199 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
200 *
201 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
202 * to the current ones.
203 *
204 * @param FormOptions $opts
205 * @return FormOptions
206 */
207 protected function fetchOptionsFromRequest( $opts ) {
208 static $compatibilityMap = [
209 'hideMinor' => 'hideminor',
210 'hideBots' => 'hidebots',
211 'hideAnons' => 'hideanons',
212 'hideLiu' => 'hideliu',
213 'hidePatrolled' => 'hidepatrolled',
214 'hideOwn' => 'hidemyself',
215 ];
216
217 $params = $this->getRequest()->getValues();
218 foreach ( $compatibilityMap as $from => $to ) {
219 if ( isset( $params[$from] ) ) {
220 $params[$to] = $params[$from];
221 unset( $params[$from] );
222 }
223 }
224
225 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
226 $allBooleansFalse = [];
227
228 // If the user submitted the form, start with a baseline of "all
229 // booleans are false", then change the ones they checked. This
230 // means we ignore the defaults.
231
232 // This is how we handle the fact that HTML forms don't submit
233 // unchecked boxes.
234 foreach ( $this->filterGroups as $filterGroup ) {
235 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
236 foreach ( $filterGroup->getFilters() as $filter ) {
237 $allBooleansFalse[$filter->getName()] = false;
238 }
239 }
240 }
241
242 $params = $params + $allBooleansFalse;
243 }
244
245 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
246 // methods defined on WebRequest and removing this dependency would cause some code duplication.
247 $request = new DerivativeRequest( $this->getRequest(), $params );
248 $opts->fetchValuesFromRequest( $request );
249
250 return $opts;
251 }
252
253 /**
254 * @inheritDoc
255 */
256 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
257 &$join_conds, FormOptions $opts
258 ) {
259 $dbr = $this->getDB();
260 parent::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
261 $opts );
262
263 // Calculate cutoff
264 if ( $opts['days'] > 0 ) {
265 $conds[] = 'rc_timestamp > ' .
266 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
267 }
268 }
269
270 /**
271 * @inheritDoc
272 */
273 protected function doMainQuery( $tables, $fields, $conds, $query_options,
274 $join_conds, FormOptions $opts
275 ) {
276 $dbr = $this->getDB();
277 $user = $this->getUser();
278
279 # Toggle watchlist content (all recent edits or just the latest)
280 if ( $opts['extended'] ) {
281 $usePage = false;
282 } else {
283 # Top log Ids for a page are not stored
284 $nonRevisionTypes = [ RC_LOG ];
285 Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
286 if ( $nonRevisionTypes ) {
287 $conds[] = $dbr->makeList(
288 [
289 'rc_this_oldid=page_latest',
290 'rc_type' => $nonRevisionTypes,
291 ],
292 LIST_OR
293 );
294 }
295 $usePage = true;
296 }
297
298 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
299 $fields = array_merge( RecentChange::selectFields(), $fields );
300
301 $query_options = array_merge( [
302 'ORDER BY' => 'rc_timestamp DESC',
303 'LIMIT' => $user->getIntOption( 'wllimit' )
304 ], $query_options );
305 $join_conds = array_merge(
306 [
307 'watchlist' => [
308 'INNER JOIN',
309 [
310 'wl_user' => $user->getId(),
311 'wl_namespace=rc_namespace',
312 'wl_title=rc_title'
313 ],
314 ],
315 ],
316 $join_conds
317 );
318
319 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
320 $fields[] = 'wl_notificationtimestamp';
321 }
322
323 $rollbacker = $user->isAllowed( 'rollback' );
324 if ( $usePage || $rollbacker ) {
325 $tables[] = 'page';
326 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
327 if ( $rollbacker ) {
328 $fields[] = 'page_latest';
329 }
330 }
331
332 // Log entries with DELETED_ACTION must not show up unless the user has
333 // the necessary rights.
334 if ( !$user->isAllowed( 'deletedhistory' ) ) {
335 $bitmask = LogPage::DELETED_ACTION;
336 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
337 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
338 } else {
339 $bitmask = 0;
340 }
341 if ( $bitmask ) {
342 $conds[] = $dbr->makeList( [
343 'rc_type != ' . RC_LOG,
344 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
345 ], LIST_OR );
346 }
347
348 ChangeTags::modifyDisplayQuery(
349 $tables,
350 $fields,
351 $conds,
352 $join_conds,
353 $query_options,
354 ''
355 );
356
357 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
358
359 return $dbr->select(
360 $tables,
361 $fields,
362 $conds,
363 __METHOD__,
364 $query_options,
365 $join_conds
366 );
367 }
368
369 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
370 &$join_conds, $opts
371 ) {
372 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
373 && Hooks::run(
374 'SpecialWatchlistQuery',
375 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
376 '1.23'
377 );
378 }
379
380 /**
381 * Return a IDatabase object for reading
382 *
383 * @return IDatabase
384 */
385 protected function getDB() {
386 return wfGetDB( DB_REPLICA, 'watchlist' );
387 }
388
389 /**
390 * Output feed links.
391 */
392 public function outputFeedLinks() {
393 $user = $this->getUser();
394 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
395 if ( $wlToken ) {
396 $this->addFeedLinks( [
397 'action' => 'feedwatchlist',
398 'allrev' => 1,
399 'wlowner' => $user->getName(),
400 'wltoken' => $wlToken,
401 ] );
402 }
403 }
404
405 /**
406 * Build and output the actual changes list.
407 *
408 * @param ResultWrapper $rows Database rows
409 * @param FormOptions $opts
410 */
411 public function outputChangesList( $rows, $opts ) {
412 $dbr = $this->getDB();
413 $user = $this->getUser();
414 $output = $this->getOutput();
415
416 # Show a message about replica DB lag, if applicable
417 $lag = wfGetLB()->safeGetLag( $dbr );
418 if ( $lag > 0 ) {
419 $output->showLagWarning( $lag );
420 }
421
422 # If no rows to display, show message before try to render the list
423 if ( $rows->numRows() == 0 ) {
424 $output->wrapWikiMsg(
425 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
426 );
427 return;
428 }
429
430 $dbr->dataSeek( $rows, 0 );
431
432 $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
433 $list->setWatchlistDivs();
434 $list->initChangesListRows( $rows );
435 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
436 $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
437 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
438 // since EnhancedChangesList groups log entries by performer rather than by target article
439 if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
440 $grouped ) {
441 return '';
442 } else {
443 return $this->getLinkRenderer()
444 ->makeKnownLink( $rc->getTitle(),
445 $this->msg( 'watchlist-unwatch' )->text(), [
446 'class' => 'mw-unwatch-link',
447 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
448 ], [ 'action' => 'unwatch' ] ) . '&#160;';
449 }
450 } );
451 }
452 $dbr->dataSeek( $rows, 0 );
453
454 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
455 && $user->getOption( 'shownumberswatching' )
456 ) {
457 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
458 }
459
460 $s = $list->beginRecentChangesList();
461 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
462 $counter = 1;
463 foreach ( $rows as $obj ) {
464 # Make RC entry
465 $rc = RecentChange::newFromRow( $obj );
466
467 # Skip CatWatch entries for hidden cats based on user preference
468 if (
469 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
470 !$userShowHiddenCats &&
471 $rc->getParam( 'hidden-cat' )
472 ) {
473 continue;
474 }
475
476 $rc->counter = $counter++;
477
478 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
479 $updated = $obj->wl_notificationtimestamp;
480 } else {
481 $updated = false;
482 }
483
484 if ( isset( $watchedItemStore ) ) {
485 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
486 $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
487 } else {
488 $rc->numberofWatchingusers = 0;
489 }
490
491 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
492 if ( $changeLine !== false ) {
493 $s .= $changeLine;
494 }
495 }
496 $s .= $list->endRecentChangesList();
497
498 $output->addHTML( $s );
499 }
500
501 /**
502 * Set the text to be displayed above the changes
503 *
504 * @param FormOptions $opts
505 * @param int $numRows Number of rows in the result to show after this header
506 */
507 public function doHeader( $opts, $numRows ) {
508 $user = $this->getUser();
509 $out = $this->getOutput();
510
511 $out->addSubtitle(
512 $this->msg( 'watchlistfor2', $user->getName() )
513 ->rawParams( SpecialEditWatchlist::buildTools(
514 $this->getLanguage(),
515 $this->getLinkRenderer()
516 ) )
517 );
518
519 $this->setTopText( $opts );
520
521 $lang = $this->getLanguage();
522 if ( $opts['days'] > 0 ) {
523 $days = $opts['days'];
524 } else {
525 $days = $this->maxDays;
526 }
527 $timestamp = wfTimestampNow();
528 $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
529 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
530 )->parse() . "<br />\n";
531
532 $nondefaults = $opts->getChangedValues();
533 $cutofflinks = $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts );
534
535 # Spit out some control panel links
536 $links = [];
537 $context = $this->getContext();
538 $namesOfDisplayedFilters = [];
539 foreach ( $this->getFilterGroups() as $groupName => $group ) {
540 if ( !$group->isPerGroupRequestParameter() ) {
541 foreach ( $group->getFilters() as $filterName => $filter ) {
542 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
543 $namesOfDisplayedFilters[] = $filterName;
544 $links[] = $this->showHideCheck(
545 $nondefaults,
546 $filter->getShowHide(),
547 $filterName,
548 $opts[$filterName]
549 );
550 }
551 }
552 }
553 }
554
555 $hiddenFields = $nondefaults;
556 $hiddenFields['action'] = 'submit';
557 unset( $hiddenFields['namespace'] );
558 unset( $hiddenFields['invert'] );
559 unset( $hiddenFields['associated'] );
560 unset( $hiddenFields['days'] );
561 foreach ( $namesOfDisplayedFilters as $filterName ) {
562 unset( $hiddenFields[$filterName] );
563 }
564
565 # Create output
566 $form = '';
567
568 # Namespace filter and put the whole form together.
569 $form .= $wlInfo;
570 $form .= $cutofflinks;
571 $form .= $this->msg( 'watchlist-hide' ) .
572 $this->msg( 'colon-separator' )->escaped() .
573 implode( ' ', $links );
574 $form .= "\n<br />\n";
575 $form .= Html::namespaceSelector(
576 [
577 'selected' => $opts['namespace'],
578 'all' => '',
579 'label' => $this->msg( 'namespace' )->text()
580 ], [
581 'name' => 'namespace',
582 'id' => 'namespace',
583 'class' => 'namespaceselector',
584 ]
585 ) . "\n";
586 $form .= '<span class="mw-input-with-label">' . Xml::checkLabel(
587 $this->msg( 'invert' )->text(),
588 'invert',
589 'nsinvert',
590 $opts['invert'],
591 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
592 ) . "</span>\n";
593 $form .= '<span class="mw-input-with-label">' . Xml::checkLabel(
594 $this->msg( 'namespace_association' )->text(),
595 'associated',
596 'nsassociated',
597 $opts['associated'],
598 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
599 ) . "</span>\n";
600 $form .= Xml::submitButton( $this->msg( 'watchlist-submit' )->text() ) . "\n";
601 foreach ( $hiddenFields as $key => $value ) {
602 $form .= Html::hidden( $key, $value ) . "\n";
603 }
604 $form .= Xml::closeElement( 'fieldset' ) . "\n";
605 $form .= Xml::closeElement( 'form' ) . "\n";
606 $this->getOutput()->addHTML( $form );
607
608 $this->setBottomText( $opts );
609 }
610
611 function cutoffselector( $options ) {
612 // Cast everything to strings immediately, so that we know all of the values have the same
613 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
614 // default string representation, for example, and would confuse comparisons.
615
616 // Misleadingly, the 'days' option supports hours too.
617 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
618
619 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
620 // add the user preference, if it isn't available already
621 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
622 $days[] = $userWatchlistOption;
623 }
624
625 $maxDays = (string)$this->maxDays;
626 // add the maximum possible value, if it isn't available already
627 if ( !in_array( $maxDays, $days ) ) {
628 $days[] = $maxDays;
629 }
630
631 $selected = (string)$options['days'];
632 if ( $selected <= 0 ) {
633 $selected = $maxDays;
634 }
635
636 // add the currently selected value, if it isn't available already
637 if ( !in_array( $selected, $days ) ) {
638 $days[] = $selected;
639 }
640
641 $select = new XmlSelect( 'days', 'days', $selected );
642
643 asort( $days );
644 foreach ( $days as $value ) {
645 if ( $value < 1 ) {
646 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
647 } else {
648 $name = $this->msg( 'days' )->numParams( $value )->text();
649 }
650 $select->addOption( $name, $value );
651 }
652
653 return $select->getHTML() . "\n<br />\n";
654 }
655
656 function setTopText( FormOptions $opts ) {
657 $nondefaults = $opts->getChangedValues();
658 $form = "";
659 $user = $this->getUser();
660
661 $numItems = $this->countItems();
662 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
663
664 // Show watchlist header
665 $form .= "<p>";
666 if ( $numItems == 0 ) {
667 $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
668 } else {
669 $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
670 if ( $this->getConfig()->get( 'EnotifWatchlist' )
671 && $user->getOption( 'enotifwatchlistpages' )
672 ) {
673 $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
674 }
675 if ( $showUpdatedMarker ) {
676 $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
677 }
678 }
679 $form .= "</p>";
680
681 if ( $numItems > 0 && $showUpdatedMarker ) {
682 $form .= Xml::openElement( 'form', [ 'method' => 'post',
683 'action' => $this->getPageTitle()->getLocalURL(),
684 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
685 Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
686 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
687 Html::hidden( 'token', $user->getEditToken() ) . "\n" .
688 Html::hidden( 'reset', 'all' ) . "\n";
689 foreach ( $nondefaults as $key => $value ) {
690 $form .= Html::hidden( $key, $value ) . "\n";
691 }
692 $form .= Xml::closeElement( 'form' ) . "\n";
693 }
694
695 $form .= Xml::openElement( 'form', [
696 'method' => 'get',
697 'action' => wfScript(),
698 'id' => 'mw-watchlist-form'
699 ] );
700 $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
701 $form .= Xml::fieldset(
702 $this->msg( 'watchlist-options' )->text(),
703 false,
704 [ 'id' => 'mw-watchlist-options' ]
705 );
706
707 $form .= $this->makeLegend();
708
709 $this->getOutput()->addHTML( $form );
710 }
711
712 protected function showHideCheck( $options, $message, $name, $value ) {
713 $options[$name] = 1 - (int)$value;
714
715 return '<span class="mw-input-with-label">' . Xml::checkLabel(
716 $this->msg( $message, '' )->text(),
717 $name,
718 $name,
719 (int)$value
720 ) . '</span>';
721 }
722
723 /**
724 * Count the number of paired items on a user's watchlist.
725 * The assumption made here is that when a subject page is watched a talk page is also watched.
726 * Hence the number of individual items is halved.
727 *
728 * @return int
729 */
730 protected function countItems() {
731 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
732 $count = $store->countWatchedItems( $this->getUser() );
733 return floor( $count / 2 );
734 }
735 }