Skip to content

Commit

Permalink
(1.43) Set $wgLocalFileRepo earlier (before RepoGroup is initialized)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edwardspec committed Nov 17, 2024
1 parent 62b247b commit ce8701f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down
17 changes: 16 additions & 1 deletion includes/AmazonS3Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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'.
Expand Down

0 comments on commit ce8701f

Please sign in to comment.