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:
parent
42098e0a9f
commit
614a48c6ff
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -64,4 +71,12 @@ class WikiReference < ActiveRecord::Base
|
|||
link_type == INCLUDED_PAGE
|
||||
end
|
||||
|
||||
def file?
|
||||
link_type == FILE
|
||||
end
|
||||
|
||||
def wanted_file?
|
||||
link_type == WANTED_FILE
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<% end %>
|
||||
|
||||
<ul>
|
||||
<% @pages_by_name.each do |page| %>
|
||||
<% @pages_in_category.each do |page| %>
|
||||
<li>
|
||||
<%= link_to_existing_page page, truncate(page.plain_name, 35) %>
|
||||
</li>
|
||||
|
@ -19,7 +19,7 @@
|
|||
|
||||
<% if @web.count_pages? %>
|
||||
<% 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 %>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -66,11 +66,16 @@ class PageRenderer
|
|||
|
||||
# Returns an array of all the WikiWords present in the content of this revision.
|
||||
def wiki_words
|
||||
unless @wiki_words_cache
|
||||
wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
|
||||
@wiki_words_cache = wiki_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
|
||||
@wiki_words_cache ||= find_wiki_words(display_content)
|
||||
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
|
||||
|
||||
# Returns an array of all the WikiWords present in the content of this revision.
|
||||
|
@ -88,12 +93,8 @@ class PageRenderer
|
|||
private
|
||||
|
||||
def render(options = {})
|
||||
|
||||
rendering_result = WikiContent.new(@revision, @@url_generator, options).render!
|
||||
|
||||
if options[:update_references]
|
||||
update_references(rendering_result)
|
||||
end
|
||||
update_references(rendering_result) if options[:update_references]
|
||||
rendering_result
|
||||
end
|
||||
|
||||
|
@ -102,8 +103,9 @@ class PageRenderer
|
|||
|
||||
references = @revision.page.wiki_references
|
||||
|
||||
wiki_word_chunks = rendering_result.find_chunks(WikiChunk::WikiLink)
|
||||
wiki_words = wiki_word_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
|
||||
wiki_words = find_wiki_words(rendering_result)
|
||||
# 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|
|
||||
# Links to self are always considered linked
|
||||
|
|
|
@ -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; }
|
||||
|
||||
#Container { float: none; margin: 0 auto; text-align: center; }
|
||||
#Content { margin: 0; padding: 5px; text-align: left; border-top: none; float: left; }
|
||||
|
||||
a { color: #000; }
|
||||
a { color: black; }
|
||||
a:visited { color: #666; }
|
||||
a:hover { color: #fff; background-color:#000; }
|
||||
|
||||
.newWikiWord { background-color: #eee; }
|
||||
.newWikiWord a:hover { background-color: white; }
|
||||
a:hover { color: white; background-color:#000; }
|
||||
|
||||
h1, h2, h3 { color: #333; font-family: georgia, verdana, sans-serif; }
|
||||
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:hover { color: #fff; background-color:#000; }
|
||||
|
||||
.newWikiWord { background-color: #BFBFBF; }
|
||||
.newWikiWord a:hover { background-color: white; }
|
||||
|
||||
li { margin-bottom: 7px }
|
||||
|
||||
.navigation { margin-top: 5px; font-size : 12px; color: #999; }
|
||||
|
|
Loading…
Reference in a new issue