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 $out->addJsConfigVars( 'wgStructuredChangeFilters', $jsData['groups'] );
181 $out->addJsConfigVars(
182 'wgStructuredChangeFiltersEnableSaving',
183 $this->getConfig()->get( 'StructuredChangeFiltersEnableSaving' )
185 $out->addJsConfigVars(
186 'wgStructuredChangeFiltersEnableExperimentalViews',
187 $this->getConfig()->get( 'StructuredChangeFiltersEnableExperimentalViews' )
189 $out->addJsConfigVars(
190 'wgStructuredChangeFiltersEnableLiveUpdate',
191 $this->getConfig()->get( 'StructuredChangeFiltersEnableLiveUpdate' )
193 $out->addJsConfigVars(
194 'wgRCFiltersChangeTags',
195 $this->buildChangeTagList()
201 * Fetch the change tags list for the front end
203 * @return Array Tag data
205 protected function buildChangeTagList() {
206 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
207 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
208 $tagStats = ChangeTags
::tagUsageStatistics();
210 $tagHitCounts = array_merge( $explicitlyDefinedTags, $softwareActivatedTags, $tagStats );
213 arsort( $tagHitCounts );
215 // Build the list and data
217 foreach ( $tagHitCounts as $tagName => $hits ) {
219 // Only get active tags
220 isset( $explicitlyDefinedTags[ $tagName ] ) ||
221 isset( $softwareActivatedTags[ $tagName ] )
224 $desc = ChangeTags
::tagLongDescriptionMessage( $tagName, $this->getContext() );
228 'label' => Sanitizer
::stripAllTags(
229 ChangeTags
::tagDescription( $tagName, $this->getContext() )
231 'description' => $desc ? Sanitizer
::stripAllTags( $desc->parse() ) : '',
232 'cssClass' => Sanitizer
::escapeClass( 'mw-tag-' . $tagName ),
244 protected function transformFilterDefinition( array $filterDefinition ) {
245 if ( isset( $filterDefinition['showHideSuffix'] ) ) {
246 $filterDefinition['showHide'] = 'rc' . $filterDefinition['showHideSuffix'];
249 return $filterDefinition;
255 protected function registerFilters() {
256 parent
::registerFilters();
259 !$this->including() &&
260 $this->getUser()->isLoggedIn() &&
261 $this->getUser()->isAllowed( 'viewmywatchlist' )
263 $this->registerFiltersFromDefinitions( [ $this->watchlistFilterGroupDefinition
] );
264 $watchlistGroup = $this->getFilterGroup( 'watchlist' );
265 $watchlistGroup->getFilter( 'watched' )->setAsSupersetOf(
266 $watchlistGroup->getFilter( 'watchednew' )
270 $user = $this->getUser();
272 $significance = $this->getFilterGroup( 'significance' );
273 $hideMinor = $significance->getFilter( 'hideminor' );
274 $hideMinor->setDefault( $user->getBoolOption( 'hideminor' ) );
276 $automated = $this->getFilterGroup( 'automated' );
277 $hideBots = $automated->getFilter( 'hidebots' );
278 $hideBots->setDefault( true );
280 $reviewStatus = $this->getFilterGroup( 'reviewStatus' );
281 if ( $reviewStatus !== null ) {
282 // Conditional on feature being available and rights
283 $hidePatrolled = $reviewStatus->getFilter( 'hidepatrolled' );
284 $hidePatrolled->setDefault( $user->getBoolOption( 'hidepatrolled' ) );
287 $changeType = $this->getFilterGroup( 'changeType' );
288 $hideCategorization = $changeType->getFilter( 'hidecategorization' );
289 if ( $hideCategorization !== null ) {
290 // Conditional on feature being available
291 $hideCategorization->setDefault( $user->getBoolOption( 'hidecategorization' ) );
296 * Get a FormOptions object containing the default options
298 * @return FormOptions
300 public function getDefaultOptions() {
301 $opts = parent
::getDefaultOptions();
302 $user = $this->getUser();
304 $opts->add( 'days', $user->getIntOption( 'rcdays' ) );
305 $opts->add( 'limit', $user->getIntOption( 'rclimit' ) );
306 $opts->add( 'from', '' );
308 $opts->add( 'categories', '' );
309 $opts->add( 'categories_any', false );
310 $opts->add( 'tagfilter', '' );
316 * Get all custom filters
318 * @return array Map of filter URL param names to properties (msg/default)
320 protected function getCustomFilters() {
321 if ( $this->customFilters
=== null ) {
322 $this->customFilters
= parent
::getCustomFilters();
323 Hooks
::run( 'SpecialRecentChangesFilters', [ $this, &$this->customFilters
], '1.23' );
326 return $this->customFilters
;
330 * Process $par and put options found in $opts. Used when including the page.
333 * @param FormOptions $opts
335 public function parseParameters( $par, FormOptions
$opts ) {
336 parent
::parseParameters( $par, $opts );
338 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
339 foreach ( $bits as $bit ) {
340 if ( is_numeric( $bit ) ) {
341 $opts['limit'] = $bit;
345 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) ) {
346 $opts['limit'] = $m[1];
348 if ( preg_match( '/^days=(\d+)$/', $bit, $m ) ) {
349 $opts['days'] = $m[1];
351 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
352 $opts['namespace'] = $m[1];
354 if ( preg_match( '/^tagfilter=(.*)$/', $bit, $m ) ) {
355 $opts['tagfilter'] = $m[1];
360 public function validateOptions( FormOptions
$opts ) {
361 $opts->validateIntBounds( 'limit', 0, 5000 );
362 parent
::validateOptions( $opts );
368 protected function buildQuery( &$tables, &$fields, &$conds,
369 &$query_options, &$join_conds, FormOptions
$opts
371 $dbr = $this->getDB();
372 parent
::buildQuery( $tables, $fields, $conds,
373 $query_options, $join_conds, $opts );
376 $cutoff_unixtime = time() - ( $opts['days'] * 86400 );
377 $cutoff_unixtime = $cutoff_unixtime - ( $cutoff_unixtime %
86400 );
378 $cutoff = $dbr->timestamp( $cutoff_unixtime );
380 $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] );
381 if ( $fromValid && $opts['from'] > wfTimestamp( TS_MW
, $cutoff ) ) {
382 $cutoff = $dbr->timestamp( $opts['from'] );
384 $opts->reset( 'from' );
387 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
393 protected function doMainQuery( $tables, $fields, $conds, $query_options,
394 $join_conds, FormOptions
$opts
396 $dbr = $this->getDB();
397 $user = $this->getUser();
399 $tables[] = 'recentchanges';
400 $fields = array_merge( RecentChange
::selectFields(), $fields );
402 // JOIN on watchlist for users
403 if ( $user->isLoggedIn() && $user->isAllowed( 'viewmywatchlist' ) ) {
404 $tables[] = 'watchlist';
405 $fields[] = 'wl_user';
406 $fields[] = 'wl_notificationtimestamp';
407 $join_conds['watchlist'] = [ 'LEFT JOIN', [
408 'wl_user' => $user->getId(),
410 'wl_namespace=rc_namespace'
414 // JOIN on page, used for 'last revision' filter highlight
416 $fields[] = 'page_latest';
417 $join_conds['page'] = [ 'LEFT JOIN', 'rc_cur_id=page_id' ];
419 ChangeTags
::modifyDisplayQuery(
428 if ( !$this->runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds,
434 if ( $this->areFiltersInConflict() ) {
438 // array_merge() is used intentionally here so that hooks can, should
439 // they so desire, override the ORDER BY / LIMIT condition(s); prior to
440 // MediaWiki 1.26 this used to use the plus operator instead, which meant
441 // that extensions weren't able to change these conditions
442 $query_options = array_merge( [
443 'ORDER BY' => 'rc_timestamp DESC',
444 'LIMIT' => $opts['limit'] ], $query_options );
445 $rows = $dbr->select(
448 // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough
449 // knowledge to use an index merge if it wants (it may use some other index though).
450 $conds +
[ 'rc_new' => [ 0, 1 ] ],
456 // Build the final data
457 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
458 $this->filterByCategories( $rows, $opts );
464 protected function runMainQueryHook( &$tables, &$fields, &$conds,
465 &$query_options, &$join_conds, $opts
467 return parent
::runMainQueryHook( $tables, $fields, $conds, $query_options, $join_conds, $opts )
469 'SpecialRecentChangesQuery',
470 [ &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ],
475 protected function getDB() {
476 return wfGetDB( DB_REPLICA
, 'recentchanges' );
479 public function outputFeedLinks() {
480 $this->addFeedLinks( $this->getFeedQuery() );
484 * Get URL query parameters for action=feedrecentchanges API feed of current recent changes view.
488 protected function getFeedQuery() {
489 $query = array_filter( $this->getOptions()->getAllValues(), function ( $value ) {
490 // API handles empty parameters in a different way
491 return $value !== '';
493 $query['action'] = 'feedrecentchanges';
494 $feedLimit = $this->getConfig()->get( 'FeedLimit' );
495 if ( $query['limit'] > $feedLimit ) {
496 $query['limit'] = $feedLimit;
503 * Build and output the actual changes list.
505 * @param ResultWrapper $rows Database rows
506 * @param FormOptions $opts
508 public function outputChangesList( $rows, $opts ) {
509 $limit = $opts['limit'];
511 $showWatcherCount = $this->getConfig()->get( 'RCShowWatchingUsers' )
512 && $this->getUser()->getOption( 'shownumberswatching' );
515 $dbr = $this->getDB();
518 $list = ChangesList
::newFromContext( $this->getContext(), $this->filterGroups
);
519 $list->initChangesListRows( $rows );
521 $userShowHiddenCats = $this->getUser()->getBoolOption( 'showhiddencats' );
522 $rclistOutput = $list->beginRecentChangesList();
523 if ( $this->isStructuredFilterUiEnabled() ) {
524 $rclistOutput .= $this->makeLegend();
527 foreach ( $rows as $obj ) {
531 $rc = RecentChange
::newFromRow( $obj );
533 # Skip CatWatch entries for hidden cats based on user preference
535 $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE
&&
536 !$userShowHiddenCats &&
537 $rc->getParam( 'hidden-cat' )
542 $rc->counter
= $counter++
;
543 # Check if the page has been updated since the last visit
544 if ( $this->getConfig()->get( 'ShowUpdatedMarker' )
545 && !empty( $obj->wl_notificationtimestamp
)
547 $rc->notificationtimestamp
= ( $obj->rc_timestamp
>= $obj->wl_notificationtimestamp
);
549 $rc->notificationtimestamp
= false; // Default
551 # Check the number of users watching the page
552 $rc->numberofWatchingusers
= 0; // Default
553 if ( $showWatcherCount && $obj->rc_namespace
>= 0 ) {
554 if ( !isset( $watcherCache[$obj->rc_namespace
][$obj->rc_title
] ) ) {
555 $watcherCache[$obj->rc_namespace
][$obj->rc_title
] =
556 MediaWikiServices
::getInstance()->getWatchedItemStore()->countWatchers(
557 new TitleValue( (int)$obj->rc_namespace
, $obj->rc_title
)
560 $rc->numberofWatchingusers
= $watcherCache[$obj->rc_namespace
][$obj->rc_title
];
563 $changeLine = $list->recentChangesLine( $rc, !empty( $obj->wl_user
), $counter );
564 if ( $changeLine !== false ) {
565 $rclistOutput .= $changeLine;
569 $rclistOutput .= $list->endRecentChangesList();
571 if ( $rows->numRows() === 0 ) {
572 $this->outputNoResults();
573 if ( !$this->including() ) {
574 $this->getOutput()->setStatusCode( 404 );
577 $this->getOutput()->addHTML( $rclistOutput );
582 * Set the text to be displayed above the changes
584 * @param FormOptions $opts
585 * @param int $numRows Number of rows in the result to show after this header
587 public function doHeader( $opts, $numRows ) {
588 $this->setTopText( $opts );
590 $defaults = $opts->getAllValues();
591 $nondefaults = $opts->getChangedValues();
594 if ( !$this->isStructuredFilterUiEnabled() ) {
595 $panel[] = $this->makeLegend();
597 $panel[] = $this->optionsPanel( $defaults, $nondefaults, $numRows );
600 $extraOpts = $this->getExtraOptions( $opts );
601 $extraOptsCount = count( $extraOpts );
603 $submit = ' ' . Xml
::submitButton( $this->msg( 'recentchanges-submit' )->text() );
605 $out = Xml
::openElement( 'table', [ 'class' => 'mw-recentchanges-table' ] );
606 foreach ( $extraOpts as $name => $optionRow ) {
607 # Add submit button to the last row only
609 $addSubmit = ( $count === $extraOptsCount ) ?
$submit : '';
611 $out .= Xml
::openElement( 'tr' );
612 if ( is_array( $optionRow ) ) {
615 [ 'class' => 'mw-label mw-' . $name . '-label' ],
620 [ 'class' => 'mw-input' ],
621 $optionRow[1] . $addSubmit
626 [ 'class' => 'mw-input', 'colspan' => 2 ],
627 $optionRow . $addSubmit
630 $out .= Xml
::closeElement( 'tr' );
632 $out .= Xml
::closeElement( 'table' );
634 $unconsumed = $opts->getUnconsumedValues();
635 foreach ( $unconsumed as $key => $value ) {
636 $out .= Html
::hidden( $key, $value );
639 $t = $this->getPageTitle();
640 $out .= Html
::hidden( 'title', $t->getPrefixedText() );
641 $form = Xml
::tags( 'form', [ 'action' => wfScript() ], $out );
643 $panelString = implode( "\n", $panel );
645 $rcoptions = Xml
::fieldset(
646 $this->msg( 'recentchanges-legend' )->text(),
648 [ 'class' => 'rcoptions' ]
651 // Insert a placeholder for RCFilters
652 if ( $this->getUser()->getOption( 'rcenhancedfilters' ) ) {
653 $rcfilterContainer = Html
::element(
655 [ 'class' => 'rcfilters-container' ]
658 // Wrap both with rcfilters-head
659 $this->getOutput()->addHTML(
662 [ 'class' => 'rcfilters-head' ],
663 $rcfilterContainer . $rcoptions
667 $this->getOutput()->addHTML( $rcoptions );
670 $this->setBottomText( $opts );
674 * Send the text to be displayed above the options
676 * @param FormOptions $opts Unused
678 function setTopText( FormOptions
$opts ) {
681 $message = $this->msg( 'recentchangestext' )->inContentLanguage();
682 if ( !$message->isDisabled() ) {
683 $this->getOutput()->addWikiText(
684 Html
::rawElement( 'div',
686 'class' => 'mw-recentchanges-toplinks',
687 'lang' => $wgContLang->getHtmlCode(),
688 'dir' => $wgContLang->getDir()
690 "\n" . $message->plain() . "\n"
692 /* $lineStart */ true,
693 /* $interface */ false
699 * Get options to be displayed in a form
701 * @param FormOptions $opts
704 function getExtraOptions( $opts ) {
705 $opts->consumeValues( [
706 'namespace', 'invert', 'associated', 'tagfilter', 'categories', 'categories_any'
710 $extraOpts['namespace'] = $this->namespaceFilterForm( $opts );
712 if ( $this->getConfig()->get( 'AllowCategorizedRecentChanges' ) ) {
713 $extraOpts['category'] = $this->categoryFilterForm( $opts );
716 $tagFilter = ChangeTags
::buildTagFilterSelector(
717 $opts['tagfilter'], false, $this->getContext() );
718 if ( count( $tagFilter ) ) {
719 $extraOpts['tagfilter'] = $tagFilter;
722 // Don't fire the hook for subclasses. (Or should we?)
723 if ( $this->getName() === 'Recentchanges' ) {
724 Hooks
::run( 'SpecialRecentChangesPanel', [ &$extraOpts, $opts ] );
731 * Check whether the structured filter UI is enabled
735 protected function isStructuredFilterUiEnabled() {
736 return $this->getUser()->getOption(
742 * Add page-specific modules.
744 protected function addModules() {
745 parent
::addModules();
746 $out = $this->getOutput();
747 $out->addModules( 'mediawiki.special.recentchanges' );
748 if ( $this->isStructuredFilterUiEnabled() ) {
749 $out->addModules( 'mediawiki.rcfilters.filters.ui' );
750 $out->addModuleStyles( 'mediawiki.rcfilters.filters.base.styles' );
755 * Get last modified date, for client caching
756 * Don't use this if we are using the patrol feature, patrol changes don't
757 * update the timestamp
759 * @return string|bool
761 public function checkLastModified() {
762 $dbr = $this->getDB();
763 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__
);
769 * Creates the choose namespace selection
771 * @param FormOptions $opts
774 protected function namespaceFilterForm( FormOptions
$opts ) {
775 $nsSelect = Html
::namespaceSelector(
776 [ 'selected' => $opts['namespace'], 'all' => '' ],
777 [ 'name' => 'namespace', 'id' => 'namespace' ]
779 $nsLabel = Xml
::label( $this->msg( 'namespace' )->text(), 'namespace' );
780 $invert = Xml
::checkLabel(
781 $this->msg( 'invert' )->text(), 'invert', 'nsinvert',
783 [ 'title' => $this->msg( 'tooltip-invert' )->text() ]
785 $associated = Xml
::checkLabel(
786 $this->msg( 'namespace_association' )->text(), 'associated', 'nsassociated',
788 [ 'title' => $this->msg( 'tooltip-namespace_association' )->text() ]
791 return [ $nsLabel, "$nsSelect $invert $associated" ];
795 * Create an input to filter changes by categories
797 * @param FormOptions $opts
800 protected function categoryFilterForm( FormOptions
$opts ) {
801 list( $label, $input ) = Xml
::inputLabelSep( $this->msg( 'rc_categories' )->text(),
802 'categories', 'mw-categories', false, $opts['categories'] );
804 $input .= ' ' . Xml
::checkLabel( $this->msg( 'rc_categories_any' )->text(),
805 'categories_any', 'mw-categories_any', $opts['categories_any'] );
807 return [ $label, $input ];
811 * Filter $rows by categories set in $opts
813 * @param ResultWrapper $rows Database rows
814 * @param FormOptions $opts
816 function filterByCategories( &$rows, FormOptions
$opts ) {
817 $categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
819 if ( !count( $categories ) ) {
825 foreach ( $categories as $cat ) {
837 foreach ( $rows as $k => $r ) {
838 $nt = Title
::makeTitle( $r->rc_namespace
, $r->rc_title
);
839 $id = $nt->getArticleID();
841 continue; # Page might have been deleted...
843 if ( !in_array( $id, $articles ) ) {
846 if ( !isset( $a2r[$id] ) ) {
854 if ( !count( $articles ) ||
!count( $cats ) ) {
859 $catFind = new CategoryFinder
;
860 $catFind->seed( $articles, $cats, $opts['categories_any'] ?
'OR' : 'AND' );
861 $match = $catFind->run();
865 foreach ( $match as $id ) {
866 foreach ( $a2r[$id] as $rev ) {
868 $newrows[$k] = $rowsarr[$k];
871 $rows = new FakeResultWrapper( array_values( $newrows ) );
875 * Makes change an option link which carries all the other options
877 * @param string $title Title
878 * @param array $override Options to override
879 * @param array $options Current options
880 * @param bool $active Whether to show the link in bold
883 function makeOptionsLink( $title, $override, $options, $active = false ) {
884 $params = $this->convertParamsForLink( $override +
$options );
887 $title = new HtmlArmor( '<strong>' . htmlspecialchars( $title ) . '</strong>' );
890 return $this->getLinkRenderer()->makeKnownLink( $this->getPageTitle(), $title, [
891 'data-params' => json_encode( $override ),
892 'data-keys' => implode( ',', array_keys( $override ) ),
897 * Creates the options panel.
899 * @param array $defaults
900 * @param array $nondefaults
901 * @param int $numRows Number of rows in the result to show after this header
904 function optionsPanel( $defaults, $nondefaults, $numRows ) {
905 $options = $nondefaults +
$defaults;
908 $msg = $this->msg( 'rclegend' );
909 if ( !$msg->isDisabled() ) {
910 $note .= '<div class="mw-rclegend">' . $msg->parse() . "</div>\n";
913 $lang = $this->getLanguage();
914 $user = $this->getUser();
915 $config = $this->getConfig();
916 if ( $options['from'] ) {
917 $resetLink = $this->makeOptionsLink( $this->msg( 'rclistfromreset' ),
918 [ 'from' => '' ], $nondefaults );
920 $note .= $this->msg( 'rcnotefrom' )
921 ->numParams( $options['limit'] )
923 $lang->userTimeAndDate( $options['from'], $user ),
924 $lang->userDate( $options['from'], $user ),
925 $lang->userTime( $options['from'], $user )
927 ->numParams( $numRows )
931 [ 'class' => 'rcoptions-listfromreset' ],
932 $this->msg( 'parentheses' )->rawParams( $resetLink )->parse()
937 # Sort data for display and make sure it's unique after we've added user data.
938 $linkLimits = $config->get( 'RCLinkLimits' );
939 $linkLimits[] = $options['limit'];
941 $linkLimits = array_unique( $linkLimits );
943 $linkDays = $config->get( 'RCLinkDays' );
944 $linkDays[] = $options['days'];
946 $linkDays = array_unique( $linkDays );
950 foreach ( $linkLimits as $value ) {
951 $cl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
952 [ 'limit' => $value ], $nondefaults, $value == $options['limit'] );
954 $cl = $lang->pipeList( $cl );
956 // day links, reset 'from' to none
958 foreach ( $linkDays as $value ) {
959 $dl[] = $this->makeOptionsLink( $lang->formatNum( $value ),
960 [ 'days' => $value, 'from' => '' ], $nondefaults, $value == $options['days'] );
962 $dl = $lang->pipeList( $dl );
964 $showhide = [ 'show', 'hide' ];
968 $filterGroups = $this->getFilterGroups();
970 $context = $this->getContext();
971 foreach ( $filterGroups as $groupName => $group ) {
972 if ( !$group->isPerGroupRequestParameter() ) {
973 foreach ( $group->getFilters() as $key => $filter ) {
974 if ( $filter->displaysOnUnstructuredUi( $this ) ) {
975 $msg = $filter->getShowHide();
976 $linkMessage = $this->msg( $msg . '-' . $showhide[1 - $options[$key]] );
977 // Extensions can define additional filters, but don't need to define the corresponding
978 // messages. If they don't exist, just fall back to 'show' and 'hide'.
979 if ( !$linkMessage->exists() ) {
980 $linkMessage = $this->msg( $showhide[1 - $options[$key]] );
983 $link = $this->makeOptionsLink( $linkMessage->text(),
984 [ $key => 1 - $options[$key] ], $nondefaults );
987 'class' => "$msg rcshowhideoption",
988 'data-filter-name' => $filter->getName(),
991 if ( $filter->isFeatureAvailableOnStructuredUi( $this ) ) {
992 $attribs['data-feature-in-structured-ui'] = true;
995 $links[] = Html
::rawElement(
998 $this->msg( $msg )->rawParams( $link )->escaped()
1005 // show from this onward link
1006 $timestamp = wfTimestampNow();
1007 $now = $lang->userTimeAndDate( $timestamp, $user );
1008 $timenow = $lang->userTime( $timestamp, $user );
1009 $datenow = $lang->userDate( $timestamp, $user );
1010 $pipedLinks = '<span class="rcshowhide">' . $lang->pipeList( $links ) . '</span>';
1012 $rclinks = '<span class="rclinks">' . $this->msg( 'rclinks' )->rawParams( $cl, $dl, '' )
1013 ->parse() . '</span>';
1015 $rclistfrom = '<span class="rclistfrom">' . $this->makeOptionsLink(
1016 $this->msg( 'rclistfrom' )->rawParams( $now, $timenow, $datenow )->parse(),
1017 [ 'from' => $timestamp ],
1021 return "{$note}$rclinks<br />$pipedLinks<br />$rclistfrom";
1024 public function isIncludable() {
1028 protected function getCacheTTL() {