Fix external media download - #564
Open
splitbrain wants to merge 4 commits into
Open
Conversation
mpdf used the resolved local file only when its basepathIsLocal flag was set. That flag is false whenever the baseurl host differs from the request host, which a non-default port is enough to cause, since HTTP_HOST carries the port while the parsed basepath host does not. Media was then fetched over HTTP again or, for the dw2pdf:// scheme, not at all, leaving exports without images and without an error message. Fixes a regression from 3c796bb.
media_get_from_URL() refuses to download anything unless the wiki's fetchsize is set, which it is not by default. A browser is redirected to the original URL in that case, but an export has no client to delegate to, so external images were missing from the PDF without an error. The new fetchsize setting caps what an export may download and disables downloading when set to zero. The cache mode now comes from the media URL through calc_cache(), the way fetch.php reads it, so a page asking for nocache or recache is honoured. The wiki's cachetime was applied to every image before, which also turned a cachetime of 0 into nocache for the whole wiki. Media marked nocache is downloaded on every export rather than refused, again because an export has no browser it could redirect to. Fixes #562, a regression from 3c796bb.
Media this wiki serves was requested back from fetch.php whenever it could not be resolved. Such a request is anonymous, so it cannot reach media the exporting user may read, and for external media fetch.php redirects to the origin, which downloaded the file outside the export's own limit. It is refused now. Remote assets mpdf still loads over HTTP, such as external stylesheets and fonts, went through an unbounded DokuHTTPClient. The fetchsize setting caps them now, and a limit of zero refuses the request without contacting the host. Both failures are logged. They used to pass silently because mpdf is wired with a NullLogger.
MediaLinkResolver pointed at the removed ImageProcessor and claimed extractMediaID() determines the mime type, which resolve() does. Both class headers carried a hedge.
3 tasks
Klap-in
reviewed
Aug 26, 2026
| $path = $originalSrc = $resolved['path']; | ||
| $data = parent::fetchDataFromPath($path, $originalSrc); | ||
| if ($data === '') { | ||
| Logger::error('Resolved media could not be read for PDF export', $path); |
Collaborator
There was a problem hiding this comment.
Why is this through a Nulllogger for the AssetFetcher?
Owner
Author
There was a problem hiding this comment.
Logger is the DokuWiki logger. See line 5: use dokuwiki\Logger;
A PSR3 compatible NullLogger is only passed to mpdf.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a fix for #562
It makes the code work the way I had it intended to work: fetch external images first and hand cache paths to mpdf. it worked in my tests because I had a fetchsize set. but default wiki setups do not.
this introduces a fetchsize config to dw2pdf with a 2mb default. it also makes sure that mpdf is not trying to pull stuff via http through fetch.php which is silly and should never be needed now.
this includes the fix from #557