3 * Implements Special:Recentchanges
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
24 use MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\ResultWrapper
;
26 use Wikimedia\Rdbms\FakeResultWrapper
;
29 * A special page that lists last changes made to the wiki
31 * @ingroup SpecialPage
33 class SpecialRecentChanges
extends ChangesListSpecialPage
{
35 private $watchlistFilterGroupDefinition;
37 // @codingStandardsIgnoreStart Needed "useless" override to change parameters.
38 public function __construct( $name = 'Recentchanges', $restriction = '' ) {
39 parent
::__construct( $name, $restriction );
41 $this->watchlistFilterGroupDefinition
= [
42 'name' => 'watchlist',
43 'title' => 'rcfilters-filtergroup-watchlist',
44 'class' => ChangesListStringOptionsFilterGroup
::class,
46 'isFullCoverage' => true,
50 'label' => 'rcfilters-filter-watchlist-watched-label',
51 'description' => 'rcfilters-filter-watchlist-watched-description',
52 'cssClassSuffix' => 'watched',
53 'isRowApplicableCallable' => function ( $ctx, $rc ) {
54 return $rc->getAttribute( 'wl_user' );
58 'name' => 'watchednew',
59 'label' => 'rcfilters-filter-watchlist-watchednew-label',
60 'description' => 'rcfilters-filter-watchlist-watchednew-description',
61 'cssClassSuffix' => 'watchednew',
62 'isRowApplicableCallable' => function ( $ctx, $rc ) {
63 return $rc->getAttribute( 'wl_user' ) &&
64 $rc->getAttribute( 'rc_timestamp' ) &&
65 $rc->getAttribute( 'wl_notificationtimestamp' ) &&
66 $rc->getAttribute( 'rc_timestamp' ) >= $rc->getAttribute( 'wl_notificationtimestamp' );
70 'name' => 'notwatched',
71 'label' => 'rcfilters-filter-watchlist-notwatched-label',
72 'description' => 'rcfilters-filter-watchlist-notwatched-description',
73 'cssClassSuffix' => 'notwatched',
74 'isRowApplicableCallable' => function ( $ctx, $rc ) {
75 return $rc->getAttribute( 'wl_user' ) === null;
79 'default' => ChangesListStringOptionsFilterGroup
::NONE
,
80 'queryCallable' => function ( $specialPageClassName, $context, $dbr,
81 &$tables, &$fields, &$conds, &$query_options, &$join_conds, $selectedValues ) {
82 sort( $selectedValues );
83 $notwatchedCond = 'wl_user IS NULL';
84 $watchedCond = 'wl_user IS NOT NULL';
85 $newCond = 'rc_timestamp >= wl_notificationtimestamp';
87 if ( $selectedValues === [ 'notwatched' ] ) {
88 $conds[] = $notwatchedCond;
92 if ( $selectedValues === [ 'watched' ] ) {
93 $conds[] = $watchedCond;
97 if ( $selectedValues === [ 'watchednew' ] ) {
98 $conds[] = $dbr->makeList( [
105 if ( $selectedValues === [ 'notwatched', 'watched' ] ) {
110 if ( $selectedValues === [ 'notwatched', 'watchednew' ] ) {
111 $conds[] = $dbr->makeList( [
121 if ( $selectedValues === [ 'watched', 'watchednew' ] ) {
122 $conds[] = $watchedCond;
126 if ( $selectedValues === [ 'notwatched', 'watched', 'watchednew' ] ) {
133 // @codingStandardsIgnoreEnd
136 * Main execution point
138 * @param string $subpage
140 public function execute( $subpage ) {
141 // Backwards-compatibility: redirect to new feed URLs
142 $feedFormat = $this->getRequest()->getVal( 'feed' );
143 if ( !$this->including() && $feedFormat ) {
144 $query = $this->getFeedQuery();
145 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
146 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
151 // 10 seconds server-side caching max
152 $out = $this->getOutput();
153 $out->setCdnMaxage( 10 );
154 // Check if the client has a cached version
155 $lastmod = $this->checkLastModified();
156 if ( $lastmod === false ) {
161 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
164 parent
::execute( $subpage );
166 if ( $this->isStructuredFilterUiEnabled() ) {
167 $jsData = $this->getStructuredFilterJsData();
170 foreach ( $jsData['messageKeys'] as $key ) {
171 $messages[$key] = $this->msg( $key )->plain();
175 ResourceLoader
::makeInlineScript(
176 ResourceLoader
::makeMessageSetScript( $messages )
180 $experimentalStructuredChangeFilters =
181 $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' );
183 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
184 $out->addJsConfigVars(
185 'wgStructuredChangeFiltersEnableSaving',
186 $this->getConfig()->get( 'StructuredChangeFiltersEnableSaving' )
188 $out->addJsConfigVars(
189 'wgStructuredChangeFiltersEnableExperimentalViews',
190 $experimentalStructuredChangeFilters
192 $out->addJsConfigVars(
193 'wgStructuredChangeFiltersEnableLiveUpdate',
194 $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
196 if ( $experimentalStructuredChangeFilters ) {
197 $out->addJsConfigVars(
198 'wgRCFiltersChangeTags',
199 $this->buildChangeTagList()
206 * Fetch the change tags list for the front end
208 * @return Array Tag data
210 protected function buildChangeTagList() {
211 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
212 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
214 // Hit counts disabled for perf reasons, see T169997
216 $tagStats = ChangeTags::tagUsageStatistics();
217 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
220 arsort( $tagHitCounts );
222 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags );
224 // Build the list and data
226 foreach ( $tagHitCounts as $tagName => $hits ) {
228 // Only get active tags
229 isset( $explicitlyDefinedTags[ $tagName ] ) ||
230 isset( $softwareActivatedTags[ $tagName ] )
233 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
237 'label' => Sanitizer
::stripAllTags(
238 ChangeTags
::tagDescription( $tagName, $this->getContext() )
240 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
241 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
247 // Instead of sorting by hit count (disabled, see above), sort by display name
248 usort( $result, function ( $a, $b ) {
249 return strcasecmp( $a['label'], $b['label'] );
258 protected function transformFilterDefinition( array $filterDefinition ) {
259 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
260 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
263 return $filterDefinition;
269 protected function registerFilters() {
270 parent
::registerFilters();
273 !$this->including() &&
274 $this->getUser()->isLoggedIn() &&
275 $this->getUser()->isAllowed( 'viewmywatchlist' )
277 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
278 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
279 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
280 $watchlistGroup->getFilter( 'watchednew' )
284 $user = $this->getUser();
286 $significance = $this->getFilterGroup( 'significance' );
287 $hideMinor = $significance->getFilter( 'hideminor' );
288 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
290 $automated = $this->getFilterGroup( 'automated' );
291 $hideBots = $automated->getFilter( 'hidebots' );
292 $hideBots->setDefault( true );
294 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
295 if ( $reviewStatus !== null ) {
296 // Conditional on feature being available and rights
297 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
298 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
301 $changeType = $this->getFilterGroup( 'changeType' );
302 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
303 if ( $hideCategorization !== null ) {
304 // Conditional on feature being available
305 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
310 * Get a FormOptions object containing the default options
312 * @return FormOptions
314 public function getDefaultOptions() {
315 $opts = parent
::getDefaultOptions();
316 $user = $this->getUser();
318 $opts->add( 'days', $user->getIntOption( 'rcdays' ), FormOptions
::FLOAT );
319 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
320 $opts->add( 'from', '' );
322 $opts->add( 'categories', '' );
323 $opts->add( 'categories_any', false );
324 $opts->add( 'tagfilter', '' );
330 * Get all custom filters
332 * @return array Map of filter URL param names to properties (msg/default)
334 protected function getCustomFilters() {
335 if ( $this->customFilters
=== null ) {
336 $this->customFilters
= parent
::getCustomFilters();
337 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
340 return $this->customFilters
;
344 * Process $par and put options found in $opts. Used when including the page.
347 * @param FormOptions $opts
349 public function parseParameters( $par, FormOptions
$opts ) {
350 parent
::parseParameters( $par, $opts );
352 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
353 foreach ( $bits as $bit ) {
354 if ( is_numeric( $bit ) ) {
355 $opts['limit'] = $bit;
359 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
360 $opts['limit'] = $m[1];
362 if ( preg_match( '/^days=(\d+(?:\.\d+)?)$/', $bit, $m ) ) {
363 $opts['days'] = $m[1];
365 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
366 $opts['namespace'] = $m[1];
368 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
369 $opts['tagfilter'] = $m[1];
374 public function validateOptions( FormOptions
$opts ) {
375 $opts->validateIntBounds( 'limit', 0, 5000 );
376 $opts->validateBounds( 'days', 0, $this->getConfig()->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
377 parent
::validateOptions( $opts );
383 protected function buildQuery( &$tables, &$fields, &$conds,
384 &$query_options, &$join_conds, FormOptions
$opts
386 $dbr = $this->getDB();
387 parent
::buildQuery( $tables, $fields, $conds,
388 $query_options, $join_conds, $opts );
391 $cutoff_unixtime = time() - $opts['days'] * 3600 * 24;
392 $cutoff = $dbr->timestamp( $cutoff_unixtime );
394 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
395 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
396 $cutoff = $dbr->timestamp( $opts['from'] );
398 $opts->reset( 'from' );
401 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
407 protected function doMainQuery( $tables, $fields, $conds, $query_options,
408 $join_conds, FormOptions
$opts
410 $dbr = $this->getDB();
411 $user = $this->getUser();
413 $tables[] = 'recentchanges';
414 $fields = array_merge( RecentChange
::selectFields(), $fields );
416 // JOIN on watchlist for users
417 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
418 $tables[] = 'watchlist';
419 $fields[] = 'wl_user';
420 $fields[] = 'wl_notificationtimestamp';
421 $join_conds['watchlist'] = [ 'LEFT JOIN', [
422 'wl_user' => $user->getId(),
424 'wl_namespace=rc_namespace'
428 // JOIN on page, used for 'last revision' filter highlight
430 $fields[] = 'page_latest';
431 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
433 $tagFilter = $opts['tagfilter'] ?
explode( '|', $opts['tagfilter'] ) : [];
434 ChangeTags
::modifyDisplayQuery(
443 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
449 if ( $this->areFiltersInConflict() ) {
454 'ORDER BY' => 'rc_timestamp DESC',
455 'LIMIT' => $opts['limit']
457 if ( in_array( 'DISTINCT', $query_options ) ) {
458 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
459 // In order to prevent DISTINCT from causing query performance problems,
460 // we have to GROUP BY the primary key. This in turn requires us to add
461 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
462 // start of the GROUP BY
463 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
464 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
466 // array_merge() is used intentionally here so that hooks can, should
467 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
468 // MediaWiki 1.26 this used to use the plus operator instead, which meant
469 // that extensions weren't able to change these conditions
470 $query_options = array_merge( $orderByAndLimit, $query_options );
471 $rows = $dbr->select(
474 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
475 // knowledge to use an index merge if it wants (it may use some other index though).
476 $conds +
[ 'rc_new' => [ 0, 1 ] ],
482 // Build the final data
483 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
484 $this->filterByCategories( $rows, $opts );
490 protected function runMainQueryHook( &$tables, &$fields, &$conds,
491 &$query_options, &$join_conds, $opts
493 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
495 'SpecialRecentChangesQuery',
496 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
501 protected function getDB() {
502 return wfGetDB( DB_REPLICA
, 'recentchanges' );
505 public function outputFeedLinks() {
506 $this->addFeedLinks( $this->getFeedQuery() );
510 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
514 protected function getFeedQuery() {
515 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
516 // API handles empty parameters in a different way
517 return $value !== '';
519 $query['action'] = 'feedrecentchanges';
520 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
521 if ( $query['limit'] > $feedLimit ) {
522 $query['limit'] = $feedLimit;
529 * Build and output the actual changes list.
531 * @param ResultWrapper $rows Database rows
532 * @param FormOptions $opts
534 public function outputChangesList( $rows, $opts ) {
535 $limit = $opts['limit'];
537 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
538 && $this->getUser()->getOption( 'shownumberswatching' );
541 $dbr = $this->getDB();
544 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
545 $list->initChangesListRows( $rows );
547 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
548 $rclistOutput = $list->beginRecentChangesList();
549 if ( $this->isStructuredFilterUiEnabled() ) {
550 $rclistOutput .= $this->makeLegend();
553 foreach ( $rows as $obj ) {
557 $rc = RecentChange
::newFromRow( $obj );
559 # Skip CatWatch entries for hidden cats based on user preference
561 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
562 !$userShowHiddenCats &&
563 $rc->getParam( 'hidden-cat' )
568 $rc->counter
= $counter++
;
569 # Check if the page has been updated since the last visit
570 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
571 && !empty( $obj->wl_notificationtimestamp
)
573 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
575 $rc->notificationtimestamp
= false; // Default
577 # Check the number of users watching the page
578 $rc->numberofWatchingusers
= 0; // Default
579 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
580 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
581 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
582 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
583 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
586 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
589 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
590 if ( $changeLine !== false ) {
591 $rclistOutput .= $changeLine;
595 $rclistOutput .= $list->endRecentChangesList();
597 if ( $rows->numRows() === 0 ) {
598 $this->outputNoResults();
599 if ( !$this->including() ) {
600 $this->getOutput()->setStatusCode( 404 );
603 $this->getOutput()->addHTML( $rclistOutput );
608 * Set the text to be displayed above the changes
610 * @param FormOptions $opts
611 * @param int $numRows Number of rows in the result to show after this header
613 public function doHeader( $opts, $numRows ) {
614 $this->setTopText( $opts );
616 $defaults = $opts->getAllValues();
617 $nondefaults = $opts->getChangedValues();
620 if ( !$this->isStructuredFilterUiEnabled() ) {
621 $panel[] = $this->makeLegend();
623 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
626 $extraOpts = $this->getExtraOptions( $opts );
627 $extraOptsCount = count( $extraOpts );
629 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
631 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
632 foreach ( $extraOpts as $name => $optionRow ) {
633 # Add submit button to the last row only
635 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
637 $out .= Xml
::openElement( 'tr' );
638 if ( is_array( $optionRow ) ) {
641 [ 'class' => 'mw-label mw-' . $name . '-label' ],
646 [ 'class' => 'mw-input' ],
647 $optionRow[1] . $addSubmit
652 [ 'class' => 'mw-input', 'colspan' => 2 ],
653 $optionRow . $addSubmit
656 $out .= Xml
::closeElement( 'tr' );
658 $out .= Xml
::closeElement( 'table' );
660 $unconsumed = $opts->getUnconsumedValues();
661 foreach ( $unconsumed as $key => $value ) {
662 $out .= Html
::hidden( $key, $value );
665 $t = $this->getPageTitle();
666 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
667 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
669 $panelString = implode( "\n", $panel );
671 $rcoptions = Xml
::fieldset(
672 $this->msg( 'recentchanges-legend' )->text(),
674 [ 'class' => 'rcoptions' ]
677 // Insert a placeholder for RCFilters
678 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
679 $rcfilterContainer = Html
::element(
681 [ 'class' => 'rcfilters-container' ]
684 $loadingContainer = Html
::rawElement(
686 [ 'class' => 'rcfilters-spinner' ],
689 [ 'class' => 'rcfilters-spinner-bounce' ]
693 // Wrap both with rcfilters-head
694 $this->getOutput()->addHTML(
697 [ 'class' => 'rcfilters-head' ],
698 $rcfilterContainer . $rcoptions
703 $this->getOutput()->addHTML( $loadingContainer );
705 $this->getOutput()->addHTML( $rcoptions );
708 $this->setBottomText( $opts );
712 * Send the text to be displayed above the options
714 * @param FormOptions $opts Unused
716 function setTopText( FormOptions
$opts ) {
719 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
720 if ( !$message->isDisabled() ) {
721 $this->getOutput()->addWikiText(
722 Html
::rawElement( 'div',
724 'class' => 'mw-recentchanges-toplinks',
725 'lang' => $wgContLang->getHtmlCode(),
726 'dir' => $wgContLang->getDir()
728 "\n" . $message->plain() . "\n"
730 /* $lineStart */ true,
731 /* $interface */ false
737 * Get options to be displayed in a form
739 * @param FormOptions $opts
742 function getExtraOptions( $opts ) {
743 $opts->consumeValues( [
744 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
748 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
750 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
751 $extraOpts['category'] = $this->categoryFilterForm( $opts );
754 $tagFilter = ChangeTags
::buildTagFilterSelector(
755 $opts['tagfilter'], false, $this->getContext() );
756 if ( count( $tagFilter ) ) {
757 $extraOpts['tagfilter'] = $tagFilter;
760 // Don't fire the hook for subclasses. (Or should we?)
761 if ( $this->getName() === 'Recentchanges' ) {
762 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
769 * Check whether the structured filter UI is enabled
773 protected function isStructuredFilterUiEnabled() {
774 return $this->getUser()->getOption(
780 * Add page-specific modules.
782 protected function addModules() {
783 parent
::addModules();
784 $out = $this->getOutput();
785 $out->addModules( 'mediawiki.special.recentchanges' );
786 if ( $this->isStructuredFilterUiEnabled() ) {
787 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
788 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
793 * Get last modified date, for client caching
794 * Don't use this if we are using the patrol feature, patrol changes don't
795 * update the timestamp
797 * @return string|bool
799 public function checkLastModified() {
800 $dbr = $this->getDB();
801 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
807 * Creates the choose namespace selection
809 * @param FormOptions $opts
812 protected function namespaceFilterForm( FormOptions
$opts ) {
813 $nsSelect = Html
::namespaceSelector(
814 [ 'selected' => $opts['namespace'], 'all' => '' ],
815 [ 'name' => 'namespace', 'id' => 'namespace' ]
817 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
818 $invert = Xml
::checkLabel(
819 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
821 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
823 $associated = Xml
::checkLabel(
824 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
826 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
829 return [ $nsLabel, "$nsSelect $invert $associated" ];
833 * Create an input to filter changes by categories
835 * @param FormOptions $opts
838 protected function categoryFilterForm( FormOptions
$opts ) {
839 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
840 'categories', 'mw-categories', false, $opts['categories'] );
842 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
843 'categories_any', 'mw-categories_any', $opts['categories_any'] );
845 return [ $label, $input ];
849 * Filter $rows by categories set in $opts
851 * @param ResultWrapper $rows Database rows
852 * @param FormOptions $opts
854 function filterByCategories( &$rows, FormOptions
$opts ) {
855 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
857 if ( !count( $categories ) ) {
863 foreach ( $categories as $cat ) {
875 foreach ( $rows as $k => $r ) {
876 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
877 $id = $nt->getArticleID();
879 continue; # Page might have been deleted...
881 if ( !in_array( $id, $articles ) ) {
884 if ( !isset( $a2r[$id] ) ) {
892 if ( !count( $articles ) ||
!count( $cats ) ) {
897 $catFind = new CategoryFinder
;
898 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
899 $match = $catFind->run();
903 foreach ( $match as $id ) {
904 foreach ( $a2r[$id] as $rev ) {
906 $newrows[$k] = $rowsarr[$k];
909 $rows = new FakeResultWrapper( array_values( $newrows ) );
913 * Makes change an option link which carries all the other options
915 * @param string $title Title
916 * @param array $override Options to override
917 * @param array $options Current options
918 * @param bool $active Whether to show the link in bold
921 function makeOptionsLink( $title, $override, $options, $active = false ) {
922 $params = $this->convertParamsForLink( $override +
$options );
925 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
928 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
929 'data-params' => json_encode( $override ),
930 'data-keys' => implode( ',', array_keys( $override ) ),
935 * Creates the options panel.
937 * @param array $defaults
938 * @param array $nondefaults
939 * @param int $numRows Number of rows in the result to show after this header
942 function optionsPanel( $defaults, $nondefaults, $numRows ) {
943 $options = $nondefaults +
$defaults;
946 $msg = $this->msg( 'rclegend' );
947 if ( !$msg->isDisabled() ) {
948 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
951 $lang = $this->getLanguage();
952 $user = $this->getUser();
953 $config = $this->getConfig();
954 if ( $options['from'] ) {
955 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
956 [ 'from' => '' ], $nondefaults );
958 $note .= $this->msg( 'rcnotefrom' )
959 ->numParams( $options['limit'] )
961 $lang->userTimeAndDate( $options['from'], $user ),
962 $lang->userDate( $options['from'], $user ),
963 $lang->userTime( $options['from'], $user )
965 ->numParams( $numRows )
969 [ 'class' => 'rcoptions-listfromreset' ],
970 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
975 # Sort data for display and make sure it's unique after we've added user data.
976 $linkLimits = $config->get( 'RCLinkLimits' );
977 $linkLimits[] = $options['limit'];
979 $linkLimits = array_unique( $linkLimits );
981 $linkDays = $config->get( 'RCLinkDays' );
982 $linkDays[] = $options['days'];
984 $linkDays = array_unique( $linkDays );
988 foreach ( $linkLimits as $value ) {
989 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
990 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
992 $cl = $lang->pipeList( $cl );
994 // day links, reset 'from' to none
996 foreach ( $linkDays as $value ) {
997 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
998 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
1000 $dl = $lang->pipeList( $dl );
1002 $showhide = [ 'show', 'hide' ];
1006 $filterGroups = $this->getFilterGroups();
1008 $context = $this->getContext();
1009 foreach ( $filterGroups as $groupName => $group ) {
1010 if ( !$group->isPerGroupRequestParameter() ) {
1011 foreach ( $group->getFilters() as $key => $filter ) {
1012 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
1013 $msg = $filter->getShowHide();
1014 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
1015 // Extensions can define additional filters, but don't need to define the corresponding
1016 // messages. If they don't exist, just fall back to 'show' and 'hide'.
1017 if ( !$linkMessage->exists() ) {
1018 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
1021 $link = $this->makeOptionsLink( $linkMessage->text(),
1022 [ $key => 1 - $options[$key] ], $nondefaults );
1025 'class' => "$msg rcshowhideoption",
1026 'data-filter-name' => $filter->getName(),
1029 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
1030 $attribs['data-feature-in-structured-ui'] = true;
1033 $links[] = Html
::rawElement(
1036 $this->msg( $msg )->rawParams( $link )->escaped()
1043 // show from this onward link
1044 $timestamp = wfTimestampNow();
1045 $now = $lang->userTimeAndDate( $timestamp, $user );
1046 $timenow = $lang->userTime( $timestamp, $user );
1047 $datenow = $lang->userDate( $timestamp, $user );
1048 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1050 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1051 ->parse() . '</span>';
1053 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1054 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1055 [ 'from' => $timestamp ],
1059 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1062 public function isIncludable() {
1066 protected function getCacheTTL() {