You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

application_helper.rb 64KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require 'forwardable'
  19. require 'cgi'
  20. module ApplicationHelper
  21. include Redmine::WikiFormatting::Macros::Definitions
  22. include Redmine::I18n
  23. include Redmine::Pagination::Helper
  24. include Redmine::SudoMode::Helper
  25. include Redmine::Themes::Helper
  26. include Redmine::Hook::Helper
  27. include Redmine::Helpers::URL
  28. extend Forwardable
  29. def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
  30. # Return true if user is authorized for controller/action, otherwise false
  31. def authorize_for(controller, action)
  32. User.current.allowed_to?({:controller => controller, :action => action}, @project)
  33. end
  34. # Display a link if user is authorized
  35. #
  36. # @param [String] name Anchor text (passed to link_to)
  37. # @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
  38. # @param [optional, Hash] html_options Options passed to link_to
  39. # @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
  40. def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
  41. if authorize_for(options[:controller] || params[:controller], options[:action])
  42. link_to(name, options, html_options, *parameters_for_method_reference)
  43. end
  44. end
  45. # Displays a link to user's account page if active
  46. def link_to_user(user, options={})
  47. user.is_a?(User) ? link_to_principal(user, options) : h(user.to_s)
  48. end
  49. # Displays a link to user's account page or group page
  50. def link_to_principal(principal, options={})
  51. only_path = options[:only_path].nil? ? true : options[:only_path]
  52. case principal
  53. when User
  54. name = h(principal.name(options[:format]))
  55. css_classes = ''
  56. if principal.active? || (User.current.admin? && principal.logged?)
  57. url = user_url(principal, :only_path => only_path)
  58. css_classes += principal.css_classes
  59. end
  60. when Group
  61. name = h(principal.to_s)
  62. url = group_url(principal, :only_path => only_path)
  63. css_classes = principal.css_classes
  64. else
  65. name = h(principal.to_s)
  66. end
  67. css_classes += " #{options[:class]}" if css_classes && options[:class].present?
  68. url ? link_to(name, url, :class => css_classes) : name
  69. end
  70. # Displays a link to edit group page if current user is admin
  71. # Otherwise display only the group name
  72. def link_to_group(group, options={})
  73. if group.is_a?(Group)
  74. name = h(group.name)
  75. if User.current.admin?
  76. only_path = options[:only_path].nil? ? true : options[:only_path]
  77. link_to name, edit_group_path(group, :only_path => only_path)
  78. else
  79. name
  80. end
  81. end
  82. end
  83. # Displays a link to +issue+ with its subject.
  84. # Examples:
  85. #
  86. # link_to_issue(issue) # => Defect #6: This is the subject
  87. # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
  88. # link_to_issue(issue, :subject => false) # => Defect #6
  89. # link_to_issue(issue, :project => true) # => Foo - Defect #6
  90. # link_to_issue(issue, :subject => false, :tracker => false) # => #6
  91. #
  92. def link_to_issue(issue, options={})
  93. title = nil
  94. subject = nil
  95. text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}"
  96. if options[:subject] == false
  97. title = issue.subject.truncate(60)
  98. else
  99. subject = issue.subject
  100. if truncate_length = options[:truncate]
  101. subject = subject.truncate(truncate_length)
  102. end
  103. end
  104. only_path = options[:only_path].nil? ? true : options[:only_path]
  105. s = link_to(text, issue_url(issue, :only_path => only_path),
  106. :class => issue.css_classes, :title => title)
  107. s << h(": #{subject}") if subject
  108. s = h("#{issue.project} - ") + s if options[:project]
  109. s
  110. end
  111. # Generates a link to an attachment.
  112. # Options:
  113. # * :text - Link text (default to attachment filename)
  114. # * :download - Force download (default: false)
  115. def link_to_attachment(attachment, options={})
  116. text = options.delete(:text) || attachment.filename
  117. if options.delete(:download)
  118. route_method = :download_named_attachment_url
  119. options[:filename] = attachment.filename
  120. else
  121. route_method = :attachment_url
  122. # make sure we don't have an extraneous :filename in the options
  123. options.delete(:filename)
  124. end
  125. html_options = options.slice!(:only_path, :filename)
  126. options[:only_path] = true unless options.key?(:only_path)
  127. url = send(route_method, attachment, options)
  128. link_to text, url, html_options
  129. end
  130. # Generates a link to a SCM revision
  131. # Options:
  132. # * :text - Link text (default to the formatted revision)
  133. def link_to_revision(revision, repository, options={})
  134. if repository.is_a?(Project)
  135. repository = repository.repository
  136. end
  137. text = options.delete(:text) || format_revision(revision)
  138. rev = revision.respond_to?(:identifier) ? revision.identifier : revision
  139. link_to(
  140. h(text),
  141. {:controller => 'repositories', :action => 'revision',
  142. :id => repository.project,
  143. :repository_id => repository.identifier_param, :rev => rev},
  144. :title => l(:label_revision_id, format_revision(revision)),
  145. :accesskey => options[:accesskey]
  146. )
  147. end
  148. # Generates a link to a message
  149. def link_to_message(message, options={}, html_options = nil)
  150. link_to(
  151. message.subject.truncate(60),
  152. board_message_url(message.board_id, message.parent_id || message.id, {
  153. :r => (message.parent_id && message.id),
  154. :anchor => (message.parent_id ? "message-#{message.id}" : nil),
  155. :only_path => true
  156. }.merge(options)),
  157. html_options
  158. )
  159. end
  160. # Generates a link to a project if active
  161. # Examples:
  162. #
  163. # link_to_project(project) # => link to the specified project overview
  164. # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
  165. # link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
  166. #
  167. def link_to_project(project, options={}, html_options = nil)
  168. if project.archived?
  169. h(project.name)
  170. else
  171. link_to project.name,
  172. project_url(project, {:only_path => true}.merge(options)),
  173. html_options
  174. end
  175. end
  176. # Generates a link to a project settings if active
  177. def link_to_project_settings(project, options={}, html_options=nil)
  178. if project.active?
  179. link_to project.name, settings_project_path(project, options), html_options
  180. elsif project.archived?
  181. h(project.name)
  182. else
  183. link_to project.name, project_path(project, options), html_options
  184. end
  185. end
  186. # Generates a link to a version
  187. def link_to_version(version, options = {})
  188. return '' unless version && version.is_a?(Version)
  189. options = {:title => format_date(version.effective_date)}.merge(options)
  190. link_to_if version.visible?, format_version_name(version), version_path(version), options
  191. end
  192. RECORD_LINK = {
  193. 'CustomValue' => lambda {|custom_value| link_to_record(custom_value.customized)},
  194. 'Document' => lambda {|document| link_to(document.title, document_path(document))},
  195. 'Group' => lambda {|group| link_to(group.name, group_path(group))},
  196. 'Issue' => lambda {|issue| link_to_issue(issue, :subject => false)},
  197. 'Message' => lambda {|message| link_to_message(message)},
  198. 'News' => lambda {|news| link_to(news.title, news_path(news))},
  199. 'Project' => lambda {|project| link_to_project(project)},
  200. 'User' => lambda {|user| link_to_user(user)},
  201. 'Version' => lambda {|version| link_to_version(version)},
  202. 'WikiPage' =>
  203. lambda do |wiki_page|
  204. link_to(
  205. wiki_page.pretty_title,
  206. project_wiki_page_path(wiki_page.project, wiki_page.title)
  207. )
  208. end
  209. }
  210. def link_to_record(record)
  211. if link = RECORD_LINK[record.class.name]
  212. self.instance_exec(record, &link)
  213. end
  214. end
  215. ATTACHMENT_CONTAINER_LINK = {
  216. # Custom list, since project/version attachments are listed in the files
  217. # view and not in the project/milestone view
  218. 'Project' =>
  219. lambda {|project| link_to(l(:project_module_files), project_files_path(project))},
  220. 'Version' =>
  221. lambda {|version| link_to(l(:project_module_files), project_files_path(version.project))},
  222. }
  223. def link_to_attachment_container(attachment_container)
  224. if link = ATTACHMENT_CONTAINER_LINK[attachment_container.class.name] ||
  225. RECORD_LINK[attachment_container.class.name]
  226. self.instance_exec(attachment_container, &link)
  227. end
  228. end
  229. # Helper that formats object for html or text rendering
  230. def format_object(object, html=true, &block)
  231. if block_given?
  232. object = yield object
  233. end
  234. case object.class.name
  235. when 'Array'
  236. formatted_objects = object.map {|o| format_object(o, html)}
  237. html ? safe_join(formatted_objects, ', ') : formatted_objects.join(', ')
  238. when 'Time'
  239. format_time(object)
  240. when 'Date'
  241. format_date(object)
  242. when 'Fixnum'
  243. object.to_s
  244. when 'Float'
  245. sprintf "%.2f", object
  246. when 'User', 'Group'
  247. html ? link_to_principal(object) : object.to_s
  248. when 'Project'
  249. html ? link_to_project(object) : object.to_s
  250. when 'Version'
  251. html ? link_to_version(object) : object.to_s
  252. when 'TrueClass'
  253. l(:general_text_Yes)
  254. when 'FalseClass'
  255. l(:general_text_No)
  256. when 'Issue'
  257. object.visible? && html ? link_to_issue(object) : "##{object.id}"
  258. when 'Attachment'
  259. if html
  260. content_tag(
  261. :span,
  262. link_to_attachment(object) +
  263. link_to_attachment(
  264. object,
  265. :class => ['icon-only', 'icon-download'],
  266. :title => l(:button_download),
  267. :download => true
  268. )
  269. )
  270. else
  271. object.filename
  272. end
  273. when 'CustomValue', 'CustomFieldValue'
  274. if object.custom_field
  275. f = object.custom_field.format.formatted_custom_value(self, object, html)
  276. if f.nil? || f.is_a?(String)
  277. f
  278. else
  279. format_object(f, html, &block)
  280. end
  281. else
  282. object.value.to_s
  283. end
  284. else
  285. html ? h(object) : object.to_s
  286. end
  287. end
  288. def wiki_page_path(page, options={})
  289. url_for({:controller => 'wiki', :action => 'show', :project_id => page.project,
  290. :id => page.title}.merge(options))
  291. end
  292. def thumbnail_tag(attachment)
  293. thumbnail_size = Setting.thumbnails_size.to_i
  294. link_to(
  295. image_tag(
  296. thumbnail_path(attachment),
  297. :srcset => "#{thumbnail_path(attachment, :size => thumbnail_size * 2)} 2x",
  298. :style => "max-width: #{thumbnail_size}px; max-height: #{thumbnail_size}px;",
  299. :loading => "lazy"
  300. ),
  301. attachment_path(
  302. attachment
  303. ),
  304. :title => attachment.filename
  305. )
  306. end
  307. def toggle_link(name, id, options={})
  308. onclick = +"$('##{id}').toggle(); "
  309. onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
  310. onclick << "$(window).scrollTop($('##{options[:focus]}').position().top); " if options[:scroll]
  311. onclick << "return false;"
  312. link_to(name, "#", :onclick => onclick)
  313. end
  314. def link_to_previous_month(year, month, options={})
  315. target_year, target_month = if month == 1
  316. [year - 1, 12]
  317. else
  318. [year, month - 1]
  319. end
  320. name = if target_month == 12
  321. "#{month_name(target_month)} #{target_year}"
  322. else
  323. month_name(target_month)
  324. end
  325. link_to_month(("« " + name), target_year, target_month, options)
  326. end
  327. def link_to_next_month(year, month, options={})
  328. target_year, target_month = if month == 12
  329. [year + 1, 1]
  330. else
  331. [year, month + 1]
  332. end
  333. name = if target_month == 1
  334. "#{month_name(target_month)} #{target_year}"
  335. else
  336. month_name(target_month)
  337. end
  338. link_to_month((name + " »"), target_year, target_month, options)
  339. end
  340. def link_to_month(link_name, year, month, options={})
  341. link_to(link_name, {:params => request.query_parameters.merge(:year => year, :month => month)}, options)
  342. end
  343. # Used to format item titles on the activity view
  344. def format_activity_title(text)
  345. text
  346. end
  347. def format_activity_day(date)
  348. date == User.current.today ? l(:label_today).titleize : format_date(date)
  349. end
  350. def format_activity_description(text)
  351. h(text.to_s.truncate(120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).
  352. gsub(/[\r\n]+/, "<br />").html_safe
  353. end
  354. def format_version_name(version)
  355. if version.project == @project
  356. h(version)
  357. else
  358. h("#{version.project} - #{version}")
  359. end
  360. end
  361. def format_changeset_comments(changeset, options={})
  362. method = options[:short] ? :short_comments : :comments
  363. textilizable changeset, method, :formatting => Setting.commit_logs_formatting?
  364. end
  365. def due_date_distance_in_words(date)
  366. if date
  367. l((if date < User.current.today
  368. :label_roadmap_overdue
  369. else
  370. :label_roadmap_due_in
  371. end),
  372. distance_of_date_in_words(User.current.today, date))
  373. end
  374. end
  375. # Renders a tree of projects as a nested set of unordered lists
  376. # The given collection may be a subset of the whole project tree
  377. # (eg. some intermediate nodes are private and can not be seen)
  378. def render_project_nested_lists(projects, &block)
  379. s = +''
  380. if projects.any?
  381. ancestors = []
  382. original_project = @project
  383. projects.sort_by(&:lft).each do |project|
  384. # set the project environment to please macros.
  385. @project = project
  386. if ancestors.empty? || project.is_descendant_of?(ancestors.last)
  387. s << "<ul class='projects #{ancestors.empty? ? 'root' : nil}'>\n"
  388. else
  389. ancestors.pop
  390. s << "</li>"
  391. while ancestors.any? && !project.is_descendant_of?(ancestors.last)
  392. ancestors.pop
  393. s << "</ul></li>\n"
  394. end
  395. end
  396. classes = (ancestors.empty? ? 'root' : 'child')
  397. classes += ' archived' if project.archived?
  398. s << "<li class='#{classes}'><div class='#{classes}'>"
  399. s << h(block_given? ? capture(project, &block) : project.name)
  400. s << "</div>\n"
  401. ancestors << project
  402. end
  403. s << ("</li></ul>\n" * ancestors.size)
  404. @project = original_project
  405. end
  406. s.html_safe
  407. end
  408. def render_page_hierarchy(pages, node=nil, options={})
  409. content = +''
  410. if pages[node]
  411. content << "<ul class=\"pages-hierarchy\">\n"
  412. pages[node].each do |page|
  413. content << "<li>"
  414. if controller.controller_name == 'wiki' && controller.action_name == 'export'
  415. href = "##{page.title}"
  416. else
  417. href = {:controller => 'wiki', :action => 'show',
  418. :project_id => page.project, :id => page.title, :version => nil}
  419. end
  420. content <<
  421. link_to(
  422. h(page.pretty_title),
  423. href,
  424. :title => (if options[:timestamp] && page.updated_on
  425. l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on))
  426. else
  427. nil
  428. end)
  429. )
  430. content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
  431. content << "</li>\n"
  432. end
  433. content << "</ul>\n"
  434. end
  435. content.html_safe
  436. end
  437. # Renders flash messages
  438. def render_flash_messages
  439. s = +''
  440. flash.each do |k, v|
  441. s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
  442. end
  443. s.html_safe
  444. end
  445. # Renders tabs and their content
  446. def render_tabs(tabs, selected=params[:tab])
  447. if tabs.any?
  448. unless tabs.detect {|tab| tab[:name] == selected}
  449. selected = nil
  450. end
  451. selected ||= tabs.first[:name]
  452. render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected}
  453. else
  454. content_tag 'p', l(:label_no_data), :class => "nodata"
  455. end
  456. end
  457. # Returns the tab action depending on the tab properties
  458. def get_tab_action(tab)
  459. if tab[:onclick]
  460. return tab[:onclick]
  461. elsif tab[:partial]
  462. return "showTab('#{tab[:name]}', this.href)"
  463. else
  464. return nil
  465. end
  466. end
  467. # Returns the default scope for the quick search form
  468. # Could be 'all', 'my_projects', 'subprojects' or nil (current project)
  469. def default_search_project_scope
  470. if @project && !@project.leaf?
  471. 'subprojects'
  472. end
  473. end
  474. # Returns an array of projects that are displayed in the quick-jump box
  475. def projects_for_jump_box(user=User.current)
  476. if user.logged?
  477. user.projects.active.select(:id, :name, :identifier, :lft, :rgt).to_a
  478. else
  479. []
  480. end
  481. end
  482. def render_projects_for_jump_box(projects, selected: nil, query: nil)
  483. if query.blank?
  484. jump_box = Redmine::ProjectJumpBox.new User.current
  485. bookmarked = jump_box.bookmarked_projects
  486. recents = jump_box.recently_used_projects
  487. projects_label = :label_project_all
  488. else
  489. projects_label = :label_result_plural
  490. end
  491. jump = params[:jump].presence || current_menu_item
  492. s = (+'').html_safe
  493. build_project_link = lambda do |project, level = 0|
  494. padding = level * 16
  495. text = content_tag('span', project.name, :style => "padding-left:#{padding}px;")
  496. s << link_to(text, project_path(project, :jump => jump),
  497. :title => project.name,
  498. :class => (project == selected ? 'selected' : nil))
  499. end
  500. [
  501. [bookmarked, :label_optgroup_bookmarks, true],
  502. [recents, :label_optgroup_recents, false],
  503. [projects, projects_label, true]
  504. ].each do |projects, label, is_tree|
  505. next if projects.blank?
  506. s << content_tag(:strong, l(label))
  507. if is_tree
  508. project_tree(projects, &build_project_link)
  509. else
  510. # we do not want to render recently used projects as a tree, but in the
  511. # order they were used (most recent first)
  512. projects.each(&build_project_link)
  513. end
  514. end
  515. s
  516. end
  517. # Renders the project quick-jump box
  518. def render_project_jump_box
  519. projects = projects_for_jump_box(User.current)
  520. if @project && @project.persisted?
  521. text = @project.name_was
  522. end
  523. text ||= l(:label_jump_to_a_project)
  524. url = autocomplete_projects_path(:format => 'js', :jump => current_menu_item)
  525. trigger = content_tag('span', text, :class => 'drdn-trigger')
  526. q = text_field_tag('q', '', :id => 'projects-quick-search',
  527. :class => 'autocomplete',
  528. :data => {:automcomplete_url => url},
  529. :autocomplete => 'off')
  530. all = link_to(l(:label_project_all), projects_path(:jump => current_menu_item),
  531. :class => (@project.nil? && controller.class.main_menu ? 'selected' : nil))
  532. content =
  533. content_tag('div',
  534. content_tag('div', q, :class => 'quick-search') +
  535. content_tag('div', render_projects_for_jump_box(projects, selected: @project),
  536. :class => 'drdn-items projects selection') +
  537. content_tag('div', all, :class => 'drdn-items all-projects selection'),
  538. :class => 'drdn-content')
  539. content_tag('div', trigger + content, :id => "project-jump", :class => "drdn")
  540. end
  541. def project_tree_options_for_select(projects, options = {})
  542. s = ''.html_safe
  543. if blank_text = options[:include_blank]
  544. if blank_text == true
  545. blank_text = '&nbsp;'.html_safe
  546. end
  547. s << content_tag('option', blank_text, :value => '')
  548. end
  549. project_tree(projects) do |project, level|
  550. name_prefix = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
  551. tag_options = {:value => project.id}
  552. if project == options[:selected] || (options[:selected].respond_to?(:include?) &&
  553. options[:selected].include?(project))
  554. tag_options[:selected] = 'selected'
  555. else
  556. tag_options[:selected] = nil
  557. end
  558. tag_options.merge!(yield(project)) if block_given?
  559. s << content_tag('option', name_prefix + h(project), tag_options)
  560. end
  561. s.html_safe
  562. end
  563. # Yields the given block for each project with its level in the tree
  564. #
  565. # Wrapper for Project#project_tree
  566. def project_tree(projects, options={}, &block)
  567. Project.project_tree(projects, options, &block)
  568. end
  569. def principals_check_box_tags(name, principals)
  570. s = +''
  571. principals.each do |principal|
  572. s <<
  573. content_tag(
  574. 'label',
  575. check_box_tag(name, principal.id, false, :id => nil) +
  576. (avatar(principal, :size => 16).presence ||
  577. content_tag(
  578. 'span', nil,
  579. :class => "name icon icon-#{principal.class.name.downcase}"
  580. )
  581. ) + principal
  582. )
  583. end
  584. s.html_safe
  585. end
  586. # Returns a string for users/groups option tags
  587. def principals_options_for_select(collection, selected=nil)
  588. s = +''
  589. if collection.include?(User.current)
  590. s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
  591. end
  592. groups = +''
  593. collection.sort.each do |element|
  594. if option_value_selected?(element, selected) || element.id.to_s == selected
  595. selected_attribute = ' selected="selected"'
  596. end
  597. (element.is_a?(Group) ? groups : s) <<
  598. %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
  599. end
  600. unless groups.empty?
  601. s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
  602. end
  603. s.html_safe
  604. end
  605. def option_tag(name, text, value, selected=nil, options={})
  606. content_tag 'option', value, options.merge(:value => value, :selected => (value == selected))
  607. end
  608. def truncate_single_line_raw(string, length)
  609. string.to_s.truncate(length).gsub(%r{[\r\n]+}m, ' ')
  610. end
  611. # Truncates at line break after 250 characters or options[:length]
  612. def truncate_lines(string, options={})
  613. length = options[:length] || 250
  614. if string.to_s =~ /\A(.{#{length}}.*?)$/m
  615. "#{$1}..."
  616. else
  617. string
  618. end
  619. end
  620. def anchor(text)
  621. text.to_s.tr(' ', '_')
  622. end
  623. def html_hours(text)
  624. text.gsub(
  625. %r{(\d+)([\.:])(\d+)},
  626. '<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>'
  627. ).html_safe
  628. end
  629. def authoring(created, author, options={})
  630. l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
  631. end
  632. def time_tag(time)
  633. text = distance_of_time_in_words(Time.now, time)
  634. if @project
  635. link_to(text,
  636. project_activity_path(@project, :from => User.current.time_to_date(time)),
  637. :title => format_time(time))
  638. else
  639. content_tag('abbr', text, :title => format_time(time))
  640. end
  641. end
  642. def syntax_highlight_lines(name, content)
  643. syntax_highlight(name, content).each_line.to_a
  644. end
  645. def syntax_highlight(name, content)
  646. Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
  647. end
  648. def to_path_param(path)
  649. str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/")
  650. str.blank? ? nil : str
  651. end
  652. def reorder_handle(object, options={})
  653. data = {
  654. :reorder_url => options[:url] || url_for(object),
  655. :reorder_param => options[:param] || object.class.name.underscore
  656. }
  657. content_tag('span', '',
  658. :class => "icon-only icon-sort-handle sort-handle",
  659. :data => data,
  660. :title => l(:button_sort))
  661. end
  662. def breadcrumb(*args)
  663. elements = args.flatten
  664. elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
  665. end
  666. def other_formats_links(&block)
  667. concat('<p class="other-formats">'.html_safe + l(:label_export_to))
  668. yield Redmine::Views::OtherFormatsBuilder.new(self)
  669. concat('</p>'.html_safe)
  670. end
  671. def page_header_title
  672. if @project.nil? || @project.new_record?
  673. h(Setting.app_title)
  674. else
  675. b = []
  676. ancestors = (@project.root? ? [] : @project.ancestors.visible.to_a)
  677. if ancestors.any?
  678. root = ancestors.shift
  679. b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
  680. if ancestors.size > 2
  681. b << "\xe2\x80\xa6"
  682. ancestors = ancestors[-2, 2]
  683. end
  684. b +=
  685. ancestors.collect do |p|
  686. link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor')
  687. end
  688. end
  689. b << content_tag(:span, h(@project), class: 'current-project')
  690. if b.size > 1
  691. separator = content_tag(:span, ' &raquo; '.html_safe, class: 'separator')
  692. path = safe_join(b[0..-2], separator) + separator
  693. b = [content_tag(:span, path.html_safe, class: 'breadcrumbs'), b[-1]]
  694. end
  695. safe_join b
  696. end
  697. end
  698. # Returns a h2 tag and sets the html title with the given arguments
  699. def title(*args)
  700. strings = args.map do |arg|
  701. if arg.is_a?(Array) && arg.size >= 2
  702. link_to(*arg)
  703. else
  704. h(arg.to_s)
  705. end
  706. end
  707. html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s}
  708. content_tag('h2', strings.join(' &#187; ').html_safe)
  709. end
  710. # Sets the html title
  711. # Returns the html title when called without arguments
  712. # Current project name and app_title are automatically appended
  713. # Exemples:
  714. # html_title 'Foo', 'Bar'
  715. # html_title # => 'Foo - Bar - My Project - Redmine'
  716. def html_title(*args)
  717. if args.empty?
  718. title = @html_title || []
  719. title << @project.name if @project
  720. title << Setting.app_title unless Setting.app_title == title.last
  721. title.reject(&:blank?).join(' - ')
  722. else
  723. @html_title ||= []
  724. @html_title += args
  725. end
  726. end
  727. def actions_dropdown(&block)
  728. content = capture(&block)
  729. if content.present?
  730. trigger =
  731. content_tag('span', l(:button_actions), :class => 'icon-only icon-actions',
  732. :title => l(:button_actions))
  733. trigger = content_tag('span', trigger, :class => 'drdn-trigger')
  734. content = content_tag('div', content, :class => 'drdn-items')
  735. content = content_tag('div', content, :class => 'drdn-content')
  736. content_tag('span', trigger + content, :class => 'drdn')
  737. end
  738. end
  739. # Returns the theme, controller name, and action as css classes for the
  740. # HTML body.
  741. def body_css_classes
  742. css = []
  743. if theme = Redmine::Themes.theme(Setting.ui_theme)
  744. css << 'theme-' + theme.name
  745. end
  746. css << 'project-' + @project.identifier if @project && @project.identifier.present?
  747. css << 'has-main-menu' if display_main_menu?(@project)
  748. css << 'controller-' + controller_name
  749. css << 'action-' + action_name
  750. css << 'avatars-' + (Setting.gravatar_enabled? ? 'on' : 'off')
  751. if UserPreference::TEXTAREA_FONT_OPTIONS.include?(User.current.pref.textarea_font)
  752. css << "textarea-#{User.current.pref.textarea_font}"
  753. end
  754. css.join(' ')
  755. end
  756. def accesskey(s)
  757. @used_accesskeys ||= []
  758. key = Redmine::AccessKeys.key_for(s)
  759. return nil if @used_accesskeys.include?(key)
  760. @used_accesskeys << key
  761. key
  762. end
  763. # Formats text according to system settings.
  764. # 2 ways to call this method:
  765. # * with a String: textilizable(text, options)
  766. # * with an object and one of its attribute: textilizable(issue, :description, options)
  767. def textilizable(*args)
  768. options = args.last.is_a?(Hash) ? args.pop : {}
  769. case args.size
  770. when 1
  771. obj = options[:object]
  772. text = args.shift
  773. when 2
  774. obj = args.shift
  775. attr = args.shift
  776. text = obj.send(attr).to_s
  777. else
  778. raise ArgumentError, 'invalid arguments to textilizable'
  779. end
  780. return '' if text.blank?
  781. project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
  782. @only_path = only_path = options.delete(:only_path) == false ? false : true
  783. text = text.dup
  784. macros = catch_macros(text)
  785. if options[:formatting] == false
  786. text = h(text)
  787. else
  788. formatting = Setting.text_formatting
  789. text = Redmine::WikiFormatting.to_html(formatting, text, :object => obj, :attribute => attr)
  790. end
  791. @parsed_headings = []
  792. @heading_anchors = {}
  793. @current_section = 0 if options[:edit_section_links]
  794. parse_sections(text, project, obj, attr, only_path, options)
  795. text = parse_non_pre_blocks(text, obj, macros, options) do |text|
  796. [:parse_inline_attachments, :parse_hires_images, :parse_wiki_links, :parse_redmine_links].each do |method_name|
  797. send method_name, text, project, obj, attr, only_path, options
  798. end
  799. end
  800. parse_headings(text, project, obj, attr, only_path, options)
  801. if @parsed_headings.any?
  802. replace_toc(text, @parsed_headings)
  803. end
  804. text.html_safe
  805. end
  806. def parse_non_pre_blocks(text, obj, macros, options={})
  807. s = StringScanner.new(text)
  808. tags = []
  809. parsed = +''
  810. while !s.eos?
  811. s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
  812. text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
  813. if tags.empty?
  814. yield text
  815. inject_macros(text, obj, macros, true, options) if macros.any?
  816. else
  817. inject_macros(text, obj, macros, false, options) if macros.any?
  818. end
  819. parsed << text
  820. if tag
  821. if closing
  822. if tags.last && tags.last.casecmp(tag) == 0
  823. tags.pop
  824. end
  825. else
  826. tags << tag.downcase
  827. end
  828. parsed << full_tag
  829. end
  830. end
  831. # Close any non closing tags
  832. while tag = tags.pop
  833. parsed << "</#{tag}>"
  834. end
  835. parsed
  836. end
  837. # add srcset attribute to img tags if filename includes @2x, @3x, etc.
  838. # to support hires displays
  839. def parse_hires_images(text, project, obj, attr, only_path, options)
  840. text.gsub!(/src="([^"]+@(\dx)\.(bmp|gif|jpg|jpe|jpeg|png))"/i) do |m|
  841. filename, dpr = $1, $2
  842. m + " srcset=\"#{filename} #{dpr}\""
  843. end
  844. end
  845. def parse_inline_attachments(text, project, obj, attr, only_path, options)
  846. return if options[:inline_attachments] == false
  847. # when using an image link, try to use an attachment, if possible
  848. attachments = options[:attachments] || []
  849. if obj.is_a?(Journal)
  850. attachments += obj.journalized.attachments if obj.journalized.respond_to?(:attachments)
  851. else
  852. attachments += obj.attachments if obj.respond_to?(:attachments)
  853. end
  854. if attachments.present?
  855. text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
  856. filename, ext, alt, alttext = $1, $2, $3, $4
  857. # search for the picture in attachments
  858. if found = Attachment.latest_attach(attachments, CGI.unescape(filename))
  859. image_url = download_named_attachment_url(found, found.filename, :only_path => only_path)
  860. desc = found.description.to_s.delete('"')
  861. if !desc.blank? && alttext.blank?
  862. alt = " title=\"#{desc}\" alt=\"#{desc}\""
  863. end
  864. "src=\"#{image_url}\"#{alt} loading=\"lazy\""
  865. else
  866. m
  867. end
  868. end
  869. end
  870. end
  871. # Wiki links
  872. #
  873. # Examples:
  874. # [[mypage]]
  875. # [[mypage|mytext]]
  876. # wiki links can refer other project wikis, using project name or identifier:
  877. # [[project:]] -> wiki starting page
  878. # [[project:|mytext]]
  879. # [[project:mypage]]
  880. # [[project:mypage|mytext]]
  881. def parse_wiki_links(text, project, obj, attr, only_path, options)
  882. text.gsub!(/(!)?(\[\[([^\n\|]+?)(\|([^\n\|]+?))?\]\])/) do |m|
  883. link_project = project
  884. esc, all, page, title = $1, $2, $3, $5
  885. if esc.nil?
  886. page = CGI.unescapeHTML(page)
  887. if page =~ /^\#(.+)$/
  888. anchor = sanitize_anchor_name($1)
  889. url = "##{anchor}"
  890. next link_to(title.present? ? title.html_safe : h(page), url, :class => 'wiki-page')
  891. end
  892. if page =~ /^([^\:]+)\:(.*)$/
  893. identifier, page = $1, $2
  894. link_project = Project.find_by_identifier(identifier) || Project.find_by_name(identifier)
  895. title ||= identifier if page.blank?
  896. end
  897. if link_project && link_project.wiki && User.current.allowed_to?(:view_wiki_pages, link_project)
  898. # extract anchor
  899. anchor = nil
  900. if page =~ /^(.+?)\#(.+)$/
  901. page, anchor = $1, $2
  902. end
  903. anchor = sanitize_anchor_name(anchor) if anchor.present?
  904. # check if page exists
  905. wiki_page = link_project.wiki.find_page(page)
  906. url =
  907. if anchor.present? && wiki_page.present? &&
  908. (obj.is_a?(WikiContent) || obj.is_a?(WikiContentVersion)) &&
  909. obj.page == wiki_page
  910. "##{anchor}"
  911. else
  912. case options[:wiki_links]
  913. when :local
  914. "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
  915. when :anchor
  916. # used for single-file wiki export
  917. "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '')
  918. else
  919. wiki_page_id = page.present? ? Wiki.titleize(page) : nil
  920. parent =
  921. if wiki_page.nil? && obj.is_a?(WikiContent) &&
  922. obj.page && project == link_project
  923. obj.page.title
  924. else
  925. nil
  926. end
  927. url_for(:only_path => only_path, :controller => 'wiki',
  928. :action => 'show', :project_id => link_project,
  929. :id => wiki_page_id, :version => nil, :anchor => anchor,
  930. :parent => parent)
  931. end
  932. end
  933. link_to(title.present? ? title.html_safe : h(page),
  934. url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
  935. else
  936. # project or wiki doesn't exist
  937. all
  938. end
  939. else
  940. all
  941. end
  942. end
  943. end
  944. # Redmine links
  945. #
  946. # Examples:
  947. # Issues:
  948. # #52 -> Link to issue #52
  949. # ##52 -> Link to issue #52, including the issue's subject
  950. # Changesets:
  951. # r52 -> Link to revision 52
  952. # commit:a85130f -> Link to scmid starting with a85130f
  953. # Documents:
  954. # document#17 -> Link to document with id 17
  955. # document:Greetings -> Link to the document with title "Greetings"
  956. # document:"Some document" -> Link to the document with title "Some document"
  957. # Versions:
  958. # version#3 -> Link to version with id 3
  959. # version:1.0.0 -> Link to version named "1.0.0"
  960. # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
  961. # Attachments:
  962. # attachment:file.zip -> Link to the attachment of the current object named file.zip
  963. # Source files:
  964. # source:some/file -> Link to the file located at /some/file in the project's repository
  965. # source:some/file@52 -> Link to the file's revision 52
  966. # source:some/file#L120 -> Link to line 120 of the file
  967. # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
  968. # export:some/file -> Force the download of the file
  969. # Forums:
  970. # forum#1 -> Link to forum with id 1
  971. # forum:Support -> Link to forum named "Support"
  972. # forum:"Technical Support" -> Link to forum named "Technical Support"
  973. # Forum messages:
  974. # message#1218 -> Link to message with id 1218
  975. # Projects:
  976. # project:someproject -> Link to project named "someproject"
  977. # project#3 -> Link to project with id 3
  978. # News:
  979. # news#2 -> Link to news item with id 1
  980. # news:Greetings -> Link to news item named "Greetings"
  981. # news:"First Release" -> Link to news item named "First Release"
  982. # Users:
  983. # user:jsmith -> Link to user with login jsmith
  984. # @jsmith -> Link to user with login jsmith
  985. # user#2 -> Link to user with id 2
  986. #
  987. # Links can refer other objects from other projects, using project identifier:
  988. # identifier:r52
  989. # identifier:document:"Some document"
  990. # identifier:version:1.0.0
  991. # identifier:source:some/file
  992. def parse_redmine_links(text, default_project, obj, attr, only_path, options)
  993. text.gsub!(LINKS_RE) do |_|
  994. tag_content = $~[:tag_content]
  995. leading = $~[:leading]
  996. esc = $~[:esc]
  997. project_prefix = $~[:project_prefix]
  998. project_identifier = $~[:project_identifier]
  999. prefix = $~[:prefix]
  1000. repo_prefix = $~[:repo_prefix]
  1001. repo_identifier = $~[:repo_identifier]
  1002. sep = $~[:sep1] || $~[:sep2] || $~[:sep3] || $~[:sep4]
  1003. identifier = $~[:identifier1] || $~[:identifier2] || $~[:identifier3]
  1004. comment_suffix = $~[:comment_suffix]
  1005. comment_id = $~[:comment_id]
  1006. if tag_content
  1007. $&
  1008. else
  1009. link = nil
  1010. project = default_project
  1011. if project_identifier
  1012. project = Project.visible.find_by_identifier(project_identifier)
  1013. end
  1014. if esc.nil?
  1015. if prefix.nil? && sep == 'r'
  1016. if project
  1017. repository = nil
  1018. if repo_identifier
  1019. repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
  1020. else
  1021. repository = project.repository
  1022. end
  1023. # project.changesets.visible raises an SQL error because of a double join on repositories
  1024. if repository &&
  1025. (changeset = Changeset.visible.
  1026. find_by_repository_id_and_revision(repository.id, identifier))
  1027. link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"),
  1028. {:only_path => only_path, :controller => 'repositories',
  1029. :action => 'revision', :id => project,
  1030. :repository_id => repository.identifier_param,
  1031. :rev => changeset.revision},
  1032. :class => 'changeset',
  1033. :title => truncate_single_line_raw(changeset.comments, 100))
  1034. end
  1035. end
  1036. elsif sep == '#' || sep == '##'
  1037. oid = identifier.to_i
  1038. case prefix
  1039. when nil
  1040. if oid.to_s == identifier &&
  1041. issue = Issue.visible.find_by_id(oid)
  1042. anchor = comment_id ? "note-#{comment_id}" : nil
  1043. url = issue_url(issue, :only_path => only_path, :anchor => anchor)
  1044. link =
  1045. if sep == '##'
  1046. link_to("#{issue.tracker.name} ##{oid}#{comment_suffix}: #{issue.subject}",
  1047. url,
  1048. :class => issue.css_classes,
  1049. :title => "#{l(:field_status)}: #{issue.status.name}")
  1050. else
  1051. link_to("##{oid}#{comment_suffix}",
  1052. url,
  1053. :class => issue.css_classes,
  1054. :title => "#{issue.tracker.name}: #{issue.subject.truncate(100)} (#{issue.status.name})")
  1055. end
  1056. elsif identifier == 'note'
  1057. link = link_to("#note-#{comment_id}", "#note-#{comment_id}")
  1058. end
  1059. when 'document'
  1060. if document = Document.visible.find_by_id(oid)
  1061. link = link_to(document.title,
  1062. document_url(document, :only_path => only_path),
  1063. :class => 'document')
  1064. end
  1065. when 'version'
  1066. if version = Version.visible.find_by_id(oid)
  1067. link = link_to(version.name, version_url(version, :only_path => only_path), :class => 'version')
  1068. end
  1069. when 'message'
  1070. if message = Message.visible.find_by_id(oid)
  1071. link = link_to_message(message, {:only_path => only_path}, :class => 'message')
  1072. end
  1073. when 'forum'
  1074. if board = Board.visible.find_by_id(oid)
  1075. link = link_to(board.name,
  1076. project_board_url(board.project, board, :only_path => only_path),
  1077. :class => 'board')
  1078. end
  1079. when 'news'
  1080. if news = News.visible.find_by_id(oid)
  1081. link = link_to(news.title, news_url(news, :only_path => only_path), :class => 'news')
  1082. end
  1083. when 'project'
  1084. if p = Project.visible.find_by_id(oid)
  1085. link = link_to_project(p, {:only_path => only_path}, :class => 'project')
  1086. end
  1087. when 'user'
  1088. u = User.visible.find_by(:id => oid, :type => 'User')
  1089. link = link_to_user(u, :only_path => only_path) if u
  1090. end
  1091. elsif sep == ':'
  1092. name = remove_double_quotes(identifier)
  1093. case prefix
  1094. when 'document'
  1095. if project && document = project.documents.visible.find_by_title(name)
  1096. link = link_to(document.title,
  1097. document_url(document, :only_path => only_path),
  1098. :class => 'document')
  1099. end
  1100. when 'version'
  1101. if project && version = project.versions.visible.find_by_name(name)
  1102. link = link_to(version.name, version_url(version, :only_path => only_path), :class => 'version')
  1103. end
  1104. when 'forum'
  1105. if project && board = project.boards.visible.find_by_name(name)
  1106. link = link_to(board.name,
  1107. project_board_url(board.project, board, :only_path => only_path),
  1108. :class => 'board')
  1109. end
  1110. when 'news'
  1111. if project && news = project.news.visible.find_by_title(name)
  1112. link = link_to(news.title, news_url(news, :only_path => only_path), :class => 'news')
  1113. end
  1114. when 'commit', 'source', 'export'
  1115. if project
  1116. repository = nil
  1117. if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$}
  1118. repo_prefix, repo_identifier, name = $1, $2, $3
  1119. repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
  1120. else
  1121. repository = project.repository
  1122. end
  1123. if prefix == 'commit'
  1124. if repository &&
  1125. (changeset =
  1126. Changeset.visible.
  1127. where(
  1128. "repository_id = ? AND scmid LIKE ?",
  1129. repository.id, "#{name}%"
  1130. ).first)
  1131. link =
  1132. link_to(
  1133. h("#{project_prefix}#{repo_prefix}#{name}"),
  1134. {:only_path => only_path, :controller => 'repositories',
  1135. :action => 'revision', :id => project,
  1136. :repository_id => repository.identifier_param,
  1137. :rev => changeset.identifier},
  1138. :class => 'changeset',
  1139. :title => truncate_single_line_raw(changeset.comments, 100)
  1140. )
  1141. end
  1142. else
  1143. if repository && User.current.allowed_to?(:browse_repository, project)
  1144. name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$}
  1145. path, rev, anchor = $1, $3, $5
  1146. link =
  1147. link_to(
  1148. h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"),
  1149. {:only_path => only_path, :controller => 'repositories',
  1150. :action => (prefix == 'export' ? 'raw' : 'entry'),
  1151. :id => project, :repository_id => repository.identifier_param,
  1152. :path => to_path_param(path),
  1153. :rev => rev,
  1154. :anchor => anchor},
  1155. :class => (prefix == 'export' ? 'source download' : 'source'))
  1156. end
  1157. end
  1158. repo_prefix = nil
  1159. end
  1160. when 'attachment'
  1161. attachments = options[:attachments] || []
  1162. attachments += obj.attachments if obj.respond_to?(:attachments)
  1163. if attachments && attachment = Attachment.latest_attach(attachments, name)
  1164. link = link_to_attachment(attachment, :only_path => only_path, :class => 'attachment')
  1165. end
  1166. when 'project'
  1167. if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
  1168. link = link_to_project(p, {:only_path => only_path}, :class => 'project')
  1169. end
  1170. when 'user'
  1171. u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
  1172. link = link_to_user(u, :only_path => only_path) if u
  1173. end
  1174. elsif sep == "@"
  1175. name = remove_double_quotes(identifier)
  1176. u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
  1177. link = link_to_user(u, :only_path => only_path) if u
  1178. end
  1179. end
  1180. (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
  1181. end
  1182. end
  1183. end
  1184. LINKS_RE =
  1185. %r{
  1186. <a( [^>]+?)?>(?<tag_content>.*?)</a>|
  1187. (?<leading>[\s\(,\-\[\>]|^)
  1188. (?<esc>!)?
  1189. (?<project_prefix>(?<project_identifier>[a-z0-9\-_]+):)?
  1190. (?<prefix>attachment|document|version|forum|news|message|project|commit|source|export|user)?
  1191. (
  1192. (
  1193. (?<sep1>\#\#?)|
  1194. (
  1195. (?<repo_prefix>(?<repo_identifier>[a-z0-9\-_]+)\|)?
  1196. (?<sep2>r)
  1197. )
  1198. )
  1199. (
  1200. (?<identifier1>((\d)+|(note)))
  1201. (?<comment_suffix>
  1202. (\#note)?
  1203. -(?<comment_id>\d+)
  1204. )?
  1205. )|
  1206. (
  1207. (?<sep3>:)
  1208. (?<identifier2>[^"\s<>][^\s<>]*?|"[^"]+?")
  1209. )|
  1210. (
  1211. (?<sep4>@)
  1212. (?<identifier3>[A-Za-z0-9_\-@\.]*?)
  1213. )
  1214. )
  1215. (?=
  1216. (?=[[:punct:]][^A-Za-z0-9_/])|
  1217. ,|
  1218. \s|
  1219. \]|
  1220. <|
  1221. $)
  1222. }x
  1223. HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
  1224. def parse_sections(text, project, obj, attr, only_path, options)
  1225. return unless options[:edit_section_links]
  1226. text.gsub!(HEADING_RE) do
  1227. heading, level = $1, $2
  1228. @current_section += 1
  1229. if @current_section > 1
  1230. content_tag(
  1231. 'div',
  1232. link_to(
  1233. l(:button_edit_section),
  1234. options[:edit_section_links].merge(
  1235. :section => @current_section),
  1236. :class => 'icon-only icon-edit'),
  1237. :class => "contextual heading-#{level}",
  1238. :title => l(:button_edit_section),
  1239. :id => "section-#{@current_section}") + heading.html_safe
  1240. else
  1241. heading
  1242. end
  1243. end
  1244. end
  1245. # Headings and TOC
  1246. # Adds ids and links to headings unless options[:headings] is set to false
  1247. def parse_headings(text, project, obj, attr, only_path, options)
  1248. return if options[:headings] == false
  1249. text.gsub!(HEADING_RE) do
  1250. level, attrs, content = $2.to_i, $3, $4
  1251. item = strip_tags(content).strip
  1252. anchor = sanitize_anchor_name(item)
  1253. # used for single-file wiki export
  1254. if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) ||
  1255. obj.is_a?(WikiContentVersion))
  1256. anchor = "#{obj.page.title}_#{anchor}"
  1257. end
  1258. @heading_anchors[anchor] ||= 0
  1259. idx = (@heading_anchors[anchor] += 1)
  1260. if idx > 1
  1261. anchor = "#{anchor}-#{idx}"
  1262. end
  1263. @parsed_headings << [level, anchor, item]
  1264. "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}" \
  1265. "<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
  1266. end
  1267. end
  1268. unless const_defined?(:MACROS_RE)
  1269. MACROS_RE = /(
  1270. (!)? # escaping
  1271. (
  1272. \{\{ # opening tag
  1273. ([\w]+) # macro name
  1274. (\(([^\n\r]*?)\))? # optional arguments
  1275. ([\n\r].*?[\n\r])? # optional block of text
  1276. \}\} # closing tag
  1277. )
  1278. )/mx
  1279. end
  1280. unless const_defined?(:MACRO_SUB_RE)
  1281. MACRO_SUB_RE = /(
  1282. \{\{
  1283. macro\((\d+)\)
  1284. \}\}
  1285. )/x
  1286. end
  1287. # Extracts macros from text
  1288. def catch_macros(text)
  1289. macros = {}
  1290. text.gsub!(MACROS_RE) do
  1291. all, macro = $1, $4.downcase
  1292. if macro_exists?(macro) || all =~ MACRO_SUB_RE
  1293. index = macros.size
  1294. macros[index] = all
  1295. "{{macro(#{index})}}"
  1296. else
  1297. all
  1298. end
  1299. end
  1300. macros
  1301. end
  1302. # Executes and replaces macros in text
  1303. def inject_macros(text, obj, macros, execute=true, options={})
  1304. text.gsub!(MACRO_SUB_RE) do
  1305. all, index = $1, $2.to_i
  1306. orig = macros.delete(index)
  1307. if execute && orig && orig =~ MACROS_RE
  1308. esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip)
  1309. if esc.nil?
  1310. h(exec_macro(macro, obj, args, block, options) || all)
  1311. else
  1312. h(all)
  1313. end
  1314. elsif orig
  1315. h(orig)
  1316. else
  1317. h(all)
  1318. end
  1319. end
  1320. end
  1321. TOC_RE = /<p>\{\{((<|&lt;)|(>|&gt;))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
  1322. # Renders the TOC with given headings
  1323. def replace_toc(text, headings)
  1324. text.gsub!(TOC_RE) do
  1325. left_align, right_align = $2, $3
  1326. # Keep only the 4 first levels
  1327. headings = headings.select{|level, anchor, item| level <= 4}
  1328. if headings.empty?
  1329. ''
  1330. else
  1331. div_class = +'toc'
  1332. div_class << ' right' if right_align
  1333. div_class << ' left' if left_align
  1334. out = +"<ul class=\"#{div_class}\"><li><strong>#{l :label_table_of_contents}</strong></li><li>"
  1335. root = headings.map(&:first).min
  1336. current = root
  1337. started = false
  1338. headings.each do |level, anchor, item|
  1339. if level > current
  1340. out << '<ul><li>' * (level - current)
  1341. elsif level < current
  1342. out << "</li></ul>\n" * (current - level) + "</li><li>"
  1343. elsif started
  1344. out << '</li><li>'
  1345. end
  1346. out << "<a href=\"##{anchor}\">#{item}</a>"
  1347. current = level
  1348. started = true
  1349. end
  1350. out << '</li></ul>' * (current - root)
  1351. out << '</li></ul>'
  1352. end
  1353. end
  1354. end
  1355. # Same as Rails' simple_format helper without using paragraphs
  1356. def simple_format_without_paragraph(text)
  1357. text.to_s.
  1358. gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
  1359. gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
  1360. gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
  1361. html_safe
  1362. end
  1363. def lang_options_for_select(blank=true)
  1364. (blank ? [["(auto)", ""]] : []) + languages_options
  1365. end
  1366. def labelled_form_for(*args, &proc)
  1367. args << {} unless args.last.is_a?(Hash)
  1368. options = args.last
  1369. if args.first.is_a?(Symbol)
  1370. options[:as] = args.shift
  1371. end
  1372. options[:builder] = Redmine::Views::LabelledFormBuilder
  1373. form_for(*args, &proc)
  1374. end
  1375. def labelled_fields_for(*args, &proc)
  1376. args << {} unless args.last.is_a?(Hash)
  1377. options = args.last
  1378. options[:builder] = Redmine::Views::LabelledFormBuilder
  1379. fields_for(*args, &proc)
  1380. end
  1381. def form_tag_html(html_options)
  1382. # Set a randomized name attribute on all form fields by default
  1383. # as a workaround to https://bugzilla.mozilla.org/show_bug.cgi?id=1279253
  1384. html_options['name'] ||= "#{html_options['id'] || 'form'}-#{SecureRandom.hex(4)}"
  1385. super
  1386. end
  1387. # Render the error messages for the given objects
  1388. def error_messages_for(*objects)
  1389. objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
  1390. errors = objects.map {|o| o.errors.full_messages}.flatten
  1391. render_error_messages(errors)
  1392. end
  1393. # Renders a list of error messages
  1394. def render_error_messages(errors)
  1395. html = +""
  1396. if errors.present?
  1397. html << "<div id='errorExplanation'><ul>\n"
  1398. errors.each do |error|
  1399. html << "<li>#{h error}</li>\n"
  1400. end
  1401. html << "</ul></div>\n"
  1402. end
  1403. html.html_safe
  1404. end
  1405. def delete_link(url, options={}, button_name=l(:button_delete))
  1406. options = {
  1407. :method => :delete,
  1408. :data => {:confirm => l(:text_are_you_sure)},
  1409. :class => 'icon icon-del'
  1410. }.merge(options)
  1411. link_to button_name, url, options
  1412. end
  1413. def link_to_function(name, function, html_options={})
  1414. content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
  1415. end
  1416. def link_to_context_menu
  1417. link_to l(:button_actions), '#', title: l(:button_actions), class: 'icon-only icon-actions js-contextmenu'
  1418. end
  1419. # Helper to render JSON in views
  1420. def raw_json(arg)
  1421. arg.to_json.to_s.gsub('/', '\/').html_safe
  1422. end
  1423. def back_url_hidden_field_tag
  1424. url = validate_back_url(back_url)
  1425. hidden_field_tag('back_url', url, :id => nil) unless url.blank?
  1426. end
  1427. def cancel_button_tag(fallback_url)
  1428. url = validate_back_url(back_url) || fallback_url
  1429. link_to l(:button_cancel), url
  1430. end
  1431. def check_all_links(form_name)
  1432. link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
  1433. " | ".html_safe +
  1434. link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
  1435. end
  1436. def toggle_checkboxes_link(selector)
  1437. link_to_function '',
  1438. "toggleCheckboxesBySelector('#{selector}')",
  1439. :title => "#{l(:button_check_all)} / #{l(:button_uncheck_all)}",
  1440. :class => 'icon icon-checked'
  1441. end
  1442. def progress_bar(pcts, options={})
  1443. pcts = [pcts, pcts] unless pcts.is_a?(Array)
  1444. pcts = pcts.collect(&:floor)
  1445. pcts[1] = pcts[1] - pcts[0]
  1446. pcts << (100 - pcts[1] - pcts[0])
  1447. titles = options[:titles].to_a
  1448. titles[0] = "#{pcts[0]}%" if titles[0].blank?
  1449. legend = options[:legend] || ''
  1450. content_tag(
  1451. 'table',
  1452. content_tag(
  1453. 'tr',
  1454. (if pcts[0] > 0
  1455. content_tag('td', '', :style => "width: #{pcts[0]}%;",
  1456. :class => 'closed', :title => titles[0])
  1457. else
  1458. ''.html_safe
  1459. end) +
  1460. (if pcts[1] > 0
  1461. content_tag('td', '', :style => "width: #{pcts[1]}%;",
  1462. :class => 'done', :title => titles[1])
  1463. else
  1464. ''.html_safe
  1465. end) +
  1466. (if pcts[2] > 0
  1467. content_tag('td', '', :style => "width: #{pcts[2]}%;",
  1468. :class => 'todo', :title => titles[2])
  1469. else
  1470. ''.html_safe
  1471. end)
  1472. ), :class => "progress progress-#{pcts[0]}").html_safe +
  1473. content_tag('p', legend, :class => 'percent').html_safe
  1474. end
  1475. def checked_image(checked=true)
  1476. if checked
  1477. @checked_image_tag ||= content_tag(:span, nil, :class => 'icon-only icon-checked')
  1478. end
  1479. end
  1480. def context_menu
  1481. unless @context_menu_included
  1482. content_for :header_tags do
  1483. javascript_include_tag('context_menu') +
  1484. stylesheet_link_tag('context_menu')
  1485. end
  1486. if l(:direction) == 'rtl'
  1487. content_for :header_tags do
  1488. stylesheet_link_tag('context_menu_rtl')
  1489. end
  1490. end
  1491. @context_menu_included = true
  1492. end
  1493. nil
  1494. end
  1495. def calendar_for(field_id)
  1496. include_calendar_headers_tags
  1497. javascript_tag(
  1498. "$(function() { $('##{field_id}').addClass('date').datepickerFallback(datepickerOptions); });"
  1499. )
  1500. end
  1501. def include_calendar_headers_tags
  1502. unless @calendar_headers_tags_included
  1503. tags = ''.html_safe
  1504. @calendar_headers_tags_included = true
  1505. content_for :header_tags do
  1506. start_of_week = Setting.start_of_week
  1507. start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
  1508. # Redmine uses 1..7 (monday..sunday) in settings and locales
  1509. # JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
  1510. start_of_week = start_of_week.to_i % 7
  1511. tags <<
  1512. javascript_tag(
  1513. "var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " \
  1514. "showOn: 'button', buttonImageOnly: true, buttonImage: '" +
  1515. path_to_image('/images/calendar.png') +
  1516. "', showButtonPanel: true, showWeek: true, showOtherMonths: true, " \
  1517. "selectOtherMonths: true, changeMonth: true, changeYear: true, " \
  1518. "beforeShow: beforeShowDatePicker};"
  1519. )
  1520. jquery_locale = l('jquery.locale', :default => current_language.to_s)
  1521. unless jquery_locale == 'en'
  1522. tags << javascript_include_tag("i18n/datepicker-#{jquery_locale}.js")
  1523. end
  1524. tags
  1525. end
  1526. end
  1527. end
  1528. # Overrides Rails' stylesheet_link_tag with themes and plugins support.
  1529. # Examples:
  1530. # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults
  1531. # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets
  1532. #
  1533. def stylesheet_link_tag(*sources)
  1534. options = sources.last.is_a?(Hash) ? sources.pop : {}
  1535. plugin = options.delete(:plugin)
  1536. sources = sources.map do |source|
  1537. if plugin
  1538. "/plugin_assets/#{plugin}/stylesheets/#{source}"
  1539. elsif current_theme && current_theme.stylesheets.include?(source)
  1540. current_theme.stylesheet_path(source)
  1541. else
  1542. source
  1543. end
  1544. end
  1545. super *sources, options
  1546. end
  1547. # Overrides Rails' image_tag with themes and plugins support.
  1548. # Examples:
  1549. # image_tag('image.png') # => picks image.png from the current theme or defaults
  1550. # image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
  1551. #
  1552. def image_tag(source, options={})
  1553. if plugin = options.delete(:plugin)
  1554. source = "/plugin_assets/#{plugin}/images/#{source}"
  1555. elsif current_theme && current_theme.images.include?(source)
  1556. source = current_theme.image_path(source)
  1557. end
  1558. super source, options
  1559. end
  1560. # Overrides Rails' javascript_include_tag with plugins support
  1561. # Examples:
  1562. # javascript_include_tag('scripts') # => picks scripts.js from defaults
  1563. # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets
  1564. #
  1565. def javascript_include_tag(*sources)
  1566. options = sources.last.is_a?(Hash) ? sources.pop : {}
  1567. if plugin = options.delete(:plugin)
  1568. sources = sources.map do |source|
  1569. if plugin
  1570. "/plugin_assets/#{plugin}/javascripts/#{source}"
  1571. else
  1572. source
  1573. end
  1574. end
  1575. end
  1576. super *sources, options
  1577. end
  1578. def sidebar_content?
  1579. content_for?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
  1580. end
  1581. def view_layouts_base_sidebar_hook_response
  1582. @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
  1583. end
  1584. def email_delivery_enabled?
  1585. !!ActionMailer::Base.perform_deliveries
  1586. end
  1587. def sanitize_anchor_name(anchor)
  1588. anchor.gsub(%r{[^\s\-\p{Word}]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
  1589. end
  1590. # Returns the javascript tags that are included in the html layout head
  1591. def javascript_heads
  1592. tags = javascript_include_tag(
  1593. 'jquery-3.5.1-ui-1.12.1-ujs-6.1.3.1',
  1594. 'tribute-5.1.3.min',
  1595. 'tablesort-5.2.1.min.js',
  1596. 'tablesort-5.2.1.number.min.js',
  1597. 'application',
  1598. 'responsive')
  1599. unless User.current.pref.warn_on_leaving_unsaved == '0'
  1600. warn_text = escape_javascript(l(:text_warn_on_leaving_unsaved))
  1601. tags <<
  1602. "\n".html_safe +
  1603. javascript_tag(
  1604. "$(window).on('load', function(){ warnLeavingUnsaved('#{warn_text}'); });"
  1605. )
  1606. end
  1607. tags
  1608. end
  1609. def favicon
  1610. "<link rel='shortcut icon' href='#{favicon_path}' />".html_safe
  1611. end
  1612. # Returns the path to the favicon
  1613. def favicon_path
  1614. icon = (current_theme && current_theme.favicon?) ? current_theme.favicon_path : '/favicon.ico'
  1615. image_path(icon)
  1616. end
  1617. # Returns the full URL to the favicon
  1618. def favicon_url
  1619. # TODO: use #image_url introduced in Rails4
  1620. path = favicon_path
  1621. base = url_for(:controller => 'welcome', :action => 'index', :only_path => false)
  1622. base.sub(%r{/+$}, '') + '/' + path.sub(%r{^/+}, '')
  1623. end
  1624. def robot_exclusion_tag
  1625. '<meta name="robots" content="noindex,follow,noarchive" />'.html_safe
  1626. end
  1627. # Returns true if arg is expected in the API response
  1628. def include_in_api_response?(arg)
  1629. unless @included_in_api_response
  1630. param = params[:include]
  1631. @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
  1632. @included_in_api_response.collect!(&:strip)
  1633. end
  1634. @included_in_api_response.include?(arg.to_s)
  1635. end
  1636. # Returns options or nil if nometa param or X-Redmine-Nometa header
  1637. # was set in the request
  1638. def api_meta(options)
  1639. if params[:nometa].present? || request.headers['X-Redmine-Nometa']
  1640. # compatibility mode for activeresource clients that raise
  1641. # an error when deserializing an array with attributes
  1642. nil
  1643. else
  1644. options
  1645. end
  1646. end
  1647. def export_csv_encoding_select_tag
  1648. return if l(:general_csv_encoding).casecmp('UTF-8') == 0
  1649. options = [l(:general_csv_encoding), 'UTF-8']
  1650. content_tag(:p) do
  1651. concat(
  1652. content_tag(:label) do
  1653. concat l(:label_encoding) + ' '
  1654. concat select_tag('encoding', options_for_select(options, l(:general_csv_encoding)))
  1655. end
  1656. )
  1657. end
  1658. end
  1659. # Returns an array of error messages for bulk edited items (issues, time entries)
  1660. def bulk_edit_error_messages(items)
  1661. messages = {}
  1662. items.each do |item|
  1663. item.errors.full_messages.each do |message|
  1664. messages[message] ||= []
  1665. messages[message] << item
  1666. end
  1667. end
  1668. messages.map do |message, items|
  1669. "#{message}: " + items.map {|i| "##{i.id}"}.join(', ')
  1670. end
  1671. end
  1672. def render_if_exist(options = {}, locals = {}, &block)
  1673. if options[:partial]
  1674. if lookup_context.exists?(options[:partial], lookup_context.prefixes, true)
  1675. render(options, locals, &block)
  1676. end
  1677. else
  1678. render(options, locals, &block)
  1679. end
  1680. end
  1681. def autocomplete_data_sources(project)
  1682. {
  1683. issues: auto_complete_issues_path(:project_id => project, :q => ''),
  1684. wiki_pages: auto_complete_wiki_pages_path(:project_id => project, :q => '')
  1685. }
  1686. end
  1687. def heads_for_auto_complete(project)
  1688. data_sources = autocomplete_data_sources(project)
  1689. javascript_tag(
  1690. "rm = window.rm || {};" \
  1691. "rm.AutoComplete = rm.AutoComplete || {};" \
  1692. "rm.AutoComplete.dataSources = '#{data_sources.to_json}';"
  1693. )
  1694. end
  1695. def copy_object_url_link(url)
  1696. link_to_function(
  1697. l(:button_copy_link), 'copyTextToClipboard(this);',
  1698. class: 'icon icon-copy-link',
  1699. data: {'clipboard-text' => url}
  1700. )
  1701. end
  1702. # Returns the markdown formatter: markdown or common_mark
  1703. # ToDo: Remove this when markdown will be removed
  1704. def markdown_formatter
  1705. if Setting.text_formatting == "common_mark"
  1706. "common_mark"
  1707. else
  1708. "markdown"
  1709. end
  1710. end
  1711. private
  1712. def wiki_helper
  1713. helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
  1714. extend helper
  1715. return self
  1716. end
  1717. # remove double quotes if any
  1718. def remove_double_quotes(identifier)
  1719. name = identifier.gsub(%r{^"(.*)"$}, "\\1")
  1720. return CGI.unescapeHTML(name)
  1721. end
  1722. end