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