Module: WikiActions

Extended by:
ActiveSupport::Concern
Includes:
DiffHelper, Gitlab::Utils::StrongMemoize, PreviewMarkdown, RedisTracking, SendsBlob
Included in:
Projects::WikisController
Defined in:
app/controllers/concerns/wiki_actions.rb

Constant Summary collapse

RESCUE_GIT_TIMEOUTS_IN =
%w[show edit history diff pages].freeze

Instance Method Summary collapse

Methods included from Gitlab::Tracking::Helpers

#dnt_enabled?, #trackable_html_request?

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from SendsBlob

#send_blob

Methods included from PreviewMarkdown

#preview_markdown

Methods included from DiffHelper

#apply_diff_view_cookie!, #collapsed_diff_url, #conflicts, #diff_file_blob_raw_path, #diff_file_blob_raw_url, #diff_file_old_blob_raw_path, #diff_file_old_blob_raw_url, #diff_file_stats_data, #diff_line_content, #diff_link_number, #diff_match_line, #diff_nomappinginraw_line, #diff_options, #diff_view, #diffs_expanded?, #editable_diff?, #inline_diff_btn, #mark_inline_diffs, #parallel_diff_btn, #parallel_diff_discussions, #render_fork_suggestion, #render_overflow_warning?, #show_only_context_commits?, #submodule_diff_compare_link, #submodule_link

Instance Method Details

#createObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/controllers/concerns/wiki_actions.rb', line 126

def create
  response = WikiPages::CreateService.new(container: container, current_user: current_user, params: wiki_params).execute
  @page = response.payload[:page]

  if response.success?
    flash[:toast] = _('Wiki page was successfully created.')

    redirect_to(
      wiki_page_path(wiki, page)
    )
  else
    render 'shared/wikis/edit'
  end
end

#destroyObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'app/controllers/concerns/wiki_actions.rb', line 173

def destroy
  return render_404 unless page

  response = WikiPages::DestroyService.new(container: container, current_user: current_user).execute(page)

  if response.success?
    flash[:toast] = _("Wiki page was successfully deleted.")

    redirect_to wiki_path(wiki),
    status: :found
  else
    @error = response.message
    render 'shared/wikis/edit'
  end
end

#diffObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


160
161
162
163
164
165
166
167
168
169
# File 'app/controllers/concerns/wiki_actions.rb', line 160

def diff
  return render_404 unless page

  apply_diff_view_cookie!

  @diffs = page.diffs(diff_options)
  @diff_notes_disabled = true

  render 'shared/wikis/diff'
end

#editObject

rubocop:enable Gitlab/ModuleWithInstanceVariables


101
102
103
# File 'app/controllers/concerns/wiki_actions.rb', line 101

def edit
  render 'shared/wikis/edit'
end

#git_accessObject

rubocop:enable Gitlab/ModuleWithInstanceVariables


190
191
192
# File 'app/controllers/concerns/wiki_actions.rb', line 190

def git_access
  render 'shared/wikis/git_access'
end

#historyObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/concerns/wiki_actions.rb', line 143

def history
  if page
    @commits = Kaminari.paginate_array(page.versions(page: params[:page].to_i),
                                       total_count: page.count_versions)
      .page(params[:page])

    render 'shared/wikis/history'
  else
    redirect_to(
      wiki_path(wiki),
      notice: _("Page not found")
    )
  end
end

#newObject


53
54
55
# File 'app/controllers/concerns/wiki_actions.rb', line 53

def new
  redirect_to wiki_page_path(wiki, SecureRandom.uuid, random_title: true)
end

#pagesObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


58
59
60
61
62
# File 'app/controllers/concerns/wiki_actions.rb', line 58

def pages
  @wiki_entries = WikiDirectory.group_pages(wiki_pages)

  render 'shared/wikis/pages'
end

#showObject

`#show` handles a number of scenarios:

  • If `id` matches a WikiPage, then show the wiki page.

  • If `id` is a file in the wiki repository, then send the file.

  • If we know the user wants to create a new page with the given `id`, then display a create form.

  • Otherwise show the empty wiki page and invite the user to create a page.

rubocop:disable Gitlab/ModuleWithInstanceVariables


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/concerns/wiki_actions.rb', line 74

def show
  if page
    set_encoding_error unless valid_encoding?

    # Assign vars expected by MarkupHelper
    @ref = params[:version_id]
    @path = page.path

    Gitlab::UsageDataCounters::WikiPageCounter.count(:view)

    render 'shared/wikis/show'
  elsif file_blob
    # This is needed by [GitLab JH](https://gitlab.com/gitlab-jh/gitlab/-/issues/247)
    send_wiki_file_blob(wiki, file_blob)
  elsif show_create_form?
    # Assign a title to the WikiPage unless `id` is a randomly generated slug from #new
    title = params[:id] unless params[:random_title].present?

    @page = build_page(title: title)

    render 'shared/wikis/edit'
  else
    render 'shared/wikis/empty'
  end
end

#updateObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/concerns/wiki_actions.rb', line 106

def update
  return render('shared/wikis/empty') unless can?(current_user, :create_wiki, container)

  response = WikiPages::UpdateService.new(container: container, current_user: current_user, params: wiki_params).execute(page)
  @page = response.payload[:page]

  if response.success?
    flash[:toast] = _('Wiki page was successfully updated.')

    redirect_to(
      wiki_page_path(wiki, page)
    )
  else
    @error = response.message
    render 'shared/wikis/edit'
  end
end