Delete Orphan Pages in Category
If a Web has categories defined, you can delete orphaned pages in a given category (in addition to being able to delete all orphaned pages).
This commit is contained in:
parent
61799bc63f
commit
3a78ef3dbf
|
@ -104,6 +104,23 @@ class AdminController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_orphaned_pages_in_category
|
||||||
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
||||||
|
headers['Allow'] = 'POST'
|
||||||
|
render(:status => 405, :text => 'You must use an HTTP POST', :layout => 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if wiki.authenticate(params['system_password_orphaned_in_category'])
|
||||||
|
category = params['category']
|
||||||
|
wiki.remove_orphaned_pages_in_category(@web_name, category)
|
||||||
|
flash[:info] = "Orphaned pages in category \"#{category}\" removed"
|
||||||
|
redirect_to :controller => 'wiki', :web => @web_name, :action => 'list'
|
||||||
|
else
|
||||||
|
flash[:error] = password_error(params['system_password_orphaned_in_category'])
|
||||||
|
redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete_web
|
def delete_web
|
||||||
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
unless (request.post? || ENV["RAILS_ENV"] == "test")
|
||||||
headers['Allow'] = 'POST'
|
headers['Allow'] = 'POST'
|
||||||
|
|
|
@ -15,4 +15,9 @@ class WebSweeper < ActionController::Caching::Sweeper
|
||||||
def after_remove_orphaned_pages(web)
|
def after_remove_orphaned_pages(web)
|
||||||
expire_cached_summary_pages(web)
|
expire_cached_summary_pages(web)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def after_remove_orphaned_pages_in_category(web)
|
||||||
|
expire_cached_summary_pages(web)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,6 +73,12 @@ class PageSet < Array
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pages_in_category(category)
|
||||||
|
self.select { |page|
|
||||||
|
WikiReference.pages_in_category(web, category).map.include?(page.name)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# Returns all the wiki words in this page set for which
|
# Returns all the wiki words in this page set for which
|
||||||
# there are no pages in this page set's web
|
# there are no pages in this page set's web
|
||||||
def wanted_pages
|
def wanted_pages
|
||||||
|
|
|
@ -54,6 +54,12 @@ class Wiki
|
||||||
web.remove_pages(web.select.orphaned_pages)
|
web.remove_pages(web.select.orphaned_pages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_orphaned_pages_in_category(web_address,category)
|
||||||
|
web = Web.find_by_address(web_address)
|
||||||
|
pages_in_category = PageSet.new(web, web.select.pages_in_category(category))
|
||||||
|
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, content, revised_at, author, renderer)
|
||||||
page = read_page(web_address, page_name)
|
page = read_page(web_address, page_name)
|
||||||
page.revise(content, revised_at, author, renderer)
|
page.revise(content, revised_at, author, renderer)
|
||||||
|
|
|
@ -118,24 +118,46 @@
|
||||||
'accept-charset' => 'utf-8' }) do
|
'accept-charset' => 'utf-8' }) do
|
||||||
%>
|
%>
|
||||||
<p style="text-align:right;font-size:.85em;">
|
<p style="text-align:right;font-size:.85em;">
|
||||||
Clean up by entering system password
|
Clean up this Web by entering the system password
|
||||||
<input type="password" id="system_password_orphaned" class="disableAutoComplete" name="system_password_orphaned" />
|
<input type="password" id="system_password_orphaned" class="disableAutoComplete" name="system_password_orphaned" />
|
||||||
and
|
and
|
||||||
<input type="submit" value="Delete Orphan Pages" />
|
<input type="submit" value="Delete Orphan Pages" />
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% categories = WikiReference.list_categories(@web).sort
|
||||||
|
if categories.length > 0 %>
|
||||||
|
<% form_tag({:controller => 'admin', :web => @web.address, :action => 'remove_orphaned_pages_in_category'},
|
||||||
|
{ :id => 'remove_orphaned_pages_in_category',
|
||||||
|
:onsubmit => "return checkSystemPassword(document.getElementById('system_password_orphaned_in_category').value)",
|
||||||
|
'accept-charset' => 'utf-8' }) do
|
||||||
|
%>
|
||||||
|
<p style="text-align:right;font-size:.85em;">
|
||||||
|
Clean up selected category:
|
||||||
|
<select id="category" name="category">
|
||||||
|
<%= html_options(categories) %>
|
||||||
|
</select>
|
||||||
|
Enter system password
|
||||||
|
<input type="password" id="system_password_orphaned_in_category" class="disableAutoComplete" name="system_password_orphaned_in_category" />
|
||||||
|
and
|
||||||
|
<input type="submit" value="Delete Orphan Pages in Category" />
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="inputBox">
|
||||||
<% form_tag({:controller => 'admin', :web => @web.address, :action => 'delete_web'},
|
<% form_tag({:controller => 'admin', :web => @web.address, :action => 'delete_web'},
|
||||||
{ :id => 'delete_web',
|
{ :id => 'delete_web',
|
||||||
:onsubmit => "return checkSystemPassword(document.getElementById('system_password_delete_web').value)",
|
:onsubmit => "return checkSystemPassword(document.getElementById('system_password_delete_web').value)",
|
||||||
'accept-charset' => 'utf-8' }) do
|
'accept-charset' => 'utf-8' }) do
|
||||||
%>
|
%>
|
||||||
<p style="text-align:right;font-size:.85em;">
|
<p style="text-align:right;">
|
||||||
Delete this Web, and all its pages.
|
Delete this Web, and all its pages. Enter system password
|
||||||
<input type="password" id="system_password_delete_web" class="disableAutoComplete" name="system_password_delete_web" />
|
<input type="password" id="system_password_delete_web" class="disableAutoComplete" name="system_password_delete_web" />
|
||||||
and
|
and
|
||||||
<input type="submit" value="Delete Web" />
|
<input type="submit" value="Delete Web" />
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= javascript_include_tag 'edit_web' %>
|
<%= javascript_include_tag 'edit_web' %>
|
||||||
|
|
|
@ -16,6 +16,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
|
|
||||||
connect_to_web map, ':web/edit_web', :controller => 'admin', :action => 'edit_web'
|
connect_to_web map, ':web/edit_web', :controller => 'admin', :action => 'edit_web'
|
||||||
connect_to_web map, ':web/remove_orphaned_pages', :controller => 'admin', :action => 'remove_orphaned_pages'
|
connect_to_web map, ':web/remove_orphaned_pages', :controller => 'admin', :action => 'remove_orphaned_pages'
|
||||||
|
connect_to_web map, ':web/remove_orphaned_pages_in_category', :controller => 'admin', :action => 'remove_orphaned_pages_in_category'
|
||||||
connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil
|
connect_to_web map, ':web/files/:id', :controller => 'file', :action => 'file', :requirements => {:id => /[-._\w]+/}, :id => nil
|
||||||
connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import'
|
connect_to_web map, ':web/import/:id', :controller => 'file', :action => 'import'
|
||||||
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'
|
connect_to_web map, ':web/login', :controller => 'wiki', :action => 'login'
|
||||||
|
|
Loading…
Reference in a new issue