/[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.11 - (hide annotations) (download)
Sat May 3 01:01:29 2003 UTC (21 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.10: +4 -1 lines
Update to new syntax

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 wakaba 1.10 my $HAS_XML = SuikaWiki::Plugin->feature ('SuikaWiki::Markup::XML');
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 if ($o->feature ('SuikaWiki::Markup::XML')) {
45     my $ul = SuikaWiki::Markup::XML->new (local_name => 'ul', namespace_uri => $NS_XHTML1);
46     for (@r) {
47     my $li = $ul->append_new_node (local_name => 'li', namespace_uri => $NS_XHTML1);
48     $li->append_text ('{' . $_->[1] . '} ');
49     my $a = $li->append_new_node (local_name => 'a', namespace_uri => $NS_XHTML1);
50     $a->set_attribute (href => $o->uri('wiki').'?'.$o->encode($_->[0]));
51     $a->set_attribute (class => 'wiki');
52     $a->append_text ($_->[0]);
53     $li->append_text (' ');
54     my $hl = $li->append_new_node (local_name => 'span', namespace_uri => $NS_XHTML1);
55     $hl->set_attribute (class => 'headline');
56     $hl->append_text (main::get_subjectline ($_->[0]));
57     $ul->append_text ("\n");
58 w 1.4 }
59 wakaba 1.9 $r = $ul;
60     } else {
61     $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;
62     $r = qq|<ul class="search-result">$r</ul>| if $r;
63 w 1.4 }
64     }
65    
66     {
67     Name:
68     wikiview/last-modified
69     FullName:
70     Last-modified date & time of the page
71     Format:
72     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
73     }
74     {
75     Name:
76     wikiview-resource/last-modified
77     FullName:
78     Last-modified date & time of the page
79     Format:
80     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
81     }
82     {
83     Name:
84     wikiform_input/last-modified
85     FullName:
86     Last-modified date & time of the page
87     Format:
88     $r = &main::_rfc3339_date ($main::database->mtime ($p->{page} || $o->{page}));
89     }
90     {
91     Name:
92 wakaba 1.7 wikiview-resource/page-name
93     wikiform_input/page-name
94 w 1.4 wikiview/page-name
95 wakaba 1.7 wikipage_list_item/page-name
96 w 1.4 FullName:
97     Page name
98     Format:
99 wakaba 1.10 if ($HAS_XML) {
100     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{page});
101     } else {
102     $r = $o->escape ($o->{page});
103     }
104 w 1.4 }
105 wakaba 1.7
106 w 1.4 {
107     Name:
108     wikiview/wiki-link
109 wakaba 1.7 wikiview-resource/wiki-link
110 w 1.4 FullName:
111     Link to the WikiPage
112     Format:
113     $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => 1);
114     }
115     {
116     Name:
117 wakaba 1.7 wikipage_list_item/wiki-link
118 w 1.4 FullName:
119     Link to the WikiPage
120     Format:
121 wakaba 1.7 $r = $o->_html_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, latest => $p->{up_to_date}, label => $p->{label});
122 w 1.4 }
123    
124     {
125     Name:
126     wikiview/link-wiki
127     FullName:
128     Link element to the wiki itself
129     Format:
130     unless ($p->{href}) {
131     $p->{mode} ||= 'read';
132 wakaba 1.7 $p->{page} ||= $o->{page};
133 w 1.4 $p->{href} = $o->uri('wiki').'?';
134     if ($p->{up_to_date} || $p->{mode} ne 'read' || $p->{add_param}) {
135     $p->{href} .= qq(mypage=@{[$o->encode($p->{page})]};mycmd=@{[$o->encode($p->{mode})]});
136     $p->{href} .= ';'.$p->{add_param} if $p->{add_param};
137     $p->{href} .= ';x-d='.time if $p->{up_to_date};
138     $p->{href} .= ';x-lm='.($main::database->mtime ($p->{page})||0) if $p->{with_lm};
139     } else {
140     $p->{href} .= $o->encode ($p->{page});
141     }
142     }
143     $r = qq(<link);
144 wakaba 1.11 for my $attr (qw/rel rev href title class type hreflang charset accesskey/) {
145 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
146     }
147     $r .= '/' if $o->{media}->{type} =~ /xml/;
148     $r .= '>';
149     }
150     {
151     Name:
152     wikiview/anchor-wiki
153     FullName:
154     A element to the wiki page
155     Format:
156 wakaba 1.7 $p->{href} ||= compose_wiki_page_uri ($o, $p, {});
157     $p->{label} = $p->{page} unless length $p->{label};
158     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
159     $p->{title} = $p->{page};
160     }
161     $r = qq(<a);
162     for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
163     $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
164 w 1.4 }
165 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
166     }
167     {
168     Name:
169     wikiview-resource/anchor-wiki
170     FullName:
171     A element to the wiki page
172     Format:
173     $p->{href} = compose_wiki_page_uri ($o, $p, {});
174     $p->{label} = $p->{page} unless length $p->{label};
175     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
176     $p->{title} = $p->{page} || $o->{page};
177 w 1.4 }
178     $r = qq(<a);
179 wakaba 1.7 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
180 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
181     }
182 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
183 w 1.4 }
184    
185     {
186     Name:
187     wikiview/referer-list
188     FullName:
189     Referer-list of page
190     Format:
191     $r = wiki::referer::list_html ($o->{page});
192     }
193    
194     {
195     Name:
196     wikiview/uri-wiki
197     FullName:
198     Output URI of the WikiPage (as anchor)
199     Format:
200     my $uri = $o->uri('wiki').'?'.$o->encode($p->{page}||$o->{page});
201     $r = qq(&lt;<a href="$uri">$uri</a>&gt;);
202 w 1.1 }
203 wakaba 1.6
204     {
205     Name:
206     wikiview/log-hotness
207     FullName:
208     Logging hotness of the page
209     Format:
210     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
211     $db->{$o->{page}||$p->{page}} += ($p->{weight} || 1);
212     }
213     {
214     Name:
215     wikiform_input/hotness-list
216     FullName:
217     Hotness-of-pages' list
218     Format:
219     my $db = $o->cache ('hotness', -expires=>7*24*3600, -removes=>7*24*3600);
220     my $i = 0;
221     $r = qq(<ol class="hotness">\n);
222     for (sort {$db->{$b}<=>$db->{$a}} grep {$db->{$_} > $p->{threshold}} keys %$db) {
223     do {$i++; next if $i > $p->{n}} if $p->{n};
224     $r .= qq(<li><a href="@{[$o->uri('wiki')]}?@{[$o->encode($_)]}" class="wiki" title="{@{[$db->{$_}+0]}}">) . $o->escape ($_) . qq(</a></li>\n);
225     }
226     $r .= '</ol>';
227     }
228    
229     MODULE:
230     sub compose_wiki_page_uri ($$$) {
231     my ($o, $p, $q) = @_;
232     $q->{mode} ||= $p->{mode} || 'read';
233     $q->{page} ||= $p->{page} || $o->{page};
234     $q->{add_param} ||= $p->{add_param};
235     $q->{up_to_date} = $p->{up_to_date} unless defined $q->{up_to_date};
236     $q->{with_lm} = $p->{with_lm} unless defined $q->{with_lm};
237     $q->{href} = $o->uri('wiki').'?';
238     if ($q->{up_to_date} || $q->{mode} ne 'read' || $q->{add_param} || $q->{with_lm}) {
239     $q->{href} .= qq(mypage=@{[$o->encode($q->{page})]};mycmd=@{[$o->encode($q->{mode})]});
240     $q->{href} .= ';'.$q->{add_param} if $q->{add_param};
241     $q->{href} .= ';x-d='.time if $q->{up_to_date};
242     $q->{href} .= ';x-lm='.($main::database->mtime ($q->{page})||0) if $q->{with_lm};
243     } else {
244     $q->{href} .= $o->encode ($q->{page});
245     }
246 wakaba 1.7 $q->{href};
247 wakaba 1.6 }
248 wakaba 1.11 SuikaWiki::View->template ('links')->add_line (<<EOH);
249     %link-wiki(page=>@{[$main::PageName{SearchPage}]},rel=>search,class=>wiki,title=>"%res(name=>GoToSearchPageLink);"p);
250     EOH
251 wakaba 1.9
252 w 1.1
253     POD:LICENSE:
254     Copyright 2003 Wakaba <w@suika.fam.cx>
255    
256     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24