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