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