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