MediaWiki REL1_30
SpecialWatchlist.php
Go to the documentation of this file.
1<?php
27
35 protected static $savedQueriesPreferenceName = 'rcfilters-wl-saved-queries';
36
37 private $maxDays;
38
39 public function __construct( $page = 'Watchlist', $restriction = 'viewmywatchlist' ) {
40 parent::__construct( $page, $restriction );
41
42 $this->maxDays = $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 );
43 }
44
45 public function doesWrites() {
46 return true;
47 }
48
54 function execute( $subpage ) {
55 // Anons don't get a watchlist
56 $this->requireLogin( 'watchlistanontext' );
57
58 $output = $this->getOutput();
59 $request = $this->getRequest();
60 $this->addHelpLink( 'Help:Watching pages' );
61 $output->addModules( [
62 'mediawiki.special.changeslist.visitedstatus',
63 'mediawiki.special.watchlist',
64 ] );
65 $output->addModuleStyles( [ 'mediawiki.special.watchlist.styles' ] );
66
67 $mode = SpecialEditWatchlist::getMode( $request, $subpage );
68 if ( $mode !== false ) {
69 if ( $mode === SpecialEditWatchlist::EDIT_RAW ) {
70 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' );
71 } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) {
72 $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' );
73 } else {
74 $title = SpecialPage::getTitleFor( 'EditWatchlist' );
75 }
76
77 $output->redirect( $title->getLocalURL() );
78
79 return;
80 }
81
82 $this->checkPermissions();
83
84 $user = $this->getUser();
85 $opts = $this->getOptions();
86
87 $config = $this->getConfig();
88 if ( ( $config->get( 'EnotifWatchlist' ) || $config->get( 'ShowUpdatedMarker' ) )
89 && $request->getVal( 'reset' )
90 && $request->wasPosted()
91 && $user->matchEditToken( $request->getVal( 'token' ) )
92 ) {
93 $user->clearAllNotifications();
94 $output->redirect( $this->getPageTitle()->getFullURL( $opts->getChangedValues() ) );
95
96 return;
97 }
98
99 parent::execute( $subpage );
100
101 if ( $this->isStructuredFilterUiEnabled() ) {
102 $output->addModuleStyles( [ 'mediawiki.rcfilters.highlightCircles.seenunseen.styles' ] );
103
104 $output->addJsConfigVars( 'wgStructuredChangeFiltersLiveUpdateSupported', false );
105 $output->addJsConfigVars(
106 'wgStructuredChangeFiltersEditWatchlistUrl',
107 SpecialPage::getTitleFor( 'EditWatchlist' )->getLocalURL()
108 );
109 }
110 }
111
112 public function isStructuredFilterUiEnabled() {
113 return $this->getRequest()->getBool( 'rcfilters' ) || (
114 $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
115 $this->getUser()->getOption( 'rcenhancedfilters' )
116 );
117 }
118
120 return $this->getConfig()->get( 'StructuredChangeFiltersOnWatchlist' ) &&
121 $this->getUser()->getDefaultOption( 'rcenhancedfilters' );
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',
192 'class' => ChangesListStringOptionsFilterGroup::class,
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, $rc ) {
202 $changeTs = $rc->getAttribute( 'rc_timestamp' );
203 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
204 return $lastVisitTs !== null && $changeTs >= $lastVisitTs;
205 },
206 ],
207 [
208 'name' => 'seen',
209 'label' => 'rcfilters-filter-watchlistactivity-seen-label',
210 'description' => 'rcfilters-filter-watchlistactivity-seen-description',
211 'cssClassSuffix' => 'watchedseen',
212 'isRowApplicableCallable' => function ( $ctx, $rc ) {
213 $changeTs = $rc->getAttribute( 'rc_timestamp' );
214 $lastVisitTs = $rc->getAttribute( 'wl_notificationtimestamp' );
215 return $lastVisitTs === null || $changeTs < $lastVisitTs;
216 }
217 ],
218 ],
220 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
221 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
222 if ( $selectedValues === [ 'seen' ] ) {
223 $conds[] = $dbr->makeList( [
224 'wl_notificationtimestamp IS NULL',
225 'rc_timestamp < wl_notificationtimestamp'
226 ], LIST_OR );
227 } elseif ( $selectedValues === [ 'unseen' ] ) {
228 $conds[] = $dbr->makeList( [
229 'wl_notificationtimestamp IS NOT NULL',
230 'rc_timestamp >= wl_notificationtimestamp'
231 ], LIST_AND );
232 }
233 }
234 ] ) );
235
236 $user = $this->getUser();
237
238 $significance = $this->getFilterGroup( 'significance' );
239 $hideMinor = $significance->getFilter( 'hideminor' );
240 $hideMinor->setDefault( $user->getBoolOption( 'watchlisthideminor' ) );
241
242 $automated = $this->getFilterGroup( 'automated' );
243 $hideBots = $automated->getFilter( 'hidebots' );
244 $hideBots->setDefault( $user->getBoolOption( 'watchlisthidebots' ) );
245
246 $registration = $this->getFilterGroup( 'registration' );
247 $hideAnons = $registration->getFilter( 'hideanons' );
248 $hideAnons->setDefault( $user->getBoolOption( 'watchlisthideanons' ) );
249 $hideLiu = $registration->getFilter( 'hideliu' );
250 $hideLiu->setDefault( $user->getBoolOption( 'watchlisthideliu' ) );
251
252 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
253 if ( $reviewStatus !== null ) {
254 // Conditional on feature being available and rights
255 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
256 $hidePatrolled->setDefault( $user->getBoolOption( 'watchlisthidepatrolled' ) );
257 }
258
259 $authorship = $this->getFilterGroup( 'authorship' );
260 $hideMyself = $authorship->getFilter( 'hidemyself' );
261 $hideMyself->setDefault( $user->getBoolOption( 'watchlisthideown' ) );
262
263 $changeType = $this->getFilterGroup( 'changeType' );
264 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
265 if ( $hideCategorization !== null ) {
266 // Conditional on feature being available
267 $hideCategorization->setDefault( $user->getBoolOption( 'watchlisthidecategorization' ) );
268 }
269 }
270
276 public function getDefaultOptions() {
277 $opts = parent::getDefaultOptions();
278
279 $opts->add( 'days', $this->getDefaultDays(), FormOptions::FLOAT );
280 $opts->add( 'limit', $this->getDefaultLimit(), FormOptions::INT );
281
282 return $opts;
283 }
284
285 public function validateOptions( FormOptions $opts ) {
286 $opts->validateBounds( 'days', 0, $this->maxDays );
287 $opts->validateIntBounds( 'limit', 0, 5000 );
288 parent::validateOptions( $opts );
289 }
290
296 protected function getCustomFilters() {
297 if ( $this->customFilters === null ) {
298 $this->customFilters = parent::getCustomFilters();
299 Hooks::run( 'SpecialWatchlistFilters', [ $this, &$this->customFilters ], '1.23' );
300 }
301
303 }
304
314 protected function fetchOptionsFromRequest( $opts ) {
315 static $compatibilityMap = [
316 'hideMinor' => 'hideminor',
317 'hideBots' => 'hidebots',
318 'hideAnons' => 'hideanons',
319 'hideLiu' => 'hideliu',
320 'hidePatrolled' => 'hidepatrolled',
321 'hideOwn' => 'hidemyself',
322 ];
323
324 $params = $this->getRequest()->getValues();
325 foreach ( $compatibilityMap as $from => $to ) {
326 if ( isset( $params[$from] ) ) {
327 $params[$to] = $params[$from];
328 unset( $params[$from] );
329 }
330 }
331
332 if ( $this->getRequest()->getVal( 'action' ) == 'submit' ) {
333 $allBooleansFalse = [];
334
335 // If the user submitted the form, start with a baseline of "all
336 // booleans are false", then change the ones they checked. This
337 // means we ignore the defaults.
338
339 // This is how we handle the fact that HTML forms don't submit
340 // unchecked boxes.
341 foreach ( $this->filterGroups as $filterGroup ) {
342 if ( $filterGroup instanceof ChangesListBooleanFilterGroup ) {
344 foreach ( $filterGroup->getFilters() as $filter ) {
345 if ( $filter->displaysOnUnstructuredUi() ) {
346 $allBooleansFalse[$filter->getName()] = false;
347 }
348 }
349 }
350 }
351
352 $params = $params + $allBooleansFalse;
353 }
354
355 // Not the prettiest way to achieve this… FormOptions internally depends on data sanitization
356 // methods defined on WebRequest and removing this dependency would cause some code duplication.
357 $request = new DerivativeRequest( $this->getRequest(), $params );
358 $opts->fetchValuesFromRequest( $request );
359
360 return $opts;
361 }
362
366 protected function buildQuery( &$tables, &$fields, &$conds, &$query_options,
367 &$join_conds, FormOptions $opts
368 ) {
369 $dbr = $this->getDB();
370 parent::buildQuery( $tables, $fields, $conds, $query_options, $join_conds,
371 $opts );
372
373 // Calculate cutoff
374 if ( $opts['days'] > 0 ) {
375 $conds[] = 'rc_timestamp > ' .
376 $dbr->addQuotes( $dbr->timestamp( time() - $opts['days'] * 3600 * 24 ) );
377 }
378 }
379
383 protected function doMainQuery( $tables, $fields, $conds, $query_options,
384 $join_conds, FormOptions $opts
385 ) {
386 $dbr = $this->getDB();
387 $user = $this->getUser();
388
389 $tables = array_merge( [ 'recentchanges', 'watchlist' ], $tables );
390 $fields = array_merge( RecentChange::selectFields(), $fields );
391
392 $join_conds = array_merge(
393 [
394 'watchlist' => [
395 'INNER JOIN',
396 [
397 'wl_user' => $user->getId(),
398 'wl_namespace=rc_namespace',
399 'wl_title=rc_title'
400 ],
401 ],
402 ],
403 $join_conds
404 );
405
406 $tables[] = 'page';
407 $fields[] = 'page_latest';
408 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
409
410 $fields[] = 'wl_notificationtimestamp';
411
412 // Log entries with DELETED_ACTION must not show up unless the user has
413 // the necessary rights.
414 if ( !$user->isAllowed( 'deletedhistory' ) ) {
415 $bitmask = LogPage::DELETED_ACTION;
416 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
418 } else {
419 $bitmask = 0;
420 }
421 if ( $bitmask ) {
422 $conds[] = $dbr->makeList( [
423 'rc_type != ' . RC_LOG,
424 $dbr->bitAnd( 'rc_deleted', $bitmask ) . " != $bitmask",
425 ], LIST_OR );
426 }
427
428 $tagFilter = $opts['tagfilter'] ? explode( '|', $opts['tagfilter'] ) : [];
430 $tables,
431 $fields,
432 $conds,
433 $join_conds,
434 $query_options,
435 $tagFilter
436 );
437
438 $this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts );
439
440 if ( $this->areFiltersInConflict() ) {
441 return false;
442 }
443
444 $orderByAndLimit = [
445 'ORDER BY' => 'rc_timestamp DESC',
446 'LIMIT' => $opts['limit']
447 ];
448 if ( in_array( 'DISTINCT', $query_options ) ) {
449 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
450 // In order to prevent DISTINCT from causing query performance problems,
451 // we have to GROUP BY the primary key. This in turn requires us to add
452 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
453 // start of the GROUP BY
454 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
455 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
456 }
457 // array_merge() is used intentionally here so that hooks can, should
458 // they so desire, override the ORDER BY / LIMIT condition(s)
459 $query_options = array_merge( $orderByAndLimit, $query_options );
460
461 return $dbr->select(
462 $tables,
463 $fields,
464 $conds,
465 __METHOD__,
466 $query_options,
467 $join_conds
468 );
469 }
470
471 protected function runMainQueryHook( &$tables, &$fields, &$conds, &$query_options,
472 &$join_conds, $opts
473 ) {
474 return parent::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
475 && Hooks::run(
476 'SpecialWatchlistQuery',
477 [ &$conds, &$tables, &$join_conds, &$fields, $opts ],
478 '1.23'
479 );
480 }
481
487 protected function getDB() {
488 return wfGetDB( DB_REPLICA, 'watchlist' );
489 }
490
494 public function outputFeedLinks() {
495 $user = $this->getUser();
496 $wlToken = $user->getTokenFromOption( 'watchlisttoken' );
497 if ( $wlToken ) {
498 $this->addFeedLinks( [
499 'action' => 'feedwatchlist',
500 'allrev' => 1,
501 'wlowner' => $user->getName(),
502 'wltoken' => $wlToken,
503 ] );
504 }
505 }
506
513 public function outputChangesList( $rows, $opts ) {
514 $dbr = $this->getDB();
515 $user = $this->getUser();
516 $output = $this->getOutput();
517
518 # Show a message about replica DB lag, if applicable
519 $lag = wfGetLB()->safeGetLag( $dbr );
520 if ( $lag > 0 ) {
521 $output->showLagWarning( $lag );
522 }
523
524 # If no rows to display, show message before try to render the list
525 if ( $rows->numRows() == 0 ) {
526 $output->wrapWikiMsg(
527 "<div class='mw-changeslist-empty'>\n$1\n</div>", 'recentchanges-noresult'
528 );
529 return;
530 }
531
532 $dbr->dataSeek( $rows, 0 );
533
534 $list = ChangesList::newFromContext( $this->getContext(), $this->filterGroups );
535 $list->setWatchlistDivs();
536 $list->initChangesListRows( $rows );
537 if ( $user->getOption( 'watchlistunwatchlinks' ) ) {
538 $list->setChangeLinePrefixer( function ( RecentChange $rc, ChangesList $cl, $grouped ) {
539 // Don't show unwatch link if the line is a grouped log entry using EnhancedChangesList,
540 // since EnhancedChangesList groups log entries by performer rather than by target article
541 if ( $rc->mAttribs['rc_type'] == RC_LOG && $cl instanceof EnhancedChangesList &&
542 $grouped ) {
543 return '';
544 } else {
545 return $this->getLinkRenderer()
546 ->makeKnownLink( $rc->getTitle(),
547 $this->msg( 'watchlist-unwatch' )->text(), [
548 'class' => 'mw-unwatch-link',
549 'title' => $this->msg( 'tooltip-ca-unwatch' )->text()
550 ], [ 'action' => 'unwatch' ] ) . '&#160;';
551 }
552 } );
553 }
554 $dbr->dataSeek( $rows, 0 );
555
556 if ( $this->getConfig()->get( 'RCShowWatchingUsers' )
557 && $user->getOption( 'shownumberswatching' )
558 ) {
559 $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
560 }
561
562 $s = $list->beginRecentChangesList();
563
564 if ( $this->isStructuredFilterUiEnabled() ) {
565 $s .= $this->makeLegend();
566 }
567
568 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
569 $counter = 1;
570 foreach ( $rows as $obj ) {
571 # Make RC entry
572 $rc = RecentChange::newFromRow( $obj );
573
574 # Skip CatWatch entries for hidden cats based on user preference
575 if (
576 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE &&
577 !$userShowHiddenCats &&
578 $rc->getParam( 'hidden-cat' )
579 ) {
580 continue;
581 }
582
583 $rc->counter = $counter++;
584
585 if ( $this->getConfig()->get( 'ShowUpdatedMarker' ) ) {
586 $updated = $obj->wl_notificationtimestamp;
587 } else {
588 $updated = false;
589 }
590
591 if ( isset( $watchedItemStore ) ) {
592 $rcTitleValue = new TitleValue( (int)$obj->rc_namespace, $obj->rc_title );
593 $rc->numberofWatchingusers = $watchedItemStore->countWatchers( $rcTitleValue );
594 } else {
595 $rc->numberofWatchingusers = 0;
596 }
597
598 $changeLine = $list->recentChangesLine( $rc, $updated, $counter );
599 if ( $changeLine !== false ) {
600 $s .= $changeLine;
601 }
602 }
603 $s .= $list->endRecentChangesList();
604
605 $output->addHTML( $s );
606 }
607
614 public function doHeader( $opts, $numRows ) {
615 $user = $this->getUser();
616 $out = $this->getOutput();
617
618 $out->addSubtitle(
619 $this->msg( 'watchlistfor2', $user->getName() )
621 $this->getLanguage(),
622 $this->getLinkRenderer()
623 ) )
624 );
625
626 $this->setTopText( $opts );
627
628 $form = '';
629
630 $form .= Xml::openElement( 'form', [
631 'method' => 'get',
632 'action' => wfScript(),
633 'id' => 'mw-watchlist-form'
634 ] );
635 $form .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() );
636 $form .= Xml::openElement(
637 'fieldset',
638 [ 'id' => 'mw-watchlist-options', 'class' => 'cloptions' ]
639 );
640 $form .= Xml::element(
641 'legend', null, $this->msg( 'watchlist-options' )->text()
642 );
643
644 if ( !$this->isStructuredFilterUiEnabled() ) {
645 $form .= $this->makeLegend();
646 }
647
648 $lang = $this->getLanguage();
649 if ( $opts['days'] > 0 ) {
650 $days = $opts['days'];
651 } else {
652 $days = $this->maxDays;
653 }
654 $timestamp = wfTimestampNow();
655 $wlInfo = Html::rawElement(
656 'span',
657 [ 'class' => 'wlinfo' ],
658 $this->msg( 'wlnote' )->numParams( $numRows, round( $days * 24 ) )->params(
659 $lang->userDate( $timestamp, $user ), $lang->userTime( $timestamp, $user )
660 )->parse()
661 ) . "<br />\n";
662
663 $nondefaults = $opts->getChangedValues();
664 $cutofflinks = Html::rawElement(
665 'span',
666 [ 'class' => 'cldays cloption' ],
667 $this->msg( 'wlshowtime' ) . ' ' . $this->cutoffselector( $opts )
668 );
669
670 # Spit out some control panel links
671 $links = [];
672 $namesOfDisplayedFilters = [];
673 foreach ( $this->getFilterGroups() as $groupName => $group ) {
674 if ( !$group->isPerGroupRequestParameter() ) {
675 foreach ( $group->getFilters() as $filterName => $filter ) {
676 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
677 $namesOfDisplayedFilters[] = $filterName;
678 $links[] = $this->showHideCheck(
679 $nondefaults,
680 $filter->getShowHide(),
681 $filterName,
682 $opts[$filterName],
683 $filter->isFeatureAvailableOnStructuredUi( $this )
684 );
685 }
686 }
687 }
688 }
689
690 $hiddenFields = $nondefaults;
691 $hiddenFields['action'] = 'submit';
692 unset( $hiddenFields['namespace'] );
693 unset( $hiddenFields['invert'] );
694 unset( $hiddenFields['associated'] );
695 unset( $hiddenFields['days'] );
696 foreach ( $namesOfDisplayedFilters as $filterName ) {
697 unset( $hiddenFields[$filterName] );
698 }
699
700 # Namespace filter and put the whole form together.
701 $form .= $wlInfo;
702 $form .= $cutofflinks;
703 $form .= Html::rawElement(
704 'span',
705 [ 'class' => 'clshowhide' ],
706 $this->msg( 'watchlist-hide' ) .
707 $this->msg( 'colon-separator' )->escaped() .
708 implode( ' ', $links )
709 );
710 $form .= "\n<br />\n";
711
712 $namespaceForm = Html::namespaceSelector(
713 [
714 'selected' => $opts['namespace'],
715 'all' => '',
716 'label' => $this->msg( 'namespace' )->text()
717 ], [
718 'name' => 'namespace',
719 'id' => 'namespace',
720 'class' => 'namespaceselector',
721 ]
722 ) . "\n";
723 $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
724 $this->msg( 'invert' )->text(),
725 'invert',
726 'nsinvert',
727 $opts['invert'],
728 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
729 ) . "</span>\n";
730 $namespaceForm .= '<span class="mw-input-with-label">' . Xml::checkLabel(
731 $this->msg( 'namespace_association' )->text(),
732 'associated',
733 'nsassociated',
734 $opts['associated'],
735 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
736 ) . "</span>\n";
737 $form .= Html::rawElement(
738 'span',
739 [ 'class' => 'namespaceForm cloption' ],
740 $namespaceForm
741 );
742
743 $form .= Xml::submitButton(
744 $this->msg( 'watchlist-submit' )->text(),
745 [ 'class' => 'cloption-submit' ]
746 ) . "\n";
747 foreach ( $hiddenFields as $key => $value ) {
748 $form .= Html::hidden( $key, $value ) . "\n";
749 }
750 $form .= Xml::closeElement( 'fieldset' ) . "\n";
751 $form .= Xml::closeElement( 'form' ) . "\n";
752
753 // Insert a placeholder for RCFilters
754 if ( $this->isStructuredFilterUiEnabled() ) {
755 $rcfilterContainer = Html::element(
756 'div',
757 [ 'class' => 'rcfilters-container' ]
758 );
759
760 $loadingContainer = Html::rawElement(
761 'div',
762 [ 'class' => 'rcfilters-spinner' ],
763 Html::element(
764 'div',
765 [ 'class' => 'rcfilters-spinner-bounce' ]
766 )
767 );
768
769 // Wrap both with rcfilters-head
770 $this->getOutput()->addHTML(
771 Html::rawElement(
772 'div',
773 [ 'class' => 'rcfilters-head' ],
774 $rcfilterContainer . $form
775 )
776 );
777
778 // Add spinner
779 $this->getOutput()->addHTML( $loadingContainer );
780 } else {
781 $this->getOutput()->addHTML( $form );
782 }
783
784 $this->setBottomText( $opts );
785 }
786
788 // Cast everything to strings immediately, so that we know all of the values have the same
789 // precision, and can be compared with '==='. 2/24 has a few more decimal places than its
790 // default string representation, for example, and would confuse comparisons.
791
792 // Misleadingly, the 'days' option supports hours too.
793 $days = array_map( 'strval', [ 1 / 24, 2 / 24, 6 / 24, 12 / 24, 1, 3, 7 ] );
794
795 $userWatchlistOption = (string)$this->getUser()->getOption( 'watchlistdays' );
796 // add the user preference, if it isn't available already
797 if ( !in_array( $userWatchlistOption, $days ) && $userWatchlistOption !== '0' ) {
798 $days[] = $userWatchlistOption;
799 }
800
801 $maxDays = (string)$this->maxDays;
802 // add the maximum possible value, if it isn't available already
803 if ( !in_array( $maxDays, $days ) ) {
804 $days[] = $maxDays;
805 }
806
807 $selected = (string)$options['days'];
808 if ( $selected <= 0 ) {
809 $selected = $maxDays;
810 }
811
812 // add the currently selected value, if it isn't available already
813 if ( !in_array( $selected, $days ) ) {
814 $days[] = $selected;
815 }
816
817 $select = new XmlSelect( 'days', 'days', $selected );
818
819 asort( $days );
820 foreach ( $days as $value ) {
821 if ( $value < 1 ) {
822 $name = $this->msg( 'hours' )->numParams( $value * 24 )->text();
823 } else {
824 $name = $this->msg( 'days' )->numParams( $value )->text();
825 }
826 $select->addOption( $name, $value );
827 }
828
829 return $select->getHTML() . "\n<br />\n";
830 }
831
832 function setTopText( FormOptions $opts ) {
833 $nondefaults = $opts->getChangedValues();
834 $form = '';
835 $user = $this->getUser();
836
837 $numItems = $this->countItems();
838 $showUpdatedMarker = $this->getConfig()->get( 'ShowUpdatedMarker' );
839
840 // Show watchlist header
841 $watchlistHeader = '';
842 if ( $numItems == 0 ) {
843 $watchlistHeader = $this->msg( 'nowatchlist' )->parse();
844 } else {
845 $watchlistHeader .= $this->msg( 'watchlist-details' )->numParams( $numItems )->parse() . "\n";
846 if ( $this->getConfig()->get( 'EnotifWatchlist' )
847 && $user->getOption( 'enotifwatchlistpages' )
848 ) {
849 $watchlistHeader .= $this->msg( 'wlheader-enotif' )->parse() . "\n";
850 }
851 if ( $showUpdatedMarker ) {
852 $watchlistHeader .= $this->msg(
854 'rcfilters-watchlist-showupdated' :
855 'wlheader-showupdated'
856 )->parse() . "\n";
857 }
858 }
859 $form .= Html::rawElement(
860 'div',
861 [ 'class' => 'watchlistDetails' ],
862 $watchlistHeader
863 );
864
865 if ( $numItems > 0 && $showUpdatedMarker ) {
866 $form .= Xml::openElement( 'form', [ 'method' => 'post',
867 'action' => $this->getPageTitle()->getLocalURL(),
868 'id' => 'mw-watchlist-resetbutton' ] ) . "\n" .
869 Xml::submitButton( $this->msg( 'enotif_reset' )->text(),
870 [ 'name' => 'mw-watchlist-reset-submit' ] ) . "\n" .
871 Html::hidden( 'token', $user->getEditToken() ) . "\n" .
872 Html::hidden( 'reset', 'all' ) . "\n";
873 foreach ( $nondefaults as $key => $value ) {
874 $form .= Html::hidden( $key, $value ) . "\n";
875 }
876 $form .= Xml::closeElement( 'form' ) . "\n";
877 }
878
879 $this->getOutput()->addHTML( $form );
880 }
881
882 protected function showHideCheck( $options, $message, $name, $value, $inStructuredUi ) {
883 $options[$name] = 1 - (int)$value;
884
885 $attribs = [ 'class' => 'mw-input-with-label clshowhideoption cloption' ];
886 if ( $inStructuredUi ) {
887 $attribs[ 'data-feature-in-structured-ui' ] = true;
888 }
889
890 return Html::rawElement(
891 'span',
892 $attribs,
893 Xml::checkLabel(
894 $this->msg( $message, '' )->text(),
895 $name,
896 $name,
897 (int)$value
898 )
899 );
900 }
901
909 protected function countItems() {
910 $store = MediaWikiServices::getInstance()->getWatchedItemStore();
911 $count = $store->countWatchedItems( $this->getUser() );
912 return floor( $count / 2 );
913 }
914
915 function getDefaultLimit() {
916 return $this->getUser()->getIntOption( 'wllimit' );
917 }
918
919 function getDefaultDays() {
920 return floatval( $this->getUser()->getOption( 'watchlistdays' ) );
921 }
922}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetLB( $wiki=false)
Get a load balancer object.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
If the group is active, any unchecked filters will translate to hide parameters in the URL.
Special page which uses a ChangesList to show query results.
getFilterGroup( $groupName)
Gets a specified ChangesListFilterGroup by name.
areFiltersInConflict()
Check if filters are in conflict and guaranteed to return no results.
getFilterGroups()
Gets the currently registered filters groups.
registerFilterGroup(ChangesListFilterGroup $group)
Register a structured changes list filter group.
getOptions()
Get the current FormOptions for this request.
setBottomText(FormOptions $opts)
Send the text to be displayed after the options.
makeLegend()
Return the legend displayed within the fieldset.
Represents a filter group with multiple string options.
const NONE
Signifies that no options in the group are selected, meaning the group has no effect.
static newFromContext(IContextSource $context, array $groups=[])
Fetch an appropriate changes list class for the specified context Some users might want to use an enh...
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Helper class to keep track of options when mixing links and form elements.
const FLOAT
Float type, maps guessType() to WebRequest::getFloat()
validateBounds( $name, $min, $max)
Constrain a numeric value for a given option to a given range.
validateIntBounds( $name, $min, $max)
const INT
Integer type, maps guessType() to WebRequest::getInt()
getChangedValues()
Return options modified as an array ( name => value )
const DELETED_RESTRICTED
Definition LogPage.php:35
const DELETED_ACTION
Definition LogPage.php:32
MediaWikiServices is the service locator for the application scope of MediaWiki.
Utility class for creating new RC entries.
static newFromRow( $row)
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
static buildTools( $lang, LinkRenderer $linkRenderer=null)
Build a set of links for convenient navigation between watchlist viewing and editing modes.
const EDIT_CLEAR
Editing modes.
static getMode( $request, $par)
Determine whether we are editing the watchlist, and if so, what kind of editing operation.
getOutput()
Get the OutputPage being used for this instance.
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.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
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,...
addFeedLinks( $params)
Adds RSS/atom links.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
__construct( $page='Watchlist', $restriction='viewmywatchlist')
getCustomFilters()
Get all custom filters.
outputFeedLinks()
Output feed links.
doHeader( $opts, $numRows)
Set the text to be displayed above the changes.
showHideCheck( $options, $message, $name, $value, $inStructuredUi)
getDefaultOptions()
Get a FormOptions object containing the default options.
getSubpagesForPrefixSearch()
Return an array of subpages that this special page will accept.
runMainQueryHook(&$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts)
getDefaultDays()
Get the default value of the number of days to display when loading the result set.
fetchOptionsFromRequest( $opts)
Fetch values for a FormOptions object from the WebRequest associated with this instance.
doMainQuery( $tables, $fields, $conds, $query_options, $join_conds, FormOptions $opts)
@inheritDoc
static $savedQueriesPreferenceName
isStructuredFilterUiEnabledByDefault()
Check whether the structured filter UI is enabled by default (regardless of this particular user's se...
getDB()
Return a IDatabase object for reading.
transformFilterDefinition(array $filterDefinition)
@inheritDoc
countItems()
Count the number of paired items on a user's watchlist.
setTopText(FormOptions $opts)
Send the text to be displayed before the options.
execute( $subpage)
Main execution point.
registerFilters()
@inheritDoc
validateOptions(FormOptions $opts)
Validate a FormOptions object generated by getDefaultOptions() with values already populated.
outputChangesList( $rows, $opts)
Build and output the actual changes list.
isStructuredFilterUiEnabled()
Check whether the structured filter UI is enabled.
buildQuery(&$tables, &$fields, &$conds, &$query_options, &$join_conds, FormOptions $opts)
@inheritDoc
doesWrites()
Indicates whether this special page may perform database writes.
Represents a page (or page fragment) title within MediaWiki.
Result wrapper for grabbing data queried from an IDatabase object.
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:26
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
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
const LIST_OR
Definition Defines.php:47
const RC_LOG
Definition Defines.php:145
const LIST_AND
Definition Defines.php:44
const RC_CATEGORIZE
Definition Defines.php:147
the array() calling protocol came about after MediaWiki 1.4rc1.
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:2746
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:2775
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2225
this hook is for auditing only RecentChangesLinked and Watchlist 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:1013
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition hooks.txt:181
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:1971
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:2780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:962
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:862
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
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:1984
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 local account $user
Definition hooks.txt:247
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:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
const DB_REPLICA
Definition defines.php:25
$params
if(!isset( $args[0])) $lang