Merge branch 'bzr/golem' of /Users/distler/Sites/code/instiki
This commit is contained in:
commit
3d626dae30
16 changed files with 161 additions and 33 deletions
|
@ -129,7 +129,7 @@ class FileController < ApplicationController
|
|||
next
|
||||
else
|
||||
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
||||
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||
wiki.revise_page(@web.address, page_name, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||
end
|
||||
else
|
||||
wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||
|
|
|
@ -22,8 +22,9 @@ class RevisionSweeper < ActionController::Caching::Sweeper
|
|||
|
||||
def expire_caches(page)
|
||||
expire_cached_summary_pages(page.web)
|
||||
pages_to_expire = ([page.name] + WikiReference.pages_that_reference(page.web, page.name) +
|
||||
WikiReference.pages_that_include(page.web, page.name)).uniq
|
||||
pages_to_expire = ([page.name] + WikiReference.pages_that_reference(page.web, page.name)
|
||||
+ WikiReference.pages_redirected_to(page.web, page.name)
|
||||
+ WikiReference.pages_that_include(page.web, page.name)).uniq
|
||||
pages_to_expire.each { |page_name| expire_cached_page(page.web, page_name) }
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class WebSweeper < ActionController::Caching::Sweeper
|
|||
web.pages.each { |page| expire_cached_page(web, page.name) }
|
||||
expire_cached_summary_pages(web)
|
||||
elsif record.is_a?(WikiFile)
|
||||
record.web.pages_that_link_to(record.file_name).each do |page|
|
||||
record.web.pages_that_link_to_file(record.file_name).each do |page|
|
||||
expire_cached_page(record.web, page)
|
||||
end
|
||||
expire_cached_summary_pages(record.web)
|
||||
|
|
|
@ -268,9 +268,13 @@ class WikiController < ApplicationController
|
|||
raise Instiki::ValidationError.new('Your content was not valid utf-8.')
|
||||
end
|
||||
if @page
|
||||
wiki.revise_page(@web_name, @page_name, the_content, Time.now,
|
||||
new_name = params['new_name'] || @page_name
|
||||
raise Instiki::ValidationError.new('Your new title was not valid utf-8.') unless new_name.is_utf8?
|
||||
raise Instiki::ValidationError.new('A page named "' + new_name.escapeHTML + '" already exists.') if @page_name != new_name && @web.has_page?(new_name)
|
||||
wiki.revise_page(@web_name, @page_name, new_name, the_content, Time.now,
|
||||
Author.new(author_name, remote_ip), PageRenderer.new)
|
||||
@page.unlock
|
||||
@page_name = new_name
|
||||
else
|
||||
wiki.write_page(@web_name, @page_name, the_content, Time.now,
|
||||
Author.new(author_name, remote_ip), PageRenderer.new)
|
||||
|
|
|
@ -4,13 +4,14 @@ class Page < ActiveRecord::Base
|
|||
has_many :wiki_references, :order => 'referenced_name'
|
||||
has_one :current_revision, :class_name => 'Revision', :order => 'id DESC'
|
||||
|
||||
def revise(content, time, author, renderer)
|
||||
def revise(content, name, time, author, renderer)
|
||||
revisions_size = new_record? ? 0 : revisions.size
|
||||
if (revisions_size > 0) and content == current_revision.content
|
||||
if (revisions_size > 0) and content == current_revision.content and name == self.name
|
||||
raise Instiki::ValidationError.new(
|
||||
"You have tried to save page '#{name}' without changing its content")
|
||||
end
|
||||
|
||||
self.name = name
|
||||
author = Author.new(author.to_s) unless author.is_a?(Author)
|
||||
|
||||
# Try to render content to make sure that markup engine can take it,
|
||||
|
@ -37,7 +38,7 @@ class Page < ActiveRecord::Base
|
|||
raise Instiki::ValidationError.new("Revision #{revision_number} not found")
|
||||
end
|
||||
author = Author.new(roll_back_revision.author.name, author_ip)
|
||||
revise(roll_back_revision.content, time, author, renderer)
|
||||
revise(roll_back_revision.content, self.name, time, author, renderer)
|
||||
end
|
||||
|
||||
def revisions?
|
||||
|
@ -70,6 +71,10 @@ class Page < ActiveRecord::Base
|
|||
def linked_from
|
||||
web.select.pages_that_link_to(name)
|
||||
end
|
||||
|
||||
def redirects_for
|
||||
wiki_references.select { |ref| ref.redirected_page?}.map { |ref| ref.referenced_name }
|
||||
end
|
||||
|
||||
def included_from
|
||||
web.select.pages_that_include(name)
|
||||
|
|
|
@ -14,7 +14,7 @@ class Web < ActiveRecord::Base
|
|||
|
||||
def add_page(name, content, time, author, renderer)
|
||||
page = page(name) || Page.new(:web => self, :name => name)
|
||||
page.revise(content, time, author, renderer)
|
||||
page.revise(content, name, time, author, renderer)
|
||||
end
|
||||
|
||||
def authors
|
||||
|
@ -42,6 +42,14 @@ class Web < ActiveRecord::Base
|
|||
def has_page?(name)
|
||||
Page.count(:conditions => ['web_id = ? AND name = ?', id, name]) > 0
|
||||
end
|
||||
|
||||
def has_redirect_for?(name)
|
||||
WikiReference.page_that_redirects_for(self, name)
|
||||
end
|
||||
|
||||
def page_that_redirects_for(name)
|
||||
page(WikiReference.page_that_redirects_for(self, name))
|
||||
end
|
||||
|
||||
def has_file?(file_name)
|
||||
WikiFile.find_by_file_name(file_name) != nil
|
||||
|
@ -51,10 +59,14 @@ class Web < ActiveRecord::Base
|
|||
WikiFile.all(:order => sort_order, :conditions => ['web_id = ?', id])
|
||||
end
|
||||
|
||||
def pages_that_link_to(file_name)
|
||||
def pages_that_link_to(page_name)
|
||||
WikiReference.pages_that_link_to(self, page_name)
|
||||
end
|
||||
|
||||
def pages_that_link_to_file(file_name)
|
||||
WikiReference.pages_that_link_to_file(self, file_name)
|
||||
end
|
||||
|
||||
|
||||
def description(file_name)
|
||||
file = WikiFile.find_by_file_name(file_name)
|
||||
file.description if file
|
||||
|
|
|
@ -60,9 +60,9 @@ class Wiki
|
|||
web.remove_pages(pages_in_category.orphaned_pages)
|
||||
end
|
||||
|
||||
def revise_page(web_address, page_name, content, revised_at, author, renderer)
|
||||
def revise_page(web_address, page_name, new_name, content, revised_at, author, renderer)
|
||||
page = read_page(web_address, page_name)
|
||||
page.revise(content, revised_at, author, renderer)
|
||||
page.revise(content, new_name, revised_at, author, renderer)
|
||||
end
|
||||
|
||||
def rollback_page(web_address, page_name, revision_number, time, author_id = nil)
|
||||
|
|
|
@ -2,6 +2,7 @@ class WikiReference < ActiveRecord::Base
|
|||
|
||||
LINKED_PAGE = 'L'
|
||||
WANTED_PAGE = 'W'
|
||||
REDIRECTED_PAGE = 'R'
|
||||
INCLUDED_PAGE = 'I'
|
||||
CATEGORY = 'C'
|
||||
AUTHOR = 'A'
|
||||
|
@ -9,7 +10,7 @@ class WikiReference < ActiveRecord::Base
|
|||
WANTED_FILE = 'E'
|
||||
|
||||
belongs_to :page
|
||||
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR, FILE, WANTED_FILE]
|
||||
validates_inclusion_of :link_type, :in => [LINKED_PAGE, WANTED_PAGE, REDIRECTED_PAGE, INCLUDED_PAGE, CATEGORY, AUTHOR, FILE, WANTED_FILE]
|
||||
|
||||
def self.link_type(web, page_name)
|
||||
web.has_page?(page_name) ? LINKED_PAGE : WANTED_PAGE
|
||||
|
@ -51,6 +52,28 @@ class WikiReference < ActiveRecord::Base
|
|||
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
||||
end
|
||||
|
||||
def self.pages_redirected_to(web, page_name)
|
||||
names = []
|
||||
if web.has_page?(page_name)
|
||||
page = web.page(page_name)
|
||||
redirected_names = page.redirects_for
|
||||
redirected_names.each do |name|
|
||||
names = names | self.pages_that_reference(web, name)
|
||||
end
|
||||
end
|
||||
names
|
||||
end
|
||||
|
||||
def self.page_that_redirects_for(web, page_name)
|
||||
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 = '#{REDIRECTED_PAGE}' " +
|
||||
"AND pages.web_id = '#{web.id}'"
|
||||
names = connection.select_all(sanitize_sql([query, page_name])).map { |row| row['name'] }
|
||||
names[0]
|
||||
end
|
||||
|
||||
def self.pages_in_category(web, category)
|
||||
query =
|
||||
"SELECT name FROM pages JOIN wiki_references " +
|
||||
|
@ -82,6 +105,10 @@ class WikiReference < ActiveRecord::Base
|
|||
link_type == LINKED_PAGE
|
||||
end
|
||||
|
||||
def redirected_page?
|
||||
link_type == REDIRECTED_PAGE
|
||||
end
|
||||
|
||||
def wanted_page?
|
||||
link_type == WANTED_PAGE
|
||||
end
|
||||
|
|
|
@ -12,6 +12,16 @@
|
|||
<% form_tag({ :action => 'save', :web => @web.address, :id => @page.name },
|
||||
{ 'id' => 'editForm', 'method' => 'post', 'onsubmit' => 'cleanAuthorName()',
|
||||
'accept-charset' => 'utf-8' }) do %>
|
||||
<% if @page_name != 'HomePage' -%>
|
||||
<p>
|
||||
<%= check_box_tag :alter_title, value = "1", checked=false,
|
||||
'onchange' => "toggleVisibility();" %> <label for="alter_title">Change page name.</label><br/>
|
||||
<span id="title_change" style="display:none"><label for="new_name">New name:</label> <%= text_field_tag :new_name, h(@page.name.purify),
|
||||
:onblur => "addRedirect();" %></span>
|
||||
</p>
|
||||
<% else -%>
|
||||
<%= hidden_field_tag 'new_name', @page_name %>
|
||||
<% 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>
|
||||
|
@ -31,10 +41,30 @@
|
|||
<%- end -%>
|
||||
|
||||
<script type="text/javascript">
|
||||
function toggleVisibility() {
|
||||
var span = document.getElementById('title_change');
|
||||
if (span.style.display =='inline') {
|
||||
span.style.display ='none';
|
||||
document.getElementById('new_name').value = "<%= @page.name %>";
|
||||
var content = document.getElementById('content').value
|
||||
document.getElementById('content').value = content.replace(/\[\[!redirects <%= Regexp.escape(@page.name) %>\]\]\n/, '')
|
||||
}
|
||||
else
|
||||
span.style.display ='inline'
|
||||
}
|
||||
|
||||
function addRedirect(){
|
||||
if (document.getElementById('new_name').value != "<%= @page.name %>" ) {
|
||||
var content = document.getElementById('content');
|
||||
content.value = '[[!redirects <%= @page.name %>]]\n' + content.value
|
||||
}
|
||||
}
|
||||
|
||||
function cleanAuthorName() {
|
||||
if (document.getElementById('authorName').value == "") {
|
||||
document.getElementById('authorName').value = 'AnonymousCoward';
|
||||
}
|
||||
}
|
||||
|
||||
document.forms["editForm"].elements["content"].focus();
|
||||
</script>
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
<input type="checkbox" name="<%= file.file_name %>" value="delete"/>
|
||||
<a href="<%= url_for :web => @web.address, :action => 'files',
|
||||
:id => file.file_name %>"><%= file.file_name%></a> (<%= file.created_at.asctime %>) <span class="linked"><%= "Linked to by: " unless
|
||||
@web.pages_that_link_to(file.file_name).empty? -%>
|
||||
<%= @web.pages_that_link_to(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %></span>
|
||||
@web.pages_that_link_to_file(file.file_name).empty? -%>
|
||||
<%= @web.pages_that_link_to_file(file.file_name).collect { |referring_page| link_to_page(referring_page) }.join(", ") %></span>
|
||||
</li>
|
||||
<%- end -%>
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue