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 global $wgStructuredChangeFiltersEnableSaving,
142 $wgStructuredChangeFiltersEnableExperimentalViews,
143 $wgStructuredChangeFiltersEnableLiveUpdate;
145 // Backwards-compatibility: redirect to new feed URLs
146 $feedFormat = $this->getRequest()->getVal( 'feed' );
147 if ( !$this->including() && $feedFormat ) {
148 $query = $this->getFeedQuery();
149 $query['feedformat'] = $feedFormat === 'atom' ?
'atom' : 'rss';
150 $this->getOutput()->redirect( wfAppendQuery( wfScript( 'api' ), $query ) );
155 // 10 seconds server-side caching max
156 $out = $this->getOutput();
157 $out->setCdnMaxage( 10 );
158 // Check if the client has a cached version
159 $lastmod = $this->checkLastModified();
160 if ( $lastmod === false ) {
165 '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Recent_changes',
168 parent
::execute( $subpage );
170 if ( $this->isStructuredFilterUiEnabled() ) {
171 $jsData = $this->getStructuredFilterJsData();
174 foreach ( $jsData['messageKeys'] as $key ) {
175 $messages[$key] = $this->msg( $key )->plain();
179 ResourceLoader
::makeInlineScript(
180 ResourceLoader
::makeMessageSetScript( $messages )
184 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
185 $out->addJsConfigVars(
186 'wgStructuredChangeFiltersEnableSaving',
187 $wgStructuredChangeFiltersEnableSaving
189 $out->addJsConfigVars(
190 'wgStructuredChangeFiltersEnableExperimentalViews',
191 $wgStructuredChangeFiltersEnableExperimentalViews
193 $out->addJsConfigVars(
194 'wgStructuredChangeFiltersEnableLiveUpdate',
195 $wgStructuredChangeFiltersEnableLiveUpdate
197 $out->addJsConfigVars(
198 'wgRCFiltersChangeTags',
199 $this->buildChangeTagList()
205 * Fetch the change tags list for the front end
207 * @return Array Tag data
209 protected function buildChangeTagList() {
210 function stripAllHtml( $input ) {
211 return trim( html_entity_decode( strip_tags( $input ) ) );
214 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
215 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
216 $tagStats = ChangeTags
::tagUsageStatistics();
218 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
221 arsort( $tagHitCounts );
223 // Build the list and data
225 foreach ( $tagHitCounts as $tagName => $hits ) {
227 // Only get active tags
228 isset( $explicitlyDefinedTags[ $tagName ] ) ||
229 isset( $softwareActivatedTags[ $tagName ] )
232 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
236 'label' => stripAllHtml( ChangeTags
::tagDescription( $tagName, $this->getContext() ) ),
237 'description' => $desc ?
stripAllHtml( $desc->parse() ) : '',
238 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
250 protected function transformFilterDefinition( array $filterDefinition ) {
251 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
252 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
255 return $filterDefinition;
261 protected function registerFilters() {
262 parent
::registerFilters();
265 !$this->including() &&
266 $this->getUser()->isLoggedIn() &&
267 $this->getUser()->isAllowed( 'viewmywatchlist' )
269 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
270 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
271 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
272 $watchlistGroup->getFilter( 'watchednew' )
276 $user = $this->getUser();
278 $significance = $this->getFilterGroup( 'significance' );
279 $hideMinor = $significance->getFilter( 'hideminor' );
280 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
282 $automated = $this->getFilterGroup( 'automated' );
283 $hideBots = $automated->getFilter( 'hidebots' );
284 $hideBots->setDefault( true );
286 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
287 if ( $reviewStatus !== null ) {
288 // Conditional on feature being available and rights
289 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
290 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
293 $changeType = $this->getFilterGroup( 'changeType' );
294 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
295 if ( $hideCategorization !== null ) {
296 // Conditional on feature being available
297 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
302 * Get a FormOptions object containing the default options
304 * @return FormOptions
306 public function getDefaultOptions() {
307 $opts = parent
::getDefaultOptions();
308 $user = $this->getUser();
310 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
311 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
312 $opts->add( 'from', '' );
314 $opts->add( 'categories', '' );
315 $opts->add( 'categories_any', false );
316 $opts->add( 'tagfilter', '' );
322 * Get all custom filters
324 * @return array Map of filter URL param names to properties (msg/default)
326 protected function getCustomFilters() {
327 if ( $this->customFilters
=== null ) {
328 $this->customFilters
= parent
::getCustomFilters();
329 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
332 return $this->customFilters
;
336 * Process $par and put options found in $opts. Used when including the page.
339 * @param FormOptions $opts
341 public function parseParameters( $par, FormOptions
$opts ) {
342 parent
::parseParameters( $par, $opts );
344 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
345 foreach ( $bits as $bit ) {
346 if ( is_numeric( $bit ) ) {
347 $opts['limit'] = $bit;
351 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
352 $opts['limit'] = $m[1];
354 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
355 $opts['days'] = $m[1];
357 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
358 $opts['namespace'] = $m[1];
360 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
361 $opts['tagfilter'] = $m[1];
366 public function validateOptions( FormOptions
$opts ) {
367 $opts->validateIntBounds( 'limit', 0, 5000 );
368 parent
::validateOptions( $opts );
374 protected function buildQuery( &$tables, &$fields, &$conds,
375 &$query_options, &$join_conds, FormOptions
$opts
377 $dbr = $this->getDB();
378 parent
::buildQuery( $tables, $fields, $conds,
379 $query_options, $join_conds, $opts );
382 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
383 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime %
86400 );
384 $cutoff = $dbr->timestamp( $cutoff_unixtime );
386 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
387 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
388 $cutoff = $dbr->timestamp( $opts['from'] );
390 $opts->reset( 'from' );
393 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
399 protected function doMainQuery( $tables, $fields, $conds, $query_options,
400 $join_conds, FormOptions
$opts
402 $dbr = $this->getDB();
403 $user = $this->getUser();
405 $tables[] = 'recentchanges';
406 $fields = array_merge( RecentChange
::selectFields(), $fields );
408 // JOIN on watchlist for users
409 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
410 $tables[] = 'watchlist';
411 $fields[] = 'wl_user';
412 $fields[] = 'wl_notificationtimestamp';
413 $join_conds['watchlist'] = [ 'LEFT JOIN', [
414 'wl_user' => $user->getId(),
416 'wl_namespace=rc_namespace'
420 // JOIN on page, used for 'last revision' filter highlight
422 $fields[] = 'page_latest';
423 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
425 $tagFilter = explode( '|', $opts['tagfilter'] );
426 ChangeTags
::modifyDisplayQuery(
435 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
441 if ( $this->areFiltersInConflict() ) {
446 'ORDER BY' => 'rc_timestamp DESC',
447 'LIMIT' => $opts['limit']
449 if ( in_array( 'DISTINCT', $query_options ) ) {
450 // ChangeTags::modifyDisplayQuery() adds DISTINCT when filtering on multiple tags.
451 // In order to prevent DISTINCT from causing query performance problems,
452 // we have to GROUP BY the primary key. This in turn requires us to add
453 // the primary key to the end of the ORDER BY, and the old ORDER BY to the
454 // start of the GROUP BY
455 $orderByAndLimit['ORDER BY'] = 'rc_timestamp DESC, rc_id DESC';
456 $orderByAndLimit['GROUP BY'] = 'rc_timestamp, rc_id';
458 // array_merge() is used intentionally here so that hooks can, should
459 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
460 // MediaWiki 1.26 this used to use the plus operator instead, which meant
461 // that extensions weren't able to change these conditions
462 $query_options = array_merge( $orderByAndLimit, $query_options );
463 $rows = $dbr->select(
466 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
467 // knowledge to use an index merge if it wants (it may use some other index though).
468 $conds +
[ 'rc_new' => [ 0, 1 ] ],
474 // Build the final data
475 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
476 $this->filterByCategories( $rows, $opts );
482 protected function runMainQueryHook( &$tables, &$fields, &$conds,
483 &$query_options, &$join_conds, $opts
485 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
487 'SpecialRecentChangesQuery',
488 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
493 protected function getDB() {
494 return wfGetDB( DB_REPLICA
, 'recentchanges' );
497 public function outputFeedLinks() {
498 $this->addFeedLinks( $this->getFeedQuery() );
502 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
506 protected function getFeedQuery() {
507 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
508 // API handles empty parameters in a different way
509 return $value !== '';
511 $query['action'] = 'feedrecentchanges';
512 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
513 if ( $query['limit'] > $feedLimit ) {
514 $query['limit'] = $feedLimit;
521 * Build and output the actual changes list.
523 * @param ResultWrapper $rows Database rows
524 * @param FormOptions $opts
526 public function outputChangesList( $rows, $opts ) {
527 $limit = $opts['limit'];
529 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
530 && $this->getUser()->getOption( 'shownumberswatching' );
533 $dbr = $this->getDB();
536 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
537 $list->initChangesListRows( $rows );
539 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
540 $rclistOutput = $list->beginRecentChangesList();
541 if ( $this->isStructuredFilterUiEnabled() ) {
542 $rclistOutput .= $this->makeLegend();
545 foreach ( $rows as $obj ) {
549 $rc = RecentChange
::newFromRow( $obj );
551 # Skip CatWatch entries for hidden cats based on user preference
553 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
554 !$userShowHiddenCats &&
555 $rc->getParam( 'hidden-cat' )
560 $rc->counter
= $counter++
;
561 # Check if the page has been updated since the last visit
562 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
563 && !empty( $obj->wl_notificationtimestamp
)
565 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
567 $rc->notificationtimestamp
= false; // Default
569 # Check the number of users watching the page
570 $rc->numberofWatchingusers
= 0; // Default
571 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
572 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
573 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
574 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
575 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
578 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
581 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
582 if ( $changeLine !== false ) {
583 $rclistOutput .= $changeLine;
587 $rclistOutput .= $list->endRecentChangesList();
589 if ( $rows->numRows() === 0 ) {
590 $this->outputNoResults();
591 if ( !$this->including() ) {
592 $this->getOutput()->setStatusCode( 404 );
595 $this->getOutput()->addHTML( $rclistOutput );
600 * Set the text to be displayed above the changes
602 * @param FormOptions $opts
603 * @param int $numRows Number of rows in the result to show after this header
605 public function doHeader( $opts, $numRows ) {
606 $this->setTopText( $opts );
608 $defaults = $opts->getAllValues();
609 $nondefaults = $opts->getChangedValues();
612 if ( !$this->isStructuredFilterUiEnabled() ) {
613 $panel[] = $this->makeLegend();
615 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
618 $extraOpts = $this->getExtraOptions( $opts );
619 $extraOptsCount = count( $extraOpts );
621 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
623 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
624 foreach ( $extraOpts as $name => $optionRow ) {
625 # Add submit button to the last row only
627 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
629 $out .= Xml
::openElement( 'tr' );
630 if ( is_array( $optionRow ) ) {
633 [ 'class' => 'mw-label mw-' . $name . '-label' ],
638 [ 'class' => 'mw-input' ],
639 $optionRow[1] . $addSubmit
644 [ 'class' => 'mw-input', 'colspan' => 2 ],
645 $optionRow . $addSubmit
648 $out .= Xml
::closeElement( 'tr' );
650 $out .= Xml
::closeElement( 'table' );
652 $unconsumed = $opts->getUnconsumedValues();
653 foreach ( $unconsumed as $key => $value ) {
654 $out .= Html
::hidden( $key, $value );
657 $t = $this->getPageTitle();
658 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
659 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
661 $panelString = implode( "\n", $panel );
663 $rcoptions = Xml
::fieldset(
664 $this->msg( 'recentchanges-legend' )->text(),
666 [ 'class' => 'rcoptions' ]
669 // Insert a placeholder for RCFilters
670 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
671 $rcfilterContainer = Html
::element(
673 [ 'class' => 'rcfilters-container' ]
676 // Wrap both with rcfilters-head
677 $this->getOutput()->addHTML(
680 [ 'class' => 'rcfilters-head' ],
681 $rcfilterContainer . $rcoptions
685 $this->getOutput()->addHTML( $rcoptions );
688 $this->setBottomText( $opts );
692 * Send the text to be displayed above the options
694 * @param FormOptions $opts Unused
696 function setTopText( FormOptions
$opts ) {
699 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
700 if ( !$message->isDisabled() ) {
701 $this->getOutput()->addWikiText(
702 Html
::rawElement( 'div',
704 'class' => 'mw-recentchanges-toplinks',
705 'lang' => $wgContLang->getHtmlCode(),
706 'dir' => $wgContLang->getDir()
708 "\n" . $message->plain() . "\n"
710 /* $lineStart */ true,
711 /* $interface */ false
717 * Get options to be displayed in a form
719 * @param FormOptions $opts
722 function getExtraOptions( $opts ) {
723 $opts->consumeValues( [
724 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
728 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
730 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
731 $extraOpts['category'] = $this->categoryFilterForm( $opts );
734 $tagFilter = ChangeTags
::buildTagFilterSelector(
735 $opts['tagfilter'], false, $this->getContext() );
736 if ( count( $tagFilter ) ) {
737 $extraOpts['tagfilter'] = $tagFilter;
740 // Don't fire the hook for subclasses. (Or should we?)
741 if ( $this->getName() === 'Recentchanges' ) {
742 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
749 * Check whether the structured filter UI is enabled
753 protected function isStructuredFilterUiEnabled() {
754 return $this->getUser()->getOption(
760 * Add page-specific modules.
762 protected function addModules() {
763 parent
::addModules();
764 $out = $this->getOutput();
765 $out->addModules( 'mediawiki.special.recentchanges' );
766 if ( $this->isStructuredFilterUiEnabled() ) {
767 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
768 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
773 * Get last modified date, for client caching
774 * Don't use this if we are using the patrol feature, patrol changes don't
775 * update the timestamp
777 * @return string|bool
779 public function checkLastModified() {
780 $dbr = $this->getDB();
781 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
787 * Creates the choose namespace selection
789 * @param FormOptions $opts
792 protected function namespaceFilterForm( FormOptions
$opts ) {
793 $nsSelect = Html
::namespaceSelector(
794 [ 'selected' => $opts['namespace'], 'all' => '' ],
795 [ 'name' => 'namespace', 'id' => 'namespace' ]
797 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
798 $invert = Xml
::checkLabel(
799 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
801 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
803 $associated = Xml
::checkLabel(
804 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
806 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
809 return [ $nsLabel, "$nsSelect $invert $associated" ];
813 * Create an input to filter changes by categories
815 * @param FormOptions $opts
818 protected function categoryFilterForm( FormOptions
$opts ) {
819 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
820 'categories', 'mw-categories', false, $opts['categories'] );
822 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
823 'categories_any', 'mw-categories_any', $opts['categories_any'] );
825 return [ $label, $input ];
829 * Filter $rows by categories set in $opts
831 * @param ResultWrapper $rows Database rows
832 * @param FormOptions $opts
834 function filterByCategories( &$rows, FormOptions
$opts ) {
835 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
837 if ( !count( $categories ) ) {
843 foreach ( $categories as $cat ) {
855 foreach ( $rows as $k => $r ) {
856 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
857 $id = $nt->getArticleID();
859 continue; # Page might have been deleted...
861 if ( !in_array( $id, $articles ) ) {
864 if ( !isset( $a2r[$id] ) ) {
872 if ( !count( $articles ) ||
!count( $cats ) ) {
877 $catFind = new CategoryFinder
;
878 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
879 $match = $catFind->run();
883 foreach ( $match as $id ) {
884 foreach ( $a2r[$id] as $rev ) {
886 $newrows[$k] = $rowsarr[$k];
889 $rows = new FakeResultWrapper( array_values( $newrows ) );
893 * Makes change an option link which carries all the other options
895 * @param string $title Title
896 * @param array $override Options to override
897 * @param array $options Current options
898 * @param bool $active Whether to show the link in bold
901 function makeOptionsLink( $title, $override, $options, $active = false ) {
902 $params = $this->convertParamsForLink( $override +
$options );
905 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
908 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
909 'data-params' => json_encode( $override ),
910 'data-keys' => implode( ',', array_keys( $override ) ),
915 * Creates the options panel.
917 * @param array $defaults
918 * @param array $nondefaults
919 * @param int $numRows Number of rows in the result to show after this header
922 function optionsPanel( $defaults, $nondefaults, $numRows ) {
923 $options = $nondefaults +
$defaults;
926 $msg = $this->msg( 'rclegend' );
927 if ( !$msg->isDisabled() ) {
928 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
931 $lang = $this->getLanguage();
932 $user = $this->getUser();
933 $config = $this->getConfig();
934 if ( $options['from'] ) {
935 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
936 [ 'from' => '' ], $nondefaults );
938 $note .= $this->msg( 'rcnotefrom' )
939 ->numParams( $options['limit'] )
941 $lang->userTimeAndDate( $options['from'], $user ),
942 $lang->userDate( $options['from'], $user ),
943 $lang->userTime( $options['from'], $user )
945 ->numParams( $numRows )
949 [ 'class' => 'rcoptions-listfromreset' ],
950 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
955 # Sort data for display and make sure it's unique after we've added user data.
956 $linkLimits = $config->get( 'RCLinkLimits' );
957 $linkLimits[] = $options['limit'];
959 $linkLimits = array_unique( $linkLimits );
961 $linkDays = $config->get( 'RCLinkDays' );
962 $linkDays[] = $options['days'];
964 $linkDays = array_unique( $linkDays );
968 foreach ( $linkLimits as $value ) {
969 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
970 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
972 $cl = $lang->pipeList( $cl );
974 // day links, reset 'from' to none
976 foreach ( $linkDays as $value ) {
977 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
978 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
980 $dl = $lang->pipeList( $dl );
982 $showhide = [ 'show', 'hide' ];
986 $filterGroups = $this->getFilterGroups();
988 $context = $this->getContext();
989 foreach ( $filterGroups as $groupName => $group ) {
990 if ( !$group->isPerGroupRequestParameter() ) {
991 foreach ( $group->getFilters() as $key => $filter ) {
992 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
993 $msg = $filter->getShowHide();
994 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
995 // Extensions can define additional filters, but don't need to define the corresponding
996 // messages. If they don't exist, just fall back to 'show' and 'hide'.
997 if ( !$linkMessage->exists() ) {
998 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
1001 $link = $this->makeOptionsLink( $linkMessage->text(),
1002 [ $key => 1 - $options[$key] ], $nondefaults );
1005 'class' => "$msg rcshowhideoption",
1006 'data-filter-name' => $filter->getName(),
1009 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
1010 $attribs['data-feature-in-structured-ui'] = true;
1013 $links[] = Html
::rawElement(
1016 $this->msg( $msg )->rawParams( $link )->escaped()
1023 // show from this onward link
1024 $timestamp = wfTimestampNow();
1025 $now = $lang->userTimeAndDate( $timestamp, $user );
1026 $timenow = $lang->userTime( $timestamp, $user );
1027 $datenow = $lang->userDate( $timestamp, $user );
1028 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1030 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1031 ->parse() . '</span>';
1033 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1034 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1035 [ 'from' => $timestamp ],
1039 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1042 public function isIncludable() {
1046 protected function getCacheTTL() {