Class: Projects::WikisController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects/wikis_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#createObject


57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/projects/wikis_controller.rb', line 57

def create
  @page = WikiPages::CreateService.new(@project, current_user, wiki_params).execute

  if @page.persisted?
    redirect_to(
      namespace_project_wiki_path(@project.namespace, @project, @page),
      notice: 'Wiki was successfully updated.'
    )
  else
    render action: "edit"
  end
end

#destroyObject


81
82
83
84
85
86
87
88
89
# File 'app/controllers/projects/wikis_controller.rb', line 81

def destroy
  @page = @project_wiki.find_page(params[:id])
  @page.delete if @page

  redirect_to(
    namespace_project_wiki_path(@project.namespace, @project, :home),
    notice: "Page was successfully deleted"
  )
end

#editObject


38
39
40
# File 'app/controllers/projects/wikis_controller.rb', line 38

def edit
  @page = @project_wiki.find_page(params[:id])
end

#git_accessObject


105
106
# File 'app/controllers/projects/wikis_controller.rb', line 105

def git_access
end

#historyObject


70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/projects/wikis_controller.rb', line 70

def history
  @page = @project_wiki.find_page(params[:id])

  unless @page
    redirect_to(
      namespace_project_wiki_path(@project.namespace, @project, :home),
      notice: "Page not found"
    )
  end
end

#markdown_previewObject


91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/projects/wikis_controller.rb', line 91

def markdown_preview
  text = params[:text]

  ext = Gitlab::ReferenceExtractor.new(@project, current_user, current_user)
  ext.analyze(text)

  render json: {
    body: view_context.markdown(text, pipeline: :wiki, project_wiki: @project_wiki),
    references: {
      users: ext.users.map(&:username)
    }
  }
end

#pagesObject


9
10
11
# File 'app/controllers/projects/wikis_controller.rb', line 9

def pages
  @wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page])
end

#showObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/projects/wikis_controller.rb', line 13

def show
  @page = @project_wiki.find_page(params[:id], params[:version_id])

  if @page
    render 'show'
  elsif file = @project_wiki.find_file(params[:id], params[:version_id])
    if file.on_disk?
      send_file file.on_disk_path, disposition: 'inline'
    else
      send_data(
        file.raw_data,
        type: file.mime_type,
        disposition: 'inline',
        filename: file.name
      )
    end
  else
    return render('empty') unless can?(current_user, :create_wiki, @project)
    @page = WikiPage.new(@project_wiki)
    @page.title = params[:id]

    render 'edit'
  end
end

#updateObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/projects/wikis_controller.rb', line 42

def update
  return render('empty') unless can?(current_user, :create_wiki, @project)

  @page = @project_wiki.find_page(params[:id])

  if @page = WikiPages::UpdateService.new(@project, current_user, wiki_params).execute(@page)
    redirect_to(
      namespace_project_wiki_path(@project.namespace, @project, @page),
      notice: 'Wiki was successfully updated.'
    )
  else
    render 'edit'
  end
end