Commit 85974948e778f5261cc24a2911bd652a91e950da
1 parent
b565cd19
Exists in
master
and in
4 other branches
Wiki: history
Showing
7 changed files
with
41 additions
and
4 deletions
Show diff stats
app/controllers/wikis_controller.rb
| @@ -4,7 +4,11 @@ class WikisController < ApplicationController | @@ -4,7 +4,11 @@ class WikisController < ApplicationController | ||
| 4 | layout "project" | 4 | layout "project" |
| 5 | 5 | ||
| 6 | def show | 6 | def show |
| 7 | - @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last | 7 | + if params[:old_page_id] |
| 8 | + @wiki = @project.wikis.find(params[:old_page_id]) | ||
| 9 | + else | ||
| 10 | + @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last | ||
| 11 | + end | ||
| 8 | respond_to do |format| | 12 | respond_to do |format| |
| 9 | if @wiki | 13 | if @wiki |
| 10 | format.html | 14 | format.html |
| @@ -22,6 +26,7 @@ class WikisController < ApplicationController | @@ -22,6 +26,7 @@ class WikisController < ApplicationController | ||
| 22 | 26 | ||
| 23 | def create | 27 | def create |
| 24 | @wiki = @project.wikis.new(params[:wiki]) | 28 | @wiki = @project.wikis.new(params[:wiki]) |
| 29 | + @wiki.user = current_user | ||
| 25 | 30 | ||
| 26 | respond_to do |format| | 31 | respond_to do |format| |
| 27 | if @wiki.save | 32 | if @wiki.save |
| @@ -31,6 +36,10 @@ class WikisController < ApplicationController | @@ -31,6 +36,10 @@ class WikisController < ApplicationController | ||
| 31 | end | 36 | end |
| 32 | end | 37 | end |
| 33 | end | 38 | end |
| 39 | + | ||
| 40 | + def history | ||
| 41 | + @wikis = @project.wikis.where(:slug => params[:id]).order("created_at") | ||
| 42 | + end | ||
| 34 | 43 | ||
| 35 | def destroy | 44 | def destroy |
| 36 | @wiki = @project.wikis.find(params[:id]) | 45 | @wiki = @project.wikis.find(params[:id]) |
app/models/wiki.rb
| 1 | class Wiki < ActiveRecord::Base | 1 | class Wiki < ActiveRecord::Base |
| 2 | belongs_to :project | 2 | belongs_to :project |
| 3 | + belongs_to :user | ||
| 3 | 4 | ||
| 4 | - validates :content, :title, :presence => true | 5 | + validates :content, :title, :user_id, :presence => true |
| 5 | validates :title, :length => 1..250 | 6 | validates :title, :length => 1..250 |
| 6 | 7 | ||
| 7 | before_update :set_slug | 8 | before_update :set_slug |
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +%h2 Versions | ||
| 2 | +%table | ||
| 3 | + %thead | ||
| 4 | + %tr | ||
| 5 | + %th # | ||
| 6 | + %th last edit | ||
| 7 | + %th created by | ||
| 8 | + %tbody | ||
| 9 | + - @wikis.each_with_index do |wiki_page, i| | ||
| 10 | + %tr | ||
| 11 | + %td= i + 1 | ||
| 12 | + %td= link_to wiki_page.created_at.to_s(:short), project_wiki_path(@project, wiki_page, :old_page_id => wiki_page.id) | ||
| 13 | + %td= wiki_page.user.name | ||
| 14 | + |
app/views/wikis/show.html.haml
| 1 | %h3 | 1 | %h3 |
| 2 | = @wiki.title | 2 | = @wiki.title |
| 3 | - if can? current_user, :write_wiki, @project | 3 | - if can? current_user, :write_wiki, @project |
| 4 | + = link_to history_project_wiki_path(@project, @wiki), :class => "right btn small" do | ||
| 5 | + History | ||
| 4 | = link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do | 6 | = link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do |
| 5 | Edit | 7 | Edit |
| 6 | 8 |
config/routes.rb
| @@ -56,7 +56,11 @@ Gitlab::Application.routes.draw do | @@ -56,7 +56,11 @@ Gitlab::Application.routes.draw do | ||
| 56 | get "files" | 56 | get "files" |
| 57 | end | 57 | end |
| 58 | 58 | ||
| 59 | - resources :wikis, :only => [:show, :edit, :destroy, :create] | 59 | + resources :wikis, :only => [:show, :edit, :destroy, :create] do |
| 60 | + member do | ||
| 61 | + get "history" | ||
| 62 | + end | ||
| 63 | + end | ||
| 60 | 64 | ||
| 61 | resource :repository do | 65 | resource :repository do |
| 62 | member do | 66 | member do |
db/schema.rb
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | ||
| 14 | -ActiveRecord::Schema.define(:version => 20120219140810) do | 14 | +ActiveRecord::Schema.define(:version => 20120219193300) do |
| 15 | 15 | ||
| 16 | create_table "issues", :force => true do |t| | 16 | create_table "issues", :force => true do |t| |
| 17 | t.string "title" | 17 | t.string "title" |
| @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(:version => 20120219140810) do | @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(:version => 20120219140810) do | ||
| 166 | t.datetime "created_at", :null => false | 166 | t.datetime "created_at", :null => false |
| 167 | t.datetime "updated_at", :null => false | 167 | t.datetime "updated_at", :null => false |
| 168 | t.string "slug" | 168 | t.string "slug" |
| 169 | + t.integer "user_id" | ||
| 169 | end | 170 | end |
| 170 | 171 | ||
| 171 | end | 172 | end |