diff --git a/NEWS.mdtext b/NEWS.mdtext index d9a6076..8d6df37 100644 --- a/NEWS.mdtext +++ b/NEWS.mdtext @@ -3,6 +3,7 @@ ## New Features - Mercurial source views now show parent revisions (if any) and detailed change information +- File download URLs now contain the file name rather than the upload id; old links still work though (issue 686) ## Bugfixes diff --git a/src/IDF/Views/Download.php b/src/IDF/Views/Download.php index ac4f827..87c9bf5 100644 --- a/src/IDF/Views/Download.php +++ b/src/IDF/Views/Download.php @@ -59,7 +59,7 @@ class IDF_Views_Download $sql .= ' AND id NOT IN ('.implode(',', $ids).')'; } $pag->forced_where = new Pluf_SQL($sql, array($prj->id)); - + $list_display = array( 'file' => __('File'), array('summary', 'IDF_Views_Download_SummaryAndLabels', __('Summary')), @@ -79,7 +79,7 @@ class IDF_Views_Download 'dlabel' => $dtag, ), $request); - + } /** @@ -99,17 +99,17 @@ class IDF_Views_Download $deprecated = Pluf_Model_InArray($dtag, $tags); if ($request->method == 'POST' and true === IDF_Precondition::projectMemberOrOwner($request)) { - + $form = new IDF_Form_UpdateUpload($request->POST, array('project' => $prj, 'upload' => $upload, 'user' => $request->user)); if ($form->isValid()) { $upload = $form->save(); - $urlfile = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', + $urlfile = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', array($prj->shortname, $upload->id)); $request->user->setMessage(sprintf(__('The file %2$s has been updated.'), $urlfile, Pluf_esc($upload->file))); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } @@ -162,7 +162,7 @@ class IDF_Views_Download * [description] * * This signal allows an application to perform a set of tasks - * just before the deletion of the corresponding object in the + * just before the deletion of the corresponding object in the * database but just after the deletion from the storage. * * [parameters] @@ -171,11 +171,11 @@ class IDF_Views_Download * */ $params = array('upload' => $upload); - Pluf_Signal::send('IDF_Upload::delete', + Pluf_Signal::send('IDF_Upload::delete', 'IDF_Views_Download', $params); $upload->delete(); $request->user->setMessage(__('The file has been deleted.')); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } @@ -190,19 +190,35 @@ class IDF_Views_Download } /** - * Download a file. + * Download the file with the given name. */ public $download_precond = array('IDF_Precondition::accessDownloads'); public function download($request, $match) { $prj = $request->project; - $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]); + $sql = new Pluf_SQL('file=%s', array($match[2])); + $upload = Pluf::factory('IDF_Upload')->getOne(array('filter' => $sql->gen())); + if (!$upload) throw new Pluf_HTTP_Error404(); $prj->inOr404($upload); $upload->downloads += 1; $upload->update(); return new Pluf_HTTP_Response_Redirect($upload->getAbsoluteUrl($prj)); } + /** + * Download the file with the given ID (for legacy links). + */ + public $downloadById_precond = array('IDF_Precondition::accessDownloads'); + public function downloadById($request, $match) + { + $upload = Pluf_Shortcuts_GetObjectOr404('IDF_Upload', $match[2]); + return new Pluf_HTTP_Response_Redirect( + Pluf_HTTP_URL_urlForView('IDF_Views_Download::download', array( + $match[1], $upload->file + )), 301 + ); + } + /** * Submit a new file for download. */ @@ -218,10 +234,10 @@ class IDF_Views_Download 'user' => $request->user)); if ($form->isValid()) { $upload = $form->save(); - $urlfile = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', + $urlfile = Pluf_HTTP_URL_urlForView('IDF_Views_Download::view', array($prj->shortname, $upload->id)); $request->user->setMessage(sprintf(__('The file has been uploaded.'), $urlfile)); - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::index', array($prj->shortname)); return new Pluf_HTTP_Response_Redirect($url); } @@ -246,7 +262,7 @@ class IDF_Views_Download { $conf = new IDF_Conf(); $conf->setProject($project); - $st = preg_split("/\015\012|\015|\012/", + $st = preg_split("/\015\012|\015|\012/", $conf->getVal('labels_download_predefined', IDF_Form_UploadConf::init_predefined), -1, PREG_SPLIT_NO_EMPTY); $auto = ''; foreach ($st as $s) { @@ -354,7 +370,7 @@ function IDF_Views_Download_SummaryAndLabels($field, $down, $extra='') { $tags = array(); foreach ($down->get_tags_list() as $tag) { - $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::listLabel', + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Download::listLabel', array($down->shortname, $tag->id)); $tags[] = sprintf('%s', $url, Pluf_esc((string) $tag)); } diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 365536a..7eea70e 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -73,7 +73,7 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/$#', 'base' => $base, 'model' => 'IDF_Views_Project', 'method' => 'home'); - + $ctl[] = array('regex' => '#^/p/([\-\w]+)/logo/$#', 'base' => $base, 'model' => 'IDF_Views_Project', @@ -294,11 +294,16 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/$#', 'model' => 'IDF_Views_Download', 'method' => 'view'); -$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/get/$#', +$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/get/(.+)$#', 'base' => $base, 'model' => 'IDF_Views_Download', 'method' => 'download'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/(\d+)/get/$#', + 'base' => $base, + 'model' => 'IDF_Views_Download', + 'method' => 'downloadById'); + $ctl[] = array('regex' => '#^/p/([\-\w]+)/downloads/create/$#', 'base' => $base, 'model' => 'IDF_Views_Download', diff --git a/src/IDF/templates/idf/downloads/delete.html b/src/IDF/templates/idf/downloads/delete.html index 60e0b75..621be7c 100644 --- a/src/IDF/templates/idf/downloads/delete.html +++ b/src/IDF/templates/idf/downloads/delete.html @@ -3,7 +3,7 @@ {block body}
{blocktrans}Attention! If you want to delete a specific version of your software, maybe, someone is depending on this specific version to run his systems. Are you sure, you will not affect anybody when removing this file?{/blocktrans}
@@ -15,7 +15,7 @@- | | {trans 'Cancel'} + | | {trans 'Cancel'} |
{blocktrans}Attention! This file is marked as deprecated, download it only if you are sure you need this specific version.{/blocktrans}
{/if} -{$file} - {$file.filesize|size} +{$file} - {$file.filesize|size}