Skip to content

Fix external media download - #564

Open
splitbrain wants to merge 4 commits into
masterfrom
external-media-download
Open

Fix external media download#564
splitbrain wants to merge 4 commits into
masterfrom
external-media-download

Conversation

@splitbrain

Copy link
Copy Markdown
Owner

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

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.
Comment thread src/DokuAssetFetcher.php
$path = $originalSrc = $resolved['path'];
$data = parent::fetchDataFromPath($path, $originalSrc);
if ($data === '') {
Logger::error('Resolved media could not be read for PDF export', $path);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this through a Nulllogger for the AssetFetcher?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger is the DokuWiki logger. See line 5: use dokuwiki\Logger;

A PSR3 compatible NullLogger is only passed to mpdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants