Merge "Use HTML::hidden to create input fields"
[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 $usePage = false;
281 } else {
282 # Top log Ids for a page are not stored
283 $nonRevisionTypes = [ RC_LOG ];
284 Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
285 if ( $nonRevisionTypes ) {
286 $conds[] = $dbr->makeList(
287 [
288 'rc_this_oldid=page_latest',
289 'rc_type' => $nonRevisionTypes,
290 ],
291 LIST_OR
292 );
293 }
294 $usePage = true;
295 }
296
297 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
298 $fields = array_merge( RecentChange::selectFields(), $fields );
299
300 $query_options = array_merge( [
301 'ORDER BY' => 'rc_timestamp DESC',
302 'LIMIT' => $user->getIntOption( 'wllimit' )
303 ], $query_options );
304 $join_conds = array_merge(
305 [
306 'watchlist' => [
307 'INNER JOIN',
308 [
309 'wl_user' => $user->getId(),
310 'wl_namespace=rc_namespace',
311 'wl_title=rc_title'
312 ],
313 ],
314 ],
315 $join_conds
316 );
317
318 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
319 $fields[] = 'wl_notificationtimestamp';
320 }
321
322 $rollbacker = $user->isAllowed( 'rollback' );
323 if ( $usePage || $rollbacker ) {
324 $tables[] = 'page';
325 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
326 if ( $rollbacker ) {
327 $fields[] = 'page_latest';
328 }
329 }
330
331 // Log entries with DELETED_ACTION must not show up unless the user has
332 // the necessary rights.
333 if ( !$user->isAllowed( 'deletedhistory' ) ) {
334 $bitmask = LogPage::DELETED_ACTION;
335 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
336 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
337 } else {
338 $bitmask = 0;
339 }
340 if ( $bitmask ) {
341 $conds[] = $dbr->makeList( [
342 'rc_type != ' . RC_LOG,
343 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
344 ], LIST_OR );
345 }
346
347 ChangeTags::modifyDisplayQuery(
348 $tables,
349 $fields,
350 $conds,
351 $join_conds,
352 $query_options,
353 ''
354 );
355
356 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
357
358 return $dbr->select(
359 $tables,
360 $fields,
361 $conds,
362 __METHOD__,
363 $query_options,
364 $join_conds
365 );
366 }
367
368 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
369 &$join_conds, $opts
370 ) {
371 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
372 && Hooks::run(
373 'SpecialWatchlistQuery',
374 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
375 '1.23'
376 );
377 }
378
379 /**
380 * Return a IDatabase object for reading
381 *
382 * @return IDatabase
383 */
384 protected function getDB() {
385 return wfGetDB( DB_REPLICA, 'watchlist' );
386 }
387
388 /**
389 * Output feed links.
390 */
391 public function outputFeedLinks() {
392 $user = $this->getUser();
393 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
394 if ( $wlToken ) {
395 $this->addFeedLinks( [
396 'action' => 'feedwatchlist',
397 'allrev' => 1,
398 'wlowner' => $user->getName(),
399 'wltoken' => $wlToken,
400 ] );
401 }
402 }
403
404 /**
405 * Build and output the actual changes list.
406 *
407 * @param ResultWrapper $rows Database rows
408 * @param FormOptions $opts
409 */
410 public function outputChangesList( $rows, $opts ) {
411 $dbr = $this->getDB();
412 $user = $this->getUser();
413 $output = $this->getOutput();
414
415 # Show a message about replica DB lag, if applicable
416 $lag = wfGetLB()->safeGetLag( $dbr );
417 if ( $lag > 0 ) {
418 $output->showLagWarning( $lag );
419 }
420
421 # If no rows to display, show message before try to render the list
422 if ( $rows->numRows() == 0 ) {
423 $output->wrapWikiMsg(
424 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
425 );
426 return;
427 }
428
429 $dbr->dataSeek( $rows, 0 );
430
431 $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
432 $list->setWatchlistDivs();
433 $list->initChangesListRows( $rows );
434 $dbr->dataSeek( $rows, 0 );
435
436 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
437 && $user->getOption( 'shownumberswatching' )
438 ) {
439 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
440 }
441
442 $s = $list->beginRecentChangesList();
443 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
444 $counter = 1;
445 foreach ( $rows as $obj ) {
446 # Make RC entry
447 $rc = RecentChange::newFromRow( $obj );
448
449 # Skip CatWatch entries for hidden cats based on user preference
450 if (
451 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
452 !$userShowHiddenCats &&
453 $rc->getParam( 'hidden-cat' )
454 ) {
455 continue;
456 }
457
458 $rc->counter = $counter++;
459
460 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
461 $updated = $obj->wl_notificationtimestamp;
462 } else {
463 $updated = false;
464 }
465
466 if ( isset( $watchedItemStore ) ) {
467 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
468 $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
469 } else {
470 $rc->numberofWatchingusers = 0;
471 }
472
473 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
474 if ( $changeLine !== false ) {
475 $s .= $changeLine;
476 }
477 }
478 $s .= $list->endRecentChangesList();
479
480 $output->addHTML( $s );
481 }
482
483 /**
484 * Set the text to be displayed above the changes
485 *
486 * @param FormOptions $opts
487 * @param int $numRows Number of rows in the result to show after this header
488 */
489 public function doHeader( $opts, $numRows ) {
490 $user = $this->getUser();
491 $out = $this->getOutput();
492
493 $out->addSubtitle(
494 $this->msg( 'watchlistfor2', $user->getName() )
495 ->rawParams( SpecialEditWatchlist::buildTools(
496 $this->getLanguage(),
497 $this->getLinkRenderer()
498 ) )
499 );
500
501 $this->setTopText( $opts );
502
503 $lang = $this->getLanguage();
504 if ( $opts['days'] > 0 ) {
505 $days = $opts['days'];
506 } else {
507 $days = $this->maxDays;
508 }
509 $timestamp = wfTimestampNow();
510 $wlInfo = $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
511 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
512 )->parse() . "<br />\n";
513
514 $nondefaults = $opts->getChangedValues();
515 $cutofflinks = $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts );
516
517 # Spit out some control panel links
518 $links = [];
519 $context = $this->getContext();
520 $namesOfDisplayedFilters = [];
521 foreach ( $this->getFilterGroups() as $groupName => $group ) {
522 if ( !$group->isPerGroupRequestParameter() ) {
523 foreach ( $group->getFilters() as $filterName => $filter ) {
524 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
525 $namesOfDisplayedFilters[] = $filterName;
526 $links[] = $this->showHideCheck(
527 $nondefaults,
528 $filter->getShowHide(),
529 $filterName,
530 $opts[$filterName]
531 );
532 }
533 }
534 }
535 }
536
537 $hiddenFields = $nondefaults;
538 $hiddenFields['action'] = 'submit';
539 unset( $hiddenFields['namespace'] );
540 unset( $hiddenFields['invert'] );
541 unset( $hiddenFields['associated'] );
542 unset( $hiddenFields['days'] );
543 foreach ( $namesOfDisplayedFilters as $filterName ) {
544 unset( $hiddenFields[$filterName] );
545 }
546
547 # Create output
548 $form = '';
549
550 # Namespace filter and put the whole form together.
551 $form .= $wlInfo;
552 $form .= $cutofflinks;
553 $form .= $this->msg( 'watchlist-hide' ) .
554 $this->msg( 'colon-separator' )->escaped() .
555 implode( ' ', $links );
556 $form .= "\n<br />\n";
557 $form .= Html::namespaceSelector(
558 [
559 'selected' => $opts['namespace'],
560 'all' => '',
561 'label' => $this->msg( 'namespace' )->text()
562 ], [
563 'name' => 'namespace',
564 'id' => 'namespace',
565 'class' => 'namespaceselector',
566 ]
567 ) . "\n";
568 $form .= '<span class="mw-input-with-label">' . Xml::checkLabel(
569 $this->msg( 'invert' )->text(),
570 'invert',
571 'nsinvert',
572 $opts['invert'],
573 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
574 ) . "</span>\n";
575 $form .= '<span class="mw-input-with-label">' . Xml::checkLabel(
576 $this->msg( 'namespace_association' )->text(),
577 'associated',
578 'nsassociated',
579 $opts['associated'],
580 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
581 ) . "</span>\n";
582 $form .= Xml::submitButton( $this->msg( 'watchlist-submit' )->text() ) . "\n";
583 foreach ( $hiddenFields as $key => $value ) {
584 $form .= Html::hidden( $key, $value ) . "\n";
585 }
586 $form .= Xml::closeElement( 'fieldset' ) . "\n";
587 $form .= Xml::closeElement( 'form' ) . "\n";
588 $this->getOutput()->addHTML( $form );
589
590 $this->setBottomText( $opts );
591 }
592
593 function cutoffselector( $options ) {
594 // Cast everything to strings immediately, so that we know all of the values have the same
595 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
596 // default string representation, for example, and would confuse comparisons.
597
598 // Misleadingly, the 'days' option supports hours too.
599 $days = array_map( 'strval', [ 1/24, 2/24, 6/24, 12/24, 1, 3, 7 ] );
600
601 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
602 // add the user preference, if it isn't available already
603 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
604 $days[] = $userWatchlistOption;
605 }
606
607 $maxDays = (string)$this->maxDays;
608 // add the maximum possible value, if it isn't available already
609 if ( !in_array( $maxDays, $days ) ) {
610 $days[] = $maxDays;
611 }
612
613 $selected = (string)$options['days'];
614 if ( $selected <= 0 ) {
615 $selected = $maxDays;
616 }
617
618 // add the currently selected value, if it isn't available already
619 if ( !in_array( $selected, $days ) ) {
620 $days[] = $selected;
621 }
622
623 $select = new XmlSelect( 'days', 'days', $selected );
624
625 asort( $days );
626 foreach ( $days as $value ) {
627 if ( $value < 1 ) {
628 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
629 } else {
630 $name = $this->msg( 'days' )->numParams( $value )->text();
631 }
632 $select->addOption( $name, $value );
633 }
634
635 return $select->getHTML() . "\n<br />\n";
636 }
637
638 function setTopText( FormOptions $opts ) {
639 $nondefaults = $opts->getChangedValues();
640 $form = "";
641 $user = $this->getUser();
642
643 $numItems = $this->countItems();
644 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
645
646 // Show watchlist header
647 $form .= "<p>";
648 if ( $numItems == 0 ) {
649 $form .= $this->msg( 'nowatchlist' )->parse() . "\n";
650 } else {
651 $form .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
652 if ( $this->getConfig()->get( 'EnotifWatchlist' )
653 && $user->getOption( 'enotifwatchlistpages' )
654 ) {
655 $form .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
656 }
657 if ( $showUpdatedMarker ) {
658 $form .= $this->msg( 'wlheader-showupdated' )->parse() . "\n";
659 }
660 }
661 $form .= "</p>";
662
663 if ( $numItems > 0 && $showUpdatedMarker ) {
664 $form .= Xml::openElement( 'form', [ 'method' => 'post',
665 'action' => $this->getPageTitle()->getLocalURL(),
666 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
667 Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
668 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
669 Html::hidden( 'token', $user->getEditToken() ) . "\n" .
670 Html::hidden( 'reset', 'all' ) . "\n";
671 foreach ( $nondefaults as $key => $value ) {
672 $form .= Html::hidden( $key, $value ) . "\n";
673 }
674 $form .= Xml::closeElement( 'form' ) . "\n";
675 }
676
677 $form .= Xml::openElement( 'form', [
678 'method' => 'get',
679 'action' => wfScript(),
680 'id' => 'mw-watchlist-form'
681 ] );
682 $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
683 $form .= Xml::fieldset(
684 $this->msg( 'watchlist-options' )->text(),
685 false,
686 [ 'id' => 'mw-watchlist-options' ]
687 );
688
689 $form .= $this->makeLegend();
690
691 $this->getOutput()->addHTML( $form );
692 }
693
694 protected function showHideCheck( $options, $message, $name, $value ) {
695 $options[$name] = 1 - (int)$value;
696
697 return '<span class="mw-input-with-label">' . Xml::checkLabel(
698 $this->msg( $message, '' )->text(),
699 $name,
700 $name,
701 (int)$value
702 ) . '</span>';
703 }
704
705 /**
706 * Count the number of paired items on a user's watchlist.
707 * The assumption made here is that when a subject page is watched a talk page is also watched.
708 * Hence the number of individual items is halved.
709 *
710 * @return int
711 */
712 protected function countItems() {
713 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
714 $count = $store->countWatchedItems( $this->getUser() );
715 return floor( $count / 2 );
716 }
717 }