diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 787f8c6a..13d76598 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -46,7 +46,8 @@ class WikiController < ApplicationController # Within a single web --------------------------------------------------------- def authors - @authors = @web.select.authors.sort + @page_names_by_author = @web.page_names_by_author + @authors = @page_names_by_author.keys.sort end def export_html diff --git a/app/models/page.rb b/app/models/page.rb index a44b5558..e45b609e 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -16,7 +16,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) - renderer.display_content + renderer.display_content(update_references = true) # A user may change a page, look at it and make some more changes - several times. # Not to record every such iteration as a new revision, if the previous revision was done @@ -59,10 +59,6 @@ class Page < ActiveRecord::Base end end - def authors - revisions.collect { |rev| rev.author } - end - def references web.select.pages_that_reference(name) end diff --git a/app/models/page_set.rb b/app/models/page_set.rb index 873e4c49..9589b36c 100644 --- a/app/models/page_set.rb +++ b/app/models/page_set.rb @@ -46,6 +46,9 @@ class PageSet < Array end def pages_authored_by(author) + all_pages_authored_by_the_author = + Page.connection.select_all(sanitize_sql([ + "SELECT page_id FROM revision WHERE author = '?'", author])) self.select { |page| page.authors.include?(author) } end @@ -59,7 +62,7 @@ class PageSet < Array # references and so cannot be orphans # Pages that refer to themselves and have no links from outside are oprphans. def orphaned_pages - never_orphans = web.select.authors + ['HomePage'] + never_orphans = web.authors + ['HomePage'] self.select { |page| if never_orphans.include? page.name false @@ -88,8 +91,4 @@ class PageSet < Array }.flatten.uniq end - def authors - self.inject([]) { |authors, page| authors << page.authors }.flatten.uniq.sort - end - end diff --git a/app/models/web.rb b/app/models/web.rb index 65a97832..c38c8061 100644 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -21,7 +21,11 @@ class Web < ActiveRecord::Base end def authors - select.authors + connection.select_all( + 'SELECT DISTINCT r.author AS author ' + + 'FROM revisions r ' + + 'JOIN pages p ON p.id = r.page_id ' + + 'ORDER by 1').collect { |row| row['author'] } end def categories @@ -44,6 +48,21 @@ class Web < ActiveRecord::Base read_attribute('markup').to_sym end + def page_names_by_author + connection.select_all( + 'SELECT DISTINCT r.author AS author, p.name AS page_name ' + + 'FROM revisions r ' + + 'JOIN pages p ON r.page_id = p.id ' + + "WHERE p.web_id = #{self.id} " + + 'ORDER by p.name' + ).inject({}) { |result, row| + author, page_name = row['author'], row['page_name'] + result[author] = [] unless result.has_key?(author) + result[author] << page_name + result + } + end + def remove_pages(pages_to_be_removed) pages_to_be_removed.each { |p| p.destroy } end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 773fd011..e0da8644 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -1,4 +1,5 @@ class Wiki + cattr_accessor :storage_path, :logger self.storage_path = "#{RAILS_ROOT}/storage/" self.logger = RAILS_DEFAULT_LOGGER diff --git a/app/models/wiki_reference.rb b/app/models/wiki_reference.rb index 6ebe1d55..9f4534a7 100644 --- a/app/models/wiki_reference.rb +++ b/app/models/wiki_reference.rb @@ -4,9 +4,10 @@ class WikiReference < ActiveRecord::Base WANTED_PAGE = 'W' INCLUDED_PAGE = 'I' CATEGORY = 'C' + AUTHOR = 'A' belongs_to :page - validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY] + validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR] # FIXME all finders below MUST restrict their results to pages belonging to a particular web diff --git a/app/views/wiki/authors.rhtml b/app/views/wiki/authors.rhtml index 97eb5c9d..57f529ee 100644 --- a/app/views/wiki/authors.rhtml +++ b/app/views/wiki/authors.rhtml @@ -5,7 +5,7 @@