MediaWiki  master
SpecialWatchlist.php
Go to the documentation of this file.
1 <?php
27 
35  protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
36  protected static $daysPreferenceName = 'watchlistdays';
37  protected static $limitPreferenceName = 'wllimit';
38  protected static $collapsedPreferenceName = 'rcfilters-wl-collapsed';
39 
41  private $maxDays;
43  private $watchStore;
44 
45  public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
46  parent::__construct( $page, $restriction );
47 
48  $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
49  $this->watchStore = MediaWikiServices::getInstance()->getWatchedItemStore();
50  }
51 
52  public function doesWrites() {
53  return true;
54  }
55 
61  function execute( $subpage ) {
62  // Anons don't get a watchlist
63  $this->requireLogin( 'watchlistanontext' );
64 
65  $output = $this->getOutput();
66  $request = $this->getRequest();
67  $this->addHelpLink( 'Help:Watching pages' );
68  $output->addModuleStyles( [ 'mediawiki.special' ] );
69  $output->addModules( [
70  'mediawiki.special.recentchanges',
71  'mediawiki.special.watchlist',
72  ] );
73 
74  $mode = SpecialEditWatchlist::getMode( $request, $subpage );
75  if ( $mode !== false ) {
76  if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
77  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
78  } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
79  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
80  } else {
81  $title = SpecialPage::getTitleFor( 'EditWatchlist' );
82  }
83 
84  $output->redirect( $title->getLocalURL() );
85 
86  return;
87  }
88 
89  $this->checkPermissions();
90 
91  $user = $this->getUser();
92  $opts = $this->getOptions();
93 
94  $config = $this->getConfig();
95  if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
96  && $request->getVal( 'reset' )
97  && $request->wasPosted()
98  && $user->matchEditToken( $request->getVal( 'token' ) )
99  ) {
100  $user->clearAllNotifications();
101  $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
102 
103  return;
104  }
105 
106  parent::execute( $subpage );
107 
108  if ( $this->isStructuredFilterUiEnabled() ) {
109  $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
110  }
111  }
112 
116  public static function checkStructuredFilterUiEnabled( $user ) {
117  if ( $user instanceof Config ) {
118  wfDeprecated( __METHOD__ . ' with Config argument', '1.34' );
119  $user = func_get_arg( 1 );
120  }
121  return !$user->getOption( 'wlenhancedfilters-disable' );
122  }
123 
130  public function getSubpagesForPrefixSearch() {
131  return [
132  'clear',
133  'edit',
134  'raw',
135  ];
136  }
137 
141  protected function transformFilterDefinition( array $filterDefinition ) {
142  if ( isset( $filterDefinition['showHideSuffix'] ) ) {
143  $filterDefinition['showHide'] = 'wl' . $filterDefinition['showHideSuffix'];
144  }
145 
146  return $filterDefinition;
147  }
148 
152  protected function registerFilters() {
153  parent::registerFilters();
154 
155  // legacy 'extended' filter
157  'name' => 'extended-group',
158  'filters' => [
159  [
160  'name' => 'extended',
161  'isReplacedInStructuredUi' => true,
162  'activeValue' => false,
163  'default' => $this->getUser()->getBoolOption( 'extendwatchlist' ),
164  'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables,
165  &$fields, &$conds, &$query_options, &$join_conds ) {
166  $nonRevisionTypes = [ RC_LOG ];
167  Hooks::run( 'SpecialWatchlistGetNonRevisionTypes', [ &$nonRevisionTypes ] );
168  if ( $nonRevisionTypes ) {
169  $conds[] = $dbr->makeList(
170  [
171  'rc_this_oldid=page_latest',
172  'rc_type' => $nonRevisionTypes,
173  ],
174  LIST_OR
175  );
176  }
177  },
178  ]
179  ],
180 
181  ] ) );
182 
183  if ( $this->isStructuredFilterUiEnabled() ) {
184  $this->getFilterGroup( 'lastRevision' )
185  ->getFilter( 'hidepreviousrevisions' )
186  ->setDefault( !$this->getUser()->getBoolOption( 'extendwatchlist' ) );
187  }
188 
190  'name' => 'watchlistactivity',
191  'title' => 'rcfilters-filtergroup-watchlistactivity',
193  'priority' => 3,
194  'isFullCoverage' => true,
195  'filters' => [
196  [
197  'name' => 'unseen',
198  'label' => 'rcfilters-filter-watchlistactivity-unseen-label',
199  'description' => 'rcfilters-filter-watchlistactivity-unseen-description',
200  'cssClassSuffix' => 'watchedunseen',
201  'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
202  return !$this->isChangeEffectivelySeen( $rc );
203  },
204  ],
205  [
206  'name' => 'seen',
207  'label' => 'rcfilters-filter-watchlistactivity-seen-label',
208  'description' => 'rcfilters-filter-watchlistactivity-seen-description',
209  'cssClassSuffix' => 'watchedseen',
210  'isRowApplicableCallable' => function ( $ctx, RecentChange $rc ) {
211  return $this->isChangeEffectivelySeen( $rc );
212  }
213  ],
214  ],
216  'queryCallable' => function (
217  $specialPageClassName,
218  $context,
219  IDatabase $dbr,
220  &$tables,
221  &$fields,
222  &$conds,
223  &$query_options,
224  &$join_conds,
225  $selectedValues
226  ) {
227  if ( $selectedValues === [ 'seen' ] ) {
228  $conds[] = $dbr->makeList( [
229  'wl_notificationtimestamp IS NULL',
230  'rc_timestamp < wl_notificationtimestamp'
231  ], LIST_OR );
232  } elseif ( $selectedValues === [ 'unseen' ] ) {
233  $conds[] = $dbr->makeList( [
234  'wl_notificationtimestamp IS NOT NULL',
235  'rc_timestamp >= wl_notificationtimestamp'
236  ], LIST_AND );
237  }
238  }
239  ] ) );
240 
241  $user = $this->getUser();
242 
243  $significance = $this->getFilterGroup( 'significance' );
244  $hideMinor = $significance->getFilter( 'hideminor' );
245  $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
246 
247  $automated = $this->getFilterGroup( 'automated' );
248  $hideBots = $automated->getFilter( 'hidebots' );
249  $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
250 
251  $registration = $this->getFilterGroup( 'registration' );
252  $hideAnons = $registration->getFilter( 'hideanons' );
253  $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
254  $hideLiu = $registration->getFilter( 'hideliu' );
255  $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
256 
257  // Selecting both hideanons and hideliu on watchlist preferances
258  // gives mutually exclusive filters, so those are ignored
259  if ( $user->getBoolOption( 'watchlisthideanons' ) &&
260  !$user->getBoolOption( 'watchlisthideliu' )
261  ) {
262  $this->getFilterGroup( 'userExpLevel' )
263  ->setDefault( 'registered' );
264  }
265 
266  if ( $user->getBoolOption( 'watchlisthideliu' ) &&
267  !$user->getBoolOption( 'watchlisthideanons' )
268  ) {
269  $this->getFilterGroup( 'userExpLevel' )
270  ->setDefault( 'unregistered' );
271  }
272 
273  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
274  if ( $reviewStatus !== null ) {
275  // Conditional on feature being available and rights
276  if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
277  $reviewStatus->setDefault( 'unpatrolled' );
278  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
279  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
280  $legacyHidePatrolled->setDefault( true );
281  }
282  }
283 
284  $authorship = $this->getFilterGroup( 'authorship' );
285  $hideMyself = $authorship->getFilter( 'hidemyself' );
286  $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
287 
288  $changeType = $this->getFilterGroup( 'changeType' );
289  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
290  if ( $hideCategorization !== null ) {
291  // Conditional on feature being available
292  $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
293  }
294  }
295 
305  protected function fetchOptionsFromRequest( $opts ) {
306  static $compatibilityMap = [
307  'hideMinor' => 'hideminor',
308  'hideBots' => 'hidebots',
309  'hideAnons' => 'hideanons',
310  'hideLiu' => 'hideliu',
311  'hidePatrolled' => 'hidepatrolled',
312  'hideOwn' => 'hidemyself',
313  ];
314 
315  $params = $this->getRequest()->getValues();
316  foreach ( $compatibilityMap as $from => $to ) {
317  if ( isset( $params[$from] ) ) {
318  $params[$to] = $params[$from];
319  unset( $params[$from] );
320  }
321  }
322 
323  if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
324  $allBooleansFalse = [];
325 
326  // If the user submitted the form, start with a baseline of "all
327  // booleans are false", then change the ones they checked. This
328  // means we ignore the defaults.
329 
330  // This is how we handle the fact that HTML forms don't submit
331  // unchecked boxes.
332  foreach ( $this->getLegacyShowHideFilters() as $filter ) {
333  $allBooleansFalse[ $filter->getName() ] = false;
334  }
335 
336  $params = $params + $allBooleansFalse;
337  }
338 
339  // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
340  // methods defined on WebRequest and removing this dependency would cause some code duplication.
341  $request = new DerivativeRequest( $this->getRequest(), $params );
342  $opts->fetchValuesFromRequest( $request );
343 
344  return $opts;
345  }
346 
350  protected function doMainQuery( $tables, $fields, $conds, $query_options,
351  $join_conds, FormOptions $opts
352  ) {
353  $dbr = $this->getDB();
354  $user = $this->getUser();
355 
356  $rcQuery = RecentChange::getQueryInfo();
357  $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
358  $fields = array_merge( $rcQuery['fields'], $fields );
359 
360  $join_conds = array_merge(
361  [
362  'watchlist' => [
363  'JOIN',
364  [
365  'wl_user' => $user->getId(),
366  'wl_namespace=rc_namespace',
367  'wl_title=rc_title'
368  ],
369  ],
370  ],
371  $rcQuery['joins'],
372  $join_conds
373  );
374 
375  $tables[] = 'page';
376  $fields[] = 'page_latest';
377  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
378 
379  $fields[] = 'wl_notificationtimestamp';
380 
381  // Log entries with DELETED_ACTION must not show up unless the user has
382  // the necessary rights.
383  if ( !$user->isAllowed( 'deletedhistory' ) ) {
384  $bitmask = LogPage::DELETED_ACTION;
385  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
387  } else {
388  $bitmask = 0;
389  }
390  if ( $bitmask ) {
391  $conds[] = $dbr->makeList( [
392  'rc_type != ' . RC_LOG,
393  $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
394  ], LIST_OR );
395  }
396 
397  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
399  $tables,
400  $fields,
401  $conds,
402  $join_conds,
403  $query_options,
404  $tagFilter
405  );
406 
407  $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
408 
409  if ( $this->areFiltersInConflict() ) {
410  return false;
411  }
412 
413  $orderByAndLimit = [
414  'ORDER BY' => 'rc_timestamp DESC',
415  'LIMIT' => $opts['limit']
416  ];
417  if ( in_array( 'DISTINCT', $query_options ) ) {
418  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
419  // In order to prevent DISTINCT from causing query performance problems,
420  // we have to GROUP BY the primary key. This in turn requires us to add
421  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
422  // start of the GROUP BY
423  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
424  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
425  }
426  // array_merge() is used intentionally here so that hooks can, should
427  // they so desire, override the ORDER BY / LIMIT condition(s)
428  $query_options = array_merge( $orderByAndLimit, $query_options );
429 
430  return $dbr->select(
431  $tables,
432  $fields,
433  $conds,
434  __METHOD__,
435  $query_options,
436  $join_conds
437  );
438  }
439 
445  protected function getDB() {
446  return wfGetDB( DB_REPLICA, 'watchlist' );
447  }
448 
452  public function outputFeedLinks() {
453  $user = $this->getUser();
454  $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
455  if ( $wlToken ) {
456  $this->addFeedLinks( [
457  'action' => 'feedwatchlist',
458  'allrev' => 1,
459  'wlowner' => $user->getName(),
460  'wltoken' => $wlToken,
461  ] );
462  }
463  }
464 
471  public function outputChangesList( $rows, $opts ) {
472  $dbr = $this->getDB();
473  $user = $this->getUser();
474  $output = $this->getOutput();
475  $services = MediaWikiServices::getInstance();
476 
477  # Show a message about replica DB lag, if applicable
478  $lag = $dbr->getSessionLagStatus()['lag'];
479  if ( $lag > 0 ) {
480  $output->showLagWarning( $lag );
481  }
482 
483  # If no rows to display, show message before try to render the list
484  if ( $rows->numRows() == 0 ) {
485  $output->wrapWikiMsg(
486  "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
487  );
488  return;
489  }
490 
491  $dbr->dataSeek( $rows, 0 );
492 
493  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
494  $list->setWatchlistDivs();
495  $list->initChangesListRows( $rows );
496  if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
497  $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
498  // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
499  // since EnhancedChangesList groups log entries by performer rather than by target article
500  if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
501  $grouped ) {
502  return '';
503  } else {
504  return $this->getLinkRenderer()
505  ->makeKnownLink( $rc->getTitle(),
506  $this->msg( 'watchlist-unwatch' )->text(), [
507  'class' => 'mw-unwatch-link',
508  'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
509  ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
510  }
511  } );
512  }
513  $dbr->dataSeek( $rows, 0 );
514 
515  if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
516  && $user->getOption( 'shownumberswatching' )
517  ) {
518  $watchedItemStore = $services->getWatchedItemStore();
519  }
520 
521  $s = $list->beginRecentChangesList();
522 
523  if ( $this->isStructuredFilterUiEnabled() ) {
524  $s .= $this->makeLegend();
525  }
526 
527  $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
528  $counter = 1;
529  foreach ( $rows as $obj ) {
530  # Make RC entry
531  $rc = RecentChange::newFromRow( $obj );
532 
533  # Skip CatWatch entries for hidden cats based on user preference
534  if (
535  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
536  !$userShowHiddenCats &&
537  $rc->getParam( 'hidden-cat' )
538  ) {
539  continue;
540  }
541 
542  $rc->counter = $counter++;
543 
544  if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
545  $unseen = !$this->isChangeEffectivelySeen( $rc );
546  } else {
547  $unseen = false;
548  }
549 
550  if ( isset( $watchedItemStore ) ) {
551  $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
552  $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
553  } else {
554  $rc->numberofWatchingusers = 0;
555  }
556 
557  // XXX: this treats pages with no unseen changes as "not on the watchlist" since
558  // everything is on the watchlist and it is an easy way to make pages with unseen
559  // changes appear bold. @TODO: clean this up.
560  $changeLine = $list->recentChangesLine( $rc, $unseen, $counter );
561  if ( $changeLine !== false ) {
562  $s .= $changeLine;
563  }
564  }
565  $s .= $list->endRecentChangesList();
566 
567  $output->addHTML( $s );
568  }
569 
576  public function doHeader( $opts, $numRows ) {
577  $user = $this->getUser();
578  $out = $this->getOutput();
579 
580  $out->addSubtitle(
581  $this->msg( 'watchlistfor2', $user->getName() )
583  $this->getLanguage(),
584  $this->getLinkRenderer()
585  ) )
586  );
587 
588  $this->setTopText( $opts );
589 
590  $form = '';
591 
592  $form .= Xml::openElement( 'form', [
593  'method' => 'get',
594  'action' => wfScript(),
595  'id' => 'mw-watchlist-form'
596  ] );
597  $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
598  $form .= Xml::openElement(
599  'fieldset',
600  [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
601  );
602  $form .= Xml::element(
603  'legend', null, $this->msg( 'watchlist-options' )->text()
604  );
605 
606  if ( !$this->isStructuredFilterUiEnabled() ) {
607  $form .= $this->makeLegend();
608  }
609 
610  $lang = $this->getLanguage();
611  $timestamp = wfTimestampNow();
612  $now = $lang->userTimeAndDate( $timestamp, $user );
613  $wlInfo = Html::rawElement(
614  'span',
615  [
616  'class' => 'wlinfo',
617  'data-params' => json_encode( [ 'from' => $timestamp, 'fromFormatted' => $now ] ),
618  ],
619  $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
620  $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
621  )->parse()
622  ) . "<br />\n";
623 
624  $nondefaults = $opts->getChangedValues();
625  $cutofflinks = Html::rawElement(
626  'span',
627  [ 'class' => 'cldays cloption' ],
628  $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
629  );
630 
631  # Spit out some control panel links
632  $links = [];
633  $namesOfDisplayedFilters = [];
634  foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
635  $namesOfDisplayedFilters[] = $filterName;
636  $links[] = $this->showHideCheck(
637  $nondefaults,
638  $filter->getShowHide(),
639  $filterName,
640  $opts[ $filterName ],
641  $filter->isFeatureAvailableOnStructuredUi( $this )
642  );
643  }
644 
645  $hiddenFields = $nondefaults;
646  $hiddenFields['action'] = 'submit';
647  unset( $hiddenFields['namespace'] );
648  unset( $hiddenFields['invert'] );
649  unset( $hiddenFields['associated'] );
650  unset( $hiddenFields['days'] );
651  foreach ( $namesOfDisplayedFilters as $filterName ) {
652  unset( $hiddenFields[$filterName] );
653  }
654 
655  # Namespace filter and put the whole form together.
656  $form .= $wlInfo;
657  $form .= $cutofflinks;
658  $form .= Html::rawElement(
659  'span',
660  [ 'class' => 'clshowhide' ],
661  $this->msg( 'watchlist-hide' ) .
662  $this->msg( 'colon-separator' )->escaped() .
663  implode( ' ', $links )
664  );
665  $form .= "\n<br />\n";
666 
667  $namespaceForm = Html::namespaceSelector(
668  [
669  'selected' => $opts['namespace'],
670  'all' => '',
671  'label' => $this->msg( 'namespace' )->text(),
672  'in-user-lang' => true,
673  ], [
674  'name' => 'namespace',
675  'id' => 'namespace',
676  'class' => 'namespaceselector',
677  ]
678  ) . "\n";
679  $hidden = $opts['namespace'] === '' ? ' mw-input-hidden' : '';
680  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
681  $this->msg( 'invert' )->text(),
682  'invert',
683  'nsinvert',
684  $opts['invert'],
685  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
686  ) . "</span>\n";
687  $namespaceForm .= '<span class="mw-input-with-label' . $hidden . '">' . Xml::checkLabel(
688  $this->msg( 'namespace_association' )->text(),
689  'associated',
690  'nsassociated',
691  $opts['associated'],
692  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
693  ) . "</span>\n";
694  $form .= Html::rawElement(
695  'span',
696  [ 'class' => 'namespaceForm cloption' ],
697  $namespaceForm
698  );
699 
700  $form .= Xml::submitButton(
701  $this->msg( 'watchlist-submit' )->text(),
702  [ 'class' => 'cloption-submit' ]
703  ) . "\n";
704  foreach ( $hiddenFields as $key => $value ) {
705  $form .= Html::hidden( $key, $value ) . "\n";
706  }
707  $form .= Xml::closeElement( 'fieldset' ) . "\n";
708  $form .= Xml::closeElement( 'form' ) . "\n";
709 
710  // Insert a placeholder for RCFilters
711  if ( $this->isStructuredFilterUiEnabled() ) {
712  $rcfilterContainer = Html::element(
713  'div',
714  // TODO: Remove deprecated rcfilters-container class
715  [ 'class' => 'rcfilters-container mw-rcfilters-container' ]
716  );
717 
718  $loadingContainer = Html::rawElement(
719  'div',
720  [ 'class' => 'mw-rcfilters-spinner' ],
722  'div',
723  [ 'class' => 'mw-rcfilters-spinner-bounce' ]
724  )
725  );
726 
727  // Wrap both with rcfilters-head
728  $this->getOutput()->addHTML(
730  'div',
731  // TODO: Remove deprecated rcfilters-head class
732  [ 'class' => 'rcfilters-head mw-rcfilters-head' ],
733  $rcfilterContainer . $form
734  )
735  );
736 
737  // Add spinner
738  $this->getOutput()->addHTML( $loadingContainer );
739  } else {
740  $this->getOutput()->addHTML( $form );
741  }
742 
743  $this->setBottomText( $opts );
744  }
745 
746  function cutoffselector( $options ) {
747  $selected = (float)$options['days'];
748  if ( $selected <= 0 ) {
749  $selected = $this->maxDays;
750  }
751 
752  $selectedHours = round( $selected * 24 );
753 
754  $hours = array_unique( array_filter( [
755  1,
756  2,
757  6,
758  12,
759  24,
760  72,
761  168,
762  24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
763  24 * $this->maxDays,
764  $selectedHours
765  ] ) );
766  asort( $hours );
767 
768  $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
769 
770  foreach ( $hours as $value ) {
771  if ( $value < 24 ) {
772  $name = $this->msg( 'hours' )->numParams( $value )->text();
773  } else {
774  $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
775  }
776  $select->addOption( $name, (float)( $value / 24 ) );
777  }
778 
779  return $select->getHTML() . "\n<br />\n";
780  }
781 
782  function setTopText( FormOptions $opts ) {
783  $nondefaults = $opts->getChangedValues();
784  $form = '';
785  $user = $this->getUser();
786 
787  $numItems = $this->countItems();
788  $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
789 
790  // Show watchlist header
791  $watchlistHeader = '';
792  if ( $numItems == 0 ) {
793  $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
794  } else {
795  $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
796  if ( $this->getConfig()->get( 'EnotifWatchlist' )
797  && $user->getOption( 'enotifwatchlistpages' )
798  ) {
799  $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
800  }
801  if ( $showUpdatedMarker ) {
802  $watchlistHeader .= $this->msg(
803  $this->isStructuredFilterUiEnabled() ?
804  'rcfilters-watchlist-showupdated' :
805  'wlheader-showupdated'
806  )->parse() . "\n";
807  }
808  }
809  $form .= Html::rawElement(
810  'div',
811  [ 'class' => 'watchlistDetails' ],
812  $watchlistHeader
813  );
814 
815  if ( $numItems > 0 && $showUpdatedMarker ) {
816  $form .= Xml::openElement( 'form', [ 'method' => 'post',
817  'action' => $this->getPageTitle()->getLocalURL(),
818  'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
819  Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
820  [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
821  Html::hidden( 'token', $user->getEditToken() ) . "\n" .
822  Html::hidden( 'reset', 'all' ) . "\n";
823  foreach ( $nondefaults as $key => $value ) {
824  $form .= Html::hidden( $key, $value ) . "\n";
825  }
826  $form .= Xml::closeElement( 'form' ) . "\n";
827  }
828 
829  $this->getOutput()->addHTML( $form );
830  }
831 
832  protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
833  $options[$name] = 1 - (int)$value;
834 
835  $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
836  if ( $inStructuredUi ) {
837  $attribs[ 'data-feature-in-structured-ui' ] = true;
838  }
839 
840  return Html::rawElement(
841  'span',
842  $attribs,
843  // not using Html::checkLabel because that would escape the contents
844  Html::check( $name, (int)$value, [ 'id' => $name ] ) . Html::rawElement(
845  'label',
846  $attribs + [ 'for' => $name ],
847  // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
848  $this->msg( $message, '<nowiki/>' )->parse()
849  )
850  );
851  }
852 
860  protected function countItems() {
861  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
862  $count = $store->countWatchedItems( $this->getUser() );
863  return floor( $count / 2 );
864  }
865 
870  protected function isChangeEffectivelySeen( RecentChange $rc ) {
871  $firstUnseen = $this->getLatestNotificationTimestamp( $rc );
872 
873  return ( $firstUnseen === null || $firstUnseen > $rc->getAttribute( 'rc_timestamp' ) );
874  }
875 
881  return $this->watchStore->getLatestNotificationTimestamp(
882  $rc->getAttribute( 'wl_notificationtimestamp' ),
883  $this->getUser(),
884  $rc->getTitle()
885  );
886  }
887 }
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:772
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
const RC_CATEGORIZE
Definition: Defines.php:126
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition: hooks.txt:2621
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
getContext()
Gets the context this SpecialPage is executed in.
$batch execute()
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
outputChangesList( $rows, $opts)
Build and output the actual changes list.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static $collapsedPreferenceName
const EDIT_CLEAR
Editing modes.
static $savedQueriesPreferenceName
static array static newFromRow( $row)
if(!isset( $args[0])) $lang
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
getAttribute( $name)
Get an attribute value.
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$watchStore
WatchedItemStore.
getDB()
Return a IDatabase object for reading.
static checkStructuredFilterUiEnabled( $user)
static getMode( $request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
$value
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
static buildTools( $lang, LinkRenderer $linkRenderer=null)
Build a set of links for convenient navigation between watchlist viewing and editing modes...
getOutput()
Get the OutputPage being used for this instance.
fetchOptionsFromRequest( $opts)
Fetch values for a FormOptions object from the WebRequest associated with this instance.
isChangeEffectivelySeen(RecentChange $rc)
getOptions()
Get the current FormOptions for this request.
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
getLatestNotificationTimestamp(RecentChange $rc)
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition: hooks.txt:960
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2205
__construct( $page='Watchlist', $restriction='viewmywatchlist')
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:767
transformFilterDefinition(array $filterDefinition)
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
Interface for configuration instances.
Definition: Config.php:28
const LIST_AND
Definition: Defines.php:39
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2205
showHideCheck( $options, $message, $name, $value, $inStructuredUi)
countItems()
Count the number of paired items on a user&#39;s watchlist.
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:459
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
$params
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1972
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1972
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
$filter
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:83
Represents a filter group with multiple string options.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
const DELETED_RESTRICTED
Definition: LogPage.php:37
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
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:87
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:688
const LIST_OR
Definition: Defines.php:42
registerFilterGroup(ChangesListFilterGroup $group)
Register a structured changes list filter group.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
addFeedLinks( $params)
Adds RSS/atom links.
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Special page which uses a ChangesList to show query results.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
outputFeedLinks()
Output feed links.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
getUser()
Shortcut to get the User executing this instance.
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:796
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getConfig()
Shortcut to get main config object.
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
getLanguage()
Shortcut to get user&#39;s language.
msg( $key)
Wrapper around wfMessage that sets the current context.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2621
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object...
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
getChangedValues()
Return options modified as an array ( name => value )
const DB_REPLICA
Definition: defines.php:25
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:419
getRequest()
Get the WebRequest being used for this instance.
const DELETED_ACTION
Definition: LogPage.php:34
makeLegend()
Return the legend displayed within the fieldset.
cutoffselector( $options)
If the group is active, any unchecked filters will translate to hide parameters in the URL...
A special page that lists last changes made to the wiki, limited to user-defined list of titles...
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2621
setTopText(FormOptions $opts)
getPageTitle( $subpage=false)
Get a self-referential title object.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
const RC_LOG
Definition: Defines.php:124
execute( $subpage)
Main execution point.
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:886