Loading...
 
Features / Usability

Features / Usability


Wiki attachments require unique filenames

posts: 13 United States

If I upload a file attachment to a wiki page, and then go to another wiki page and upload a file of the same name, then the first file will get replaced by the contents of the second without warning.

So there is a uniqueness requirement to filenames for wiki uploads across the site.

This is apparently only an issue if I use Admin->Wiki Attachments->Use a directory to store files. I'd very much like to keep using filesystem storage over database storage.

I haven't found where exactly it does it in the source, but it would seem the files get stored onto disk in the designated wiki file directory according to the md5 hash of the filename. So a second file of the same name will have the same hash and overwrite any pre-existing one. Can the md5 hash be changed so it's a concatenation of the ))WikiPageNamewith theFileName((? Then there would only be a naming uniqueness requirement per-wiki page?

posts: 13 United States

> If I upload a file attachment to a wiki page, and then go to another wiki page and upload a file of the same name, then the first file will get replaced by the contents of the second without warning.
>
> So there is a uniqueness requirement to filenames for wiki uploads across the site.
>
> This is apparently only an issue if I use Admin->Wiki Attachments->Use a directory to store files. I'd very much like to keep using filesystem storage over database storage.
>
> I haven't found where exactly it does it in the source, but it would seem the files get stored onto disk in the designated wiki file directory according to the md5 hash of the filename. So a second file of the same name will have the same hash and overwrite any pre-existing one. Can the md5 hash be changed so it's a concatenation of the ))WikiPageNamewith theFileName((? Then there would only be a naming uniqueness requirement per-wiki page?

Looks like file galleries (tiki-upload_file.php) avoids this problem by using uniqid(filename) to generate the md5 name to store on disk. Some small patches to tiki-index.php and tiki-admin_include_wikiatt.php seem to be all that's needed. (Attached diff run through patch)

--Art


posts: 104

On the other hand, I was told that the remove unreferenced images features is not very reliable.

In the meantime I was already using unique filenames when uploading and I consider it a feature to be able to replace images on the filesystem directly with the upload image possibility of the wiki.

If you don't have this and you need to just replace a picture, there needs to be a working remove image feature FIRST. Otherwise you will be left with a lot of unused images over time ....

Best regards, - Bernhard

posts: 13 United States

Indeed. The build up of stale files would be annoying. Though I can't see trusting a user base (or myself for that matter) to upload unique filenames site-wide.

I made some tweaks so now the file name md5 will be found based on the combination of the filename and the wiki page name it's uploaded to. I can have the same filename on a different page with no problem but if I upload a new file with the same name to a page where that filename already exists, it will replace it on the disk. So no stale files.

Also a tweak to wikilib.php makes the database record get updated if you upload the same filename to a given page instead of inserting a new record (which leaves the original record stale).

(If you keep wiki files in the database, you can have unlimited identical filenames on a given page. If you then convert these to filesystem storage though this patch won't prevent stale database records... and the last file you converted will be the only file on disk)

see attached

--Art


posts: 1092

ardavis
Are you a tiki developper?
Do you want to become one?
Give me your sourceforge login (or give it to any admin) and they will add you to the list

sylvie