Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
This commit is contained in:
commit
8624a40bf8
|
@ -71,10 +71,6 @@ class Page < ActiveRecord::Base
|
||||||
def linked_from
|
def linked_from
|
||||||
web.select.pages_that_link_to(name)
|
web.select.pages_that_link_to(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirects_for
|
|
||||||
wiki_references.select { |ref| ref.redirected_page?}.map { |ref| ref.referenced_name }
|
|
||||||
end
|
|
||||||
|
|
||||||
def included_from
|
def included_from
|
||||||
web.select.pages_that_include(name)
|
web.select.pages_that_include(name)
|
||||||
|
|
|
@ -54,14 +54,9 @@ class WikiReference < ActiveRecord::Base
|
||||||
|
|
||||||
def self.pages_redirected_to(web, page_name)
|
def self.pages_redirected_to(web, page_name)
|
||||||
names = []
|
names = []
|
||||||
if web.has_page?(page_name)
|
page = web.page(page_name)
|
||||||
page = web.page(page_name)
|
Thread.current[:page_redirects][page.name].each { |name| names = names + self.pages_that_reference(web, name) }
|
||||||
redirected_names = page.redirects_for
|
names.uniq
|
||||||
redirected_names.each do |name|
|
|
||||||
names = names | self.pages_that_reference(web, name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
names
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.page_that_redirects_for(web, page_name)
|
def self.page_that_redirects_for(web, page_name)
|
||||||
|
@ -70,8 +65,8 @@ class WikiReference < ActiveRecord::Base
|
||||||
'WHERE wiki_references.referenced_name = ? ' +
|
'WHERE wiki_references.referenced_name = ? ' +
|
||||||
"AND wiki_references.link_type = '#{REDIRECTED_PAGE}' " +
|
"AND wiki_references.link_type = '#{REDIRECTED_PAGE}' " +
|
||||||
"AND pages.web_id = '#{web.id}'"
|
"AND pages.web_id = '#{web.id}'"
|
||||||
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
row = connection.select_one(sanitize_sql([query, page_name]))
|
||||||
names[0]
|
row['name'] if row
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pages_in_category(web, category)
|
def self.pages_in_category(web, category)
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
<% form_tag({ :action => 'save', :web => @web.address, :id => @page.name },
|
<% form_tag({ :action => 'save', :web => @web.address, :id => @page.name },
|
||||||
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
||||||
'accept-charset' => 'utf-8' }) do %>
|
'accept-charset' => 'utf-8' }) do %>
|
||||||
|
<div>
|
||||||
|
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] ||
|
||||||
|
((params['content'] && params['content'].is_utf8?) ? params['content'] : @page.content).purify) %></textarea>
|
||||||
<% if @page_name != 'HomePage' -%>
|
<% if @page_name != 'HomePage' -%>
|
||||||
<p>
|
<p>
|
||||||
<%= check_box_tag :alter_title, value = "1", checked=false,
|
<%= check_box_tag :alter_title, value = "1", checked=false,
|
||||||
|
@ -22,9 +25,6 @@
|
||||||
<% else -%>
|
<% else -%>
|
||||||
<%= hidden_field_tag 'new_name', @page_name %>
|
<%= hidden_field_tag 'new_name', @page_name %>
|
||||||
<% end%>
|
<% end%>
|
||||||
<div>
|
|
||||||
<textarea name="content" id="content" rows="24" cols="60"><%= h(flash[:content] ||
|
|
||||||
((params['content'] && params['content'].is_utf8?) ? params['content'] : @page.content).purify) %></textarea>
|
|
||||||
<div id="editFormButtons">
|
<div id="editFormButtons">
|
||||||
<input type="submit" value="Submit" accesskey="s"/> as
|
<input type="submit" value="Submit" accesskey="s"/> as
|
||||||
<%= text_field_tag :author, h(@author.purify),
|
<%= text_field_tag :author, h(@author.purify),
|
||||||
|
|
|
@ -179,7 +179,12 @@ class PageRenderer
|
||||||
references.build :referenced_name => redirected_page_name,
|
references.build :referenced_name => redirected_page_name,
|
||||||
:link_type => WikiReference::REDIRECTED_PAGE
|
:link_type => WikiReference::REDIRECTED_PAGE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ugly hack: store these in a thread-local variable, so that the cache-sweeper has access to it.
|
||||||
|
Thread.current[:page_redirects] ?
|
||||||
|
Thread.current[:page_redirects].update({ @revision.page.name => redirects}) :
|
||||||
|
Thread.current[:page_redirects] = { @revision.page.name => redirects}
|
||||||
|
|
||||||
categories = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
|
categories = rendering_result.find_chunks(Category).map { |cat| cat.list }.flatten
|
||||||
categories.each do |category|
|
categories.each do |category|
|
||||||
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
|
references.build :referenced_name => category, :link_type => WikiReference::CATEGORY
|
||||||
|
|
|
@ -524,6 +524,7 @@ END_THM
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_revisions_diff
|
def test_revisions_diff
|
||||||
|
Thread.current[:page_redirects] = { @page.name => []}
|
||||||
Revision.create(:page => @page, :content => 'What a blue and lovely morning',
|
Revision.create(:page => @page, :content => 'What a blue and lovely morning',
|
||||||
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
|
:author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
|
||||||
Revision.create(:page => @page, :content => 'What a red and lovely morning today',
|
Revision.create(:page => @page, :content => 'What a red and lovely morning today',
|
||||||
|
|
Loading…
Reference in a new issue