/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/WikiPage.wps
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/WikiPage.wps

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Thu Oct 30 07:45:10 2003 UTC (21 years, 5 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +0 -0 lines
FILE REMOVED
Remove some obsolete rules

1 Name:
2 WikiPage
3 FullName:
4 Getting WikiPage information
5 URI:
6 IW:SuikaWiki:WikiAdmin
7 Require:
8 SuikaWiki::Markup::XML main
9 Initialize:
10 my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
11
12 {
13 Name:
14 wikiview/search-result
15 wikiform_input/search-result
16 FullName:
17 Search result with the given string
18 Format:
19 $p->{key} ||= $o->{page};
20 my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};
21 my @r;
22 my $sr = $o->cache ('search');
23 unless (defined $sr->{$word}) {
24 for my $page (keys %main::database) {
25 my ($magic, $content) = $o->magic_and_content ($main::database{$page});
26 $content = $p->{case_sensible} ? $content : lc $content;
27 $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
28 if (index (lc $page, $word) > -1) {
29 my $c = $content =~ s/\Q$word\E//g;
30 push @r, [$page, $c+20];
31 } elsif (index ($word, lc $page) > -1) {
32 my $c = $content =~ s/\Q$word\E//g;
33 push @r, [$page, $c+10];
34 } elsif (my $c = $content =~ s/\Q$word\E//g) {
35 push @r, [$page, $c];
36 }
37 }
38 @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
39 $sr->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r;
40 } else {
41 @r = map {[split /\x1F/, $_, 2]} split /\x1E/, $sr->{$word};
42 }
43 my $em = $p->{em} ? sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s } : sub {$_[0]};
44 my $ul = SuikaWiki::Markup::XML->new (local_name => 'ul', namespace_uri => $NS_XHTML1);
45 for (@r) {
46 my $li = $ul->append_new_node (local_name => 'li', namespace_uri => $NS_XHTML1);
47 $li->append_text ('{' . $_->[1] . '} ');
48 my $a = $li->append_new_node (local_name => 'a', namespace_uri => $NS_XHTML1);
49 $a->set_attribute (href => $o->uri('wiki').'?'.$o->encode($_->[0]));
50 $a->set_attribute (class => 'wiki');
51 $a->append_text ($_->[0]);
52 $li->append_text (' ');
53 my $hl = $li->append_new_node (local_name => 'span', namespace_uri => $NS_XHTML1);
54 $hl->set_attribute (class => 'headline');
55 $hl->append_text (__PACKAGE__->_get_subjectline ($_->[0]));
56 $ul->append_text ("\n");
57 }
58 $r = $ul if $ul->count;
59 }
60
61 {
62 Name:
63 wikiview/last-modified
64 wikiview-resource/last-modified
65 wikiform-input/last-modified
66 FullName:
67 Last-modified date & time of the page
68 Format:
69 $r = SuikaWiki::Markup::XML->new (type => '#text', value => &main::_rfc3339_date ($o->get_data (lastmodified => [$p->{page} || $o->{page}])));
70 ## TODO:
71 }
72 {
73 Name:
74 wikipage-link/last-modified
75 FullName:
76 Last-modified date & time of the page
77 Format:
78 $r = SuikaWiki::Markup::XML->new (type => '#text', value => &main::_rfc3339_date ($o->{link}->{dest}->{page_lastmodified} || $o->get_data (lastmodified => [$o->{link}->{dest}->{page_name}])));
79 ## TODO: temp.
80 }
81
82 {
83 Name:
84 wikiview-resource/page-name
85 wikiform-input/page-name
86 wikiview/page-name
87 wikipage_list_item/page-name
88 FullName:
89 Page name
90 Format:
91 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{page});
92 }
93
94 {
95 Name:
96 wikipage-link/page-name
97 FullName:
98 Name of the WikiPage
99 Format:
100 if ($p->{relative}) {
101 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name_relative});
102 } else {
103 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name});
104 }
105 }
106
107 {
108 Name:
109 wikipage-link/page-title
110 FullName:
111 Title of the WikiPage
112 Description:
113 Returns title of the destination WikiPage.
114 Note that currently WikiPage itself cannot have page title information
115 so that title not same as WikiName is only able to be specified by
116 generator of the link context. (In other words, customized title is
117 defined by the link, not the page linked to.)
118 Format:
119 if (defined $o->{link}->{dest}->{page_title}) {
120 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_title});
121 } elsif ($p->{relative}) {
122 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name_relative});
123 } else {
124 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name});
125 }
126 }
127
128 {
129 Name:
130 wikipage-link/page-headline
131 FullName:
132 Headline of the WikiPage
133 Format:
134 $r = SuikaWiki::Markup::XML->new (type => '#text', value => __PACKAGE__->_get_subjectline ($o->{link}->{dest}->{page_name}, delimiter => ''));
135 }
136
137 {
138 Name:
139 wikiview/wiki-link
140 wikiview-resource/wiki-link
141 FullName:
142 Link to the WikiPage
143 Format:
144 $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => 1);
145 }
146 {
147 Name:
148 wikipage_list_item/wiki-link
149 FullName:
150 Link to the WikiPage
151 Format:
152 $r = $o->_html_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => $p->{up_to_date}, label => $p->{label});
153 }
154
155 {
156 Name:
157 wikiview/link-wiki
158 FullName:
159 Link element to the wiki itself
160 Format:
161 unless ($p->{href}) {
162 $p->{mode} ||= 'read';
163 $p->{page} ||= $o->{page};
164 $p->{href} = $o->uri('wiki').'?';
165 if ($p->{up_to_date} || $p->{mode} ne 'read' || $p->{add_param}) {
166 $p->{href} .= qq(mypage=@{[$o->encode($p->{page})]};mycmd=@{[$o->encode($p->{mode})]});
167 $p->{href} .= ';'.$p->{add_param} if $p->{add_param};
168 $p->{href} .= ';x-d='.time if $p->{up_to_date};
169 $p->{href} .= ';x-lm='.($main::database->mtime ($p->{page})||0) if $p->{with_lm};
170 } else {
171 $p->{href} .= $o->encode ($p->{page});
172 }
173 }
174 $r = qq(<link);
175 for my $attr (qw/rel rev href title class type hreflang charset accesskey/) {
176 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
177 }
178 $r .= '/' if $o->{media}->{type} =~ /xml/;
179 $r .= '>';
180 }
181 {
182 Name:
183 wikiview/anchor-wiki
184 FullName:
185 A element to the wiki page
186 Format:
187 $p->{href} ||= compose_wiki_page_uri ($o, $p, {});
188 $p->{label} = $p->{page} unless length $p->{label};
189 if ($p->{page} ne $p->{label} && !defined $p->{title}) {
190 $p->{title} = $p->{page};
191 }
192 $r = qq(<a);
193 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
194 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
195 }
196 $r .= '>' . $o->escape ($p->{label}) . '</a>';
197 }
198 {
199 Name:
200 wikiview-resource/anchor-wiki
201 FullName:
202 A element to the wiki page
203 Format:
204 $p->{href} = compose_wiki_page_uri ($o, $p, {});
205 $p->{label} = $p->{page} unless length $p->{label};
206 if ($p->{page} ne $p->{label} && !defined $p->{title}) {
207 $p->{title} = $p->{page} || $o->{page};
208 }
209 $r = qq(<a);
210 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
211 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
212 }
213 $r .= '>' . $o->escape ($p->{label}) . '</a>';
214 }
215
216 {
217 Name:
218 wikiview/uri-wiki
219 FullName:
220 Output URI of the WikiPage (as anchor)
221 Format:
222 my $uri = $o->uri('wiki').'?'.$o->encode($p->{page}||$o->{page});
223 $r = qq(&lt;<a href="$uri">$uri</a>&gt;);
224 }
225
226 {
227 Name:
228 wikiview/log-hotness
229 FullName:
230 Logging hotness of the page
231 Format:
232 my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
233 $db->{$o->{page}||$p->{page}} += ($p->{weight} || 1);
234 }
235 {
236 Name:
237 wikiform_input/hotness-list
238 FullName:
239 Hotness-of-pages' list
240 Format:
241 my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
242 my $i = 0;
243 $r = qq(<ol class="hotness">\n);
244 for (sort {$db->{$b}<=>$db->{$a}} grep {$db->{$_} > $p->{threshold}} keys %$db) {
245 do {$i++; next if $i > $p->{n}} if $p->{n};
246 $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="{@{[$db->{$_}+0]}}">) . $o->escape ($_) . qq(</a></li>\n);
247 }
248 $r .= '</ol>';
249 }
250
251 MODULE:
252 sub compose_wiki_page_uri ($$$) {
253 my ($o, $p, $q) = @_;
254 $q->{mode} ||= $p->{mode} || 'read';
255 $q->{page} ||= $p->{page} || $o->{page};
256 $q->{add_param} ||= $p->{add_param};
257 $q->{up_to_date} = $p->{up_to_date} unless defined $q->{up_to_date};
258 $q->{with_lm} = $p->{with_lm} unless defined $q->{with_lm};
259 $q->{href} = $o->uri('wiki').'?';
260 if ($q->{up_to_date} || $q->{mode} ne 'read' || $q->{add_param} || $q->{with_lm}) {
261 $q->{href} .= qq(mypage=@{[$o->encode($q->{page})]};mycmd=@{[$o->encode($q->{mode})]});
262 $q->{href} .= ';'.$q->{add_param} if $q->{add_param};
263 $q->{href} .= ';x-d='.time if $q->{up_to_date};
264 $q->{href} .= ';x-lm='.($main::database->mtime ($q->{page})||0) if $q->{with_lm};
265 } else {
266 $q->{href} .= $o->encode ($q->{page});
267 }
268 $q->{href};
269 }
270
271 ## TODO: obsolete this function in the future
272 sub _get_subjectline {
273 my (undef, $page, %option) = @_;
274 my $SubjectLine = SuikaWiki::Plugin->cache ('headline');
275 unless (defined $SubjectLine->{$page}) {
276 if (not &main::is_editable($page)) {
277 $SubjectLine->{$page} = "";
278 } else {
279 $SubjectLine->{$page} = do {
280 my $s=$main::database{$page};
281 $s =~ tr/\x0D//d;
282 $s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
283 $s =~ s/\x0A\x0A.*//s;
284 if (length ($s) > 500) {
285 $s = substr ($s, 0, 500);
286 $s =~ s/[^\x09\x0A\x20-\x7E]+$//s;
287 $s .= '...';
288 }
289 #if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/s) {
290 # $s = $1;
291 #}
292 $s =~ s/[\x09\x0A\x20]+/\x20/gs;
293 $s =~ s/^[-=*>,:]+//;
294 $s =~ s/'''?//g;
295 $s =~ s/\[\[([^]]+)\]\]/$1/g;
296 $s =~ s/__&&([^&]+)&&__/$1/g;
297 $s =~ s/\[[A-Z]+(?:\([^)]+\))?\[([^]]+)\](?:\s\[([^]]+)\])?\]/$1$2/g;
298 $s =~ s/\([^\(\)]+\)//g;
299 $s =~ s/\[[^\[\]]+\]//g;
300 $s =~ s/>>[0-9]+//g;
301 $s =~ s/<[^<>]+>//g;
302 $s =~ s/20[0-9][0-9]-[01][0-9]-[0-3][0-9]\x20*[0-2][0-9]:[0-5][0-9]//g;
303 $s =~ s/ [Aa]n? / /g;
304 $s =~ s/ [Aa]t / @ /g;
305 $s =~ s/ [Tt]he / /g;
306 $s =~ s/,? and / & /g;
307 $s =~ s!,? or ! / !g;
308 $s =~ s! not !n't !g;
309 $s =~ s! (?:i|ha)s !'s !g;
310 $s =~ s! are !'re !g;
311 $s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge;
312 $s =~ s!です。!。!g;
313 $s =~ s!ました。!た。!g;
314 $s =~ s!ありません!ない!g;
315 $s =~ s!します!する!g;
316 $s =~ s!(?:り)?ます!る!g;
317 $s =~ s!いよいよ|とうとう|ようやく!!g;
318 $s =~ s!とりあえず!!g;
319 $s =~ s!(?:、|。|[.,])\x20?$!!g;
320 $s =~ s/\x20+/\x20/g;
321 if (length ($s) > 400) {
322 $s = substr ($s, 0, 400);
323 $s =~ s/[^\x20-\x7E]+$//s;
324 $s .= '...';
325 }
326 $s};
327 }
328 }
329 if (length $SubjectLine->{$page}) {
330 $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : SuikaWiki::Plugin->resource('Title-Summary Delimiter');
331 $option{delimiter}.$SubjectLine->{$page}.$option{tail};
332 } else {
333 '';
334 }
335 } # main::get_subjectline
336
337 SuikaWiki::View->template ('links')->add_line (<<EOH);
338 %link-wiki(page=>@{[$main::PageName{SearchPage}]},rel=>search,class=>wiki,title=>"%res(name=>GoToSearchPageLink);"p);
339 EOH
340
341
342 POD:LICENSE:
343 Copyright 2003 Wakaba <w@suika.fam.cx>
344
345 %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24