Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

AttachDelete

Summary: An enhancement to the current upload feature to allow the deletion of uploaded files.
Version: 0.05 24 Nov 2006
Prerequisites: Requires PmWiki version: 2.0; last tested on PmWiki version: 2.1 beta 12;
Status:
Maintainer:
Categories: Functions Uploads

Questions answered by this recipe

An enhancement to the current upload feature to allow the deletion of uploaded files.

This cookbook entry creates a new markup (:newattachlist:) which includes a delete link for each file listed. The user needs to have upload permission to see the link and the associated action delattach requires upload permission as well.

If you want to replace the standard list PmWiki uses for the upload action you have to edit the page Site.UploadQuickReference and replace (:attachlist:) with (:newattachlist:).

This is my first PmWiki extension and I am still learning how to properly write those enhancements. Feedback is highly encouraged so I can learn.

I don't want to forget to mention that the base code for this script was taken from the standard upload.php script. Maybe down the road this could be integrated with the core upload.php script.

Notes

Copy the attachdel.php to your cookbook folder. Add the line include_once('cookbook/attachdel.php'); to your local/config.php file

Releases

DateVersionNotes
14 Dec 20050.01Initial release, still testing
14 Dec 20050.02* Changed delete actions from a get URL to a post form
* Multiple Files can be deleted at once
* File names go through a very basic validation filter
17 Jan 20060.03Fixed a bug that occured when no files were selected when pressing delete. Thanks Peter for reporting this
23 Jan 20060.04ΔWas too quick to fix the previous problem and introduced more problems. All tested now and working properly.
24 Nov 20060.05Show upload input field after deleting an attachment (they were missing in older versions)

Comments

Hi Dan, it's a nice cookbook, thanks! In the wiki philosophy there is a "mantra" that you can not delete anything, this is of course infeasible by deleting files, ;-) but could you make it a little bit less dangerous. It would be fine, if there were at least a promt "would you really delete this files" next pressing the button "delete checked files".

cg 2006-03-29


Great recipe! Is it possible to use it for certain groups only by including it in the group config file only?

I tried to make a universal UploadQuickReference page with the following markup, but it didn't work. Any ideas how to fix it?

(:if enabled ATTACH_DELETE_VERSION:)
(:newattachlist:)
(:if:)
(:if !enabled ATTACH_DELETE_VERSION:)
(:attachlist:)
(:if:)

--Henning October 31, 2006, at 08:19 AM

Here is a working solution that is not completely automatical, but requires entering the name of the group (FooBar for the example) for which the recipe is enabled on the univeral UploadQuickReference page:

(:if ! equal {$Group} FooBar:)
(:attachlist:)
(:if:)
(:if equal {$Group} FooBar:)
(:newattachlist:)
(:if:)

--Henning November 03, 2006, at 08:09 AM

Just some tidying- Using 'else' saves a bit of processing power:
(:if equal {$Group} FooBar:)
(:newattachlist:)
(:else:)
(:attachlist:)
(:ifend:)

After talking to Dan I added a patch which prevent upload input fields from disappearing ater deleting an attachment and I increased the version number to 0.05 :-)

-- Jann November 24, 2006, at 09:11 AM

-- Ulli? January 11, 2007

Is it possible to chnage the delete to move the file to a spezial folder with an timestamp, so may it can be restored....?

I think this is important. The deletepage? recipe leaves the file, but appends it. This wouldn't work here because it will show all files in the directory. However, if [=(:newattachlist:)=) hid all files with an extension of .deleted, then there would be no problem!

See Also

Contributors

Dan Weber

Edit - History - Print - Recent Changes - Search
Page last modified on November 24, 2007, at 04:49 PM