/[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.8 - (hide annotations) (download)
Sat Mar 13 11:39:31 2004 UTC (21 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +3 -1 lines
Make upper bound

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: Map
5     @Description:
6     @@@:
7     Visualization of page to page relatinships
8     @@lang:en
9 wakaba 1.3 @License: %%Perl%%
10 wakaba 1.1 @Author:
11     @@Name:
12     @@@@: Wakaba
13     @@@lang:ja
14     @@@script:Latn
15     @@Mail[list]: w@suika.fam.cx
16 wakaba 1.2 @Date.RCS:
17 wakaba 1.8 $Date: 2004/03/13 06:05:51 $
18 wakaba 1.1 @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 wakaba 1.2 my $ns = $o->{wiki}->name ($p->{ns});
69     #$ns->append_component ('') unless $ns->[$#$ns] eq '';
70 wakaba 1.1 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 wakaba 1.4 catch SuikaWiki::DB::Util::Error with {
80     my $err = shift;
81     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
82     [$_, undef]} }
83 wakaba 1.1 $o->{wiki}->{db}->keys ('content',
84 wakaba 1.2 -ns => $ns,
85 wakaba 1.1 -type => 'key',
86     -recursive => $p->{recursive})) {
87     next unless $_->[0];
88     last if $i++ == $p->{n};
89    
90     $WIKILINKING->to_wikipage_in_html ({
91     label => $p->{template},
92     } => {
93 wakaba 1.2 base => $o->{wiki}->{var}->{page},
94     page_name_relative => $o->{wiki}->name ($_->[0]),
95 wakaba 1.1 wiki_mode => $p->{mode},
96     _with_lm => 1,
97     page_lastmodified => $_->[1],
98     }, {
99     o => $o,
100 wakaba 1.5 parent => $list->append_new_node
101     (type => '#element',
102     namespace_uri => $NS_XHTML1,
103     local_name => 'li'),
104 wakaba 1.1 });
105     }
106    
107     FormattingRule:
108     @Category[list]:
109     form-input
110     view
111     view-resource
112     @Name: page-list
113     @Description:
114     @@@: WikiPage list
115     @@lang: en
116     @Parameter:
117     @@Name: ns
118     @@Type: WikiName
119     @@Default: (auto)
120     @@Description:
121     @@@@:
122     WikiNamespace name to which listed WikiPages belong
123     @@@lang: en
124     @Formatting:
125     my $list = $p->{-parent}->append_new_node
126     (type => '#element',
127     namespace_uri => $NS_XHTML1,
128     local_name => 'ul');
129    
130     __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;
131     __ATTRTEXT:%n__;
132     $p->{recursive} = 1 unless length $p->{recursive};
133 wakaba 1.2 my $ns = $o->{wiki}->name ($p->{ns});
134     #$ns->append_component ('') unless $ns->[$#$ns] eq '';
135 wakaba 1.1 my $i = 0;
136     $p->{n} ||= -1;
137     __ATTRTEXT:%template__;
138     $p->{template} ||= $WIKIRESOURCE->get
139     (name => 'Link:toWikiPage:SourceLabelLong:PageList',
140     wiki => $o->{wiki}, o => $o);
141 wakaba 1.3 __ATTRTEXT:%match__; ## WARNING: This parameter might be dangerous!
142     my $reg = $p->{match} ? qr/$p->{match}/ : qr/./;
143 wakaba 1.1 __ATTRTEXT:%mode__;
144     try {
145     for (sort {$a->[1] cmp $b->[1]}
146 wakaba 1.3 grep {$_->[1] =~ /$reg/}
147 wakaba 1.2 map {[$_, join '//', @{$_}]} # make sort key
148 wakaba 1.1 $o->{wiki}->{db}->keys ('content',
149 wakaba 1.2 -ns => $ns,
150 wakaba 1.1 -type => 'key',
151     -recursive => $p->{recursive})) {
152     last if $i++ == $p->{n};
153    
154     $WIKILINKING->to_wikipage_in_html ({
155     label => $p->{template},
156     } => {
157 wakaba 1.2 base => $o->{wiki}->{var}->{page},
158     page_name_relative => $o->{wiki}->name ($_->[0]),
159 wakaba 1.1 wiki_mode => $p->{mode},
160     }, {
161     o => $o,
162 wakaba 1.5 parent => $list->append_new_node
163     (type => '#element',
164     namespace_uri => $NS_XHTML1,
165     local_name => 'li'),
166 wakaba 1.1 });
167     }
168     } catch SuikaWiki::DB::Util::Error with {
169 wakaba 1.4 my $err = shift;
170     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
171 wakaba 1.1 };
172     $p->{-parent}->remove_child_node ($list) unless $list->count;
173    
174     FormattingRule:
175     @Category[list]:
176     form-input
177     view
178     view-resource
179     @Name: search-result
180     @Formatting:
181     __ATTRTEXT:%key__;
182 wakaba 1.2 $p->{key} ||= $o->{wiki}->{var}->{page}->stringify (wiki => $o->{wiki});
183 wakaba 1.1 __ATTRTEXT:%case_sensible__;
184     my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};
185     my @r;
186     my $sr = $o->{wiki}->{db}->get (m__search_result => [$word]);
187     unless ($sr) {
188 wakaba 1.8 my $i = 0;
189 wakaba 1.1 for my $page ($o->{wiki}->{db}->keys ('content')) {
190 wakaba 1.8 last if ++$i == 512;
191 wakaba 1.1 my $content;
192     try {
193     $content = $o->{wiki}->{db}->get (content => $page);
194     } catch SuikaWiki::DB::Util::Error with {
195 wakaba 1.4 my $err = shift;
196     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
197 wakaba 1.1 $content = undef;
198     };
199 wakaba 1.5 $content = $p->{case_sensitive} ? $content : lc $content;
200 wakaba 1.1 $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
201 wakaba 1.2 $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 wakaba 1.1 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 wakaba 1.2 $sr = join "\x1E",
216     map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D")
217     ."\x1F".$_->[1]} @r;
218 wakaba 1.1 $o->{wiki}->{db}->set (m__search_result => [$word] => $sr);
219 wakaba 1.5 ## TODO: Cache & case-sensitivility
220 wakaba 1.1 } else {
221 wakaba 1.2 @r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]}
222 wakaba 1.1 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     $WIKILINKING->to_wikipage_in_html ({
235     label => $p->{template},
236     } => {
237 wakaba 1.2 base => $o->{wiki}->{var}->{page},
238 wakaba 1.1 page_name_relative => $_->[0],
239     wiki_mode => $p->{mode},
240     }, {
241     o => $o,
242 wakaba 1.5 parent => $list->append_new_node
243     (type => '#element',
244     namespace_uri => $NS_XHTML1,
245     local_name => 'li'),
246 wakaba 1.1 -m__weight => $_->[1],
247     });
248     }
249    
250     FormattingRule:
251     @Category[list]:
252     page-link
253     @Name: m--link-weight
254     @Formatting:
255     $p->{-parent}->append_text ($o->{link}->{option}->{-m__weight}+0);
256    
257     ViewFragment:
258     @Name: ws--post-content
259     @Description:
260 wakaba 1.6 @@@: After content body -- children and backward links
261 wakaba 1.1 @@lang:en
262     @Order: 100
263     @Formatting:
264     %section (
265     id => children,
266     title => {%res(name=>{Children:Title});}p, heading,
267     content => {%page-list (
268     ns => {%page-name;}p, recursive => 0,
269     type => both,
270     template => {%resource-as-plain-text (name => {Children:Item});}p,
271     );}p,
272     );
273     %section (
274     id => see-also,
275     title => {%res(name=>SeeAlso);}p, heading,
276     content => {%search-result;}p,
277     );
278    
279     Resource:
280     @Children:Title:
281     %link-to-it(label=>{%ns-short-page-name;}p,
282     description=>{%page-name(absolute);}p,
283     );
284     %span(class=>headline, content=>{%page-headline;}p);
285     @Link:toWikiPage:SourceLabelLong:PageList:
286     %link-to-it(
287     label=>{%page-title(relative);}p,
288     description=>{%page-name(absolute);}p,
289     );
290     %span(class=>headline,content=>{%page-headline;}p);
291     @Link:toWikiPage:SourceLabelLong:RecentChangeItem:
292     %last-modified;
293     %link-to-it(
294     label=>{%page-title(relative);}p,
295     description=>{%page-name(absolute);}p,
296     );
297     %span(class=>headline,content=>{%page-headline;}p);
298     @Link:toWikiPage:SourceLabelLong:SearchResult:
299     {%m--link-weight;}
300     %link-to-it(
301     label=>{%page-title(relative);}p,
302     description=>{%page-name(absolute);}p,
303     );
304     %span(class=>headline,content=>{%page-headline;}p);
305    
306 wakaba 1.7 ## TODO: Make recent-changes page name customizable
307 wakaba 1.1 ViewFragment:
308     @Name: navbar
309     @Order: 21
310     @Formatting:
311     %link-to-wikipage (
312     page => {RecentChanges},
313     label => {%link-to-it (
314 wakaba 1.7 label => {%res (name => GoToRecentChanges);}p,
315     description => {%res (name => GoToRecentChangesLong);}p,
316 wakaba 1.1 );},
317     rel => news,
318     );
319    
320     ## TODO:
321     ViewFragment:
322     @Name: links
323     @Formatting:
324     %link-to-wikipage (
325     page => {RecentChanges},
326     rel => news,
327     label => {%html-link (
328     description => {%res(name=>GoToRecentChangesLink);}p,
329     );},
330 wakaba 1.7 );
331    
332     Resource:
333     @GoToRecentChanges:
334     @@@: Recent
335     @@lang: en
336     @GoToRecentChangesLink:
337     @@@: Recently modified WikiPages list
338     @@lang: en
339     @GoToRecentChangesLong:
340     @@@: Review recently modified WikiPages list
341     @@lang: en
342    
343    
344    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24