Setup.php: Ensure that defaults for 'rcdays' and 'watchlistdays' are not invalid
authorBartosz Dziewoński <matma.rex@gmail.com>
Tue, 29 Dec 2015 13:24:27 +0000 (14:24 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Tue, 29 Dec 2015 13:40:20 +0000 (14:40 +0100)
I ran into this when I set $wgRCMaxAge = 3600*24 (1 day) when testing
recent changes stuff.

Change-Id: Ib618f0e47f30ebe1ad44f4c70fee5789bfa8c095

includes/Setup.php

index c863722..9e4d2a3 100644 (file)
@@ -264,6 +264,7 @@ 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.
@@ -273,12 +274,22 @@ if ( $wgRCFilterByAge ) {
        // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
        for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
                // @codingStandardsIgnoreEnd
-               if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
+               if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
                        $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
                        break;
                }
        }
 }
+// Ensure that default user options are not invalid, since that breaks Special:Preferences
+$wgDefaultUserOptions['rcdays'] = min(
+       $wgDefaultUserOptions['rcdays'],
+       ceil( $rcMaxAgeDays )
+);
+$wgDefaultUserOptions['watchlistdays'] = min(
+       $wgDefaultUserOptions['watchlistdays'],
+       ceil( $rcMaxAgeDays )
+);
+unset( $rcMaxAgeDays );
 
 if ( $wgSkipSkin ) {
        $wgSkipSkins[] = $wgSkipSkin;