Merge "Use pseudo elements to style changelist-separators on Contributions"
[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\IResultWrapper;
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 protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
36 protected static $daysPreferenceName = 'watchlistdays';
37 protected static $limitPreferenceName = 'wllimit';
38 protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
39
40 private $maxDays;
41
42 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
43 parent::__construct( $page, $restriction );
44
45 $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
46 }
47
48 public function doesWrites() {
49 return true;
50 }
51
52 /**
53 * Main execution point
54 *
55 * @param string $subpage
56 */
57 function execute( $subpage ) {
58 // Anons don't get a watchlist
59 $this->requireLogin( 'watchlistanontext' );
60
61 $output = $this->getOutput();
62 $request = $this->getRequest();
63 $this->addHelpLink( 'Help:Watching pages' );
64 $output->addModuleStyles( [ 'mediawiki.special' ] );
65 $output->addModules( [
66 'mediawiki.special.watchlist',
67 ] );
68
69 $mode = SpecialEditWatchlist::getMode( $request, $subpage );
70 if ( $mode !== false ) {
71 if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
72 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
73 } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
74 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
75 } else {
76 $title = SpecialPage::getTitleFor( 'EditWatchlist' );
77 }
78
79 $output->redirect( $title->getLocalURL() );
80
81 return;
82 }
83
84 $this->checkPermissions();
85
86 $user = $this->getUser();
87 $opts = $this->getOptions();
88
89 $config = $this->getConfig();
90 if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
91 && $request->getVal( 'reset' )
92 && $request->wasPosted()
93 && $user->matchEditToken( $request->getVal( 'token' ) )
94 ) {
95 $user->clearAllNotifications();
96 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
97
98 return;
99 }
100
101 parent::execute( $subpage );
102
103 if ( $this->isStructuredFilterUiEnabled() ) {
104 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
105
106 $output->addJsConfigVars(
107 'wgStructuredChangeFiltersEditWatchlistUrl',
108 SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
109 );
110 }
111 }
112
113 public static function checkStructuredFilterUiEnabled( Config $config, User $user ) {
114 return !$user->getOption( 'wlenhancedfilters-disable' );
115 }
116
117 /**
118 * Return an array of subpages that this special page will accept.
119 *
120 * @see also SpecialEditWatchlist::getSubpagesForPrefixSearch
121 * @return string[] subpages
122 */
123 public function getSubpagesForPrefixSearch() {
124 return [
125 'clear',
126 'edit',
127 'raw',
128 ];
129 }
130
131 /**
132 * @inheritDoc
133 */
134 protected function transformFilterDefinition( array $filterDefinition ) {
135 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
136 $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
137 }
138
139 return $filterDefinition;
140 }
141
142 /**
143 * @inheritDoc
144 */
145 protected function registerFilters() {
146 parent::registerFilters();
147
148 // legacy 'extended' filter
149 $this->registerFilterGroup( new ChangesListBooleanFilterGroup( [
150 'name' => 'extended-group',
151 'filters' => [
152 [
153 'name' => 'extended',
154 'isReplacedInStructuredUi' => true,
155 'activeValue' => false,
156 'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
157 'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
158 &$fields, &$conds, &$query_options, &$join_conds ) {
159 $nonRevisionTypes = [ RC_LOG ];
160 Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
161 if ( $nonRevisionTypes ) {
162 $conds[] = $dbr->makeList(
163 [
164 'rc_this_oldid=page_latest',
165 'rc_type' => $nonRevisionTypes,
166 ],
167 LIST_OR
168 );
169 }
170 },
171 ]
172 ],
173
174 ] ) );
175
176 if ( $this->isStructuredFilterUiEnabled() ) {
177 $this->getFilterGroup( 'lastRevision' )
178 ->getFilter( 'hidepreviousrevisions' )
179 ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
180 }
181
182 $this->registerFilterGroup( new ChangesListStringOptionsFilterGroup( [
183 'name' => 'watchlistactivity',
184 'title' => 'rcfilters-filtergroup-watchlistactivity',
185 'class' => ChangesListStringOptionsFilterGroup::class,
186 'priority' => 3,
187 'isFullCoverage' => true,
188 'filters' => [
189 [
190 'name' => 'unseen',
191 'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
192 'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
193 'cssClassSuffix' => 'watchedunseen',
194 'isRowApplicableCallable' => function ( $ctx, $rc ) {
195 $changeTs = $rc->getAttribute( 'rc_timestamp' );
196 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
197 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
198 },
199 ],
200 [
201 'name' => 'seen',
202 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
203 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
204 'cssClassSuffix' => 'watchedseen',
205 'isRowApplicableCallable' => function ( $ctx, $rc ) {
206 $changeTs = $rc->getAttribute( 'rc_timestamp' );
207 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
208 return $lastVisitTs === null || $changeTs < $lastVisitTs;
209 }
210 ],
211 ],
212 'default' => ChangesListStringOptionsFilterGroup::NONE,
213 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
214 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
215 if ( $selectedValues === [ 'seen' ] ) {
216 $conds[] = $dbr->makeList( [
217 'wl_notificationtimestamp IS NULL',
218 'rc_timestamp < wl_notificationtimestamp'
219 ], LIST_OR );
220 } elseif ( $selectedValues === [ 'unseen' ] ) {
221 $conds[] = $dbr->makeList( [
222 'wl_notificationtimestamp IS NOT NULL',
223 'rc_timestamp >= wl_notificationtimestamp'
224 ], LIST_AND );
225 }
226 }
227 ] ) );
228
229 $user = $this->getUser();
230
231 $significance = $this->getFilterGroup( 'significance' );
232 $hideMinor = $significance->getFilter( 'hideminor' );
233 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
234
235 $automated = $this->getFilterGroup( 'automated' );
236 $hideBots = $automated->getFilter( 'hidebots' );
237 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
238
239 $registration = $this->getFilterGroup( 'registration' );
240 $hideAnons = $registration->getFilter( 'hideanons' );
241 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
242 $hideLiu = $registration->getFilter( 'hideliu' );
243 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
244
245 // Selecting both hideanons and hideliu on watchlist preferances
246 // gives mutually exclusive filters, so those are ignored
247 if ( $user->getBoolOption( 'watchlisthideanons' ) &&
248 !$user->getBoolOption( 'watchlisthideliu' )
249 ) {
250 $this->getFilterGroup( 'userExpLevel' )
251 ->setDefault( 'registered' );
252 }
253
254 if ( $user->getBoolOption( 'watchlisthideliu' ) &&
255 !$user->getBoolOption( 'watchlisthideanons' )
256 ) {
257 $this->getFilterGroup( 'userExpLevel' )
258 ->setDefault( 'unregistered' );
259 }
260
261 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
262 if ( $reviewStatus !== null ) {
263 // Conditional on feature being available and rights
264 if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
265 $reviewStatus->setDefault( 'unpatrolled' );
266 $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
267 $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
268 $legacyHidePatrolled->setDefault( true );
269 }
270 }
271
272 $authorship = $this->getFilterGroup( 'authorship' );
273 $hideMyself = $authorship->getFilter( 'hidemyself' );
274 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
275
276 $changeType = $this->getFilterGroup( 'changeType' );
277 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
278 if ( $hideCategorization !== null ) {
279 // Conditional on feature being available
280 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
281 }
282 }
283
284 /**
285 * Fetch values for a FormOptions object from the WebRequest associated with this instance.
286 *
287 * Maps old pre-1.23 request parameters Watchlist used to use (different from Recentchanges' ones)
288 * to the current ones.
289 *
290 * @param FormOptions $opts
291 * @return FormOptions
292 */
293 protected function fetchOptionsFromRequest( $opts ) {
294 static $compatibilityMap = [
295 'hideMinor' => 'hideminor',
296 'hideBots' => 'hidebots',
297 'hideAnons' => 'hideanons',
298 'hideLiu' => 'hideliu',
299 'hidePatrolled' => 'hidepatrolled',
300 'hideOwn' => 'hidemyself',
301 ];
302
303 $params = $this->getRequest()->getValues();
304 foreach ( $compatibilityMap as $from => $to ) {
305 if ( isset( $params[$from] ) ) {
306 $params[$to] = $params[$from];
307 unset( $params[$from] );
308 }
309 }
310
311 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
312 $allBooleansFalse = [];
313
314 // If the user submitted the form, start with a baseline of "all
315 // booleans are false", then change the ones they checked. This
316 // means we ignore the defaults.
317
318 // This is how we handle the fact that HTML forms don't submit
319 // unchecked boxes.
320 foreach ( $this->getLegacyShowHideFilters() as $filter ) {
321 $allBooleansFalse[ $filter->getName() ] = false;
322 }
323
324 $params = $params + $allBooleansFalse;
325 }
326
327 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
328 // methods defined on WebRequest and removing this dependency would cause some code duplication.
329 $request = new DerivativeRequest( $this->getRequest(), $params );
330 $opts->fetchValuesFromRequest( $request );
331
332 return $opts;
333 }
334
335 /**
336 * @inheritDoc
337 */
338 protected function doMainQuery( $tables, $fields, $conds, $query_options,
339 $join_conds, FormOptions $opts
340 ) {
341 $dbr = $this->getDB();
342 $user = $this->getUser();
343
344 $rcQuery = RecentChange::getQueryInfo();
345 $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
346 $fields = array_merge( $rcQuery['fields'], $fields );
347
348 $join_conds = array_merge(
349 [
350 'watchlist' => [
351 'INNER JOIN',
352 [
353 'wl_user' => $user->getId(),
354 'wl_namespace=rc_namespace',
355 'wl_title=rc_title'
356 ],
357 ],
358 ],
359 $rcQuery['joins'],
360 $join_conds
361 );
362
363 $tables[] = 'page';
364 $fields[] = 'page_latest';
365 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
366
367 $fields[] = 'wl_notificationtimestamp';
368
369 // Log entries with DELETED_ACTION must not show up unless the user has
370 // the necessary rights.
371 if ( !$user->isAllowed( 'deletedhistory' ) ) {
372 $bitmask = LogPage::DELETED_ACTION;
373 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
374 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
375 } else {
376 $bitmask = 0;
377 }
378 if ( $bitmask ) {
379 $conds[] = $dbr->makeList( [
380 'rc_type != ' . RC_LOG,
381 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
382 ], LIST_OR );
383 }
384
385 $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
386 ChangeTags::modifyDisplayQuery(
387 $tables,
388 $fields,
389 $conds,
390 $join_conds,
391 $query_options,
392 $tagFilter
393 );
394
395 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
396
397 if ( $this->areFiltersInConflict() ) {
398 return false;
399 }
400
401 $orderByAndLimit = [
402 'ORDER BY' => 'rc_timestamp DESC',
403 'LIMIT' => $opts['limit']
404 ];
405 if ( in_array( 'DISTINCT', $query_options ) ) {
406 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
407 // In order to prevent DISTINCT from causing query performance problems,
408 // we have to GROUP BY the primary key. This in turn requires us to add
409 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
410 // start of the GROUP BY
411 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
412 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
413 }
414 // array_merge() is used intentionally here so that hooks can, should
415 // they so desire, override the ORDER BY / LIMIT condition(s)
416 $query_options = array_merge( $orderByAndLimit, $query_options );
417
418 return $dbr->select(
419 $tables,
420 $fields,
421 $conds,
422 __METHOD__,
423 $query_options,
424 $join_conds
425 );
426 }
427
428 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
429 &$join_conds, $opts
430 ) {
431 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
432 && Hooks::run(
433 'SpecialWatchlistQuery',
434 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
435 '1.23'
436 );
437 }
438
439 /**
440 * Return a IDatabase object for reading
441 *
442 * @return IDatabase
443 */
444 protected function getDB() {
445 return wfGetDB( DB_REPLICA, 'watchlist' );
446 }
447
448 /**
449 * Output feed links.
450 */
451 public function outputFeedLinks() {
452 $user = $this->getUser();
453 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
454 if ( $wlToken ) {
455 $this->addFeedLinks( [
456 'action' => 'feedwatchlist',
457 'allrev' => 1,
458 'wlowner' => $user->getName(),
459 'wltoken' => $wlToken,
460 ] );
461 }
462 }
463
464 /**
465 * Build and output the actual changes list.
466 *
467 * @param IResultWrapper $rows Database rows
468 * @param FormOptions $opts
469 */
470 public function outputChangesList( $rows, $opts ) {
471 $dbr = $this->getDB();
472 $user = $this->getUser();
473 $output = $this->getOutput();
474 $services = MediaWikiServices::getInstance();
475
476 # Show a message about replica DB lag, if applicable
477 $lag = $services->getDBLoadBalancer()->safeGetLag( $dbr );
478 if ( $lag > 0 ) {
479 $output->showLagWarning( $lag );
480 }
481
482 # If no rows to display, show message before try to render the list
483 if ( $rows->numRows() == 0 ) {
484 $output->wrapWikiMsg(
485 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
486 );
487 return;
488 }
489
490 $dbr->dataSeek( $rows, 0 );
491
492 $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
493 $list->setWatchlistDivs();
494 $list->initChangesListRows( $rows );
495 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
496 $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
497 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
498 // since EnhancedChangesList groups log entries by performer rather than by target article
499 if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
500 $grouped ) {
501 return '';
502 } else {
503 return $this->getLinkRenderer()
504 ->makeKnownLink( $rc->getTitle(),
505 $this->msg( 'watchlist-unwatch' )->text(), [
506 'class' => 'mw-unwatch-link',
507 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
508 ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
509 }
510 } );
511 }
512 $dbr->dataSeek( $rows, 0 );
513
514 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
515 && $user->getOption( 'shownumberswatching' )
516 ) {
517 $watchedItemStore = $services->getWatchedItemStore();
518 }
519
520 $s = $list->beginRecentChangesList();
521
522 if ( $this->isStructuredFilterUiEnabled() ) {
523 $s .= $this->makeLegend();
524 }
525
526 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
527 $counter = 1;
528 foreach ( $rows as $obj ) {
529 # Make RC entry
530 $rc = RecentChange::newFromRow( $obj );
531
532 # Skip CatWatch entries for hidden cats based on user preference
533 if (
534 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
535 !$userShowHiddenCats &&
536 $rc->getParam( 'hidden-cat' )
537 ) {
538 continue;
539 }
540
541 $rc->counter = $counter++;
542
543 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
544 $updated = $obj->wl_notificationtimestamp;
545 } else {
546 $updated = false;
547 }
548
549 if ( isset( $watchedItemStore ) ) {
550 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
551 $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
552 } else {
553 $rc->numberofWatchingusers = 0;
554 }
555
556 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
557 if ( $changeLine !== false ) {
558 $s .= $changeLine;
559 }
560 }
561 $s .= $list->endRecentChangesList();
562
563 $output->addHTML( $s );
564 }
565
566 /**
567 * Set the text to be displayed above the changes
568 *
569 * @param FormOptions $opts
570 * @param int $numRows Number of rows in the result to show after this header
571 */
572 public function doHeader( $opts, $numRows ) {
573 $user = $this->getUser();
574 $out = $this->getOutput();
575
576 $out->addSubtitle(
577 $this->msg( 'watchlistfor2', $user->getName() )
578 ->rawParams( SpecialEditWatchlist::buildTools(
579 $this->getLanguage(),
580 $this->getLinkRenderer()
581 ) )
582 );
583
584 $this->setTopText( $opts );
585
586 $form = '';
587
588 $form .= Xml::openElement( 'form', [
589 'method' => 'get',
590 'action' => wfScript(),
591 'id' => 'mw-watchlist-form'
592 ] );
593 $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
594 $form .= Xml::openElement(
595 'fieldset',
596 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
597 );
598 $form .= Xml::element(
599 'legend', null, $this->msg( 'watchlist-options' )->text()
600 );
601
602 if ( !$this->isStructuredFilterUiEnabled() ) {
603 $form .= $this->makeLegend();
604 }
605
606 $lang = $this->getLanguage();
607 $timestamp = wfTimestampNow();
608 $wlInfo = Html::rawElement(
609 'span',
610 [
611 'class' => 'wlinfo',
612 'data-params' => json_encode( [ 'from' => $timestamp ] ),
613 ],
614 $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
615 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
616 )->parse()
617 ) . "<br />\n";
618
619 $nondefaults = $opts->getChangedValues();
620 $cutofflinks = Html::rawElement(
621 'span',
622 [ 'class' => 'cldays cloption' ],
623 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
624 );
625
626 # Spit out some control panel links
627 $links = [];
628 $namesOfDisplayedFilters = [];
629 foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
630 $namesOfDisplayedFilters[] = $filterName;
631 $links[] = $this->showHideCheck(
632 $nondefaults,
633 $filter->getShowHide(),
634 $filterName,
635 $opts[ $filterName ],
636 $filter->isFeatureAvailableOnStructuredUi( $this )
637 );
638 }
639
640 $hiddenFields = $nondefaults;
641 $hiddenFields['action'] = 'submit';
642 unset( $hiddenFields['namespace'] );
643 unset( $hiddenFields['invert'] );
644 unset( $hiddenFields['associated'] );
645 unset( $hiddenFields['days'] );
646 foreach ( $namesOfDisplayedFilters as $filterName ) {
647 unset( $hiddenFields[$filterName] );
648 }
649
650 # Namespace filter and put the whole form together.
651 $form .= $wlInfo;
652 $form .= $cutofflinks;
653 $form .= Html::rawElement(
654 'span',
655 [ 'class' => 'clshowhide' ],
656 $this->msg( 'watchlist-hide' ) .
657 $this->msg( 'colon-separator' )->escaped() .
658 implode( ' ', $links )
659 );
660 $form .= "\n<br />\n";
661
662 $namespaceForm = Html::namespaceSelector(
663 [
664 'selected' => $opts['namespace'],
665 'all' => '',
666 'label' => $this->msg( 'namespace' )->text()
667 ], [
668 'name' => 'namespace',
669 'id' => 'namespace',
670 'class' => 'namespaceselector',
671 ]
672 ) . "\n";
673 $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
674 $this->msg( 'invert' )->text(),
675 'invert',
676 'nsinvert',
677 $opts['invert'],
678 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
679 ) . "</span>\n";
680 $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
681 $this->msg( 'namespace_association' )->text(),
682 'associated',
683 'nsassociated',
684 $opts['associated'],
685 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
686 ) . "</span>\n";
687 $form .= Html::rawElement(
688 'span',
689 [ 'class' => 'namespaceForm cloption' ],
690 $namespaceForm
691 );
692
693 $form .= Xml::submitButton(
694 $this->msg( 'watchlist-submit' )->text(),
695 [ 'class' => 'cloption-submit' ]
696 ) . "\n";
697 foreach ( $hiddenFields as $key => $value ) {
698 $form .= Html::hidden( $key, $value ) . "\n";
699 }
700 $form .= Xml::closeElement( 'fieldset' ) . "\n";
701 $form .= Xml::closeElement( 'form' ) . "\n";
702
703 // Insert a placeholder for RCFilters
704 if ( $this->isStructuredFilterUiEnabled() ) {
705 $rcfilterContainer = Html::element(
706 'div',
707 [ 'class' => 'rcfilters-container' ]
708 );
709
710 $loadingContainer = Html::rawElement(
711 'div',
712 [ 'class' => 'rcfilters-spinner' ],
713 Html::element(
714 'div',
715 [ 'class' => 'rcfilters-spinner-bounce' ]
716 )
717 );
718
719 // Wrap both with rcfilters-head
720 $this->getOutput()->addHTML(
721 Html::rawElement(
722 'div',
723 [ 'class' => 'rcfilters-head' ],
724 $rcfilterContainer . $form
725 )
726 );
727
728 // Add spinner
729 $this->getOutput()->addHTML( $loadingContainer );
730 } else {
731 $this->getOutput()->addHTML( $form );
732 }
733
734 $this->setBottomText( $opts );
735 }
736
737 function cutoffselector( $options ) {
738 $selected = (float)$options['days'];
739 if ( $selected <= 0 ) {
740 $selected = $this->maxDays;
741 }
742
743 $selectedHours = round( $selected * 24 );
744
745 $hours = array_unique( array_filter( [
746 1,
747 2,
748 6,
749 12,
750 24,
751 72,
752 168,
753 24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
754 24 * $this->maxDays,
755 $selectedHours
756 ] ) );
757 asort( $hours );
758
759 $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
760
761 foreach ( $hours as $value ) {
762 if ( $value < 24 ) {
763 $name = $this->msg( 'hours' )->numParams( $value )->text();
764 } else {
765 $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
766 }
767 $select->addOption( $name, (float)( $value / 24 ) );
768 }
769
770 return $select->getHTML() . "\n<br />\n";
771 }
772
773 function setTopText( FormOptions $opts ) {
774 $nondefaults = $opts->getChangedValues();
775 $form = '';
776 $user = $this->getUser();
777
778 $numItems = $this->countItems();
779 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
780
781 // Show watchlist header
782 $watchlistHeader = '';
783 if ( $numItems == 0 ) {
784 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
785 } else {
786 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
787 if ( $this->getConfig()->get( 'EnotifWatchlist' )
788 && $user->getOption( 'enotifwatchlistpages' )
789 ) {
790 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
791 }
792 if ( $showUpdatedMarker ) {
793 $watchlistHeader .= $this->msg(
794 $this->isStructuredFilterUiEnabled() ?
795 'rcfilters-watchlist-showupdated' :
796 'wlheader-showupdated'
797 )->parse() . "\n";
798 }
799 }
800 $form .= Html::rawElement(
801 'div',
802 [ 'class' => 'watchlistDetails' ],
803 $watchlistHeader
804 );
805
806 if ( $numItems > 0 && $showUpdatedMarker ) {
807 $form .= Xml::openElement( 'form', [ 'method' => 'post',
808 'action' => $this->getPageTitle()->getLocalURL(),
809 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
810 Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
811 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
812 Html::hidden( 'token', $user->getEditToken() ) . "\n" .
813 Html::hidden( 'reset', 'all' ) . "\n";
814 foreach ( $nondefaults as $key => $value ) {
815 $form .= Html::hidden( $key, $value ) . "\n";
816 }
817 $form .= Xml::closeElement( 'form' ) . "\n";
818 }
819
820 $this->getOutput()->addHTML( $form );
821 }
822
823 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
824 $options[$name] = 1 - (int)$value;
825
826 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
827 if ( $inStructuredUi ) {
828 $attribs[ 'data-feature-in-structured-ui' ] = true;
829 }
830
831 return Html::rawElement(
832 'span',
833 $attribs,
834 // not using Html::checkLabel because that would escape the contents
835 Html::check( $name, (int)$value, [ 'id' => $name ] ) . Html::rawElement(
836 'label',
837 $attribs + [ 'for' => $name ],
838 // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
839 $this->msg( $message, '<nowiki/>' )->parse()
840 )
841 );
842 }
843
844 /**
845 * Count the number of paired items on a user's watchlist.
846 * The assumption made here is that when a subject page is watched a talk page is also watched.
847 * Hence the number of individual items is halved.
848 *
849 * @return int
850 */
851 protected function countItems() {
852 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
853 $count = $store->countWatchedItems( $this->getUser() );
854 return floor( $count / 2 );
855 }
856 }