diff --git a/src/IDF/Views/Issue.php b/src/IDF/Views/Issue.php index bc0689c..a13c48a 100644 --- a/src/IDF/Views/Issue.php +++ b/src/IDF/Views/Issue.php @@ -323,12 +323,50 @@ class IDF_Views_Issue $prj = $request->project; $attach = Pluf_Shortcuts_GetObjectOr404('IDF_IssueFile', $match[2]); $prj->inOr404($attach->get_comment()->get_issue()); + $info = IDF_Views_Source::getMimeType($attach->filename); + $mime = 'application/octet-stream'; + if (strpos($info[0], 'image/') === 0) { + $mime = $info[0]; + } $res = new Pluf_HTTP_Response_File(Pluf::f('upload_issue_path').'/'.$attach->attachment, - 'application/octet-stream'); - $res->headers['Content-Disposition'] = 'attachment; filename="'.$attach->filename.'"'; + $mime); + if ($mime == 'application/octet-stream') { + $res->headers['Content-Disposition'] = 'attachment; filename="'.$attach->filename.'"'; + } return $res; } + /** + * View a given attachment. + */ + public $viewAttachment_precond = array('IDF_Precondition::accessIssues'); + public function viewAttachment($request, $match) + { + $prj = $request->project; + $attach = Pluf_Shortcuts_GetObjectOr404('IDF_IssueFile', $match[2]); + $prj->inOr404($attach->get_comment()->get_issue()); + // If one cannot see the attachement, redirect to the + // getAttachment view. + $info = IDF_Views_Source::getMimeType($attach->filename); + if (!IDF_Views_Source::isText($info)) { + return $this->getAttachment($request, $match); + } + // Now we want to look at the file but with links back to the + // issue. + $file = IDF_Views_Source::highLight($info, + file_get_contents(Pluf::f('upload_issue_path').'/'.$attach->attachment)); + $title = sprintf(__('View %s'), $attach->filename); + return Pluf_Shortcuts_RenderToResponse('idf/issues/attachment.html', + array( + 'attachment' => $attach, + 'page_title' => $title, + 'comment' => $attach->get_comment(), + 'issue' => $attach->get_comment()->get_issue(), + 'file' => $file, + ), + $request); + } + /** * View list of issues for a given project with a given status. */ diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index 85fb72f..ad24ed6 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -401,7 +401,7 @@ class IDF_Views_Source if (0 === strpos($fileinfo[0], 'text/')) { return true; } - $ext = 'mdtext php js cpp php-dist h gitignore sh py pl rb ' + $ext = 'mdtext php js cpp php-dist h gitignore sh py pl rb diff patch' .Pluf::f('idf_extra_text_ext', ''); return (in_array($fileinfo[2], explode(' ', $ext))); } diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 30b5ee9..09c9f69 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -174,6 +174,12 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/issues/attachment/(\d+)/(.*)$#', 'model' => 'IDF_Views_Issue', 'method' => 'getAttachment'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/issues/view/attachment/(\d+)/(.*)$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_Issue', + 'method' => 'viewAttachment'); + // ---------- SCM ---------------------------------------- $ctl[] = array('regex' => '#^/p/([\-\w]+)/source/tree/([^/]+)/$#', diff --git a/src/IDF/templates/idf/issues/attachment.html b/src/IDF/templates/idf/issues/attachment.html new file mode 100644 index 0000000..4bfdade --- /dev/null +++ b/src/IDF/templates/idf/issues/attachment.html @@ -0,0 +1,26 @@ +{extends "idf/issues/base.html"} +{block extraheader}{/block} +{block docclass}yui-t2{assign $inIssue=true}{/block} +{block body} +
{blocktrans}Attachment to issue {$issue.id}{/blocktrans}
+{ashowuser 'submitter', $attachment.get_submitter(), $request} +{trans 'Created:'} {$attachment.creation_dtime|dateago} {blocktrans}by {$submitter}{/blocktrans}
+ +{/block} + +{block javascript} + + +{/block} diff --git a/src/IDF/templates/idf/issues/base.html b/src/IDF/templates/idf/issues/base.html index 836ae9b..8c142f8 100644 --- a/src/IDF/templates/idf/issues/base.html +++ b/src/IDF/templates/idf/issues/base.html @@ -8,6 +8,10 @@ +{if $inIssue} | +{aurl 'url', 'IDF_Views_Issue::view', array($project.shortname, $issue.id)} +{trans 'Back to the issue'} +{/if} {superblock} {/block} diff --git a/src/IDF/templates/idf/issues/issue-created-email.txt b/src/IDF/templates/idf/issues/issue-created-email.txt index d17b268..cd635ae 100644 --- a/src/IDF/templates/idf/issues/issue-created-email.txt +++ b/src/IDF/templates/idf/issues/issue-created-email.txt @@ -16,7 +16,7 @@ to you:{/blocktrans} {if $attachments.count() > 0} {trans 'Attachments:'}{foreach $attachments as $a} - {$a.filename|safe} - {$a.filesize|ssize} - {$url_base}{url 'IDF_Views_Issue::getAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach} + {$url_base}{url 'IDF_Views_Issue::viewAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach} {/if} -- {trans 'Issue:'} {$url_base}{url 'IDF_Views_Issue::view', array($project.shortname, $issue.id)} diff --git a/src/IDF/templates/idf/issues/issue-updated-email.txt b/src/IDF/templates/idf/issues/issue-updated-email.txt index a7658de..aaee025 100644 --- a/src/IDF/templates/idf/issues/issue-updated-email.txt +++ b/src/IDF/templates/idf/issues/issue-updated-email.txt @@ -20,7 +20,7 @@ {trans 'Attachments:'}{foreach $attachments as $a} - {$a.filename|safe} - {$a.filesize|ssize} - {$url_base}{url 'IDF_Views_Issue::getAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach} + {$url_base}{url 'IDF_Views_Issue::viewAttachment', array($project.shortname, $a.id, $a.filename)}{/foreach} {/if} {/foreach} diff --git a/src/IDF/templates/idf/issues/view.html b/src/IDF/templates/idf/issues/view.html index a9d9d8a..2807b5e 100644 --- a/src/IDF/templates/idf/issues/view.html +++ b/src/IDF/templates/idf/issues/view.html @@ -20,7 +20,7 @@ {if $attachments.count() > 0}