1 |
wakaba |
1.1 |
# -*- perl -*- |
2 |
|
|
|
3 |
|
|
=head1 NAME |
4 |
|
|
|
5 |
|
|
SuikaWiki::Plugin --- SuikaWiki: Plugin manager and the interface to the Wiki database from plugins |
6 |
|
|
|
7 |
|
|
=cut |
8 |
|
|
|
9 |
|
|
package SuikaWiki::Plugin; |
10 |
|
|
use strict; |
11 |
wakaba |
1.6 |
our $VERSION = do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
12 |
wakaba |
1.4 |
our ($plugin_directory, @plugin_directory, %List, %Index, %Cache, %On); |
13 |
wakaba |
1.1 |
push @main::INC, $plugin_directory.'/../..'; |
14 |
w |
1.5 |
require SuikaWiki::Markup::XML; ## Used by plugins |
15 |
wakaba |
1.1 |
|
16 |
|
|
=head1 PLUGIN INTERFACE |
17 |
|
|
|
18 |
|
|
=over 4 |
19 |
|
|
|
20 |
|
|
=item $o->new_index ($index_name) |
21 |
|
|
|
22 |
|
|
Increments the index number and returns the new index number. |
23 |
|
|
|
24 |
|
|
=cut |
25 |
|
|
|
26 |
|
|
sub new_index ($$) { ++$Index{$_[1]} } |
27 |
|
|
|
28 |
w |
1.5 |
=item $o->magic_and_content ($document) |
29 |
wakaba |
1.1 |
|
30 |
w |
1.5 |
(DEPRECATED) Splits the documents into the magic line and content part. |
31 |
|
|
Use SuikaWiki::SrcFormat. |
32 |
wakaba |
1.1 |
|
33 |
|
|
=cut |
34 |
|
|
|
35 |
|
|
sub magic_and_content ($$) { |
36 |
|
|
my ($magic, $page) = ('', $_[1]); |
37 |
|
|
$magic = $1 if $page =~ s!^((?:\#\?|/\*|<\?)[^\x02\x0A\x0D]+)[\x02\x0A\x0D]+!!s; |
38 |
|
|
($magic, $page); |
39 |
|
|
} |
40 |
|
|
|
41 |
wakaba |
1.2 |
=item $o->feature ($package_name) |
42 |
|
|
|
43 |
|
|
Returns whether the feature is enabled or not. |
44 |
|
|
If the feature is usable but not loaded, it is loaded and C<1> is returned. |
45 |
|
|
|
46 |
|
|
=cut |
47 |
|
|
|
48 |
|
|
sub feature ($$;%) { |
49 |
|
|
my ($o, $package, %o) = @_; |
50 |
|
|
no strict 'refs'; |
51 |
|
|
if (${$package . '::VERSION'}) { |
52 |
|
|
caller (1)->import if $o{use}; |
53 |
|
|
return 1; |
54 |
|
|
} else { |
55 |
|
|
if (eval qq{require $package}) { |
56 |
|
|
caller (1)->import if $o{use}; |
57 |
|
|
return 1; |
58 |
|
|
} else { |
59 |
|
|
return 0; |
60 |
|
|
} |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
|
64 |
w |
1.5 |
{my %Formatter; |
65 |
|
|
sub formatter ($$) { |
66 |
|
|
my $t = $_[1]; $t =~ tr/-/_/; |
67 |
|
|
unless ($Formatter{$t}) { |
68 |
|
|
require Message::Util::Formatter; |
69 |
|
|
$Formatter{$t} = Message::Util::Formatter->new; |
70 |
|
|
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
71 |
|
|
$_->load_formatter ($Formatter{$t}, type => 'wiki'.$t); |
72 |
|
|
} |
73 |
|
|
$Formatter{$t}->option (return_class => 'SuikaWiki::Markup::XML'); |
74 |
|
|
} |
75 |
|
|
return $Formatter{$t}; |
76 |
|
|
}} |
77 |
|
|
|
78 |
wakaba |
1.6 |
our $DB;#temporary |
79 |
|
|
sub db ($) { |
80 |
|
|
## TODO: common interface to WikiDB |
81 |
|
|
$DB; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
sub set_data ($$$$;%) { |
85 |
|
|
my ($self, $prop, $key, $data, %opt) = @_; |
86 |
|
|
## TODO: common interface to WikiDB |
87 |
|
|
## TODO: error recovering |
88 |
|
|
$DB->set ($prop => $key => $data); |
89 |
|
|
if ($opt{-touch}) { |
90 |
|
|
$DB->set (lastmodified => $key => time); |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
sub get_data ($$$$;%) { |
95 |
|
|
my ($self, $prop, $key, %opt) = @_; |
96 |
|
|
## TODO: common interface to WikiDB |
97 |
|
|
## TODO: error recovering |
98 |
|
|
$DB->get ($prop => $key); |
99 |
|
|
} |
100 |
|
|
|
101 |
wakaba |
1.1 |
=head1 PLUGIN MANAGER |
102 |
|
|
|
103 |
|
|
=over 4 |
104 |
|
|
|
105 |
w |
1.5 |
=item SuikaWiki::Plugin->import_plugins |
106 |
wakaba |
1.1 |
|
107 |
|
|
Searchs plugins into $plugin_directory and loads all plugins found. |
108 |
|
|
This method should be called at least one time before plugin-required-features |
109 |
|
|
are used. |
110 |
|
|
|
111 |
|
|
=cut |
112 |
|
|
|
113 |
w |
1.5 |
sub import_plugins ($) { |
114 |
wakaba |
1.4 |
my @plugins; |
115 |
|
|
for my $dir ($plugin_directory, @plugin_directory) { |
116 |
|
|
opendir PDIR, $dir; |
117 |
|
|
push @plugins, map {[$_, $dir.'/'.$_.'.pm']} grep {s/\.pm$//} readdir (PDIR); |
118 |
wakaba |
1.1 |
closedir PDIR; |
119 |
wakaba |
1.4 |
} |
120 |
|
|
for my $plugin (@plugins) { |
121 |
|
|
unless ($plugin->[0] =~ /[^A-Za-z0-9_]/) { |
122 |
w |
1.5 |
eval qq{ require \$plugin->[1]; SuikaWiki::Plugin::$plugin->[0]\->import; 1 } or die $@; |
123 |
wakaba |
1.4 |
push @{$List{_all}}, qq(SuikaWiki::Plugin::$plugin->[0]); |
124 |
wakaba |
1.3 |
} |
125 |
wakaba |
1.4 |
} |
126 |
|
|
## callback (onLoad) |
127 |
|
|
for (@{$On{Load}||[]}) { |
128 |
|
|
&{$_}; |
129 |
|
|
} |
130 |
wakaba |
1.1 |
} |
131 |
|
|
|
132 |
|
|
=item SuikaWiki::Plugin::regist ($plugin_package, @categories) |
133 |
|
|
|
134 |
|
|
Regists the plugin categories provided by the plugin package. |
135 |
|
|
This method should be called from plugin packages. |
136 |
|
|
|
137 |
|
|
Example: |
138 |
|
|
|
139 |
|
|
sub import { |
140 |
|
|
my $self = shift; |
141 |
|
|
$self->SuikaWiki::Plugin::regist (qw/wikiform_input/); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
=cut |
145 |
|
|
|
146 |
|
|
sub regist ($@) { |
147 |
|
|
my $pack = shift; |
148 |
|
|
for (@_) { |
149 |
|
|
push @{$List{$_}}, $pack; |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
=back |
154 |
|
|
|
155 |
wakaba |
1.6 |
=head1 WIKIPLUGIN MANAGER OBJECT |
156 |
|
|
|
157 |
|
|
This part implements WikiPlugin manager object of SuikaWiki WikiPlugin |
158 |
|
|
implementation model, second edition. |
159 |
|
|
|
160 |
|
|
=over 4 |
161 |
|
|
|
162 |
|
|
=item $p = SuikaWiki::Plugin->new (wiki => $WIKI) |
163 |
|
|
|
164 |
|
|
Constructs new instance of WikiPlugin manager |
165 |
|
|
|
166 |
|
|
=cut |
167 |
|
|
|
168 |
|
|
sub new ($%) { |
169 |
|
|
my $class = shift; |
170 |
|
|
my $self = bless {@_}, $class; |
171 |
|
|
|
172 |
|
|
$self; |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
=item $p->use_type ($type) |
176 |
|
|
|
177 |
|
|
Declares rules classified as $type is to be used. |
178 |
|
|
Even in current implementation this method makes no meaning, |
179 |
|
|
plugin callers must declare by this method for future compatibility. |
180 |
|
|
|
181 |
|
|
=cut |
182 |
|
|
|
183 |
|
|
sub use_type ($$) { |
184 |
|
|
#my ($self, $type) = @_; |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
=item $p->{rule}->{ $type }->{ $name } = { plugin rule definition } |
188 |
|
|
|
189 |
|
|
WikiPlugin rule |
190 |
|
|
|
191 |
|
|
@@TBD@@ |
192 |
|
|
|
193 |
|
|
=item $p->{wiki} |
194 |
|
|
|
195 |
|
|
Wiki implementation $p is associated with |
196 |
|
|
|
197 |
|
|
=back |
198 |
|
|
|
199 |
wakaba |
1.1 |
=head1 SEE ALSO |
200 |
|
|
|
201 |
|
|
suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki> |
202 |
|
|
|
203 |
|
|
=head1 LICENSE |
204 |
|
|
|
205 |
|
|
Copyright 2002-2003 Wakaba <w@suika.fam.cx> |
206 |
|
|
|
207 |
|
|
This program is free software; you can redistribute it and/or |
208 |
|
|
modify it under the same terms as Perl itself. |
209 |
|
|
|
210 |
|
|
=cut |
211 |
|
|
|
212 |
wakaba |
1.6 |
1; # $Date: 2003/07/17 23:58:41 $ |