Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

class WikimediaCommonsHandler implements HandlerInterface
{
private const USER_AGENT = 'Ibexa DXP Commons Dam Connector';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe you want to inject Product name somehow . Wasn't sure if that worked in code snippets so hardcoded "Ibexa DXP"...


public function search(Query $query, int $offset = 0, int $limit = 20): AssetSearchResult
{
$searchUrl = 'https://commons.wikimedia.org/w/api.php?action=query&list=search&format=json&srnamespace=6'
Expand All @@ -22,7 +24,16 @@ public function search(Query $query, int $offset = 0, int $limit = 20): AssetSea
. '&srlimit=' . $limit
;

$jsonResponse = file_get_contents($searchUrl);
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: ' . self::USER_AGENT,
],
],
];

$jsonResponse = file_get_contents($searchUrl, false, stream_context_create($opts));
if ($jsonResponse === false) {
return new AssetSearchResult(0, new AssetCollection([]));
}
Expand Down Expand Up @@ -50,7 +61,16 @@ public function fetchAsset(string $id): Asset
. '&titles=File%3a' . urlencode($id)
;

$jsonResponse = file_get_contents($metadataUrl);
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: ' . self::USER_AGENT,
],
],
];

$jsonResponse = file_get_contents($metadataUrl, false, stream_context_create($opts));
if ($jsonResponse === false) {
throw new \RuntimeException('Couldn\'t retrieve asset metadata');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ parent() }}
<div>
<a href="{{ asset.assetMetadata.page_url }}">Image</a>
{% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author }}{% endif %}
{% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author|striptags }}{% endif %}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we trust that the URL coming from Commons cannot contain bad things. This will display the author as link:

Suggested change
{% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author|striptags }}{% endif %}
{% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author|raw }}{% endif %}

@mnocon mnocon Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a 3rd party site so we can never be 100% sure - and this template is just an example, this will be easy to modify.

I'd keep it as it (striptags instead of raw), better safe than sorry

@adriendupuis adriendupuis Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://commons.wikimedia.org/wiki/Commons:Reusing_content_outside_Wikimedia and https://commons.wikimedia.org/wiki/Commons:Credit_line#Credit_lines_required_by_license doesn't seem to specifically require a link on the author, I guess the link to the image page is enough. To strip the author link shouldn't be an legal issue. In short, I'm OK with this change.

{% if asset.assetMetadata.license and asset.assetMetadata.license_url %}
under <a href="{{ asset.assetMetadata.license_url }}">{{ asset.assetMetadata.license }}</a>
{% endif %}.
Expand Down