/[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.17 - (hide annotations) (download)
Sun Oct 5 11:55:09 2003 UTC (21 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.16: +4 -2 lines
Some temporary modifications

1 w 1.1 Name:
2     WikiPage
3     FullName:
4     Getting WikiPage information
5     URI:
6     IW:SuikaWiki:WikiAdmin
7 wakaba 1.14 Require:
8     SuikaWiki::Markup::XML main
9 wakaba 1.9 Initialize:
10     my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
11 w 1.4
12     {
13     Name:
14     wikiview/search-result
15     wikiform_input/search-result
16     FullName:
17     Search result with the given string
18     Format:
19 wakaba 1.9 $p->{key} ||= $o->{page};
20 w 1.4 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 wakaba 1.9 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 wakaba 1.14 $hl->append_text (__PACKAGE__->_get_subjectline ($_->[0]));
56 wakaba 1.9 $ul->append_text ("\n");
57 w 1.4 }
58 wakaba 1.14 $r = $ul if $ul->count;
59 w 1.4 }
60    
61     {
62     Name:
63     wikiview/last-modified
64     wikiview-resource/last-modified
65 w 1.16 wikiform-input/last-modified
66 w 1.4 FullName:
67     Last-modified date & time of the page
68     Format:
69 wakaba 1.17 $r = SuikaWiki::Markup::XML->new (type => '#text', value => &main::_rfc3339_date ($o->get_data (lastmodified => [$p->{page} || $o->{page}])));
70     ## TODO:
71 w 1.4 }
72     {
73     Name:
74 w 1.16 wikipage-link/last-modified
75 w 1.4 FullName:
76     Last-modified date & time of the page
77     Format:
78 wakaba 1.17 $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 w 1.4 }
81 w 1.16
82 w 1.4 {
83     Name:
84 wakaba 1.7 wikiview-resource/page-name
85 w 1.16 wikiform-input/page-name
86 w 1.4 wikiview/page-name
87 wakaba 1.7 wikipage_list_item/page-name
88 w 1.4 FullName:
89     Page name
90     Format:
91 wakaba 1.10 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{page});
92 w 1.4 }
93 wakaba 1.7
94 w 1.4 {
95     Name:
96 wakaba 1.13 wikipage-link/page-name
97     FullName:
98     Name of the WikiPage
99     Format:
100     if ($p->{relative}) {
101 w 1.16 $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 wakaba 1.13 $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 wakaba 1.14 $r = SuikaWiki::Markup::XML->new (type => '#text', value => __PACKAGE__->_get_subjectline ($o->{link}->{dest}->{page_name}, delimiter => ''));
135 wakaba 1.13 }
136    
137     {
138     Name:
139 w 1.4 wikiview/wiki-link
140 wakaba 1.7 wikiview-resource/wiki-link
141 w 1.4 FullName:
142     Link to the WikiPage
143     Format:
144 wakaba 1.13 $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => 1);
145 w 1.4 }
146     {
147     Name:
148 wakaba 1.7 wikipage_list_item/wiki-link
149 w 1.4 FullName:
150     Link to the WikiPage
151     Format:
152 wakaba 1.13 $r = $o->_html_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => $p->{up_to_date}, label => $p->{label});
153 w 1.4 }
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 wakaba 1.7 $p->{page} ||= $o->{page};
164 w 1.4 $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 wakaba 1.11 for my $attr (qw/rel rev href title class type hreflang charset accesskey/) {
176 w 1.4 $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 wakaba 1.7 $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 w 1.4 }
196 wakaba 1.7 $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 w 1.4 }
209     $r = qq(<a);
210 wakaba 1.7 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
211 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
212     }
213 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
214 w 1.4 }
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 w 1.1 }
225 wakaba 1.6
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 wakaba 1.7 $q->{href};
269 wakaba 1.6 }
270 wakaba 1.14
271     ## TODO: obsolete this function in the future
272     sub _get_subjectline {
273 wakaba 1.15 my (undef, $page, %option) = @_;
274 wakaba 1.14 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 wakaba 1.11 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 wakaba 1.9
341 w 1.1
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