/[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.13 - (hide annotations) (download)
Sun May 25 10:54:55 2003 UTC (21 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.12: +24 -2 lines
WikiLinking : 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 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 wakaba 1.13 wikipage-link/page-name
109     FullName:
110     Name of the WikiPage
111     Format:
112     if ($p->{relative}) {
113     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name_relative});
114     } else {
115     $r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_name});
116     }
117     }
118    
119     {
120     Name:
121     wikipage-link/page-headline
122     FullName:
123     Headline of the WikiPage
124     Format:
125     $r = SuikaWiki::Markup::XML->new (type => '#text', value => &main::get_subjectline ($o->{link}->{dest}->{page_name}, delimiter => ''));
126     }
127    
128     {
129     Name:
130 w 1.4 wikiview/wiki-link
131 wakaba 1.7 wikiview-resource/wiki-link
132 w 1.4 FullName:
133     Link to the WikiPage
134     Format:
135 wakaba 1.13 $r = &main::make_wikilink ($o->escape ($p->{page}||$o->{page}), anchor => $p->{anchor}, up_to_date => 1);
136 w 1.4 }
137     {
138     Name:
139 wakaba 1.7 wikipage_list_item/wiki-link
140 w 1.4 FullName:
141     Link to the WikiPage
142     Format:
143 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});
144 w 1.4 }
145    
146     {
147     Name:
148     wikiview/link-wiki
149     FullName:
150     Link element to the wiki itself
151     Format:
152     unless ($p->{href}) {
153     $p->{mode} ||= 'read';
154 wakaba 1.7 $p->{page} ||= $o->{page};
155 w 1.4 $p->{href} = $o->uri('wiki').'?';
156     if ($p->{up_to_date} || $p->{mode} ne 'read' || $p->{add_param}) {
157     $p->{href} .= qq(mypage=@{[$o->encode($p->{page})]};mycmd=@{[$o->encode($p->{mode})]});
158     $p->{href} .= ';'.$p->{add_param} if $p->{add_param};
159     $p->{href} .= ';x-d='.time if $p->{up_to_date};
160     $p->{href} .= ';x-lm='.($main::database->mtime ($p->{page})||0) if $p->{with_lm};
161     } else {
162     $p->{href} .= $o->encode ($p->{page});
163     }
164     }
165     $r = qq(<link);
166 wakaba 1.11 for my $attr (qw/rel rev href title class type hreflang charset accesskey/) {
167 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
168     }
169     $r .= '/' if $o->{media}->{type} =~ /xml/;
170     $r .= '>';
171     }
172     {
173     Name:
174     wikiview/anchor-wiki
175     FullName:
176     A element to the wiki page
177     Format:
178 wakaba 1.7 $p->{href} ||= compose_wiki_page_uri ($o, $p, {});
179     $p->{label} = $p->{page} unless length $p->{label};
180     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
181     $p->{title} = $p->{page};
182     }
183     $r = qq(<a);
184     for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
185     $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
186 w 1.4 }
187 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
188     }
189     {
190     Name:
191     wikiview-resource/anchor-wiki
192     FullName:
193     A element to the wiki page
194     Format:
195     $p->{href} = compose_wiki_page_uri ($o, $p, {});
196     $p->{label} = $p->{page} unless length $p->{label};
197     if ($p->{page} ne $p->{label} && !defined $p->{title}) {
198     $p->{title} = $p->{page} || $o->{page};
199 w 1.4 }
200     $r = qq(<a);
201 wakaba 1.7 for my $attr (qw/rel rev href class title type hreflang charset target accesskey/) {
202 w 1.4 $r .= qq( $attr="@{[$o->escape($p->{$attr})]}") if $p->{$attr};
203     }
204 wakaba 1.7 $r .= '>' . $o->escape ($p->{label}) . '</a>';
205 w 1.4 }
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.11 SuikaWiki::View->template ('links')->add_line (<<EOH);
262     %link-wiki(page=>@{[$main::PageName{SearchPage}]},rel=>search,class=>wiki,title=>"%res(name=>GoToSearchPageLink);"p);
263     EOH
264 wakaba 1.9
265 w 1.1
266     POD:LICENSE:
267     Copyright 2003 Wakaba <w@suika.fam.cx>
268    
269     %%GNUGPL2%%

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24