Module: WikiActions
- Extended by:
- ActiveSupport::Concern
- Includes:
- DiffHelper, Gitlab::Utils::StrongMemoize, PreviewMarkdown, SendsBlob
- Included in:
- Projects::WikisController
- Defined in:
- app/controllers/concerns/wiki_actions.rb
Instance Method Summary collapse
-
#create ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
-
#destroy ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
-
#diff ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
-
#edit ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables.
-
#history ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
- #new ⇒ Object
-
#pages ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
-
#show ⇒ Object
`#show` handles a number of scenarios:.
-
#update ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
Methods included from Gitlab::Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Methods included from SendsBlob
Methods included from PreviewMarkdown
Methods included from DiffHelper
#apply_diff_view_cookie!, #diff_file_blob_raw_path, #diff_file_blob_raw_url, #diff_file_changed_icon, #diff_file_changed_icon_color, #diff_file_old_blob_raw_path, #diff_file_old_blob_raw_url, #diff_line_content, #diff_match_line, #diff_options, #diff_view, #diffs_expanded?, #editable_diff?, #inline_diff_btn, #mark_inline_diffs, #parallel_diff_btn, #parallel_diff_discussions, #render_overflow_warning?, #submodule_diff_compare_link, #submodule_link
Instance Method Details
#create ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/concerns/wiki_actions.rb', line 114 def create response = WikiPages::CreateService.new(container: container, current_user: current_user, params: wiki_params).execute @page = response.payload[:page] if response.success? redirect_to( wiki_page_path(wiki, page), notice: _('Wiki was successfully updated.') ) else render 'shared/wikis/edit' end end |
#destroy ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/concerns/wiki_actions.rb', line 160 def destroy return render_404 unless page response = WikiPages::DestroyService.new(container: container, current_user: current_user).execute(page) if response.success? redirect_to wiki_path(wiki), status: :found, notice: _("Page was successfully deleted") else @error = response render 'shared/wikis/edit' end end |
#diff ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/concerns/wiki_actions.rb', line 147 def diff return render_404 unless page @diffs = page.diffs() @diff_notes_disabled = true render 'shared/wikis/diff' end |
#edit ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables
88 89 90 |
# File 'app/controllers/concerns/wiki_actions.rb', line 88 def edit render 'shared/wikis/edit' end |
#history ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/concerns/wiki_actions.rb', line 130 def history if page @page_versions = 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 |
#new ⇒ Object
37 38 39 |
# File 'app/controllers/concerns/wiki_actions.rb', line 37 def new redirect_to wiki_page_path(wiki, SecureRandom.uuid, random_title: true) end |
#pages ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/concerns/wiki_actions.rb', line 42 def pages @wiki_pages = Kaminari.paginate_array( wiki.list_pages(sort: params[:sort], direction: params[:direction]) ).page(params[:page]) @wiki_entries = WikiPage.group_by_directory(@wiki_pages) render 'shared/wikis/pages' end |
#show ⇒ Object
`#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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/concerns/wiki_actions.rb', line 62 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 send_blob(wiki.repository, 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 |
#update ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/concerns/wiki_actions.rb', line 93 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? redirect_to( wiki_page_path(wiki, page), notice: _('Wiki was successfully updated.') ) else render 'shared/wikis/edit' end rescue WikiPage::PageChangedError, WikiPage::PageRenameError => e @error = e render 'shared/wikis/edit' end |