/[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.6 - (hide annotations) (download)
Thu Mar 11 10:13:07 2004 UTC (21 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +2 -7 lines
Referer list fragment moved

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.6 $Date: 2004/03/11 08:06:09 $
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     for my $page ($o->{wiki}->{db}->keys ('content')) {
189     my $content;
190     try {
191     $content = $o->{wiki}->{db}->get (content => $page);
192     } catch SuikaWiki::DB::Util::Error with {
193 wakaba 1.4 my $err = shift;
194     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
195 wakaba 1.1 $content = undef;
196     };
197 wakaba 1.5 $content = $p->{case_sensitive} ? $content : lc $content;
198 wakaba 1.1 $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;
199 wakaba 1.2 $page = $o->{wiki}->name ($page);
200     my $n_page = $page->stringify (wiki => $o->{wiki});
201     $n_page = lc $n_page unless $p->{case_sensible};
202 wakaba 1.1 if (index ($n_page, $word) > -1) {
203     my $c = $content =~ s/\Q$word\E//g;
204     push @r, [$page, $c+20];
205     } elsif (index ($word, $n_page) > -1) {
206     my $c = $content =~ s/\Q$word\E//g;
207     push @r, [$page, $c+10];
208     } elsif (my $c = $content =~ s/\Q$word\E//g) {
209     push @r, [$page, $c];
210     }
211     }
212     @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;
213 wakaba 1.2 $sr = join "\x1E",
214     map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D")
215     ."\x1F".$_->[1]} @r;
216 wakaba 1.1 $o->{wiki}->{db}->set (m__search_result => [$word] => $sr);
217 wakaba 1.5 ## TODO: Cache & case-sensitivility
218 wakaba 1.1 } else {
219 wakaba 1.2 @r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]}
220 wakaba 1.1 map {[split /\x1F/, $_, 2]} split /\x1E/, $sr;
221     }
222     return unless @r;
223     my $list = $p->{-parent}->append_new_node
224     (type => '#element',
225     namespace_uri => $NS_XHTML1,
226     local_name => 'ol');
227     __ATTRTEXT:%template__;
228     $p->{template} ||= $WIKIRESOURCE->get
229     (name => 'Link:toWikiPage:SourceLabelLong:SearchResult',
230     wiki => $o->{wiki}, o => $o);
231     for (@r) {
232     $WIKILINKING->to_wikipage_in_html ({
233     label => $p->{template},
234     } => {
235 wakaba 1.2 base => $o->{wiki}->{var}->{page},
236 wakaba 1.1 page_name_relative => $_->[0],
237     wiki_mode => $p->{mode},
238     }, {
239     o => $o,
240 wakaba 1.5 parent => $list->append_new_node
241     (type => '#element',
242     namespace_uri => $NS_XHTML1,
243     local_name => 'li'),
244 wakaba 1.1 -m__weight => $_->[1],
245     });
246     }
247    
248     FormattingRule:
249     @Category[list]:
250     page-link
251     @Name: m--link-weight
252     @Formatting:
253     $p->{-parent}->append_text ($o->{link}->{option}->{-m__weight}+0);
254    
255     ViewFragment:
256     @Name: ws--post-content
257     @Description:
258 wakaba 1.6 @@@: After content body -- children and backward links
259 wakaba 1.1 @@lang:en
260     @Order: 100
261     @Formatting:
262     %section (
263     id => children,
264     title => {%res(name=>{Children:Title});}p, heading,
265     content => {%page-list (
266     ns => {%page-name;}p, recursive => 0,
267     type => both,
268     template => {%resource-as-plain-text (name => {Children:Item});}p,
269     );}p,
270     );
271     %section (
272     id => see-also,
273     title => {%res(name=>SeeAlso);}p, heading,
274     content => {%search-result;}p,
275     );
276    
277     Resource:
278     @Children:Title:
279     %link-to-it(label=>{%ns-short-page-name;}p,
280     description=>{%page-name(absolute);}p,
281     );
282     %span(class=>headline, content=>{%page-headline;}p);
283     @Link:toWikiPage:SourceLabelLong:PageList:
284     %link-to-it(
285     label=>{%page-title(relative);}p,
286     description=>{%page-name(absolute);}p,
287     );
288     %span(class=>headline,content=>{%page-headline;}p);
289     @Link:toWikiPage:SourceLabelLong:RecentChangeItem:
290     %last-modified;
291     %link-to-it(
292     label=>{%page-title(relative);}p,
293     description=>{%page-name(absolute);}p,
294     );
295     %span(class=>headline,content=>{%page-headline;}p);
296     @Link:toWikiPage:SourceLabelLong:SearchResult:
297     {%m--link-weight;}
298     %link-to-it(
299     label=>{%page-title(relative);}p,
300     description=>{%page-name(absolute);}p,
301     );
302     %span(class=>headline,content=>{%page-headline;}p);
303    
304     ## TODO:
305     ViewFragment:
306     @Name: navbar
307     @Order: 21
308     @Formatting:
309     %link-to-wikipage (
310     page => {RecentChanges},
311     label => {%link-to-it (
312     label=>"%res(name=>GoToRecentChanges);"p,
313     description=>"%res(name=>GoToRecentChangesLong);"p,
314     );},
315     rel => news,
316     );
317    
318     ## TODO:
319     ViewFragment:
320     @Name: links
321     @Formatting:
322     %link-to-wikipage (
323     page => {RecentChanges},
324     rel => news,
325     label => {%html-link (
326     description => {%res(name=>GoToRecentChangesLink);}p,
327     );},
328     );

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24