#?SuikaWikiConfig/2.0 Plugin: @Name: Paragraph @Description: @@@: Paragraph-oriented wiki'ing @@lang:en @License: %%Perl%% @Author: @@Name: @@@@: Wakaba @@@lang:ja @@@script:Latn @@Mail[list]: w@suika.fam.cx @Date.RCS: $Date: 2004/08/11 00:05:02 $ @RequiredPlugin[list]: WikiFormat WikiStruct WikiLinking HTML WikiRead @Use: require SuikaWiki::Format::Definition; use Message::Util::Error; my $WIKIFORMAT; my $WIKIRESOURCE; ViewDefinition: @Mode: para--read @Condition: @@http-method[list]: GET HEAD POST @Description: @@@: Show WikiPage content as whole (paragraph-oriented) @@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 => para--read-body);}p, ); }, ); }p, ); ViewFragment: @Template[list]:para--read-body @Order: 0 @Description: @@@: "Read" mode body -- WikiPage main content (parahraph-oriented) @@lang:en @Formatting: %para--read; %section ( class => para--new, title => {%res (name => {Paragraph:New:Title});}p, heading, content => {%para--new-paragraph;}p, ); PluginConst: @NS_XHTML1: http://www.w3.org/1999/xhtml @WIKIFORMAT: {($WIKIFORMAT ||= SuikaWiki::Plugin->module_package ('WikiFormat'))} @WIKIRESOURCE: {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} FormattingRule: @Category[list]: view @Name: para--read @Description: @@@: Show the WikiPage to be "read" (paragraph-oriented) @@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: 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 @page; if (@$page != 1 and $page->[0] eq 'Wiki') { push @page, $page; } else { my $list; try { $list = $o->{wiki}->{db}->get (content_map => $page); } catch SuikaWiki::DB::Util::Error with { my $err = shift; $err->throw if $err->{-type} eq 'ERROR_REPORTED'; $list = undef; }; push @page, map {$o->{wiki}->name ([0+$_])} grep $_, split /\n/, $list || ''; } 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); } __ATTRTEXT:%paragraph__; my $para_template = $p->{paragraph} || $WIKIRESOURCE->get_text (name => 'Paragraph:Read:Paragraph', o => $o, wiki => $o->{wiki}); for my $page (@page) { local $o->{para__paragraph} = { number => 0 + $page->[0], page => $page, }; try { $f->replace ($para_template, param => $o, -parent => $p->{-parent}); } catch Message::Util::Formatter::error with { my $err = shift; SuikaWiki::Plugin->module_package ('Error') ->reporting_formatting_template_error ($err, $err->{option}->{param}->{wiki}); throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED'; }; } FormattingRule: @Category[list]: view view-resource form-input page-link link-to-resource @Name: para--page-name @Description: @@@: WikiName for paragraph @@lang: en @Formatting: $p->{-parent}->append_text ($o->{para__paragraph}->{page}->stringify (wiki => $o->{wiki})); FormattingRule: @Category[list]: view view-resource form-input page-link link-to-resource @Name: para--number @Description: @@@: Sequential number for paragraph @@lang: en @Formatting: $p->{-parent}->append_text ($o->{para__paragraph}->{number} + 0); ViewFragment: @Name: links @Description: @@@: Link to read mode of the WikiPage @@lang:en @Formatting: %link-wiki(mode=>para--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 => para--read, up-to-date, label => {%link-to-it ( class => wiki-cmd, label => {%res(name=>ViewThisPage);}p, description => {%res(name=>ViewThisPageLong);}p, );}, ); FormattingRule: @Category[list]: view view-resource form-input @Name: para--new-paragraph @Formatting: my $page = $o->{wiki}->name ($p->{page} || $o->{wiki}->{var}->{page}); SuikaWiki::Plugin->module_package ('WikiFormCore') ->make_form_in_html ($p->{-parent}, $p->{content} || $WIKIRESOURCE->get (name => 'Paragraph:NewForm:Content', o => $o, wiki => $o->{wiki}), wiki => $o->{wiki}, o => $o, index => -1, output => { mode => 'para--new', page => $page, }); ViewDefinition: @Mode: para--new @Condition: @@output: http-cgi @@http-method[list]: POST @Description: @@@: Create a new paragraph @@lang:en @method: @@@: my $wiki = $self->{view}->{wiki}; ## Open Database $wiki->{var}->{db}->{read_only}->{content} = 0; $wiki->{var}->{db}->{read_only}->{content_prop} = 0; $wiki->{var}->{db}->{read_only}->{lastmodified} = 0; $self->{view}->init_db; my $page = $wiki->{var}->{page}; my $o = { wiki => $wiki, }; $o->{para__paragraph}->{number} = $wiki->{db}->_do (content => '_next_number'); $wiki->{db}->set (content => [$o->{para__paragraph}->{number}], => scalar $wiki->{input}->parameter ('para--content')); $wiki->{db}->set (lastmodified => [$o->{para__paragraph}->{number}], => time); my $map = $wiki->{db}->get (content_map => $page); $map .= "\n" . $o->{para__paragraph}->{number}; $wiki->{db}->set (content_map => $page => $map); $wiki->{db}->set (lastmodified => $page => time); my $uri = $self->{view}->{wiki}->uri_reference (page => $page, up_to_date => 1); require SuikaWiki::Output::HTTP; my $output = SuikaWiki::Output::HTTP->new (wiki => $self->{view}->{wiki}); $output->set_redirect (uri => $uri, status_code => 303, status_phrase => q(Created)); ## Should we use 201 Created? $output->output (output => 'http-cgi'); @@Name: main Resource: @Paragraph:New:Title: @@@: Add @@lang: en @Paragraph:NewForm:Content: %line (content => { %textarea ( id => para--content, label => {%res (name => {Paragraph:NewForm:MainText:Label});}p, size => 20, lines => 10, ); }p); %line (content => { %submit (label => {%res (name => {Paragraph:NewForm:Submit:Label});}p); }p); @Paragraph:NewForm:MainText:Label: @@@: Content @@lang: en @Paragraph:NewForm:Submit:Label: @@@: Add @@lang: en @Paragraph:Read:Paragraph: %block ( class => para--page, content => { %read (page => {%para--page-name;}p); %block ( class => para--footer, content => { %link-to-wikipage ( label => {%link-to-it (label => {#%para--number;}p);}, page => {%para--number;}p, mode => para--para-read, ); @%last-modified (page => {%para--number;}p); }p, ); }p, );