opf/openproject

View on GitHub
app/views/wiki/show.html.erb

Summary

Maintainability
Test Coverage
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 2012-2024 the OpenProject GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.

OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

See COPYRIGHT and LICENSE files for more details.

++#%>

<%= call_hook :wiki_navigation %>
<% if @page.current_version? %>
  <% title = h(@page.title) %>
<% else %>
  <% title = link_to(@page.title, { action: 'show', id: @page, project_id: @page.project }) %>
<% end %>

<%# Set meta tags %>
<% title "#{t(:project_module_wiki)} | #{title}" %>
<% @formatted_text = format_text @page, :text, attachments: @page.attachments  %>
<% description strip_tags(@formatted_text) %>

<%= toolbar title: title, html: {class: '-with-dropdown'} do %>
  <% if @editable %>
    <% if @page && User.current.allowed_in_project?(:edit_wiki_pages, @project) %>
      <li class="toolbar-item">
          <%= link_to({controller: '/wiki', action: 'new_child', project_id: @project.identifier, id: @page},
              { class: 'button -primary',
                aria: {label: t('wiki.index.no_results_content_text')},
                title: t('wiki.index.no_results_content_text')}) do %>
            <%= op_icon('button--icon icon-add') %>
            <span class="button--text"><%= t(:create_new_page) %></span>
          <% end %>
      </li>
    <% end %>
    <% if @page.current_version? %>
      <li class="toolbar-item">
        <%= link_to_if_authorized({ action: 'edit', id: @page },
                                  { aria: { label: t(:button_edit) },
                                    title: t(:button_edit),
                                    class: 'button' }) do %>
          <%= op_icon('button--icon icon-edit') %>
          <span class="button--text"><%= t(:button_edit) %></span>
        <% end %>
      </li>
    <% end %>
    <li class="toolbar-item hidden-for-tablet">
      <%= watcher_link(@page.object, User.current) %>
    </li>
    <% unless @page.current_version? %>
      <li class="toolbar-item  hidden-for-mobile">
        <%= link_to(t(:label_history), {action: 'history', id: @page}, class: 'button icon-wiki') %>
      </li>
    <% end %>
  <% end %>
  <li class="toolbar-item drop-down">
    <a href="#" aria-haspopup="true" title="<%= t(:label_more) %>" class="button">
      <%= op_icon('button--icon icon-show-more hidden-for-desktop') %>
      <span class="button--text"><%= t(:label_more) %></span>
      <%= op_icon('button--dropdown-indicator') %>
    </a>
    <ul style="display:none;" class="menu-drop-down-container">
      <% if @editable %>
        <%= li_unless_nil(link_to_if_authorized(t(:button_lock), {action: 'protect', id: @page, protected: 1}, method: :post, class: 'icon-context icon-locked')) if !@page.protected? %>
        <%= li_unless_nil(link_to_if_authorized(t(:button_unlock), {action: 'protect', id: @page, protected: 0}, method: :post, class: 'icon-context icon-unlocked')) if @page.protected? %>
        <% if @page.current_version? %>
          <%= li_unless_nil(link_to_if_authorized(t(:button_rename),
                                                  {action: 'rename', id: @page},
                                                  class: 'icon-context icon-rename')) %>
          <%= li_unless_nil(link_to_if_authorized(t(:button_change_parent_page),
                                                  {action: 'edit_parent_page', id: @page},
                                                  class: 'icon-context icon-link')) %>
        <% end %>
        <%= li_unless_nil(link_to_if_authorized(t(:button_delete), {action: 'destroy', id: @page}, method: :delete, data: { confirm: t(:text_are_you_sure) }, class: 'icon-context icon-delete')) %>
        <%= li_unless_nil(link_to_if_authorized(t(:button_rollback), {action: 'edit', id: @page, version: @page.version }, class: 'icon-context icon-cancel')) unless @page.current_version? %>
      <% end %>
      <%= li_unless_nil(link_to_if_authorized(t(:label_history), {action: 'history', id: @page}, class: 'icon-context icon-activity-history')) %>
      <%= li_unless_nil(link_to_if_authorized(t(:button_manage_menu_entry), {controller: '/wiki_menu_items', action: 'edit', project_id: @project.identifier, id: @page}, class: 'icon-context icon-settings')) %>
      <li>
        <%= link_to t(:button_print),
                    '',
                    title: t('wiki.print_hint'),
                    class: 'icon-context icon-print',
                    data: {
                      controller: 'print',
                      action: 'print#triggerPrint'
                    }
        %>
      </li>
      <% if User.current.allowed_in_project?(:export_wiki_pages, @project) %>
        <section data-augmented-model-wrapper
                 data-modal-class-name="wiki-export---modal">
          <li>
            <%= link_to I18n.t('js.label_export'),
                        '',
                        title: I18n.t('js.label_export'),
                        class: 'modal-delivery-element--activation-link icon-context icon-export' %>
          </li>
          <%= render partial: 'wiki/wiki_export_modal' %>
        </section>
      <% end %>
      <%= li_unless_nil(link_to_if_authorized(t(:label_table_of_contents), {controller: '/wiki', action: 'index', project_id: @project.identifier, id: @page}, class: 'icon-context icon-view-list')) %>
    </ul>
  </li>
<% end %>

<% breadcrumb_paths(*(@page.ancestors.reverse.collect { |parent| link_to h(parent.breadcrumb_title), {id: parent, project_id: parent.project}} + [h(@page.breadcrumb_title)])) %>

<% if params[:version] %>
  <hr />
  <div class="wiki-version--details">
    <div>
      <%= link_to(t(:label_previous), { action: 'show', id: @page, project_id: @page.project, version: (@page.version - 1) }, class: 'button navigate-left') if @page.version > 1 %>
      <span><%= "#{Version.model_name.human} #{@page.version}/#{@page.latest_version}" %> &#x2014;</span>
      <span><em><%= @page.author ? link_to_user(@page.author) : t(:label_user_anonymous) %></em> &#x2014; <%= format_time(@page.updated_at) %></span>
      <%= link_to(t(:label_next), { action: 'show', id: @page, project_id: @page.project, version: (@page.version + 1) }, class: 'button navigate-right') unless @page.current_version? %>
    </div>
    <hr />
  </div>
<% end %>

<%= render(partial: "wiki/text", locals: { page: @page }) %>

<% resource = ::API::V3::WikiPages::WikiPageRepresenter.new(@page, current_user: current_user, embed_links: true) %>
<%= list_attachments(resource) %>

<% html_title h(@page.title) %>