/[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.9 - (hide annotations) (download)
Sun Apr 27 03:18:51 2003 UTC (22 years ago) by wakaba
Branch: MAIN
Changes since 1.8: +22 -238 lines
Map.wps: New.

1 w 1.1 Name:
2     WikiPage
3     FullName:
4     Getting WikiPage information
5     URI:
6     IW:SuikaWiki:WikiAdmin
7    
8 wakaba 1.9 Initialize:
9     my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
10 w 1.4
11     {
12     Name:
13     wikiview/search-result
14     wikiform_input/search-result
15     FullName:
16     Search result with the given string
17     Format:
18 wakaba 1.9 $p->{key} ||= $o->{page};
19 w 1.4 my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};
20     my @r;
21     my $sr = $o->cache ('search');
22     unless (defined $sr->{$word}) {
23     for my $page (keys %main::database) {
24     my ($magic, $content) = $o->magic_and_content ($main::database{$page});
25     $content = $p->{case_sensible} ? $content : lc $content;
26     $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
27     if (index (lc $page, $word) > -1) {
28     my $c = $content =~ s/\Q$word\E//g;
29     push @r, [$page, $c+20];
30     } elsif (index ($word, lc $page) > -1) {
31     my $c = $content =~ s/\Q$word\E//g;
32     push @r, [$page, $c+10];
33     } elsif (my $c = $content =~ s/\Q$word\E//g) {
34     push @r, [$page, $c];
35     }
36     }
37     @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
38     $sr->{$word} = join "\x1E", map {$_->[0]."\x1F".$_->[1]} @r;
39     } else {
40     @r = map {[split /\x1F/, $_, 2]} split /\x1E/, $sr->{$word};
41     }
42     my $em = $p->{em} ? sub { my $s = shift; $s =~ s#(\Q$word\E)#<em>$1</em>#gi; $s } : sub {$_[0]};
43 wakaba 1.9 if ($o->feature ('SuikaWiki::Markup::XML')) {
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 (main::get_subjectline ($_->[0]));
56     $ul->append_text ("\n");
57 w 1.4 }
58 wakaba 1.9 $r = $ul;
59     } else {
60     $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;
61     $r = qq|<ul class="search-result">$r</ul>| if $r;
62 w 1.4 }
63     }
64    
65     {
66     Name:
67     wikiview/last-modified
68     FullName:
69     Last-modified date & time of the page
70     Format:
71     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
72     }
73     {
74     Name:
75     wikiview-resource/last-modified
76     FullName:
77     Last-modified date & time of the page
78     Format:
79     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
80     }
81     {
82     Name:
83     wikiform_input/last-modified
84     FullName:
85     Last-modified date & time of the page
86     Format:
87     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
88     }
89     {
90     Name:
91 wakaba 1.7 wikiview-resource/page-name
92     wikiform_input/page-name
93     FullName:
94     Page name
95     Format:
96     $r = $o->escape ($o->{page});
97     }
98     {
99     Name:
100 w 1.4 wikiview/page-name
101 wakaba 1.7 wikipage_list_item/page-name
102     wikiview-resource-safe/page-name
103 w 1.4 FullName:
104     Page name
105     Format:
106 wakaba 1.7 $r = $o->{page};
107     $r = $o->escape ($r) unless $p->{safe};
108 w 1.4 }
109     {
110     Name:
111 wakaba 1.7 wikipage_list_item_safe/page-name
112     wikiform_input_safe/page-name
113 w 1.4 FullName:
114     Page name
115     Format:
116 wakaba 1.7 $r = $o->{page};
117 w 1.4 }
118 wakaba 1.7
119 w 1.4 {
120     Name:
121     wikiview/wiki-link
122 wakaba 1.7 wikiview-resource/wiki-link
123 w 1.4 FullName:
124     Link to the WikiPage
125     Format:
126     $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => 1);
127     }
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.7 $r = $o->_html_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => $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.7 for my $attr (qw/rel rev href title class type hreflang charset/) {
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/referer-list
201     FullName:
202     Referer-list of page
203     Format:
204     $r = wiki::referer::list_html ($o->{page});
205     }
206    
207     {
208     Name:
209     wikiview/uri-wiki
210     FullName:
211     Output URI of the WikiPage (as anchor)
212     Format:
213     my $uri = $o->uri('wiki').'?'.$o->encode($p->{page}||$o->{page});
214     $r = qq(&lt;<a href="$uri">$uri</a>&gt;);
215 w 1.1 }
216 wakaba 1.6
217     {
218     Name:
219     wikiview/log-hotness
220     FullName:
221     Logging hotness of the page
222     Format:
223     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
224     $db->{$o->{page}||$p->{page}} += ($p->{weight} || 1);
225     }
226     {
227     Name:
228     wikiform_input/hotness-list
229     FullName:
230     Hotness-of-pages' list
231     Format:
232     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
233     my $i = 0;
234     $r = qq(<ol class="hotness">\n);
235     for (sort {$db->{$b}<=>$db->{$a}} grep {$db->{$_} > $p->{threshold}} keys %$db) {
236     do {$i++; next if $i > $p->{n}} if $p->{n};
237     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="{@{[$db->{$_}+0]}}">) . $o->escape ($_) . qq(</a></li>\n);
238     }
239     $r .= '</ol>';
240     }
241    
242     MODULE:
243     sub compose_wiki_page_uri ($$$) {
244     my ($o, $p, $q) = @_;
245     $q->{mode} ||= $p->{mode} || 'read';
246     $q->{page} ||= $p->{page} || $o->{page};
247     $q->{add_param} ||= $p->{add_param};
248     $q->{up_to_date} = $p->{up_to_date} unless defined $q->{up_to_date};
249     $q->{with_lm} = $p->{with_lm} unless defined $q->{with_lm};
250     $q->{href} = $o->uri('wiki').'?';
251     if ($q->{up_to_date} || $q->{mode} ne 'read' || $q->{add_param} || $q->{with_lm}) {
252     $q->{href} .= qq(mypage=@{[$o->encode($q->{page})]};mycmd=@{[$o->encode($q->{mode})]});
253     $q->{href} .= ';'.$q->{add_param} if $q->{add_param};
254     $q->{href} .= ';x-d='.time if $q->{up_to_date};
255     $q->{href} .= ';x-lm='.($main::database->mtime ($q->{page})||0) if $q->{with_lm};
256     } else {
257     $q->{href} .= $o->encode ($q->{page});
258     }
259 wakaba 1.7 $q->{href};
260 wakaba 1.6 }
261 wakaba 1.9
262 w 1.1
263     POD:LICENSE:
264     Copyright 2003 Wakaba <w@suika.fam.cx>
265    
266     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24