/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/WikiLinking.wp2
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/WikiLinking.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Sun Feb 1 12:17:32 2004 UTC (21 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +25 -80 lines
(logging_template_error, logging_template_error): Removed

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiLinking
5     @Description:
6     @@@: Wiki hyperlinking support
7     @@lang:en
8     @License: %%GPL%%
9     @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.5 @Date.RCS: $Date: 2004/01/16 07:49:41 $
16 wakaba 1.2 @Use:
17     use Message::Util::Error;
18     our $NestLevel = 0;
19 wakaba 1.1
20     PluginConst:
21     @NS_XHTML1:
22     http://www.w3.org/1999/xhtml
23     @NS_XHTML2:
24     http://www.w3.org/2002/06/xhtml2
25     @NS_XLINK:
26     http://www.w3.org/1999/xlink
27     @NS_HLINK:
28     http://www.w3.org/2002/06/hlink
29    
30     FormattingRule:
31     @Category[list]:
32     view
33     view-resource
34     form-input
35     @Name: link-to-wikipage
36     @Description:
37     @@@:
38     Creating "from" anchor field of a link whose "to" is a WikiPage
39     @@lang: en
40     @Parameter:
41     @@Name: base-page
42     @@Type: WikiName
43     @@Default: (current)
44     @@Description:
45     @@@@:Base WikiName (Relative WikiName is resolved with)
46     @@@lang:en
47     @Parameter:
48     @@Name: hreflang
49     @@Type:
50     HTML4:LanguageCode
51     @@Default:(none)
52     @@Description:
53     @@@@:(Human) language the linked WikiPage written in
54     @@@lang:en
55     @Parameter:
56     @@Name: hreftype
57     @@Type:
58     HTML4:ContentType
59     @@Default:(none)
60     @@Description:
61     @@@@:Media type the linked WikiPage provided with
62     @@@lang:en
63     @Parameter:
64     @@Name:label
65     @@Type:CDATA
66     @@Default:(auto)
67     @@Description:
68     @@@@:Source anchor label
69     @@@lang:en
70     @Parameter:
71     @@Name: mode
72     @@Type: WikiMode
73     @@Default:(default)
74     @@Description:
75     @@@@:Mode of the Wiki linked to
76     @@@lang:en
77     @Parameter:
78     @@Name: page
79     @@Type: WikiName
80     @@Default: (current)
81     @@Description:
82     @@@@:WikiPage linked to
83     @@@lang:en
84     @Parameter:
85     @@Name: page-anchor-name
86     @@Type:
87     XML:ID
88     @@Default: (none)
89     @@Description:
90     @@@@:Identifier in the WikiPage linked to
91     @@@lang:en
92     @Parameter:
93     @@Name: page-anchor-no
94     @@Type:
95     SGML:NUMBER
96     @@Default: (none)
97     @@Description:
98     @@@@:Numeral anchor index in the WikiPage linked to
99     @@@lang:en
100     @Parameter:
101     @@Name: page-title
102     @@Type:CDATA
103     @@Default:(auto)
104     @@Description:
105     @@@@:Title of the WikiPage linked to
106     @@@lang:en
107     @Parameter:
108     @@Name: rel
109     @@Type:
110     HTML4:LinkTypes
111     @@Default:(none)
112     @@Description:
113     @@@@:Link relationships
114     @@@lang:en
115     @Parameter:
116     @@Name: rev
117     @@Type:
118     HTML4:LinkTypes
119     @@Default:(none)
120     @@Description:
121     @@@@:Link relationship (reverse)
122     @@@lang:en
123     @Parameter:
124     @@Name: up-to-date
125     @@Type: boolean
126     @@Default: "0"
127     @@Description:
128     @@@@:Appends random "up-to-date" parameter to the URI reference
129     @@@lang:en
130     @Parameter:
131     @@Name: with-lm
132     @@Type: boolean
133     @@Default:"0"
134     @@Description:
135     @@@@:Appends "last-modified" parameter to the URI reference
136     @@@lang:en
137     @Formatting:
138     __ATTRNODE:%page_title__;
139     __ATTRTEXT:%class__;
140 wakaba 1.2 __ATTRTEXT:%label__;
141 wakaba 1.1 __ATTRTEXT:%page__;__ATTRTEXT:%base_page__;__ATTRTEXT:%page_anchor_no__;
142     __ATTRTEXT:%with_lm__;__ATTRTEXT:%up_to_date__;
143     __ATTRTEXT:%page_anchor_name__;
144     __ATTRTEXT:%hreflang__;__ATTRTEXT:%hreftype__;
145     __ATTRTEXT:%mode__;
146     __ATTRTEXT:%rel__;__ATTRTEXT:%rev__;
147     __FUNCPACK__->to_wikipage_in_html ({
148     label => ($p->{label}),
149     } => {
150     base => [split m#//#, ($p->{base_page}||$o->{page})],
151 wakaba 1.3 page_name_relative => $p->{page} ? [split m#//#, $p->{page}]
152     : $o->{wiki}->{var}->{page},
153 wakaba 1.1 page_anchor_no => $p->{page_anchor_no},
154     page_anchor_name => $p->{page_anchor_name},
155     page_title => $p->{page_title},
156     wiki_mode => $p->{mode},
157     _with_lm => $p->{with_lm},
158     _up_to_date => $p->{up_to_date},
159     -hreflang => $p->{hreflang},
160     -hreftype => $p->{type},
161     }, {
162     o => $o,
163     parent => $p->{-parent},
164     -rel => $p->{rel},
165     -rev => $p->{rev},
166     });
167    
168     FormattingRule:
169 wakaba 1.3 @Category[list]:
170     view
171     view-resource
172     form-input
173     @Name: link-to-resource
174     @Description:
175     @@@:
176     Creating source anchor field of a link whose destination is a resource
177     @@lang: en
178     @Parameter
179     @@Name: hreflang
180     @@Type:
181     HTML4:LanguageCode
182     @@Default:(none)
183     @@Description:
184     @@@@:(Human) language the linked WikiPage written in (advisory)
185     @@@lang:en
186     @Parameter:
187     @@Name: hreftype
188     @@Type:
189     HTML4:ContentType
190     @@Default:(none)
191     @@Description:
192     @@@@:Media type the linked WikiPage provided with (advisory)
193     @@@lang:en
194     @Parameter:
195     @@Name:label
196     @@Type:CDATA
197     @@Default:(auto)
198     @@Description:
199     @@@@:Source anchor label
200     @@@lang:en
201     @Parameter:
202     @@Name: rel
203     @@Type:
204     HTML4:LinkTypes
205     @@Default:(none)
206     @@Description:
207     @@@@:Link relationships
208     @@@lang:en
209     @Parameter:
210     @@Name: rev
211     @@Type:
212     HTML4:LinkTypes
213     @@Default:(none)
214     @@Description:
215     @@@@:Link relationship (reverse)
216     @@@lang:en
217     @Parameter:
218     @@Name: uri
219     @@Type:
220     HTML4:URI
221     @@Default:(required)
222     @@Description:
223     @@@@:URI reference of the resoruce referred to
224     @@@lang:en
225     @Formatting:
226     __ATTRTEXT:%class__;
227     __ATTRTEXT:%label__;
228     __ATTRTEXT:%hreflang__;__ATTRTEXT:%hreftype__;
229     __ATTRTEXT:%rel__;__ATTRTEXT:%rev__;
230     __ATTRTEXT:%uri__;
231     __FUNCPACK__->to_resource_in_html ({
232     label => ($p->{label}),
233     } => {
234     #base_uri => ...
235     uri => $p->{uri},
236     -hreflang => $p->{hreflang},
237     -hreftype => $p->{type},
238     }, {
239     o => $o,
240     parent => $p->{-parent},
241     -rel => $p->{rel},
242     -rev => $p->{rev},
243     });
244    
245     FormattingRule:
246     @Category[list]:
247     page-link
248     link-to-resource
249 wakaba 1.1 @Name: link-to-it
250     @Description:
251     @@@:
252     Source anchor
253     @@lang: en
254     @Parameter:
255     @@Name: class
256     @@Type:
257     HTML4:class
258     @@Default: (none)
259     @@Description:
260     @@@@: Class names
261     @@@lang:en
262     @Parameter:
263     @@Name: description
264     @@Type: CDATA
265     @@Default: (none)
266     @@Description:
267     @@@@: Description of the anchor or link
268     @@@lang:en
269     @Parameter:
270     @@Name: label
271     @@Type: CDATA
272     @@Default: ""
273     @@Description:
274     @@@@: Source anchor label (content)
275     @@@lang:en
276     @Formatting:
277     __ATTRTEXT:%class__;
278     __ATTRTEXT:%description__;
279     my $A = $p->{-parent}->append_new_node (type => '#element',
280     namespace_uri => $NS_XHTML1,
281     local_name => 'a');
282     $A->set_attribute (href => $o->{link}->{dest}->{uri});
283    
284 wakaba 1.2 __ATTRNODE:%label->{$A}__;
285 wakaba 1.1 $A->set_attribute (title => $p->{description}) if $p->{description};
286     my @class = split /\s+/, $p->{class};
287 wakaba 1.3 if ($o->{wiki}->uri_is_part_of_wiki ($o->{link}->{dest}->{absolute_uri} or
288     $o->{link}->{dest}->{uri})) {
289 wakaba 1.1 push @class, 'wiki'; ## Link to the page within the Wiki
290     }
291     $A->set_attribute (class => join ' ', @class) if @class;
292    
293     $A->set_attribute (rel => $o->{link}->{option}->{-rel})
294     if $o->{link}->{option}->{-rel};
295     $A->set_attribute (rev => $o->{link}->{option}->{-rev})
296     if $o->{link}->{option}->{-rev};
297    
298     $A->set_attribute (hreflang => $o->{link}->{dest}->{-lang})
299     if $o->{link}->{dest}->{-lang};
300     $A->set_attribute (type => $o->{link}->{dest}->{-type})
301     if $o->{link}->{dest}->{-type};
302    
303     FormattingRule:
304 wakaba 1.3 @Category[list]:
305     page-link
306     link-to-resource
307     @Name: uri-reference
308     @Description:
309     @@@: URI Reference of destination anchor
310     @@lang:en
311     @Formatting:
312     $p->{-parent}->append_text ($o->{link}->{dest}->{absolute_uri} or
313     $o->{link}->{dest}->{uri});
314    
315     FormattingRule:
316     @Category[list]: link-to-resource
317     @Name: link-resource-scheme
318     @Description:
319     @@@: Linking scheme (defined as ReferenceScheme in SuikaWiki/0.9 syntax)
320     @@lang:en
321     @Formatting:
322     $p->{-parent}->append_text ($o->{link}->{dest}->{resource_scheme});
323    
324     FormattingRule:
325     @Category[list]: link-to-resource
326     @Name: link-resource-parameters
327     @Description:
328     @@@: Linking parameters (defined as ReferenceParameter in SuikaWiki/0.9 syntax)
329     @@lang:en
330     @Formatting:
331     $p->{-parent}->append_text ($o->{link}->{dest}->{resource_parameter});
332    
333     FormattingRule:
334 wakaba 1.1 @Category[list]: page-link
335     @Name: link-base-page-name
336     @Description:
337     @@@: Base WikiPage name
338     @@lang: en
339     @Formatting:
340     $p->{-parent}->append_text (join '//', @{$o->{link}->{dest}->{base}});
341    
342     FormattingRule:
343     @Category[list]: page-link
344     @Name: link-dest-anchor-no
345     @Description:
346     @@@: Anchor number in the WikiPage linked to, if specified
347     @@lang: en
348     @Formatting:
349     $p->{-parent}->append_text ($o->{link}->{dest}->{page_anchor_no});
350    
351     FormattingRule:
352 wakaba 1.3 @Category[list]: link-to-resource
353     @Name: if-link-resource-scheme
354     @Description:
355     @@@: If or if not resource pointing scheme matches to
356     @@lang:en
357     @Parameter:
358     @@Name: name
359     @@Type:
360     SW09:name
361     @@Default:(required)
362     @@Description:
363     @@@@: Scheme name
364     @@@lang:en
365     @Formatting:
366     __ATTRTEXT:%name__;
367     my $rule;
368     if ($o->{link}->{dest}->{resource_scheme} eq $p->{name}) {
369     $rule = __ATTRTEXT:%true__;
370     } else {
371     $rule = __ATTRTEXT:%false__;
372     }
373     SuikaWiki::Plugin->formatter ($f->{-category_name})
374     ->replace ($rule, param => $o, -parent => $p->{-parent});
375    
376     FormattingRule:
377     @Category[list]: link-to-resource
378     @Name: select-link-resource-scheme
379     @Description:
380     @@@: Selecting template by resource pointing scheme matches to
381     @@lang:en
382     @Parameter:
383     @@Name: SCHEMENAME
384     @@Type:
385     template
386     @@Default:(none)
387     @@Description:
388     @@@@: Template used when scheme name is SCHEMENAME
389     @@@lang:en
390     @Parameter:
391     @@Name: otherwise
392     @@Type:
393     template
394     @@Default:(none)
395     @@Description:
396     @@@@: Template used when no SCHEMENAME parameter matches
397     @@@lang:en
398     @Formatting:
399     my $rule;
400     if (defined $p->{$o->{link}->{dest}->{resource_scheme}}) {
401     $rule = __ATTRTEXT:%{$o->{link}->{dest}->{resource_scheme}}__;
402     } else {
403     $rule = __ATTRTEXT:%otherwise__;
404     }
405     SuikaWiki::Plugin->formatter ($f->{-category_name})
406     ->replace ($rule, param => $o, -parent => $p->{-parent});
407    
408     FormattingRule:
409 wakaba 1.1 @Category[list]: page-link
410     @Name: if-linked-wikipage-exist
411     @Description:
412     @@@: If or if not linked WikiPage exists, then
413     @@lang: en
414     @Formatting:
415 wakaba 1.2 my $page = $o->{link}->{dest}->{page_name};
416 wakaba 1.1 my $rule;
417 wakaba 1.5 my $exists;
418     try {
419     $exists = $o->{wiki}->{db}->exist (content => $page);
420     } catch SuikaWiki::DB::Util::Error with {
421     $exists = 0;
422     };
423     if ($exists) {
424 wakaba 1.1 $rule = __ATTRTEXT:%true__;
425     } else {
426     $rule = __ATTRTEXT:%false__;
427     }
428 wakaba 1.5 SuikaWiki::Plugin->formatter ('page_link')
429 wakaba 1.1 ->replace ($rule, param => $o, -parent => $p->{-parent});
430    
431     FormattingRule:
432     @Category[list]: page-link
433     @Name: if-link-has-dest-anchor-no
434     @Description:
435     @@@: If or if the link has destination numeral anchor
436     @@lang: en
437     @Formatting:
438     my $rule;
439     if ($o->{link}->{dest}->{page_anchor_no}) {
440     $rule = __ATTRTEXT:%true__;
441     } else {
442     $rule = __ATTRTEXT:%false__;
443     }
444     SuikaWiki::Plugin->formatter ('page-link')
445     ->replace ($rule, param => $o, -parent => $p->{-parent});
446    
447     FormattingRule:
448 wakaba 1.3 @Category[list]:
449     page-link
450     link-to-resource
451 wakaba 1.1 @Name:-bare-text
452     @Formatting:
453     $p->{-parent}->append_text ($p->{-bare_text});
454    
455     Function:
456 wakaba 1.3 @Name: to_resource_in_html
457     @Description:
458     @@@Make a link to the resource (outputted in HTML)
459     @@lang:en
460     @Main:
461     my (undef, $src => $dest, $opt) = @_;
462     if ($dest->{resource_scheme} eq 'URI' or
463     $dest->{resource_scheme} eq 'URL') {
464     $dest->{uri} = $dest->{resource_parameter};
465     ## TODO: Check syntax of URI reference
466     } elsif ($dest->{resource_scheme} eq 'IW') {
467 wakaba 1.5 $dest->{uri} = SuikaWiki::Plugin->module_package ('InterWikiCore')
468 wakaba 1.3 ->interwikireference_to_urireference
469 wakaba 1.5 (packed => $dest->{resource_parameter},
470     o => $opt->{o},
471     wiki => $opt->{o}->{wiki});
472 wakaba 1.3 } elsif ($dest->{resource_scheme} eq 'MAIL') {
473     $dest->{uri} = 'mailto:'.$dest->{resource_parameter};
474     } else {
475     ## TODO: Unknown scheme error
476     }
477     __FUNCPACK__->to_resource_by_uri_in_html ($src => $dest, $opt);
478    
479     Function:
480     @Name: to_resource_by_uri_in_html
481     @Description:
482     @@@:Make a link to the resource by URI reference (outputted in HTML)
483     @@lang:en
484     @Main:
485     my (undef, $src => $dest, $opt) = @_;
486     local $NestLevel = $NestLevel + 1;
487     if (100 < $NestLevel) {
488     $opt->{parent}->append_new_node (type => '#comment',
489     value => $src->{label});
490     SuikaWiki::Plugin->module_package ('Error')
491     ## TODO:
492     ->report_error_simple
493     ($opt->{o}->{wiki},
494     'Condition' => 'Link nesting too deep',
495     'Template' => $src->{label},
496     -trace => 1);
497     return;
498     }
499     local $opt->{o}->{link} = {
500     src => $src,
501     dest => $dest,
502     option => $opt,
503     };
504 wakaba 1.4 $src->{label} ||= SuikaWiki::Plugin->module_package ('WikiResource')
505     ->get_text (name => 'Link:toResource:SourceLabel',
506     param => $opt->{o},
507     wiki => $opt->{o}->{wiki});
508 wakaba 1.3 try {
509     SuikaWiki::Plugin->formatter ('link_to_resource')
510     ->replace ($src->{label}, param => $opt->{o}, -parent => $opt->{parent});
511     } catch Message::Util::Formatter::error with {
512     my $err = shift;
513 wakaba 1.5 if ($err->{-object}->{-category_name} eq 'link_to_resource') {
514     my $wiki = $err->{option}->{param}->{wiki};
515     SuikaWiki::Plugin->module_package ('Error')
516     ->reporting_formatting_template_error
517     ($err, $wiki,
518     template => $src->{label});
519 wakaba 1.3 undef;
520     } else {
521     $err->throw;
522     }
523     };
524    
525     Function:
526 wakaba 1.1 @Name: to_wikipage_in_html
527     @Description:
528 wakaba 1.3 @@@:Make a link to the WikiPage (outputed in HTML)
529 wakaba 1.1 @@lang:en
530     @Main:
531     my (undef, $src => $dest, $opt) = @_;
532 wakaba 1.2 local $NestLevel = $NestLevel + 1;
533     if (100 < $NestLevel) {
534     $opt->{parent}->append_new_node (type => '#comment',
535     value => $src->{label});
536     SuikaWiki::Plugin->module_package ('Error')
537     ->report_error_simple
538     ($opt->{o}->{wiki},
539     'Condition' => 'Link nesting too deep',
540     'Template' => $src->{label},
541     -trace => 1);
542     return;
543     }
544 wakaba 1.1 #$dest->{page_name} = SuikaWiki::Plugin::WikiNamespace->resolve_relative_name
545     # ($dest->{base} => $dest->{page_name_relative});
546     $dest->{page_name} = $dest->{page_name_relative};
547 wakaba 1.3 ($dest->{uri}, $dest->{absolute_uri})
548     = $opt->{o}->{wiki}->uri_reference
549     (page => $dest->{page_name},
550     mode => $dest->{wiki_mode},
551     anchor_no => $dest->{page_anchor_no},
552     up_to_date => $dest->{_up_to_date},
553     with_lm => $dest->{_with_lm},
554     fragment => $dest->{page_anchor_name},
555     base => $dest->{-use_absolute_uri} ? undef:
556     ($src->{base_uri} || 1));
557 wakaba 1.1
558     local $opt->{o}->{link} = {
559     src => $src,
560     dest => $dest,
561     option => $opt,
562     };
563 wakaba 1.4 $src->{label} ||= SuikaWiki::Plugin->module_package ('WikiResource')
564     ->get_text (name => 'Link:toWikiPage:SourceLabel',
565     param => $opt->{o},
566     wiki => $opt->{o}->{wiki});
567 wakaba 1.2 try {
568     SuikaWiki::Plugin->formatter ('page_link')
569     ->replace ($src->{label}, param => $opt->{o}, -parent => $opt->{parent});
570     } catch Message::Util::Formatter::error with {
571     my $err = shift;
572 wakaba 1.5 if ($err->{-object}->{-category_name} eq 'page_link') {
573     my $wiki = $err->{option}->{param}->{wiki};
574     SuikaWiki::Plugin->moduke_package ('Error')
575     ->reporting_formatting_template_error
576     ($err, $wiki,
577     template => $src->{label});
578 wakaba 1.2 undef;
579     } else {
580     $err->throw;
581     }
582     };
583 wakaba 1.1
584 wakaba 1.3 PluginCategory:
585     @Name: page-link
586     @Description:
587     @@@: Source anchor label of link whose destination is a WikiPage
588     @@lang:en
589    
590     PluginCategory:
591     @Name: link-to-resource
592     @Description:
593     @@@: Source anchor label of link whose destination is a resource
594     @@lang:en
595    
596 wakaba 1.2 Resource:
597 wakaba 1.3 @Link:toResource:SourceLabel:
598     @@@:
599     %select-link-resource-scheme (
600     URI => {<%link-to-it(
601     label => {%uri-reference;}p,
602     );>},
603     MAIL => {<%link-to-it(
604     label => {%link-resource-parameters;}p,
605     description
606     => {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p,
607     );>},
608     otherwise => {<%link-to-it(
609     label => {%link-resource-scheme;:%link-resource-parameters;}p,
610     description => {%res (name=>{Link:URIReference=});<%uri-reference;>}p,
611     );>},
612     );
613 wakaba 1.2 @Link:toWikiPage:SourceLabel:
614     @@@:
615     %link-to-it(
616     label=>{%page-title (relative);%if-linked-wikipage-exist(
617     true=>{%if-link-has-dest-anchor-no(true=>{>>%link-dest-anchor-no;});},
618     false=>{%res(name=>{Link:toWikiPage:NotExist:Mark});}
619     );}p,
620     description=>{%page-name(absolute);; %if-linked-wikipage-exist(
621     true=>{%page-headline;},
622     false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)},
623     );}p,
624     class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,
625     );
626 wakaba 1.3 @Link:MailAddress=:
627     @@@:
628     Internet Mail Address:
629     @@lang:en
630     @Link:URIReference=:
631     @@@:
632     URI Reference:
633     @@lang:en

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24