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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Fri Aug 6 08:57:50 2004 UTC (20 years, 8 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, HEAD
Branch point for: helowiki, helowiki-2005
Changes since 1.9: +169 -1 lines
wr--propread: New formatting rule

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: WikiRead
5     @Description:
6     @@@: Showing WikiPage content
7     @@lang:en
8 wakaba 1.9 @License: %%Perl%%
9 wakaba 1.1 @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: w@suika.fam.cx
15 wakaba 1.9 @Date.RCS:
16 wakaba 1.10 $Date: 2004/04/25 07:06:50 $
17 wakaba 1.2 @RequiredModule[list]:
18 wakaba 1.3 SuikaWiki::Format::Definition
19 wakaba 1.2 @RequiredPlugin[list]:
20 wakaba 1.5 WikiFormat
21 wakaba 1.2 WikiView
22     WikiStruct
23     WikiLinking
24     HTML
25     SuikaWiki09
26 wakaba 1.3 @Use:
27     require SuikaWiki::Format::Definition;
28 wakaba 1.6 use Message::Util::Error;
29 wakaba 1.10 @Namespace:
30     @@media-type:
31     http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt#
32     @@pe:
33     http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit#
34    
35 wakaba 1.1
36     ViewDefinition:
37     @Mode: read
38     @Condition:
39     @@http-method[list]:
40     GET
41     HEAD
42 wakaba 1.7 POST
43 wakaba 1.1 @Description:
44     @@@: Show WikiPage content as whole
45     @@lang: en
46     @template:
47     @@http-status-code: 200
48     @@media-type: text/html
49     @@use-media-type-charset: 1
50     @@expires: %%view%%
51     @@body:
52     %html-document (
53 wakaba 1.2 title => {%res (name => {View:WebPageTitle});}p,
54     link-meta => {%template (name => links);}p,
55 wakaba 1.1 content => {
56     %template (
57     name => ws--page,
58     -content => {
59     %block (
60 wakaba 1.3 class => "bodytext",
61 wakaba 1.2 content => {%template (name => wr--read-body);}p,
62 wakaba 1.1 );
63     },
64     );
65     }p,
66     );
67    
68 wakaba 1.2 ViewFragment:
69     @Template[list]:wr--read-body
70     @Order: 0
71     @Description:
72     @@@: "Read" mode body -- WikiPage main content
73     @@lang:en
74     @Formatting:
75     %read (comment);
76    
77 wakaba 1.1 PluginConst:
78     @NS_XHTML1:
79     http://www.w3.org/1999/xhtml
80    
81     FormattingRule:
82     @Category[list]: view
83     @Name: read
84     @Description:
85     @@@:
86     Show the WikiPage to be "read"
87     @@lang: en
88     @Parameter:
89     @@Name: page
90     @@Type: WikiName
91     @@Default: (current)
92     @@Description:
93     @@@@: WikiPage shown
94     @@@lang:en
95     @Parameter:
96     @@Name: comment
97     @@Type: boolean
98     @@Default: {0}
99     @@Description:
100     @@@@: Append comment form
101     @@@lang:en
102 wakaba 1.7 @Parameter:
103     @@Name: IsFragment
104     @@Type: boolean
105     @@Default: (auto)
106     @@Description:
107     @@@@:
108     Specify whether convertion result should be "fragment" format.
109     (For example, "text/html" fragment will not have "html" element
110     as the root element.)
111     @@@lang: en
112     @Parameter:
113     @@Name: Name
114     @@Type: product-name-token
115     @@Default: (auto)
116     @@Description:
117     @@@@:
118     Media type name (product style).
119     @@@lang: en
120     @Parameter:
121     @@Name: return-type
122     @@Type: token
123     @@Default: (default)
124     @@Description:
125     @@@@:
126     Select how the content converted to be returned.
127     \
128     (default): Result is appended to the parent node.
129     \
130     'ToString': Result is returned as a Perl string.
131     \
132     'ToOctetStream': Result is returned as a Perl byte string.
133     \
134     Nothing is returned in case convertion to specified returning method
135     is not defined by the Format definition.
136     @Parameter:
137     @@Name: Type
138     @@Type: internet-media-type-subtype
139     @@Default: (auto)
140     @@Description:
141     @@@@:
142     Internet media type (type/subtype pair) to which content should be
143     converted.
144     \
145     Note that media type parameters cannot be specified here.
146     Way to specify them are under consideration.
147     \
148     Neither Type nor Name is specified, defaulted to
149     (Type => {text/html}, IsFragment => 1).
150     @Parameter:
151     @@Name: Version
152     @@Type: product-version-token
153     @@Default: (auto)
154     @@Description:
155     @@@@:
156     Media type version (product style).
157     \
158     Name parameter should also be specified, otherwise Version makes
159     no mean.
160     @Parameter:
161     @@Name: when-no-converter
162     @@Type: token
163     @@Default: "exception"
164     @@Description:
165     @@@@:
166     Specify how behave if Converter not found.
167     \
168     'exception': Throw an exception.
169     \
170     '406': Turn to -wf--converter-not-found mode.
171     \
172     'ignore': Ignore. Returned value is not defined.
173 wakaba 1.1 @Formatting:
174 wakaba 1.3 __ATTRTEXT:%page__;__ATTRTEXT:%comment__;
175 wakaba 1.7 my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page});
176 wakaba 1.6 my $content;
177 wakaba 1.9 my $content_prop;
178 wakaba 1.6 try {
179     $content = $o->{wiki}->{db}->get (content => $page);
180 wakaba 1.9 $content_prop = $o->{wiki}->{db}->get (content_prop => $page);
181 wakaba 1.6 } catch SuikaWiki::DB::Util::Error with {
182 wakaba 1.8 my $err = shift;
183     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
184 wakaba 1.6 $content = undef;
185     };
186 wakaba 1.4
187 wakaba 1.7 my %param;
188     if ($p->{Type} or $p->{Name}) {
189     for (qw/Type Name Version IsFragment return_type/) {
190     $param{$_} = $p->{$_};
191     }
192     ## TODO: Type_param
193     } else {
194     %param = (Type => 'text/html', IsFragment => 1);
195     }
196    
197     my $return;
198     try {
199     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
200     ->handler (\$content,
201 wakaba 1.9 content_prop => $content_prop,
202 wakaba 1.7 o => $o, wiki => $o->{wiki});
203     $return = $format->convert
204     (\$content, %param,
205     -parent => $p->{-parent},
206 wakaba 1.9 content_prop => $content_prop,
207 wakaba 1.7 o => $o, page => $page,
208     -with_annotation_input => $p->{comment});
209     } catch SuikaWiki::Format::Definition::error with {
210     my $err = shift;
211    
212     if ($p->{when_no_converter} eq '406') {
213     SuikaWiki::Plugin->module_package ('Error')
214     ->report_error_simple
215     ($o->{wiki}, WikiFormat => $err->text);
216     $o->{wiki}->view_in_mode (mode => '-wf--converter-not-found',
217     method => 'GET');
218     throw SuikaWiki::View::Implementation::error
219     -type => 'ERROR_REPORTED';
220     } elsif ($p->{when_no_converter} ne 'ignore') {
221     $err->throw;
222 wakaba 1.10 }
223     };
224     if ($p->{return_type} eq 'ToString' or
225     $p->{return_type} eq 'ToOctetStream') {
226     $p->{-parent}->append_new_node (type => '#xml', value => $return);
227     }
228    
229     FormattingRule:
230     @Category[list]: view
231     @Name: wr--propread
232     @Description:
233     @@@:
234     Show property value to be "read".
235     @@lang: en
236     @Parameter:
237     @@Name: IsFragment
238     @@Type: boolean
239     @@Default: (auto)
240     @@Description:
241     @@@@:
242     Specify whether convertion result should be "fragment" format.
243     (For example, "text/html" fragment will not have "html" element
244     as the root element.)
245     @@@lang: en
246     @Parameter:
247     @@Name: Name
248     @@Type: product-name-token
249     @@Default: (auto)
250     @@Description:
251     @@@@:
252     Media type name (product style).
253     @@@lang: en
254     @Parameter:
255     @@Name: page
256     @@Type: WikiName
257     @@Default: (current)
258     @@Description:
259     @@@@: WikiPage shown
260     @@@lang:en
261     @Parameter:
262     @@Name: prop
263     @@Type: token
264     @@Default: "abstract"
265     @@Description:
266     @@@lang:en
267     @@@@: Property name (short one defined in suikawiki-config.ph).
268     @Parameter:
269     @@Name: return-type
270     @@Type: token
271     @@Default: (default)
272     @@Description:
273     @@@@:
274     Select how the content converted to be returned.
275     \
276     (default): Result is appended to the parent node.
277     \
278     'ToString': Result is returned as a Perl string.
279     \
280     'ToOctetStream': Result is returned as a Perl byte string.
281     \
282     Nothing is returned in case convertion to specified returning method
283     is not defined by the Format definition.
284     @Parameter:
285     @@Name: Type
286     @@Type: internet-media-type-subtype
287     @@Default: (auto)
288     @@Description:
289     @@@@:
290     Internet media type (type/subtype pair) to which content should be
291     converted.
292     \
293     Note that media type parameters cannot be specified here.
294     Way to specify them are under consideration.
295     \
296     Neither Type nor Name is specified, defaulted to
297     (Type => {text/html}, IsFragment => 1).
298     @Parameter:
299     @@Name: Version
300     @@Type: product-version-token
301     @@Default: (auto)
302     @@Description:
303     @@@@:
304     Media type version (product style).
305     \
306     Name parameter should also be specified, otherwise Version makes
307     no mean.
308     @Parameter:
309     @@Name: when-no-converter
310     @@Type: token
311     @@Default: "exception"
312     @@Description:
313     @@@@:
314     Specify how behave if Converter not found.
315     \
316     'exception': Throw an exception.
317     \
318     '406': Turn to -wf--converter-not-found mode.
319     \
320     'ignore': Ignore. Returned value is not defined.
321     \
322     Otherwise, error message is instead outputed.
323     @@@lang: en
324     @Parameter:
325     @@Name: when-no-converter-message
326     @@Type: template
327     @@Description:
328     @@@@: Message template.
329     @@@lang:en
330     @Formatting:
331     __ATTRTEXT:%page__;__ATTRTEXT:%prop__;
332     my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page});
333     my $content_prop;
334     try {
335     $content_prop = $o->{wiki}->{db}->get (content_prop => $page);
336     } catch SuikaWiki::DB::Util::Error with {
337     my $err = shift;
338     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
339     };
340     my $prop = $o->{wiki}->{config}->{<Q:pe:prop>}->{$p->{prop}};
341     return unless $prop;
342     my $content = $content_prop->get_attribute_value ($prop->{uri});
343     return unless defined $content and length $content;
344     my $content_type = $content_prop->get_attribute_value
345     ($prop->{<Q:media-type:media-type-prop>});
346    
347     my %param;
348     if ($p->{Type} or $p->{Name}) {
349     for (qw/Type Name Version IsFragment return_type/) {
350     $param{$_} = $p->{$_};
351     }
352     ## TODO: Type_param
353     } else {
354     %param = (Type => 'text/html', IsFragment => 1);
355     }
356    
357     my $return;
358     try {
359     my $format = __FUNCPACK{WikiFormat}__
360     ->handler (\$content,
361     content_prop => $content_prop,
362     serialized_media_type => $content_type,
363     o => $o, wiki => $o->{wiki});
364     $return = $format->convert
365     (\$content, %param,
366     -parent => $p->{-parent},
367     content_prop => $content_prop,
368     o => $o, page => $page);
369     } catch SuikaWiki::Format::Definition::error with {
370     my $err = shift;
371    
372     if ($p->{when_no_converter} eq '406') {
373     __FUNCPACK{Error}__
374     ->report_error_simple
375     ($o->{wiki}, WikiFormat => $err->text);
376     $o->{wiki}->view_in_mode (mode => '-wf--converter-not-found',
377     method => 'GET');
378     throw SuikaWiki::View::Implementation::error
379     -type => 'ERROR_REPORTED';
380     } elsif ($p->{when_no_converter} eq 'exception') {
381     $err->throw;
382     } elsif ($p->{when_no_converter} ne 'ignore') {
383     __ATTRNODE:%when_no_converter_message->{$p->{-parent}}__;
384 wakaba 1.7 }
385     };
386     if ($p->{return_type} eq 'ToString' or
387     $p->{return_type} eq 'ToOctetStream') {
388     $p->{-parent}->append_new_node (type => '#xml', value => $return);
389     }
390 wakaba 1.1
391     ViewFragment:
392     @Name: links
393     @Description:
394     @@@: Link to read mode of the WikiPage
395     @@lang:en
396     @Formatting:
397     %link-wiki(mode=>read,rel=>view,class=>wiki-cmd,
398 wakaba 1.4 description=>{%res(name=>{Link:View:Description});}p,up-to-date);
399 wakaba 1.1
400     ViewFragment:
401     @Name: navbar
402     @Description:
403     @@@: Link to read mode of the WikiPage
404     @Order: 0
405     @Formatting:
406 wakaba 1.3 %link-to-wikipage (
407     rel => view,
408     mode => read,
409     up-to-date,
410     label => {%link-to-it (
411     class => wiki-cmd,
412     label => {%res(name=>ViewThisPage);}p,
413     description => {%res(name=>ViewThisPageLong);}p,
414     );},
415     );
416 wakaba 1.1
417     Resource:
418     @Link:View:Description:
419     @@@: Show this WikiPage in reading mode
420     @@lang:en
421 wakaba 1.7 @Mode:read:
422     @@@: Browsing
423     @@lang: en
424 wakaba 1.1 @ViewThisPage:
425     @@@: View
426     @@lang:en
427     @ViewThisPageLong:
428     @@@: Show latest version of this WikiPage
429     @@lang:en
430     @View:WebPageTitle:
431     @@@: %page-name;
432     @@lang:en
433    
434    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24