##// END OF EJS Templates
Fix links to activity pages broken with r4047. #6392...
Jean-Baptiste Barth -
r3978:0d967c057276
parent child
Show More
@@ -0,0 +1,26
1 <div class="contextual">
2 <%= watcher_tag(@wiki, User.current) %>
3 </div>
4
5 <h2><%= l(:label_index_by_title) %></h2>
6
7 <% if @pages.empty? %>
8 <p class="nodata"><%= l(:label_no_data) %></p>
9 <% end %>
10
11 <%= render_page_hierarchy(@pages_by_parent_id) %>
12
13 <% content_for :sidebar do %>
14 <%= render :partial => 'sidebar' %>
15 <% end %>
16
17 <% unless @pages.empty? %>
18 <% other_formats_links do |f| %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
20 <%= f.link_to('HTML', :url => {:action => 'special', :page => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
21 <% end %>
22 <% end %>
23
24 <% content_for :header_tags do %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
26 <% end %>
@@ -1,864 +1,864
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 'forwardable'
19 19 require 'cgi'
20 20
21 21 module ApplicationHelper
22 22 include Redmine::WikiFormatting::Macros::Definitions
23 23 include Redmine::I18n
24 24 include GravatarHelper::PublicMethods
25 25
26 26 extend Forwardable
27 27 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
28 28
29 29 # Return true if user is authorized for controller/action, otherwise false
30 30 def authorize_for(controller, action)
31 31 User.current.allowed_to?({:controller => controller, :action => action}, @project)
32 32 end
33 33
34 34 # Display a link if user is authorized
35 35 #
36 36 # @param [String] name Anchor text (passed to link_to)
37 37 # @param [Hash, String] options Hash params or url for the link target (passed to link_to).
38 38 # This will checked by authorize_for to see if the user is authorized
39 39 # @param [optional, Hash] html_options Options passed to link_to
40 40 # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
41 41 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
42 42 if options.is_a?(String)
43 43 begin
44 44 route = ActionController::Routing::Routes.recognize_path(options.gsub(/\?.*/,''), :method => options[:method] || :get)
45 45 link_controller = route[:controller]
46 46 link_action = route[:action]
47 47 rescue ActionController::RoutingError # Parse failed, not a route
48 48 link_controller, link_action = nil, nil
49 49 end
50 50 else
51 51 link_controller = options[:controller] || params[:controller]
52 52 link_action = options[:action]
53 53 end
54 54
55 55 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(link_controller, link_action)
56 56 end
57 57
58 58 # Display a link to remote if user is authorized
59 59 def link_to_remote_if_authorized(name, options = {}, html_options = nil)
60 60 url = options[:url] || {}
61 61 link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
62 62 end
63 63
64 64 # Displays a link to user's account page if active
65 65 def link_to_user(user, options={})
66 66 if user.is_a?(User)
67 67 name = h(user.name(options[:format]))
68 68 if user.active?
69 69 link_to name, :controller => 'users', :action => 'show', :id => user
70 70 else
71 71 name
72 72 end
73 73 else
74 74 h(user.to_s)
75 75 end
76 76 end
77 77
78 78 # Displays a link to +issue+ with its subject.
79 79 # Examples:
80 80 #
81 81 # link_to_issue(issue) # => Defect #6: This is the subject
82 82 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
83 83 # link_to_issue(issue, :subject => false) # => Defect #6
84 84 # link_to_issue(issue, :project => true) # => Foo - Defect #6
85 85 #
86 86 def link_to_issue(issue, options={})
87 87 title = nil
88 88 subject = nil
89 89 if options[:subject] == false
90 90 title = truncate(issue.subject, :length => 60)
91 91 else
92 92 subject = issue.subject
93 93 if options[:truncate]
94 94 subject = truncate(subject, :length => options[:truncate])
95 95 end
96 96 end
97 97 s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
98 98 :class => issue.css_classes,
99 99 :title => title
100 100 s << ": #{h subject}" if subject
101 101 s = "#{h issue.project} - " + s if options[:project]
102 102 s
103 103 end
104 104
105 105 # Generates a link to an attachment.
106 106 # Options:
107 107 # * :text - Link text (default to attachment filename)
108 108 # * :download - Force download (default: false)
109 109 def link_to_attachment(attachment, options={})
110 110 text = options.delete(:text) || attachment.filename
111 111 action = options.delete(:download) ? 'download' : 'show'
112 112
113 113 link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
114 114 end
115 115
116 116 # Generates a link to a SCM revision
117 117 # Options:
118 118 # * :text - Link text (default to the formatted revision)
119 119 def link_to_revision(revision, project, options={})
120 120 text = options.delete(:text) || format_revision(revision)
121 121
122 122 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision))
123 123 end
124 124
125 125 def link_to_project(project, options={})
126 126 options[:class] ||= 'project'
127 127 link_to(h(project), {:controller => 'projects', :action => 'show', :id => project}, :class => options[:class])
128 128 end
129 129
130 130 # Generates a link to a project if active
131 131 # Examples:
132 132 #
133 133 # link_to_project(project) # => link to the specified project overview
134 134 # link_to_project(project, :action=>'settings') # => link to project settings
135 135 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
136 136 # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
137 137 #
138 138 def link_to_project(project, options={}, html_options = nil)
139 139 if project.active?
140 140 url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
141 141 link_to(h(project), url, html_options)
142 142 else
143 143 h(project)
144 144 end
145 145 end
146 146
147 147 def toggle_link(name, id, options={})
148 148 onclick = "Element.toggle('#{id}'); "
149 149 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
150 150 onclick << "return false;"
151 151 link_to(name, "#", :onclick => onclick)
152 152 end
153 153
154 154 def image_to_function(name, function, html_options = {})
155 155 html_options.symbolize_keys!
156 156 tag(:input, html_options.merge({
157 157 :type => "image", :src => image_path(name),
158 158 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
159 159 }))
160 160 end
161 161
162 162 def prompt_to_remote(name, text, param, url, html_options = {})
163 163 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
164 164 link_to name, {}, html_options
165 165 end
166 166
167 167 def format_activity_title(text)
168 168 h(truncate_single_line(text, :length => 100))
169 169 end
170 170
171 171 def format_activity_day(date)
172 172 date == Date.today ? l(:label_today).titleize : format_date(date)
173 173 end
174 174
175 175 def format_activity_description(text)
176 176 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
177 177 end
178 178
179 179 def format_version_name(version)
180 180 if version.project == @project
181 181 h(version)
182 182 else
183 183 h("#{version.project} - #{version}")
184 184 end
185 185 end
186 186
187 187 def due_date_distance_in_words(date)
188 188 if date
189 189 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
190 190 end
191 191 end
192 192
193 193 def render_page_hierarchy(pages, node=nil)
194 194 content = ''
195 195 if pages[node]
196 196 content << "<ul class=\"pages-hierarchy\">\n"
197 197 pages[node].each do |page|
198 198 content << "<li>"
199 199 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
200 200 :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
201 201 content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
202 202 content << "</li>\n"
203 203 end
204 204 content << "</ul>\n"
205 205 end
206 206 content
207 207 end
208 208
209 209 # Renders flash messages
210 210 def render_flash_messages
211 211 s = ''
212 212 flash.each do |k,v|
213 213 s << content_tag('div', v, :class => "flash #{k}")
214 214 end
215 215 s
216 216 end
217 217
218 218 # Renders tabs and their content
219 219 def render_tabs(tabs)
220 220 if tabs.any?
221 221 render :partial => 'common/tabs', :locals => {:tabs => tabs}
222 222 else
223 223 content_tag 'p', l(:label_no_data), :class => "nodata"
224 224 end
225 225 end
226 226
227 227 # Renders the project quick-jump box
228 228 def render_project_jump_box
229 229 # Retrieve them now to avoid a COUNT query
230 230 projects = User.current.projects.all
231 231 if projects.any?
232 232 s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
233 233 "<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
234 234 '<option value="" disabled="disabled">---</option>'
235 235 s << project_tree_options_for_select(projects, :selected => @project) do |p|
236 236 { :value => url_for(:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item) }
237 237 end
238 238 s << '</select>'
239 239 s
240 240 end
241 241 end
242 242
243 243 def project_tree_options_for_select(projects, options = {})
244 244 s = ''
245 245 project_tree(projects) do |project, level|
246 246 name_prefix = (level > 0 ? ('&nbsp;' * 2 * level + '&#187; ') : '')
247 247 tag_options = {:value => project.id}
248 248 if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
249 249 tag_options[:selected] = 'selected'
250 250 else
251 251 tag_options[:selected] = nil
252 252 end
253 253 tag_options.merge!(yield(project)) if block_given?
254 254 s << content_tag('option', name_prefix + h(project), tag_options)
255 255 end
256 256 s
257 257 end
258 258
259 259 # Yields the given block for each project with its level in the tree
260 260 def project_tree(projects, &block)
261 261 ancestors = []
262 262 projects.sort_by(&:lft).each do |project|
263 263 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
264 264 ancestors.pop
265 265 end
266 266 yield project, ancestors.size
267 267 ancestors << project
268 268 end
269 269 end
270 270
271 271 def project_nested_ul(projects, &block)
272 272 s = ''
273 273 if projects.any?
274 274 ancestors = []
275 275 projects.sort_by(&:lft).each do |project|
276 276 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
277 277 s << "<ul>\n"
278 278 else
279 279 ancestors.pop
280 280 s << "</li>"
281 281 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
282 282 ancestors.pop
283 283 s << "</ul></li>\n"
284 284 end
285 285 end
286 286 s << "<li>"
287 287 s << yield(project).to_s
288 288 ancestors << project
289 289 end
290 290 s << ("</li></ul>\n" * ancestors.size)
291 291 end
292 292 s
293 293 end
294 294
295 295 def principals_check_box_tags(name, principals)
296 296 s = ''
297 297 principals.sort.each do |principal|
298 298 s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
299 299 end
300 300 s
301 301 end
302 302
303 303 # Truncates and returns the string as a single line
304 304 def truncate_single_line(string, *args)
305 305 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
306 306 end
307 307
308 308 # Truncates at line break after 250 characters or options[:length]
309 309 def truncate_lines(string, options={})
310 310 length = options[:length] || 250
311 311 if string.to_s =~ /\A(.{#{length}}.*?)$/m
312 312 "#{$1}..."
313 313 else
314 314 string
315 315 end
316 316 end
317 317
318 318 def html_hours(text)
319 319 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
320 320 end
321 321
322 322 def authoring(created, author, options={})
323 323 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
324 324 end
325 325
326 326 def time_tag(time)
327 327 text = distance_of_time_in_words(Time.now, time)
328 328 if @project
329 link_to(text, {:controller => 'projects', :action => 'activity', :id => @project, :from => time.to_date}, :title => format_time(time))
329 link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => time.to_date}, :title => format_time(time))
330 330 else
331 331 content_tag('acronym', text, :title => format_time(time))
332 332 end
333 333 end
334 334
335 335 def syntax_highlight(name, content)
336 336 Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
337 337 end
338 338
339 339 def to_path_param(path)
340 340 path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
341 341 end
342 342
343 343 def pagination_links_full(paginator, count=nil, options={})
344 344 page_param = options.delete(:page_param) || :page
345 345 per_page_links = options.delete(:per_page_links)
346 346 url_param = params.dup
347 347 # don't reuse query params if filters are present
348 348 url_param.merge!(:fields => nil, :values => nil, :operators => nil) if url_param.delete(:set_filter)
349 349
350 350 html = ''
351 351 if paginator.current.previous
352 352 html << link_to_remote_content_update('&#171; ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
353 353 end
354 354
355 355 html << (pagination_links_each(paginator, options) do |n|
356 356 link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
357 357 end || '')
358 358
359 359 if paginator.current.next
360 360 html << ' ' + link_to_remote_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
361 361 end
362 362
363 363 unless count.nil?
364 364 html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
365 365 if per_page_links != false && links = per_page_links(paginator.items_per_page)
366 366 html << " | #{links}"
367 367 end
368 368 end
369 369
370 370 html
371 371 end
372 372
373 373 def per_page_links(selected=nil)
374 374 url_param = params.dup
375 375 url_param.clear if url_param.has_key?(:set_filter)
376 376
377 377 links = Setting.per_page_options_array.collect do |n|
378 378 n == selected ? n : link_to_remote(n, {:update => "content",
379 379 :url => params.dup.merge(:per_page => n),
380 380 :method => :get},
381 381 {:href => url_for(url_param.merge(:per_page => n))})
382 382 end
383 383 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
384 384 end
385 385
386 386 def reorder_links(name, url)
387 387 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
388 388 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
389 389 link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :title => l(:label_sort_lower)) +
390 390 link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), :method => :post, :title => l(:label_sort_lowest))
391 391 end
392 392
393 393 def breadcrumb(*args)
394 394 elements = args.flatten
395 395 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
396 396 end
397 397
398 398 def other_formats_links(&block)
399 399 concat('<p class="other-formats">' + l(:label_export_to))
400 400 yield Redmine::Views::OtherFormatsBuilder.new(self)
401 401 concat('</p>')
402 402 end
403 403
404 404 def page_header_title
405 405 if @project.nil? || @project.new_record?
406 406 h(Setting.app_title)
407 407 else
408 408 b = []
409 409 ancestors = (@project.root? ? [] : @project.ancestors.visible)
410 410 if ancestors.any?
411 411 root = ancestors.shift
412 412 b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
413 413 if ancestors.size > 2
414 414 b << '&#8230;'
415 415 ancestors = ancestors[-2, 2]
416 416 end
417 417 b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
418 418 end
419 419 b << h(@project)
420 420 b.join(' &#187; ')
421 421 end
422 422 end
423 423
424 424 def html_title(*args)
425 425 if args.empty?
426 426 title = []
427 427 title << @project.name if @project
428 428 title += @html_title if @html_title
429 429 title << Setting.app_title
430 430 title.select {|t| !t.blank? }.join(' - ')
431 431 else
432 432 @html_title ||= []
433 433 @html_title += args
434 434 end
435 435 end
436 436
437 437 # Returns the theme, controller name, and action as css classes for the
438 438 # HTML body.
439 439 def body_css_classes
440 440 css = []
441 441 if theme = Redmine::Themes.theme(Setting.ui_theme)
442 442 css << 'theme-' + theme.name
443 443 end
444 444
445 445 css << 'controller-' + params[:controller]
446 446 css << 'action-' + params[:action]
447 447 css.join(' ')
448 448 end
449 449
450 450 def accesskey(s)
451 451 Redmine::AccessKeys.key_for s
452 452 end
453 453
454 454 # Formats text according to system settings.
455 455 # 2 ways to call this method:
456 456 # * with a String: textilizable(text, options)
457 457 # * with an object and one of its attribute: textilizable(issue, :description, options)
458 458 def textilizable(*args)
459 459 options = args.last.is_a?(Hash) ? args.pop : {}
460 460 case args.size
461 461 when 1
462 462 obj = options[:object]
463 463 text = args.shift
464 464 when 2
465 465 obj = args.shift
466 466 attr = args.shift
467 467 text = obj.send(attr).to_s
468 468 else
469 469 raise ArgumentError, 'invalid arguments to textilizable'
470 470 end
471 471 return '' if text.blank?
472 472 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
473 473 only_path = options.delete(:only_path) == false ? false : true
474 474
475 475 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
476 476
477 477 parse_non_pre_blocks(text) do |text|
478 478 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
479 479 send method_name, text, project, obj, attr, only_path, options
480 480 end
481 481 end
482 482 end
483 483
484 484 def parse_non_pre_blocks(text)
485 485 s = StringScanner.new(text)
486 486 tags = []
487 487 parsed = ''
488 488 while !s.eos?
489 489 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
490 490 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
491 491 if tags.empty?
492 492 yield text
493 493 end
494 494 parsed << text
495 495 if tag
496 496 if closing
497 497 if tags.last == tag.downcase
498 498 tags.pop
499 499 end
500 500 else
501 501 tags << tag.downcase
502 502 end
503 503 parsed << full_tag
504 504 end
505 505 end
506 506 # Close any non closing tags
507 507 while tag = tags.pop
508 508 parsed << "</#{tag}>"
509 509 end
510 510 parsed
511 511 end
512 512
513 513 def parse_inline_attachments(text, project, obj, attr, only_path, options)
514 514 # when using an image link, try to use an attachment, if possible
515 515 if options[:attachments] || (obj && obj.respond_to?(:attachments))
516 516 attachments = nil
517 517 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
518 518 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
519 519 attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
520 520 # search for the picture in attachments
521 521 if found = attachments.detect { |att| att.filename.downcase == filename }
522 522 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
523 523 desc = found.description.to_s.gsub('"', '')
524 524 if !desc.blank? && alttext.blank?
525 525 alt = " title=\"#{desc}\" alt=\"#{desc}\""
526 526 end
527 527 "src=\"#{image_url}\"#{alt}"
528 528 else
529 529 m
530 530 end
531 531 end
532 532 end
533 533 end
534 534
535 535 # Wiki links
536 536 #
537 537 # Examples:
538 538 # [[mypage]]
539 539 # [[mypage|mytext]]
540 540 # wiki links can refer other project wikis, using project name or identifier:
541 541 # [[project:]] -> wiki starting page
542 542 # [[project:|mytext]]
543 543 # [[project:mypage]]
544 544 # [[project:mypage|mytext]]
545 545 def parse_wiki_links(text, project, obj, attr, only_path, options)
546 546 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
547 547 link_project = project
548 548 esc, all, page, title = $1, $2, $3, $5
549 549 if esc.nil?
550 550 if page =~ /^([^\:]+)\:(.*)$/
551 551 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
552 552 page = $2
553 553 title ||= $1 if page.blank?
554 554 end
555 555
556 556 if link_project && link_project.wiki
557 557 # extract anchor
558 558 anchor = nil
559 559 if page =~ /^(.+?)\#(.+)$/
560 560 page, anchor = $1, $2
561 561 end
562 562 # check if page exists
563 563 wiki_page = link_project.wiki.find_page(page)
564 564 url = case options[:wiki_links]
565 565 when :local; "#{title}.html"
566 566 when :anchor; "##{title}" # used for single-file wiki export
567 567 else
568 568 url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
569 569 end
570 570 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
571 571 else
572 572 # project or wiki doesn't exist
573 573 all
574 574 end
575 575 else
576 576 all
577 577 end
578 578 end
579 579 end
580 580
581 581 # Redmine links
582 582 #
583 583 # Examples:
584 584 # Issues:
585 585 # #52 -> Link to issue #52
586 586 # Changesets:
587 587 # r52 -> Link to revision 52
588 588 # commit:a85130f -> Link to scmid starting with a85130f
589 589 # Documents:
590 590 # document#17 -> Link to document with id 17
591 591 # document:Greetings -> Link to the document with title "Greetings"
592 592 # document:"Some document" -> Link to the document with title "Some document"
593 593 # Versions:
594 594 # version#3 -> Link to version with id 3
595 595 # version:1.0.0 -> Link to version named "1.0.0"
596 596 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
597 597 # Attachments:
598 598 # attachment:file.zip -> Link to the attachment of the current object named file.zip
599 599 # Source files:
600 600 # source:some/file -> Link to the file located at /some/file in the project's repository
601 601 # source:some/file@52 -> Link to the file's revision 52
602 602 # source:some/file#L120 -> Link to line 120 of the file
603 603 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
604 604 # export:some/file -> Force the download of the file
605 605 # Forum messages:
606 606 # message#1218 -> Link to message with id 1218
607 607 def parse_redmine_links(text, project, obj, attr, only_path, options)
608 608 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
609 609 leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
610 610 link = nil
611 611 if esc.nil?
612 612 if prefix.nil? && sep == 'r'
613 613 if project && (changeset = project.changesets.find_by_revision(identifier))
614 614 link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
615 615 :class => 'changeset',
616 616 :title => truncate_single_line(changeset.comments, :length => 100))
617 617 end
618 618 elsif sep == '#'
619 619 oid = identifier.to_i
620 620 case prefix
621 621 when nil
622 622 if issue = Issue.visible.find_by_id(oid, :include => :status)
623 623 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
624 624 :class => issue.css_classes,
625 625 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
626 626 end
627 627 when 'document'
628 628 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
629 629 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
630 630 :class => 'document'
631 631 end
632 632 when 'version'
633 633 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
634 634 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
635 635 :class => 'version'
636 636 end
637 637 when 'message'
638 638 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
639 639 link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
640 640 :controller => 'messages',
641 641 :action => 'show',
642 642 :board_id => message.board,
643 643 :id => message.root,
644 644 :anchor => (message.parent ? "message-#{message.id}" : nil)},
645 645 :class => 'message'
646 646 end
647 647 when 'project'
648 648 if p = Project.visible.find_by_id(oid)
649 649 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
650 650 end
651 651 end
652 652 elsif sep == ':'
653 653 # removes the double quotes if any
654 654 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
655 655 case prefix
656 656 when 'document'
657 657 if project && document = project.documents.find_by_title(name)
658 658 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
659 659 :class => 'document'
660 660 end
661 661 when 'version'
662 662 if project && version = project.versions.find_by_name(name)
663 663 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
664 664 :class => 'version'
665 665 end
666 666 when 'commit'
667 667 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
668 668 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
669 669 :class => 'changeset',
670 670 :title => truncate_single_line(changeset.comments, :length => 100)
671 671 end
672 672 when 'source', 'export'
673 673 if project && project.repository
674 674 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
675 675 path, rev, anchor = $1, $3, $5
676 676 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
677 677 :path => to_path_param(path),
678 678 :rev => rev,
679 679 :anchor => anchor,
680 680 :format => (prefix == 'export' ? 'raw' : nil)},
681 681 :class => (prefix == 'export' ? 'source download' : 'source')
682 682 end
683 683 when 'attachment'
684 684 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
685 685 if attachments && attachment = attachments.detect {|a| a.filename == name }
686 686 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
687 687 :class => 'attachment'
688 688 end
689 689 when 'project'
690 690 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
691 691 link = link_to_project(p, {:only_path => only_path}, :class => 'project')
692 692 end
693 693 end
694 694 end
695 695 end
696 696 leading + (link || "#{prefix}#{sep}#{identifier}")
697 697 end
698 698 end
699 699
700 700 # Same as Rails' simple_format helper without using paragraphs
701 701 def simple_format_without_paragraph(text)
702 702 text.to_s.
703 703 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
704 704 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
705 705 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
706 706 end
707 707
708 708 def lang_options_for_select(blank=true)
709 709 (blank ? [["(auto)", ""]] : []) +
710 710 valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
711 711 end
712 712
713 713 def label_tag_for(name, option_tags = nil, options = {})
714 714 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
715 715 content_tag("label", label_text)
716 716 end
717 717
718 718 def labelled_tabular_form_for(name, object, options, &proc)
719 719 options[:html] ||= {}
720 720 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
721 721 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
722 722 end
723 723
724 724 def back_url_hidden_field_tag
725 725 back_url = params[:back_url] || request.env['HTTP_REFERER']
726 726 back_url = CGI.unescape(back_url.to_s)
727 727 hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank?
728 728 end
729 729
730 730 def check_all_links(form_name)
731 731 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
732 732 " | " +
733 733 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
734 734 end
735 735
736 736 def progress_bar(pcts, options={})
737 737 pcts = [pcts, pcts] unless pcts.is_a?(Array)
738 738 pcts = pcts.collect(&:round)
739 739 pcts[1] = pcts[1] - pcts[0]
740 740 pcts << (100 - pcts[1] - pcts[0])
741 741 width = options[:width] || '100px;'
742 742 legend = options[:legend] || ''
743 743 content_tag('table',
744 744 content_tag('tr',
745 745 (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : '') +
746 746 (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : '') +
747 747 (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : '')
748 748 ), :class => 'progress', :style => "width: #{width};") +
749 749 content_tag('p', legend, :class => 'pourcent')
750 750 end
751 751
752 752 def checked_image(checked=true)
753 753 if checked
754 754 image_tag 'toggle_check.png'
755 755 end
756 756 end
757 757
758 758 def context_menu(url)
759 759 unless @context_menu_included
760 760 content_for :header_tags do
761 761 javascript_include_tag('context_menu') +
762 762 stylesheet_link_tag('context_menu')
763 763 end
764 764 if l(:direction) == 'rtl'
765 765 content_for :header_tags do
766 766 stylesheet_link_tag('context_menu_rtl')
767 767 end
768 768 end
769 769 @context_menu_included = true
770 770 end
771 771 javascript_tag "new ContextMenu('#{ url_for(url) }')"
772 772 end
773 773
774 774 def context_menu_link(name, url, options={})
775 775 options[:class] ||= ''
776 776 if options.delete(:selected)
777 777 options[:class] << ' icon-checked disabled'
778 778 options[:disabled] = true
779 779 end
780 780 if options.delete(:disabled)
781 781 options.delete(:method)
782 782 options.delete(:confirm)
783 783 options.delete(:onclick)
784 784 options[:class] << ' disabled'
785 785 url = '#'
786 786 end
787 787 link_to name, url, options
788 788 end
789 789
790 790 def calendar_for(field_id)
791 791 include_calendar_headers_tags
792 792 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
793 793 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
794 794 end
795 795
796 796 def include_calendar_headers_tags
797 797 unless @calendar_headers_tags_included
798 798 @calendar_headers_tags_included = true
799 799 content_for :header_tags do
800 800 start_of_week = case Setting.start_of_week.to_i
801 801 when 1
802 802 'Calendar._FD = 1;' # Monday
803 803 when 7
804 804 'Calendar._FD = 0;' # Sunday
805 805 else
806 806 '' # use language
807 807 end
808 808
809 809 javascript_include_tag('calendar/calendar') +
810 810 javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
811 811 javascript_tag(start_of_week) +
812 812 javascript_include_tag('calendar/calendar-setup') +
813 813 stylesheet_link_tag('calendar')
814 814 end
815 815 end
816 816 end
817 817
818 818 def content_for(name, content = nil, &block)
819 819 @has_content ||= {}
820 820 @has_content[name] = true
821 821 super(name, content, &block)
822 822 end
823 823
824 824 def has_content?(name)
825 825 (@has_content && @has_content[name]) || false
826 826 end
827 827
828 828 # Returns the avatar image tag for the given +user+ if avatars are enabled
829 829 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
830 830 def avatar(user, options = { })
831 831 if Setting.gravatar_enabled?
832 832 options.merge!({:ssl => Setting.protocol == 'https', :default => Setting.gravatar_default})
833 833 email = nil
834 834 if user.respond_to?(:mail)
835 835 email = user.mail
836 836 elsif user.to_s =~ %r{<(.+?)>}
837 837 email = $1
838 838 end
839 839 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
840 840 else
841 841 ''
842 842 end
843 843 end
844 844
845 845 def favicon
846 846 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
847 847 end
848 848
849 849 private
850 850
851 851 def wiki_helper
852 852 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
853 853 extend helper
854 854 return self
855 855 end
856 856
857 857 def link_to_remote_content_update(text, url_params)
858 858 link_to_remote(text,
859 859 {:url => url_params, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'},
860 860 {:href => url_for(:params => url_params)}
861 861 )
862 862 end
863 863
864 864 end
@@ -1,26 +1,26
1 1 <div class="contextual">
2 2 <%= watcher_tag(@wiki, User.current) %>
3 3 </div>
4 4
5 5 <h2><%= l(:label_index_by_title) %></h2>
6 6
7 7 <% if @pages.empty? %>
8 8 <p class="nodata"><%= l(:label_no_data) %></p>
9 9 <% end %>
10 10
11 11 <%= render_page_hierarchy(@pages_by_parent_id) %>
12 12
13 13 <% content_for :sidebar do %>
14 14 <%= render :partial => 'sidebar' %>
15 15 <% end %>
16 16
17 17 <% unless @pages.empty? %>
18 18 <% other_formats_links do |f| %>
19 <%= f.link_to 'Atom', :url => {:controller => 'projects', :action => 'activity', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
20 20 <%= f.link_to('HTML', :url => {:action => 'special', :page => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
21 21 <% end %>
22 22 <% end %>
23 23
24 24 <% content_for :header_tags do %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'projects', :action => 'activity', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
26 26 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now