/[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.2 - (hide annotations) (download)
Mon Dec 1 07:31:52 2003 UTC (22 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +90 -10 lines
Try & catch formatter text error

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.2 @Date.RCS: $Date: 2003/11/25 12:39:40 $
16     @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     page_name_relative => [split m#//#, $p->{page}],
152     page_anchor_no => $p->{page_anchor_no},
153     page_anchor_name => $p->{page_anchor_name},
154     page_title => $p->{page_title},
155     wiki_mode => $p->{mode},
156     _with_lm => $p->{with_lm},
157     _up_to_date => $p->{up_to_date},
158     -hreflang => $p->{hreflang},
159     -hreftype => $p->{type},
160     }, {
161     o => $o,
162     parent => $p->{-parent},
163     -rel => $p->{rel},
164     -rev => $p->{rev},
165     });
166    
167     FormattingRule:
168     @Category[list]: page-link
169     @Name: link-to-it
170     @Description:
171     @@@:
172     Source anchor
173     @@lang: en
174     @Parameter:
175     @@Name: class
176     @@Type:
177     HTML4:class
178     @@Default: (none)
179     @@Description:
180     @@@@: Class names
181     @@@lang:en
182     @Parameter:
183     @@Name: description
184     @@Type: CDATA
185     @@Default: (none)
186     @@Description:
187     @@@@: Description of the anchor or link
188     @@@lang:en
189     @Parameter:
190     @@Name: label
191     @@Type: CDATA
192     @@Default: ""
193     @@Description:
194     @@@@: Source anchor label (content)
195     @@@lang:en
196     @Formatting:
197     __ATTRTEXT:%class__;
198     __ATTRTEXT:%description__;
199     my $A = $p->{-parent}->append_new_node (type => '#element',
200     namespace_uri => $NS_XHTML1,
201     local_name => 'a');
202     $A->set_attribute (href => $o->{link}->{dest}->{uri});
203    
204 wakaba 1.2 __ATTRNODE:%label->{$A}__;
205 wakaba 1.1 $A->set_attribute (title => $p->{description}) if $p->{description};
206     my @class = split /\s+/, $p->{class};
207     if (substr ($o->{link}->{dest}->{uri}, 0, length ($o->uri ('wiki')))
208     eq $o->uri ('wiki')) {
209     push @class, 'wiki'; ## Link to the page within the Wiki
210     }
211     $A->set_attribute (class => join ' ', @class) if @class;
212    
213     $A->set_attribute (rel => $o->{link}->{option}->{-rel})
214     if $o->{link}->{option}->{-rel};
215     $A->set_attribute (rev => $o->{link}->{option}->{-rev})
216     if $o->{link}->{option}->{-rev};
217    
218     $A->set_attribute (hreflang => $o->{link}->{dest}->{-lang})
219     if $o->{link}->{dest}->{-lang};
220     $A->set_attribute (type => $o->{link}->{dest}->{-type})
221     if $o->{link}->{dest}->{-type};
222    
223     FormattingRule:
224     @Category[list]: page-link
225     @Name: link-base-page-name
226     @Description:
227     @@@: Base WikiPage name
228     @@lang: en
229     @Formatting:
230     $p->{-parent}->append_text (join '//', @{$o->{link}->{dest}->{base}});
231    
232     FormattingRule:
233     @Category[list]: page-link
234     @Name: link-dest-anchor-no
235     @Description:
236     @@@: Anchor number in the WikiPage linked to, if specified
237     @@lang: en
238     @Formatting:
239     $p->{-parent}->append_text ($o->{link}->{dest}->{page_anchor_no});
240    
241     FormattingRule:
242     @Category[list]: page-link
243     @Name: if-linked-wikipage-exist
244     @Description:
245     @@@: If or if not linked WikiPage exists, then
246     @@lang: en
247     @Formatting:
248 wakaba 1.2 my $page = $o->{link}->{dest}->{page_name};
249 wakaba 1.1 my $rule;
250     if ($o->{wiki}->{db}->exist (content => $page)) {
251     $rule = __ATTRTEXT:%true__;
252     } else {
253     $rule = __ATTRTEXT:%false__;
254     }
255     SuikaWiki::Plugin->formatter ('page-link')
256     ->replace ($rule, param => $o, -parent => $p->{-parent});
257    
258     FormattingRule:
259     @Category[list]: page-link
260     @Name: if-link-has-dest-anchor-no
261     @Description:
262     @@@: If or if the link has destination numeral anchor
263     @@lang: en
264     @Formatting:
265     my $rule;
266     if ($o->{link}->{dest}->{page_anchor_no}) {
267     $rule = __ATTRTEXT:%true__;
268     } else {
269     $rule = __ATTRTEXT:%false__;
270     }
271     SuikaWiki::Plugin->formatter ('page-link')
272     ->replace ($rule, param => $o, -parent => $p->{-parent});
273    
274     FormattingRule:
275     @Category[list]: page-link
276     @Name:-bare-text
277     @Formatting:
278     $p->{-parent}->append_text ($p->{-bare_text});
279    
280     Function:
281     @Name: to_wikipage_in_html
282     @Description:
283     @@@:Make a link to the WikiPage (in HTML)
284     @@lang:en
285     @Main:
286     my (undef, $src => $dest, $opt) = @_;
287 wakaba 1.2 local $NestLevel = $NestLevel + 1;
288     if (100 < $NestLevel) {
289     $opt->{parent}->append_new_node (type => '#comment',
290     value => $src->{label});
291     SuikaWiki::Plugin->module_package ('Error')
292     ->report_error_simple
293     ($opt->{o}->{wiki},
294     'Condition' => 'Link nesting too deep',
295     'Template' => $src->{label},
296     -trace => 1);
297     return;
298     }
299 wakaba 1.1 #$dest->{page_name} = SuikaWiki::Plugin::WikiNamespace->resolve_relative_name
300     # ($dest->{base} => $dest->{page_name_relative});
301     $dest->{page_name} = $dest->{page_name_relative};
302     $dest->{uri} = SuikaWiki::Plugin->_uri_wiki_page ## TODO: use formal API
303     (join (q#//#, @{$dest->{page_name}}),
304     mode => $dest->{wiki_mode},
305     anchor => $dest->{page_anchor_no}, up_to_date => $dest->{_up_to_date},
306     with_lm => $dest->{_with_lm},
307     add_param => $dest->{page_anchor_name}?"#$dest->{page_anchor_name}":'');
308    
309     local $opt->{o}->{link} = {
310     src => $src,
311     dest => $dest,
312     option => $opt,
313     };
314 wakaba 1.2 $src->{label} ||= SuikaWiki::Plugin->resource ('Link:toWikiPage:SourceLabel');
315     try {
316     SuikaWiki::Plugin->formatter ('page_link')
317     ->replace ($src->{label}, param => $opt->{o}, -parent => $opt->{parent});
318     } catch Message::Util::Formatter::error with {
319     my $err = shift;
320     if ($err->{-formatter}->{-category_name} eq 'page_link') {
321     my $wiki = $err->{-option}->{param}->{wiki};
322     __FUNCPACK__->logging_template_error ($err, $wiki,
323     template => $src->{label});
324     undef;
325     } else {
326     $err->throw;
327     }
328     };
329    
330     Function:
331     @Name: logging_template_error
332     @Description:
333     @@@:
334     Logging formatting-template-text error
335     @@lang:en
336     @Main:
337     my (undef, $err, $wiki, %opt) = @_;
338     my $error = {};
339     my $dl = $error->{description}
340     = new Message::Markup::XML::Node
341     (type => '#element',
342     namespace_uri => $NS_XHTML1,
343     local_name => 'dl');
344     ## TODO: Use resource
345     $dl->append_new_node (type => '#element',
346     namespace_uri => $NS_XHTML1,
347     local_name => 'dt')
348     ->append_text ('Template');
349     $dl->append_new_node (type => '#element',
350     namespace_uri => $NS_XHTML1,
351     local_name => 'dd')
352     ->append_text ($opt{template});
353     $dl->append_new_node (type => '#element',
354     namespace_uri => $NS_XHTML1,
355     local_name => 'dt')
356     ->append_text ('Error condition');
357     $dl->append_new_node (type => '#element',
358     namespace_uri => $NS_XHTML1,
359     local_name => 'dd')
360     ->append_text ($err->text);
361     $dl->append_new_node (type => '#element',
362     namespace_uri => $NS_XHTML1,
363     local_name => 'dt')
364     ->append_text ('Formatting context');
365     $dl->append_new_node (type => '#element',
366     namespace_uri => $NS_XHTML1,
367     local_name => 'dd')
368     ->append_text (qq($err->{-formatter}->{-category_name}));
369    
370     push @{$wiki->{var}->{error}||=[]}, $error;
371 wakaba 1.1
372 wakaba 1.2 Resource:
373     @Link:toWikiPage:SourceLabel:
374     @@@:
375     %link-to-it(
376     label=>{%page-title (relative);%if-linked-wikipage-exist(
377     true=>{%if-link-has-dest-anchor-no(true=>{>>%link-dest-anchor-no;});},
378     false=>{%res(name=>{Link:toWikiPage:NotExist:Mark});}
379     );}p,
380     description=>{%page-name(absolute);; %if-linked-wikipage-exist(
381     true=>{%page-headline;},
382     false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)},
383     );}p,
384     class=>{%if-linked-wikipage-exist(false=>{not-exist});}p,
385     );

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24