Permalink
Browse files

Merge branch 'master' of git://github.com/queso/signal-wiki

Conflicts:

	app/controllers/pages_controller.rb
	app/helpers/pages_helper.rb
	app/models/page.rb
	app/views/pages/revision.html.erb
	app/views/pages/show.html.erb
	db/schema.rb
  • Loading branch information...
Jeremy McAnally
Jeremy McAnally committed Mar 17, 2008
2 parents 81e876f + e28d252 commit 888796fb399fd73897011ebf6d723cbeaaa8caff
View
@@ -5,3 +5,6 @@ tmp/**/*
.DS_Store
doc/api
doc/app
+db/*.db
+db/*.sqlite3
+index/*
View
3 README
@@ -17,6 +17,7 @@ Enjoy :)
* json
* ruby-openid
-* redcloth
+* ruby-yadis
+* RedCloth
@@ -8,18 +8,18 @@ class PagesController < ApplicationController
# GET /pages
# GET /pages.xml
def index
- redirect_to wiki_page_url("home")
-
- #respond_to do |format|
- # format.html # index.html.erb
- # format.xml { render :xml => @pages }
- #end
+ @pages = site.pages.find(:all, :limit => 20, :order => "updated_at DESC")
+ # todo: paginate
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @pages }
+ end
end
# GET /pages/1
# GET /pages/1.xml
def show
- @page = Page.find_by_permalink(params[:id] || "home")
+ @page = site.pages.find_by_permalink(params[:id] || "home")
if @page
@@ -34,8 +34,8 @@ def show
end
def revision
- @page = Page.find_by_permalink(params[:id])
- @page = Page.find_version(@page.id, params[:version])
+ @page = site.pages.find_by_permalink(params[:id])
+ @page = site.pages.find_version(@page.id, params[:version])
respond_to do |format|
format.html
@@ -45,7 +45,7 @@ def revision
# GET /pages/new
# GET /pages/new.xml
def new
- @page = Page.new(:title => session[:new_title].to_s.gsub("-", " ").capitalize, :permalink => session[:new_title])
+ @page = site.pages.new(:title => session[:new_title].to_s.gsub("-", " ").capitalize, :permalink => session[:new_title])
@attachments = Attachment.find_parent(:all)
@button_text = "Add this page"
respond_to do |format|
@@ -56,15 +56,15 @@ def new
# GET /pages/1/edit
def edit
- @page = Page.find_by_permalink(params[:id])
+ @page = site.pages.find_by_permalink(params[:id])
@attachments = Attachment.find_parent(:all)
@button_text = "Save this version"
end
# POST /pages
# POST /pages.xml
def create
- @page = Page.new(params[:page])
+ @page = site.pages.new(params[:page])
@page.request = request
@page.user = logged_in? ? current_user : User.new
@@ -83,7 +83,7 @@ def create
# PUT /pages/1
# PUT /pages/1.xml
def update
- @page = Page.find_by_permalink(params[:id])
+ @page = site.pages.find_by_permalink(params[:id])
@page.request = request
@page.user = logged_in? ? current_user : User.new
@@ -100,7 +100,7 @@ def update
end
def rollback
- @page = Page.find_by_permalink(params[:id])
+ @page = site.pages.find_by_permalink(params[:id])
@page.revert_to!(params[:version])
expire_page("/#{@page.permalink}")
respond_to do |format|
@@ -111,7 +111,7 @@ def rollback
end
def search
- @pages = Page.find_with_index("#{params[:query]}")
+ @pages = site.pages.find_with_index("#{params[:query]}")
respond_to do |format|
format.html
format.xml
@@ -122,26 +122,20 @@ def search
# DELETE /pages/1
# DELETE /pages/1.xml
def destroy
- @page = Page.find_by_permalink(params[:id]).destroy
+ @page = site.pages.find_by_permalink(params[:id]).destroy
respond_to do |format|
format.html { redirect_to(pages_url) }
format.xml { head :ok }
end
end
def lock
- @page = Page.find_by_permalink(params[:id])
+ @page = site.pages.find_by_permalink(params[:id])
- Page.without_revision do
- if @page.locked?
- @page.locked = false
- RAILS_DEFAULT_LOGGER.info "UNLOCK"
- else
- @page.locked = true
- RAILS_DEFAULT_LOGGER.info "LOCK"
- end
-
- @page.save
+ if @page.locked?
+ @page.unlock
+ else
+ @page.lock
end
respond_to do |format|
@@ -151,7 +145,7 @@ def lock
end
def check_private
- @page = Page.find_by_permalink(params[:id])
+ @page = site.pages.find_by_permalink(params[:id])
return unless @page
if @page.private_page
login_required
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: attachments
#
View
@@ -0,0 +1,18 @@
+# == Schema Information
+# Schema version: 13
+#
+# Table name: links
+#
+# id :integer not null, primary key
+# from_page_id :integer
+# to_page_id :integer
+# created_at :datetime
+# updated_at :datetime
+#
+
+class Link < ActiveRecord::Base
+ belongs_to :to_page, :class_name => "Page"
+ belongs_to :from_page, :class_name => "Page"
+
+ validates_presence_of :to_page_id, :from_page_id
+end
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: pages
#
@@ -12,21 +12,29 @@
# updated_at :datetime
# private_page :boolean
# version :integer
+# site_id :integer
+# locked :boolean
#
class Page < ActiveRecord::Base
belongs_to :user
+ belongs_to :site
+ has_many :inbound_links, :class_name => "Link", :foreign_key => "to_page_id"
+ has_many :outbound_links, :class_name => "Link", :foreign_key => "from_page_id"
acts_as_versioned
- self.non_versioned_columns << 'locked'
+ self.non_versioned_columns << 'locked_at'
attr_accessor :ip, :agent, :referrer
acts_as_indexed :fields => [:title, :body, :author]
validates_presence_of :title
before_save :set_permalink
-
+ before_update :set_links
+ after_create :set_links
+ validates_presence_of :title, :body
+ validate_on_update :updatable
+
def validate
- site = Site.find(:first)
if site.akismet_key? && is_spam?(site)
errors.add_to_base "Your comment was marked as spam, please contact the site admin if you feel this was a mistake."
end
@@ -51,6 +59,20 @@ def set_permalink
end
end
+ def set_links
+ Link.transaction do
+ # outbound_links.delete_all
+ body.scan(/\[\[(.*?)\]\]/).each do |link|
+ link = link[0].downcase.gsub(' ', '-')
+ if page = site.pages.find_by_permalink(link)
+ Link.create! :from_page_id => id, :to_page_id => page.id
+ else
+ logger.warn "We couldn't find links for #{link}"
+ end
+ end
+ end
+ end
+
def to_param
self.permalink
end
@@ -59,8 +81,32 @@ def author
(user && user.login) ? user.login.to_s.capitalize : "Anonymous"
end
- def self.find_all_by_wiki_word(wiki_word)
- pages = self.find(:all)
+ def lock
+ self.without_revision do
+ self.update_attribute(:locked_at, Time.now)
+ end
+ RAILS_DEFAULT_LOGGER.info "LOCKED #{self.permalink}"
+ end
+
+ def unlock
+ self.without_revision do
+ self.update_attribute(:locked_at, nil)
+ end
+ RAILS_DEFAULT_LOGGER.info "UNLOCKED #{self.permalink}"
+ end
+
+ def self.find_all_by_wiki_word(wiki_word, site = nil)
+ site ||= Site.find(:first)
+ pages = site.pages.find(:all)
pages.select {|p| p.body =~ /#{wiki_word}/i}
end
+
+ private
+
+ def updatable
+ unless self.locked_at.nil?
+ errors.add("page", "is locked from editing.")
+ end
+ end
+
end
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: sites
#
@@ -15,7 +15,8 @@
#
class Site < ActiveRecord::Base
-
+ has_many :pages
+
def title
super || "Signal"
end
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 10
+# Schema version: 13
#
# Table name: users
#
@@ -3,7 +3,7 @@
<ul>
<% for page in @pages %>
- <li><%= page.title %></li>
+ <li><%= link_to page.title, page %></li>
<% end %>
</ul>
@@ -11,6 +11,7 @@
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.previous.version))) if @page.previous %></li>
<li><%= link_to('View next revision', revision_page_url(:id => @page.permalink, :version => (@page.next.version))) if @page.next %></li>
<li><%= link_to "Rollback to this revision", rollback_page_url(:id => @page.permalink, :version => (@page.version)) unless current_revision(@page.page_id, @page.version) || (Page.find(@page.page_id).locked? && !current_user.admin?) %></li>
+ <%# FIXME Clean up this revision link logic %>
<li><%= link_to 'Return to current revision', wiki_page_url(@page.permalink) %></li>
</ul>
<% end -%>
@@ -12,8 +12,14 @@
<li><%= wiki_link("#{@page.title} Discussion", 'Discuss this page') %></li>
<li><%= link_to((@page.locked? ? "Unlock this page" : "Lock this page"), lock_page_path(@page)) if logged_in? && current_user.admin? %></li>
<li><%= link_to("Delete this page and all revisions", page_path(@page), :method => :delete, :confirm => "Are you sure you want to delete this page and *all* of its revisions?") if logged_in? && current_user.admin? && @page.permalink != 'home' %></li>
-
<li><%= link_to('View previous revision', revision_page_url(:id => @page.permalink, :version => (@page.version - 1) )) if (@page.versions.size > 1 && @page.version > 1) %></li>
<li><%= link_to 'Return to home', pages_path unless @page.permalink == "home" %></li>
+ <li>Inbound links:
+ <ul>
+ <% @page.inbound_links.each do |link| -%>
+ <li><%= link_to link.from_page.title, link.from_page %>
+ <% end %>
+ </ul>
+ </li>
</ul>
<% end -%>
@@ -0,0 +1,14 @@
+class CreateLinks < ActiveRecord::Migration
+ def self.up
+ create_table :links do |t|
+ t.integer :from_page_id
+ t.integer :to_page_id
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :links
+ end
+end
@@ -0,0 +1,12 @@
+class PageSiteFk < ActiveRecord::Migration
+ def self.up
+ add_column :pages, :site_id, :integer
+ add_column :page_versions, :site_id, :integer
+ Page.update_all 'site_id=1'
+ end
+
+ def self.down
+ remove_column :pages, :site_id
+ remove_column :page_versions, :site_id
+ end
+end
@@ -0,0 +1,9 @@
+class AddLockingToPages < ActiveRecord::Migration
+ def self.up
+ add_column :pages, :locked_at, :datetime
+ end
+
+ def self.down
+ remove_column :pages, :locked_at
+ end
+end
Oops, something went wrong.

0 comments on commit 888796f

Please sign in to comment.