Module: WikiActions

Extended by:
ActiveSupport::Concern
Includes:
DiffHelper, Gitlab::Utils::StrongMemoize, PreviewMarkdown, ProductAnalyticsTracking, 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 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, #params_with_whitespace, #render_fork_suggestion, #render_overflow_warning?, #show_only_context_commits?, #submodule_diff_compare_link, #submodule_link

Instance Method Details

#createObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



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

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



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/controllers/concerns/wiki_actions.rb', line 190

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



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

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



115
116
117
# File 'app/controllers/concerns/wiki_actions.rb', line 115

def edit
  render 'shared/wikis/edit'
end

#git_accessObject

rubocop:enable Gitlab/ModuleWithInstanceVariables



206
207
208
# File 'app/controllers/concerns/wiki_actions.rb', line 206

def git_access
  render 'shared/wikis/git_access'
end

#historyObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



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

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



67
68
69
# File 'app/controllers/concerns/wiki_actions.rb', line 67

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

#pagesObject

rubocop:disable Gitlab/ModuleWithInstanceVariables



72
73
74
75
76
# File 'app/controllers/concerns/wiki_actions.rb', line 72

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/concerns/wiki_actions.rb', line 88

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/concerns/wiki_actions.rb', line 120

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