01193: $RecentUploadsFmt should use $ChangeSummary

Summary: $RecentUploadsFmt should use $ChangeSummary
Created: 2010-05-11 08:15
Status: Open
Category: Feature
Assigned:
Priority: 55
Version: 2.2.6+

Description: The way $RecentUploadsFmt is currently implemented makes it difficult to log attachment actions in a consistent manner.

At the moment, HandlePostUpload will log uploads by setting the $FmtV variables $upname and $upsize before calling PostRecentChanges. $RecentUploadsFmt has no set default, but effectively requires the direct use of the above variables.

Better consistency with $RecentChangesFmt could be achieved by setting and using the $ChangeSummary global variable, which could also be used by cookbook recipes that allow eg. the renaming or deletion of attached files.

This would require a new global variable for holding the change summaries, but it would only need to be set when the action is about to be performed. In the following sample implementation, I'm calling it $UploadSummaryFmt.


Using:

$RecentUploadsFmt['$SiteGroup.AllRecentChanges'] =
    '* [[{$Group}/]] / [[(Path:/pmwiki/uploads/{$Group}/)$upname]]  '
    .'. . . $CurrentTime by $AuthorLink: $ChangeSummary';

$UploadSummaryFmt['upload'] = 'Uploaded to [[{$Group}/{$Name}]] ($upsize $[bytes])';

The following change would allow the use of a similar log format as in use now on pmwiki.org, while also allowing the reuse of $RecentUploadsFmt by cookbook recipes.

Index: scripts/upload.php
===================================================================
--- scripts/upload.php	(revision 2556)
+++ scripts/upload.php	(working copy)
@@ -199,7 +199,7 @@

 function HandlePostUpload($pagename, $auth = 'upload') {
   global $UploadVerifyFunction, $UploadFileFmt, $LastModFile, 
-    $EnableUploadVersions, $Now, $RecentUploadsFmt, $FmtV;
+    $EnableUploadVersions, $Now, $RecentUploadsFmt, $FmtV, $ChangeSummary, $UploadSummaryFmt;
   UploadAuth($pagename, $auth);
   $uploadfile = $_FILES['uploadfile'];
   $upname = $_REQUEST['upname'];
@@ -222,6 +222,7 @@
     if (IsEnabled($RecentUploadsFmt, 0)) {
       $FmtV['$upname'] = $upname;
       $FmtV['$upsize'] = $uploadfile['size'];
+      $ChangeSummary = FmtPageName(@$UploadSummaryFmt['upload'], $pagename);
       PostRecentChanges($pagename, '', '', $RecentUploadsFmt);
     }
   }