MediaWiki  1.32.5
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 
40  private $maxDays;
41 
42  public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
43  parent::__construct( $page, $restriction );
44 
45  $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
46  }
47 
48  public function doesWrites() {
49  return true;
50  }
51 
57  function execute( $subpage ) {
58  // Anons don't get a watchlist
59  $this->requireLogin( 'watchlistanontext' );
60 
61  $output = $this->getOutput();
62  $request = $this->getRequest();
63  $this->addHelpLink( 'Help:Watching pages' );
64  $output->addModuleStyles( [ 'mediawiki.special' ] );
65  $output->addModules( [
66  'mediawiki.special.watchlist',
67  ] );
68 
69  $mode = SpecialEditWatchlist::getMode( $request, $subpage );
70  if ( $mode !== false ) {
71  if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
72  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
73  } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
74  $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
75  } else {
76  $title = SpecialPage::getTitleFor( 'EditWatchlist' );
77  }
78 
79  $output->redirect( $title->getLocalURL() );
80 
81  return;
82  }
83 
84  $this->checkPermissions();
85 
86  $user = $this->getUser();
87  $opts = $this->getOptions();
88 
89  $config = $this->getConfig();
90  if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
91  && $request->getVal( 'reset' )
92  && $request->wasPosted()
93  && $user->matchEditToken( $request->getVal( 'token' ) )
94  ) {
95  $user->clearAllNotifications();
96  $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
97 
98  return;
99  }
100 
101  parent::execute( $subpage );
102 
103  if ( $this->isStructuredFilterUiEnabled() ) {
104  $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
105 
106  $output->addJsConfigVars(
107  'wgStructuredChangeFiltersEditWatchlistUrl',
108  SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
109  );
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, $rc ) {
195  $changeTs = $rc->getAttribute( 'rc_timestamp' );
196  $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
197  return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
198  },
199  ],
200  [
201  'name' => 'seen',
202  'label' => 'rcfilters-filter-watchlistactivity-seen-label',
203  'description' => 'rcfilters-filter-watchlistactivity-seen-description',
204  'cssClassSuffix' => 'watchedseen',
205  'isRowApplicableCallable' => function ( $ctx, $rc ) {
206  $changeTs = $rc->getAttribute( 'rc_timestamp' );
207  $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
208  return $lastVisitTs === null || $changeTs < $lastVisitTs;
209  }
210  ],
211  ],
213  'queryCallable' => function ( $specialPageClassName, $context, $dbr,
214  &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
215  if ( $selectedValues === [ 'seen' ] ) {
216  $conds[] = $dbr->makeList( [
217  'wl_notificationtimestamp IS NULL',
218  'rc_timestamp < wl_notificationtimestamp'
219  ], LIST_OR );
220  } elseif ( $selectedValues === [ 'unseen' ] ) {
221  $conds[] = $dbr->makeList( [
222  'wl_notificationtimestamp IS NOT NULL',
223  'rc_timestamp >= wl_notificationtimestamp'
224  ], LIST_AND );
225  }
226  }
227  ] ) );
228 
229  $user = $this->getUser();
230 
231  $significance = $this->getFilterGroup( 'significance' );
232  $hideMinor = $significance->getFilter( 'hideminor' );
233  $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
234 
235  $automated = $this->getFilterGroup( 'automated' );
236  $hideBots = $automated->getFilter( 'hidebots' );
237  $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
238 
239  $registration = $this->getFilterGroup( 'registration' );
240  $hideAnons = $registration->getFilter( 'hideanons' );
241  $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
242  $hideLiu = $registration->getFilter( 'hideliu' );
243  $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
244 
245  // Selecting both hideanons and hideliu on watchlist preferances
246  // gives mutually exclusive filters, so those are ignored
247  if ( $user->getBoolOption( 'watchlisthideanons' ) &&
248  !$user->getBoolOption( 'watchlisthideliu' )
249  ) {
250  $this->getFilterGroup( 'userExpLevel' )
251  ->setDefault( 'registered' );
252  }
253 
254  if ( $user->getBoolOption( 'watchlisthideliu' ) &&
255  !$user->getBoolOption( 'watchlisthideanons' )
256  ) {
257  $this->getFilterGroup( 'userExpLevel' )
258  ->setDefault( 'unregistered' );
259  }
260 
261  $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
262  if ( $reviewStatus !== null ) {
263  // Conditional on feature being available and rights
264  if ( $user->getBoolOption( 'watchlisthidepatrolled' ) ) {
265  $reviewStatus->setDefault( 'unpatrolled' );
266  $legacyReviewStatus = $this->getFilterGroup( 'legacyReviewStatus' );
267  $legacyHidePatrolled = $legacyReviewStatus->getFilter( 'hidepatrolled' );
268  $legacyHidePatrolled->setDefault( true );
269  }
270  }
271 
272  $authorship = $this->getFilterGroup( 'authorship' );
273  $hideMyself = $authorship->getFilter( 'hidemyself' );
274  $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
275 
276  $changeType = $this->getFilterGroup( 'changeType' );
277  $hideCategorization = $changeType->getFilter( 'hidecategorization' );
278  if ( $hideCategorization !== null ) {
279  // Conditional on feature being available
280  $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
281  }
282  }
283 
293  protected function fetchOptionsFromRequest( $opts ) {
294  static $compatibilityMap = [
295  'hideMinor' => 'hideminor',
296  'hideBots' => 'hidebots',
297  'hideAnons' => 'hideanons',
298  'hideLiu' => 'hideliu',
299  'hidePatrolled' => 'hidepatrolled',
300  'hideOwn' => 'hidemyself',
301  ];
302 
303  $params = $this->getRequest()->getValues();
304  foreach ( $compatibilityMap as $from => $to ) {
305  if ( isset( $params[$from] ) ) {
306  $params[$to] = $params[$from];
307  unset( $params[$from] );
308  }
309  }
310 
311  if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
312  $allBooleansFalse = [];
313 
314  // If the user submitted the form, start with a baseline of "all
315  // booleans are false", then change the ones they checked. This
316  // means we ignore the defaults.
317 
318  // This is how we handle the fact that HTML forms don't submit
319  // unchecked boxes.
320  foreach ( $this->getLegacyShowHideFilters() as $filter ) {
321  $allBooleansFalse[ $filter->getName() ] = false;
322  }
323 
324  $params = $params + $allBooleansFalse;
325  }
326 
327  // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
328  // methods defined on WebRequest and removing this dependency would cause some code duplication.
329  $request = new DerivativeRequest( $this->getRequest(), $params );
330  $opts->fetchValuesFromRequest( $request );
331 
332  return $opts;
333  }
334 
338  protected function doMainQuery( $tables, $fields, $conds, $query_options,
339  $join_conds, FormOptions $opts
340  ) {
341  $dbr = $this->getDB();
342  $user = $this->getUser();
343 
344  $rcQuery = RecentChange::getQueryInfo();
345  $tables = array_merge( $tables, $rcQuery['tables'], [ 'watchlist' ] );
346  $fields = array_merge( $rcQuery['fields'], $fields );
347 
348  $join_conds = array_merge(
349  [
350  'watchlist' => [
351  'INNER JOIN',
352  [
353  'wl_user' => $user->getId(),
354  'wl_namespace=rc_namespace',
355  'wl_title=rc_title'
356  ],
357  ],
358  ],
359  $rcQuery['joins'],
360  $join_conds
361  );
362 
363  $tables[] = 'page';
364  $fields[] = 'page_latest';
365  $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
366 
367  $fields[] = 'wl_notificationtimestamp';
368 
369  // Log entries with DELETED_ACTION must not show up unless the user has
370  // the necessary rights.
371  if ( !$user->isAllowed( 'deletedhistory' ) ) {
372  $bitmask = LogPage::DELETED_ACTION;
373  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
375  } else {
376  $bitmask = 0;
377  }
378  if ( $bitmask ) {
379  $conds[] = $dbr->makeList( [
380  'rc_type != ' . RC_LOG,
381  $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
382  ], LIST_OR );
383  }
384 
385  $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
387  $tables,
388  $fields,
389  $conds,
390  $join_conds,
391  $query_options,
392  $tagFilter
393  );
394 
395  $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
396 
397  if ( $this->areFiltersInConflict() ) {
398  return false;
399  }
400 
401  $orderByAndLimit = [
402  'ORDER BY' => 'rc_timestamp DESC',
403  'LIMIT' => $opts['limit']
404  ];
405  if ( in_array( 'DISTINCT', $query_options ) ) {
406  // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
407  // In order to prevent DISTINCT from causing query performance problems,
408  // we have to GROUP BY the primary key. This in turn requires us to add
409  // the primary key to the end of the ORDER BY, and the old ORDER BY to the
410  // start of the GROUP BY
411  $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
412  $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
413  }
414  // array_merge() is used intentionally here so that hooks can, should
415  // they so desire, override the ORDER BY / LIMIT condition(s)
416  $query_options = array_merge( $orderByAndLimit, $query_options );
417 
418  return $dbr->select(
419  $tables,
420  $fields,
421  $conds,
422  __METHOD__,
423  $query_options,
424  $join_conds
425  );
426  }
427 
433  protected function getDB() {
434  return wfGetDB( DB_REPLICA, 'watchlist' );
435  }
436 
440  public function outputFeedLinks() {
441  $user = $this->getUser();
442  $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
443  if ( $wlToken ) {
444  $this->addFeedLinks( [
445  'action' => 'feedwatchlist',
446  'allrev' => 1,
447  'wlowner' => $user->getName(),
448  'wltoken' => $wlToken,
449  ] );
450  }
451  }
452 
459  public function outputChangesList( $rows, $opts ) {
460  $dbr = $this->getDB();
461  $user = $this->getUser();
462  $output = $this->getOutput();
463  $services = MediaWikiServices::getInstance();
464 
465  # Show a message about replica DB lag, if applicable
466  $lag = $services->getDBLoadBalancer()->safeGetLag( $dbr );
467  if ( $lag > 0 ) {
468  $output->showLagWarning( $lag );
469  }
470 
471  # If no rows to display, show message before try to render the list
472  if ( $rows->numRows() == 0 ) {
473  $output->wrapWikiMsg(
474  "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
475  );
476  return;
477  }
478 
479  $dbr->dataSeek( $rows, 0 );
480 
481  $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
482  $list->setWatchlistDivs();
483  $list->initChangesListRows( $rows );
484  if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
485  $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
486  // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
487  // since EnhancedChangesList groups log entries by performer rather than by target article
488  if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
489  $grouped ) {
490  return '';
491  } else {
492  return $this->getLinkRenderer()
493  ->makeKnownLink( $rc->getTitle(),
494  $this->msg( 'watchlist-unwatch' )->text(), [
495  'class' => 'mw-unwatch-link',
496  'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
497  ], [ 'action' => 'unwatch' ] ) . "\u{00A0}";
498  }
499  } );
500  }
501  $dbr->dataSeek( $rows, 0 );
502 
503  if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
504  && $user->getOption( 'shownumberswatching' )
505  ) {
506  $watchedItemStore = $services->getWatchedItemStore();
507  }
508 
509  $s = $list->beginRecentChangesList();
510 
511  if ( $this->isStructuredFilterUiEnabled() ) {
512  $s .= $this->makeLegend();
513  }
514 
515  $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
516  $counter = 1;
517  foreach ( $rows as $obj ) {
518  # Make RC entry
519  $rc = RecentChange::newFromRow( $obj );
520 
521  # Skip CatWatch entries for hidden cats based on user preference
522  if (
523  $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
524  !$userShowHiddenCats &&
525  $rc->getParam( 'hidden-cat' )
526  ) {
527  continue;
528  }
529 
530  $rc->counter = $counter++;
531 
532  if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
533  $updated = $obj->wl_notificationtimestamp;
534  } else {
535  $updated = false;
536  }
537 
538  if ( isset( $watchedItemStore ) ) {
539  $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
540  $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
541  } else {
542  $rc->numberofWatchingusers = 0;
543  }
544 
545  $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
546  if ( $changeLine !== false ) {
547  $s .= $changeLine;
548  }
549  }
550  $s .= $list->endRecentChangesList();
551 
552  $output->addHTML( $s );
553  }
554 
561  public function doHeader( $opts, $numRows ) {
562  $user = $this->getUser();
563  $out = $this->getOutput();
564 
565  $out->addSubtitle(
566  $this->msg( 'watchlistfor2', $user->getName() )
568  $this->getLanguage(),
569  $this->getLinkRenderer()
570  ) )
571  );
572 
573  $this->setTopText( $opts );
574 
575  $form = '';
576 
577  $form .= Xml::openElement( 'form', [
578  'method' => 'get',
579  'action' => wfScript(),
580  'id' => 'mw-watchlist-form'
581  ] );
582  $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
583  $form .= Xml::openElement(
584  'fieldset',
585  [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
586  );
587  $form .= Xml::element(
588  'legend', null, $this->msg( 'watchlist-options' )->text()
589  );
590 
591  if ( !$this->isStructuredFilterUiEnabled() ) {
592  $form .= $this->makeLegend();
593  }
594 
595  $lang = $this->getLanguage();
596  $timestamp = wfTimestampNow();
597  $wlInfo = Html::rawElement(
598  'span',
599  [
600  'class' => 'wlinfo',
601  'data-params' => json_encode( [ 'from' => $timestamp ] ),
602  ],
603  $this->msg( 'wlnote' )->numParams( $numRows, round( $opts['days'] * 24 ) )->params(
604  $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
605  )->parse()
606  ) . "<br />\n";
607 
608  $nondefaults = $opts->getChangedValues();
609  $cutofflinks = Html::rawElement(
610  'span',
611  [ 'class' => 'cldays cloption' ],
612  $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
613  );
614 
615  # Spit out some control panel links
616  $links = [];
617  $namesOfDisplayedFilters = [];
618  foreach ( $this->getLegacyShowHideFilters() as $filterName => $filter ) {
619  $namesOfDisplayedFilters[] = $filterName;
620  $links[] = $this->showHideCheck(
621  $nondefaults,
622  $filter->getShowHide(),
623  $filterName,
624  $opts[ $filterName ],
625  $filter->isFeatureAvailableOnStructuredUi( $this )
626  );
627  }
628 
629  $hiddenFields = $nondefaults;
630  $hiddenFields['action'] = 'submit';
631  unset( $hiddenFields['namespace'] );
632  unset( $hiddenFields['invert'] );
633  unset( $hiddenFields['associated'] );
634  unset( $hiddenFields['days'] );
635  foreach ( $namesOfDisplayedFilters as $filterName ) {
636  unset( $hiddenFields[$filterName] );
637  }
638 
639  # Namespace filter and put the whole form together.
640  $form .= $wlInfo;
641  $form .= $cutofflinks;
642  $form .= Html::rawElement(
643  'span',
644  [ 'class' => 'clshowhide' ],
645  $this->msg( 'watchlist-hide' ) .
646  $this->msg( 'colon-separator' )->escaped() .
647  implode( ' ', $links )
648  );
649  $form .= "\n<br />\n";
650 
651  $namespaceForm = Html::namespaceSelector(
652  [
653  'selected' => $opts['namespace'],
654  'all' => '',
655  'label' => $this->msg( 'namespace' )->text()
656  ], [
657  'name' => 'namespace',
658  'id' => 'namespace',
659  'class' => 'namespaceselector',
660  ]
661  ) . "\n";
662  $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
663  $this->msg( 'invert' )->text(),
664  'invert',
665  'nsinvert',
666  $opts['invert'],
667  [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
668  ) . "</span>\n";
669  $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
670  $this->msg( 'namespace_association' )->text(),
671  'associated',
672  'nsassociated',
673  $opts['associated'],
674  [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
675  ) . "</span>\n";
676  $form .= Html::rawElement(
677  'span',
678  [ 'class' => 'namespaceForm cloption' ],
679  $namespaceForm
680  );
681 
682  $form .= Xml::submitButton(
683  $this->msg( 'watchlist-submit' )->text(),
684  [ 'class' => 'cloption-submit' ]
685  ) . "\n";
686  foreach ( $hiddenFields as $key => $value ) {
687  $form .= Html::hidden( $key, $value ) . "\n";
688  }
689  $form .= Xml::closeElement( 'fieldset' ) . "\n";
690  $form .= Xml::closeElement( 'form' ) . "\n";
691 
692  // Insert a placeholder for RCFilters
693  if ( $this->isStructuredFilterUiEnabled() ) {
694  $rcfilterContainer = Html::element(
695  'div',
696  [ 'class' => 'rcfilters-container' ]
697  );
698 
699  $loadingContainer = Html::rawElement(
700  'div',
701  [ 'class' => 'rcfilters-spinner' ],
703  'div',
704  [ 'class' => 'rcfilters-spinner-bounce' ]
705  )
706  );
707 
708  // Wrap both with rcfilters-head
709  $this->getOutput()->addHTML(
711  'div',
712  [ 'class' => 'rcfilters-head' ],
713  $rcfilterContainer . $form
714  )
715  );
716 
717  // Add spinner
718  $this->getOutput()->addHTML( $loadingContainer );
719  } else {
720  $this->getOutput()->addHTML( $form );
721  }
722 
723  $this->setBottomText( $opts );
724  }
725 
726  function cutoffselector( $options ) {
727  $selected = (float)$options['days'];
728  if ( $selected <= 0 ) {
729  $selected = $this->maxDays;
730  }
731 
732  $selectedHours = round( $selected * 24 );
733 
734  $hours = array_unique( array_filter( [
735  1,
736  2,
737  6,
738  12,
739  24,
740  72,
741  168,
742  24 * (float)$this->getUser()->getOption( 'watchlistdays', 0 ),
743  24 * $this->maxDays,
744  $selectedHours
745  ] ) );
746  asort( $hours );
747 
748  $select = new XmlSelect( 'days', 'days', (float)( $selectedHours / 24 ) );
749 
750  foreach ( $hours as $value ) {
751  if ( $value < 24 ) {
752  $name = $this->msg( 'hours' )->numParams( $value )->text();
753  } else {
754  $name = $this->msg( 'days' )->numParams( $value / 24 )->text();
755  }
756  $select->addOption( $name, (float)( $value / 24 ) );
757  }
758 
759  return $select->getHTML() . "\n<br />\n";
760  }
761 
762  function setTopText( FormOptions $opts ) {
763  $nondefaults = $opts->getChangedValues();
764  $form = '';
765  $user = $this->getUser();
766 
767  $numItems = $this->countItems();
768  $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
769 
770  // Show watchlist header
771  $watchlistHeader = '';
772  if ( $numItems == 0 ) {
773  $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
774  } else {
775  $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
776  if ( $this->getConfig()->get( 'EnotifWatchlist' )
777  && $user->getOption( 'enotifwatchlistpages' )
778  ) {
779  $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
780  }
781  if ( $showUpdatedMarker ) {
782  $watchlistHeader .= $this->msg(
783  $this->isStructuredFilterUiEnabled() ?
784  'rcfilters-watchlist-showupdated' :
785  'wlheader-showupdated'
786  )->parse() . "\n";
787  }
788  }
789  $form .= Html::rawElement(
790  'div',
791  [ 'class' => 'watchlistDetails' ],
792  $watchlistHeader
793  );
794 
795  if ( $numItems > 0 && $showUpdatedMarker ) {
796  $form .= Xml::openElement( 'form', [ 'method' => 'post',
797  'action' => $this->getPageTitle()->getLocalURL(),
798  'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
799  Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
800  [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
801  Html::hidden( 'token', $user->getEditToken() ) . "\n" .
802  Html::hidden( 'reset', 'all' ) . "\n";
803  foreach ( $nondefaults as $key => $value ) {
804  $form .= Html::hidden( $key, $value ) . "\n";
805  }
806  $form .= Xml::closeElement( 'form' ) . "\n";
807  }
808 
809  $this->getOutput()->addHTML( $form );
810  }
811 
812  protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
813  $options[$name] = 1 - (int)$value;
814 
815  $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
816  if ( $inStructuredUi ) {
817  $attribs[ 'data-feature-in-structured-ui' ] = true;
818  }
819 
820  return Html::rawElement(
821  'span',
822  $attribs,
823  // not using Html::checkLabel because that would escape the contents
824  Html::check( $name, (int)$value, [ 'id' => $name ] ) . Html::rawElement(
825  'label',
826  $attribs + [ 'for' => $name ],
827  // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags
828  $this->msg( $message, '<nowiki/>' )->parse()
829  )
830  );
831  }
832 
840  protected function countItems() {
841  $store = MediaWikiServices::getInstance()->getWatchedItemStore();
842  $count = $store->countWatchedItems( $this->getUser() );
843  return floor( $count / 2 );
844  }
845 }
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:34
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:678
SpecialEditWatchlist\EDIT_CLEAR
const EDIT_CLEAR
Editing modes.
Definition: SpecialEditWatchlist.php:46
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:279
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
SpecialEditWatchlist\EDIT_RAW
const EDIT_RAW
Definition: SpecialEditWatchlist.php:47
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
$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:2683
SpecialWatchlist\$savedQueriesPreferenceName
static $savedQueriesPreferenceName
Definition: SpecialWatchlist.php:35
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ChangesListSpecialPage\makeLegend
makeLegend()
Return the legend displayed within the fieldset.
Definition: ChangesListSpecialPage.php:1631
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:68
SpecialWatchlist\getSubpagesForPrefixSearch
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
Definition: SpecialWatchlist.php:123
SpecialWatchlist\getDB
getDB()
Return a IDatabase object for reading.
Definition: SpecialWatchlist.php:433
Html\check
static check( $name, $checked=false, array $attribs=[])
Convenience function to produce a checkbox (input element with type=checkbox)
Definition: Html.php:687
RC_LOG
const RC_LOG
Definition: Defines.php:144
ChangesListSpecialPage
Special page which uses a ChangesList to show query results.
Definition: ChangesListSpecialPage.php:35
$tables
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:1018
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:309
$params
$params
Definition: styleTest.css.php:44
$s
$s
Definition: mergeMessageFileList.php:187
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:82
SpecialWatchlist\__construct
__construct( $page='Watchlist', $restriction='viewmywatchlist')
Definition: SpecialWatchlist.php:42
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:755
SpecialWatchlist\doHeader
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
Definition: SpecialWatchlist.php:561
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:110
php
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
LIST_AND
const LIST_AND
Definition: Defines.php:43
SpecialWatchlist\doMainQuery
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
@inheritDoc
Definition: SpecialWatchlist.php:338
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
XmlSelect
Class for generating HTML <select> or <datalist> elements.
Definition: XmlSelect.php:26
$dbr
$dbr
Definition: testCompression.php:50
SpecialWatchlist\$maxDays
$maxDays
Definition: SpecialWatchlist.php:40
SpecialWatchlist\$collapsedPreferenceName
static $collapsedPreferenceName
Definition: SpecialWatchlist.php:38
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:783
Config
Interface for configuration instances.
Definition: Config.php:28
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:832
LIST_OR
const LIST_OR
Definition: Defines.php:46
SpecialWatchlist\transformFilterDefinition
transformFilterDefinition(array $filterDefinition)
@inheritDoc
Definition: SpecialWatchlist.php:134
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:764
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:814
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:2771
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
ChangesListSpecialPage\runMainQueryHook
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
Definition: ChangesListSpecialPage.php:1521
ChangesListSpecialPage\isStructuredFilterUiEnabled
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
Definition: ChangesListSpecialPage.php:1831
SpecialWatchlist\countItems
countItems()
Count the number of paired items on a user's watchlist.
Definition: SpecialWatchlist.php:840
$attribs
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:2044
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:134
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
SpecialWatchlist\cutoffselector
cutoffselector( $options)
Definition: SpecialWatchlist.php:726
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:735
$output
$output
Definition: SyntaxHighlight.php:334
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1983
array
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))
SpecialWatchlist\showHideCheck
showHideCheck( $options, $message, $name, $value, $inStructuredUi)
Definition: SpecialWatchlist.php:812
SpecialWatchlist\registerFilters
registerFilters()
@inheritDoc
Definition: SpecialWatchlist.php:145
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:34
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
SpecialPage\requireLogin
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:339
SpecialWatchlist
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
Definition: SpecialWatchlist.php:34
$request
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:2683
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:88
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
execute
$batch execute()
Html\hidden
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:795
EnhancedChangesList
Definition: EnhancedChangesList.php:23
SpecialWatchlist\execute
execute( $subpage)
Main execution point.
Definition: SpecialWatchlist.php:57
SpecialEditWatchlist\getMode
static getMode( $request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
Definition: SpecialEditWatchlist.php:709
$value
$value
Definition: styleTest.css.php:49
Html\namespaceSelector
static namespaceSelector(array $params=[], array $selectAttribs=[])
Build a drop-down box for selecting a namespace.
Definition: Html.php:883
ChangesListSpecialPage\getFilterGroup
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
Definition: ChangesListSpecialPage.php:1172
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:715
ChangesListStringOptionsFilterGroup\NONE
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
Definition: ChangesListStringOptionsFilterGroup.php:59
SpecialWatchlist\outputFeedLinks
outputFeedLinks()
Output feed links.
Definition: SpecialWatchlist.php:440
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:908
text
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
Definition: All_system_messages.txt:1267
ChangesListSpecialPage\areFiltersInConflict
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
Definition: ChangesListSpecialPage.php:580
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:735
SpecialWatchlist\doesWrites
doesWrites()
Indicates whether this special page may perform database writes.
Definition: SpecialWatchlist.php:48
ChangesListBooleanFilterGroup
If the group is active, any unchecked filters will translate to hide parameters in the URL.
Definition: ChangesListBooleanFilterGroup.php:12
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:119
$rows
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:2683
$options
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:2044
SpecialWatchlist\outputChangesList
outputChangesList( $rows, $opts)
Build and output the actual changes list.
Definition: SpecialWatchlist.php:459
as
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
SpecialWatchlist\$limitPreferenceName
static $limitPreferenceName
Definition: SpecialWatchlist.php:37
LogPage\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: LogPage.php:37
ChangesList
Definition: ChangesList.php:28
SpecialWatchlist\checkStructuredFilterUiEnabled
static checkStructuredFilterUiEnabled(Config $config, User $user)
Static method to check whether StructuredFilter UI is enabled for the given user.
Definition: SpecialWatchlist.php:113
class
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
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:146
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
$services
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:2278
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
MediaWikiServices
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
FormOptions\getChangedValues
getChangedValues()
Return options modified as an array ( name => value )
Definition: FormOptions.php:306
SpecialWatchlist\setTopText
setTopText(FormOptions $opts)
Send the text to be displayed before the options.
Definition: SpecialWatchlist.php:762
SpecialWatchlist\fetchOptionsFromRequest
fetchOptionsFromRequest( $opts)
Fetch values for a FormOptions object from the WebRequest associated with this instance.
Definition: SpecialWatchlist.php:293
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
ChangesListSpecialPage\setBottomText
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
Definition: ChangesListSpecialPage.php:1609
ChangesListSpecialPage\registerFilterGroup
registerFilterGroup(ChangesListFilterGroup $group)
Register a structured changes list filter group.
Definition: ChangesListSpecialPage.php:1150
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:942
SpecialWatchlist\$daysPreferenceName
static $daysPreferenceName
Definition: SpecialWatchlist.php:36
ChangesListSpecialPage\getLegacyShowHideFilters
getLegacyShowHideFilters()
Definition: ChangesListSpecialPage.php:1072
Xml\submitButton
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:461
Xml\checkLabel
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
Definition: Xml.php:421
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:813