MediaWiki  master
SpecialWatchlist.php
Go to the documentation of this file.
1 <?php
29 
37  protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
38  protected static $daysPreferenceName = 'watchlistdays';
39  protected static $limitPreferenceName = 'wllimit';
40  protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
41 
44 
47 
49  private $loadBalancer;
50 
53 
60  public function __construct(
65  ) {
66  parent::__construct( 'Watchlist', 'viewmywatchlist' );
67 
68  $this->watchedItemStore = $watchedItemStore;
69  $this->watchlistManager = $watchlistManager;
70  $this->loadBalancer = $loadBalancer;
71  $this->userOptionsLookup = $userOptionsLookup;
72  }
73 
74  public function doesWrites() {
75  return true;
76  }
77 
83  public function execute( $subpage ) {
84  // Anons don't get a watchlist
85  $this->requireLogin( 'watchlistanontext' );
86 
87  $output = $this->getOutput();
88  $request = $this->getRequest();
89  $this->addHelpLink( 'Help:Watching pages' );
90  $output->addModuleStyles( [ 'mediawiki.special' ] );
91  $output->addModules( [
92  'mediawiki.special.recentchanges',
93  'mediawiki.special.watchlist',
94  ] );
95 
96  $mode = SpecialEditWatchlist::getMode( $request, $subpage );
97  if ( $mode !== false ) {
98  if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
99  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
100  } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
101  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
102  } else {
103  $title = SpecialPage::getTitleFor( 'EditWatchlist' );
104  }
105 
106  $output->redirect( $title->getLocalURL() );
107 
108  return;
109  }
110 
111  $this->checkPermissions();
112 
113  $user = $this->getUser();
114  $opts = $this->getOptions();
115 
116  $config = $this->getConfig();
117  if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
118  && $request->getVal( 'reset' )
119  && $request->wasPosted()
120  && $this->getContext()->getCsrfTokenSet()->matchTokenField( 'token' )
121  ) {
122  $this->watchlistManager->clearAllUserNotifications( $user );
123  $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
124 
125  return;
126  }
127 
128  parent::execute( $subpage );
129 
130  if ( $this->isStructuredFilterUiEnabled() ) {
131  $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
132  }
133  }
134 
138  public static function checkStructuredFilterUiEnabled( $user ) {
139  if ( $user instanceof Config ) {
140  wfDeprecated( __METHOD__ . ' with Config argument', '1.34' );
141  $user = func_get_arg( 1 );
142  }
143  return !$user->getOption( 'wlenhancedfilters-disable' );
144  }
145 
152  public function getSubpagesForPrefixSearch() {
153  return [
154  'clear',
155  'edit',
156  'raw',
157  ];
158  }
159 
163  protected function transformFilterDefinition( array $filterDefinition ) {
164  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
165  $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
166  }
167 
168  return $filterDefinition;
169  }
170 
175  protected function registerFilters() {
176  parent::registerFilters();
177 
178  // legacy 'extended' filter
180  'name' => 'extended-group',
181  'filters' => [
182  [
183  'name' => 'extended',
184  'isReplacedInStructuredUi' => true,
185  'activeValue' => false,
186  'default' => $this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ),
187  'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
188  &$fields, &$conds, &$query_options, &$join_conds ) {
189  $nonRevisionTypes = [ RC_LOG ];
190  $this->getHookRunner()->onSpecialWatchlistGetNonRevisionTypes(
191  $nonRevisionTypes );
192  if ( $nonRevisionTypes ) {
193  $conds[] = $dbr->makeList(
194  [
195  'rc_this_oldid=page_latest',
196  'rc_type' => $nonRevisionTypes,
197  ],
198  LIST_OR
199  );
200  }
201  },
202  ]
203  ],
204 
205  ] ) );
206 
207  if ( $this->isStructuredFilterUiEnabled() ) {
208  $this->getFilterGroup( 'lastRevision' )
209  ->getFilter( 'hidepreviousrevisions' )
210  ->setDefault( !$this->userOptionsLookup->getBoolOption( $this->getUser(), 'extendwatchlist' ) );
211  }
212 
214  'name' => 'watchlistactivity',
215  'title' => 'rcfilters-filtergroup-watchlistactivity',
216  'class' => ChangesListStringOptionsFilterGroup::class,
217  'priority' => 3,
218  'isFullCoverage' => true,
219  'filters' => [
220  [
221  'name' => 'unseen',
222  'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
223  'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
224  'cssClassSuffix' => 'watchedunseen',
225  'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
226  return !$this->isChangeEffectivelySeen( $rc );
227  },
228  ],
229  [
230  'name' => 'seen',
231  'label' => 'rcfilters-filter-watchlistactivity-seen-label',
232  'description' => 'rcfilters-filter-watchlistactivity-seen-description',
233  'cssClassSuffix' => 'watchedseen',
234  'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
235  return $this->isChangeEffectivelySeen( $rc );
236  }
237  ],
238  ],
240  'queryCallable' => static function (
241  $specialPageClassName,
242  $context,
243  IDatabase $dbr,
244  &$tables,
245  &$fields,
246  &$conds,
247  &$query_options,
248  &$join_conds,
249  $selectedValues
250  ) {
251  if ( $selectedValues === [ 'seen' ] ) {
252  $conds[] = $dbr->makeList( [
253  'wl_notificationtimestamp IS NULL',
254  'rc_timestamp < wl_notificationtimestamp'
255  ], LIST_OR );
256  } elseif ( $selectedValues === [ 'unseen' ] ) {
257  $conds[] = $dbr->makeList( [
258  'wl_notificationtimestamp IS NOT NULL',
259  'rc_timestamp >= wl_notificationtimestamp'
260  ], LIST_AND );
261  }
262  }
263  ] ) );
264 
265  $user = $this->getUser();
266 
267  $significance = $this->getFilterGroup( 'significance' );
268  $hideMinor = $significance->getFilter( 'hideminor' );
269  $hideMinor->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideminor' ) );
270 
271  $automated = $this->getFilterGroup( 'automated' );
272  $hideBots = $automated->getFilter( 'hidebots' );
273  $hideBots->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidebots' ) );
274 
275  $registration = $this->getFilterGroup( 'registration' );
276  $hideAnons = $registration->getFilter( 'hideanons' );
277  $hideAnons->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) );
278  $hideLiu = $registration->getFilter( 'hideliu' );
279  $hideLiu->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) );
280 
281  // Selecting both hideanons and hideliu on watchlist preferances
282  // gives mutually exclusive filters, so those are ignored
283  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' ) &&
284  !$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' )
285  ) {
286  $this->getFilterGroup( 'userExpLevel' )
287  ->setDefault( 'registered' );
288  }
289 
290  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideliu' ) &&
291  !$this->userOptionsLookup->getBoolOption( $user, 'watchlisthideanons' )
292  ) {
293  $this->getFilterGroup( 'userExpLevel' )
294  ->setDefault( 'unregistered' );
295  }
296 
297  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
298  if ( $reviewStatus !== null ) {
299  // Conditional on feature being available and rights
300  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidepatrolled' ) ) {
301  $reviewStatus->setDefault( 'unpatrolled' );
302  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
303  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
304  $legacyHidePatrolled->setDefault( true );
305  }
306  }
307 
308  $authorship = $this->getFilterGroup( 'authorship' );
309  $hideMyself = $authorship->getFilter( 'hidemyself' );
310  $hideMyself->setDefault( $this->userOptionsLookup->getBoolOption( $user, 'watchlisthideown' ) );
311 
312  $changeType = $this->getFilterGroup( 'changeType' );
313  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
314  if ( $hideCategorization !== null ) {
315  // Conditional on feature being available
316  $hideCategorization->setDefault(
317  $this->userOptionsLookup->getBoolOption( $user, 'watchlisthidecategorization' )
318  );
319  }
320  }
321 
331  protected function fetchOptionsFromRequest( $opts ) {
332  static $compatibilityMap = [
333  'hideMinor' => 'hideminor',
334  'hideBots' => 'hidebots',
335  'hideAnons' => 'hideanons',
336  'hideLiu' => 'hideliu',
337  'hidePatrolled' => 'hidepatrolled',
338  'hideOwn' => 'hidemyself',
339  ];
340 
341  $params = $this->getRequest()->getValues();
342  foreach ( $compatibilityMap as $from => $to ) {
343  if ( isset( $params[$from] ) ) {
344  $params[$to] = $params[$from];
345  unset( $params[$from] );
346  }
347  }
348 
349  if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
350  $allBooleansFalse = [];
351 
352  // If the user submitted the form, start with a baseline of "all
353  // booleans are false", then change the ones they checked. This
354  // means we ignore the defaults.
355 
356  // This is how we handle the fact that HTML forms don't submit
357  // unchecked boxes.
358  foreach ( $this->getLegacyShowHideFilters() as $filter ) {
359  $allBooleansFalse[ $filter->getName() ] = false;
360  }
361 
362  $params += $allBooleansFalse;
363  }
364 
365  // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
366  // methods defined on WebRequest and removing this dependency would cause some code duplication.
367  $request = new DerivativeRequest( $this->getRequest(), $params );
368  $opts->fetchValuesFromRequest( $request );
369 
370  return $opts;
371  }
372 
376  protected function doMainQuery( $tables, $fields, $conds, $query_options,
377  $join_conds, FormOptions $opts
378  ) {
379  $dbr = $this->getDB();
380  $user = $this->getUser();
381 
382  $rcQuery = RecentChange::getQueryInfo();
383  $tables = array_merge( $rcQuery['tables'], $tables, [ 'watchlist' ] );
384  $fields = array_merge( $rcQuery['fields'], $fields );
385 
386  $join_conds = array_merge(
387  [
388  'watchlist' => [
389  'JOIN',
390  [
391  'wl_user' => $user->getId(),
392  'wl_namespace=rc_namespace',
393  'wl_title=rc_title'
394  ],
395  ],
396  ],
397  $rcQuery['joins'],
398  $join_conds
399  );
400 
401  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
402  $tables[] = 'watchlist_expiry';
403  $fields[] = 'we_expiry';
404  $join_conds['watchlist_expiry'] = [ 'LEFT JOIN', 'wl_id = we_item' ];
405  $conds[] = 'we_expiry IS NULL OR we_expiry > ' . $dbr->addQuotes( $dbr->timestamp() );
406  }
407 
408  $tables[] = 'page';
409  $fields[] = 'page_latest';
410  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
411 
412  $fields[] = 'wl_notificationtimestamp';
413 
414  // Log entries with DELETED_ACTION must not show up unless the user has
415  // the necessary rights.
416  $authority = $this->getAuthority();
417  if ( !$authority->isAllowed( 'deletedhistory' ) ) {
418  $bitmask = LogPage::DELETED_ACTION;
419  } elseif ( !$authority->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
421  } else {
422  $bitmask = 0;
423  }
424  if ( $bitmask ) {
425  $conds[] = $dbr->makeList( [
426  'rc_type != ' . RC_LOG,
427  $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
428  ], LIST_OR );
429  }
430 
431  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
433  $tables,
434  $fields,
435  $conds,
436  $join_conds,
437  $query_options,
438  $tagFilter
439  );
440 
441  $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
442 
443  if ( $this->areFiltersInConflict() ) {
444  return false;
445  }
446 
447  $orderByAndLimit = [
448  'ORDER BY' => 'rc_timestamp DESC',
449  'LIMIT' => $opts['limit']
450  ];
451  if ( in_array( 'DISTINCT', $query_options ) ) {
452  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
453  // In order to prevent DISTINCT from causing query performance problems,
454  // we have to GROUP BY the primary key. This in turn requires us to add
455  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
456  // start of the GROUP BY
457  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
458  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
459  }
460  // array_merge() is used intentionally here so that hooks can, should
461  // they so desire, override the ORDER BY / LIMIT condition(s)
462  $query_options = array_merge( $orderByAndLimit, $query_options );
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  $dbr->dataSeek( $rows, 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  $dbr->dataSeek( $rows, 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', $this->getContext()->getCsrfTokenSet()->getToken()->toString() ) . "\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 ] ) . 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 }
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:743
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:257
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:911
SpecialEditWatchlist\EDIT_RAW
const EDIT_RAW
Definition: SpecialEditWatchlist.php:50
SpecialWatchlist\$savedQueriesPreferenceName
static $savedQueriesPreferenceName
Definition: SpecialWatchlist.php:37
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:789
SpecialWatchlist\checkStructuredFilterUiEnabled
static checkStructuredFilterUiEnabled( $user)
Static method to check whether StructuredFilter UI is enabled for the given user.1....
Definition: SpecialWatchlist.php:138
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1744
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:80
SpecialWatchlist\getSubpagesForPrefixSearch
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialWatchlist.php:152
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:691
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:38
SpecialWatchlist\$loadBalancer
ILoadBalancer $loadBalancer
Definition: SpecialWatchlist.php:49
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:357
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:107
SpecialPage\getAuthority
getAuthority()
Shortcut to get the Authority executing this instance.
Definition: SpecialPage.php:809
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:829
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:46
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
RecentChange\getTitle
getTitle()
Definition: RecentChange.php:329
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:376
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
$dbr
$dbr
Definition: testCompression.php:54
RC_LOG
const RC_LOG
Definition: Defines.php:117
SpecialWatchlist\$collapsedPreferenceName
static $collapsedPreferenceName
Definition: SpecialWatchlist.php:40
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:891
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:947
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1094
SpecialWatchlist\transformFilterDefinition
transformFilterDefinition(array $filterDefinition)
Transforms filter definition to prepare it for constructor.See overrides of this method as well....
Definition: SpecialWatchlist.php:163
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:877
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:929
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:996
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:2306
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
ChangesListSpecialPage\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: ChangesListSpecialPage.php:1637
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1969
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:41
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:156
$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:799
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1721
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:175
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:39
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:763
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:387
SpecialWatchlist
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
Definition: SpecialWatchlist.php:36
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:95
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:805
EnhancedChangesList
Definition: EnhancedChangesList.php:26
SpecialWatchlist\execute
execute( $subpage)
Main execution point.
Definition: SpecialWatchlist.php:83
$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:897
ChangesListSpecialPage\getFilterGroup
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Definition: ChangesListSpecialPage.php:1267
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:779
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
SpecialWatchlist\outputFeedLinks
outputFeedLinks()
Definition: SpecialWatchlist.php:483
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:1167
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1027
ChangesListSpecialPage\areFiltersInConflict
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
Definition: ChangesListSpecialPage.php:578
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:74
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:119
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:43
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:212
SpecialWatchlist\$limitPreferenceName
static $limitPreferenceName
Definition: SpecialWatchlist.php:39
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:42
ChangesList
Definition: ChangesList.php:35
SpecialWatchlist\$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: SpecialWatchlist.php:52
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:234
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:331
WatchedItemStoreInterface
Definition: WatchedItemStoreInterface.php:31
ChangesListSpecialPage\setBottomText
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
Definition: ChangesListSpecialPage.php:1722
ChangesListSpecialPage\registerFilterGroup
registerFilterGroup(ChangesListFilterGroup $group)
Register a structured changes list filter group.
Definition: ChangesListSpecialPage.php:1245
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:1036
SpecialWatchlist\$daysPreferenceName
static $daysPreferenceName
Definition: SpecialWatchlist.php:38
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:60
SpecialWatchlist\getLatestNotificationTimestamp
getLatestNotificationTimestamp(RecentChange $rc)
Definition: SpecialWatchlist.php:924
ChangesListSpecialPage\getLegacyShowHideFilters
getLegacyShowHideFilters()
Definition: ChangesListSpecialPage.php:1167
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:465
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:425
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:40