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