PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/app/helpers/application_helper.rb

https://bitbucket.org/eimajenthat/redmine
Ruby | 1240 lines | 974 code | 110 blank | 156 comment | 185 complexity | 88269c5e7dde314c884e01e218fac07e MD5 | raw file
Possible License(s): GPL-2.0
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2013 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. require 'forwardable'
  20. require 'cgi'
  21. module ApplicationHelper
  22. include Redmine::WikiFormatting::Macros::Definitions
  23. include Redmine::I18n
  24. include GravatarHelper::PublicMethods
  25. include Redmine::Pagination::Helper
  26. extend Forwardable
  27. def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
  28. # Return true if user is authorized for controller/action, otherwise false
  29. def authorize_for(controller, action)
  30. User.current.allowed_to?({:controller => controller, :action => action}, @project)
  31. end
  32. # Display a link if user is authorized
  33. #
  34. # @param [String] name Anchor text (passed to link_to)
  35. # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
  36. # @param [optional, Hash] html_options Options passed to link_to
  37. # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
  38. def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
  39. link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
  40. end
  41. # Displays a link to user's account page if active
  42. def link_to_user(user, options={})
  43. if user.is_a?(User)
  44. name = h(user.name(options[:format]))
  45. if user.active? || (User.current.admin? && user.logged?)
  46. link_to name, user_path(user), :class => user.css_classes
  47. else
  48. name
  49. end
  50. else
  51. h(user.to_s)
  52. end
  53. end
  54. # Displays a link to +issue+ with its subject.
  55. # Examples:
  56. #
  57. # link_to_issue(issue) # => Defect #6: This is the subject
  58. # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
  59. # link_to_issue(issue, :subject => false) # => Defect #6
  60. # link_to_issue(issue, :project => true) # => Foo - Defect #6
  61. # link_to_issue(issue, :subject => false, :tracker => false) # => #6
  62. #
  63. def link_to_issue(issue, options={})
  64. title = nil
  65. subject = nil
  66. text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}"
  67. if options[:subject] == false
  68. title = truncate(issue.subject, :length => 60)
  69. else
  70. subject = issue.subject
  71. if options[:truncate]
  72. subject = truncate(subject, :length => options[:truncate])
  73. end
  74. end
  75. s = link_to text, issue_path(issue), :class => issue.css_classes, :title => title
  76. s << h(": #{subject}") if subject
  77. s = h("#{issue.project} - ") + s if options[:project]
  78. s
  79. end
  80. # Generates a link to an attachment.
  81. # Options:
  82. # * :text - Link text (default to attachment filename)
  83. # * :download - Force download (default: false)
  84. def link_to_attachment(attachment, options={})
  85. text = options.delete(:text) || attachment.filename
  86. route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
  87. html_options = options.slice!(:only_path)
  88. url = send(route_method, attachment, attachment.filename, options)
  89. link_to text, url, html_options
  90. end
  91. # Generates a link to a SCM revision
  92. # Options:
  93. # * :text - Link text (default to the formatted revision)
  94. def link_to_revision(revision, repository, options={})
  95. if repository.is_a?(Project)
  96. repository = repository.repository
  97. end
  98. text = options.delete(:text) || format_revision(revision)
  99. rev = revision.respond_to?(:identifier) ? revision.identifier : revision
  100. link_to(
  101. h(text),
  102. {:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev},
  103. :title => l(:label_revision_id, format_revision(revision))
  104. )
  105. end
  106. # Generates a link to a message
  107. def link_to_message(message, options={}, html_options = nil)
  108. link_to(
  109. truncate(message.subject, :length => 60),
  110. board_message_path(message.board_id, message.parent_id || message.id, {
  111. :r => (message.parent_id && message.id),
  112. :anchor => (message.parent_id ? "message-#{message.id}" : nil)
  113. }.merge(options)),
  114. html_options
  115. )
  116. end
  117. # Generates a link to a project if active
  118. # Examples:
  119. #
  120. # link_to_project(project) # => link to the specified project overview
  121. # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
  122. # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
  123. #
  124. def link_to_project(project, options={}, html_options = nil)
  125. if project.archived?
  126. h(project.name)
  127. elsif options.key?(:action)
  128. ActiveSupport::Deprecation.warn "#link_to_project with :action option is deprecated and will be removed in Redmine 3.0."
  129. url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
  130. link_to project.name, url, html_options
  131. else
  132. link_to project.name, project_path(project, options), html_options
  133. end
  134. end
  135. # Generates a link to a project settings if active
  136. def link_to_project_settings(project, options={}, html_options=nil)
  137. if project.active?
  138. link_to project.name, settings_project_path(project, options), html_options
  139. elsif project.archived?
  140. h(project.name)
  141. else
  142. link_to project.name, project_path(project, options), html_options
  143. end
  144. end
  145. def wiki_page_path(page, options={})
  146. url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options))
  147. end
  148. def thumbnail_tag(attachment)
  149. link_to image_tag(thumbnail_path(attachment)),
  150. named_attachment_path(attachment, attachment.filename),
  151. :title => attachment.filename
  152. end
  153. def toggle_link(name, id, options={})
  154. onclick = "$('##{id}').toggle(); "
  155. onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
  156. onclick << "return false;"
  157. link_to(name, "#", :onclick => onclick)
  158. end
  159. def image_to_function(name, function, html_options = {})
  160. html_options.symbolize_keys!
  161. tag(:input, html_options.merge({
  162. :type => "image", :src => image_path(name),
  163. :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
  164. }))
  165. end
  166. def format_activity_title(text)
  167. h(truncate_single_line(text, :length => 100))
  168. end
  169. def format_activity_day(date)
  170. date == User.current.today ? l(:label_today).titleize : format_date(date)
  171. end
  172. def format_activity_description(text)
  173. h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')
  174. ).gsub(/[\r\n]+/, "<br />").html_safe
  175. end
  176. def format_version_name(version)
  177. if version.project == @project
  178. h(version)
  179. else
  180. h("#{version.project} - #{version}")
  181. end
  182. end
  183. def due_date_distance_in_words(date)
  184. if date
  185. l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
  186. end
  187. end
  188. # Renders a tree of projects as a nested set of unordered lists
  189. # The given collection may be a subset of the whole project tree
  190. # (eg. some intermediate nodes are private and can not be seen)
  191. def render_project_nested_lists(projects)
  192. s = ''
  193. if projects.any?
  194. ancestors = []
  195. original_project = @project
  196. projects.sort_by(&:lft).each do |project|
  197. # set the project environment to please macros.
  198. @project = project
  199. if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
  200. s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
  201. else
  202. ancestors.pop
  203. s << "</li>"
  204. while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
  205. ancestors.pop
  206. s << "</ul></li>\n"
  207. end
  208. end
  209. classes = (ancestors.empty? ? 'root' : 'child')
  210. s << "<li class='#{classes}'><div class='#{classes}'>"
  211. s << h(block_given? ? yield(project) : project.name)
  212. s << "</div>\n"
  213. ancestors << project
  214. end
  215. s << ("</li></ul>\n" * ancestors.size)
  216. @project = original_project
  217. end
  218. s.html_safe
  219. end
  220. def render_page_hierarchy(pages, node=nil, options={})
  221. content = ''
  222. if pages[node]
  223. content << "<ul class=\"pages-hierarchy\">\n"
  224. pages[node].each do |page|
  225. content << "<li>"
  226. content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
  227. :title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
  228. content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
  229. content << "</li>\n"
  230. end
  231. content << "</ul>\n"
  232. end
  233. content.html_safe
  234. end
  235. # Renders flash messages
  236. def render_flash_messages
  237. s = ''
  238. flash.each do |k,v|
  239. s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
  240. end
  241. s.html_safe
  242. end
  243. # Renders tabs and their content
  244. def render_tabs(tabs)
  245. if tabs.any?
  246. render :partial => 'common/tabs', :locals => {:tabs => tabs}
  247. else
  248. content_tag 'p', l(:label_no_data), :class => "nodata"
  249. end
  250. end
  251. # Renders the project quick-jump box
  252. def render_project_jump_box
  253. return unless User.current.logged?
  254. projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq
  255. if projects.any?
  256. options =
  257. ("<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
  258. '<option value="" disabled="disabled">---</option>').html_safe
  259. options << project_tree_options_for_select(projects, :selected => @project) do |p|
  260. { :value => project_path(:id => p, :jump => current_menu_item) }
  261. end
  262. select_tag('project_quick_jump_box', options, :onchange => 'if (this.value != \'\') { window.location = this.value; }')
  263. end
  264. end
  265. def project_tree_options_for_select(projects, options = {})
  266. s = ''
  267. project_tree(projects) do |project, level|
  268. name_prefix = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
  269. tag_options = {:value => project.id}
  270. if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
  271. tag_options[:selected] = 'selected'
  272. else
  273. tag_options[:selected] = nil
  274. end
  275. tag_options.merge!(yield(project)) if block_given?
  276. s << content_tag('option', name_prefix + h(project), tag_options)
  277. end
  278. s.html_safe
  279. end
  280. # Yields the given block for each project with its level in the tree
  281. #
  282. # Wrapper for Project#project_tree
  283. def project_tree(projects, &block)
  284. Project.project_tree(projects, &block)
  285. end
  286. def principals_check_box_tags(name, principals)
  287. s = ''
  288. principals.each do |principal|
  289. s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
  290. end
  291. s.html_safe
  292. end
  293. # Returns a string for users/groups option tags
  294. def principals_options_for_select(collection, selected=nil)
  295. s = ''
  296. if collection.include?(User.current)
  297. s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
  298. end
  299. groups = ''
  300. collection.sort.each do |element|
  301. selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
  302. (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
  303. end
  304. unless groups.empty?
  305. s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
  306. end
  307. s.html_safe
  308. end
  309. # Options for the new membership projects combo-box
  310. def options_for_membership_project_select(principal, projects)
  311. options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
  312. options << project_tree_options_for_select(projects) do |p|
  313. {:disabled => principal.projects.include?(p)}
  314. end
  315. options
  316. end
  317. # Truncates and returns the string as a single line
  318. def truncate_single_line(string, *args)
  319. truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
  320. end
  321. # Truncates at line break after 250 characters or options[:length]
  322. def truncate_lines(string, options={})
  323. length = options[:length] || 250
  324. if string.to_s =~ /\A(.{#{length}}.*?)$/m
  325. "#{$1}..."
  326. else
  327. string
  328. end
  329. end
  330. def anchor(text)
  331. text.to_s.gsub(' ', '_')
  332. end
  333. def html_hours(text)
  334. text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
  335. end
  336. def authoring(created, author, options={})
  337. l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
  338. end
  339. def time_tag(time)
  340. text = distance_of_time_in_words(Time.now, time)
  341. if @project
  342. link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)}, :title => format_time(time))
  343. else
  344. content_tag('acronym', text, :title => format_time(time))
  345. end
  346. end
  347. def syntax_highlight_lines(name, content)
  348. lines = []
  349. syntax_highlight(name, content).each_line { |line| lines << line }
  350. lines
  351. end
  352. def syntax_highlight(name, content)
  353. Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
  354. end
  355. def to_path_param(path)
  356. str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/")
  357. str.blank? ? nil : str
  358. end
  359. def reorder_links(name, url, method = :post)
  360. link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)),
  361. url.merge({"#{name}[move_to]" => 'highest'}),
  362. :method => method, :title => l(:label_sort_highest)) +
  363. link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)),
  364. url.merge({"#{name}[move_to]" => 'higher'}),
  365. :method => method, :title => l(:label_sort_higher)) +
  366. link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)),
  367. url.merge({"#{name}[move_to]" => 'lower'}),
  368. :method => method, :title => l(:label_sort_lower)) +
  369. link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)),
  370. url.merge({"#{name}[move_to]" => 'lowest'}),
  371. :method => method, :title => l(:label_sort_lowest))
  372. end
  373. def breadcrumb(*args)
  374. elements = args.flatten
  375. elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
  376. end
  377. def other_formats_links(&block)
  378. concat('<p class="other-formats">'.html_safe + l(:label_export_to))
  379. yield Redmine::Views::OtherFormatsBuilder.new(self)
  380. concat('</p>'.html_safe)
  381. end
  382. def page_header_title
  383. if @project.nil? || @project.new_record?
  384. h(Setting.app_title)
  385. else
  386. b = []
  387. ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
  388. if ancestors.any?
  389. root = ancestors.shift
  390. b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
  391. if ancestors.size > 2
  392. b << "\xe2\x80\xa6"
  393. ancestors = ancestors[-2, 2]
  394. end
  395. b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
  396. end
  397. b << h(@project)
  398. b.join(" \xc2\xbb ").html_safe
  399. end
  400. end
  401. def html_title(*args)
  402. if args.empty?
  403. title = @html_title || []
  404. title << @project.name if @project
  405. title << Setting.app_title unless Setting.app_title == title.last
  406. title.select {|t| !t.blank? }.join(' - ')
  407. else
  408. @html_title ||= []
  409. @html_title += args
  410. end
  411. end
  412. # Returns the theme, controller name, and action as css classes for the
  413. # HTML body.
  414. def body_css_classes
  415. css = []
  416. if theme = Redmine::Themes.theme(Setting.ui_theme)
  417. css << 'theme-' + theme.name
  418. end
  419. css << 'controller-' + controller_name
  420. css << 'action-' + action_name
  421. css.join(' ')
  422. end
  423. def accesskey(s)
  424. Redmine::AccessKeys.key_for s
  425. end
  426. # Formats text according to system settings.
  427. # 2 ways to call this method:
  428. # * with a String: textilizable(text, options)
  429. # * with an object and one of its attribute: textilizable(issue, :description, options)
  430. def textilizable(*args)
  431. options = args.last.is_a?(Hash) ? args.pop : {}
  432. case args.size
  433. when 1
  434. obj = options[:object]
  435. text = args.shift
  436. when 2
  437. obj = args.shift
  438. attr = args.shift
  439. text = obj.send(attr).to_s
  440. else
  441. raise ArgumentError, 'invalid arguments to textilizable'
  442. end
  443. return '' if text.blank?
  444. project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
  445. only_path = options.delete(:only_path) == false ? false : true
  446. text = text.dup
  447. macros = catch_macros(text)
  448. text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
  449. @parsed_headings = []
  450. @heading_anchors = {}
  451. @current_section = 0 if options[:edit_section_links]
  452. parse_sections(text, project, obj, attr, only_path, options)
  453. text = parse_non_pre_blocks(text, obj, macros) do |text|
  454. [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
  455. send method_name, text, project, obj, attr, only_path, options
  456. end
  457. end
  458. parse_headings(text, project, obj, attr, only_path, options)
  459. if @parsed_headings.any?
  460. replace_toc(text, @parsed_headings)
  461. end
  462. text.html_safe
  463. end
  464. def parse_non_pre_blocks(text, obj, macros)
  465. s = StringScanner.new(text)
  466. tags = []
  467. parsed = ''
  468. while !s.eos?
  469. s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
  470. text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
  471. if tags.empty?
  472. yield text
  473. inject_macros(text, obj, macros) if macros.any?
  474. else
  475. inject_macros(text, obj, macros, false) if macros.any?
  476. end
  477. parsed << text
  478. if tag
  479. if closing
  480. if tags.last == tag.downcase
  481. tags.pop
  482. end
  483. else
  484. tags << tag.downcase
  485. end
  486. parsed << full_tag
  487. end
  488. end
  489. # Close any non closing tags
  490. while tag = tags.pop
  491. parsed << "</#{tag}>"
  492. end
  493. parsed
  494. end
  495. def parse_inline_attachments(text, project, obj, attr, only_path, options)
  496. # when using an image link, try to use an attachment, if possible
  497. attachments = options[:attachments] || []
  498. attachments += obj.attachments if obj.respond_to?(:attachments)
  499. if attachments.present?
  500. text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
  501. filename, ext, alt, alttext = $1.downcase, $2, $3, $4
  502. # search for the picture in attachments
  503. if found = Attachment.latest_attach(attachments, filename)
  504. image_url = download_named_attachment_path(found, found.filename, :only_path => only_path)
  505. desc = found.description.to_s.gsub('"', '')
  506. if !desc.blank? && alttext.blank?
  507. alt = " title=\"#{desc}\" alt=\"#{desc}\""
  508. end
  509. "src=\"#{image_url}\"#{alt}"
  510. else
  511. m
  512. end
  513. end
  514. end
  515. end
  516. # Wiki links
  517. #
  518. # Examples:
  519. # [[mypage]]
  520. # [[mypage|mytext]]
  521. # wiki links can refer other project wikis, using project name or identifier:
  522. # [[project:]] -> wiki starting page
  523. # [[project:|mytext]]
  524. # [[project:mypage]]
  525. # [[project:mypage|mytext]]
  526. def parse_wiki_links(text, project, obj, attr, only_path, options)
  527. text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
  528. link_project = project
  529. esc, all, page, title = $1, $2, $3, $5
  530. if esc.nil?
  531. if page =~ /^([^\:]+)\:(.*)$/
  532. link_project = Project.find_by_identifier($1) || Project.find_by_name($1)
  533. page = $2
  534. title ||= $1 if page.blank?
  535. end
  536. if link_project && link_project.wiki
  537. # extract anchor
  538. anchor = nil
  539. if page =~ /^(.+?)\#(.+)$/
  540. page, anchor = $1, $2
  541. end
  542. anchor = sanitize_anchor_name(anchor) if anchor.present?
  543. # check if page exists
  544. wiki_page = link_project.wiki.find_page(page)
  545. url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
  546. "##{anchor}"
  547. else
  548. case options[:wiki_links]
  549. when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
  550. when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
  551. else
  552. wiki_page_id = page.present? ? Wiki.titleize(page) : nil
  553. parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
  554. url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
  555. :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent)
  556. end
  557. end
  558. link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
  559. else
  560. # project or wiki doesn't exist
  561. all
  562. end
  563. else
  564. all
  565. end
  566. end
  567. end
  568. # Redmine links
  569. #
  570. # Examples:
  571. # Issues:
  572. # #52 -> Link to issue #52
  573. # Changesets:
  574. # r52 -> Link to revision 52
  575. # commit:a85130f -> Link to scmid starting with a85130f
  576. # Documents:
  577. # document#17 -> Link to document with id 17
  578. # document:Greetings -> Link to the document with title "Greetings"
  579. # document:"Some document" -> Link to the document with title "Some document"
  580. # Versions:
  581. # version#3 -> Link to version with id 3
  582. # version:1.0.0 -> Link to version named "1.0.0"
  583. # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
  584. # Attachments:
  585. # attachment:file.zip -> Link to the attachment of the current object named file.zip
  586. # Source files:
  587. # source:some/file -> Link to the file located at /some/file in the project's repository
  588. # source:some/file@52 -> Link to the file's revision 52
  589. # source:some/file#L120 -> Link to line 120 of the file
  590. # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
  591. # export:some/file -> Force the download of the file
  592. # Forum messages:
  593. # message#1218 -> Link to message with id 1218
  594. #
  595. # Links can refer other objects from other projects, using project identifier:
  596. # identifier:r52
  597. # identifier:document:"Some document"
  598. # identifier:version:1.0.0
  599. # identifier:source:some/file
  600. def parse_redmine_links(text, default_project, obj, attr, only_path, options)
  601. text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
  602. leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $18, $14 || $19, $15, $17
  603. link = nil
  604. project = default_project
  605. if project_identifier
  606. project = Project.visible.find_by_identifier(project_identifier)
  607. end
  608. if esc.nil?
  609. if prefix.nil? && sep == 'r'
  610. if project
  611. repository = nil
  612. if repo_identifier
  613. repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
  614. else
  615. repository = project.repository
  616. end
  617. # project.changesets.visible raises an SQL error because of a double join on repositories
  618. if repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(repository.id, identifier))
  619. link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.revision},
  620. :class => 'changeset',
  621. :title => truncate_single_line(changeset.comments, :length => 100))
  622. end
  623. end
  624. elsif sep == '#'
  625. oid = identifier.to_i
  626. case prefix
  627. when nil
  628. if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid, :include => :status)
  629. anchor = comment_id ? "note-#{comment_id}" : nil
  630. link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor},
  631. :class => issue.css_classes,
  632. :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
  633. end
  634. when 'document'
  635. if document = Document.visible.find_by_id(oid)
  636. link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
  637. :class => 'document'
  638. end
  639. when 'version'
  640. if version = Version.visible.find_by_id(oid)
  641. link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
  642. :class => 'version'
  643. end
  644. when 'message'
  645. if message = Message.visible.find_by_id(oid, :include => :parent)
  646. link = link_to_message(message, {:only_path => only_path}, :class => 'message')
  647. end
  648. when 'forum'
  649. if board = Board.visible.find_by_id(oid)
  650. link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
  651. :class => 'board'
  652. end
  653. when 'news'
  654. if news = News.visible.find_by_id(oid)
  655. link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
  656. :class => 'news'
  657. end
  658. when 'project'
  659. if p = Project.visible.find_by_id(oid)
  660. link = link_to_project(p, {:only_path => only_path}, :class => 'project')
  661. end
  662. end
  663. elsif sep == ':'
  664. # removes the double quotes if any
  665. name = identifier.gsub(%r{^"(.*)"$}, "\\1")
  666. case prefix
  667. when 'document'
  668. if project && document = project.documents.visible.find_by_title(name)
  669. link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
  670. :class => 'document'
  671. end
  672. when 'version'
  673. if project && version = project.versions.visible.find_by_name(name)
  674. link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
  675. :class => 'version'
  676. end
  677. when 'forum'
  678. if project && board = project.boards.visible.find_by_name(name)
  679. link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
  680. :class => 'board'
  681. end
  682. when 'news'
  683. if project && news = project.news.visible.find_by_title(name)
  684. link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
  685. :class => 'news'
  686. end
  687. when 'commit', 'source', 'export'
  688. if project
  689. repository = nil
  690. if name =~ %r{^(([a-z0-9\-]+)\|)(.+)$}
  691. repo_prefix, repo_identifier, name = $1, $2, $3
  692. repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
  693. else
  694. repository = project.repository
  695. end
  696. if prefix == 'commit'
  697. if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
  698. link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
  699. :class => 'changeset',
  700. :title => truncate_single_line(h(changeset.comments), :length => 100)
  701. end
  702. else
  703. if repository && User.current.allowed_to?(:browse_repository, project)
  704. name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$}
  705. path, rev, anchor = $1, $3, $5
  706. link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param,
  707. :path => to_path_param(path),
  708. :rev => rev,
  709. :anchor => anchor},
  710. :class => (prefix == 'export' ? 'source download' : 'source')
  711. end
  712. end
  713. repo_prefix = nil
  714. end
  715. when 'attachment'
  716. attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
  717. if attachments && attachment = Attachment.latest_attach(attachments, name)
  718. link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
  719. end
  720. when 'project'
  721. if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
  722. link = link_to_project(p, {:only_path => only_path}, :class => 'project')
  723. end
  724. end
  725. end
  726. end
  727. (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
  728. end
  729. end
  730. HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
  731. def parse_sections(text, project, obj, attr, only_path, options)
  732. return unless options[:edit_section_links]
  733. text.gsub!(HEADING_RE) do
  734. heading = $1
  735. @current_section += 1
  736. if @current_section > 1
  737. content_tag('div',
  738. link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)),
  739. :class => 'contextual',
  740. :title => l(:button_edit_section)) + heading.html_safe
  741. else
  742. heading
  743. end
  744. end
  745. end
  746. # Headings and TOC
  747. # Adds ids and links to headings unless options[:headings] is set to false
  748. def parse_headings(text, project, obj, attr, only_path, options)
  749. return if options[:headings] == false
  750. text.gsub!(HEADING_RE) do
  751. level, attrs, content = $2.to_i, $3, $4
  752. item = strip_tags(content).strip
  753. anchor = sanitize_anchor_name(item)
  754. # used for single-file wiki export
  755. anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
  756. @heading_anchors[anchor] ||= 0
  757. idx = (@heading_anchors[anchor] += 1)
  758. if idx > 1
  759. anchor = "#{anchor}-#{idx}"
  760. end
  761. @parsed_headings << [level, anchor, item]
  762. "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
  763. end
  764. end
  765. MACROS_RE = /(
  766. (!)? # escaping
  767. (
  768. \{\{ # opening tag
  769. ([\w]+) # macro name
  770. (\(([^\n\r]*?)\))? # optional arguments
  771. ([\n\r].*?[\n\r])? # optional block of text
  772. \}\} # closing tag
  773. )
  774. )/mx unless const_defined?(:MACROS_RE)
  775. MACRO_SUB_RE = /(
  776. \{\{
  777. macro\((\d+)\)
  778. \}\}
  779. )/x unless const_defined?(:MACRO_SUB_RE)
  780. # Extracts macros from text
  781. def catch_macros(text)
  782. macros = {}
  783. text.gsub!(MACROS_RE) do
  784. all, macro = $1, $4.downcase
  785. if macro_exists?(macro) || all =~ MACRO_SUB_RE
  786. index = macros.size
  787. macros[index] = all
  788. "{{macro(#{index})}}"
  789. else
  790. all
  791. end
  792. end
  793. macros
  794. end
  795. # Executes and replaces macros in text
  796. def inject_macros(text, obj, macros, execute=true)
  797. text.gsub!(MACRO_SUB_RE) do
  798. all, index = $1, $2.to_i
  799. orig = macros.delete(index)
  800. if execute && orig && orig =~ MACROS_RE
  801. esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip)
  802. if esc.nil?
  803. h(exec_macro(macro, obj, args, block) || all)
  804. else
  805. h(all)
  806. end
  807. elsif orig
  808. h(orig)
  809. else
  810. h(all)
  811. end
  812. end
  813. end
  814. TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
  815. # Renders the TOC with given headings
  816. def replace_toc(text, headings)
  817. text.gsub!(TOC_RE) do
  818. # Keep only the 4 first levels
  819. headings = headings.select{|level, anchor, item| level <= 4}
  820. if headings.empty?
  821. ''
  822. else
  823. div_class = 'toc'
  824. div_class << ' right' if $1 == '>'
  825. div_class << ' left' if $1 == '<'
  826. out = "<ul class=\"#{div_class}\"><li>"
  827. root = headings.map(&:first).min
  828. current = root
  829. started = false
  830. headings.each do |level, anchor, item|
  831. if level > current
  832. out << '<ul><li>' * (level - current)
  833. elsif level < current
  834. out << "</li></ul>\n" * (current - level) + "</li><li>"
  835. elsif started
  836. out << '</li><li>'
  837. end
  838. out << "<a href=\"##{anchor}\">#{item}</a>"
  839. current = level
  840. started = true
  841. end
  842. out << '</li></ul>' * (current - root)
  843. out << '</li></ul>'
  844. end
  845. end
  846. end
  847. # Same as Rails' simple_format helper without using paragraphs
  848. def simple_format_without_paragraph(text)
  849. text.to_s.
  850. gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
  851. gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
  852. gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
  853. html_safe
  854. end
  855. def lang_options_for_select(blank=true)
  856. (blank ? [["(auto)", ""]] : []) + languages_options
  857. end
  858. def label_tag_for(name, option_tags = nil, options = {})
  859. label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
  860. content_tag("label", label_text)
  861. end
  862. def labelled_form_for(*args, &proc)
  863. args << {} unless args.last.is_a?(Hash)
  864. options = args.last
  865. if args.first.is_a?(Symbol)
  866. options.merge!(:as => args.shift)
  867. end
  868. options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
  869. form_for(*args, &proc)
  870. end
  871. def labelled_fields_for(*args, &proc)
  872. args << {} unless args.last.is_a?(Hash)
  873. options = args.last
  874. options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
  875. fields_for(*args, &proc)
  876. end
  877. def labelled_remote_form_for(*args, &proc)
  878. ActiveSupport::Deprecation.warn "ApplicationHelper#labelled_remote_form_for is deprecated and will be removed in Redmine 2.2."
  879. args << {} unless args.last.is_a?(Hash)
  880. options = args.last
  881. options.merge!({:builder => Redmine::Views::LabelledFormBuilder, :remote => true})
  882. form_for(*args, &proc)
  883. end
  884. def error_messages_for(*objects)
  885. html = ""
  886. objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
  887. errors = objects.map {|o| o.errors.full_messages}.flatten
  888. if errors.any?
  889. html << "<div id='errorExplanation'><ul>\n"
  890. errors.each do |error|
  891. html << "<li>#{h error}</li>\n"
  892. end
  893. html << "</ul></div>\n"
  894. end
  895. html.html_safe
  896. end
  897. def delete_link(url, options={})
  898. options = {
  899. :method => :delete,
  900. :data => {:confirm => l(:text_are_you_sure)},
  901. :class => 'icon icon-del'
  902. }.merge(options)
  903. link_to l(:button_delete), url, options
  904. end
  905. def preview_link(url, form, target='preview', options={})
  906. content_tag 'a', l(:label_preview), {
  907. :href => "#",
  908. :onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|,
  909. :accesskey => accesskey(:preview)
  910. }.merge(options)
  911. end
  912. def link_to_function(name, function, html_options={})
  913. content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
  914. end
  915. # Helper to render JSON in views
  916. def raw_json(arg)
  917. arg.to_json.to_s.gsub('/', '\/').html_safe
  918. end
  919. def back_url
  920. url = params[:back_url]
  921. if url.nil? && referer = request.env['HTTP_REFERER']
  922. url = CGI.unescape(referer.to_s)
  923. end
  924. url
  925. end
  926. def back_url_hidden_field_tag
  927. url = back_url
  928. hidden_field_tag('back_url', url, :id => nil) unless url.blank?
  929. end
  930. def check_all_links(form_name)
  931. link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
  932. " | ".html_safe +
  933. link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
  934. end
  935. def progress_bar(pcts, options={})
  936. pcts = [pcts, pcts] unless pcts.is_a?(Array)
  937. pcts = pcts.collect(&:round)
  938. pcts[1] = pcts[1] - pcts[0]
  939. pcts << (100 - pcts[1] - pcts[0])
  940. width = options[:width] || '100px;'
  941. legend = options[:legend] || ''
  942. content_tag('table',
  943. content_tag('tr',
  944. (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) +
  945. (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) +
  946. (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe)
  947. ), :class => 'progress', :style => "width: #{width};").html_safe +
  948. content_tag('p', legend, :class => 'percent').html_safe
  949. end
  950. def checked_image(checked=true)
  951. if checked
  952. image_tag 'toggle_check.png'
  953. end
  954. end
  955. def context_menu(url)
  956. unless @context_menu_included
  957. content_for :header_tags do
  958. javascript_include_tag('context_menu') +
  959. stylesheet_link_tag('context_menu')
  960. end
  961. if l(:direction) == 'rtl'
  962. content_for :header_tags do
  963. stylesheet_link_tag('context_menu_rtl')
  964. end
  965. end
  966. @context_menu_included = true
  967. end
  968. javascript_tag "contextMenuInit('#{ url_for(url) }')"
  969. end
  970. def calendar_for(field_id)
  971. include_calendar_headers_tags
  972. javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });")
  973. end
  974. def include_calendar_headers_tags
  975. unless @calendar_headers_tags_included
  976. @calendar_headers_tags_included = true
  977. content_for :header_tags do
  978. start_of_week = Setting.start_of_week
  979. start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
  980. # Redmine uses 1..7 (monday..sunday) in settings and locales
  981. # JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
  982. start_of_week = start_of_week.to_i % 7
  983. tags = javascript_tag(
  984. "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
  985. "showOn: 'button', buttonImageOnly: true, buttonImage: '" +
  986. path_to_image('/images/calendar.png') +
  987. "', showButtonPanel: true};")
  988. jquery_locale = l('jquery.locale', :default => current_language.to_s)
  989. unless jquery_locale == 'en'
  990. tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js")
  991. end
  992. tags
  993. end
  994. end
  995. end
  996. # Overrides Rails' stylesheet_link_tag with themes and plugins support.
  997. # Examples:
  998. # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults
  999. # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets
  1000. #
  1001. def stylesheet_link_tag(*sources)
  1002. options = sources.last.is_a?(Hash) ? sources.pop : {}
  1003. plugin = options.delete(:plugin)
  1004. sources = sources.map do |source|
  1005. if plugin
  1006. "/plugin_assets/#{plugin}/stylesheets/#{source}"
  1007. elsif current_theme && current_theme.stylesheets.include?(source)
  1008. current_theme.stylesheet_path(source)
  1009. else
  1010. source
  1011. end
  1012. end
  1013. super sources, options
  1014. end
  1015. # Overrides Rails' image_tag with themes and plugins support.
  1016. # Examples:
  1017. # image_tag('image.png') # => picks image.png from the current theme or defaults
  1018. # image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
  1019. #
  1020. def image_tag(source, options={})
  1021. if plugin = options.delete(:plugin)
  1022. source = "/plugin_assets/#{plugin}/images/#{source}"
  1023. elsif current_theme && current_theme.images.include?(source)
  1024. source = current_theme.image_path(source)
  1025. end
  1026. super source, options
  1027. end
  1028. # Overrides Rails' javascript_include_tag with plugins support
  1029. # Examples:
  1030. # javascript_include_tag('scripts') # => picks scripts.js from defaults
  1031. # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets
  1032. #
  1033. def javascript_include_tag(*sources)
  1034. options = sources.last.is_a?(Hash) ? sources.pop : {}
  1035. if plugin = options.delete(:plugin)
  1036. sources = sources.map do |source|
  1037. if plugin
  1038. "/plugin_assets/#{plugin}/javascripts/#{source}"
  1039. else
  1040. source
  1041. end
  1042. end
  1043. end
  1044. super sources, options
  1045. end
  1046. def content_for(name, content = nil, &block)
  1047. @has_content ||= {}
  1048. @has_content[name] = true
  1049. super(name, content, &block)
  1050. end
  1051. def has_content?(name)
  1052. (@has_content && @has_content[name]) || false
  1053. end
  1054. def sidebar_content?
  1055. has_content?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
  1056. end
  1057. def view_layouts_base_sidebar_hook_response
  1058. @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
  1059. end
  1060. def email_delivery_enabled?
  1061. !!ActionMailer::Base.perform_deliveries
  1062. end
  1063. # Returns the avatar image tag for the given +user+ if avatars are enabled
  1064. # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
  1065. def avatar(user, options = { })
  1066. if Setting.gravatar_enabled?
  1067. options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default})
  1068. email = nil
  1069. if user.respond_to?(:mail)
  1070. email = user.mail
  1071. elsif user.to_s =~ %r{<(.+?)>}
  1072. email = $1
  1073. end
  1074. return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
  1075. else
  1076. ''
  1077. end
  1078. end
  1079. def sanitize_anchor_name(anchor)
  1080. if ''.respond_to?(:encoding) || RUBY_PLATFORM == 'java'
  1081. anchor.gsub(%r{[^\p{Word}\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
  1082. else
  1083. # TODO: remove when ruby1.8 is no longer supported
  1084. anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
  1085. end
  1086. end
  1087. # Returns the javascript tags that are included in the html layout head
  1088. def javascript_heads
  1089. tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application')
  1090. unless User.current.pref.warn_on_leaving_unsaved == '0'
  1091. tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
  1092. end
  1093. tags
  1094. end
  1095. def favicon
  1096. "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />".html_safe
  1097. end
  1098. def robot_exclusion_tag
  1099. '<meta name="robots" content="noindex,follow,noarchive" />'.html_safe
  1100. end
  1101. # Returns true if arg is expected in the API response
  1102. def include_in_api_response?(arg)
  1103. unless @included_in_api_response
  1104. param = params[:include]
  1105. @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
  1106. @included_in_api_response.collect!(&:strip)
  1107. end
  1108. @included_in_api_response.include?(arg.to_s)
  1109. end
  1110. # Returns options or nil if nometa param or X-Redmine-Nometa header
  1111. # was set in the request
  1112. def api_meta(options)
  1113. if params[:nometa].present? || request.headers['X-Redmine-Nometa']
  1114. # compatibility mode for activeresource clients that raise
  1115. # an error when unserializing an array with attributes
  1116. nil
  1117. else
  1118. options
  1119. end
  1120. end
  1121. private
  1122. def wiki_helper
  1123. helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
  1124. extend helper
  1125. return self
  1126. end
  1127. def link_to_content_update(text, url_params = {}, html_options = {})
  1128. link_to(text, url_params, html_options)
  1129. end
  1130. end