#?SuikaWikiConfig/2.0 Plugin: @Name: WikiRead @Description: @@@: Showing WikiPage content @@lang:en @License: %%Perl%% @Author: @@Name: @@@@: Wakaba @@@lang:ja @@@script:Latn @@Mail[list]: w@suika.fam.cx @Date.RCS: $Date: 2004/08/06 08:57:50 $ @RequiredModule[list]: SuikaWiki::Format::Definition @RequiredPlugin[list]: WikiFormat WikiView WikiStruct WikiLinking HTML SuikaWiki09 @Use: require SuikaWiki::Format::Definition; use Message::Util::Error; @Namespace: @@media-type: http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt# @@pe: http://suika.fam.cx/~wakaba/archive/2004/7/20/sw-propedit# ViewDefinition: @Mode: read @Condition: @@http-method[list]: GET HEAD POST @Description: @@@: Show WikiPage content as whole @@lang: en @template: @@http-status-code: 200 @@media-type: text/html @@use-media-type-charset: 1 @@expires: %%view%% @@body: %html-document ( title => {%res (name => {View:WebPageTitle});}p, link-meta => {%template (name => links);}p, content => { %template ( name => ws--page, -content => { %block ( class => "bodytext", content => {%template (name => wr--read-body);}p, ); }, ); }p, ); ViewFragment: @Template[list]:wr--read-body @Order: 0 @Description: @@@: "Read" mode body -- WikiPage main content @@lang:en @Formatting: %read (comment); PluginConst: @NS_XHTML1: http://www.w3.org/1999/xhtml FormattingRule: @Category[list]: view @Name: read @Description: @@@: Show the WikiPage to be "read" @@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (current) @@Description: @@@@: WikiPage shown @@@lang:en @Parameter: @@Name: comment @@Type: boolean @@Default: {0} @@Description: @@@@: Append comment form @@@lang:en @Parameter: @@Name: IsFragment @@Type: boolean @@Default: (auto) @@Description: @@@@: Specify whether convertion result should be "fragment" format. (For example, "text/html" fragment will not have "html" element as the root element.) @@@lang: en @Parameter: @@Name: Name @@Type: product-name-token @@Default: (auto) @@Description: @@@@: Media type name (product style). @@@lang: en @Parameter: @@Name: return-type @@Type: token @@Default: (default) @@Description: @@@@: Select how the content converted to be returned. \ (default): Result is appended to the parent node. \ 'ToString': Result is returned as a Perl string. \ 'ToOctetStream': Result is returned as a Perl byte string. \ Nothing is returned in case convertion to specified returning method is not defined by the Format definition. @Parameter: @@Name: Type @@Type: internet-media-type-subtype @@Default: (auto) @@Description: @@@@: Internet media type (type/subtype pair) to which content should be converted. \ Note that media type parameters cannot be specified here. Way to specify them are under consideration. \ Neither Type nor Name is specified, defaulted to (Type => {text/html}, IsFragment => 1). @Parameter: @@Name: Version @@Type: product-version-token @@Default: (auto) @@Description: @@@@: Media type version (product style). \ Name parameter should also be specified, otherwise Version makes no mean. @Parameter: @@Name: when-no-converter @@Type: token @@Default: "exception" @@Description: @@@@: Specify how behave if Converter not found. \ 'exception': Throw an exception. \ '406': Turn to -wf--converter-not-found mode. \ 'ignore': Ignore. Returned value is not defined. @Formatting: __ATTRTEXT:%page__;__ATTRTEXT:%comment__; my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page}); my $content; my $content_prop; try { $content = $o->{wiki}->{db}->get (content => $page); $content_prop = $o->{wiki}->{db}->get (content_prop => $page); } catch SuikaWiki::DB::Util::Error with { my $err = shift; $err->throw if $err->{-type} eq 'ERROR_REPORTED'; $content = undef; }; my %param; if ($p->{Type} or $p->{Name}) { for (qw/Type Name Version IsFragment return_type/) { $param{$_} = $p->{$_}; } ## TODO: Type_param } else { %param = (Type => 'text/html', IsFragment => 1); } my $return; try { my $format = SuikaWiki::Plugin->module_package ('WikiFormat') ->handler (\$content, content_prop => $content_prop, o => $o, wiki => $o->{wiki}); $return = $format->convert (\$content, %param, -parent => $p->{-parent}, content_prop => $content_prop, o => $o, page => $page, -with_annotation_input => $p->{comment}); } catch SuikaWiki::Format::Definition::error with { my $err = shift; if ($p->{when_no_converter} eq '406') { SuikaWiki::Plugin->module_package ('Error') ->report_error_simple ($o->{wiki}, WikiFormat => $err->text); $o->{wiki}->view_in_mode (mode => '-wf--converter-not-found', method => 'GET'); throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED'; } elsif ($p->{when_no_converter} ne 'ignore') { $err->throw; } }; if ($p->{return_type} eq 'ToString' or $p->{return_type} eq 'ToOctetStream') { $p->{-parent}->append_new_node (type => '#xml', value => $return); } FormattingRule: @Category[list]: view @Name: wr--propread @Description: @@@: Show property value to be "read". @@lang: en @Parameter: @@Name: IsFragment @@Type: boolean @@Default: (auto) @@Description: @@@@: Specify whether convertion result should be "fragment" format. (For example, "text/html" fragment will not have "html" element as the root element.) @@@lang: en @Parameter: @@Name: Name @@Type: product-name-token @@Default: (auto) @@Description: @@@@: Media type name (product style). @@@lang: en @Parameter: @@Name: page @@Type: WikiName @@Default: (current) @@Description: @@@@: WikiPage shown @@@lang:en @Parameter: @@Name: prop @@Type: token @@Default: "abstract" @@Description: @@@lang:en @@@@: Property name (short one defined in suikawiki-config.ph). @Parameter: @@Name: return-type @@Type: token @@Default: (default) @@Description: @@@@: Select how the content converted to be returned. \ (default): Result is appended to the parent node. \ 'ToString': Result is returned as a Perl string. \ 'ToOctetStream': Result is returned as a Perl byte string. \ Nothing is returned in case convertion to specified returning method is not defined by the Format definition. @Parameter: @@Name: Type @@Type: internet-media-type-subtype @@Default: (auto) @@Description: @@@@: Internet media type (type/subtype pair) to which content should be converted. \ Note that media type parameters cannot be specified here. Way to specify them are under consideration. \ Neither Type nor Name is specified, defaulted to (Type => {text/html}, IsFragment => 1). @Parameter: @@Name: Version @@Type: product-version-token @@Default: (auto) @@Description: @@@@: Media type version (product style). \ Name parameter should also be specified, otherwise Version makes no mean. @Parameter: @@Name: when-no-converter @@Type: token @@Default: "exception" @@Description: @@@@: Specify how behave if Converter not found. \ 'exception': Throw an exception. \ '406': Turn to -wf--converter-not-found mode. \ 'ignore': Ignore. Returned value is not defined. \ Otherwise, error message is instead outputed. @@@lang: en @Parameter: @@Name: when-no-converter-message @@Type: template @@Description: @@@@: Message template. @@@lang:en @Formatting: __ATTRTEXT:%page__;__ATTRTEXT:%prop__; my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page}); my $content_prop; try { $content_prop = $o->{wiki}->{db}->get (content_prop => $page); } catch SuikaWiki::DB::Util::Error with { my $err = shift; $err->throw if $err->{-type} eq 'ERROR_REPORTED'; }; my $prop = $o->{wiki}->{config}->{}->{$p->{prop}}; return unless $prop; my $content = $content_prop->get_attribute_value ($prop->{uri}); return unless defined $content and length $content; my $content_type = $content_prop->get_attribute_value ($prop->{}); my %param; if ($p->{Type} or $p->{Name}) { for (qw/Type Name Version IsFragment return_type/) { $param{$_} = $p->{$_}; } ## TODO: Type_param } else { %param = (Type => 'text/html', IsFragment => 1); } my $return; try { my $format = __FUNCPACK{WikiFormat}__ ->handler (\$content, content_prop => $content_prop, serialized_media_type => $content_type, o => $o, wiki => $o->{wiki}); $return = $format->convert (\$content, %param, -parent => $p->{-parent}, content_prop => $content_prop, o => $o, page => $page); } catch SuikaWiki::Format::Definition::error with { my $err = shift; if ($p->{when_no_converter} eq '406') { __FUNCPACK{Error}__ ->report_error_simple ($o->{wiki}, WikiFormat => $err->text); $o->{wiki}->view_in_mode (mode => '-wf--converter-not-found', method => 'GET'); throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED'; } elsif ($p->{when_no_converter} eq 'exception') { $err->throw; } elsif ($p->{when_no_converter} ne 'ignore') { __ATTRNODE:%when_no_converter_message->{$p->{-parent}}__; } }; if ($p->{return_type} eq 'ToString' or $p->{return_type} eq 'ToOctetStream') { $p->{-parent}->append_new_node (type => '#xml', value => $return); } ViewFragment: @Name: links @Description: @@@: Link to read mode of the WikiPage @@lang:en @Formatting: %link-wiki(mode=>read,rel=>view,class=>wiki-cmd, description=>{%res(name=>{Link:View:Description});}p,up-to-date); ViewFragment: @Name: navbar @Description: @@@: Link to read mode of the WikiPage @Order: 0 @Formatting: %link-to-wikipage ( rel => view, mode => read, up-to-date, label => {%link-to-it ( class => wiki-cmd, label => {%res(name=>ViewThisPage);}p, description => {%res(name=>ViewThisPageLong);}p, );}, ); Resource: @Link:View:Description: @@@: Show this WikiPage in reading mode @@lang:en @Mode:read: @@@: Browsing @@lang: en @ViewThisPage: @@@: View @@lang:en @ViewThisPageLong: @@@: Show latest version of this WikiPage @@lang:en @View:WebPageTitle: @@@: %page-name; @@lang:en