From 97957ad95280fa36838a7581485d745c64a18c85 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) 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 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. --- extension.json | 6 +++--- includes/AmazonS3Hooks.php | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) 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..c09694a 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'.