Commit c4b1a5f5ea338d9be6b24f29a562b567b3c2598b
1 parent
0050c07f
Exists in
spb-stable
and in
2 other branches
Allow nested files in wiki.
Showing
4 changed files
with
20 additions
and
4 deletions
Show diff stats
app/models/project_wiki.rb
| @@ -64,7 +64,8 @@ class ProjectWiki | @@ -64,7 +64,8 @@ class ProjectWiki | ||
| 64 | # | 64 | # |
| 65 | # Returns an initialized WikiPage instance or nil | 65 | # Returns an initialized WikiPage instance or nil |
| 66 | def find_page(title, version = nil) | 66 | def find_page(title, version = nil) |
| 67 | - if page = wiki.page(title, version) | 67 | + page_title, page_dir = page_title_and_dir(title) |
| 68 | + if page = wiki.page(page_title, version, page_dir) | ||
| 68 | WikiPage.new(self, page, true) | 69 | WikiPage.new(self, page, true) |
| 69 | else | 70 | else |
| 70 | nil | 71 | nil |
| @@ -90,6 +91,12 @@ class ProjectWiki | @@ -90,6 +91,12 @@ class ProjectWiki | ||
| 90 | wiki.delete_page(page, commit_details(:deleted, message, page.title)) | 91 | wiki.delete_page(page, commit_details(:deleted, message, page.title)) |
| 91 | end | 92 | end |
| 92 | 93 | ||
| 94 | + def page_title_and_dir(title) | ||
| 95 | + title_array = title.split("/") | ||
| 96 | + title = title_array.pop | ||
| 97 | + [title.gsub(/\.[^.]*$/, ""), title_array.join("/")] | ||
| 98 | + end | ||
| 99 | + | ||
| 93 | private | 100 | private |
| 94 | 101 | ||
| 95 | def create_repo! | 102 | def create_repo! |
app/models/wiki_page.rb
| @@ -175,8 +175,17 @@ class WikiPage | @@ -175,8 +175,17 @@ class WikiPage | ||
| 175 | end | 175 | end |
| 176 | 176 | ||
| 177 | def save(method, *args) | 177 | def save(method, *args) |
| 178 | + | ||
| 178 | if valid? && wiki.send(method, *args) | 179 | if valid? && wiki.send(method, *args) |
| 179 | - @page = wiki.wiki.paged(title) | 180 | + |
| 181 | + page_details = if method == :update_page | ||
| 182 | + @page.path | ||
| 183 | + else | ||
| 184 | + title | ||
| 185 | + end | ||
| 186 | + | ||
| 187 | + page_title, page_dir = wiki.page_title_and_dir(page_details) | ||
| 188 | + @page = wiki.wiki.paged(page_title, page_dir) | ||
| 180 | 189 | ||
| 181 | set_attributes | 190 | set_attributes |
| 182 | 191 |
app/views/projects/wikis/_new.html.haml
| @@ -9,6 +9,6 @@ | @@ -9,6 +9,6 @@ | ||
| 9 | %span Page slug | 9 | %span Page slug |
| 10 | = text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'form-control', required: true, :'data-wikis-path' => project_wikis_path(@project) | 10 | = text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'form-control', required: true, :'data-wikis-path' => project_wikis_path(@project) |
| 11 | %p.hint | 11 | %p.hint |
| 12 | - Please don't use spaces and slashes | 12 | + Please don't use spaces. |
| 13 | .modal-footer | 13 | .modal-footer |
| 14 | = link_to 'Build', '#', class: 'build-new-wiki btn btn-create' | 14 | = link_to 'Build', '#', class: 'build-new-wiki btn btn-create' |
config/routes.rb
| @@ -204,7 +204,7 @@ Gitlab::Application.routes.draw do | @@ -204,7 +204,7 @@ Gitlab::Application.routes.draw do | ||
| 204 | end | 204 | end |
| 205 | end | 205 | end |
| 206 | 206 | ||
| 207 | - resources :wikis, only: [:show, :edit, :destroy, :create], constraints: {id: /[a-zA-Z.0-9_\-]+/} do | 207 | + resources :wikis, only: [:show, :edit, :destroy, :create], constraints: {id: /[a-zA-Z.0-9_\-\/]+/} do |
| 208 | collection do | 208 | collection do |
| 209 | get :pages | 209 | get :pages |
| 210 | put ':id' => 'wikis#update' | 210 | put ':id' => 'wikis#update' |