attach
attachプラグイン
もともとのHikiでは、attach(ファイル添付)プラグインを使う時には、misc/plugin/attach/attach.cgiをHikiのルートにコピーして使っていました。
Rackで動かす場合にはこの作業は必要ありません。
CGIでRackブランチを動かす場合も、大抵は必要ありません。
が、サーバーの設定のせいで/attachへのリクエストをhiki.cgiに投げられない場合、やはりmisc/plugin/attach/attach.cgiをHikiルートにコピーする必要があります。
それでもうまく行かない場合は、hikiconf.rbに
@options = {}
@options['attach.cgi_name'] = 'attch.cgi'
と書き込んで、Hikiルートにアップしてください。
ファイル添付機能の変更
このHikidashiブランチは、Commit 16d6f549e1d47daf794a(2010年10月24日)から、ファイル添付機能の実装を変更しました。
- CGIで動かす場合でもattach.cgiは不要になりました。
- 権限の管理はHTTP Auth(.htaccessと.htpasswd)ではなくHikiの権限管理を使うようになりました。
- 特定のユーザーにのみファイル添付 / 削除を許可したい場合にはedit_userプラグインを使ってください。
- ファイル添付のPOSTリクエストを直接/attachへ送っていた場合には/?c=attachに送るよう、変更してください。
プラグイン実例
- Zend Frameworkでのユニットテスト
- Hiki Atomプラグイン
- attach
- ij
- jQueryプラグイン
- learning.quickstart.create-model.html
- 閲覧制限プラグイン
- rails3
- 続きを読むプラグイン
# = $Id: atom.rb, v 0.4 2010-10-05
# Copyright (C) 2010 KITAITI Makoto <KitaitiMakoto@gmai.com>
#
# A Hiki plugin to syndicate Atom feed
#
# rss.rb plugin is very helpful for this plugin, thanks!
#
# == Required
# * rss library which can make Atom feeds
# (If your rss lib cannot, download from
# http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser)
#
# == Environment
# Operation hecked under:
# * Ruby 1.8.7
# * Hiki 0.8.8.1
#
# == To Do
# * Selection of the number of syndicated pages at admin page
# * Syndication per page
#
# == License
# atom.rb, en/atom.rb and ja/atom.rb are
# distributed under the GPL v2.(see {HIKIROOT}/doc/COPYING.)
require 'time'
def atom
pages = atom_recent_updates(10) # Magic number!
last_modified = pages.first.values[0][:last_modified]
header = {}
if_modified_since = ENV['HTTP_IF_MODIFIED_SINCE']
if_modified_since = Time.parse(if_modified_since) if if_modified_since
if if_modified_since and last_modified <= if_modified_since
header['status'] = 'NOT_MODIFIED'
print @cgi.header(header)
else
body = atom_body(pages)
header['Last-Modified'] = CGI.rfc1123_date(last_modified)
header['type'] = 'application/atom+xml'
header['charset'] = body.encoding
header['Content-Language'] = @conf.lang
header['Pragma'] = 'no-cache'
header['Cache-Control'] = 'no-cache'
print @cgi.header(header)
puts euc_to_utf8(body.to_s)
end
nil # Don't move to the 'FrontPage'
end
def atom_recent_updates(page_count = 10)
@db.page_info.sort_by do |p|
p[p.keys[0]][:last_modified]
end.last(page_count).reverse
end
def atom_body(pages)
require 'rss/maker'
RSS::Maker.make('atom') do |maker|
maker.encoding = 'UTF-8'
maker.channel.author = @conf.author_name
maker.channel.about = @conf.index_url + '?c=atom'
maker.channel.title = @conf.site_name + ' : ' + label_atom_recent
maker.channel.description = @conf.site_name + ' ' + label_atom_recent
maker.channel.language = @conf.lang
maker.channel.date = pages.first.values[0][:last_modified]
maker.channel.rights = 'Copyright (C) ' + @conf.author_name
maker.channel.generator do |generator|
generator.uri = 'http://hikiwiki.org/'
generator.version = ::Hiki::VERSION
generator.content = 'Hiki'
end
maker.channel.links.new_link do |link|
link.rel = 'self'
link.type = 'application/atom+xml'
link.href = maker.channel.about
end
maker.channel.links.new_link do |link|
link.rel = 'alternate'
link.type = 'text/html'
link.href = @conf.index_url + '?c=recent'
end
pages.each do |p|
maker.items.new_item do |item|
name = p.keys[0]
src = @db.load_backup(name) || ''
dst = @db.load(name) || ''
case @conf['atom.mode']
when :unidiff
content = h(unified_diff(src, dst)).strip.gsub(/\n/, "<br>\n").gsub(/ /, ' ')
when :worddiff_digest
content = word_diff(src, dst, true).strip.gsub(/\n/, "<br>\n")
when :worddiff_full
content = word_diff(src, dst).strip.gsub(/\n/, "<br>\n")
when :html_full
tokens = @db.load_cache(name)
unless tokens
parser = @conf.parser.new(@conf)
tokens = parser.parse(@db.load(name))
@db.save_cache(name, tokens)
end
tmp = @conf.use_plugin
@conf.use_plugin = false
formatter = @conf.formatter.new(tokens, @db, Plugin.new(@conf.options, @conf), @conf)
content = formatter.to_s
@conf.use_plugin = tmp
else
raise "Invalid atom.mode: #{@conf['atom.mode']}"
end
if content.empty?
content = shorten(dst).strip.gsub(/\n/, "<br>\n")
end
uri = @conf.index_url + '?' + name.escape
item.title = page_name(name)
item.link = uri
item.author = p[name][:editor] if p[name][:editor]
item.date = p[name][:last_modified].utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')
item.content.type = 'html'
item.content.content = content
end
end
end
end
add_body_enter_proc do
@conf['atom.mode'] ||= :unidiff
@conf['atom.menu'] ? add_plugin_command('atom', 'Atom') : add_plugin_command('atom', nil)
end
add_header_proc do
%Q| <link rel="alternate" type="application/atom+xml" title="Atom" href="#{@conf.index_url}?c=atom">|
end
def saveconf_atom
@conf['atom.mode'] = @cgi.params['atom.mode'][0].intern if @mode == 'saveconf'
end
if @cgi.params['conf'][0] == 'atom' && @mode == 'saveconf'
@conf['atom.menu'] = (@cgi.params['atom.menu'][0] == 'true')
end
add_conf_proc('atom', label_atom_config) do
saveconf_atom
str = <<HTML
<h3 class="subtitle">#{label_atom_mode_title}</h3>
<p><select name="atom.mode">
HTML
label_atom_mode_candidate.each_pair do |value, label|
str << %Q|<option value="#{value}"#{' selected' if @conf['atom.mode'] == value}>#{label}</option>\n|
end
str << "</select></p>\n"
str << <<HTML
<h3 class="subtitle">#{label_atom_menu_title}</h3>
<p><select name="atom.menu">
HTML
label_atom_menu_candidate.each_index do |i|
str << %Q|<option value="#{[true,false][i]}"#{' selected' if @conf['atom.menu'] == [true,false][i]}>#{label_atom_menu_candidate[i]}</option>\n|
end
str << "</select></p>\n"
end
export_plugin_methods :atom
# $Id: rss.rb,v 1.23 2008-07-06 02:40:43 hsbt Exp $
# Copyright (C) 2003-2004 TAKEUCHI Hitoshi <hitoshi@namaraii.com>
# Copyright (C) 2005 Kazuhiko <kazuhiko@fdiary.net>
def rss_body(page_num = 10)
pages = @db.page_info.sort do |a, b|
k1 = a.keys[0]
k2 = b.keys[0]
b[k2][:last_modified] <=> a[k1][:last_modified]
end
n = 0
item_list = ''
last_modified = pages[0].values[0][:last_modified]
items = <<EOS
<?xml version="1.0" encoding="#{@conf.charset}" standalone="yes"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xml:lang="ja-JP">
<channel rdf:about="#{@conf.index_url}?c=rss">
<title>#{CGI::escapeHTML(@conf.site_name)} : #{label_rss_recent}</title>
<link>#{@conf.index_url}?c=recent</link>
<description>#{CGI::escapeHTML(@conf.site_name)} #{label_rss_recent}</description>
<dc:language>ja</dc:language>
<dc:rights>Copyright (C) #{CGI::escapeHTML(@conf.author_name)}</dc:rights>
<dc:date>#{last_modified.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</dc:date>
<items>
<rdf:Seq>
EOS
pages.each do |p|
break if (n += 1) > page_num
name = p.keys[0]
src = @db.load_backup(name) || ''
dst = @db.load(name) || ''
case @conf['rss.mode']
when 1
content = word_diff(src, dst, true).strip.gsub(/\n/, "<br>\n")
when 2
content = word_diff(src, dst).strip.gsub(/\n/, "<br>\n")
when 3
tokens = @db.load_cache( name )
unless tokens
parser = @conf.parser::new( @conf )
tokens = parser.parse( @db.load( name ) )
@db.save_cache( name, tokens )
end
tmp = @conf.use_plugin
@conf.use_plugin = false
formatter = @conf.formatter::new( tokens, @db, Plugin.new( @conf.options, @conf), @conf )
content = formatter.to_s
@conf.use_plugin = tmp
else
content = CGI::escapeHTML(unified_diff(src, dst)).strip.gsub(/\n/, "<br>\n").gsub(/ /, ' ')
end
if content and content.empty?
content = shorten(dst).strip.gsub(/\n/, "<br>\n")
end
items << ' '
uri = "#{@conf.index_url}?#{name.escape}"
items << %Q!<rdf:li rdf:resource="#{uri}"/>\n!
item_list << <<EOS
<item rdf:about="#{uri}">
<title>#{CGI::escapeHTML(page_name(name))}</title>
<link>#{uri}</link>
<dc:date>#{p[name][:last_modified].utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</dc:date>
EOS
item_list << " <content:encoded><![CDATA[<div>#{content}</div>]]></content:encoded>" if content
item_list << ' </item>'
end
items << <<EOS
</rdf:Seq>
</items>
</channel>
EOS
items << item_list << '</rdf:RDF>'
return( [items, last_modified] )
end
def rss
body, last_modified = rss_body
header = Hash::new
require 'time'
begin
if_modified_since = Time.parse(ENV['HTTP_IF_MODIFIED_SINCE'])
rescue
if_modified_since = nil
end
if if_modified_since and last_modified < if_modified_since
header['status'] = 'NOT_MODIFIED'
print @cgi.header(header)
else
header['Last-Modified'] = CGI::rfc1123_date(last_modified)
header['type'] = 'text/xml'
header['charset'] = @conf.charset
header['Content-Language'] = @conf.lang
header['Pragma'] = 'no-cache'
header['Cache-Control'] = 'no-cache'
print @cgi.header(header)
puts body
end
nil # Don't move to the 'FrontPage'
end
add_body_enter_proc(Proc.new do
@conf['rss.mode'] ||= 0
if @conf['rss.menu'] == 1
add_plugin_command('rss', nil)
else
add_plugin_command('rss', 'RSS')
end
end)
add_header_proc(Proc.new do
%Q! <link rel="alternate" type="application/rss+xml" title="RSS" href="#{@conf.index_url}?c=rss">!
end)
def saveconf_rss
if @mode == 'saveconf' then
@conf['rss.mode'] = @cgi.params['rss.mode'][0].to_i
end
end
if @cgi.params['conf'][0] == 'rss' && @mode == 'saveconf'
@conf['rss.menu'] = @cgi.params['rss.menu'][0].to_i
end
add_conf_proc('rss', label_rss_config) do
saveconf_rss
str = <<-HTML
<h3 class="subtitle">#{label_rss_mode_title}</h3>
<p><select name="rss.mode">
HTML
label_rss_mode_candidate.each_index{ |i|
str << %Q|<option value="#{i}"#{@conf['rss.mode'] == i ? ' selected' : ''}>#{label_rss_mode_candidate[i]}</option>\n|
}
str << "</select></p>\n"
str << <<-HTML
<h3 class="subtitle">#{label_rss_menu_title}</h3>
<p><select name="rss.menu">
HTML
label_rss_menu_candidate.each_index{ |i|
str << %Q|<option value="#{i}"#{@conf['rss.menu'] == i ? ' selected' : ''}>#{label_rss_menu_candidate[i]}</option>\n|
}
str << "</select></p>\n"
str
end
export_plugin_methods(:rss)
Referer | 357 | 291 | 164 | 41 | 23 | 13 | 12 | 12 | 11 | 11 | 11 | 10 | 10 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 9 | 8 | 8 | 8 | 8 | 7 | 7 | 7 | 7 | 7 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | 5 | 5 | 5 | 5 | 5 | 4 | 4 | 4 | 4 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Keyword(s):
References: