From 743547c20b382e75423037dc9836744575697bf7 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 25 Aug 2019 23:19:48 +0100 Subject: [PATCH] Setup: Move wgRCLinkDays logic from Setup to ChangesListSpecialPage This is only needed when viewing SpecialRecentChanges (or a related page). Move the consuming logic to that class, where it can be maintained as part of the rest of the code. This also makes it more testable and makes config easier to work with or load from elsewhere in the future. Aside from some dynamic default values, configuration should generally not mutate. If there is some domain- specific way to consume it, the relevant component should be responsible for doing so. This also means we defer such logic to where it is needed, instead of unconditionally for all possible features that might be used. Bug: T189966 Change-Id: If17608909711d98ac560b6d64f72ba7913a561a9 --- includes/DefaultSettings.php | 2 ++ includes/Setup.php | 13 --------- .../specialpage/ChangesListSpecialPage.php | 29 ++++++++++++++++++- includes/specials/SpecialRecentChanges.php | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 8341dac19a..ce6f87c8e6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6844,6 +6844,8 @@ $wgRCLinkLimits = [ 50, 100, 250, 500 ]; /** * List of Days options to list in the Special:Recentchanges and * Special:Recentchangeslinked pages. + * + * @see ChangesListSpecialPage::getLinkDays */ $wgRCLinkDays = [ 1, 3, 7, 14, 30 ]; diff --git a/includes/Setup.php b/includes/Setup.php index 201e1a9d42..4717d1af51 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -368,19 +368,6 @@ foreach ( $wgForeignFileRepos as &$repo ) { unset( $repo ); // no global pollution; destroy reference $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 ); -if ( $wgRCFilterByAge ) { - // Trim down $wgRCLinkDays so that it only lists links which are valid - // as determined by $wgRCMaxAge. - // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link. - sort( $wgRCLinkDays ); - - foreach ( $wgRCLinkDays as $i => $days ) { - if ( $days >= $rcMaxAgeDays ) { - array_splice( $wgRCLinkDays, $i + 1 ); - break; - } - } -} // Ensure that default user options are not invalid, since that breaks Special:Preferences $wgDefaultUserOptions['rcdays'] = min( $wgDefaultUserOptions['rcdays'], diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index 2fa8fab647..3893e92091 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -766,6 +766,33 @@ abstract class ChangesListSpecialPage extends SpecialPage { } } + /** + * @see $wgRCLinkDays in DefaultSettings.php. + * @see $wgRCFilterByAge in DefaultSettings.php. + * @return int[] + */ + protected function getLinkDays() { + $linkDays = $this->getConfig()->get( 'RCLinkDays' ); + $filterByAge = $this->getConfig()->get( 'RCFilterByAge' ); + $maxAge = $this->getConfig()->get( 'RCMaxAge' ); + if ( $filterByAge ) { + // Trim it to only links which are within $wgRCMaxAge. + // Note that we allow one link higher than the max for things like + // "age 56 days" being accessible through the "60 days" link. + sort( $linkDays ); + + $maxAgeDays = $maxAge / ( 3600 * 24 ); + foreach ( $linkDays as $i => $days ) { + if ( $days >= $maxAgeDays ) { + array_splice( $linkDays, $i + 1 ); + break; + } + } + } + + return $linkDays; + } + /** * Include the modules and configuration for the RCFilters app. * Conditional on the user having the feature enabled. @@ -798,7 +825,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'maxDays' => (int)$this->getConfig()->get( 'RCMaxAge' ) / ( 24 * 3600 ), // Translate to days 'limitArray' => $this->getConfig()->get( 'RCLinkLimits' ), 'limitDefault' => $this->getDefaultLimit(), - 'daysArray' => $this->getConfig()->get( 'RCLinkDays' ), + 'daysArray' => $this->getLinkDays(), 'daysDefault' => $this->getDefaultDays(), ] ); diff --git a/includes/specials/SpecialRecentChanges.php b/includes/specials/SpecialRecentChanges.php index 6949c6185c..30f4655bad 100644 --- a/includes/specials/SpecialRecentChanges.php +++ b/includes/specials/SpecialRecentChanges.php @@ -847,7 +847,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { sort( $linkLimits ); $linkLimits = array_unique( $linkLimits ); - $linkDays = $config->get( 'RCLinkDays' ); + $linkDays = $this->getLinkDays(); $linkDays[] = $options['days']; sort( $linkDays ); $linkDays = array_unique( $linkDays ); -- 2.20.1