Hi everyone, the attached patch adds a new event MEDIA_UPLOAD_FINISH to DokuWikis' event system. The event is triggered when a file is uploaded via the mediamanager. The event itself is preventable. It offers the possibility to pre/postprocess uploaded files. Usage examples could be extracting zipped files after upload, implementing some sort of quota system to limit upload diskspace for users or badword checking of uploaded files. This is my first attempt integrating a new event into DokuWiki and I would appreciate any feedback. Best Regards, chi -- Michael Klier mail: chi@xxxxxxxxxxx www: http://www.chimeric.de icq: 206179334 jabber: chi@xxxxxxxxxxxxxxxxxx key: http://downloads.chimeric.de/chi.asc key-id: 0x8308F551
New patches: [New event MEDIA_UPLOAD_FINISH Michael Klier <chi@xxxxxxxxxxx>**20070909003843 This adds a new event MEDIA_UPLOAD_FINISH which is triggered when a media file is uploaded via the mediamanager. (The event is preventable) Event data: data[0] temporary file name (read from $_FILES) data[1] file name of the file being uploaded data[2] future directory id of the file being uploaded data[3] the mime type of the file being uploaded ] { hunk ./inc/media.php 179 + * This generates an action event and delegates to _media_upload_action(). + * Action plugins are allowed to pre/postprocess the uploaded file. + * (The triggered event is preventable.) + * + * Event data: + * $data[0] fn_tmp: the temporary file name (read from $_FILES) + * $data[1] fn: the file name of the uploaded file + * $data[2] id: the future directory id of the uploaded file + * $data[3] imime: the mimetype of the uploaded file + * + * @triggers MEDIA_UPLOAD_FINISH hunk ./inc/media.php 191 + * @author Michael Klier <chi@xxxxxxxxxxx> hunk ./inc/media.php 246 - // prepare directory - io_createNamespace($id, 'media'); - if(move_uploaded_file($file['tmp_name'], $fn)) { - // Set the correct permission here. - // Always chmod media because they may be saved with different permissions than expected from the php umask. - // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) - chmod($fn, $conf['fmode']); - msg($lang['uploadsucc'],1); - media_notify($id,$fn,$imime); - return $id; - }else{ - msg($lang['uploadfail'],-1); - } + // prepare event data + $data[0] = $file['tmp_name']; + $data[1] = $fn; + $data[2] = $id; + $data[3] = $imime; + + // trigger event + return trigger_event('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true); + hunk ./inc/media.php 260 + +/** + * Callback adapter for media_upload_finish() + * @author Michael Klier <chi@xxxxxxxxxxx> + */ +function _media_upload_action($data) { + // fixme do further sanity tests of given data? + if(is_array($data) && count($data)===4) { + return media_upload_finish($data[0], $data[1], $data[2], $data[3]); + } else { + return false; //callback error + } +} + +/** + * Saves an uploaded media file + * + * @author Andreas Gohr <andi@xxxxxxxxxxxxxx> + * @author Michael Klier <chi@xxxxxxxxxxx> + */ +function media_upload_finish($fn_tmp, $fn, $id, $imime) { + global $conf; + global $lang; + + // prepare directory + io_createNamespace($id, 'media'); + + if(move_uploaded_file($fn_tmp, $fn)) { + // Set the correct permission here. + // Always chmod media because they may be saved with different permissions than expected from the php umask. + // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.) + chmod($fn, $conf['fmode']); + msg($lang['uploadsucc'],1); + media_notify($id,$fn,$imime); + return $id; + }else{ + msg($lang['uploadfail'],-1); + } +} } Context: [Fix for Basic HTTP authentication Michael Klier <chi@xxxxxxxxxxx>**20070908222540] [Use Content-Length in HTTP client Andreas Gohr <andi@xxxxxxxxxxxxxx>**20070906194435 If a Server supplies a Content-Length header we stop reading when the specified number of bytes was read. This fixes problems with Servers not closing the connection after sending the body. ] [Esperanto update Andreas Gohr <andi@xxxxxxxxxxxxxx>**20070906183038] [respect DOKU_BASE in CSS cache file name Michael Klier <chi@xxxxxxxxxxx>**20070906125503] [send security token on login/logout Michael Klier <chi@xxxxxxxxxxx>**20070904185355] [TAG develsnap 2007-09-01 Andreas Gohr <andi@xxxxxxxxxxxxxx>**20070831230001] Patch bundle hash: a5c19783428d5319a2899141a8fe10c56c109b43