summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2012-02-19 21:52:05 +0200
committerValery Sizov <vsv2711@gmail.com>2012-02-19 21:52:05 +0200
commit85974948e778f5261cc24a2911bd652a91e950da (patch)
tree0554502fbf8545ad8692ed8e1402ac3c26cf8e35
parentb565cd1972b32071420c51004ba78b6c22cb5742 (diff)
downloadgitlab-ce-85974948e778f5261cc24a2911bd652a91e950da.tar.gz
Wiki: history
-rw-r--r--app/controllers/wikis_controller.rb11
-rw-r--r--app/models/wiki.rb3
-rw-r--r--app/views/wikis/history.html.haml14
-rw-r--r--app/views/wikis/show.html.haml2
-rw-r--r--config/routes.rb6
-rw-r--r--db/migrate/20120219193300_add_user_to_wiki.rb6
-rw-r--r--db/schema.rb3
7 files changed, 41 insertions, 4 deletions
diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb
index 5d3f72a165e..9a1638f2e4a 100644
--- a/app/controllers/wikis_controller.rb
+++ b/app/controllers/wikis_controller.rb
@@ -4,7 +4,11 @@ class WikisController < ApplicationController
layout "project"
def show
- @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
+ if params[:old_page_id]
+ @wiki = @project.wikis.find(params[:old_page_id])
+ else
+ @wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
+ end
respond_to do |format|
if @wiki
format.html
@@ -22,6 +26,7 @@ class WikisController < ApplicationController
def create
@wiki = @project.wikis.new(params[:wiki])
+ @wiki.user = current_user
respond_to do |format|
if @wiki.save
@@ -31,6 +36,10 @@ class WikisController < ApplicationController
end
end
end
+
+ def history
+ @wikis = @project.wikis.where(:slug => params[:id]).order("created_at")
+ end
def destroy
@wiki = @project.wikis.find(params[:id])
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index b1ecc06e132..62ac4cb8a9a 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -1,7 +1,8 @@
class Wiki < ActiveRecord::Base
belongs_to :project
+ belongs_to :user
- validates :content, :title, :presence => true
+ validates :content, :title, :user_id, :presence => true
validates :title, :length => 1..250
before_update :set_slug
diff --git a/app/views/wikis/history.html.haml b/app/views/wikis/history.html.haml
new file mode 100644
index 00000000000..513f3777bf4
--- /dev/null
+++ b/app/views/wikis/history.html.haml
@@ -0,0 +1,14 @@
+%h2 Versions
+%table
+ %thead
+ %tr
+ %th #
+ %th last edit
+ %th created by
+ %tbody
+ - @wikis.each_with_index do |wiki_page, i|
+ %tr
+ %td= i + 1
+ %td= link_to wiki_page.created_at.to_s(:short), project_wiki_path(@project, wiki_page, :old_page_id => wiki_page.id)
+ %td= wiki_page.user.name
+
diff --git a/app/views/wikis/show.html.haml b/app/views/wikis/show.html.haml
index 59c1778d0bc..97e1231cbaa 100644
--- a/app/views/wikis/show.html.haml
+++ b/app/views/wikis/show.html.haml
@@ -1,6 +1,8 @@
%h3
= @wiki.title
- if can? current_user, :write_wiki, @project
+ = link_to history_project_wiki_path(@project, @wiki), :class => "right btn small" do
+ History
= link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do
Edit
diff --git a/config/routes.rb b/config/routes.rb
index ef2ff709c9f..eae5b7ea1c9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -56,7 +56,11 @@ Gitlab::Application.routes.draw do
get "files"
end
- resources :wikis, :only => [:show, :edit, :destroy, :create]
+ resources :wikis, :only => [:show, :edit, :destroy, :create] do
+ member do
+ get "history"
+ end
+ end
resource :repository do
member do
diff --git a/db/migrate/20120219193300_add_user_to_wiki.rb b/db/migrate/20120219193300_add_user_to_wiki.rb
new file mode 100644
index 00000000000..8a6c0a06ef0
--- /dev/null
+++ b/db/migrate/20120219193300_add_user_to_wiki.rb
@@ -0,0 +1,6 @@
+class AddUserToWiki < ActiveRecord::Migration
+ def change
+ add_column :wikis, :user_id, :integer
+
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 752da4b5449..c32df7ea198 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120219140810) do
+ActiveRecord::Schema.define(:version => 20120219193300) do
create_table "issues", :force => true do |t|
t.string "title"
@@ -166,6 +166,7 @@ ActiveRecord::Schema.define(:version => 20120219140810) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "slug"
+ t.integer "user_id"
end
end