Show user a human readable message when $wgLocaltimezone is set to an invalid timezone

Reason for backport:

This can also be a Debian 13 support issue, some MW installations may
have had `$wgLocaltimezone` set to deprecated values[1] like `PRC`
by the installer or manually.
After they upgrade to Debian 13, the `tzdata` package no longer
provides these timezones, and the `tzdata-legacy` package is not to be
installed by default.

[1]: https://www.php.net/manual/en/timezones.others.php

Bug: T380423
Change-Id: Ie2001796442ee6ba973fdb4b7b1dc7312f802e8d
(cherry picked from commit 45dc435d897d7716ddc8215cb841b07f1c7a2f9c)
This commit is contained in:
Aditya Kumar 2024-11-24 15:53:13 +05:30 committed by Func
parent bc5dad6ace
commit f4e70dc71e

View file

@ -40,6 +40,7 @@ use MediaWiki\Auth\ResetPasswordSecondaryAuthenticationProvider;
use MediaWiki\Auth\TemporaryPasswordAuthenticationRequest;
use MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider;
use MediaWiki\Auth\ThrottlePreAuthenticationProvider;
use MediaWiki\Config\ConfigException;
use MediaWiki\Content\CssContentHandler;
use MediaWiki\Content\FallbackContentHandler;
use MediaWiki\Content\JavaScriptContentHandler;
@ -5104,7 +5105,19 @@ class MainConfigSchema {
// in them, erroneously generated by the installer.
$localtimezone = $localtimezone ?: self::getDefaultLocaltimezone();
$offset = ( new DateTimeZone( $localtimezone ) )->getOffset( new DateTime() );
try {
$timezone = new DateTimeZone( $localtimezone );
} catch ( \Exception $e ) {
throw new ConfigException(
sprintf( "Invalid timezone '%s'. Please set a valid timezone in '$%s' in LocalSettings.php. Refer to the list of valid timezones at https://www.php.net/timezones. Error: %s",
$localtimezone,
"wgLocaltimezone",
$e->getMessage() ),
);
}
$offset = $timezone->getOffset( new DateTime() );
return (int)( $offset / 60 );
}