[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] wikiplugin_mediaplayer.php: add wiki attachment URL support and type-based extension fallback
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69b01a032460b_3b1898f45269b@gitlab-sidekiq-low-urgency-cpu-bound-v2-6df5f9ffdd-d7m8c.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
dd67b889 by Alfred Syatsukwa at 2026-03-10T13:00:57+00:00
[FIX] wikiplugin_mediaplayer.php: add wiki attachment URL support and type-based extension fallback
---
* [FIX] wikiplugin_mediaplayer.php: add wiki attachment URL support and type-based extension fallback
See merge request tikiwiki/tiki!9716
- - - - -
1 changed file:
- lib/wiki-plugins/wikiplugin_mediaplayer.php
Changes:
=====================================
lib/wiki-plugins/wikiplugin_mediaplayer.php
=====================================
@@ -103,36 +103,60 @@ function wikiplugin_mediaplayer($data, $params)
} elseif (! is_null($params['src'])) {
// This regex is used to extract the file ID from various URL formats:
// - tiki-display.php?fileId=74
+ // - tiki-download_file.php?fileId=74
+ // - tiki-download_wiki_attachment.php?attId=81
// - display74
// - dl74
//
- // The pattern (?:dl|display|fileId=)(\d*)(?:$|&|?) ensures that:
- // - The correct fileId is captured regardless of URL format.
+ // The pattern (?:dl|display|fileId=|attId=)(\d*)(?:$|&|?) ensures that:
+ // - The correct fileId/attId is captured regardless of URL format.
// - It properly handles URLs with additional parameters.
//
// Ideally, URL parsing should be handled by the routing system (route.php) instead of using a regex in a plugin.
// However, since the necessary abstractions are not currently available, this regex is applied here as a temporary solution.
preg_match('/(?:dl|display|attId=|fileId=)(\d+)(?:$|&|\?|#)/', $params['src'], $matches);
+
+ // Detect wiki attachment URLs (tiki-download_wiki_attachment.php?attId=X)
+ // These are stored in a separate table and handled by a different library than file gallery files.
+ $isWikiAttachment = strpos($params['src'], 'tiki-download_wiki_attachment.php') !== false
+ || (! empty($matches[0]) && strpos($matches[0], 'attId=') === 0);
+
$file = '';
- if (! empty($matches[1])) { // fileId 0 is also invalid
- $fileId = $matches[1];
- $filegallib = TikiLib::lib('filegal');
+ if (! empty($matches[1])) { // fileId/attId 0 is also invalid
+ $itemId = $matches[1];
global $base_url;
$sourceLink = $access->absoluteUrl($params['src']);
// Internal link.
if (strrpos($sourceLink, $base_url) !== false) {
- $file = $filegallib->get_file_info($fileId);
- if (! empty($file['filetype']) && $file['fileId'] == $fileId) {
- $extension = pathinfo($file['filename'], PATHINFO_EXTENSION);
- $params['type'] = $file['filetype'];
- $sourceLink = smarty_modifier_sefurl($fileId, 'display');
- $fileUrl = $access->absoluteUrl($sourceLink);
- $params['src'] = $fileUrl;
+ if ($isWikiAttachment) {
+ // Wiki attachment: use tikilib instead of filegallib.
+ $tikilib = TikiLib::lib('tiki');
+ $file = $tikilib->get_wiki_attachment($itemId);
+ if (! empty($file['filetype']) && $file['attId'] == $itemId) {
+ $extension = pathinfo($file['filename'], PATHINFO_EXTENSION);
+ $params['type'] = $file['filetype'];
+ // Keep $params['src'] pointing to the wiki attachment URL as-is.
+ } else {
+ Feedback::error(tr("PluginMediaPlayer: File %0 not found.", $params['src']));
+ return '';
+ }
} else {
- Feedback::error(tr("PluginMediaPlayer: File %0 not found.", $params['src']));
- return '';
+ // File gallery file.
+ $fileId = $itemId;
+ $filegallib = TikiLib::lib('filegal');
+ $file = $filegallib->get_file_info($fileId);
+ if (! empty($file['filetype']) && $file['fileId'] == $fileId) {
+ $extension = pathinfo($file['filename'], PATHINFO_EXTENSION);
+ $params['type'] = $file['filetype'];
+ $sourceLink = smarty_modifier_sefurl($fileId, 'display');
+ $fileUrl = $access->absoluteUrl($sourceLink);
+ $params['src'] = $fileUrl;
+ } else {
+ Feedback::error(tr("PluginMediaPlayer: File %0 not found.", $params['src']));
+ return '';
+ }
}
} else {
// External link.
@@ -163,6 +187,19 @@ function wikiplugin_mediaplayer($data, $params)
$extension = pathinfo($params['src'], PATHINFO_EXTENSION);
}
+ // If the extension could not be determined from the URL or remote headers,
+ // fall back to deriving it from the 'type' parameter (e.g. 'mp4' or 'video/mp4').
+ if (empty($extension) && ! empty($params['type'])) {
+ $typeHint = strtolower($params['type']);
+ // Strip MIME type prefix (e.g. 'video/mp4' → 'mp4').
+ if (strpos($typeHint, '/') !== false) {
+ $typeHint = substr($typeHint, strrpos($typeHint, '/') + 1);
+ }
+ if (in_array($typeHint, ALL_ACCEPTED_FORMATS)) {
+ $extension = $typeHint;
+ }
+ }
+
if (! in_array($extension, ALL_ACCEPTED_FORMATS)) {
Feedback::error(tr("PluginMediaPlayer: Media format not supported. Here are the supported formats: ") . implode(", ", ALL_ACCEPTED_FORMATS));
return '';
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/dd67b88975de722dcd4f6d667b51bf850de31de6
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/dd67b88975de722dcd4f6d667b51bf850de31de6
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs