| 1 |
#?SuikaWikiConfig/2.0 |
| 2 |
|
| 3 |
Plugin: |
| 4 |
@Name: WikiFormat |
| 5 |
@Description: |
| 6 |
@@@: WikiFormat - format independent proceding |
| 7 |
@@lang:en |
| 8 |
@License: %%Perl%% |
| 9 |
@Author: |
| 10 |
@@Name: |
| 11 |
@@@@: Wakaba |
| 12 |
@@@lang:ja |
| 13 |
@@@script:Latn |
| 14 |
@@Mail[list]: w@suika.fam.cx |
| 15 |
@Date.RCS: |
| 16 |
$Date: 2004/06/03 06:38:48 $ |
| 17 |
@RequiredPackage[list]: |
| 18 |
Error |
| 19 |
@Use: |
| 20 |
my $WIKIFORMCORE; |
| 21 |
my $WIKIRESOURCE; |
| 22 |
@Namespace: |
| 23 |
@@media-type: |
| 24 |
http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt# |
| 25 |
|
| 26 |
PluginConst: |
| 27 |
@NS_XHTML1: |
| 28 |
http://www.w3.org/1999/xhtml |
| 29 |
@WIKIFORMCORE: |
| 30 |
{($WIKIFORMCORE ||= SuikaWiki::Plugin->module_package ('WikiFormCore'))} |
| 31 |
@WIKIRESOURCE: |
| 32 |
{($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} |
| 33 |
|
| 34 |
Function: |
| 35 |
@Name: handler |
| 36 |
@Description: |
| 37 |
@@@: |
| 38 |
Getting format handler for given data |
| 39 |
@@lang:en |
| 40 |
@Main: |
| 41 |
my (undef, $content, %opt) = @_; |
| 42 |
my %type; |
| 43 |
if (not $opt{serialized_media_type} and $opt{content_prop}) { |
| 44 |
$type{serialized_media_type} = $opt{content_prop} |
| 45 |
->get_attribute_value (<Q:media-type:media-type>); |
| 46 |
} |
| 47 |
$type{serialized_media_type} ||= $opt{serialized_media_type}; |
| 48 |
unless ($type{serialized_media_type}) { |
| 49 |
my $magic = $opt{magic}; |
| 50 |
if (not $magic and |
| 51 |
$$content =~ m[^(?:\#\?|/\*\s*)([\w.+-]+(?:/[\w.+-]+)?)]) { |
| 52 |
$magic = $1; |
| 53 |
} |
| 54 |
%type = $magic ? (magic => $magic) : |
| 55 |
(Type => 'text/x-suikawiki', |
| 56 |
Type_param => {version => '0.9'}); |
| 57 |
} |
| 58 |
my $def = SuikaWiki::Format::Definition->new_handler (%type, -error => sub { |
| 59 |
my ($err) = @_; |
| 60 |
__FUNCPACK{Error}__ |
| 61 |
->report_error_simple ($opt{wiki} ||= $opt{o}->{wiki}, |
| 62 |
SuikaWiki::Plugin |
| 63 |
->module_package ('WikiResource') |
| 64 |
->get (name => 'WikiFormat:Error:Type=WikiFormat', |
| 65 |
wiki => $opt{wiki} || |
| 66 |
$opt{o}->{wiki}, |
| 67 |
o => $opt{o}) |
| 68 |
=> $err->text, |
| 69 |
-trace => $opt{wiki}->{config} |
| 70 |
->{debug}->{format}); |
| 71 |
}); |
| 72 |
$def->{wiki} = $opt{wiki} || $opt{o}->{wiki}; |
| 73 |
$def->{view} = $def->{wiki}->{view}; |
| 74 |
$def; |
| 75 |
|
| 76 |
ViewDefinition: |
| 77 |
@Mode: -wf--converter-not-found |
| 78 |
@Condition: |
| 79 |
@@http-method[list]: |
| 80 |
GET |
| 81 |
HEAD |
| 82 |
POST |
| 83 |
@Description: |
| 84 |
@@@: Converter to requested media type not found |
| 85 |
@@lang: en |
| 86 |
@template: |
| 87 |
@@http-status-code: 406 |
| 88 |
@@http-status-phrase: Converter Not Found |
| 89 |
@@media-type: text/html |
| 90 |
@@use-media-type-charset: 1 |
| 91 |
@@expires: %%error%% |
| 92 |
@@body: |
| 93 |
%html-document ( |
| 94 |
title => {%res (name => {WikiFormat:NoConverter:WebPageTitle});}p, |
| 95 |
link-meta => {%template (name => links);}p, |
| 96 |
content => { |
| 97 |
%block (id => tools1, class => tools, |
| 98 |
content => {%template (name => navbar);}p); |
| 99 |
%section ( |
| 100 |
title => {%res (name => {WikiFormat:NoConverter:Title});}p, heading, |
| 101 |
content => {%paragraph ( |
| 102 |
content => {%res (name => {WikiFormat:NoConverter:Description});}p, |
| 103 |
);%error-list ( |
| 104 |
no-error => {%res (name => {Error:NoErrorReported});}p, |
| 105 |
);}p, |
| 106 |
); |
| 107 |
%block (id => footer, content => {%template (name => ws--footer);}p); |
| 108 |
}p, |
| 109 |
); |
| 110 |
|
| 111 |
FormattingRule: |
| 112 |
@Category[list]: |
| 113 |
form-input |
| 114 |
view |
| 115 |
view-resource |
| 116 |
@Name: wf--select-media-type |
| 117 |
@Parameter: |
| 118 |
@@Name: source |
| 119 |
@@Type: CDATA |
| 120 |
@@Default: (auto) |
| 121 |
@@Description: |
| 122 |
@@@@: |
| 123 |
Default value provider. If specified, |
| 124 |
$o->{var}->{source}->{ $p->{source} } must be a CODE reference |
| 125 |
which returns the default value (a serialized media type, |
| 126 |
with additional information). |
| 127 |
@@@lang: en |
| 128 |
@Formatting: |
| 129 |
my $id = __FUNCPACK{WikiFormCore}__->control_id ($o, |
| 130 |
local_id => $p->{id}, |
| 131 |
require_local_id => 1); |
| 132 |
|
| 133 |
__ATTRNODE:%label__; |
| 134 |
my $has_label = 0; |
| 135 |
if ($p->{label}->count) { |
| 136 |
$has_label = 1; |
| 137 |
for ($p->{-parent}->append_new_node |
| 138 |
(type => '#element', |
| 139 |
namespace_uri => $NS_XHTML1, |
| 140 |
local_name => 'label')) { |
| 141 |
$_->set_attribute (for => $id->{global_id}); |
| 142 |
$_->append_node ($p->{label}); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
my $select = $p->{-parent}->append_new_node |
| 147 |
(type => '#element', |
| 148 |
namespace_uri => $NS_XHTML1, |
| 149 |
local_name => 'select'); |
| 150 |
$select->set_attribute (name => $id->{local_id}); |
| 151 |
|
| 152 |
$select->set_attribute (id => $id->{global_id}) if $has_label; |
| 153 |
__ATTRTEXT:%class__;__ATTRTEXT:%description__; |
| 154 |
$select->set_attribute (title => $p->{description}) if $p->{description}; |
| 155 |
$select->set_attribute (disabled => 'disabled') if $o->{form}->{disabled}; |
| 156 |
my @class = split /\s+/, $p->{class}; |
| 157 |
push @class, 'require' if $o->{form}->{require}->{id}->{$p->{id}}; |
| 158 |
$select->set_attribute (class => join ' ', @class) if @class; |
| 159 |
|
| 160 |
my $default; |
| 161 |
__ATTRTEXT:%source__; |
| 162 |
if ($p->{source}) { |
| 163 |
if (ref $o->{var}->{source}->{$p->{source}}) { |
| 164 |
my $d = $o->{var}->{source}->{$p->{source}} |
| 165 |
->(p => $p, o => $o, type => <Q:media-type:media-type>); |
| 166 |
$default = $d->{value}; |
| 167 |
} |
| 168 |
} else { |
| 169 |
if ($o->{var}->{content_prop}) { |
| 170 |
$default = $o->{var}->{content_prop}->get_attribute_value |
| 171 |
(<Q:media-type:media-type>, default => undef); |
| 172 |
} |
| 173 |
} |
| 174 |
unless ($default) { |
| 175 |
__ATTRTEXT:%default__; |
| 176 |
$default = $p->{default} || 'IMT:application/octet-stream##'; |
| 177 |
} |
| 178 |
|
| 179 |
my $mt = $o->{wiki}->{config}->{<Q:media-type:accept-media-type>} || {}; |
| 180 |
for my $mtname (sort keys %$mt) { |
| 181 |
for my $option ($select->append_new_node |
| 182 |
(type => '#element', |
| 183 |
namespace_uri => $NS_XHTML1, |
| 184 |
local_name => 'option')) { |
| 185 |
$option->set_attribute (title => $WIKIRESOURCE->get_text |
| 186 |
(name => 'WikiFormat:MediaType:Description:'.$mtname, |
| 187 |
o => $o, wiki => $o->{wiki}, default => $mtname)); |
| 188 |
$option->set_attribute (value => $mtname); |
| 189 |
if ($default eq $mtname) { |
| 190 |
$option->set_attribute (selected => 'selected'); |
| 191 |
undef $default; |
| 192 |
} |
| 193 |
$WIKIRESOURCE->get_op ('WikiFormat:MediaType:Label:'.$mtname, |
| 194 |
$o, $option, default => $mtname); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if ($default) { |
| 199 |
for my $option ($select->append_new_node |
| 200 |
(type => '#element', |
| 201 |
namespace_uri => $NS_XHTML1, |
| 202 |
local_name => 'option')) { |
| 203 |
$option->set_attribute (value => '#asis'); |
| 204 |
$option->set_attribute (title => $WIKIRESOURCE->get_text |
| 205 |
(name => 'WikiFormat:MediaType:Description:'.$default, |
| 206 |
o => $o, wiki => $o->{wiki}, default => $default)); |
| 207 |
$option->set_attribute (selected => 'selected'); |
| 208 |
$WIKIRESOURCE->get_op ('WikiFormat:MediaType:Label:'.$default, |
| 209 |
$o, $option, default => $default); |
| 210 |
|
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
ViewFragment: |
| 215 |
@Name: we--edit |
| 216 |
@Description: |
| 217 |
@@@: Edit form --- media type selection |
| 218 |
@@lang:en |
| 219 |
@Order: 420 |
| 220 |
@Formatting: |
| 221 |
%wf--select-media-type (id => wf--media-type); |
| 222 |
|
| 223 |
Resource: |
| 224 |
@WikiFormat:Error:Type=WikiFormat: |
| 225 |
@@@: WikiFormat |
| 226 |
@@lang: en |
| 227 |
@WikiFormat:NoConverter:Description: |
| 228 |
@@@: |
| 229 |
Converter to media type requested not found, so that your |
| 230 |
request cannot be completed. |
| 231 |
@@lang: en |
| 232 |
@WikiFormat:NoConverter:Title: |
| 233 |
@@@: Converter Not Found |
| 234 |
@@lang: en |
| 235 |
@WikiFormat:NoConverter:WebPageTitle: |
| 236 |
@@@: 406 Converter Not Found |
| 237 |
@@lang: en |
| 238 |
|
| 239 |
|