Compare commits
41 Commits
Author | SHA1 | Date |
---|---|---|
Kolan Sh | 6125ca1246 | |
Kolan Sh | 6978a86c97 | |
Kolan Sh | b4e5f6cd0d | |
Kolan Sh | 5e370b720b | |
Kolan Sh | 9ebbce7ba3 | |
Kolan Sh | efe53a60c5 | |
Kolan Sh | 8e78e2d78b | |
Kolan Sh | 19f2859e1b | |
Holger Just | 7efc8dbb19 | |
Holger Just | eb41ffd854 | |
Holger Just | f9180b1dc8 | |
Andrew Smith | b43e8186c4 | |
Holger Just | 4c4383ff71 | |
Andrew Smith | 72e9805b72 | |
Felix Schäfer | 5cefd6a425 | |
Felix Schäfer | 7437eaea53 | |
Holger Just | f6ebdb3405 | |
Andrew Smith | 1a28b5a281 | |
Romano Licker | a57691369e | |
Holger Just | d91b297846 | |
Felix Schäfer | 45f628591e | |
Andrew Smith | 9017d14054 | |
Felix Schäfer | 037bb192ac | |
Felix Schäfer | f0f0171a59 | |
Andrew Smith | 03e68da23c | |
Holger Just | 8e80e65e0a | |
Holger Just | 5350f4323a | |
Holger Just | abfc04973e | |
Andrew Smith | 8478e6a115 | |
Andrew Smith | c9bec63b7d | |
Andrew Smith | 90c4453b58 | |
Jan Vlnas | 935b2c8635 | |
Holger Just | fe19c6c5be | |
Holger Just | a91563e194 | |
Felix Schäfer | 645f44a419 | |
Holger Just | 1ed846cd01 | |
Holger Just | 02d2deeae6 | |
Kolan Sh | 1e908da66c | |
Kolan Sh | e5de5f43cc | |
Kolan Sh | 65b94d2014 | |
Kolan Sh | 786e92349b |
2
Gemfile
2
Gemfile
|
@ -13,6 +13,8 @@ gem "acts-as-taggable-on", "= 2.1.0"
|
|||
gem 'gravatarify', '~> 3.0.0'
|
||||
# Needed only on RUBY_VERSION = 1.8, ruby 1.9+ compatible interpreters should bring their csv
|
||||
gem "fastercsv", "~> 1.5.0", :platforms => [:ruby_18, :jruby, :mingw_18]
|
||||
# need for automatic encoding detection in diff,annotate and cat
|
||||
gem "chardet", ">= 0.9.0"
|
||||
gem "tzinfo", "~> 0.3.31" # Fixes #903. Not required for Rails >= 3.2
|
||||
|
||||
group :test do
|
||||
|
|
|
@ -36,6 +36,7 @@ class WikiController < ApplicationController
|
|||
verify :method => :post, :only => [:protect], :redirect_to => { :action => :show }
|
||||
|
||||
include AttachmentsHelper
|
||||
include Redmine::Export::PDF
|
||||
|
||||
# List of pages, sorted alphabetically and by parent (hierarchy)
|
||||
def index
|
||||
|
@ -69,7 +70,10 @@ class WikiController < ApplicationController
|
|||
end
|
||||
@content = @page.content_for_version(params[:version])
|
||||
if User.current.allowed_to?(:export_wiki_pages, @project)
|
||||
if params[:format] == 'html'
|
||||
if params[:format] == 'pdf'
|
||||
send_data(wiki_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
|
||||
return
|
||||
elsif params[:format] == 'html'
|
||||
export = render_to_string :action => 'export', :layout => false
|
||||
send_data(export, :type => 'text/html', :filename => "#{@page.title}.html")
|
||||
return
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
# See doc/COPYRIGHT.rdoc for more details.
|
||||
#++
|
||||
|
||||
require 'rubygems'
|
||||
require 'UniversalDetector'
|
||||
|
||||
module AttachmentsHelper
|
||||
# Displays view/delete links to the attachments of the given object
|
||||
# Options:
|
||||
|
@ -26,18 +29,16 @@ module AttachmentsHelper
|
|||
end
|
||||
|
||||
def to_utf8_for_attachments(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
return str if str.valid_encoding?
|
||||
else
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
end
|
||||
|
||||
begin
|
||||
Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3]
|
||||
rescue Iconv::InvalidEncoding
|
||||
# "UTF-8//IGNORE" is not supported on some OS
|
||||
str
|
||||
end
|
||||
return nil if str.nil?
|
||||
iconv_str = str
|
||||
detected = UniversalDetector::chardet(str)
|
||||
enc = detected['encoding']
|
||||
if !enc.nil?
|
||||
begin
|
||||
iconv_str = Iconv.conv('UTF-8', enc, str)
|
||||
rescue Iconv::Failure => err
|
||||
end
|
||||
end
|
||||
iconv_str
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
<% other_formats_links do |f| %>
|
||||
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
|
||||
<%= f.link_to 'PDF', :url => {:id => @page.title, :version => @content.version} %>
|
||||
<%= f.link_to 'HTML', :url => {:id => @page.title, :version => @content.version} %>
|
||||
<%= f.link_to 'TXT', :url => {:id => @page.title, :version => @content.version} %>
|
||||
<%= call_hook(:view_wiki_show_other_formats, {:link_builder => f, :url_params => {:id => @page.title, :version => @content.version}}) %>
|
||||
|
|
|
@ -26,6 +26,8 @@ require 'redmine/notifiable'
|
|||
require 'redmine/wiki_formatting'
|
||||
require 'redmine/scm/base'
|
||||
|
||||
RMAGICK_BYPASS_VERSION_TEST = true
|
||||
|
||||
begin
|
||||
require_library_or_gem 'RMagick' unless Object.const_defined?(:Magick)
|
||||
rescue LoadError
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
require 'iconv'
|
||||
|
||||
module Redmine
|
||||
module CodesetUtil
|
||||
|
||||
def self.replace_invalid_utf8(str)
|
||||
return str if str.nil?
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
if ! str.valid_encoding?
|
||||
str = str.encode("US-ASCII", :invalid => :replace,
|
||||
:undef => :replace, :replace => '?').encode("UTF-8")
|
||||
end
|
||||
elsif RUBY_PLATFORM == 'java'
|
||||
begin
|
||||
ic = Iconv.new('UTF-8', 'UTF-8')
|
||||
str = ic.iconv(str)
|
||||
rescue
|
||||
str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
|
||||
end
|
||||
else
|
||||
ic = Iconv.new('UTF-8', 'UTF-8')
|
||||
txtar = ""
|
||||
begin
|
||||
txtar += ic.iconv(str)
|
||||
rescue Iconv::IllegalSequence
|
||||
txtar += $!.success
|
||||
str = '?' + $!.failed[1,$!.failed.length]
|
||||
retry
|
||||
rescue
|
||||
txtar += $!.success
|
||||
end
|
||||
str = txtar
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def self.to_utf8(str, encoding)
|
||||
return str if str.nil?
|
||||
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
||||
if str.empty?
|
||||
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||
return str
|
||||
end
|
||||
enc = encoding.blank? ? "UTF-8" : encoding
|
||||
if str.respond_to?(:force_encoding)
|
||||
if enc.upcase != "UTF-8"
|
||||
str.force_encoding(enc)
|
||||
str = str.encode("UTF-8", :invalid => :replace,
|
||||
:undef => :replace, :replace => '?')
|
||||
else
|
||||
str.force_encoding("UTF-8")
|
||||
if ! str.valid_encoding?
|
||||
str = str.encode("US-ASCII", :invalid => :replace,
|
||||
:undef => :replace, :replace => '?').encode("UTF-8")
|
||||
end
|
||||
end
|
||||
elsif RUBY_PLATFORM == 'java'
|
||||
begin
|
||||
ic = Iconv.new('UTF-8', enc)
|
||||
str = ic.iconv(str)
|
||||
rescue
|
||||
str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
|
||||
end
|
||||
else
|
||||
ic = Iconv.new('UTF-8', enc)
|
||||
txtar = ""
|
||||
begin
|
||||
txtar += ic.iconv(str)
|
||||
rescue Iconv::IllegalSequence
|
||||
txtar += $!.success
|
||||
str = '?' + $!.failed[1,$!.failed.length]
|
||||
retry
|
||||
rescue
|
||||
txtar += $!.success
|
||||
end
|
||||
str = txtar
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def self.to_utf8_by_setting(str)
|
||||
return str if str.nil?
|
||||
str = self.to_utf8_by_setting_internal(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def self.to_utf8_by_setting_internal(str)
|
||||
return str if str.nil?
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('ASCII-8BIT')
|
||||
end
|
||||
return str if str.empty?
|
||||
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
end
|
||||
encodings = Setting.repositories_encodings.split(',').collect(&:strip)
|
||||
encodings.each do |encoding|
|
||||
begin
|
||||
return Iconv.conv('UTF-8', encoding, str)
|
||||
rescue Iconv::Failure
|
||||
# do nothing here and try the next encoding
|
||||
end
|
||||
end
|
||||
str = self.replace_invalid_utf8(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def self.from_utf8(str, encoding)
|
||||
str ||= ''
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
if encoding.upcase != 'UTF-8'
|
||||
str = str.encode(encoding, :invalid => :replace,
|
||||
:undef => :replace, :replace => '?')
|
||||
else
|
||||
str = self.replace_invalid_utf8(str)
|
||||
end
|
||||
elsif RUBY_PLATFORM == 'java'
|
||||
begin
|
||||
ic = Iconv.new(encoding, 'UTF-8')
|
||||
str = ic.iconv(str)
|
||||
rescue
|
||||
str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
|
||||
end
|
||||
else
|
||||
ic = Iconv.new(encoding, 'UTF-8')
|
||||
txtar = ""
|
||||
begin
|
||||
txtar += ic.iconv(str)
|
||||
rescue Iconv::IllegalSequence
|
||||
txtar += $!.success
|
||||
str = '?' + $!.failed[1, $!.failed.length]
|
||||
retry
|
||||
rescue
|
||||
txtar += $!.success
|
||||
end
|
||||
str = txtar
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -74,6 +74,24 @@ module Redmine
|
|||
SetX(-30)
|
||||
RDMCell(0, 5, PageNo().to_s + '/{nb}', 0, 0, 'C')
|
||||
end
|
||||
|
||||
def fix_text_encoding(txt)
|
||||
RDMPdfEncoding::rdm_from_utf8(txt, l(:general_pdf_encoding))
|
||||
end
|
||||
|
||||
def formatted_text(text)
|
||||
html = Redmine::WikiFormatting.to_html(Setting.text_formatting, text)
|
||||
# Strip {{toc}} tags
|
||||
html.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i, '')
|
||||
html
|
||||
end
|
||||
|
||||
def RDMwriteHTMLCell(w, h, x, y, txt='', attachments=[], border=0, ln=1, fill=0)
|
||||
@attachments = attachments
|
||||
writeHTMLCell(w, h, x, y,
|
||||
fix_text_encoding(formatted_text(txt)),
|
||||
border, ln, fill)
|
||||
end
|
||||
end
|
||||
|
||||
class IFPDF < FPDF
|
||||
|
@ -441,6 +459,67 @@ module Redmine
|
|||
pdf.Output
|
||||
end
|
||||
|
||||
# Returns a PDF string of a single wiki page
|
||||
def wiki_to_pdf(page, project)
|
||||
pdf = ITCPDF.new(current_language)
|
||||
pdf.SetTitle("#{project} - #{page.title}")
|
||||
pdf.alias_nb_pages
|
||||
pdf.footer_date = format_date(Date.today)
|
||||
pdf.AddPage
|
||||
pdf.SetFontStyle('B',11)
|
||||
pdf.RDMMultiCell(190,5,
|
||||
"#{project} - #{page.title} - # #{page.content.version}")
|
||||
pdf.Ln
|
||||
|
||||
# Set resize image scale
|
||||
pdf.SetImageScale(1.6)
|
||||
|
||||
pdf.SetFontStyle('',9)
|
||||
pdf.RDMwriteHTMLCell(190,5,0,0,
|
||||
page.content.text.to_s, page.attachments, "TLRB")
|
||||
|
||||
if page.attachments.any?
|
||||
pdf.Ln
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
||||
pdf.Ln
|
||||
for attachment in page.attachments
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMCell(80,5, attachment.filename)
|
||||
pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
||||
pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
|
||||
pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
|
||||
pdf.Ln
|
||||
end
|
||||
end
|
||||
|
||||
pdf.Output
|
||||
end
|
||||
end
|
||||
|
||||
class RDMPdfEncoding
|
||||
def self.rdm_from_utf8(txt, encoding)
|
||||
txt ||= ''
|
||||
txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
|
||||
if txt.respond_to?(:force_encoding)
|
||||
txt.force_encoding('ASCII-8BIT')
|
||||
end
|
||||
txt
|
||||
end
|
||||
|
||||
def self.attach(attachments, filename, encoding)
|
||||
filename_utf8 = Redmine::CodesetUtil.to_utf8(filename, encoding)
|
||||
atta = nil
|
||||
if filename_utf8 =~ /^[^\/"]+\.(gif|jpg|jpe|jpeg|png)$/i
|
||||
atta = Attachment.latest_attach(attachments, filename_utf8)
|
||||
end
|
||||
if atta && atta.readable? && atta.visible?
|
||||
return atta
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
require_dependency 'redmine/scm/adapters/abstract_adapter'
|
||||
require 'cgi'
|
||||
require 'rubygems'
|
||||
require 'UniversalDetector'
|
||||
|
||||
module Redmine
|
||||
module Scm
|
||||
|
@ -239,7 +241,18 @@ module Redmine
|
|||
diff = []
|
||||
hg *hg_args do |io|
|
||||
io.each_line do |line|
|
||||
diff << line
|
||||
iconv_line = line
|
||||
if !line.nil?
|
||||
detected = UniversalDetector::chardet(line)
|
||||
enc = detected['encoding']
|
||||
if !enc.nil?
|
||||
begin
|
||||
iconv_line = Iconv.conv('UTF-8', enc, line)
|
||||
rescue Iconv::Failure => err
|
||||
end
|
||||
end
|
||||
end
|
||||
diff << iconv_line
|
||||
end
|
||||
end
|
||||
diff
|
||||
|
@ -251,7 +264,18 @@ module Redmine
|
|||
p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
|
||||
hg 'rhcat', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
|
||||
io.binmode
|
||||
io.read
|
||||
str = io.read
|
||||
return nil if str.nil?
|
||||
iconv_str = str
|
||||
detected = UniversalDetector::chardet(str)
|
||||
enc = detected['encoding']
|
||||
if !enc.nil?
|
||||
begin
|
||||
iconv_str = Iconv.conv('UTF-8', enc, str)
|
||||
rescue Iconv::Failure => err
|
||||
end
|
||||
end
|
||||
return iconv_str
|
||||
end
|
||||
rescue HgCommandAborted
|
||||
nil # means not found
|
||||
|
@ -266,7 +290,19 @@ module Redmine
|
|||
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
|
||||
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
|
||||
:identifier => $3)
|
||||
blame.add_line($4.rstrip, r)
|
||||
str = $4.rstrip
|
||||
iconv_str = str
|
||||
if !str.nil?
|
||||
detected = UniversalDetector::chardet(str)
|
||||
enc = detected['encoding']
|
||||
if !enc.nil?
|
||||
begin
|
||||
iconv_str = Iconv.conv('UTF-8', enc, str)
|
||||
rescue Iconv::Failure => err
|
||||
end
|
||||
end
|
||||
end
|
||||
blame.add_line(iconv_str, r)
|
||||
end
|
||||
end
|
||||
blame
|
||||
|
|
|
@ -3377,7 +3377,7 @@ class TCPDF
|
|||
#Extract attributes
|
||||
# get tag name
|
||||
tag = element.scan(/([a-zA-Z0-9]*)/).flatten.delete_if {|x| x.length == 0}
|
||||
tag = tag[0].downcase;
|
||||
tag = tag[0].to_s.downcase;
|
||||
|
||||
# get attributes
|
||||
attr_array = element.scan(/([^=\s]*)=["\']?([^"\']*)["\']?/)
|
||||
|
|
Loading…
Reference in New Issue