edwardspec / mediawiki-aws-s3

Extension:AWS allows MediaWiki to use Amazon S3 (instead of the local directory) to store images.
https://www.mediawiki.org/wiki/Extension:AWS
GNU General Public License v2.0
42 stars 32 forks source link

Issue when using $wgConf to set $wgAWSBucketName #82

Closed OAuthority closed 1 month ago

OAuthority commented 1 month ago

There seems to be some kind of issue with MediaWiki 1.41 and this extension.

MediaWiki internal error.

Original exception: [2feaf6c626289cd6496b94ea] /wiki/File:Google_Stadia.jpg InvalidArgumentException: No backend defined with the name 'local-backend'.
Backtrace:
from /var/www/html/mediawiki/includes/filebackend/FileBackendGroup.php(218)
#0 /var/www/html/mediawiki/includes/filebackend/FileBackendGroup.php(189): FileBackendGroup->config()
#1 /var/www/html/mediawiki/includes/filerepo/FileRepo.php(189): FileBackendGroup->get()
#2 /var/www/html/mediawiki/includes/filerepo/LocalRepo.php(84): FileRepo->__construct()
#3 /var/www/html/mediawiki/includes/filerepo/RepoGroup.php(417): LocalRepo->__construct()
#4 /var/www/html/mediawiki/includes/filerepo/RepoGroup.php(389): RepoGroup->newRepo()
#5 /var/www/html/mediawiki/includes/filerepo/RepoGroup.php(116): RepoGroup->initialiseRepos()
#6 /var/www/html/mediawiki/includes/page/WikiFilePage.php(68): RepoGroup->findFile()
#7 /var/www/html/mediawiki/includes/page/WikiFilePage.php(141): WikiFilePage->loadFile()
#8 /var/www/html/mediawiki/includes/MediaWiki.php(489): WikiFilePage->getFile()
#9 /var/www/html/mediawiki/includes/MediaWiki.php(361): MediaWiki->initializeArticle()
#10 /var/www/html/mediawiki/includes/MediaWiki.php(960): MediaWiki->performRequest()
#11 /var/www/html/mediawiki/includes/MediaWiki.php(613): MediaWiki->main()
#12 /var/www/html/mediawiki/index.php(50): MediaWiki->run()
#13 /var/www/html/mediawiki/index.php(46): wfIndexMain()
#14 {main}

Exception caught inside exception handler: [2feaf6c626289cd6496b94ea] /wiki/File:Google_Stadia.jpg Error: Call to a member function findFile() on null
Backtrace:
from /var/www/html/mediawiki/includes/filerepo/RepoGroup.php(140)
#0 /var/www/html/mediawiki/includes/page/WikiFilePage.php(68): RepoGroup->findFile()
#1 /var/www/html/mediawiki/includes/page/WikiFilePage.php(141): WikiFilePage->loadFile()
#2 /var/www/html/mediawiki/includes/page/WikiFilePage.php(268): WikiFilePage->getFile()
#3 /var/www/html/mediawiki/includes/page/Article.php(2025): WikiFilePage->getActionOverrides()
#4 /var/www/html/mediawiki/includes/actions/ActionFactory.php(258): Article->getActionOverrides()
#5 /var/www/html/mediawiki/includes/actions/ActionFactory.php(404): MediaWiki\Actions\ActionFactory->getAction()
#6 /var/www/html/mediawiki/includes/context/RequestContext.php(306): MediaWiki\Actions\ActionFactory->getActionName()
#7 /var/www/html/mediawiki/includes/context/ContextSource.php(134): RequestContext->getActionName()
#8 /var/www/html/mediawiki/extensions/CodeMirror/includes/Hooks.php(48): ContextSource->getActionName()
#9 /var/www/html/mediawiki/extensions/CodeMirror/includes/Hooks.php(63): MediaWiki\Extension\CodeMirror\Hooks->isCodeMirrorOnPage()
#10 /var/www/html/mediawiki/includes/HookContainer/HookContainer.php(161): MediaWiki\Extension\CodeMirror\Hooks->onBeforePageDisplay()
#11 /var/www/html/mediawiki/includes/HookContainer/HookRunner.php(938): MediaWiki\HookContainer\HookContainer->run()
#12 /var/www/html/mediawiki/includes/Output/OutputPage.php(2942): MediaWiki\HookContainer\HookRunner->onBeforePageDisplay()
#13 /var/www/html/mediawiki/includes/exception/MWExceptionRenderer.php(188): MediaWiki\Output\OutputPage->output()
#14 /var/www/html/mediawiki/includes/exception/MWExceptionRenderer.php(105): MWExceptionRenderer::reportHTML()
#15 /var/www/html/mediawiki/includes/exception/MWExceptionHandler.php(134): MWExceptionRenderer::output()
#16 /var/www/html/mediawiki/includes/exception/MWExceptionHandler.php(251): MWExceptionHandler::report()
#17 /var/www/html/mediawiki/includes/MediaWiki.php(632): MWExceptionHandler::handleException()
#18 /var/www/html/mediawiki/index.php(50): MediaWiki->run()
#19 /var/www/html/mediawiki/index.php(46): wfIndexMain()
#20 {main}

