Exclude links to files and pages from All Pages (so that they don't show up in Wanted Pages etc).

This commit is contained in:
Alexey Verkhovsky 2005-11-14 11:00:46 +00:00
parent 42098e0a9f
commit 614a48c6ff
7 changed files with 54 additions and 36 deletions

View file

@ -115,7 +115,6 @@ class WikiController < ApplicationController
def list def list
parse_category parse_category
@pages_by_name = @pages_in_category.by_name
@page_names_that_are_wanted = @pages_in_category.wanted_pages @page_names_that_are_wanted = @pages_in_category.wanted_pages
@pages_that_are_orphaned = @pages_in_category.orphaned_pages @pages_that_are_orphaned = @pages_in_category.orphaned_pages
end end
@ -334,15 +333,15 @@ class WikiController < ApplicationController
end end
def parse_category def parse_category
@category = @params['category']
@categories = WikiReference.list_categories.sort @categories = WikiReference.list_categories.sort
page_names_in_category = WikiReference.pages_in_category(@category) @category = @params['category']
if (page_names_in_category.empty?) 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 @pages_in_category = @web.select_all.by_name
@set_name = 'the web' @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
end end

View file

@ -63,6 +63,10 @@ class Page < ActiveRecord::Base
web.select.pages_that_reference(name) web.select.pages_that_reference(name)
end end
def wiki_words
wiki_references.select { |ref| ref.wiki_word? }.map { |ref| ref.referenced_name }
end
def linked_from def linked_from
web.select.pages_that_link_to(name) web.select.pages_that_link_to(name)
end end

View file

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

View file

@ -5,9 +5,11 @@ class WikiReference < ActiveRecord::Base
INCLUDED_PAGE = 'I' INCLUDED_PAGE = 'I'
CATEGORY = 'C' CATEGORY = 'C'
AUTHOR = 'A' AUTHOR = 'A'
FILE = 'F'
WANTED_FILE = 'E'
belongs_to :page 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 # FIXME all finders below MUST restrict their results to pages belonging to a particular web
@ -37,9 +39,10 @@ class WikiReference < ActiveRecord::Base
end end
def self.pages_in_category(category) 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 = ? ' + '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'] } names = connection.select_all(sanitize_sql([query, category])).map { |row| row['name'] }
end end
@ -48,10 +51,14 @@ class WikiReference < ActiveRecord::Base
connection.select_all(query).map { |row| row['referenced_name'] } connection.select_all(query).map { |row| row['referenced_name'] }
end end
def wiki_link? def wiki_word?
linked_page? or wanted_page? linked_page? or wanted_page?
end end
def wiki_link?
linked_page? or wanted_page? or file? or wanted_file?
end
def linked_page? def linked_page?
link_type == LINKED_PAGE link_type == LINKED_PAGE
end end
@ -64,4 +71,12 @@ class WikiReference < ActiveRecord::Base
link_type == INCLUDED_PAGE link_type == INCLUDED_PAGE
end end
def file?
link_type == FILE
end
def wanted_file?
link_type == WANTED_FILE
end
end end

View file

@ -11,7 +11,7 @@
<% end %> <% end %>
<ul> <ul>
<% @pages_by_name.each do |page| %> <% @pages_in_category.each do |page| %>
<li> <li>
<%= link_to_existing_page page, truncate(page.plain_name, 35) %> <%= link_to_existing_page page, truncate(page.plain_name, 35) %>
</li> </li>
@ -19,7 +19,7 @@
<% if @web.count_pages? %> <% if @web.count_pages? %>
<% total_chars = @pages_in_category.characters %> <% total_chars = @pages_in_category.characters %>
<p><small>All content: <%= total_chars %> chars / <%= sprintf("%-.1f", (total_chars / 2275 )) %> pages</small></p> <p><small>All content: <%= total_chars %> chars / approx. <%= sprintf("%-.1f", (total_chars / 2275 )) %> printed pages</small></p>
<% end %> <% end %>
</div> </div>

View file

@ -66,11 +66,16 @@ class PageRenderer
# Returns an array of all the WikiWords present in the content of this revision. # Returns an array of all the WikiWords present in the content of this revision.
def wiki_words def wiki_words
unless @wiki_words_cache @wiki_words_cache ||= find_wiki_words(display_content)
wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
@wiki_words_cache = wiki_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
end end
@wiki_words_cache
def find_wiki_words(rendering_result)
wiki_links = rendering_result.find_chunks(WikiChunk::WikiLink)
# Exclude backslash-escaped wiki words, such as \WikiWord, as well as links to files
# and pictures, such as [[foo.txt:file]] or [[foo.jpg:pic]]
wiki_links.delete_if { |link| link.escaped? or [:pic, :file].include?(link.link_type) }
# convert to the list of unique page names
wiki_links.map { |link| ( link.page_name ) }.uniq
end end
# Returns an array of all the WikiWords present in the content of this revision. # Returns an array of all the WikiWords present in the content of this revision.
@ -88,12 +93,8 @@ class PageRenderer
private private
def render(options = {}) def render(options = {})
rendering_result = WikiContent.new(@revision, @@url_generator, options).render! rendering_result = WikiContent.new(@revision, @@url_generator, options).render!
update_references(rendering_result) if options[:update_references]
if options[:update_references]
update_references(rendering_result)
end
rendering_result rendering_result
end end
@ -102,8 +103,9 @@ class PageRenderer
references = @revision.page.wiki_references references = @revision.page.wiki_references
wiki_word_chunks = rendering_result.find_chunks(WikiChunk::WikiLink) wiki_words = find_wiki_words(rendering_result)
wiki_words = wiki_word_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq # TODO it may be desirable to save links to files and pictures as WikiReference objects
# present version doesn't do it
wiki_words.each do |referenced_name| wiki_words.each do |referenced_name|
# Links to self are always considered linked # Links to self are always considered linked

View file

@ -1,15 +1,12 @@
body { background-color: #fff; color: #333; } body { background-color: white; color: #333; }
body, p, ol, ul, td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; } body, p, ol, ul, td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; }
#Container { float: none; margin: 0 auto; text-align: center; } #Container { float: none; margin: 0 auto; text-align: center; }
#Content { margin: 0; padding: 5px; text-align: left; border-top: none; float: left; } #Content { margin: 0; padding: 5px; text-align: left; border-top: none; float: left; }
a { color: #000; } a { color: black; }
a:visited { color: #666; } a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; } a:hover { color: white; background-color:#000; }
.newWikiWord { background-color: #eee; }
.newWikiWord a:hover { background-color: white; }
h1, h2, h3 { color: #333; font-family: georgia, verdana, sans-serif; } h1, h2, h3 { color: #333; font-family: georgia, verdana, sans-serif; }
h1 { font-size: 28px } h1 { font-size: 28px }
@ -22,6 +19,9 @@ h1#pageName small { color: #444; line-height: 10px; font-size: 10px; padding: 0;
a.nav, a.nav:link, a.nav:visited { color: #000; } a.nav, a.nav:link, a.nav:visited { color: #000; }
a.nav:hover { color: #fff; background-color:#000; } a.nav:hover { color: #fff; background-color:#000; }
.newWikiWord { background-color: #BFBFBF; }
.newWikiWord a:hover { background-color: white; }
li { margin-bottom: 7px } li { margin-bottom: 7px }
.navigation { margin-top: 5px; font-size : 12px; color: #999; } .navigation { margin-top: 5px; font-size : 12px; color: #999; }