From 25b23c4bc991644c7db47b484dca3bb2d2694e62 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 11 Aug 2016 20:16:36 -0300 Subject: [PATCH] Do not show non-image attachment in a tag. Fixes #3215 (#3311) --- conf/locale/locale_en-US.ini | 2 ++ modules/template/template.go | 6 ++++++ public/less/_repository.less | 7 +++++++ templates/repo/issue/view_content.tmpl | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 77a6411432..9632f4b2ba 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -500,6 +500,8 @@ issues.label_deletion = Label Deletion issues.label_deletion_desc = Deleting this label will remove its information in all related issues. Do you want to continue? issues.label_deletion_success = Label has been deleted successfully! issues.num_participants = %d Participants +issues.attachment.open_tab = `Click to see "%s" in a new tab` +issues.attachment.download = `Click to download "%s"` pulls.new = New Pull Request pulls.compare_changes = Compare Changes diff --git a/modules/template/template.go b/modules/template/template.go index 76ab66bcb4..6e9b15b9be 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -9,6 +9,8 @@ import ( "encoding/json" "fmt" "html/template" + "mime" + "path/filepath" "runtime" "strings" "time" @@ -103,6 +105,10 @@ func NewFuncMap() []template.FuncMap { "ThemeColorMetaTag": func() string { return setting.UI.ThemeColorMetaTag }, + "FilenameIsImage": func(filename string) bool { + mimeType := mime.TypeByExtension(filepath.Ext(filename)) + return strings.HasPrefix(mimeType, "image/") + }, }} } diff --git a/public/less/_repository.less b/public/less/_repository.less index cb1cc121ce..0fdc23df24 100644 --- a/public/less/_repository.less +++ b/public/less/_repository.less @@ -463,6 +463,13 @@ margin: 0; vertical-align: middle; } + span.ui.image { + font-size: 8vw; + color: #000000; + } + span.ui.image:hover { + color: #000000; + } } } diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index d2183d4164..ebd737c381 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -41,7 +41,13 @@
{{range .Issue.Attachments}} - + + {{if FilenameIsImage .Name}} + + {{else}} + + {{end}} + {{end}}
@@ -96,7 +102,13 @@