/[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.8 - (hide annotations) (download)
Thu Apr 3 01:07:41 2003 UTC (22 years ago) by wakaba
Branch: MAIN
Changes since 1.7: +0 -21 lines
*** empty log message ***

1 w 1.1 Name:
2     WikiPage
3     FullName:
4     Getting WikiPage information
5     URI:
6     IW:SuikaWiki:WikiAdmin
7    
8     {
9     Name:
10     wikiform_input/recent-change-list
11     FullName:
12     Recent-changed-pages list
13     Format:
14     eval q{
15 w 1.3 if ($o->{to} eq 'RSS') {
16     require Yuki::RSS;
17     my $rss = new Yuki::RSS (version => '1.0');
18     my $myuri = $o->uri ('wiki');
19 wakaba 1.6 #$rss->stylesheet (
20     # href => $myuri . "?mycmd=css;mypage=WikiStyle:RSS",
21     # type => 'text/css',
22     #);
23 w 1.3 $rss->channel(
24 wakaba 1.6 xml_declare => 0,
25 w 1.3 title => $o->resource ('RSS:WikiTitle'),
26     link => $myuri,
27     description => $o->resource ('RSS:WikiDescription'),
28     'dc:language' => $main::lang,
29     );
30 wakaba 1.7 $p->{ns} .= '//' if $p->{ns} && $p->{ns} !~ m#//$#;
31     for my $title ($main::database->recent_changes (($p->{n} || 10),0,{ns => $p->{ns}, recursive => (defined $p->{recursive} ? $p->{recursive} : 1)})) {
32 w 1.3 next unless $title;
33     $rss->add_item (
34     title => $o->escape ($title),
35     link => $myuri . '?' . $o->encode ($title),
36     description => $o->escape(&main::get_subjectline($title,delimiter=>'')),
37     'dc:date' => $main::database->mtime ($title),
38     );
39     }
40     $r = $rss->as_string;
41     } else {
42     $r = qq(<ol class="recent-changes">\n);
43 wakaba 1.6 $p->{ns} .= '//' if $p->{ns} && $p->{ns} !~ m#//$#;
44     for ($main::database->recent_changes (($p->{n} || 10),0,{ns => $p->{ns}, recursive => (defined $p->{recursive} ? $p->{recursive} : 1)})) {
45 w 1.3 next unless $_;
46     my @date = gmtime $main::database->mtime ($_);
47     $date[0] = sprintf '%04d-%02d-%02d %02d:%02d:%02d+00:00', $date[5]+1900,$date[4]+1,@date[3,2,1,0];
48 wakaba 1.6 $r .= qq(<li><span class="date">$date[0]</span> <a href="@{[$o->escape(compose_wiki_page_uri ($o, $p, {page => $_,with_lm=>1}))]}" class="wiki">) . $o->escape ($_) . qq(</a>);
49 w 1.3 $r .= ' <span class="summary">'.$o->escape (&main::get_subjectline ($_)).'</span>' if $p->{summary};
50     $r .= qq(</li>\n);
51     }
52     $r .= '</ol>';
53 w 1.1 }
54     } or $r = '';
55     }
56    
57     {
58     Name:
59 w 1.4 wikiview/recent-change-dated
60     FullName:
61     Recent-changed-pages list, grouped by modified date
62     Format:
63     eval q{
64     $r = qq(<div class="recent-changes">\n);
65     my $date = '';
66 wakaba 1.7 $p->{ns} .= '//' if $p->{ns} && $p->{ns} !~ m#//$#;
67     for ($main::database->recent_changes (($p->{n} || 10),0,{ns => $p->{ns}, recursive => (defined $p->{recursive} ? $p->{recursive} : 1)})) {
68 w 1.4 next unless $_;
69     my @date = gmtime $main::database->mtime ($_);
70     my $ndate = sprintf '%04d-%02d-%02d', $date[5]+1900,$date[4]+1,$date[3];
71     if ($ndate ne $date) {
72     $r .= "</ol>\n" if $date;
73     my $id = 'h'.$o->new_index ('heading');
74     my $level = $p->{level}+0||1;
75     $r .= qq(<h$level id="$id">$ndate</h$level>\n<ol>\n);
76     push @{$o->{toc}}, [$level-1 => $id => $ndate] if !defined $p->{add_to_toc} || $p->{add_to_toc};
77     $date = $ndate;
78     }
79     $date[0] = sprintf '%s %02d:%02d:%02d+00:00', $ndate, @date[2,1,0];
80     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="@{[$o->escape (&main::get_subjectline ($_,delimiter=>''))]} [$date[0]]">) . $o->escape ($_) . qq(</a></li>\n);
81     }
82     $r .= '</ol></div>';
83     } or $r = $o->escape($@);
84     }
85     {
86     Name:
87     wikiform_input/recent-change-dated
88     FullName:
89     Recent-changed-pages list, grouped by modified date
90     Format:
91     eval q{
92     $r = qq(<div class="recent-changes">\n);
93     my $date = '';
94 wakaba 1.7 $p->{ns} .= '//' if $p->{ns} && $p->{ns} !~ m#//$#;
95     for ($main::database->recent_changes (($p->{n} || 10),0,{ns => $p->{ns}, recursive => (defined $p->{recursive} ? $p->{recursive} : 1)})) {
96 w 1.4 next unless $_;
97     my @date = gmtime $main::database->mtime ($_);
98     my $ndate = sprintf '%04d-%02d-%02d', $date[5]+1900,$date[4]+1,$date[3];
99     if ($ndate ne $date) {
100     $r .= "</ol>\n" if $date;
101     my $id = 'h'.$o->new_index ('heading');
102     my $level = ($p->{level}+0||1)+1;
103     $r .= qq(<h$level id="$id">$ndate</h$level>\n<ol>\n);
104     push @{$o->{toc}}, [$level-1 => $id => $ndate] if !defined $p->{add_to_toc} || $p->{add_to_toc};
105     $date = $ndate;
106     }
107     $date[0] = sprintf '%s %02d:%02d:%02d+00:00', $ndate, @date[2,1,0];
108     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="@{[$o->escape($_)]} [$date[0]]">) . $o->escape ($_) . qq(</a></li>\n);
109     }
110     $r .= '</ol></div>';
111     } or $r = $o->escape($@);
112     }
113    
114     {
115     Name:
116 w 1.1 wikiform_input/page-list
117 wakaba 1.7 wikiview/page-list
118 w 1.1 FullName:
119     WikiPage list
120     Format:
121     eval q{
122     my $re = $p->{match} || '.';
123 wakaba 1.7 if ($o->_database) {
124 wakaba 1.6 $p->{ns} .= '//' if $p->{ns} && $p->{ns} !~ m#//$#;
125 wakaba 1.7 for (sort grep /$re/, $o->_database->list_items ({ns => $p->{ns}, type => ($p->{type}||'key'), recursive => $p->{recursive}})) {
126     $r .= q(<li>);
127     if ($p->{template} && index ($p->{-option}->{template}, 'p') == -1) {
128     my $new_o = bless {$o}, 'SuikaWiki::Plugin';
129     $new_o->{caller_page} = $o->{page};
130     $new_o->{page} = $_;
131     my $f = $new_o->formatter ('page_list_item');
132     my $fs = $new_o->formatter ('page_list_item_safe');
133     $r .= $f->replace ($p->{template}, $new_o, {formatter => $f, formatter_s => $fs});
134     } else {
135     $r .= qq(<a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki">) . $o->escape ($_) . qq(</a>);
136     $r .= ' <span class="summary">'.$o->escape (&main::get_subjectline ($_)).'</span>' if $p->{summary};
137     }
138 wakaba 1.6 $r .= qq(</li>\n);
139     }
140 wakaba 1.7 } elsif (!$p->{ns}) {
141 wakaba 1.6 for (sort grep /$re/, keys %main::database) {
142     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki">) . $o->escape ($_) . qq(</a>);
143     $r .= ' <span class="summary">'.$o->escape (&main::get_subjectline ($_)).'</span>' if $p->{summary};
144     $r .= qq(</li>\n);
145     }
146 w 1.1 }
147 wakaba 1.7 $r = qq(<ul class="pages">$r</ul>) if $r;
148     1;
149     } or $r = qq(<div class="error">@{[$o->escape ($@)]}</div>);
150     }
151    
152     {
153     Name:
154     wikipage_list_item/-bare_text
155     FullName:
156     HTML escape for bare text
157     Format:
158     $r = $o->escape ($p->{-bare_text});
159 w 1.3 }
160    
161     {
162     Name:
163     wikiformat/SuikaWiki/0.9-to-RSS
164     FullName:
165     SuikaWiki/0.9 document format -> RSS
166     URI:
167     IW:SuikaWiki:SuikaWiki
168     Format:
169     $o->{content} =~ s($main::embed_command{form}){
170     my $i = $2;
171     $i =~ s/\\(.)/$1/gs;
172     if ($i =~ /(%recent-change-list(?:\((?:[^)]|\\.)*\))?;)/s) {
173     $r = $o->formatter ('form_input')->replace ($1 => $o);
174     return $r;
175     }
176     ''}ge;
177 wakaba 1.6 $r = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>';
178 w 1.4 }
179    
180     {
181     Name:
182     wikiview/search-result
183     FullName:
184     Search result of given page name
185     Format:
186     ($r) = main::get_search_result ($o->{page});
187     }
188    
189     {
190     Name:
191     wikiform_input/search-result
192     FullName:
193     Search result with the given string
194     Format:
195     my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};
196     my @r;
197     my $sr = $o->cache ('search');
198     unless (defined $sr->{$word}) {
199     for my $page (keys %main::database) {
200     my ($magic, $content) = $o->magic_and_content ($main::database{$page});
201     $content = $p->{case_sensible} ? $content : lc $content;
202     $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
203     if (index (lc $page, $word) > -1) {
204     my $c = $content =~ s/\Q$word\E//g;
205     push @r, [$page, $c+20];
206     } elsif (index ($word, lc $page) > -1) {
207     my $c = $content =~ s/\Q$word\E//g;
208     push @r, [$page, $c+10];
209     } elsif (my $c = $content =~ s/\Q$word\E//g) {
210     push @r, [$page, $c];
211     }
212     }
213     @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
214     $sr->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r;
215     } else {
216     @r = map {[split /\x1F/, $_, 2]} split /\x1E/, $sr->{$word};
217     }
218     my $em = $p->{em} ? sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s } : sub {$_[0]};
219     $r = join "\n", map {qq(<li>[$_->[1]] <a href ="@{[$o->uri('wiki').'?'.$o->encode($_->[0])]}" class="wiki">@{[&$em($o->escape($_->[0]))]}</a> <span class="headline">@{[&$em($o->escape(&main::get_subjectline($_->[0])))]}</span></li>)} @r;
220     $r = qq|<ul class="search-result">$r</ul>| if $r;
221     }
222    
223     {
224     Name:
225     wikiview/link-map
226     FullName:
227     Hyperlink map from the WikiPage
228     Format:
229     sub make_list ($;%) {
230     my ($page, %option) = @_;
231     $option{level} ||= 3;
232     my %weight;
233     my $content = $main::database{$page};
234     $content =~ s{^\#\?([^\x0A\x0D]+)}{
235     if ($1 =~ /import="([^"]+)"/) {
236     for (split /\s*,\s*/, $1) {
237     $weight{$_} += 2;
238     }
239     }
240     $&;
241     }ges;
242     ## Bug: this code does not support content type.
243     $content =~ s{\[\[((?!\#)[^]]+)\](?:>>\d+)?\]}{
244     $weight{$1}++; $&;
245     }ge;
246     delete $weight{$page}; ## Delete myself
247     for my $page (keys %weight) {
248     my $w = ($content =~ s/\Q$page\E/$&/g);
249     $weight{$page} += $w + $weight{$page}; ## Weight of [[name]] is x2.
250 w 1.5 ($weight{$page} *= 0.1, $option{not_exist}->{$page} = 1) unless exists $main::database {$page};
251 w 1.4 }
252     $option{weight_list}->{$page} = \%weight;
253     if (--$option{level}) {
254     for my $page (keys %weight) {
255     &make_list ($page, %option) unless $option{weight_list}->{$page};
256     }
257     }
258     $option{weight_list};
259     }
260    
261     sub list_to_html ($$;%) {
262     my ($Page, $wlist, %option) = @_;
263     my $r = '';
264     $option{outputed}->{$Page} = 1;
265     for my $page (sort {$wlist->{$Page}->{$b} <=> $wlist->{$Page}->{$a}} keys %{$wlist->{$Page}}) {
266     $r .= qq(<li><span class="weight">[@{[0+$wlist->{$Page}->{$page}]}]</span> <a href="$main::url_cgi?@{[&main::encode($page)]}" class="wiki@{[$option{not_exist}->{$page}?' not-exist':'']}">@{[$o->escape ($page).($option{not_exist}->{$page}?qq(<span class="mark">@{[$o->resource('JumpAndEditWikiPageMark',escape=>1)]}</span>):'')]}</a> <a href="$main::url_cgi?mycmd=map;mypage=@{[&main::encode($page)]}" class="wiki-cmd map-from-here" title="@{[&main::escape($option{map_from_here_description})]}">@{[$o->escape($option{map_from_here})]}</a> <span class="summary">@{[$o->escape(&main::get_subjectline($page))]}</span>);
267     unless ($option{outputed}->{$page}) {
268     $r .= &list_to_html ($page, $wlist, %option);
269     }
270     $r .= "</li>\n";
271     }
272     $r ? qq(<ul class="map">$r</ul>) : '';
273     }
274    
275     my %option = (level => 0+$o->resource('Map:Depth'), weight_list => {},
276     not_exist => {}, map_from_here => $o->resource('Map:FromHere'),
277     map_from_here_description => $o->resource('Map:FromHereLong'));
278     &make_list ($o->{page}, %option);
279     $r = &list_to_html ($o->{page}, $option{weight_list}, %option);
280     }
281    
282     {
283     Name:
284     wikiview/last-modified
285     FullName:
286     Last-modified date & time of the page
287     Format:
288     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
289     }
290     {
291     Name:
292     wikiview-resource/last-modified
293     FullName:
294     Last-modified date & time of the page
295     Format:
296     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
297     }
298     {
299     Name:
300     wikiform_input/last-modified
301     FullName:
302     Last-modified date & time of the page
303     Format:
304     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
305     }
306     {
307     Name:
308 wakaba 1.7 wikiview-resource/page-name
309     wikiform_input/page-name
310     FullName:
311     Page name
312     Format:
313     $r = $o->escape ($o->{page});
314     }
315     {
316     Name:
317 w 1.4 wikiview/page-name
318 wakaba 1.7 wikipage_list_item/page-name
319     wikiview-resource-safe/page-name
320 w 1.4 FullName:
321     Page name
322     Format:
323 wakaba 1.7 $r = $o->{page};
324     $r = $o->escape ($r) unless $p->{safe};
325 w 1.4 }
326     {
327     Name:
328 wakaba 1.7 wikipage_list_item_safe/page-name
329     wikiform_input_safe/page-name
330 w 1.4 FullName:
331     Page name
332     Format:
333 wakaba 1.7 $r = $o->{page};
334 w 1.4 }
335 wakaba 1.7
336 w 1.4 {
337     Name:
338     wikiview/wiki-link
339 wakaba 1.7 wikiview-resource/wiki-link
340 w 1.4 FullName:
341     Link to the WikiPage
342     Format:
343     $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => 1);
344     }
345     {
346     Name:
347 wakaba 1.7 wikipage_list_item/wiki-link
348 w 1.4 FullName:
349     Link to the WikiPage
350     Format:
351 wakaba 1.7 $r = $o->_html_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => $p->{up_to_date}, label => $p->{label});
352 w 1.4 }
353    
354     {
355     Name:
356     wikiview/link-wiki
357     FullName:
358     Link element to the wiki itself
359     Format:
360     unless ($p->{href}) {
361     $p->{mode} ||= 'read';
362 wakaba 1.7 $p->{page} ||= $o->{page};
363 w 1.4 $p->{href} = $o->uri('wiki').'?';
364     if ($p->{up_to_date} || $p->{mode} ne 'read' || $p->{add_param}) {
365     $p->{href} .= qq(mypage=@{[$o->encode($p->{page})]};mycmd=@{[$o->encode($p->{mode})]});
366     $p->{href} .= ';'.$p->{add_param} if $p->{add_param};
367     $p->{href} .= ';x-d='.time if $p->{up_to_date};
368     $p->{href} .= ';x-lm='.($main::database->mtime ($p->{page})||0) if $p->{with_lm};
369     } else {
370     $p->{href} .= $o->encode ($p->{page});
371     }
372     }
373     $r = qq(<link);
374 wakaba 1.7 for my $attr (qw/rel rev href title class type hreflang charset/) {
375 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
376     }
377     $r .= '/' if $o->{media}->{type} =~ /xml/;
378     $r .= '>';
379     }
380     {
381     Name:
382     wikiview/anchor-wiki
383     FullName:
384     A element to the wiki page
385     Format:
386 wakaba 1.7 $p->{href} ||= compose_wiki_page_uri ($o, $p, {});
387     $p->{label} = $p->{page} unless length $p->{label};
388     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
389     $p->{title} = $p->{page};
390     }
391     $r = qq(<a);
392     for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
393     $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
394 w 1.4 }
395 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
396     }
397     {
398     Name:
399     wikiview-resource/anchor-wiki
400     FullName:
401     A element to the wiki page
402     Format:
403     $p->{href} = compose_wiki_page_uri ($o, $p, {});
404     $p->{label} = $p->{page} unless length $p->{label};
405     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
406     $p->{title} = $p->{page} || $o->{page};
407 w 1.4 }
408     $r = qq(<a);
409 wakaba 1.7 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
410 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
411     }
412 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
413 w 1.4 }
414    
415     {
416     Name:
417     wikiview/referer-list
418     FullName:
419     Referer-list of page
420     Format:
421     $r = wiki::referer::list_html ($o->{page});
422     }
423    
424     {
425     Name:
426     wikiview/uri-wiki
427     FullName:
428     Output URI of the WikiPage (as anchor)
429     Format:
430     my $uri = $o->uri('wiki').'?'.$o->encode($p->{page}||$o->{page});
431     $r = qq(&lt;<a href="$uri">$uri</a>&gt;);
432 w 1.1 }
433 wakaba 1.6
434     {
435     Name:
436     wikiview/log-hotness
437     FullName:
438     Logging hotness of the page
439     Format:
440     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
441     $db->{$o->{page}||$p->{page}} += ($p->{weight} || 1);
442     }
443     {
444     Name:
445     wikiform_input/hotness-list
446     FullName:
447     Hotness-of-pages' list
448     Format:
449     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
450     my $i = 0;
451     $r = qq(<ol class="hotness">\n);
452     for (sort {$db->{$b}<=>$db->{$a}} grep {$db->{$_} > $p->{threshold}} keys %$db) {
453     do {$i++; next if $i > $p->{n}} if $p->{n};
454     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="{@{[$db->{$_}+0]}}">) . $o->escape ($_) . qq(</a></li>\n);
455     }
456     $r .= '</ol>';
457     }
458    
459     MODULE:
460     sub compose_wiki_page_uri ($$$) {
461     my ($o, $p, $q) = @_;
462     $q->{mode} ||= $p->{mode} || 'read';
463     $q->{page} ||= $p->{page} || $o->{page};
464     $q->{add_param} ||= $p->{add_param};
465     $q->{up_to_date} = $p->{up_to_date} unless defined $q->{up_to_date};
466     $q->{with_lm} = $p->{with_lm} unless defined $q->{with_lm};
467     $q->{href} = $o->uri('wiki').'?';
468     if ($q->{up_to_date} || $q->{mode} ne 'read' || $q->{add_param} || $q->{with_lm}) {
469     $q->{href} .= qq(mypage=@{[$o->encode($q->{page})]};mycmd=@{[$o->encode($q->{mode})]});
470     $q->{href} .= ';'.$q->{add_param} if $q->{add_param};
471     $q->{href} .= ';x-d='.time if $q->{up_to_date};
472     $q->{href} .= ';x-lm='.($main::database->mtime ($q->{page})||0) if $q->{with_lm};
473     } else {
474     $q->{href} .= $o->encode ($q->{page});
475     }
476 wakaba 1.7 $q->{href};
477 wakaba 1.6 }
478 w 1.1
479     POD:LICENSE:
480     Copyright 2003 Wakaba <w@suika.fam.cx>
481    
482     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24