FEATURE: use original filename when clicking the download link in the lightbox

This commit is contained in:
Régis Hanol
2014-10-15 19:20:04 +02:00
parent 4762b4ac24
commit 31e9cafe0e
6 changed files with 33 additions and 16 deletions

View File

@@ -159,6 +159,11 @@ class CookedPostProcessor
# then, the link to our larger image
a = Nokogiri::XML::Node.new("a", @doc)
img.add_next_sibling(a)
if upload && Discourse.store.internal?
a["data-download-href"] = Discourse.store.download_url(upload)
end
a["href"] = img["src"]
a["class"] = "lightbox"
a.add_child(img)
@@ -217,9 +222,11 @@ class CookedPostProcessor
end
def optimize_urls
@doc.css("a[href]").each do |a|
href = a["href"].to_s
a["href"] = schemaless absolute(href) if is_local(href)
%w{href data-download-href}.each do |selector|
@doc.css("a[#{selector}]").each do |a|
href = a["#{selector}"].to_s
a["#{selector}"] = schemaless absolute(href) if is_local(href)
end
end
@doc.css("img[src]").each do |img|
@@ -243,17 +250,17 @@ class CookedPostProcessor
end
def disable_if_low_on_disk_space
if available_disk_space < SiteSetting.download_remote_images_threshold
SiteSetting.download_remote_images_to_local = false
# log the site setting change
reason = I18n.t("disable_remote_images_download_reason")
staff_action_logger = StaffActionLogger.new(Discourse.system_user)
staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason })
# also send a private message to the site contact user
SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled)
return true
end
false
return false if available_disk_space >= SiteSetting.download_remote_images_threshold
SiteSetting.download_remote_images_to_local = false
# log the site setting change
reason = I18n.t("disable_remote_images_download_reason")
staff_action_logger = StaffActionLogger.new(Discourse.system_user)
staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason })
# also send a private message to the site contact user
SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled)
true
end
def available_disk_space