[FIXES BUILD] Fixed categories behavior and added id generation in import_storage. Something is still wrong with orphaned pages though

This commit is contained in:
Alexey Verkhovsky 2005-09-11 16:49:08 +00:00
parent 303622341b
commit c4f593151e
12 changed files with 149 additions and 66 deletions

View file

@ -289,20 +289,13 @@ class WikiController < ApplicationController
def parse_category
@category = @params['category']
@categories = []
@pages_in_category = @web.select do |page|
# FIXME: was PageRenderer.new(page.revisions.last).display_content.find_chunks(Category),
# heinously slow
page_categories = []
page_categories = page_categories.map { |cat| cat.list }.flatten
page_categories.each {|c| @categories << c unless @categories.include? c }
page_categories.include?(@category)
end
@categories.sort!
if (@pages_in_category.empty?)
@pages_in_category = PageSet.new(@web).by_name
@categories = WikiReference.list_categories.sort
page_names_in_category = WikiReference.pages_in_category(@category)
if (page_names_in_category.empty?)
@pages_in_category = @web.select_all.by_name
@set_name = 'the web'
else
@pages_in_category = @web.select { |page| page_names_in_category.include?(page.name) }.by_name
@set_name = "category '#{@category}'"
end
end

View file

@ -1,7 +1,7 @@
class Page < ActiveRecord::Base
belongs_to :web
has_many :revisions, :order => 'id'
has_many :wiki_references, :order => 'referenced_page_name'
has_many :wiki_references, :order => 'referenced_name'
has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
def revise(content, time, author, renderer)
@ -15,7 +15,7 @@ class Page < ActiveRecord::Base
# Try to render content to make sure that markup engine can take it,
renderer.revision = Revision.new(
:page => self, :content => content, :author => author, :revised_at => time)
:page => self, :content => content, :author => author, :revised_at => time)
renderer.display_content
# A user may change a page, look at it and make some more changes - several times.
@ -25,7 +25,7 @@ class Page < ActiveRecord::Base
if (revisions_size > 0) && continous_revision?(time, author)
current_revision.update_attributes(:content => content, :revised_at => time)
else
Revision.create(:page => self, :content => content, :author => author, :revised_at => time)
revisions.create(:content => content, :author => author, :revised_at => time)
end
save
self

View file

@ -3,13 +3,13 @@ class PageObserver < ActiveRecord::Observer
def after_create(page)
WikiReference.update_all("link_type = '#{WikiReference::LINKED_PAGE}'",
['referenced_page_name = ?', page.name])
['referenced_name = ?', page.name])
end
def before_destroy(page)
WikiReference.delete_all ['page_id = ?', page.id]
WikiReference.update_all("link_type = '#{WikiReference::WANTED_PAGE}'",
['referenced_page_name = ?', page.name])
['referenced_name = ?', page.name])
end
end

View file

@ -82,7 +82,9 @@ class PageSet < Array
def wiki_words
self.inject([]) { |wiki_words, page|
wiki_words + page.wiki_references.map { |ref| ref.referenced_page_name }
wiki_words + page.wiki_references.
select { |ref| ref.link_type != WikiReference::CATEGORY }.
map { |ref| ref.referenced_name }
}.flatten.uniq
end

View file

@ -56,6 +56,10 @@ class Web < ActiveRecord::Base
PageSet.new(self, pages, condition)
end
def select_all
PageSet.new(self, pages, nil)
end
private
# Returns an array of all the wiki words in any current revision

View file

@ -3,9 +3,12 @@ class WikiReference < ActiveRecord::Base
LINKED_PAGE = 'L'
WANTED_PAGE = 'W'
INCLUDED_PAGE = 'I'
CATEGORY = 'C'
belongs_to :page
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE]
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY]
# FIXME all finders below MUST restrict their results to pages belonging to a particular web
def self.link_type(web, page_name)
web.has_page?(page_name) ? LINKED_PAGE : WANTED_PAGE
@ -13,24 +16,37 @@ class WikiReference < ActiveRecord::Base
def self.pages_that_reference(page_name)
query = 'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' +
'WHERE wiki_references.referenced_page_name = ?'
'WHERE wiki_references.referenced_name = ?' +
"AND wiki_references.link_type in ('#{LINKED_PAGE}', '#{WANTED_PAGE}', '#{INCLUDED_PAGE}')"
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
end
def self.pages_that_link_to(page_name)
query = 'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' +
'WHERE wiki_references.referenced_page_name = ? ' +
'WHERE wiki_references.referenced_name = ? ' +
"AND wiki_references.link_type in ('#{LINKED_PAGE}', '#{WANTED_PAGE}')"
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
end
def self.pages_that_include(page_name)
query = 'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' +
'WHERE wiki_references.referenced_page_name = ? ' +
'WHERE wiki_references.referenced_name = ? ' +
"AND wiki_references.link_type = '#{INCLUDED_PAGE}'"
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
end
def self.pages_in_category(category)
query = 'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' +
'WHERE wiki_references.referenced_name = ? ' +
"AND wiki_references.link_type = '#{CATEGORY}'"
names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] }
end
def self.list_categories
query = "SELECT DISTINCT referenced_name FROM wiki_references WHERE link_type = '#{CATEGORY}'"
connection.select_all(query).map { |row| row['referenced_name'] }
end
def wiki_link?
linked_page? or wanted_page?
end