00472: Attaching files belonging to other groups

Summary: Attaching files belonging to other groups
Created: 2005-07-18 05:02
Status: Closed
Category: Not a Bug
From: Klonk
Assigned:
Priority: 45
Version: 2.0beta48
OS:

Description: As I read in the documentation I could Attach files that belong to other groups in that way:

 
 Attach:OtherGroup/filename.ext
 

The simple problem is: It does not work! Or does it have to be activated somewhere??


What part of it "doesn't work"? It seems to work on pmwiki.org -- Attach:Cookbook/gemini.zip .

--Pm


Well simple: I have a file with Attach:somefile.gif in a group lets say "Test". I have the same file with Attach:somefile.gif in a group lets say "Testing". Now I removed the file from the Testing's upload directory and changed the call to Attach:Test/somefile.gif@. The attachment link is not replaced by the image (as it should).

Maybe this helps:

When looking at the resulting link I see: ... wiki.php/Testing/Test?action=upload&upname=somefile.gif

As you can see /Testing is too much in the URL. Interesting enough it worked once but then never again (maybe some cache issue???) -- Klonk


This is realy strange: I did some testing: I inserted Attach:Fotos/20050515-162149.jpg into a page of the group Main (it was the SandBox). Works like a charm. Now I renamed the upload directroy to "Foto" and changed the link to Attach:Foto/20050515-162149.jpg. Now i have no display of the image. Isn't this strange? I disabled all additional scripts I'm calling just in case and I tried several skins just to make sure that there is no influence from that side. Nothing helped. --Klonk


Another thing which may help to track the problem: When I use Attach:Fotos/20050515-162149.jpg and the directory is named "Foto" which means the file has to be uploaded the resulting link is ... /wiki.php/Fotos/Fotos?action=upload&upname=20050515-162149.jpg --Klonk


Ok I found out that when uploading a file through PmWiki it is accessible anywhere from the wiki itself, but when renaming the directory or uploading the files via FTP the linking to another group does not work. --Klonk


I found a fix! I don't know whether this fix would be OK for your concept, but at least it works. And it is then even possible to upload files to an other group. It eould be very nice if you can include this fix to the next beta.

Simply change in upload.php in function LinkUpload the following lines from:

 
  if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
    $pagename = MakePageName($pagename, $match[1]);
    $path = $match[2];
  }

to

 
  if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
    $pagename = MakePageName($match[1], $match[1]);
    $path = $match[2];
  }

The only thing I don't like about it: When uploading to a different group you cannot come back to page you came from. -- Klonk


Wow, lots of very useful posts and diagnostics. But it appears to come down to misunderstanding the Attach: markup.

Writing Attach:Test/somefile.gif does not mean "somefile.gif" in the "Test" group. It means "somefile.gif" as it would be attached to the target of [[Test]]. This is important because some sites organize attachments on a per-page basis instead of a per-group basis.

Now then, it turns out that [[Test]] will generally be a link to another group if there's a page called "Test.Test" or "Test.HomePage", in which case Attach:Test/somefile.gif will show you the somefile.gif attachment on that page. But if there's no such page in the Test group, then Attach:Test/somefile.gif displays the somefile.gif as attached to a page called "Test" in the current group.

If you want to absolutely guarantee that you're obtaining an attachment from another group, you have to use a fully qualified pagename in the Attach: markup, as in Attach:Test/Test/somefile.gif.

--Pm


Indeed, you're right. I always thought Attach:Test/somefile.gif means the somefile.gif in the Test group. As I do not have a page called "Test.Test" I could either create a dummy page or call the attachment in that way:Attach:Test/Test/somefile.gif. The first is the group, the second is the page, where the page doesn't have to exist. The main thing is that you use a page of that group.

So this is not a bug, just a misunderstanding. I'll add this information to the documentation of uploads (just to avoid further questions or bug reports, OK) Thanks for your help. Now I understand why Attach:Fotos/20050515-162149.jpg worked but as soon I changed the directory name didi not work anymore.

For all the other readers: My suggested change to the upload.php does only work -- Klonk