/[pub]/suikawiki/script/misc/plugins/link/map.wp2
Suika

Contents of /suikawiki/script/misc/plugins/link/map.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Wed Feb 18 07:22:11 2004 UTC (21 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +9 -3 lines
WikiDB error reporting bug fixed

1 #?SuikaWikiConfig/2.0
2
3 Plugin:
4 @Name: Map
5 @Description:
6 @@@:
7 Visualization of page to page relatinships
8 @@lang:en
9 @License: %%Perl%%
10 @Author:
11 @@Name:
12 @@@@: Wakaba
13 @@@lang:ja
14 @@@script:Latn
15 @@Mail[list]: w@suika.fam.cx
16 @Date.RCS:
17 $Date: 2004/02/14 10:52:27 $
18 @RequiredPlugin[list]:
19 WikiLinking
20 @Use:
21 use Message::Util::Error;
22 my $WIKILINKING;
23 my $WIKIRESOURCE;
24
25 PluginConst:
26 @NS_XHTML1:
27 http://www.w3.org/1999/xhtml
28 @NS_RDF:
29 http://www.w3.org/1999/02/22-rdf-syntax-ns#
30 @NS_RSS:
31 http://purl.org/rss/1.0/
32 @NS_DC:
33 http://purl.org/dc/elements/1.1/
34 @NS_MAP:
35 http://members.jcom.home.ne.jp/jintrick/2003/02/site-concept.xml#
36 @WIKILINKING:
37 {($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))}
38 @WIKIRESOURCE:
39 {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))}
40
41 FormattingRule:
42 @Category[list]:
43 form-input
44 view
45 view-resource
46 @Name: recent-change-list
47 @Description:
48 @@@: Recently changed WikiPage list
49 @@lang: en
50 @Parameter:
51 @@Name: ns
52 @@Type: WikiName
53 @@Default: (auto)
54 @@Description:
55 @@@@:
56 WikiNamespace name to which listed WikiPages belong
57 @@@lang: en
58 @Formatting:
59 my $list = $p->{-parent}->append_new_node
60 (type => '#element',
61 namespace_uri => $NS_XHTML1,
62 local_name => 'ol');
63 $list->set_attribute (class => 'm--recent-changes');
64
65 __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;
66 __ATTRTEXT:%n__;
67 $p->{recursive} = 1 unless length $p->{recursive};
68 my $ns = $o->{wiki}->name ($p->{ns});
69 #$ns->append_component ('') unless $ns->[$#$ns] eq '';
70 my $i = 0;
71 $p->{n} ||= 10;
72 __ATTRTEXT:%template__;
73 $p->{template} ||= $WIKIRESOURCE->get
74 (name => 'Link:toWikiPage:SourceLabelLong:RecentChangeItem',
75 wiki => $o->{wiki}, o => $o);
76 __ATTRTEXT:%mode__;
77 for (sort {$b->[1] <=> $a->[1]}
78 map { try { [$_, $o->{wiki}->{db}->get (lastmodified => $_)] }
79 catch SuikaWiki::DB::Util::Error with {
80 my $err = shift;
81 $err->throw if $err->{-type} eq 'ERROR_REPORTED';
82 [$_, undef]} }
83 $o->{wiki}->{db}->keys ('content',
84 -ns => $ns,
85 -type => 'key',
86 -recursive => $p->{recursive})) {
87 next unless $_->[0];
88 last if $i++ == $p->{n};
89
90 my $li = $list->append_new_node
91 (type => '#element',
92 namespace_uri => $NS_XHTML1,
93 local_name => 'li');
94 $WIKILINKING->to_wikipage_in_html ({
95 label => $p->{template},
96 } => {
97 base => $o->{wiki}->{var}->{page},
98 page_name_relative => $o->{wiki}->name ($_->[0]),
99 wiki_mode => $p->{mode},
100 _with_lm => 1,
101 page_lastmodified => $_->[1],
102 }, {
103 o => $o,
104 parent => $li,
105 });
106 }
107
108 FormattingRule:
109 @Category[list]:
110 form-input
111 view
112 view-resource
113 @Name: page-list
114 @Description:
115 @@@: WikiPage list
116 @@lang: en
117 @Parameter:
118 @@Name: ns
119 @@Type: WikiName
120 @@Default: (auto)
121 @@Description:
122 @@@@:
123 WikiNamespace name to which listed WikiPages belong
124 @@@lang: en
125 @Formatting:
126 my $list = $p->{-parent}->append_new_node
127 (type => '#element',
128 namespace_uri => $NS_XHTML1,
129 local_name => 'ul');
130
131 __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;
132 __ATTRTEXT:%n__;
133 $p->{recursive} = 1 unless length $p->{recursive};
134 my $ns = $o->{wiki}->name ($p->{ns});
135 #$ns->append_component ('') unless $ns->[$#$ns] eq '';
136 my $i = 0;
137 $p->{n} ||= -1;
138 __ATTRTEXT:%template__;
139 $p->{template} ||= $WIKIRESOURCE->get
140 (name => 'Link:toWikiPage:SourceLabelLong:PageList',
141 wiki => $o->{wiki}, o => $o);
142 __ATTRTEXT:%match__; ## WARNING: This parameter might be dangerous!
143 my $reg = $p->{match} ? qr/$p->{match}/ : qr/./;
144 __ATTRTEXT:%mode__;
145 try {
146 for (sort {$a->[1] cmp $b->[1]}
147 grep {$_->[1] =~ /$reg/}
148 map {[$_, join '//', @{$_}]} # make sort key
149 $o->{wiki}->{db}->keys ('content',
150 -ns => $ns,
151 -type => 'key',
152 -recursive => $p->{recursive})) {
153 last if $i++ == $p->{n};
154
155 my $li = $list->append_new_node
156 (type => '#element',
157 namespace_uri => $NS_XHTML1,
158 local_name => 'li');
159 $WIKILINKING->to_wikipage_in_html ({
160 label => $p->{template},
161 } => {
162 base => $o->{wiki}->{var}->{page},
163 page_name_relative => $o->{wiki}->name ($_->[0]),
164 wiki_mode => $p->{mode},
165 }, {
166 o => $o,
167 parent => $li,
168 });
169 }
170 } catch SuikaWiki::DB::Util::Error with {
171 my $err = shift;
172 $err->throw if $err->{-type} eq 'ERROR_REPORTED';
173 };
174 $p->{-parent}->remove_child_node ($list) unless $list->count;
175
176 FormattingRule:
177 @Category[list]:
178 form-input
179 view
180 view-resource
181 @Name: search-result
182 @Formatting:
183 __ATTRTEXT:%key__;
184 $p->{key} ||= $o->{wiki}->{var}->{page}->stringify (wiki => $o->{wiki});
185 __ATTRTEXT:%case_sensible__;
186 my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};
187 my @r;
188 my $sr = $o->{wiki}->{db}->get (m__search_result => [$word]);
189 unless ($sr) {
190 for my $page ($o->{wiki}->{db}->keys ('content')) {
191 my $content;
192 try {
193 $content = $o->{wiki}->{db}->get (content => $page);
194 } catch SuikaWiki::DB::Util::Error with {
195 my $err = shift;
196 $err->throw if $err->{-type} eq 'ERROR_REPORTED';
197 $content = undef;
198 };
199 $content = $p->{case_sensible} ? $content : lc $content;
200 $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
201 $page = $o->{wiki}->name ($page);
202 my $n_page = $page->stringify (wiki => $o->{wiki});
203 $n_page = lc $n_page unless $p->{case_sensible};
204 if (index ($n_page, $word) > -1) {
205 my $c = $content =~ s/\Q$word\E//g;
206 push @r, [$page, $c+20];
207 } elsif (index ($word, $n_page) > -1) {
208 my $c = $content =~ s/\Q$word\E//g;
209 push @r, [$page, $c+10];
210 } elsif (my $c = $content =~ s/\Q$word\E//g) {
211 push @r, [$page, $c];
212 }
213 }
214 @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
215 $sr = join "\x1E",
216 map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D")
217 ."\x1F".$_->[1]} @r;
218 $o->{wiki}->{db}->set (m__search_result => [$word] => $sr);
219 ## TODO: Cache & case-sensibility
220 } else {
221 @r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]}
222 map {[split /\x1F/, $_, 2]} split /\x1E/, $sr;
223 }
224 return unless @r;
225 my $list = $p->{-parent}->append_new_node
226 (type => '#element',
227 namespace_uri => $NS_XHTML1,
228 local_name => 'ol');
229 __ATTRTEXT:%template__;
230 $p->{template} ||= $WIKIRESOURCE->get
231 (name => 'Link:toWikiPage:SourceLabelLong:SearchResult',
232 wiki => $o->{wiki}, o => $o);
233 for (@r) {
234 my $li = $list->append_new_node
235 (type => '#element',
236 namespace_uri => $NS_XHTML1,
237 local_name => 'li');
238 $WIKILINKING->to_wikipage_in_html ({
239 label => $p->{template},
240 } => {
241 base => $o->{wiki}->{var}->{page},
242 page_name_relative => $_->[0],
243 wiki_mode => $p->{mode},
244 }, {
245 o => $o,
246 parent => $li,
247 -m__weight => $_->[1],
248 });
249 }
250
251 FormattingRule:
252 @Category[list]:
253 page-link
254 @Name: m--link-weight
255 @Formatting:
256 $p->{-parent}->append_text ($o->{link}->{option}->{-m__weight}+0);
257
258 ViewFragment:
259 @Name: ws--post-content
260 @Description:
261 @@@: After content body -- navigation bar
262 @@lang:en
263 @Order: 100
264 @Formatting:
265 %section (
266 id => children,
267 title => {%res(name=>{Children:Title});}p, heading,
268 content => {%page-list (
269 ns => {%page-name;}p, recursive => 0,
270 type => both,
271 template => {%resource-as-plain-text (name => {Children:Item});}p,
272 );}p,
273 );
274 %section (
275 id => see-also,
276 title => {%res(name=>SeeAlso);}p, heading,
277 content => {%search-result;}p,
278 );
279 %section (
280 id => referer,
281 title => {%res(name=>Referer);}p, heading,
282 content => {%referer-list;}p,
283 );
284
285 Resource:
286 @Children:Title:
287 %link-to-it(label=>{%ns-short-page-name;}p,
288 description=>{%page-name(absolute);}p,
289 );
290 %span(class=>headline, content=>{%page-headline;}p);
291 @Link:toWikiPage:SourceLabelLong:PageList:
292 %link-to-it(
293 label=>{%page-title(relative);}p,
294 description=>{%page-name(absolute);}p,
295 );
296 %span(class=>headline,content=>{%page-headline;}p);
297 @Link:toWikiPage:SourceLabelLong:RecentChangeItem:
298 %last-modified;
299 %link-to-it(
300 label=>{%page-title(relative);}p,
301 description=>{%page-name(absolute);}p,
302 );
303 %span(class=>headline,content=>{%page-headline;}p);
304 @Link:toWikiPage:SourceLabelLong:SearchResult:
305 {%m--link-weight;}
306 %link-to-it(
307 label=>{%page-title(relative);}p,
308 description=>{%page-name(absolute);}p,
309 );
310 %span(class=>headline,content=>{%page-headline;}p);
311
312 ## TODO:
313 ViewFragment:
314 @Name: navbar
315 @Order: 21
316 @Formatting:
317 %link-to-wikipage (
318 page => {RecentChanges},
319 label => {%link-to-it (
320 label=>"%res(name=>GoToRecentChanges);"p,
321 description=>"%res(name=>GoToRecentChangesLong);"p,
322 );},
323 rel => news,
324 );
325
326 ## TODO:
327 ViewFragment:
328 @Name: links
329 @Formatting:
330 %link-to-wikipage (
331 page => {RecentChanges},
332 rel => news,
333 label => {%html-link (
334 description => {%res(name=>GoToRecentChangesLink);}p,
335 );},
336 );

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24