#?SuikaWikiConfig/2.0 Plugin: @Name: StyleSheet @Description: @@@: Stylesheet support @@lang:en @License: %%GPL%% @Author: @@Name: @@@@: Wakaba @@@lang:ja @@@script:Latn @@Mail[list]: w@suika.fam.cx @Date.RCS: $Date: 2004/02/08 08:44:13 $ @RequiredModule[list]: @RequiredPlugin[list]: Error HTML @Use: use Message::Util::Error; my $WIKIRESOURCE; PluginConst: @NS_XHTML1: http://www.w3.org/1999/xhtml @WIKIRESOURCE: {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} Format: @ModuleName: StyleSheet::CSS @Name: CSS @Type: text/css @Description: @@@: Cascading Style Sheets (CSS) @@lang: en @Use: use Message::Markup::XML::QName qw(NS_xml_URI); @Converter: @@Type: text/css @@Description: @@@: CSS -> CSS (no convertion) @@lang: en @@ToString: return $$source; ## BUG: Insecure specification MUST be removed @Converter: @@Type: text/html @@IsFragment: 1 @@Description: @@@: CSS with some decoration, marked-up in HTML @@lang: en @@Main: my $node = $opt->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'pre'); $node->set_attribute (class => 'text-css'); $node->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI); $node->append_text ($$source); return $node; ViewDefinition: @Mode: css @Condition: @@http-method[list]: GET HEAD POST @Description: @@@: CSS Style Sheet @@lang: en @template: @@http-status-code: 200 @@media-type: text/css @@use-media-type-charset: 1 @@expires: %%stylesheet%% @@body: %read (Type => {text/css}, return-type => {ToString}, when-no-converter => 406); FormattingRule: @Category[list]: view view-resource @Name: styles-wiki-html @Description: @@@: Stylesheet list as HTML (link element) @@lang: en @Paramater: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: WikiPage in which stylesheet list is defined @@@lang: en @Formatting: my $list = __FUNCPACK__->_get_stylelist_definition_page (page => $o->{wiki}->name ($p->{page} || $o->{wiki}->{config}->{page} ->{'StyleSheetList(text/html)'} || [qw!Wiki Style List text/html!]), o => $o, wiki => $o->{wiki}); return unless $list; my $parent = $p->{-parent}; my $ua_apply; my $dg = $o->{wiki}->{var}->{client}->{downgrade}; if ($dg->{stylesheet_non_standard}) { $ua_apply = $dg->{ua_netscape4} ? 'Netscape4' : $dg->{ua_winie60} ? 'WinIE6.0' : $dg->{ua_winie55} ? 'WinIE5.5' : $dg->{ua_winie50} ? 'WinIE5.0' : $dg->{ua_winie40} ? 'WinIE4.0' : $dg->{ua_winie30} ? 'WinIE3.0' : 1; } for my $set (@{$list->child_nodes}) { if ($set->local_name eq 'StyleSet') { my $type = { map {$_ => 1} map {ref $_ ? @$_ : [$_]} $set->get_attribute_value ('Apply', default => ['alternate']) }; next if $ua_apply and not $type->{$ua_apply}; my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet'; my $title = __FUNCPACK__->_get_styleset_title (StyleSet => $set, o => $o, type => $type); for my $sheet (@{$set->child_nodes}) { if ($sheet->local_name eq 'StyleSheet') { my $link = $parent->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'link'); $link->option (use_EmptyElemTag => 1); $link->set_attribute (rel => $rel); $link->set_attribute (title => $title) unless $type->{persistent}; my $media_type = $sheet->get_attribute_value ('Type', default => 'text/css'); ## TODO: parameter $link->set_attribute (type => $media_type); unless ($dg->{html_link_no_media}) { my $media_descriptor = $sheet->get_attribute_value ('Media'); $link->set_attribute (media => $media_descriptor || 'all'); } my $mode = 'css'; ## ISSUE: Make this media-type independent! $link->set_attribute (href => $o->{wiki}->uri_reference (page => $o->{wiki}->name ($sheet->get_attribute_value ('WikiPage', default => '')), mode => $mode, with_lm => 1, base => 1)); $parent->append_text ("\n"); } } } } FormattingRule: @Category[list]: view view-resource @Name: styles-wiki-xml @Description: @@@: Stylesheet list in xml-stylesheet processing instructions @@lang: en @Parameter: @@Name: downgrade-html @@Type: boolean @@Default: "0" @@Description: @@@@: HTML downgrade mode. PIs are not outputed if User-Agent does not support PIs (eg. Classic Mozilla). @@lang: en @Paramater: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: WikiPage in which stylesheet list is defined @@@lang: en @Formatting: __ATTRTEXT:%downgrade_html__; if ($p->{downgrade_html}) { return if $o->{wiki}->{var}->{client}->{downgrade}->{html_no_pi}; } my $list = __FUNCPACK__->_get_stylelist_definition_page (page => $o->{wiki}->name ($p->{page} || $o->{wiki}->{config}->{page} ->{'StyleSheetList(text/html)'} || [qw!Wiki Style List text/html!]), o => $o, wiki => $o->{wiki}); return unless $list; my $parent = $p->{-parent}; for my $set (@{$list->child_nodes}) { if ($set->local_name eq 'StyleSet') { my $type = {map {$_ => 1} @{ $set->get_attribute_value ('Apply', default => ['alternate']) }}; my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet'; my $title = __FUNCPACK__->_get_styleset_title (StyleSet => $set, o => $o, type => $type); for my $sheet (@{$set->child_nodes}) { if ($sheet->local_name eq 'StyleSheet') { my $link = $parent->append_new_node (type => '#pi', local_name => 'xml-stylesheet'); $link->set_attribute (alternate => $type->{preferred} ? 'no' : 'yes') unless $type->{persistent}; $link->set_attribute (title => $title) unless $type->{persistent}; my $media_type = $sheet->get_attribute_value ('Type', default => 'text/css'); ## TODO: parameter $link->set_attribute (type => $media_type); unless ($o->{wiki}->{var}->{client}->{downgrade} ->{html_link_no_media}) { my $media_descriptor = $sheet->get_attribute_value ('Media'); $link->set_attribute (media => $media_descriptor || 'all'); } my $mode = 'css'; ## ISSUE: Make this media-type independent! $link->set_attribute (href => $o->{wiki}->uri_reference (page => $o->{wiki}->name ($sheet->get_attribute_value ('WikiPage', default => '')), mode => $mode, with_lm => 1)); $parent->append_text ("\n"); } } } } FormattingRule: @Category[list]: view view-resource form-input @Name: select-user-preferred-style @Description: @@@: Select user preferred style @@lang: en @Paramater: @@Name: page @@Type: WikiName @@Default: (auto) @@Description: @@@@: WikiPage in which stylesheet list is defined @@@lang: en @Formatting: __ATTRTEXT:%page__; my $list = __FUNCPACK__->_get_stylelist_definition_page (page => $o->{wiki}->name ($p->{page} || $o->{wiki}->{config}->{page} ->{'StyleSheetList(text/html)'} || [qw!Wiki Style List text/html!]), o => $o, wiki => $o->{wiki}); return unless $list; my $form = $p->{-parent}->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'form'); my $id = SuikaWiki::Plugin->module_package ('WikiFormCore') ->control_id ($o, local_id => 'style-selector', require_local_id => 1); $form->set_attribute (id => $id->{global_id}); my $div = $form->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'div'); my $parent = $div->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'select'); $parent->set_attribute (id => $id->{global_id}.'-list'); my $default = $parent->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'option'); $default->set_attribute (value => 'no-style'); $default->append_text ($WIKIRESOURCE->get (name => 'Style:Default', o => $o, wiki => $o->{wiki})); my $selected = 0; for my $set (@{$list->child_nodes}) { if ($set->local_name eq 'StyleSet') { my $type = {map {$_ => 1} @{ $set->get_attribute_value ('Apply', default => ['alternate']) }}; next unless $type->{preferred} or $type->{alternate}; my $title = __FUNCPACK__->_get_styleset_title (StyleSet => $set, o => $o, type => $type); my $link = $parent->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'option'); $link->set_attribute (selected => 'selected'), $selected = 1 if $type->{preferred}; $link->set_attribute (value => $title); $link->append_text ($title); $parent->append_text ("\n"); } } $default->set_attribute (selected => 'selected') unless $selected; for ($div->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'input')) { $_->set_attribute (type => 'button'); $_->set_attribute (id => $id->{global_id}.'-save'); $_->set_attribute (value => $WIKIRESOURCE->get (name => 'Style:Save', o => $o, wiki => $o->{wiki})); $_->set_attribute (class => 'save'); $_->option (use_EmptyElemTag => 1); } for ($div->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'input')) { $_->set_attribute (type => 'reset'); $_->set_attribute (id => $id->{global_id}.'-reset'); $_->set_attribute (value => $WIKIRESOURCE->get (name => 'Style:Reset', o => $o, wiki => $o->{wiki})); $_->set_attribute (class => 'reset'); $_->option (use_EmptyElemTag => 1); } __ATTRTEXT:%expires__; my $cookie_path = '/'; ## ISSUE: Need some mechanism for ($div->append_new_node (type => '#element', namespace_uri => $NS_XHTML1, local_name => 'script')) { $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade} ->{media_type_no_app_js} ? 'text/javascript' : 'application/x-javascript'); $_->set_attribute (defer => 'defer'); ## Gecko assumes