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