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 );
213 $tagStats = ChangeTags
::tagUsageStatistics();
215 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
218 arsort( $tagHitCounts );
220 // Build the list and data
222 foreach ( $tagHitCounts as $tagName => $hits ) {
224 // Only get active tags
225 isset( $explicitlyDefinedTags[ $tagName ] ) ||
226 isset( $softwareActivatedTags[ $tagName ] )
229 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
233 'label' => Sanitizer
::stripAllTags(
234 ChangeTags
::tagDescription( $tagName, $this->getContext() )
236 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
237 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
249 protected function transformFilterDefinition( array $filterDefinition ) {
250 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
251 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
254 return $filterDefinition;
260 protected function registerFilters() {
261 parent
::registerFilters();
264 !$this->including() &&
265 $this->getUser()->isLoggedIn() &&
266 $this->getUser()->isAllowed( 'viewmywatchlist' )
268 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
269 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
270 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
271 $watchlistGroup->getFilter( 'watchednew' )
275 $user = $this->getUser();
277 $significance = $this->getFilterGroup( 'significance' );
278 $hideMinor = $significance->getFilter( 'hideminor' );
279 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
281 $automated = $this->getFilterGroup( 'automated' );
282 $hideBots = $automated->getFilter( 'hidebots' );
283 $hideBots->setDefault( true );
285 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
286 if ( $reviewStatus !== null ) {
287 // Conditional on feature being available and rights
288 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
289 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
292 $changeType = $this->getFilterGroup( 'changeType' );
293 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
294 if ( $hideCategorization !== null ) {
295 // Conditional on feature being available
296 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
301 * Get a FormOptions object containing the default options
303 * @return FormOptions
305 public function getDefaultOptions() {
306 $opts = parent
::getDefaultOptions();
307 $user = $this->getUser();
309 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
310 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
311 $opts->add( 'from', '' );
313 $opts->add( 'categories', '' );
314 $opts->add( 'categories_any', false );
315 $opts->add( 'tagfilter', '' );
321 * Get all custom filters
323 * @return array Map of filter URL param names to properties (msg/default)
325 protected function getCustomFilters() {
326 if ( $this->customFilters
=== null ) {
327 $this->customFilters
= parent
::getCustomFilters();
328 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
331 return $this->customFilters
;
335 * Process $par and put options found in $opts. Used when including the page.
338 * @param FormOptions $opts
340 public function parseParameters( $par, FormOptions
$opts ) {
341 parent
::parseParameters( $par, $opts );
343 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
344 foreach ( $bits as $bit ) {
345 if ( is_numeric( $bit ) ) {
346 $opts['limit'] = $bit;
350 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
351 $opts['limit'] = $m[1];
353 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
354 $opts['days'] = $m[1];
356 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
357 $opts['namespace'] = $m[1];
359 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
360 $opts['tagfilter'] = $m[1];
365 public function validateOptions( FormOptions
$opts ) {
366 $opts->validateIntBounds( 'limit', 0, 5000 );
367 parent
::validateOptions( $opts );
373 protected function buildQuery( &$tables, &$fields, &$conds,
374 &$query_options, &$join_conds, FormOptions
$opts
376 $dbr = $this->getDB();
377 parent
::buildQuery( $tables, $fields, $conds,
378 $query_options, $join_conds, $opts );
381 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
382 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime %
86400 );
383 $cutoff = $dbr->timestamp( $cutoff_unixtime );
385 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
386 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
387 $cutoff = $dbr->timestamp( $opts['from'] );
389 $opts->reset( 'from' );
392 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
398 protected function doMainQuery( $tables, $fields, $conds, $query_options,
399 $join_conds, FormOptions
$opts
401 $dbr = $this->getDB();
402 $user = $this->getUser();
404 $tables[] = 'recentchanges';
405 $fields = array_merge( RecentChange
::selectFields(), $fields );
407 // JOIN on watchlist for users
408 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
409 $tables[] = 'watchlist';
410 $fields[] = 'wl_user';
411 $fields[] = 'wl_notificationtimestamp';
412 $join_conds['watchlist'] = [ 'LEFT JOIN', [
413 'wl_user' => $user->getId(),
415 'wl_namespace=rc_namespace'
419 // JOIN on page, used for 'last revision' filter highlight
421 $fields[] = 'page_latest';
422 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
424 ChangeTags
::modifyDisplayQuery(
433 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
439 if ( $this->areFiltersInConflict() ) {
443 // array_merge() is used intentionally here so that hooks can, should
444 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
445 // MediaWiki 1.26 this used to use the plus operator instead, which meant
446 // that extensions weren't able to change these conditions
447 $query_options = array_merge( [
448 'ORDER BY' => 'rc_timestamp DESC',
449 'LIMIT' => $opts['limit'] ], $query_options );
450 $rows = $dbr->select(
453 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
454 // knowledge to use an index merge if it wants (it may use some other index though).
455 $conds +
[ 'rc_new' => [ 0, 1 ] ],
461 // Build the final data
462 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
463 $this->filterByCategories( $rows, $opts );
469 protected function runMainQueryHook( &$tables, &$fields, &$conds,
470 &$query_options, &$join_conds, $opts
472 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
474 'SpecialRecentChangesQuery',
475 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
480 protected function getDB() {
481 return wfGetDB( DB_REPLICA
, 'recentchanges' );
484 public function outputFeedLinks() {
485 $this->addFeedLinks( $this->getFeedQuery() );
489 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
493 protected function getFeedQuery() {
494 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
495 // API handles empty parameters in a different way
496 return $value !== '';
498 $query['action'] = 'feedrecentchanges';
499 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
500 if ( $query['limit'] > $feedLimit ) {
501 $query['limit'] = $feedLimit;
508 * Build and output the actual changes list.
510 * @param ResultWrapper $rows Database rows
511 * @param FormOptions $opts
513 public function outputChangesList( $rows, $opts ) {
514 $limit = $opts['limit'];
516 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
517 && $this->getUser()->getOption( 'shownumberswatching' );
520 $dbr = $this->getDB();
523 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
524 $list->initChangesListRows( $rows );
526 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
527 $rclistOutput = $list->beginRecentChangesList();
528 if ( $this->isStructuredFilterUiEnabled() ) {
529 $rclistOutput .= $this->makeLegend();
532 foreach ( $rows as $obj ) {
536 $rc = RecentChange
::newFromRow( $obj );
538 # Skip CatWatch entries for hidden cats based on user preference
540 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
541 !$userShowHiddenCats &&
542 $rc->getParam( 'hidden-cat' )
547 $rc->counter
= $counter++
;
548 # Check if the page has been updated since the last visit
549 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
550 && !empty( $obj->wl_notificationtimestamp
)
552 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
554 $rc->notificationtimestamp
= false; // Default
556 # Check the number of users watching the page
557 $rc->numberofWatchingusers
= 0; // Default
558 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
559 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
560 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
561 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
562 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
565 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
568 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
569 if ( $changeLine !== false ) {
570 $rclistOutput .= $changeLine;
574 $rclistOutput .= $list->endRecentChangesList();
576 if ( $rows->numRows() === 0 ) {
577 $this->outputNoResults();
578 if ( !$this->including() ) {
579 $this->getOutput()->setStatusCode( 404 );
582 $this->getOutput()->addHTML( $rclistOutput );
587 * Set the text to be displayed above the changes
589 * @param FormOptions $opts
590 * @param int $numRows Number of rows in the result to show after this header
592 public function doHeader( $opts, $numRows ) {
593 $this->setTopText( $opts );
595 $defaults = $opts->getAllValues();
596 $nondefaults = $opts->getChangedValues();
599 if ( !$this->isStructuredFilterUiEnabled() ) {
600 $panel[] = $this->makeLegend();
602 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
605 $extraOpts = $this->getExtraOptions( $opts );
606 $extraOptsCount = count( $extraOpts );
608 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
610 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
611 foreach ( $extraOpts as $name => $optionRow ) {
612 # Add submit button to the last row only
614 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
616 $out .= Xml
::openElement( 'tr' );
617 if ( is_array( $optionRow ) ) {
620 [ 'class' => 'mw-label mw-' . $name . '-label' ],
625 [ 'class' => 'mw-input' ],
626 $optionRow[1] . $addSubmit
631 [ 'class' => 'mw-input', 'colspan' => 2 ],
632 $optionRow . $addSubmit
635 $out .= Xml
::closeElement( 'tr' );
637 $out .= Xml
::closeElement( 'table' );
639 $unconsumed = $opts->getUnconsumedValues();
640 foreach ( $unconsumed as $key => $value ) {
641 $out .= Html
::hidden( $key, $value );
644 $t = $this->getPageTitle();
645 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
646 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
648 $panelString = implode( "\n", $panel );
650 $rcoptions = Xml
::fieldset(
651 $this->msg( 'recentchanges-legend' )->text(),
653 [ 'class' => 'rcoptions' ]
656 // Insert a placeholder for RCFilters
657 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
658 $rcfilterContainer = Html
::element(
660 [ 'class' => 'rcfilters-container' ]
663 // Wrap both with rcfilters-head
664 $this->getOutput()->addHTML(
667 [ 'class' => 'rcfilters-head' ],
668 $rcfilterContainer . $rcoptions
672 $this->getOutput()->addHTML( $rcoptions );
675 $this->setBottomText( $opts );
679 * Send the text to be displayed above the options
681 * @param FormOptions $opts Unused
683 function setTopText( FormOptions
$opts ) {
686 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
687 if ( !$message->isDisabled() ) {
688 $this->getOutput()->addWikiText(
689 Html
::rawElement( 'div',
691 'class' => 'mw-recentchanges-toplinks',
692 'lang' => $wgContLang->getHtmlCode(),
693 'dir' => $wgContLang->getDir()
695 "\n" . $message->plain() . "\n"
697 /* $lineStart */ true,
698 /* $interface */ false
704 * Get options to be displayed in a form
706 * @param FormOptions $opts
709 function getExtraOptions( $opts ) {
710 $opts->consumeValues( [
711 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
715 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
717 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
718 $extraOpts['category'] = $this->categoryFilterForm( $opts );
721 $tagFilter = ChangeTags
::buildTagFilterSelector(
722 $opts['tagfilter'], false, $this->getContext() );
723 if ( count( $tagFilter ) ) {
724 $extraOpts['tagfilter'] = $tagFilter;
727 // Don't fire the hook for subclasses. (Or should we?)
728 if ( $this->getName() === 'Recentchanges' ) {
729 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
736 * Check whether the structured filter UI is enabled
740 protected function isStructuredFilterUiEnabled() {
741 return $this->getUser()->getOption(
747 * Add page-specific modules.
749 protected function addModules() {
750 parent
::addModules();
751 $out = $this->getOutput();
752 $out->addModules( 'mediawiki.special.recentchanges' );
753 if ( $this->isStructuredFilterUiEnabled() ) {
754 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
755 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
760 * Get last modified date, for client caching
761 * Don't use this if we are using the patrol feature, patrol changes don't
762 * update the timestamp
764 * @return string|bool
766 public function checkLastModified() {
767 $dbr = $this->getDB();
768 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
774 * Creates the choose namespace selection
776 * @param FormOptions $opts
779 protected function namespaceFilterForm( FormOptions
$opts ) {
780 $nsSelect = Html
::namespaceSelector(
781 [ 'selected' => $opts['namespace'], 'all' => '' ],
782 [ 'name' => 'namespace', 'id' => 'namespace' ]
784 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
785 $invert = Xml
::checkLabel(
786 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
788 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
790 $associated = Xml
::checkLabel(
791 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
793 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
796 return [ $nsLabel, "$nsSelect $invert $associated" ];
800 * Create an input to filter changes by categories
802 * @param FormOptions $opts
805 protected function categoryFilterForm( FormOptions
$opts ) {
806 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
807 'categories', 'mw-categories', false, $opts['categories'] );
809 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
810 'categories_any', 'mw-categories_any', $opts['categories_any'] );
812 return [ $label, $input ];
816 * Filter $rows by categories set in $opts
818 * @param ResultWrapper $rows Database rows
819 * @param FormOptions $opts
821 function filterByCategories( &$rows, FormOptions
$opts ) {
822 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
824 if ( !count( $categories ) ) {
830 foreach ( $categories as $cat ) {
842 foreach ( $rows as $k => $r ) {
843 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
844 $id = $nt->getArticleID();
846 continue; # Page might have been deleted...
848 if ( !in_array( $id, $articles ) ) {
851 if ( !isset( $a2r[$id] ) ) {
859 if ( !count( $articles ) ||
!count( $cats ) ) {
864 $catFind = new CategoryFinder
;
865 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
866 $match = $catFind->run();
870 foreach ( $match as $id ) {
871 foreach ( $a2r[$id] as $rev ) {
873 $newrows[$k] = $rowsarr[$k];
876 $rows = new FakeResultWrapper( array_values( $newrows ) );
880 * Makes change an option link which carries all the other options
882 * @param string $title Title
883 * @param array $override Options to override
884 * @param array $options Current options
885 * @param bool $active Whether to show the link in bold
888 function makeOptionsLink( $title, $override, $options, $active = false ) {
889 $params = $this->convertParamsForLink( $override +
$options );
892 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
895 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
896 'data-params' => json_encode( $override ),
897 'data-keys' => implode( ',', array_keys( $override ) ),
902 * Creates the options panel.
904 * @param array $defaults
905 * @param array $nondefaults
906 * @param int $numRows Number of rows in the result to show after this header
909 function optionsPanel( $defaults, $nondefaults, $numRows ) {
910 $options = $nondefaults +
$defaults;
913 $msg = $this->msg( 'rclegend' );
914 if ( !$msg->isDisabled() ) {
915 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
918 $lang = $this->getLanguage();
919 $user = $this->getUser();
920 $config = $this->getConfig();
921 if ( $options['from'] ) {
922 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
923 [ 'from' => '' ], $nondefaults );
925 $note .= $this->msg( 'rcnotefrom' )
926 ->numParams( $options['limit'] )
928 $lang->userTimeAndDate( $options['from'], $user ),
929 $lang->userDate( $options['from'], $user ),
930 $lang->userTime( $options['from'], $user )
932 ->numParams( $numRows )
936 [ 'class' => 'rcoptions-listfromreset' ],
937 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
942 # Sort data for display and make sure it's unique after we've added user data.
943 $linkLimits = $config->get( 'RCLinkLimits' );
944 $linkLimits[] = $options['limit'];
946 $linkLimits = array_unique( $linkLimits );
948 $linkDays = $config->get( 'RCLinkDays' );
949 $linkDays[] = $options['days'];
951 $linkDays = array_unique( $linkDays );
955 foreach ( $linkLimits as $value ) {
956 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
957 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
959 $cl = $lang->pipeList( $cl );
961 // day links, reset 'from' to none
963 foreach ( $linkDays as $value ) {
964 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
965 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
967 $dl = $lang->pipeList( $dl );
969 $showhide = [ 'show', 'hide' ];
973 $filterGroups = $this->getFilterGroups();
975 $context = $this->getContext();
976 foreach ( $filterGroups as $groupName => $group ) {
977 if ( !$group->isPerGroupRequestParameter() ) {
978 foreach ( $group->getFilters() as $key => $filter ) {
979 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
980 $msg = $filter->getShowHide();
981 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
982 // Extensions can define additional filters, but don't need to define the corresponding
983 // messages. If they don't exist, just fall back to 'show' and 'hide'.
984 if ( !$linkMessage->exists() ) {
985 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
988 $link = $this->makeOptionsLink( $linkMessage->text(),
989 [ $key => 1 - $options[$key] ], $nondefaults );
992 'class' => "$msg rcshowhideoption",
993 'data-filter-name' => $filter->getName(),
996 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
997 $attribs['data-feature-in-structured-ui'] = true;
1000 $links[] = Html
::rawElement(
1003 $this->msg( $msg )->rawParams( $link )->escaped()
1010 // show from this onward link
1011 $timestamp = wfTimestampNow();
1012 $now = $lang->userTimeAndDate( $timestamp, $user );
1013 $timenow = $lang->userTime( $timestamp, $user );
1014 $datenow = $lang->userDate( $timestamp, $user );
1015 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1017 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1018 ->parse() . '</span>';
1020 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1021 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1022 [ 'from' => $timestamp ],
1026 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1029 public function isIncludable() {
1033 protected function getCacheTTL() {