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 
463  return $dbr->select(
464  $tables,
465  $fields,
466  $conds,
467  __METHOD__,
468  $query_options,
469  $join_conds
470  );
471  }
472 
478  protected function getDB() {
479  return $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA, 'watchlist' );
480  }
481 
482  public function outputFeedLinks() {
483  $user = $this->getUser();
484  $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
485  if ( $wlToken ) {
486  $this->addFeedLinks( [
487  'action' => 'feedwatchlist',
488  'allrev' => 1,
489  'wlowner' => $user->getName(),
490  'wltoken' => $wlToken,
491  ] );
492  }
493  }
494 
501  public function outputChangesList( $rows, $opts ) {
502  $dbr = $this->getDB();
503  $user = $this->getUser();
504  $output = $this->getOutput();
505 
506  // Show a message about replica DB lag, if applicable
507  $lag = $dbr->getSessionLagStatus()['lag'];
508  if ( $lag > 0 ) {
509  $output->showLagWarning( $lag );
510  }
511 
512  // If there are no rows to display, show message before trying to render the list
513  if ( $rows->numRows() == 0 ) {
514  $output->wrapWikiMsg(
515  "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
516  );
517  return;
518  }
519 
520  $dbr->dataSeek( $rows, 0 );
521 
522  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
523  $list->setWatchlistDivs();
524  $list->initChangesListRows( $rows );
525 
526  if ( $this->userOptionsLookup->getBoolOption( $user, 'watchlistunwatchlinks' ) ) {
527  $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
528  $unwatch = $this->msg( 'watchlist-unwatch' )->text();
529  // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
530  // since EnhancedChangesList groups log entries by performer rather than by target article
531  if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
532  $grouped ) {
533  return "<span style='visibility:hidden'>$unwatch</span>\u{00A0}";
534  } else {
535  $unwatchTooltipMessage = 'tooltip-ca-unwatch';
536  $diffInDays = null;
537  // Check if the watchlist expiry flag is enabled to show new tooltip message
538  if ( $this->getConfig()->get( 'WatchlistExpiry' ) ) {
539  $watchedItem = $this->watchedItemStore->getWatchedItem( $this->getUser(), $rc->getTitle() );
540  if ( $watchedItem instanceof WatchedItem && $watchedItem->getExpiry() !== null ) {
541  $diffInDays = $watchedItem->getExpiryInDays();
542 
543  if ( $diffInDays > 0 ) {
544  $unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring';
545  } else {
546  $unwatchTooltipMessage = 'tooltip-ca-unwatch-expiring-hours';
547  }
548  }
549  }
550 
551  return $this->getLinkRenderer()
552  ->makeKnownLink( $rc->getTitle(),
553  $unwatch, [
554  'class' => 'mw-unwatch-link',
555  'title' => $this->msg( $unwatchTooltipMessage, [ $diffInDays ] )->text()
556  ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
557  }
558  } );
559  }
560  $dbr->dataSeek( $rows, 0 );
561 
562  $s = $list->beginRecentChangesList();
563 
564  if ( $this->isStructuredFilterUiEnabled() ) {
565  $s .= $this->makeLegend();
566  }
567 
568  $userShowHiddenCats = $this->userOptionsLookup->getBoolOption( $user, 'showhiddencats' );
569  $counter = 1;
570  foreach ( $rows as $obj ) {
571  // Make RC entry
572  $rc = RecentChange::newFromRow( $obj );
573 
574  // Skip CatWatch entries for hidden cats based on user preference
575  if (
576  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
577  !$userShowHiddenCats &&
578  $rc->getParam( 'hidden-cat' )
579  ) {
580  continue;
581  }
582 
583  $rc->counter = $counter++;
584 
585  if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
586  $unseen = !$this->isChangeEffectivelySeen( $rc );
587  } else {
588  $unseen = false;
589  }
590 
591  if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
592  && $this->userOptionsLookup->getBoolOption( $user, 'shownumberswatching' )
593  ) {
594  $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
595  $rc->numberofWatchingusers = $this->watchedItemStore->countWatchers( $rcTitleValue );
596  } else {
597  $rc->numberofWatchingusers = 0;
598  }
599 
600  // XXX: this treats pages with no unseen changes as "not on the watchlist" since
601  // everything is on the watchlist and it is an easy way to make pages with unseen
602  // changes appear bold. @TODO: clean this up.
603  $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
604  if ( $changeLine !== false ) {
605  $s .= $changeLine;
606  }
607  }
608  $s .= $list->endRecentChangesList();
609 
610  $output->addHTML( $s );
611  }
612 
619  public function doHeader( $opts, $numRows ) {
620  $user = $this->getUser();
621  $out = $this->getOutput();
622 
623  $out->addSubtitle(
624  $this->msg( 'watchlistfor2', $user->getName() )
626  $this->getLanguage(),
627  $this->getLinkRenderer()
628  ) )
629  );
630 
631  $this->setTopText( $opts );
632 
633  $form = '';
634 
635  $form .= Xml::openElement( 'form', [
636  'method' => 'get',
637  'action' => wfScript(),
638  'id' => 'mw-watchlist-form'
639  ] );
640  $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
641  $form .= Xml::openElement(
642  'fieldset',
643  [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
644  );
645  $form .= Xml::element(
646  'legend', null, $this->msg( 'watchlist-options' )->text()
647  );
648 
649  if ( !$this->isStructuredFilterUiEnabled() ) {
650  $form .= $this->makeLegend();
651  }
652 
653  $lang = $this->getLanguage();
654  $timestamp = wfTimestampNow();
655  $now = $lang->userTimeAndDate( $timestamp, $user );
656  $wlInfo = Html::rawElement(
657  'span',
658  [
659  'class' => 'wlinfo',
660  'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
661  ],
662  $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
663  $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
664  )->parse()
665  ) . "<br />\n";
666 
667  $nondefaults = $opts->getChangedValues();
668  $cutofflinks = Html::rawElement(
669  'span',
670  [ 'class' => 'cldays cloption' ],
671  $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
672  );
673 
674  // Spit out some control panel links
675  $links = [];
676  $namesOfDisplayedFilters = [];
677  foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
678  $namesOfDisplayedFilters[] = $filterName;
679  $links[] = $this->showHideCheck(
680  $nondefaults,
681  $filter->getShowHide(),
682  $filterName,
683  $opts[ $filterName ],
684  $filter->isFeatureAvailableOnStructuredUi()
685  );
686  }
687 
688  $hiddenFields = $nondefaults;
689  $hiddenFields['action'] = 'submit';
690  unset( $hiddenFields['namespace'] );
691  unset( $hiddenFields['invert'] );
692  unset( $hiddenFields['associated'] );
693  unset( $hiddenFields['days'] );
694  foreach ( $namesOfDisplayedFilters as $filterName ) {
695  unset( $hiddenFields[$filterName] );
696  }
697 
698  // Namespace filter and put the whole form together.
699  $form .= $wlInfo;
700  $form .= $cutofflinks;
701  $form .= Html::rawElement(
702  'span',
703  [ 'class' => 'clshowhide' ],
704  $this->msg( 'watchlist-hide' ) .
705  $this->msg( 'colon-separator' )->escaped() .
706  implode( ' ', $links )
707  );
708  $form .= "\n<br />\n";
709 
710  $namespaceForm = Html::namespaceSelector(
711  [
712  'selected' => $opts['namespace'],
713  'all' => '',
714  'label' => $this->msg( 'namespace' )->text(),
715  'in-user-lang' => true,
716  ], [
717  'name' => 'namespace',
718  'id' => 'namespace',
719  'class' => 'namespaceselector',
720  ]
721  ) . "\n";
722  $hidden = $opts['namespace'] === '' ? ' mw-input-hidden' : '';
723  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
724  $this->msg( 'invert' )->text(),
725  'invert',
726  'nsinvert',
727  $opts['invert'],
728  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
729  ) . "</span>\n";
730  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
731  $this->msg( 'namespace_association' )->text(),
732  'associated',
733  'nsassociated',
734  $opts['associated'],
735  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
736  ) . "</span>\n";
737  $form .= Html::rawElement(
738  'span',
739  [ 'class' => 'namespaceForm cloption' ],
740  $namespaceForm
741  );
742 
743  $form .= Xml::submitButton(
744  $this->msg( 'watchlist-submit' )->text(),
745  [ 'class' => 'cloption-submit' ]
746  ) . "\n";
747  foreach ( $hiddenFields as $key => $value ) {
748  $form .= Html::hidden( $key, $value ) . "\n";
749  }
750  $form .= Xml::closeElement( 'fieldset' ) . "\n";
751  $form .= Xml::closeElement( 'form' ) . "\n";
752 
753  // Insert a placeholder for RCFilters
754  if ( $this->isStructuredFilterUiEnabled() ) {
755  $rcfilterContainer = Html::element(
756  'div',
757  // TODO: Remove deprecated rcfilters-container class
758  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
759  );
760 
761  $loadingContainer = Html::rawElement(
762  'div',
763  [ 'class' => 'mw-rcfilters-spinner' ],
765  'div',
766  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
767  )
768  );
769 
770  // Wrap both with rcfilters-head
771  $this->getOutput()->addHTML(
773  'div',
774  // TODO: Remove deprecated rcfilters-head class
775  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
776  $rcfilterContainer . $form
777  )
778  );
779 
780  // Add spinner
781  $this->getOutput()->addHTML( $loadingContainer );
782  } else {
783  $this->getOutput()->addHTML( $form );
784  }
785 
786  $this->setBottomText( $opts );
787  }
788 
789  private function cutoffselector( $options ) {
790  $selected = (float)$options['days'];
791  $maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
792  if ( $selected <= 0 ) {
793  $selected = $maxDays;
794  }
795 
796  $selectedHours = round( $selected * 24 );
797 
798  $hours = array_unique( array_filter( [
799  1,
800  2,
801  6,
802  12,
803  24,
804  72,
805  168,
806  24 * (float)$this->userOptionsLookup->getOption( $this->getUser(), 'watchlistdays', 0 ),
807  24 * $maxDays,
808  $selectedHours
809  ] ) );
810  asort( $hours );
811 
812  $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
813 
814  foreach ( $hours as $value ) {
815  if ( $value < 24 ) {
816  $name = $this->msg( 'hours' )->numParams( $value )->text();
817  } else {
818  $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
819  }
820  $select->addOption( $name, (float)( $value / 24 ) );
821  }
822 
823  return $select->getHTML() . "\n<br />\n";
824  }
825 
826  public function setTopText( FormOptions $opts ) {
827  $nondefaults = $opts->getChangedValues();
828  $form = '';
829  $user = $this->getUser();
830 
831  $numItems = $this->countItems();
832  $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
833 
834  // Show watchlist header
835  $watchlistHeader = '';
836  if ( $numItems == 0 ) {
837  $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
838  } else {
839  $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
840  if ( $this->getConfig()->get( 'EnotifWatchlist' )
841  && $this->userOptionsLookup->getBoolOption( $user, 'enotifwatchlistpages' )
842  ) {
843  $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
844  }
845  if ( $showUpdatedMarker ) {
846  $watchlistHeader .= $this->msg(
847  $this->isStructuredFilterUiEnabled() ?
848  'rcfilters-watchlist-showupdated' :
849  'wlheader-showupdated'
850  )->parse() . "\n";
851  }
852  }
853  $form .= Html::rawElement(
854  'div',
855  [ 'class' => 'watchlistDetails' ],
856  $watchlistHeader
857  );
858 
859  if ( $numItems > 0 && $showUpdatedMarker ) {
860  $form .= Xml::openElement( 'form', [ 'method' => 'post',
861  'action' => $this->getPageTitle()->getLocalURL(),
862  'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
863  Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
864  [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
865  Html::hidden( 'token', $user->getEditToken() ) . "\n" .
866  Html::hidden( 'reset', 'all' ) . "\n";
867  foreach ( $nondefaults as $key => $value ) {
868  $form .= Html::hidden( $key, $value ) . "\n";
869  }
870  $form .= Xml::closeElement( 'form' ) . "\n";
871  }
872 
873  $this->getOutput()->addHTML( $form );
874  }
875 
876  protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
877  $options[$name] = 1 - (int)$value;
878 
879  $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
880  if ( $inStructuredUi ) {
881  $attribs[ 'data-feature-in-structured-ui' ] = true;
882  }
883 
884  return Html::rawElement(
885  'span',
886  $attribs,
887  // not using Html::checkLabel because that would escape the contents
888  Html::check( $name, (int)$value, [ 'id' => $name ] ) . Html::rawElement(
889  'label',
890  $attribs + [ 'for' => $name ],
891  // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
892  $this->msg( $message, '<nowiki/>' )->parse()
893  )
894  );
895  }
896 
904  protected function countItems() {
905  $count = $this->watchedItemStore->countWatchedItems( $this->getUser() );
906  return floor( $count / 2 );
907  }
908 
913  protected function isChangeEffectivelySeen( RecentChange $rc ) {
914  $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
915 
916  return ( $firstUnseen === null || $firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
917  }
918 
924  return $this->watchedItemStore->getLatestNotificationTimestamp(
925  $rc->getAttribute( 'wl_notificationtimestamp' ),
926  $this->getUser(),
927  $rc->getTitle()
928  );
929  }
930 
934  protected function getLimitPreferenceName(): string {
935  return 'wllimit';
936  }
937 
941  protected function getSavedQueriesPreferenceName(): string {
942  return 'rcfilters-wl-saved-queries';
943  }
944 
948  protected function getDefaultDaysPreferenceName(): string {
949  return 'watchlistdays';
950  }
951 
955  protected function getCollapsedPreferenceName(): string {
956  return 'rcfilters-wl-collapsed';
957  }
958 
959 }
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:744
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:912
SpecialEditWatchlist\EDIT_RAW
const EDIT_RAW
Definition: SpecialEditWatchlist.php:50
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:790
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:199
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1734
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:151
SpecialWatchlist\getCollapsedPreferenceName
getCollapsedPreferenceName()
Definition: SpecialWatchlist.php:955
SpecialWatchlist\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialWatchlist.php:478
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:717
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:358
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:810
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:830
SpecialWatchlist\doHeader
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
Definition: SpecialWatchlist.php:619
SpecialWatchlist\$watchlistManager
WatchlistManager $watchlistManager
Definition: SpecialWatchlist.php:43
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
SpecialWatchlist\getDefaultDaysPreferenceName
getDefaultDaysPreferenceName()
Definition: SpecialWatchlist.php:948
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: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:934
$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: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:948
SpecialPage\getHookRunner
getHookRunner()
Definition: SpecialPage.php:1095
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:878
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:930
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:2282
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:1627
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1960
SpecialWatchlist\countItems
countItems()
Count the number of paired items on a user's watchlist.
Definition: SpecialWatchlist.php:904
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:789
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:800
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1694
SpecialWatchlist\showHideCheck
showHideCheck( $options, $message, $name, $value, $inStructuredUi)
Definition: SpecialWatchlist.php:876
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:764
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:388
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:831
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:923
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:780
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:941
SpecialWatchlist\outputFeedLinks
outputFeedLinks()
Definition: SpecialWatchlist.php:482
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:1169
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:1028
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: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:501
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:210
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:232
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:826
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:1712
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:923
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:465
SpecialWatchlist\isChangeEffectivelySeen
isChangeEffectivelySeen(RecentChange $rc)
Definition: SpecialWatchlist.php:913
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