/[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.15 - (hide annotations) (download)
Sun Jun 1 07:01:37 2003 UTC (21 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.14: +1 -1 lines
*** empty log message ***

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     FullName:
65     Last-modified date & time of the page
66     Format:
67     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
68     }
69     {
70     Name:
71     wikiview-resource/last-modified
72     FullName:
73     Last-modified date & time of the page
74     Format:
75     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
76     }
77     {
78     Name:
79     wikiform_input/last-modified
80     FullName:
81     Last-modified date & time of the page
82     Format:
83     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
84     }
85     {
86     Name:
87 wakaba 1.7 wikiview-resource/page-name
88     wikiform_input/page-name
89 w 1.4 wikiview/page-name
90 wakaba 1.7 wikipage_list_item/page-name
91 w 1.4 FullName:
92     Page name
93     Format:
94 wakaba 1.10 $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{page});
95 w 1.4 }
96 wakaba 1.7
97 w 1.4 {
98     Name:
99 wakaba 1.13 wikipage-link/page-name
100     FullName:
101     Name of the WikiPage
102     Format:
103     if ($p->{relative}) {
104     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name_relative});
105     } else {
106     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name});
107     }
108     }
109    
110     {
111     Name:
112     wikipage-link/page-headline
113     FullName:
114     Headline of the WikiPage
115     Format:
116 wakaba 1.14 $r = SuikaWiki::Markup::XML->new (type => '#text', value => __PACKAGE__->_get_subjectline ($o->{link}->{dest}->{page_name}, delimiter => ''));
117 wakaba 1.13 }
118    
119     {
120     Name:
121 w 1.4 wikiview/wiki-link
122 wakaba 1.7 wikiview-resource/wiki-link
123 w 1.4 FullName:
124     Link to the WikiPage
125     Format:
126 wakaba 1.13 $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => 1);
127 w 1.4 }
128     {
129     Name:
130 wakaba 1.7 wikipage_list_item/wiki-link
131 w 1.4 FullName:
132     Link to the WikiPage
133     Format:
134 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});
135 w 1.4 }
136    
137     {
138     Name:
139     wikiview/link-wiki
140     FullName:
141     Link element to the wiki itself
142     Format:
143     unless ($p->{href}) {
144     $p->{mode} ||= 'read';
145 wakaba 1.7 $p->{page} ||= $o->{page};
146 w 1.4 $p->{href} = $o->uri('wiki').'?';
147     if ($p->{up_to_date} || $p->{mode} ne 'read' || $p->{add_param}) {
148     $p->{href} .= qq(mypage=@{[$o->encode($p->{page})]};mycmd=@{[$o->encode($p->{mode})]});
149     $p->{href} .= ';'.$p->{add_param} if $p->{add_param};
150     $p->{href} .= ';x-d='.time if $p->{up_to_date};
151     $p->{href} .= ';x-lm='.($main::database->mtime ($p->{page})||0) if $p->{with_lm};
152     } else {
153     $p->{href} .= $o->encode ($p->{page});
154     }
155     }
156     $r = qq(<link);
157 wakaba 1.11 for my $attr (qw/rel rev href title class type hreflang charset accesskey/) {
158 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
159     }
160     $r .= '/' if $o->{media}->{type} =~ /xml/;
161     $r .= '>';
162     }
163     {
164     Name:
165     wikiview/anchor-wiki
166     FullName:
167     A element to the wiki page
168     Format:
169 wakaba 1.7 $p->{href} ||= compose_wiki_page_uri ($o, $p, {});
170     $p->{label} = $p->{page} unless length $p->{label};
171     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
172     $p->{title} = $p->{page};
173     }
174     $r = qq(<a);
175     for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
176     $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
177 w 1.4 }
178 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
179     }
180     {
181     Name:
182     wikiview-resource/anchor-wiki
183     FullName:
184     A element to the wiki page
185     Format:
186     $p->{href} = compose_wiki_page_uri ($o, $p, {});
187     $p->{label} = $p->{page} unless length $p->{label};
188     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
189     $p->{title} = $p->{page} || $o->{page};
190 w 1.4 }
191     $r = qq(<a);
192 wakaba 1.7 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
193 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
194     }
195 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
196 w 1.4 }
197    
198     {
199     Name:
200     wikiview/uri-wiki
201     FullName:
202     Output URI of the WikiPage (as anchor)
203     Format:
204     my $uri = $o->uri('wiki').'?'.$o->encode($p->{page}||$o->{page});
205     $r = qq(&lt;<a href="$uri">$uri</a>&gt;);
206 w 1.1 }
207 wakaba 1.6
208     {
209     Name:
210     wikiview/log-hotness
211     FullName:
212     Logging hotness of the page
213     Format:
214     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
215     $db->{$o->{page}||$p->{page}} += ($p->{weight} || 1);
216     }
217     {
218     Name:
219     wikiform_input/hotness-list
220     FullName:
221     Hotness-of-pages' list
222     Format:
223     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
224     my $i = 0;
225     $r = qq(<ol class="hotness">\n);
226     for (sort {$db->{$b}<=>$db->{$a}} grep {$db->{$_} > $p->{threshold}} keys %$db) {
227     do {$i++; next if $i > $p->{n}} if $p->{n};
228     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="{@{[$db->{$_}+0]}}">) . $o->escape ($_) . qq(</a></li>\n);
229     }
230     $r .= '</ol>';
231     }
232    
233     MODULE:
234     sub compose_wiki_page_uri ($$$) {
235     my ($o, $p, $q) = @_;
236     $q->{mode} ||= $p->{mode} || 'read';
237     $q->{page} ||= $p->{page} || $o->{page};
238     $q->{add_param} ||= $p->{add_param};
239     $q->{up_to_date} = $p->{up_to_date} unless defined $q->{up_to_date};
240     $q->{with_lm} = $p->{with_lm} unless defined $q->{with_lm};
241     $q->{href} = $o->uri('wiki').'?';
242     if ($q->{up_to_date} || $q->{mode} ne 'read' || $q->{add_param} || $q->{with_lm}) {
243     $q->{href} .= qq(mypage=@{[$o->encode($q->{page})]};mycmd=@{[$o->encode($q->{mode})]});
244     $q->{href} .= ';'.$q->{add_param} if $q->{add_param};
245     $q->{href} .= ';x-d='.time if $q->{up_to_date};
246     $q->{href} .= ';x-lm='.($main::database->mtime ($q->{page})||0) if $q->{with_lm};
247     } else {
248     $q->{href} .= $o->encode ($q->{page});
249     }
250 wakaba 1.7 $q->{href};
251 wakaba 1.6 }
252 wakaba 1.14
253     ## TODO: obsolete this function in the future
254     sub _get_subjectline {
255 wakaba 1.15 my (undef, $page, %option) = @_;
256 wakaba 1.14 my $SubjectLine = SuikaWiki::Plugin->cache ('headline');
257     unless (defined $SubjectLine->{$page}) {
258     if (not &main::is_editable($page)) {
259     $SubjectLine->{$page} = "";
260     } else {
261     $SubjectLine->{$page} = do {
262     my $s=$main::database{$page};
263     $s =~ tr/\x0D//d;
264     $s =~ s!^\#\?[^\x0A\x0D]+[\x0A\x0D]*!!s;
265     $s =~ s/\x0A\x0A.*//s;
266     if (length ($s) > 500) {
267     $s = substr ($s, 0, 500);
268     $s =~ s/[^\x09\x0A\x20-\x7E]+$//s;
269     $s .= '...';
270     }
271     #if ($s =~ /^([^\x0A]*(?:\x0A+[^\x0A]+){0,9})/s) {
272     # $s = $1;
273     #}
274     $s =~ s/[\x09\x0A\x20]+/\x20/gs;
275     $s =~ s/^[-=*>,:]+//;
276     $s =~ s/'''?//g;
277     $s =~ s/\[\[([^]]+)\]\]/$1/g;
278     $s =~ s/__&&([^&]+)&&__/$1/g;
279     $s =~ s/\[[A-Z]+(?:\([^)]+\))?\[([^]]+)\](?:\s\[([^]]+)\])?\]/$1$2/g;
280     $s =~ s/\([^\(\)]+\)//g;
281     $s =~ s/\[[^\[\]]+\]//g;
282     $s =~ s/>>[0-9]+//g;
283     $s =~ s/<[^<>]+>//g;
284     $s =~ s/20[0-9][0-9]-[01][0-9]-[0-3][0-9]\x20*[0-2][0-9]:[0-5][0-9]//g;
285     $s =~ s/ [Aa]n? / /g;
286     $s =~ s/ [Aa]t / @ /g;
287     $s =~ s/ [Tt]he / /g;
288     $s =~ s/,? and / & /g;
289     $s =~ s!,? or ! / !g;
290     $s =~ s! not !n't !g;
291     $s =~ s! (?:i|ha)s !'s !g;
292     $s =~ s! are !'re !g;
293     $s =~ s! [Ww]ith(in|out)? !' w/'.substr ($1,0,1).' '!ge;
294     $s =~ s!です。!。!g;
295     $s =~ s!ました。!た。!g;
296     $s =~ s!ありません!ない!g;
297     $s =~ s!します!する!g;
298     $s =~ s!(?:り)?ます!る!g;
299     $s =~ s!いよいよ|とうとう|ようやく!!g;
300     $s =~ s!とりあえず!!g;
301     $s =~ s!(?:、|。|[.,])\x20?$!!g;
302     $s =~ s/\x20+/\x20/g;
303     if (length ($s) > 400) {
304     $s = substr ($s, 0, 400);
305     $s =~ s/[^\x20-\x7E]+$//s;
306     $s .= '...';
307     }
308     $s};
309     }
310     }
311     if (length $SubjectLine->{$page}) {
312     $option{delimiter} = defined $option{delimiter} ? $option{delimiter} : SuikaWiki::Plugin->resource('Title-Summary Delimiter');
313     $option{delimiter}.$SubjectLine->{$page}.$option{tail};
314     } else {
315     '';
316     }
317     } # main::get_subjectline
318    
319 wakaba 1.11 SuikaWiki::View->template ('links')->add_line (<<EOH);
320     %link-wiki(page=>@{[$main::PageName{SearchPage}]},rel=>search,class=>wiki,title=>"%res(name=>GoToSearchPageLink);"p);
321     EOH
322 wakaba 1.9
323 w 1.1
324     POD:LICENSE:
325     Copyright 2003 Wakaba <w@suika.fam.cx>
326    
327     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24