diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index dbed5666..7ed3c4d5 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -115,7 +115,6 @@ class WikiController < ApplicationController def list parse_category - @pages_by_name = @pages_in_category.by_name @page_names_that_are_wanted = @pages_in_category.wanted_pages @pages_that_are_orphaned = @pages_in_category.orphaned_pages end @@ -334,15 +333,15 @@ class WikiController < ApplicationController end def parse_category - @category = @params['category'] @categories = WikiReference.list_categories.sort - page_names_in_category = WikiReference.pages_in_category(@category) - if (page_names_in_category.empty?) + @category = @params['category'] + if @category + @set_name = "category '#{@category}'" + @pages_in_category = WikiReference.pages_in_category(@category).map { |page_name| @web.page(page_name) }.by_name + else + # no category specified, return all pages of the web @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 diff --git a/app/models/page.rb b/app/models/page.rb index 1896ac5f..c5f48d43 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -63,6 +63,10 @@ class Page < ActiveRecord::Base web.select.pages_that_reference(name) end + def wiki_words + wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name } + end + def linked_from web.select.pages_that_link_to(name) end diff --git a/app/models/page_set.rb b/app/models/page_set.rb index 9589b36c..4ac08c00 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -85,10 +85,8 @@ class PageSet < Array def wiki_words self.inject([]) { |wiki_words, page| - wiki_words + page.wiki_references. - select { |ref| ref.link_type != WikiReference::CATEGORY }. - map { |ref| ref.referenced_name } - }.flatten.uniq + wiki_words + page.wiki_words + }.flatten.uniq.sort end end diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index 9f4534a7..4a8b6de6 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -5,9 +5,11 @@ class WikiReference < ActiveRecord::Base INCLUDED_PAGE = 'I' CATEGORY = 'C' AUTHOR = 'A' + FILE = 'F' + WANTED_FILE = 'E' belongs_to :page - validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR] + validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR, FILE, WANTED_FILE] # FIXME all finders below MUST restrict their results to pages belonging to a particular web @@ -37,9 +39,10 @@ class WikiReference < ActiveRecord::Base end def self.pages_in_category(category) - query = 'SELECT name FROM pages JOIN wiki_references ON pages.id = wiki_references.page_id ' + + 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}'" + "AND wiki_references.link_type = '#{CATEGORY}'" + names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] } end @@ -48,10 +51,14 @@ class WikiReference < ActiveRecord::Base connection.select_all(query).map { |row| row['referenced_name'] } end - def wiki_link? + def wiki_word? linked_page? or wanted_page? end + def wiki_link? + linked_page? or wanted_page? or file? or wanted_file? + end + def linked_page? link_type == LINKED_PAGE end @@ -63,5 +70,13 @@ class WikiReference < ActiveRecord::Base def included_page? link_type == INCLUDED_PAGE end + + def file? + link_type == FILE + end + + def wanted_file? + link_type == WANTED_FILE + end end diff --git a/app/views/wiki/list.rhtml b/app/views/wiki/list.rhtml index d891f5a2..e1b584be 100644 --- a/app/views/wiki/list.rhtml +++ b/app/views/wiki/list.rhtml @@ -11,7 +11,7 @@ <% end %>