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.7 |
our $VERSION = do{my @r=(q$Revision: 1.6 $=~/\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 |
wakaba |
1.7 |
unless ($Formatter{$t}) { |
68 |
|
|
require Message::Util::Formatter; |
69 |
|
|
$Formatter{$t} = Message::Util::Formatter->new; |
70 |
|
|
## SuikaWiki 2 Interface |
71 |
|
|
for (@{$SuikaWiki::Plugin::List{'wiki'.$t}||[]}) { |
72 |
|
|
$_->load_formatter ($Formatter{$t}, type => 'wiki'.$t); |
73 |
|
|
} |
74 |
|
|
## SuikaWiki 2.9 Interface |
75 |
|
|
for (keys %{$SuikaWiki::Plugin::Rule{$t}||{}}) { |
76 |
|
|
$Formatter{$t}->{$_} = $SuikaWiki::Plugin::Rule{$t}->{$_}->{Formatting}; |
77 |
|
|
} |
78 |
|
|
$Formatter{$t}->option (return_class => 'SuikaWiki::Markup::XML'); |
79 |
|
|
} |
80 |
w |
1.5 |
return $Formatter{$t}; |
81 |
|
|
}} |
82 |
|
|
|
83 |
wakaba |
1.6 |
sub db ($) { |
84 |
|
|
## TODO: common interface to WikiDB |
85 |
wakaba |
1.7 |
$main::WIKI->{db}; |
86 |
wakaba |
1.6 |
} |
87 |
|
|
|
88 |
|
|
sub set_data ($$$$;%) { |
89 |
|
|
my ($self, $prop, $key, $data, %opt) = @_; |
90 |
|
|
## TODO: common interface to WikiDB |
91 |
|
|
## TODO: error recovering |
92 |
wakaba |
1.7 |
$main::WIKI->{db}->set ($prop => $key => $data); |
93 |
wakaba |
1.6 |
if ($opt{-touch}) { |
94 |
wakaba |
1.7 |
$main::WIKI->{db}->set (lastmodified => $key => time); |
95 |
wakaba |
1.6 |
} |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
sub get_data ($$$$;%) { |
99 |
|
|
my ($self, $prop, $key, %opt) = @_; |
100 |
|
|
## TODO: common interface to WikiDB |
101 |
|
|
## TODO: error recovering |
102 |
wakaba |
1.7 |
$main::WIKI->{db}->get ($prop => $key); |
103 |
wakaba |
1.6 |
} |
104 |
|
|
|
105 |
wakaba |
1.1 |
=head1 PLUGIN MANAGER |
106 |
|
|
|
107 |
|
|
=over 4 |
108 |
|
|
|
109 |
w |
1.5 |
=item SuikaWiki::Plugin->import_plugins |
110 |
wakaba |
1.1 |
|
111 |
|
|
Searchs plugins into $plugin_directory and loads all plugins found. |
112 |
|
|
This method should be called at least one time before plugin-required-features |
113 |
|
|
are used. |
114 |
|
|
|
115 |
|
|
=cut |
116 |
|
|
|
117 |
w |
1.5 |
sub import_plugins ($) { |
118 |
wakaba |
1.4 |
my @plugins; |
119 |
|
|
for my $dir ($plugin_directory, @plugin_directory) { |
120 |
|
|
opendir PDIR, $dir; |
121 |
|
|
push @plugins, map {[$_, $dir.'/'.$_.'.pm']} grep {s/\.pm$//} readdir (PDIR); |
122 |
wakaba |
1.1 |
closedir PDIR; |
123 |
wakaba |
1.4 |
} |
124 |
|
|
for my $plugin (@plugins) { |
125 |
|
|
unless ($plugin->[0] =~ /[^A-Za-z0-9_]/) { |
126 |
w |
1.5 |
eval qq{ require \$plugin->[1]; SuikaWiki::Plugin::$plugin->[0]\->import; 1 } or die $@; |
127 |
wakaba |
1.4 |
push @{$List{_all}}, qq(SuikaWiki::Plugin::$plugin->[0]); |
128 |
wakaba |
1.3 |
} |
129 |
wakaba |
1.4 |
} |
130 |
|
|
## callback (onLoad) |
131 |
|
|
for (@{$On{Load}||[]}) { |
132 |
|
|
&{$_}; |
133 |
|
|
} |
134 |
wakaba |
1.1 |
} |
135 |
|
|
|
136 |
|
|
=item SuikaWiki::Plugin::regist ($plugin_package, @categories) |
137 |
|
|
|
138 |
|
|
Regists the plugin categories provided by the plugin package. |
139 |
|
|
This method should be called from plugin packages. |
140 |
|
|
|
141 |
|
|
Example: |
142 |
|
|
|
143 |
|
|
sub import { |
144 |
|
|
my $self = shift; |
145 |
|
|
$self->SuikaWiki::Plugin::regist (qw/wikiform_input/); |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
=cut |
149 |
|
|
|
150 |
|
|
sub regist ($@) { |
151 |
|
|
my $pack = shift; |
152 |
|
|
for (@_) { |
153 |
|
|
push @{$List{$_}}, $pack; |
154 |
|
|
} |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
=back |
158 |
|
|
|
159 |
wakaba |
1.6 |
=head1 WIKIPLUGIN MANAGER OBJECT |
160 |
|
|
|
161 |
|
|
This part implements WikiPlugin manager object of SuikaWiki WikiPlugin |
162 |
|
|
implementation model, second edition. |
163 |
|
|
|
164 |
|
|
=over 4 |
165 |
|
|
|
166 |
|
|
=item $p = SuikaWiki::Plugin->new (wiki => $WIKI) |
167 |
|
|
|
168 |
|
|
Constructs new instance of WikiPlugin manager |
169 |
|
|
|
170 |
|
|
=cut |
171 |
|
|
|
172 |
|
|
sub new ($%) { |
173 |
|
|
my $class = shift; |
174 |
|
|
my $self = bless {@_}, $class; |
175 |
|
|
|
176 |
|
|
$self; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
=item $p->use_type ($type) |
180 |
|
|
|
181 |
|
|
Declares rules classified as $type is to be used. |
182 |
|
|
Even in current implementation this method makes no meaning, |
183 |
|
|
plugin callers must declare by this method for future compatibility. |
184 |
|
|
|
185 |
|
|
=cut |
186 |
|
|
|
187 |
|
|
sub use_type ($$) { |
188 |
|
|
#my ($self, $type) = @_; |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
=item $p->{rule}->{ $type }->{ $name } = { plugin rule definition } |
192 |
|
|
|
193 |
|
|
WikiPlugin rule |
194 |
|
|
|
195 |
|
|
@@TBD@@ |
196 |
|
|
|
197 |
|
|
=item $p->{wiki} |
198 |
|
|
|
199 |
|
|
Wiki implementation $p is associated with |
200 |
|
|
|
201 |
|
|
=back |
202 |
|
|
|
203 |
wakaba |
1.1 |
=head1 SEE ALSO |
204 |
|
|
|
205 |
|
|
suikawiki.pl, suikawiki-config.ph, <IW:SuikaWiki:SuikaWiki> |
206 |
|
|
|
207 |
|
|
=head1 LICENSE |
208 |
|
|
|
209 |
|
|
Copyright 2002-2003 Wakaba <w@suika.fam.cx> |
210 |
|
|
|
211 |
|
|
This program is free software; you can redistribute it and/or |
212 |
|
|
modify it under the same terms as Perl itself. |
213 |
|
|
|
214 |
|
|
=cut |
215 |
|
|
|
216 |
wakaba |
1.7 |
1; # $Date: 2003/10/05 11:55:29 $ |