From ce8701f87beb8b9249edb2c2ce43b2eca5db1b5b Mon Sep 17 00:00:00 2001 From: Edward Chernenko Date: Sun, 17 Nov 2024 21:02:39 +0300 Subject: [PATCH] (1.43) Set $wgLocalFileRepo earlier (before RepoGroup is initialized) See issue #85. Extension:AWS changes $wgLocalFileRepo in replaceLocalRepo(). This is necessary to set public URLs for public/thumb zones. In MediaWiki 1.43, RepoGroup service get initialized much earlier than before, resulting in replaceLocalRepo() being called too late, when LocalRepo is already using the default value of $wgLocalFileRepo (without the correct URLs). Solution is to call replaceLocalRepo() earlier, in MediaWikiServices hook (RepoGroup can't exist at this point). This means we can't use PermissionManager service (not available early) to determine if the wiki is public or not. Alternate implementation checks $wgGroupPermissions directly. --- ChangeLog | 3 +++ extension.json | 6 +++--- includes/AmazonS3Hooks.php | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b74d0a6..5734c02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ List of changes between releases of Extension:AWS. * Added support for upcoming MediaWiki 1.43. +Bugfixes: +* Fixed situation where /img_auth.php was unnecessarily used for public wikis. + Performance optimizations: * S3Client is no longer created if it isn't actually needed for some operation. diff --git a/extension.json b/extension.json index 357dae5..0ef1493 100644 --- a/extension.json +++ b/extension.json @@ -30,9 +30,9 @@ "MWAWS\\FSFile": "includes/MWAWS/FSFile.php", "TrimStringIterator": "includes/TrimStringIterator.php" }, - "ExtensionFunctions": [ - "AmazonS3Hooks::setup" - ], + "Hooks": { + "MediaWikiServices": "AmazonS3Hooks::setup" + }, "config": { "AWSCredentials": { "description": "Credentials to connect to AWS. Setting this in LocalSettings.php is NOT NEEDED if your EC2 instance has an IAM instance profile, and its IAM role allows access to Amazon S3 (see README).", diff --git a/includes/AmazonS3Hooks.php b/includes/AmazonS3Hooks.php index 81aaca5..33ec5b6 100644 --- a/includes/AmazonS3Hooks.php +++ b/includes/AmazonS3Hooks.php @@ -84,7 +84,7 @@ protected function replaceLocalRepo() { // Container names are prefixed by WikiId string, which depends on $wgDBPrefix and $wgDBname. $wikiId = WikiMap::getCurrentWikiId(); - $isPublicWiki = AmazonS3CompatTools::isPublicWiki(); + $isPublicWiki = $this->earlyIsPublicWiki(); // Configure zones (public, thumb, deleted, etc.). $containerPaths = []; @@ -105,6 +105,21 @@ protected function replaceLocalRepo() { $wgFileBackends['s3']['containerPaths'] = $containerPaths; } + /** + * Returns true if everyone (even anonymous users) can see pages in this wiki, false otherwise. + * Unlike AmazonS3CompatTools::isPublicWiki(), this method can be used during early initialization, + * when services like PermissionManager are not available yet. + * @return bool + */ + protected function earlyIsPublicWiki() { + global $wgGroupPermissions, $wgRevokePermissions; + + $allowed = $wgGroupPermissions['*']['read'] ?? true; + $revoked = $wgRevokePermissions['*']['read'] ?? false; + + return $allowed && !$revoked; + } + /** * Returns container path for $zone, based on $wgAWSBucketName or B/C $wgAWSBucketPrefix. * @param string $zone Name of the zone, can be 'public', 'thumb', 'temp' or 'deleted'.