I'm using the same configuration that was being used for MediaWiki 1.39, which worked perfectly:

'wgAWSRegion' => [
        'default' => 'eu-west-2'
    ],
    'wgAWSBucketDomain' => [
        'default' => 'static.domain.com'
    ],
    'wgAWSRepoHashLevels' => [
        'default' => 2
    ],
    'wgAWSRepoDeletedHashLevels' => [
        'default' => 3
    ],
    'wgAWSBucketName' => [
        'default' => 'static.domain.com'
    ],
    'wgAWSBucketTopSubdirectory' => [
        'default' => "/$wgDBname"
    ],

So nothing has changed there, and the extension is still loaded. I don't think this is anything I'm doing on my end? Running the master branch on 1.41.2.

OAuthority commented 1 month ago

This seems to happen when disabling extensions like CodeEditor too, so I don't think its being caused by that.

OAuthority commented 1 month ago

I managed to fix this with the addition of:

$wgLocalFileRepo = [
    'class' => LocalRepo::class,
    'name' => 'local',
    'backend' => 'AmazonS3',
    'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
    'scriptDirUrl' => $wgScriptPath,
    'hashLevels' => 2,
    'thumbScriptUrl' => $wgThumbnailScriptPath,
    'transformVia404' => true,
    'useJsonMetadata'   => true,
    'useSplitMetadata'  => true,
    'deletedHashLevels' => 3,
    'abbrvThreshold' => 160,
    'isPrivate' => $cwPrivate,
    'zones' => $cwPrivate
        ? [
            'thumb' => [ 'url' => "$wgScriptPath/thumb_handler.php" ] ]
        : [],
];

This wasn't necessary in 1.39? Is it now necessary to define this in addition to the AWS extension config?

edwardspec commented 1 month ago

I managed to fix this with the addition of:

It shouldn't have had any effect. If $wgAWSBucketName is defined, then this extension completely overwrites $wgLocalFileRepo.

I suspect that the way in which you are configuring the wiki results in $wgAWSBucketName being set too late (after AmazonS3Hooks::setup() has already been called). When this function doesn't find $wgAWSBucketName, it skips auto-configuration of $wgLocalFileRepo.

OAuthority commented 1 month ago

Interesting -- the way I have configured $wgAWSBucketName hasn't changed between 1.39 and 1.41, its defined in the exact same place at the top of $wgConf as it was in 1.39 which worked seamlessly.

Perhaps there was some other change in 1.41 core which has caused this; notwithstanding that, the workaround I posted above works fine so I'll use that.

edwardspec commented 1 month ago

If anyone else has this problem, please use the workaround above, it is the correct/intended way.

I considered changing the extension to call AmazonS3Hooks::setup() later (when $wgConf has already been applied), but it might cause other issues (e.g. if some extension uses FileBackend very early), so let's not do this for now.