<?php if (!defined('PmWiki')) exit();
/**
	Recent Uploads
	Written by (c) Petko Yotov 2007

	This recipe logs all uploaded files in the (All)RecentChanges pages.

	This text is written for PmWiki; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published
	by the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version. See pmwiki.php for full details
	and lack of warranty.

	Copyright 2007 Petko Yotov http://5ko.free.fr
	Copyright 2004-2007 Patrick R. Michaud http://www.pmwiki.org
*/
# Version date
$RecipeInfo['RecentUploads']['Version'] = '2007-03-12';

$UploadVerifyFunctionPrev = (isset($UploadVerifyFunction) )? $UploadVerifyFunction : "UploadVerifyBasic";
$UploadVerifyFunction = "RecentUploads";

SDVA($RecentUploadsFmt, array(
	'$SiteGroup.AllRecentChanges' =>
		'* [[{$Group}.RecentUploads]]  . . . $CurrentTime $AuthorLink :'
		.' [[{$Group}/{$Name}]]/[[(Attach:{$Group}.{$Name}/)$upname]] ($upsize)',
	'$Group.RecentChanges' =>
		'* [[{$Group}/RecentUploads]]  . . . $CurrentTime $AuthorLink :'
		.' [[{$Group}/{$Name}]]/[[(Attach:{$Group}.{$Name}/)$upname]] ($upsize)',
	'$Group.RecentUploads' =>
		'* [[{$Group}/{$Name}]]/[[(Attach:{$Group}.{$Name}/)$upname]]'
		.'  . . . $CurrentTime $[by] $AuthorLink ($upsize)',
));

function RecentUploads($pagename,$uploadfile,$filepath)
{
	global $RecentChangesFmt, $UploadVerifyFunctionPrev, $IsPagePosted, $FmtPV, $RecentUploadsFmt;

	if (!function_exists($UploadVerifyFunctionPrev))
		Abort('?no UploadVerifyFunction available');
	$result = $UploadVerifyFunctionPrev($pagename,$uploadfile,$filepath);
	if($result!='') return $result;//some error occurred

	$upname = $_REQUEST['upname'];
	if ($upname=='') $upname=$uploadfile['name'];
	$upname = MakeUploadName($pagename,$upname);

	$FmtPV['$upname'] = "'$upname'";
	$FmtPV['$upsize'] = "'".$uploadfile['size']." bytes'";
	$rc = $RecentChangesFmt;
	$RecentChangesFmt = $RecentUploadsFmt;
	$IsPagePosted = 1;
	$p = array();
	PostRecentChanges($pagename, $p, $p);
	$IsPagePosted = 0;
	$RecentChangesFmt = $rc;//just in case...
	return $result;
}