@@ -1,40 +1,40 | |||
|
1 | 1 | <%= form_tag({:action => 'edit'}) do %> |
|
2 | 2 | |
|
3 | 3 | <div class="box tabular settings"> |
|
4 | 4 | <p><%= setting_text_field :app_title, :size => 30 %></p> |
|
5 | 5 | |
|
6 | 6 | <p><%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %></p> |
|
7 | 7 | <%= wikitoolbar_for 'settings_welcome_text' %> |
|
8 | 8 | |
|
9 | 9 | <p><%= setting_text_field :attachment_max_size, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p> |
|
10 | 10 | |
|
11 | 11 | <p><%= setting_text_field :per_page_options, :size => 20 %> |
|
12 | 12 | <em class="info"><%= l(:text_comma_separated) %></em></p> |
|
13 | 13 | |
|
14 | 14 | <p><%= setting_text_field :activity_days_default, :size => 6 %> <%= l(:label_day_plural) %></p> |
|
15 | 15 | |
|
16 | 16 | <p><%= setting_text_field :host_name, :size => 60 %> |
|
17 | 17 | <em class="info"><%= l(:label_example) %>: <%= @guessed_host_and_path %></em></p> |
|
18 | 18 | |
|
19 | 19 | <p><%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %></p> |
|
20 | 20 | |
|
21 |
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.format |
|
|
21 | <p><%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %></p> | |
|
22 | 22 | |
|
23 | 23 | <p><%= setting_check_box :cache_formatted_text %></p> |
|
24 | 24 | |
|
25 | 25 | <p><%= setting_select :wiki_compression, [['Gzip', 'gzip']], :blank => :label_none %></p> |
|
26 | 26 | |
|
27 | 27 | <p><%= setting_text_field :feeds_limit, :size => 6 %></p> |
|
28 | 28 | |
|
29 | 29 | <p><%= setting_text_field :file_max_size_displayed, :size => 6 %> <%= l(:"number.human.storage_units.units.kb") %></p> |
|
30 | 30 | |
|
31 | 31 | <p><%= setting_text_field :diff_max_lines_displayed, :size => 6 %></p> |
|
32 | 32 | |
|
33 | 33 | <p><%= setting_text_field :repositories_encodings, :size => 60 %> |
|
34 | 34 | <em class="info"><%= l(:text_comma_separated) %></em></p> |
|
35 | 35 | |
|
36 | 36 | <%= call_hook(:view_settings_general_form) %> |
|
37 | 37 | </div> |
|
38 | 38 | |
|
39 | 39 | <%= submit_tag l(:button_save) %> |
|
40 | 40 | <% end %> |
@@ -1,173 +1,182 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'digest/md5' |
|
19 | 19 | |
|
20 | 20 | module Redmine |
|
21 | 21 | module WikiFormatting |
|
22 | 22 | class StaleSectionError < Exception; end |
|
23 | 23 | |
|
24 | 24 | @@formatters = {} |
|
25 | 25 | |
|
26 | 26 | class << self |
|
27 | 27 | def map |
|
28 | 28 | yield self |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | def register(name, formatter, helper) | |
|
32 | raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name.to_s] | |
|
33 | @@formatters[name.to_s] = {:formatter => formatter, :helper => helper} | |
|
31 | def register(name, formatter, helper, options={}) | |
|
32 | name = name.to_s | |
|
33 | raise ArgumentError, "format name '#{name}' is already taken" if @@formatters[name] | |
|
34 | @@formatters[name] = { | |
|
35 | :formatter => formatter, | |
|
36 | :helper => helper, | |
|
37 | :label => options[:label] || name.humanize | |
|
38 | } | |
|
34 | 39 | end |
|
35 | 40 | |
|
36 | 41 | def formatter |
|
37 | 42 | formatter_for(Setting.text_formatting) |
|
38 | 43 | end |
|
39 | 44 | |
|
40 | 45 | def formatter_for(name) |
|
41 | 46 | entry = @@formatters[name.to_s] |
|
42 | 47 | (entry && entry[:formatter]) || Redmine::WikiFormatting::NullFormatter::Formatter |
|
43 | 48 | end |
|
44 | 49 | |
|
45 | 50 | def helper_for(name) |
|
46 | 51 | entry = @@formatters[name.to_s] |
|
47 | 52 | (entry && entry[:helper]) || Redmine::WikiFormatting::NullFormatter::Helper |
|
48 | 53 | end |
|
49 | 54 | |
|
50 | 55 | def format_names |
|
51 | 56 | @@formatters.keys.map |
|
52 | 57 | end |
|
53 | 58 | |
|
59 | def formats_for_select | |
|
60 | @@formatters.map {|name, options| [options[:label], name]} | |
|
61 | end | |
|
62 | ||
|
54 | 63 | def to_html(format, text, options = {}) |
|
55 | 64 | text = if Setting.cache_formatted_text? && text.size > 2.kilobyte && cache_store && cache_key = cache_key_for(format, text, options[:object], options[:attribute]) |
|
56 | 65 | # Text retrieved from the cache store may be frozen |
|
57 | 66 | # We need to dup it so we can do in-place substitutions with gsub! |
|
58 | 67 | cache_store.fetch cache_key do |
|
59 | 68 | formatter_for(format).new(text).to_html |
|
60 | 69 | end.dup |
|
61 | 70 | else |
|
62 | 71 | formatter_for(format).new(text).to_html |
|
63 | 72 | end |
|
64 | 73 | text |
|
65 | 74 | end |
|
66 | 75 | |
|
67 | 76 | # Returns true if the text formatter supports single section edit |
|
68 | 77 | def supports_section_edit? |
|
69 | 78 | (formatter.instance_methods & ['update_section', :update_section]).any? |
|
70 | 79 | end |
|
71 | 80 | |
|
72 | 81 | # Returns a cache key for the given text +format+, +text+, +object+ and +attribute+ or nil if no caching should be done |
|
73 | 82 | def cache_key_for(format, text, object, attribute) |
|
74 | 83 | if object && attribute && !object.new_record? && format.present? |
|
75 | 84 | "formatted_text/#{format}/#{object.class.model_name.cache_key}/#{object.id}-#{attribute}-#{Digest::MD5.hexdigest text}" |
|
76 | 85 | end |
|
77 | 86 | end |
|
78 | 87 | |
|
79 | 88 | # Returns the cache store used to cache HTML output |
|
80 | 89 | def cache_store |
|
81 | 90 | ActionController::Base.cache_store |
|
82 | 91 | end |
|
83 | 92 | end |
|
84 | 93 | |
|
85 | 94 | module LinksHelper |
|
86 | 95 | AUTO_LINK_RE = %r{ |
|
87 | 96 | ( # leading text |
|
88 | 97 | <\w+.*?>| # leading HTML tag, or |
|
89 | 98 | [\s\(\[,;]| # leading punctuation, or |
|
90 | 99 | ^ # beginning of line |
|
91 | 100 | ) |
|
92 | 101 | ( |
|
93 | 102 | (?:https?://)| # protocol spec, or |
|
94 | 103 | (?:s?ftps?://)| |
|
95 | 104 | (?:www\.) # www.* |
|
96 | 105 | ) |
|
97 | 106 | ( |
|
98 | 107 | ([^<]\S*?) # url |
|
99 | 108 | (\/)? # slash |
|
100 | 109 | ) |
|
101 | 110 | ((?:>)?|[^[:alnum:]_\=\/;\(\)]*?) # post |
|
102 | 111 | (?=<|\s|$) |
|
103 | 112 | }x unless const_defined?(:AUTO_LINK_RE) |
|
104 | 113 | |
|
105 | 114 | # Destructively remplaces urls into clickable links |
|
106 | 115 | def auto_link!(text) |
|
107 | 116 | text.gsub!(AUTO_LINK_RE) do |
|
108 | 117 | all, leading, proto, url, post = $&, $1, $2, $3, $6 |
|
109 | 118 | if leading =~ /<a\s/i || leading =~ /![<>=]?/ |
|
110 | 119 | # don't replace URL's that are already linked |
|
111 | 120 | # and URL's prefixed with ! !> !< != (textile images) |
|
112 | 121 | all |
|
113 | 122 | else |
|
114 | 123 | # Idea below : an URL with unbalanced parethesis and |
|
115 | 124 | # ending by ')' is put into external parenthesis |
|
116 | 125 | if ( url[-1]==?) and ((url.count("(") - url.count(")")) < 0 ) ) |
|
117 | 126 | url=url[0..-2] # discard closing parenth from url |
|
118 | 127 | post = ")"+post # add closing parenth to post |
|
119 | 128 | end |
|
120 | 129 | content = proto + url |
|
121 | 130 | href = "#{proto=="www."?"http://www.":proto}#{url}" |
|
122 | 131 | %(#{leading}<a class="external" href="#{ERB::Util.html_escape href}">#{ERB::Util.html_escape content}</a>#{post}).html_safe |
|
123 | 132 | end |
|
124 | 133 | end |
|
125 | 134 | end |
|
126 | 135 | |
|
127 | 136 | # Destructively remplaces email addresses into clickable links |
|
128 | 137 | def auto_mailto!(text) |
|
129 | 138 | text.gsub!(/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/) do |
|
130 | 139 | mail = $1 |
|
131 | 140 | if text.match(/<a\b[^>]*>(.*)(#{Regexp.escape(mail)})(.*)<\/a>/) |
|
132 | 141 | |
|
133 | 142 | else |
|
134 | 143 | %(<a class="email" href="mailto:#{ERB::Util.html_escape mail}">#{ERB::Util.html_escape mail}</a>).html_safe |
|
135 | 144 | end |
|
136 | 145 | end |
|
137 | 146 | end |
|
138 | 147 | end |
|
139 | 148 | |
|
140 | 149 | # Default formatter module |
|
141 | 150 | module NullFormatter |
|
142 | 151 | class Formatter |
|
143 | 152 | include ActionView::Helpers::TagHelper |
|
144 | 153 | include ActionView::Helpers::TextHelper |
|
145 | 154 | include ActionView::Helpers::UrlHelper |
|
146 | 155 | include Redmine::WikiFormatting::LinksHelper |
|
147 | 156 | |
|
148 | 157 | def initialize(text) |
|
149 | 158 | @text = text |
|
150 | 159 | end |
|
151 | 160 | |
|
152 | 161 | def to_html(*args) |
|
153 | 162 | t = CGI::escapeHTML(@text) |
|
154 | 163 | auto_link!(t) |
|
155 | 164 | auto_mailto!(t) |
|
156 | 165 | simple_format(t, {}, :sanitize => false) |
|
157 | 166 | end |
|
158 | 167 | end |
|
159 | 168 | |
|
160 | 169 | module Helper |
|
161 | 170 | def wikitoolbar_for(field_id) |
|
162 | 171 | end |
|
163 | 172 | |
|
164 | 173 | def heads_for_wiki_formatter |
|
165 | 174 | end |
|
166 | 175 | |
|
167 | 176 | def initial_page_content(page) |
|
168 | 177 | page.pretty_title.to_s |
|
169 | 178 | end |
|
170 | 179 | end |
|
171 | 180 | end |
|
172 | 181 | end |
|
173 | 182 | end |
@@ -1,60 +1,64 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::WikiFormattingTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :issues |
|
22 | 22 | |
|
23 | 23 | def test_textile_formatter |
|
24 | 24 | assert_equal Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting.formatter_for('textile') |
|
25 | 25 | assert_equal Redmine::WikiFormatting::Textile::Helper, Redmine::WikiFormatting.helper_for('textile') |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_null_formatter |
|
29 | 29 | assert_equal Redmine::WikiFormatting::NullFormatter::Formatter, Redmine::WikiFormatting.formatter_for('') |
|
30 | 30 | assert_equal Redmine::WikiFormatting::NullFormatter::Helper, Redmine::WikiFormatting.helper_for('') |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | def test_formats_for_select | |
|
34 | assert_include ['Textile', 'textile'], Redmine::WikiFormatting.formats_for_select | |
|
35 | end | |
|
36 | ||
|
33 | 37 | def test_should_link_urls_and_email_addresses |
|
34 | 38 | raw = <<-DIFF |
|
35 | 39 | This is a sample *text* with a link: http://www.redmine.org |
|
36 | 40 | and an email address foo@example.net |
|
37 | 41 | DIFF |
|
38 | 42 | |
|
39 | 43 | expected = <<-EXPECTED |
|
40 | 44 | <p>This is a sample *text* with a link: <a class="external" href="http://www.redmine.org">http://www.redmine.org</a><br /> |
|
41 | 45 | and an email address <a class="email" href="mailto:foo@example.net">foo@example.net</a></p> |
|
42 | 46 | EXPECTED |
|
43 | 47 | |
|
44 | 48 | assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '') |
|
45 | 49 | end |
|
46 | 50 | |
|
47 | 51 | def test_supports_section_edit |
|
48 | 52 | with_settings :text_formatting => 'textile' do |
|
49 | 53 | assert_equal true, Redmine::WikiFormatting.supports_section_edit? |
|
50 | 54 | end |
|
51 | 55 | |
|
52 | 56 | with_settings :text_formatting => '' do |
|
53 | 57 | assert_equal false, Redmine::WikiFormatting.supports_section_edit? |
|
54 | 58 | end |
|
55 | 59 | end |
|
56 | 60 | |
|
57 | 61 | def test_cache_key_for_saved_object_should_no_be_nil |
|
58 | 62 | assert_not_nil Redmine::WikiFormatting.cache_key_for('textile', 'Text', Issue.find(1), :description) |
|
59 | 63 | end |
|
60 | 64 | end |
General Comments 0
You need to be logged in to leave comments.
Login now