/[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.6 - (hide annotations) (download)
Thu Mar 27 04:17:47 2003 UTC (22 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.5: +67 -12 lines
WikiPage.wps: Namespace support

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24