From 3b4f1bd41cd4a73a5ed43939f9d857a1e560122f Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 30 Jan 2026 12:31:50 +0100 Subject: [PATCH 1/3] Added user-agent header in requests to Commons DAM --- .../Dam/Handler/WikimediaCommonsHandler.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php index 32398396d8..377c8fc176 100644 --- a/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php +++ b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php @@ -14,6 +14,7 @@ class WikimediaCommonsHandler implements HandlerInterface { + private const USER_AGENT = 'Ibexa DXP Commons Dam Connector'; 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' @@ -22,7 +23,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([])); } @@ -50,7 +60,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'); } From 1a53b54da2621ea537910b12db8af2ed9c33bee8 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Fri, 30 Jan 2026 12:32:30 +0100 Subject: [PATCH 2/3] Fixed author line in view template for Commons DAM --- .../templates/themes/standard/commons_asset_view.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig b/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig index 00a5bac1cd..33affc3362 100644 --- a/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig +++ b/code_samples/back_office/images/templates/themes/standard/commons_asset_view.html.twig @@ -4,7 +4,7 @@ {{ parent() }}
Image - {% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author }}{% endif %} + {% if asset.assetMetadata.author %} by {{ asset.assetMetadata.author|striptags }}{% endif %} {% if asset.assetMetadata.license and asset.assetMetadata.license_url %} under {{ asset.assetMetadata.license }} {% endif %}. From 9b512476589c667b5671dcf316504eec3007aed0 Mon Sep 17 00:00:00 2001 From: vidarl Date: Fri, 30 Jan 2026 11:48:52 +0000 Subject: [PATCH 3/3] PHP & JS CS Fixes --- .../Dam/Handler/WikimediaCommonsHandler.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php index 377c8fc176..485374ac61 100644 --- a/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php +++ b/code_samples/back_office/images/src/Connector/Dam/Handler/WikimediaCommonsHandler.php @@ -15,6 +15,7 @@ class WikimediaCommonsHandler implements HandlerInterface { private const USER_AGENT = 'Ibexa DXP Commons Dam Connector'; + 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' @@ -24,12 +25,12 @@ public function search(Query $query, int $offset = 0, int $limit = 20): AssetSea ; $opts = [ - "http" => [ - "method" => "GET", + 'http' => [ + 'method' => 'GET', 'header' => [ 'User-Agent: ' . self::USER_AGENT, ], - ] + ], ]; $jsonResponse = file_get_contents($searchUrl, false, stream_context_create($opts)); @@ -61,12 +62,12 @@ public function fetchAsset(string $id): Asset ; $opts = [ - "http" => [ - "method" => "GET", + 'http' => [ + 'method' => 'GET', 'header' => [ 'User-Agent: ' . self::USER_AGENT, ], - ] + ], ]; $jsonResponse = file_get_contents($metadataUrl, false, stream_context_create($opts));