MediaWiki  master
SpecialWatchlist.php
Go to the documentation of this file.
1 <?php
30 
38 
41 
44 
46  private $loadBalancer;
47 
50 
57  public function __construct(
62  ) {
63  parent::__construct( 'Watchlist', 'viewmywatchlist' );
64 
65  $this->watchedItemStore = $watchedItemStore;
66  $this->watchlistManager = $watchlistManager;
67  $this->loadBalancer = $loadBalancer;
68  $this->userOptionsLookup = $userOptionsLookup;
69  }
70 
71  public function doesWrites() {
72  return true;
73  }
74 
80  public function execute( $subpage ) {
81  // Anons don't get a watchlist
82  $this->requireLogin( 'watchlistanontext' );
83 
84  $output = $this->getOutput();
85  $request = $this->getRequest();
86  $this->addHelpLink( 'Help:Watching pages' );
87  $output->addModuleStyles( [ 'mediawiki.special' ] );
88  $output->addModules( [
89  'mediawiki.special.recentchanges',
90  'mediawiki.special.watchlist',
91  ] );
92 
93  $mode = SpecialEditWatchlist::getMode( $request, $subpage );
94  if ( $mode !== false ) {
95  if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
96  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
97  } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
98  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
99  } else {
100  $title = SpecialPage::getTitleFor( 'EditWatchlist' );
101  }
102 
103  $output->redirect( $title->getLocalURL() );
104 
105  return;
106  }
107 
108  $this->checkPermissions();
109 
110  $user = $this->getUser();
111  $opts = $this->getOptions();
112 
113  $config = $this->getConfig();
114  if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
115  && $request->getVal( 'reset' )
116  && $request->wasPosted()
117  && $user->matchEditToken( $request->getVal( 'token' ) )
118  ) {
119  $this->watchlistManager->clearAllUserNotifications( $user );
120  $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
121 
122  return;
123  }
124 
125  parent::execute( $subpage );
126 
127  if ( $this->isStructuredFilterUiEnabled() ) {
128  $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
129  }
130  }
131 
135  public static function checkStructuredFilterUiEnabled( $user ) {
136  if ( $user instanceof Config ) {
137  wfDeprecated( __METHOD__ . ' with Config argument', '1.34' );
138  $user = func_get_arg( 1 );
139  }
140  return !MediaWikiServices::getInstance()
141  ->getUserOptionsLookup()
142  ->getOption( $user, 'wlenhancedfilters-disable' );
143  }
144 
151  public function getSubpagesForPrefixSearch() {
152  return [
153  'clear',
154  'edit',
155  'raw',
156  ];
157  }
158 
162  protected function transformFilterDefinition( array $filterDefinition ) {
163  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
164  $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
165  }
166 
167  return $filterDefinition;
168  }
169 
174  protected function registerFilters() {
175  parent::registerFilters();
176 
177  // legacy 'extended' filter
179  'name' => 'extended-group',
180  'filters' => [
181  [
182  'name' => 'extended',
183  'isReplacedInStructuredUi' => true,
184  'activeValue' => false,
185  'default' => $this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ),
186  'queryCallable' => function ( string $specialClassName, IContextSource $ctx,
187  IDatabase $dbr, &$tables, &$fields, &$conds, &$query_options, &$join_conds
188  ) {
189  $nonRevisionTypes = [ RC_LOG ];
190  $this->getHookRunner()->onSpecialWatchlistGetNonRevisionTypes( $nonRevisionTypes );
191  if ( $nonRevisionTypes ) {
192  $conds[] = $dbr->makeList(
193  [
194  'rc_this_oldid=page_latest',
195  'rc_type' => $nonRevisionTypes,
196  ],
197  LIST_OR
198  );
199  }
200  },
201  ]
202  ],
203 
204  ] ) );
205 
206  if ( $this->isStructuredFilterUiEnabled() ) {
207  $this->getFilterGroup( 'lastRevision' )
208  ->getFilter( 'hidepreviousrevisions' )
209  ->setDefault( !$this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ) );
210  }
211 
213  'name' => 'watchlistactivity',
214  'title' => 'rcfilters-filtergroup-watchlistactivity',
215  'class' => ChangesListStringOptionsFilterGroup::class,
216  'priority' => 3,
217  'isFullCoverage' => true,
218  'filters' => [
219  [
220  'name' => 'unseen',
221  'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
222  'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
223  'cssClassSuffix' => 'watchedunseen',
224  'isRowApplicableCallable' => function ( IContextSource $ctx, RecentChange $rc ) {
225  return !$this->isChangeEffectivelySeen( $rc );
226  },
227  ],
228  [
229  'name' => 'seen',
230  'label' => 'rcfilters-filter-watchlistactivity-seen-label',
231  'description' => 'rcfilters-filter-watchlistactivity-seen-description',
232  'cssClassSuffix' => 'watchedseen',
233  'isRowApplicableCallable' => function ( IContextSource $ctx, RecentChange $rc ) {
234  return $this->isChangeEffectivelySeen( $rc );
235  }
236  ],
237  ],
239  'queryCallable' => static function (
240  string $specialPageClassName,
241  IContextSource $context,
242  IDatabase $dbr,
243  &$tables,
244  &$fields,
245  &$conds,
246  &$query_options,
247  &$join_conds,
248  $selectedValues
249  ) {
250  if ( $selectedValues === [ 'seen' ] ) {
251  $conds[] = $dbr->makeList( [
252  'wl_notificationtimestamp IS NULL',
253  'rc_timestamp < wl_notificationtimestamp'
254  ], LIST_OR );
255  } elseif ( $selectedValues === [ 'unseen' ] ) {
256  $conds[] = $dbr->makeList( [
257  'wl_notificationtimestamp IS NOT NULL',
258  'rc_timestamp >= wl_notificationtimestamp'
259  ], LIST_AND );
260  }
261  }
262  ] ) );
263 
264  $user = $this->getUser();
265 
266  $significance = $this->getFilterGroup( 'significance' );
267  $hideMinor = $significance->getFilter( 'hideminor' );
268  $hideMinor->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideminor' ) );
269 
270  $automated = $this->getFilterGroup( 'automated' );
271  $hideBots = $automated->getFilter( 'hidebots' );
272  $hideBots->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidebots' ) );
273 
274  $registration = $this->getFilterGroup( 'registration' );
275  $hideAnons = $registration->getFilter( 'hideanons' );
276  $hideAnons->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) );
277  $hideLiu = $registration->getFilter( 'hideliu' );
278  $hideLiu->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) );
279 
280  // Selecting both hideanons and hideliu on watchlist preferances
281  // gives mutually exclusive filters, so those are ignored
282  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) &&
283  !$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' )
284  ) {
285  $this->getFilterGroup( 'userExpLevel' )
286  ->setDefault( 'registered' );
287  }
288 
289  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) &&
290  !$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' )
291  ) {
292  $this->getFilterGroup( 'userExpLevel' )
293  ->setDefault( 'unregistered' );
294  }
295 
296  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
297  if ( $reviewStatus !== null ) {
298  // Conditional on feature being available and rights
299  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidepatrolled' ) ) {
300  $reviewStatus->setDefault( 'unpatrolled' );
301  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
302  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
303  $legacyHidePatrolled->setDefault( true );
304  }
305  }
306 
307  $authorship = $this->getFilterGroup( 'authorship' );
308  $hideMyself = $authorship->getFilter( 'hidemyself' );
309  $hideMyself->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideown' ) );
310 
311  $changeType = $this->getFilterGroup( 'changeType' );
312  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
313  if ( $hideCategorization !== null ) {
314  // Conditional on feature being available
315  $hideCategorization->setDefault(
316  $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidecategorization' )
317  );
318  }
319  }
320 
330  protected function fetchOptionsFromRequest( $opts ) {
331  static $compatibilityMap = [
332  'hideMinor' => 'hideminor',
333  'hideBots' => 'hidebots',
334  'hideAnons' => 'hideanons',
335  'hideLiu' => 'hideliu',
336  'hidePatrolled' => 'hidepatrolled',
337  'hideOwn' => 'hidemyself',
338  ];
339 
340  $params = $this->getRequest()->getValues();
341  foreach ( $compatibilityMap as $from => $to ) {
342  if ( isset( $params[$from] ) ) {
343  $params[$to] = $params[$from];
344  unset( $params[$from] );
345  }
346  }
347 
348  if ( $this->getRequest()->getRawVal( 'action' ) == 'submit' ) {
349  $allBooleansFalse = [];
350 
351  // If the user submitted the form, start with a baseline of "all
352  // booleans are false", then change the ones they checked. This
353  // means we ignore the defaults.
354 
355  // This is how we handle the fact that HTML forms don't submit
356  // unchecked boxes.
357  foreach ( $this->getLegacyShowHideFilters() as $filter ) {
358  $allBooleansFalse[ $filter->getName() ] = false;
359  }
360 
361  $params += $allBooleansFalse;
362  }
363 
364  // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
365  // methods defined on WebRequest and removing this dependency would cause some code duplication.
366  $request = new DerivativeRequest( $this->getRequest(), $params );
367  $opts->fetchValuesFromRequest( $request );
368 
369  return $opts;
370  }
371 
375  protected function doMainQuery( $tables, $fields, $conds, $query_options,
376  $join_conds, FormOptions $opts
377  ) {
378  $dbr = $this->getDB();
379  $user = $this->getUser();
380 
381  $rcQuery = RecentChange::getQueryInfo();
382  $tables = array_merge( $rcQuery['tables'], $tables, [ 'watchlist' ] );
383  $fields = array_merge( $rcQuery['fields'], $fields );
384 
385  $join_conds = array_merge(
386  [
387  'watchlist' => [
388  'JOIN',
389  [
390  'wl_user' => $user->getId(),
391  'wl_namespace=rc_namespace',
392  'wl_title=rc_title'
393  ],
394  ],
395  ],
396  $rcQuery['joins'],
397  $join_conds
398  );
399 
400  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
401  $tables[] = 'watchlist_expiry';
402  $fields[] = 'we_expiry';
403  $join_conds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ];
404  $conds[] = 'we_expiry IS NULL OR we_expiry > ' . $dbr->addQuotes( $dbr->timestamp() );
405  }
406 
407  $tables[] = 'page';
408  $fields[] = 'page_latest';
409  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
410 
411  $fields[] = 'wl_notificationtimestamp';
412 
413  // Log entries with DELETED_ACTION must not show up unless the user has
414  // the necessary rights.
415  $authority = $this->getAuthority();
416  if ( !$authority->isAllowed( 'deletedhistory' ) ) {
417  $bitmask = LogPage::DELETED_ACTION;
418  } elseif ( !$authority->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
420  } else {
421  $bitmask = 0;
422  }
423  if ( $bitmask ) {
424  $conds[] = $dbr->makeList( [
425  'rc_type != ' . RC_LOG,
426  $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
427  ], LIST_OR );
428  }
429 
430  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
432  $tables,
433  $fields,
434  $conds,
435  $join_conds,
436  $query_options,
437  $tagFilter
438  );
439 
440  $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
441 
442  if ( $this->areFiltersInConflict() ) {
443  return false;
444  }
445 
446  $orderByAndLimit = [
447  'ORDER BY' => 'rc_timestamp DESC',
448  'LIMIT' => $opts['limit']
449  ];
450  if ( in_array( 'DISTINCT', $query_options ) ) {
451  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
452  // In order to prevent DISTINCT from causing query performance problems,
453  // we have to GROUP BY the primary key. This in turn requires us to add
454  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
455  // start of the GROUP BY
456  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
457  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
458  }
459  // array_merge() is used intentionally here so that hooks can, should
460  // they so desire, override the ORDER BY / LIMIT condition(s)
461  $query_options = array_merge( $orderByAndLimit, $query_options );
462  $query_options['MAX_EXECUTION_TIME'] = $this->getConfig()->get( 'MaxExecutionTimeForExpensiveQueries' );
463 
464  return $dbr->select(
465  $tables,
466  $fields,
467  $conds,
468  __METHOD__,
469  $query_options,
470  $join_conds
471  );
472  }
473 
479  protected function getDB() {
480  return $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA, 'watchlist' );
481  }
482 
483  public function outputFeedLinks() {
484  $user = $this->getUser();
485  $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
486  if ( $wlToken ) {
487  $this->addFeedLinks( [
488  'action' => 'feedwatchlist',
489  'allrev' => 1,
490  'wlowner' => $user->getName(),
491  'wltoken' => $wlToken,
492  ] );
493  }
494  }
495 
502  public function outputChangesList( $rows, $opts ) {
503  $dbr = $this->getDB();
504  $user = $this->getUser();
505  $output = $this->getOutput();
506 
507  // Show a message about replica DB lag, if applicable
508  $lag = $dbr->getSessionLagStatus()['lag'];
509  if ( $lag > 0 ) {
510  $output->showLagWarning( $lag );
511  }
512 
513  // If there are no rows to display, show message before trying to render the list
514  if ( $rows->numRows() == 0 ) {
515  $output->wrapWikiMsg(
516  "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
517  );
518  return;
519  }
520 
521  $rows->seek( 0 );
522 
523  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
524  $list->setWatchlistDivs();
525  $list->initChangesListRows( $rows );
526 
527  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlistunwatchlinks' ) ) {
528  $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
529  $unwatch = $this->msg( 'watchlist-unwatch' )->text();
530  // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
531  // since EnhancedChangesList groups log entries by performer rather than by target article
532  if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
533  $grouped ) {
534  return "<span style='visibility:hidden'>$unwatch</span>\u{00A0}";
535  } else {
536  $unwatchTooltipMessage = 'tooltip-ca-unwatch';
537  $diffInDays = null;
538  // Check if the watchlist expiry flag is enabled to show new tooltip message
539  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
540  $watchedItem = $this->watchedItemStore->getWatchedItem( $this->getUser(), $rc->getTitle() );
541  if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
542  $diffInDays = $watchedItem->getExpiryInDays();
543 
544  if ( $diffInDays > 0 ) {
545  $unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring';
546  } else {
547  $unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring-hours';
548  }
549  }
550  }
551 
552  return $this->getLinkRenderer()
553  ->makeKnownLink( $rc->getTitle(),
554  $unwatch, [
555  'class' => 'mw-unwatch-link',
556  'title' => $this->msg( $unwatchTooltipMessage, [ $diffInDays ] )->text()
557  ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
558  }
559  } );
560  }
561  $rows->seek( 0 );
562 
563  $s = $list->beginRecentChangesList();
564 
565  if ( $this->isStructuredFilterUiEnabled() ) {
566  $s .= $this->makeLegend();
567  }
568 
569  $userShowHiddenCats = $this->userOptionsLookup->getBoolOption( $user, 'showhiddencats' );
570  $counter = 1;
571  foreach ( $rows as $obj ) {
572  // Make RC entry
573  $rc = RecentChange::newFromRow( $obj );
574 
575  // Skip CatWatch entries for hidden cats based on user preference
576  if (
577  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
578  !$userShowHiddenCats &&
579  $rc->getParam( 'hidden-cat' )
580  ) {
581  continue;
582  }
583 
584  $rc->counter = $counter++;
585 
586  if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
587  $unseen = !$this->isChangeEffectivelySeen( $rc );
588  } else {
589  $unseen = false;
590  }
591 
592  if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
593  && $this->userOptionsLookup->getBoolOption( $user, 'shownumberswatching' )
594  ) {
595  $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
596  $rc->numberofWatchingusers = $this->watchedItemStore->countWatchers( $rcTitleValue );
597  } else {
598  $rc->numberofWatchingusers = 0;
599  }
600 
601  // XXX: this treats pages with no unseen changes as "not on the watchlist" since
602  // everything is on the watchlist and it is an easy way to make pages with unseen
603  // changes appear bold. @TODO: clean this up.
604  $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
605  if ( $changeLine !== false ) {
606  $s .= $changeLine;
607  }
608  }
609  $s .= $list->endRecentChangesList();
610 
611  $output->addHTML( $s );
612  }
613 
620  public function doHeader( $opts, $numRows ) {
621  $user = $this->getUser();
622  $out = $this->getOutput();
623 
624  $out->addSubtitle(
625  $this->msg( 'watchlistfor2', $user->getName() )
627  $this->getLanguage(),
628  $this->getLinkRenderer()
629  ) )
630  );
631 
632  $this->setTopText( $opts );
633 
634  $form = '';
635 
636  $form .= Xml::openElement( 'form', [
637  'method' => 'get',
638  'action' => wfScript(),
639  'id' => 'mw-watchlist-form'
640  ] );
641  $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
642  $form .= Xml::openElement(
643  'fieldset',
644  [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
645  );
646  $form .= Xml::element(
647  'legend', null, $this->msg( 'watchlist-options' )->text()
648  );
649 
650  if ( !$this->isStructuredFilterUiEnabled() ) {
651  $form .= $this->makeLegend();
652  }
653 
654  $lang = $this->getLanguage();
655  $timestamp = wfTimestampNow();
656  $now = $lang->userTimeAndDate( $timestamp, $user );
657  $wlInfo = Html::rawElement(
658  'span',
659  [
660  'class' => 'wlinfo',
661  'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
662  ],
663  $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
664  $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
665  )->parse()
666  ) . "<br />\n";
667 
668  $nondefaults = $opts->getChangedValues();
669  $cutofflinks = Html::rawElement(
670  'span',
671  [ 'class' => 'cldays cloption' ],
672  $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
673  );
674 
675  // Spit out some control panel links
676  $links = [];
677  $namesOfDisplayedFilters = [];
678  foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
679  $namesOfDisplayedFilters[] = $filterName;
680  $links[] = $this->showHideCheck(
681  $nondefaults,
682  $filter->getShowHide(),
683  $filterName,
684  $opts[ $filterName ],
685  $filter->isFeatureAvailableOnStructuredUi()
686  );
687  }
688 
689  $hiddenFields = $nondefaults;
690  $hiddenFields['action'] = 'submit';
691  unset( $hiddenFields['namespace'] );
692  unset( $hiddenFields['invert'] );
693  unset( $hiddenFields['associated'] );
694  unset( $hiddenFields['days'] );
695  foreach ( $namesOfDisplayedFilters as $filterName ) {
696  unset( $hiddenFields[$filterName] );
697  }
698 
699  // Namespace filter and put the whole form together.
700  $form .= $wlInfo;
701  $form .= $cutofflinks;
702  $form .= Html::rawElement(
703  'span',
704  [ 'class' => 'clshowhide' ],
705  $this->msg( 'watchlist-hide' ) .
706  $this->msg( 'colon-separator' )->escaped() .
707  implode( ' ', $links )
708  );
709  $form .= "\n<br />\n";
710 
711  $namespaceForm = Html::namespaceSelector(
712  [
713  'selected' => $opts['namespace'],
714  'all' => '',
715  'label' => $this->msg( 'namespace' )->text(),
716  'in-user-lang' => true,
717  ], [
718  'name' => 'namespace',
719  'id' => 'namespace',
720  'class' => 'namespaceselector',
721  ]
722  ) . "\n";
723  $hidden = $opts['namespace'] === '' ? ' mw-input-hidden' : '';
724  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
725  $this->msg( 'invert' )->text(),
726  'invert',
727  'nsinvert',
728  $opts['invert'],
729  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
730  ) . "</span>\n";
731  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
732  $this->msg( 'namespace_association' )->text(),
733  'associated',
734  'nsassociated',
735  $opts['associated'],
736  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
737  ) . "</span>\n";
738  $form .= Html::rawElement(
739  'span',
740  [ 'class' => 'namespaceForm cloption' ],
741  $namespaceForm
742  );
743 
744  $form .= Xml::submitButton(
745  $this->msg( 'watchlist-submit' )->text(),
746  [ 'class' => 'cloption-submit' ]
747  ) . "\n";
748  foreach ( $hiddenFields as $key => $value ) {
749  $form .= Html::hidden( $key, $value ) . "\n";
750  }
751  $form .= Xml::closeElement( 'fieldset' ) . "\n";
752  $form .= Xml::closeElement( 'form' ) . "\n";
753 
754  // Insert a placeholder for RCFilters
755  if ( $this->isStructuredFilterUiEnabled() ) {
756  $rcfilterContainer = Html::element(
757  'div',
758  // TODO: Remove deprecated rcfilters-container class
759  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
760  );
761 
762  $loadingContainer = Html::rawElement(
763  'div',
764  [ 'class' => 'mw-rcfilters-spinner' ],
766  'div',
767  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
768  )
769  );
770 
771  // Wrap both with rcfilters-head
772  $this->getOutput()->addHTML(
774  'div',
775  // TODO: Remove deprecated rcfilters-head class
776  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
777  $rcfilterContainer . $form
778  )
779  );
780 
781  // Add spinner
782  $this->getOutput()->addHTML( $loadingContainer );
783  } else {
784  $this->getOutput()->addHTML( $form );
785  }
786 
787  $this->setBottomText( $opts );
788  }
789 
790  private function cutoffselector( $options ) {
791  $selected = (float)$options['days'];
792  $maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
793  if ( $selected <= 0 ) {
794  $selected = $maxDays;
795  }
796 
797  $selectedHours = round( $selected * 24 );
798 
799  $hours = array_unique( array_filter( [
800  1,
801  2,
802  6,
803  12,
804  24,
805  72,
806  168,
807  24 * (float)$this->userOptionsLookup->getOption( $this->getUser(), 'watchlistdays', 0 ),
808  24 * $maxDays,
809  $selectedHours
810  ] ) );
811  asort( $hours );
812 
813  $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
814 
815  foreach ( $hours as $value ) {
816  if ( $value < 24 ) {
817  $name = $this->msg( 'hours' )->numParams( $value )->text();
818  } else {
819  $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
820  }
821  $select->addOption( $name, (float)( $value / 24 ) );
822  }
823 
824  return $select->getHTML() . "\n<br />\n";
825  }
826 
827  public function setTopText( FormOptions $opts ) {
828  $nondefaults = $opts->getChangedValues();
829  $form = '';
830  $user = $this->getUser();
831 
832  $numItems = $this->countItems();
833  $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
834 
835  // Show watchlist header
836  $watchlistHeader = '';
837  if ( $numItems == 0 ) {
838  $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
839  } else {
840  $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
841  if ( $this->getConfig()->get( 'EnotifWatchlist' )
842  && $this->userOptionsLookup->getBoolOption( $user, 'enotifwatchlistpages' )
843  ) {
844  $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
845  }
846  if ( $showUpdatedMarker ) {
847  $watchlistHeader .= $this->msg(
848  $this->isStructuredFilterUiEnabled() ?
849  'rcfilters-watchlist-showupdated' :
850  'wlheader-showupdated'
851  )->parse() . "\n";
852  }
853  }
854  $form .= Html::rawElement(
855  'div',
856  [ 'class' => 'watchlistDetails' ],
857  $watchlistHeader
858  );
859 
860  if ( $numItems > 0 && $showUpdatedMarker ) {
861  $form .= Xml::openElement( 'form', [ 'method' => 'post',
862  'action' => $this->getPageTitle()->getLocalURL(),
863  'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
864  Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
865  [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
866  Html::hidden( 'token', $user->getEditToken() ) . "\n" .
867  Html::hidden( 'reset', 'all' ) . "\n";
868  foreach ( $nondefaults as $key => $value ) {
869  $form .= Html::hidden( $key, $value ) . "\n";
870  }
871  $form .= Xml::closeElement( 'form' ) . "\n";
872  }
873 
874  $this->getOutput()->addHTML( $form );
875  }
876 
877  protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
878  $options[$name] = 1 - (int)$value;
879 
880  $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
881  if ( $inStructuredUi ) {
882  $attribs[ 'data-feature-in-structured-ui' ] = true;
883  }
884 
885  return Html::rawElement(
886  'span',
887  $attribs,
888  // not using Html::checkLabel because that would escape the contents
889  Html::check( $name, (int)$value, [ 'id' => $name ] ) . "\n" . Html::rawElement(
890  'label',
891  $attribs + [ 'for' => $name ],
892  // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
893  $this->msg( $message, '<nowiki/>' )->parse()
894  )
895  );
896  }
897 
905  protected function countItems() {
906  $count = $this->watchedItemStore->countWatchedItems( $this->getUser() );
907  return floor( $count / 2 );
908  }
909 
914  protected function isChangeEffectivelySeen( RecentChange $rc ) {
915  $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
916 
917  return ( $firstUnseen === null || $firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
918  }
919 
925  return $this->watchedItemStore->getLatestNotificationTimestamp(
926  $rc->getAttribute( 'wl_notificationtimestamp' ),
927  $this->getUser(),
928  $rc->getTitle()
929  );
930  }
931 
935  protected function getLimitPreferenceName(): string {
936  return 'wllimit';
937  }
938 
942  protected function getSavedQueriesPreferenceName(): string {
943  return 'rcfilters-wl-saved-queries';
944  }
945 
949  protected function getDefaultDaysPreferenceName(): string {
950  return 'watchlistdays';
951  }
952 
956  protected function getCollapsedPreferenceName(): string {
957  return 'rcfilters-wl-collapsed';
958  }
959 
960 }
LIST_OR
const LIST_OR
Definition: Defines.php:46
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:36
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:768
SpecialEditWatchlist\EDIT_CLEAR
const EDIT_CLEAR
Editing modes.
Definition: SpecialEditWatchlist.php:49
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:258
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:936
SpecialEditWatchlist\EDIT_RAW
const EDIT_RAW
Definition: SpecialEditWatchlist.php:50
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:814
SpecialWatchlist\checkStructuredFilterUiEnabled
static checkStructuredFilterUiEnabled( $user)
Static method to check whether StructuredFilter UI is enabled for the given user.1....
Definition: SpecialWatchlist.php:135
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:203
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1722
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:81
SpecialWatchlist\getSubpagesForPrefixSearch
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialWatchlist.php:151
SpecialWatchlist\getCollapsedPreferenceName
getCollapsedPreferenceName()
Definition: SpecialWatchlist.php:956
SpecialWatchlist\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialWatchlist.php:479
LIST_AND
const LIST_AND
Definition: Defines.php:43
Html\check
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:720
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:39
SpecialWatchlist\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialWatchlist.php:46
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:382
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:131
SpecialPage\getAuthority
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: SpecialPage.php:834
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:854
SpecialWatchlist\doHeader
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
Definition: SpecialWatchlist.php:620
SpecialWatchlist\$watchlistManager
WatchlistManager $watchlistManager
Definition: SpecialWatchlist.php:43
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:111
SpecialWatchlist\getDefaultDaysPreferenceName
getDefaultDaysPreferenceName()
Definition: SpecialWatchlist.php:949
RecentChange\getTitle
getTitle()
Definition: RecentChange.php:330
SpecialWatchlist\doMainQuery
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
Process the query.Array of tables; see IDatabase::select $table Array of fields; see IDatabase::selec...
Definition: SpecialWatchlist.php:375
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
XmlSelect
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
SpecialWatchlist\getLimitPreferenceName
getLimitPreferenceName()
Definition: SpecialWatchlist.php:935
$dbr
$dbr
Definition: testCompression.php:54
RC_LOG
const RC_LOG
Definition: Defines.php:117
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:896
Config
Interface for configuration instances.
Definition: Config.php:30
WatchedItem\getExpiry
getExpiry(?int $style=TS_MW)
When the watched item will expire.
Definition: WatchedItem.php:150
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:972
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1119
SpecialWatchlist\transformFilterDefinition
transformFilterDefinition(array $filterDefinition)
Transforms filter definition to prepare it for constructor.See overrides of this method as well....
Definition: SpecialWatchlist.php:162
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:902
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:954
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
MediaWiki\Watchlist\WatchlistManager
WatchlistManager service.
Definition: WatchlistManager.php:52
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2268
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
ChangesListSpecialPage\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: ChangesListSpecialPage.php:1615
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1944
SpecialWatchlist\countItems
countItems()
Count the number of paired items on a user's watchlist.
Definition: SpecialWatchlist.php:905
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:42
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:157
$title
$title
Definition: testCompression.php:38
SpecialWatchlist\cutoffselector
cutoffselector( $options)
Definition: SpecialWatchlist.php:790
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:824
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1678
SpecialWatchlist\showHideCheck
showHideCheck( $options, $message, $name, $value, $inStructuredUi)
Definition: SpecialWatchlist.php:877
SpecialWatchlist\registerFilters
registerFilters()
Register all filters and their groups (including those from hooks), plus handle conflicts and default...
Definition: SpecialWatchlist.php:174
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:39
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:788
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:412
SpecialWatchlist
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
Definition: SpecialWatchlist.php:37
ChangesList\newFromContext
static newFromContext(IContextSource $context, array $groups=[])
Fetch an appropriate changes list class for the specified context Some users might want to use an enh...
Definition: ChangesList.php:98
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:834
EnhancedChangesList
Definition: EnhancedChangesList.php:26
SpecialWatchlist\execute
execute( $subpage)
Main execution point.
Definition: SpecialWatchlist.php:80
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
SpecialEditWatchlist\getMode
static getMode( $request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
Definition: SpecialEditWatchlist.php:803
Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:926
ChangesListSpecialPage\getFilterGroup
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Definition: ChangesListSpecialPage.php:1257
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:804
WatchedItem
Representation of a pair of user and title for watchlist entries.
Definition: WatchedItem.php:36
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:59
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
SpecialWatchlist\getSavedQueriesPreferenceName
getSavedQueriesPreferenceName()
Definition: SpecialWatchlist.php:942
SpecialWatchlist\outputFeedLinks
outputFeedLinks()
Definition: SpecialWatchlist.php:483
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:1173
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1052
ChangesListSpecialPage\areFiltersInConflict
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
Definition: ChangesListSpecialPage.php:564
SpecialEditWatchlist\buildTools
static buildTools( $lang, LinkRenderer $linkRenderer=null)
Build a set of links for convenient navigation between watchlist viewing and editing modes.
Definition: SpecialEditWatchlist.php:829
SpecialWatchlist\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialWatchlist.php:71
ChangesListBooleanFilterGroup
If the group is active, any unchecked filters will translate to hide parameters in the URL.
Definition: ChangesListBooleanFilterGroup.php:13
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:120
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:119
SpecialWatchlist\outputChangesList
outputChangesList( $rows, $opts)
Build and output the actual changes list.
Definition: SpecialWatchlist.php:502
SpecialWatchlist\$watchedItemStore
WatchedItemStoreInterface $watchedItemStore
Definition: SpecialWatchlist.php:40
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:213
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:42
ChangesList
Definition: ChangesList.php:36
SpecialWatchlist\$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: SpecialWatchlist.php:49
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:235
FormOptions\getChangedValues
getChangedValues()
Return options modified as an array ( name => value )
Definition: FormOptions.php:308
SpecialWatchlist\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed before the options.
Definition: SpecialWatchlist.php:827
SpecialWatchlist\fetchOptionsFromRequest
fetchOptionsFromRequest( $opts)
Fetch values for a FormOptions object from the WebRequest associated with this instance.
Definition: SpecialWatchlist.php:330
WatchedItemStoreInterface
Definition: WatchedItemStoreInterface.php:31
ChangesListSpecialPage\setBottomText
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
Definition: ChangesListSpecialPage.php:1700
ChangesListSpecialPage\registerFilterGroup
registerFilterGroup(ChangesListFilterGroup $group)
Register a structured changes list filter group.
Definition: ChangesListSpecialPage.php:1235
ChangesListStringOptionsFilterGroup
Represents a filter group with multiple string options.
Definition: ChangesListStringOptionsFilterGroup.php:37
ChangesListSpecialPage\getOptions
getOptions()
Get the current FormOptions for this request.
Definition: ChangesListSpecialPage.php:1026
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
SpecialWatchlist\__construct
__construct(WatchedItemStoreInterface $watchedItemStore, WatchlistManager $watchlistManager, ILoadBalancer $loadBalancer, UserOptionsLookup $userOptionsLookup)
Definition: SpecialWatchlist.php:57
SpecialWatchlist\getLatestNotificationTimestamp
getLatestNotificationTimestamp(RecentChange $rc)
Definition: SpecialWatchlist.php:924
ChangesListSpecialPage\getLegacyShowHideFilters
getLegacyShowHideFilters()
Definition: ChangesListSpecialPage.php:1157
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:466
SpecialWatchlist\isChangeEffectivelySeen
isChangeEffectivelySeen(RecentChange $rc)
Definition: SpecialWatchlist.php:914
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:426
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40