/[pub]/suikawiki/script/misc/plugins/view/stylesheet.pm
Suika

Contents of /suikawiki/script/misc/plugins/view/stylesheet.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun May 16 23:05:50 2010 UTC (14 years, 11 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, HEAD
Branch point for: helowiki-2005
added latest .pm files

1 wakaba 1.1 use strict;
2     package SuikaWiki::Plugin::Registry;
3    
4    
5     our %Info;
6     $Info{q#StyleSheet#}->{Name} = q#StyleSheet#;
7     $Info{q#StyleSheet#}->{q#Version#} = q#2005.0315.0849#;
8     $Info{q#StyleSheet#}->{q#InterfaceVersion#} = q#2.9.1#;
9     $Info{q#StyleSheet#}->{q#mkpluginVersion#} = q#2.1.21#;
10     $Info{q#StyleSheet#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj#;
11     $Info{q#StyleSheet#}->{q#Date.RCS#} = q#$Date: 2004/12/05 12:57:37 $#;
12     $Info{q#StyleSheet#}->{RequiredPlugin} = [q#Error#, q#HTML#];
13     $Info{q#StyleSheet#}->{RequiredModule} = [q#URI#];
14     $Info{q#StyleSheet#}->{Description} = [[q#Stylesheet support#, q#en#, q##]];
15     $Info{q#StyleSheet#}->{License} = [[q#%%Perl%%#, q##, q##]];
16     $Info{q#StyleSheet#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#w@suika.fam.cx#]], [q##]]];
17     package SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj;
18    
19    
20     #line 1 "(WikiPlugin module source stylesheet.wp2, block Plugin/Use)"
21     use URI;
22     use Message::Util::Error;
23     my $WIKIRESOURCE;
24     #line 1 "(WikiPlugin module StyleSheet, chunk 1)"
25    
26     package SuikaWiki::Format::Definition::StyleSheet::CSS;
27    
28     our @ISA;
29     push @ISA, 'SuikaWiki::Format::Definition::template';
30     $SuikaWiki::Format::Definition::Class{q#MAGIC:CSS/\#\##} = 'SuikaWiki::Format::Definition::StyleSheet::CSS';
31     $SuikaWiki::Format::Definition::Class{q#IMT:text/css\#\##} = 'SuikaWiki::Format::Definition::StyleSheet::CSS';
32    
33     #line 1 "(WikiPlugin module source stylesheet.wp2, block Format[module-name()=SuikaWiki::Format::Definition::StyleSheet::CSS]/Use)"
34     use Message::Markup::XML::QName qw(NS_xml_URI);
35     #line 251 "(WikiPlugin module StyleSheet, chunk from ../../../bin/mkplugin2.pl)"
36     our $Converter;
37     sub convert ($$;%) {
38     my ($self, $source, %opt) = @_;
39     my $t = SuikaWiki::Format::Definition->serialize_media_type (%opt);
40     my $converter = $Converter->{$t->{_}};
41     return ($converter->{$opt{return_type} or 'Main'} or
42     CORE::die "Buggy implementation: $t->{_}/@{[$opt{return_type} or 'Main']} not defined")
43     ->($self, $source, \%opt)
44     if $converter;
45     local $Error::Depth = $Error::Depth + 1;
46     $self->SUPER::convert ($source, %opt);
47     }
48    
49     #line 1 "(WikiPlugin module StyleSheet, chunk 2)"
50     $Converter->{q#IMT:text/css\#\##} = {q#Type#, q#text/css#, q#serialized_type#, q#IMT:text/css\#\##, q#ToString#, sub {my ($self, $source, $opt) = @_;
51     #line 1 "(WikiPlugin module source stylesheet.wp2, block //Converter/ToString)"
52     return $$source;
53     #line 1 "(WikiPlugin module StyleSheet, chunk 3)"
54     }, q#Type_param#, {}};
55     $Converter->{q#IMT:text/html\#\#f#} = {q#Type#, q#text/html#, q#serialized_type#, q#IMT:text/html\#\#f#, q#Type_param#, {}, q#IsFragment#, q#1#, q#Main#, sub {my ($self, $source, $opt) = @_;
56     #line 1 "(WikiPlugin module source stylesheet.wp2, block //Converter/Main)"
57     my $node = $opt->{-parent}->append_new_node
58     (type => '#element',
59     namespace_uri => q#http://www.w3.org/1999/xhtml#,
60     local_name => 'pre');
61     $node->set_attribute (class => 'text-css');
62     $node->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI);
63     $node->append_text ($$source);
64     return $node;
65     #line 1 "(WikiPlugin module StyleSheet, chunk 4)"
66     }};
67     sub content_written {
68     my ($self, %opt) = @_;
69     #line 1 "(WikiPlugin module source stylesheet.wp2, block Format[module-name()=SuikaWiki::Format::Definition::StyleSheet::CSS]/content_written])"
70     if ($opt{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#use-static#}) {
71     $opt{wiki}->{db}->set (static__css => $opt{page} => ${$opt{new_content}});
72     }
73     #line 1 "(WikiPlugin module StyleSheet, chunk 5)"
74     }
75     sub content_removed {
76     my ($self, %opt) = @_;
77     #line 1 "(WikiPlugin module source stylesheet.wp2, block Format[module-name()=SuikaWiki::Format::Definition::StyleSheet::CSS]/content_removed])"
78     if ($opt{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#use-static#}) {
79     $opt{wiki}->{db}->delete (static__css => $opt{page});
80     }
81     #line 1 "(WikiPlugin module StyleSheet, chunk 6)"
82     }
83     sub content_type_changed_from {
84     my ($self, %opt) = @_;
85     #line 1 "(WikiPlugin module source stylesheet.wp2, block Format[module-name()=SuikaWiki::Format::Definition::StyleSheet::CSS]/content_type_changed_from])"
86     if ($opt{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#use-static#}) {
87     $opt{wiki}->{db}->delete (static__css => $opt{page});
88     }
89     #line 1 "(WikiPlugin module StyleSheet, chunk 7)"
90     }
91     sub prop ($$;%) { my ($self, $name, %opt) = @_;if ($name eq q#http://suika.fam.cx/~wakaba/-temp/2004/7/25/sw-edit\#new-mode--edit#) { return q#edit# } elsif ($name eq q#http://suika.fam.cx/~wakaba/-temp/2004/7/25/sw-edit\#new-mode--adminedit#) { return q#adminedit# } else {$self->SUPER::prop ($name, %opt);}
92     }
93    
94     push @SuikaWiki::View::Implementation::CommonViewDefs, {
95     condition => {q#mode#, q#css#, q#http_method#, [q#GET#, q#HEAD#, q#POST#]},
96     object_class => q#SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::css105021508491663oY#,
97     };
98     package SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::css105021508491663oY;
99    
100    
101     our @ISA = q#SuikaWiki::View::template#;
102    
103     sub main ($$$) {
104     my ($self, $opt, $opt2) = @_;
105     require SuikaWiki::Output::HTTP;
106     $opt2->{output} = SuikaWiki::Output::HTTP->new
107     (wiki => $self->{view}->{wiki},
108     view => $self->{view}, viewobj => $self);
109     for (@{$self->{view}->{wiki}->{var}->{client}->{used_for_negotiate}},
110     'Accept-Language') {
111     $opt2->{output}->add_negotiate_header_field ($_);
112     }
113    
114     $opt2->{template} = q#%read (Type => {text/css}, return-type => {ToString},
115     when-no-converter => 406);#;
116     $opt2->{o} = bless {
117     ## SuikaWiki 3 WikiPlugin interface
118     wiki => $self->{view}->{wiki},
119     plugin => $self->{view}->{wiki}->{plugin},
120     var => {},
121     }, 'SuikaWiki::Plugin';
122     $opt2->{output}->{status_code} = 200;
123    
124     $opt2->{output}->{entity}->{media_type} = q#text/css#;
125    
126     $opt2->{output}->{entity}->{charset} = $self->{view}->{wiki}->{config}->{charset}->{output};
127     $opt2->{output}->set_expires (%{$self->{view}->{wiki}->{config}->{entity}->{expires}->{q#stylesheet#}});
128     $opt2->{output}->{entity}->{body_is_octet_stream} = 0;
129    
130     $self->{view}->{wiki}->init_db;
131     $self->main_pre ($opt, $opt2);
132    
133    
134     use Message::Util::Error;
135     try {
136     $opt2->{output}->{entity}->{body}
137     =
138     (SuikaWiki::Plugin->formatter ('view')
139     ->replace ($opt2->{template}, param => $opt2->{o}));
140     } $self->{view}->{wiki}->{config}->{catch}->{ formatter_view };
141     $opt2->{output}->output (output => 'http-cgi');
142    
143     $self->main_post ($opt, $opt2);
144     }
145    
146     package SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj;
147    
148     {my $def = {q#Parameter#, {}, q#Description#, [[q#Stylesheet list as HTML (link element)#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
149    
150     #line 1 "(WikiPlugin module source stylesheet.wp2, block FormattingRule[name()='[q#view#, q#view-resource#]/styles_wiki_html']/Formatting)"
151     my $list = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_stylelist_definition_page
152     (page => $o->{wiki}->name
153     ($p->{page} ||
154     $o->{wiki}->{config}->{page}
155     ->{'StyleSheetList(text/html)'} ||
156     [qw!Wiki Style List text/html!]),
157     o => $o, wiki => $o->{wiki});
158     return unless $list;
159     my $parent = $p->{-parent};
160     my $ua_apply;
161     my $dg = $o->{wiki}->{var}->{client}->{downgrade};
162     if ($dg->{stylesheet_non_standard}) {
163     $ua_apply = $dg->{ua_netscape4} ? 'Netscape4'
164     : $dg->{ua_winie60} ? 'WinIE6.0'
165     : $dg->{ua_winie55} ? 'WinIE5.5'
166     : $dg->{ua_winie50} ? 'WinIE5.0'
167     : $dg->{ua_winie40} ? 'WinIE4.0'
168     : $dg->{ua_winie30} ? 'WinIE3.0'
169     : 1;
170     }
171     my $mkuri = $o->{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#wikiname-to-uri#} ||
172     \&SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::generate_uri;
173     for my $set (@{$list->child_nodes}) {
174     if ($set->local_name eq 'StyleSet') {
175     my $apply = $set->get_attribute_value ('Apply',
176     default => ['alternate'],
177     as_array => 1);
178     my $type = {
179     map {$_ => 1}
180     @$apply
181     };
182     next if $ua_apply and not $type->{$ua_apply};
183     my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet';
184     my $title = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_styleset_title
185     (StyleSet => $set, o => $o,
186     type => $type);
187     for my $sheet (@{$set->child_nodes}) {
188     if ($sheet->local_name eq 'StyleSheet') {
189     my $stype = {
190     map {$_ => 1}
191     @{$sheet->get_attribute_value ('Apply', default => $apply,
192     as_array => 1)}
193     };
194     next if $ua_apply and not $stype->{$ua_apply};
195     next if not $ua_apply and (not $stype->{alternate} and
196     not $stype->{preferred} and
197     not $stype->{persistent});
198     my $link = $parent->append_new_node
199     (type => '#element',
200     namespace_uri => q#http://www.w3.org/1999/xhtml#,
201     local_name => 'link');
202     $link->option (use_EmptyElemTag => 1);
203     $link->set_attribute (rel => $rel);
204     $link->set_attribute (title => $title) unless $type->{persistent};
205     my $media_type = $sheet->get_attribute_value
206     ('Type', default => 'text/css');
207     $link->set_attribute (type => $media_type);
208     unless ($dg->{html_link_no_media}) {
209     my $media_descriptor = $sheet->get_attribute_value ('Media');
210     $link->set_attribute (media => $media_descriptor || 'all');
211     }
212     my $uri = $mkuri->(undef, o => $o, wiki => $o->{wiki},
213     wikiname => $o->{wiki}->name
214     ($sheet->get_attribute_value
215     ('WikiPage', default => '')),
216     mode => 'css'); ## ISSUE: Make this media-type independent!
217     $link->set_attribute (href => $uri);
218     $parent->append_text ("\n");
219     }
220     }
221     }
222     }}}
223     #line 1 "(WikiPlugin module StyleSheet, chunk 8)"
224     ;
225     $SuikaWiki::Plugin::Rule{view}->{styles_wiki_html} = $def;
226     $SuikaWiki::Plugin::Rule{view_resource}->{styles_wiki_html} = $def;
227     };
228    
229     {my $def = {q#Parameter#, {q#downgrade_html#, {q#Type#, q#boolean#, q#Default#, q#"0"#, q#Description#, [[q#HTML downgrade mode. PIs are not outputed if User-Agent does not
230     support PIs (eg. Classic Mozilla).#, q##, q##]]}}, q#Description#, [[q#Stylesheet list in xml-stylesheet processing instructions#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
231    
232     #line 1 "(WikiPlugin module source stylesheet.wp2, block FormattingRule[name()='[q#view#, q#view-resource#]/styles_wiki_xml']/Formatting)"
233     $p->{q#downgrade_html#} = do { my $r = $f->parse_attr ($p=>q#downgrade_html#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
234     if ($p->{downgrade_html}) {
235     return if $o->{wiki}->{var}->{client}->{downgrade}->{html_no_pi};
236     }
237     my $list = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_stylelist_definition_page
238     (page => $o->{wiki}->name
239     ($p->{page} ||
240     $o->{wiki}->{config}->{page}
241     ->{'StyleSheetList(text/html)'} ||
242     [qw!Wiki Style List text/html!]),
243     o => $o, wiki => $o->{wiki});
244     return unless $list;
245     my $parent = $p->{-parent};
246     my $mkuri = $o->{wiki}->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#wikiname-to-uri#} ||
247     \&SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::generate_uri;
248     for my $set (@{$list->child_nodes}) {
249     if ($set->local_name eq 'StyleSet') {
250     my $apply = $set->get_attribute_value
251     ('Apply', default => ['alternate'],
252     as_array => 1);
253     my $type = {map {$_ => 1} @$apply};
254     my $rel = $type->{alternate} ? 'alternate stylesheet' : 'stylesheet';
255     my $title = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_styleset_title
256     (StyleSet => $set, o => $o,
257     type => $type);
258     for my $sheet (@{$set->child_nodes}) {
259     if ($sheet->local_name eq 'StyleSheet') {
260     my $stype = {
261     map {$_ => 1}
262     @{$sheet->get_attribute_value ('Apply', default => $apply,
263     as_array => 1)}
264     };
265     next if (not $stype->{alternate} and
266     not $stype->{preferred} and
267     not $stype->{persistent});
268     my $link = $parent->append_new_node
269     (type => '#pi',
270     local_name => 'xml-stylesheet');
271     $link->set_attribute (alternate => $type->{preferred} ? 'no'
272     : 'yes')
273     unless $type->{persistent};
274     $link->set_attribute (title => $title) unless $type->{persistent};
275     my $media_type = $sheet->get_attribute_value
276     ('Type', default => 'text/css');
277     $link->set_attribute (type => $media_type);
278     unless ($o->{wiki}->{var}->{client}->{downgrade}
279     ->{html_link_no_media}) {
280     my $media_descriptor = $sheet->get_attribute_value ('Media');
281     $link->set_attribute (media => $media_descriptor || 'all');
282     }
283     my $uri = $mkuri->(undef, o => $o, wiki => $o->{wiki},
284     wikiname => $o->{wiki}->name
285     ($sheet->get_attribute_value
286     ('WikiPage', default => '')),
287     lm => time, ## TODO: Should be last-modified
288     mode => 'css'); ## ISSUE: Make this media-type independent!
289     $link->set_attribute (href => $uri);
290     $parent->append_text ("\n");
291     }
292     }
293     }
294     }}}
295     #line 1 "(WikiPlugin module StyleSheet, chunk 10)"
296     ;
297     $SuikaWiki::Plugin::Rule{view}->{styles_wiki_xml} = $def;
298     $SuikaWiki::Plugin::Rule{view_resource}->{styles_wiki_xml} = $def;
299     };
300    
301    
302     sub generate_uri {
303    
304     #line 1 "(WikiPlugin module source stylesheet.wp2, block Function[Name='generate_uri']/Main)"
305     my (undef, %opt) = @_;
306     return $opt{wiki}->uri_reference
307     (page => $opt{wikiname},
308     mode => $opt{mode},
309     with_lm => 1, base => 1);
310     }
311    
312     #line 1 "(WikiPlugin module StyleSheet, chunk 12)"
313    
314    
315     push @SuikaWiki::View::Implementation::CommonViewDefs, {
316     condition => {q#mode#, q#ss__no_static#, q#http_method#, [q#GET#, q#HEAD#, q#POST#]},
317     object_class => q#SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::ss__no_static1050215084916GAk9#,
318     };
319     package SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj::ss__no_static1050215084916GAk9;
320    
321    
322     our @ISA = q#SuikaWiki::View::template#;
323     sub main ($$) {
324     my ($self, $opt, $opt2) = @_;
325    
326     #line 1 "(WikiPlugin module source stylesheet.wp2, block ViewDefinition[Mode='ss__no_static']/method[Name='main'])"
327     require SuikaWiki::Output::HTTP;
328     my $wiki = $self->{view}->{wiki};
329     $wiki->init_db;
330     GENSTATIC: {
331     last GENSTATIC unless ref $wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#uri-to-wikiname#} and
332     $wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#use-static#} and
333     $wiki->{db} and $wiki->{input};
334     my $uri = $wiki->{input}->meta_variable ('REDIRECT_URL');
335     last GENSTATIC unless $uri;
336     my $wn = $wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#uri-to-wikiname#}
337     ->(undef, wiki => $wiki,
338     uri => URI->new ($uri));
339     my $prop = $wiki->{db}->get (content_prop => $wn);
340     my $mt = $prop->get_attribute_value (q#http://suika.fam.cx/~wakaba/-temp/2004/04/24/mt\#media-type#,
341     default => '--');
342     last GENSTATIC unless $mt eq 'IMT:text/css##';
343     $wiki->{db}->set (static__css => $wn =>
344     $wiki->{db}->get (content => $wn));
345     $uri = $wiki->{config}->{q#http://suika.fam.cx/~wakaba/archive/2004/05/sw-stylesheet\#wikiname-to-uri#}
346     ->(undef, wiki => $wiki,
347     wikiname => $wn);
348     $uri = $uri->abs ($wiki->uri_reference);
349     $uri->query (time);
350     my $output = new SuikaWiki::Output::HTTP (wiki => $wiki);
351     $output->set_redirect (uri => $uri, status_code => 303,
352     status_phrase => 'Created');
353     $output->output (output => 'http-cgi');
354     return;
355     }
356     my $output = new SuikaWiki::Output::HTTP (wiki => $wiki);
357     $output->{status_code} = 404;
358     $output->{entity}->{media_type} = 'text/plain';
359     $output->{entity}->{body} = '404';
360     $output->output (output => 'http-cgi');}
361    
362     #line 1 "(WikiPlugin module StyleSheet, chunk 13)"
363    
364     package SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj;
365    
366     {my $def = {q#Parameter#, {}, q#Description#, [[q#Select user preferred style#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
367    
368     #line 1 "(WikiPlugin module source stylesheet.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/select_user_preferred_style']/Formatting)"
369     $p->{q#page#} = do { my $r = $f->parse_attr ($p=>q#page#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
370     my $list = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_stylelist_definition_page
371     (page => $o->{wiki}->name
372     ($p->{page} ||
373     $o->{wiki}->{config}->{page}
374     ->{'StyleSheetList(text/html)'} ||
375     [qw!Wiki Style List text/html!]),
376     o => $o, wiki => $o->{wiki});
377     return unless $list;
378     my $form = $p->{-parent}->append_new_node
379     (type => '#element',
380     namespace_uri => q#http://www.w3.org/1999/xhtml#,
381     local_name => 'form');
382     my $id = SuikaWiki::Plugin->module_package ('WikiFormCore')
383     ->control_id ($o,
384     local_id => 'style-selector',
385     require_local_id => 1);
386     $form->set_attribute (id => $id->{global_id});
387     my $div = $form->append_new_node
388     (type => '#element',
389     namespace_uri => q#http://www.w3.org/1999/xhtml#,
390     local_name => 'div');
391     my $parent = $div->append_new_node
392     (type => '#element',
393     namespace_uri => q#http://www.w3.org/1999/xhtml#,
394     local_name => 'select');
395     $parent->set_attribute (id => $id->{global_id}.'-list');
396     my $default = $parent->append_new_node
397     (type => '#element',
398     namespace_uri => q#http://www.w3.org/1999/xhtml#,
399     local_name => 'option');
400     $default->set_attribute (value => 'no-style');
401     $default->append_text (($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get (name => 'Style:Default',
402     o => $o, wiki => $o->{wiki}));
403     my $selected = 0;
404     for my $set (@{$list->child_nodes}) {
405     if ($set->local_name eq 'StyleSet') {
406     my $type = {map {$_ => 1}
407     @{
408     $set->get_attribute_value ('Apply', default => ['alternate'])
409     }};
410     next unless $type->{preferred} or $type->{alternate};
411     my $title = SuikaWiki::Plugin::plugin::StyleSheet1050215084916LDrj->_get_styleset_title
412     (StyleSet => $set, o => $o,
413     type => $type);
414     my $link = $parent->append_new_node
415     (type => '#element',
416     namespace_uri => q#http://www.w3.org/1999/xhtml#,
417     local_name => 'option');
418     $link->set_attribute (selected => 'selected'), $selected = 1
419     if $type->{preferred};
420     $link->set_attribute (value => $title);
421     $link->append_text ($title);
422     $parent->append_text ("\n");
423     }
424     }
425     $default->set_attribute (selected => 'selected') unless $selected;
426     for ($div->append_new_node (type => '#element',
427     namespace_uri => q#http://www.w3.org/1999/xhtml#,
428     local_name => 'input')) {
429     $_->set_attribute (type => 'button');
430     $_->set_attribute (id => $id->{global_id}.'-save');
431     $_->set_attribute (value => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
432     (name => 'Style:Save',
433     o => $o, wiki => $o->{wiki}));
434     $_->set_attribute (class => 'save');
435     $_->option (use_EmptyElemTag => 1);
436     }
437     for ($div->append_new_node (type => '#element',
438     namespace_uri => q#http://www.w3.org/1999/xhtml#,
439     local_name => 'input')) {
440     $_->set_attribute (type => 'reset');
441     $_->set_attribute (id => $id->{global_id}.'-reset');
442     $_->set_attribute (value => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
443     (name => 'Style:Reset',
444     o => $o, wiki => $o->{wiki}));
445     $_->set_attribute (class => 'reset');
446     $_->option (use_EmptyElemTag => 1);
447     }
448     return if $o->{wiki}->{var}->{client}->{downgrade}->{js_no_regex};
449     $p->{q#expires#} = do { my $r = $f->parse_attr ($p=>q#expires#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
450     my $cookie_path = $o->{wiki}->uri_reference->path;
451     for ($div->append_new_node (type => '#element',
452     namespace_uri => q#http://www.w3.org/1999/xhtml#,
453     local_name => 'script')) {
454     $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
455     ->{media_type_no_app_js}
456     ? 'text/javascript'
457     : 'application/x-javascript');
458     $_->set_attribute (defer => 'defer');
459     $_->append_new_node (type => '#xml', value => <<EOH);
460     function getCookieValue (name) {
461     var c = document.cookie.split(';');
462     for (var i = 0; c.length > i; i++) {
463     var v = c[i].split('=');
464     if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
465     return decodeURIComponent (v[1].replace(/^\\s+/,'')
466     .replace(/\\s+\$/,''));
467     }
468     }
469     return '';
470     }
471     var selectList = document.getElementById('$id->{global_id}-list');
472     selectList.value = getCookieValue('Selected');
473     selectList.onchange = function () {
474     var selectList = document.getElementById('$id->{global_id}-list');
475     for (var i = 0; document.styleSheets.length > i; i++) {
476     var s = document.styleSheets.item(i);
477     if (s.href != document.URL) {
478     if (s.title)
479     s.disabled = (s.title != selectList.value);
480     }
481     }
482     }
483     document.getElementById('$id->{global_id}-save').onclick = function () {
484     var selectList = document.getElementById('$id->{global_id}-list');
485     var expires = new Date();
486     expires.setTime (expires.getTime()
487     + 1000*3600*24*@{[$p->{expires}||365]});
488     document.cookie = 'Selected=' + encodeURIComponent(selectList.value)
489     + ';path=$cookie_path;expires='+expires.toGMTString();
490     }
491     document.getElementById('$id->{global_id}-reset').onclick = function () {
492     var expires = new Date();
493     expires.setTime (expires.getTime() - 3600);
494     document.cookie = 'Selected=;path=$cookie_path;expires='
495     + expires.toGMTString();
496     }
497     EOH
498     }}}
499     #line 1 "(WikiPlugin module StyleSheet, chunk 14)"
500     ;
501     $SuikaWiki::Plugin::Rule{view}->{select_user_preferred_style} = $def;
502     $SuikaWiki::Plugin::Rule{view_resource}->{select_user_preferred_style} = $def;
503     $SuikaWiki::Plugin::Rule{form_input}->{select_user_preferred_style} = $def;
504     };
505    
506     {my $def = {q#Parameter#, {}, q#Description#, [[q#Applying user preferred style#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
507    
508     #line 1 "(WikiPlugin module source stylesheet.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/apply_user_preferred_style']/Formatting)"
509     return if $o->{wiki}->{var}->{client}->{downgrade}->{js_no_regex};
510     for ($p->{-parent}->append_new_node
511     (type => '#element',
512     namespace_uri => q#http://www.w3.org/1999/xhtml#,
513     local_name => 'script')) {
514     $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
515     ->{media_type_no_app_js}
516     ? 'text/javascript'
517     : 'application/x-javascript');
518     $_->set_attribute (defer => 'defer');
519     $_->append_new_node (type => '#xml', value => <<EOH);
520     function getCookieValue (name) {
521     var c = document.cookie.split(';');
522     for (var i = 0; c.length > i; i++) {
523     var v = c[i].split('=');
524     if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
525     return decodeURIComponent (v[1].replace(/^\\s+/,'')
526     .replace(/\\s+\$/,''));
527     }
528     }
529     return '';
530     }
531     var styleName = getCookieValue('Selected');
532     if (styleName) {
533     for (var i = 0; document.styleSheets.length > i; i++) {
534     var s = document.styleSheets.item(i);
535     if (s.href != document.URL) {
536     if (s.title)
537     s.disabled = (s.title != styleName) ? true : false;
538     }
539     }
540     }
541     EOH
542     }}}
543     #line 1 "(WikiPlugin module StyleSheet, chunk 16)"
544     ;
545     $SuikaWiki::Plugin::Rule{view}->{apply_user_preferred_style} = $def;
546     $SuikaWiki::Plugin::Rule{view_resource}->{apply_user_preferred_style} = $def;
547     $SuikaWiki::Plugin::Rule{form_input}->{apply_user_preferred_style} = $def;
548     };
549    
550    
551     sub _get_stylelist_definition_page {
552    
553     #line 1 "(WikiPlugin module source stylesheet.wp2, block Function[Name='_get_stylelist_definition_page']/Main)"
554     my (undef, %opt) = @_;
555     my $content;
556     my $content_prop;
557     if ($opt{wiki}->{db}) {
558     try {
559     $content = $opt{wiki}->{db}->get (content => $opt{page});
560     $content_prop = $opt{wiki}->{db}->get (content_prop => $opt{page});
561     } catch SuikaWiki::DB::Util::Error with {
562     my $err = shift;
563     $err->throw if $err->{-type} eq 'ERROR_REPORTED';
564     $content = undef;
565     };
566     }
567     my $format = SuikaWiki::Plugin->module_package ('WikiFormat')
568     ->handler (\$content,
569     content_prop => $content_prop,
570     o => $opt{o},
571     wiki => $opt{o}->{wiki});
572     my $cfg;
573     try {
574     $cfg = $format->convert (\$content,
575     Type => 'application/x.suikawiki.config',
576     Type_param => {version => '2.0'},
577     o => $opt{o}, page => $opt{page});
578     } catch SuikaWiki::Format::Definition::error with {
579     my $err = shift;
580     if ($err->{-type} eq 'CONVERTER_NOT_FOUND') {
581     SuikaWiki::Plugin->module_package ('Error')
582     ->report_error_simple
583     ($opt{o}->{wiki},
584     'Condition' => $err->stringify);
585     } else {
586     $err->throw;
587     }
588     };
589     $cfg;
590     }
591    
592     #line 1 "(WikiPlugin module StyleSheet, chunk 18)"
593    
594    
595    
596     sub _get_styleset_title {
597    
598     #line 1 "(WikiPlugin module source stylesheet.wp2, block Function[Name='_get_styleset_title']/Main)"
599     my (undef, %opt) = @_;
600     my $title;
601     if (not $opt{type}->{persistent}) {
602     $title = $opt{StyleSet}->get_attribute_value
603     ('DisplayName', default => '');
604     if (length $title) {
605     try {
606     $title = SuikaWiki::Plugin->formatter ('view_resource')
607     ->replace ($title,
608     param => $opt{o})
609     ->inner_text;
610     } catch Message::Util::Formatter::error with {
611     my $err = shift;
612     if ($err->{-object}->{-category_name} eq 'view_resource') {
613     my $wiki = $err->{option}->{param}->{wiki};
614     SuikaWiki::Plugin->module_package ('Error')
615     ->reporting_formatting_template_error
616     ($err, $wiki,
617     template => $title);
618     } else {
619     $err->throw;
620     }
621     $title ||= $opt{StyleSet}->get_attribute_value
622     ('Name', default => '');
623     };
624     } else {
625     $title = $opt{StyleSet}->get_attribute_value ('Name', default => '');
626     }
627     }
628     return $title;
629     }
630    
631     #line 1 "(WikiPlugin module StyleSheet, chunk 19)"
632    
633    
634     {my $def = {q#Parameter#, {}, q#Description#, [[q#Select user preferred mode#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_;
635    
636     #line 1 "(WikiPlugin module source stylesheet.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/select_user_preferred_mode']/Formatting)"
637     my $list = [grep /^[0-9A-Za-z_]/, keys %{$o->{wiki}->{view}->{definition}}];
638     my $form = $p->{-parent}->append_new_node
639     (type => '#element',
640     namespace_uri => q#http://www.w3.org/1999/xhtml#,
641     local_name => 'form');
642     my $id = SuikaWiki::Plugin->module_package ('WikiFormCore')
643     ->control_id ($o,
644     local_id => 'spss--mode-selector',
645     require_local_id => 1);
646     $form->set_attribute (id => $id->{global_id});
647     my $div = $form->append_new_node
648     (type => '#element',
649     namespace_uri => q#http://www.w3.org/1999/xhtml#,
650     local_name => 'div');
651     my $parent = $div->append_new_node
652     (type => '#element',
653     namespace_uri => q#http://www.w3.org/1999/xhtml#,
654     local_name => 'select');
655     $parent->set_attribute (id => $id->{global_id}.'-list');
656     my $default = $parent->append_new_node
657     (type => '#element',
658     namespace_uri => q#http://www.w3.org/1999/xhtml#,
659     local_name => 'option');
660     $default->set_attribute (value => 'default');
661     $default->append_text (($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get (name => 'Mode:Default',
662     o => $o, wiki => $o->{wiki}));
663     $default->set_attribute (selected => 'selected');
664     for my $set (@$list) {
665     my $title = ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get (name => 'Mode:'.$set,
666     o => $o, wiki => $o->{wiki});
667     my $link = $parent->append_new_node
668     (type => '#element',
669     namespace_uri => q#http://www.w3.org/1999/xhtml#,
670     local_name => 'option');
671     $link->set_attribute (value => $set);
672     $link->append_text ($title);
673     $parent->append_text ("\n");
674     }
675     for ($div->append_new_node (type => '#element',
676     namespace_uri => q#http://www.w3.org/1999/xhtml#,
677     local_name => 'input')) {
678     $_->set_attribute (type => 'button');
679     $_->set_attribute (id => $id->{global_id}.'-save');
680     $_->set_attribute (value => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
681     (name => 'Mode:Save',
682     o => $o, wiki => $o->{wiki}));
683     $_->set_attribute (class => 'save');
684     $_->option (use_EmptyElemTag => 1);
685     }
686     for ($div->append_new_node (type => '#element',
687     namespace_uri => q#http://www.w3.org/1999/xhtml#,
688     local_name => 'input')) {
689     $_->set_attribute (type => 'reset');
690     $_->set_attribute (id => $id->{global_id}.'-reset');
691     $_->set_attribute (value => ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get
692     (name => 'Mode:Reset',
693     o => $o, wiki => $o->{wiki}));
694     $_->set_attribute (class => 'reset');
695     $_->option (use_EmptyElemTag => 1);
696     }
697     return if $o->{wiki}->{var}->{client}->{downgrade}->{js_no_regex};
698     $p->{q#expires#} = do { my $r = $f->parse_attr ($p=>q#expires#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r};
699     my $cookie_path = $o->{wiki}->uri_reference->path;
700     for ($div->append_new_node (type => '#element',
701     namespace_uri => q#http://www.w3.org/1999/xhtml#,
702     local_name => 'script')) {
703     $_->set_attribute (type => $o->{wiki}->{var}->{client}->{downgrade}
704     ->{media_type_no_app_js}
705     ? 'text/javascript'
706     : 'application/x-javascript');
707     $_->set_attribute (defer => 'defer');
708     $_->append_new_node (type => '#xml', value => <<EOH);
709     function getCookieValue (name) {
710     var c = document.cookie.split(';');
711     for (var i = 0; c.length > i; i++) {
712     var v = c[i].split('=');
713     if (v[0].replace(/^\\s+/,'').replace(/\\s+\$/,'') == name) {
714     return decodeURIComponent (v[1].replace(/^\\s+/,'')
715     .replace(/\\s+\$/,''));
716     }
717     }
718     return '';
719     }
720     document.getElementById ('$id->{global_id}-list').value
721     = getCookieValue('SelectedMode');
722     document.getElementById ('$id->{global_id}-save').onclick = function () {
723     var expires = new Date ();
724     expires.setTime (expires.getTime ()
725     + 1000*3600*24*@{[$p->{expires}||365]});
726     document.cookie = 'SelectedMode='
727     + encodeURIComponent
728     (document.getElementById('$id->{global_id}-list')
729     .value)
730     + ';path=$cookie_path;expires='
731     + expires.toGMTString ();
732     }
733     document.getElementById('$id->{global_id}-reset').onclick = function () {
734     var expires = new Date();
735     expires.setTime (expires.getTime() - 3600);
736     document.cookie = 'SelectedMode=;path=$cookie_path;expires='
737     + expires.toGMTString();
738     }
739     EOH
740     }}}
741     #line 1 "(WikiPlugin module StyleSheet, chunk 20)"
742     ;
743     $SuikaWiki::Plugin::Rule{view}->{select_user_preferred_mode} = $def;
744     $SuikaWiki::Plugin::Rule{view_resource}->{select_user_preferred_mode} = $def;
745     $SuikaWiki::Plugin::Rule{form_input}->{select_user_preferred_mode} = $def;
746     };
747    
748     push @{$SuikaWiki::View::Implementation::TemplateFragment{q#ht__stylesheets_html#}}, {
749     Main => q#%styles-wiki-html;#,
750     Order => 0,
751     Description => [[q#Default stylesheets links#, q#en#, q##]],
752     };
753    
754     push @{$SuikaWiki::View::Implementation::TemplateFragment{q#ht__pre_element_content#}}, {
755     Main => q#%styles-wiki-xml (downgrade-html);#,
756     Order => 0,
757     Description => [[q#Default stylesheets links (as xml-stylesheet PIs)#, q#en#, q##]],
758     };
759    
760     push @{$SuikaWiki::View::Implementation::TemplateFragment{q#ws__footer#}}, {
761     Main => q#%apply-user-preferred-style;#,
762     Order => 100000,
763     Description => [[q#Apply user selected stylesheets#, q#en#, q##]],
764     };
765    
766     package SuikaWiki::Plugin::Resource;
767    
768     our $BaseResource;
769     $BaseResource->{q#en#}->{q##}->{q#Mode:css#} = q#Cascading Style Sheet output#;
770     $BaseResource->{q#en#}->{q##}->{q#Mode:Default#} = q#Default#;
771     $BaseResource->{q#en#}->{q##}->{q#Mode:Reset#} = q#Reset default mode selection#;
772     $BaseResource->{q#en#}->{q##}->{q#Mode:Save#} = q#Save default mode selection#;
773     $BaseResource->{q#und#}->{q##}->{q#Style:Default#} = q#Basic Page Style#;
774     $BaseResource->{q#en#}->{q##}->{q#Style:Reset#} = q#Reset style selection#;
775     $BaseResource->{q#en#}->{q##}->{q#Style:Save#} = q#Save style selection#;
776     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Description:IMT:text/css\#\##} = q#CSS (Cascading Style Sheets)#;
777     $BaseResource->{q#en#}->{q##}->{q#WikiFormat:MediaType:Label:IMT:text/css\#\##} = q#CSS#;
778     package SuikaWiki::Plugin::Registry;
779    
780     $Info{q#StyleSheet#}->{provide} = {q#rule#, {q#form_input#, [q#select_user_preferred_style#, q#apply_user_preferred_style#, q#select_user_preferred_mode#], q#view#, [q#styles_wiki_html#, q#styles_wiki_xml#, q#select_user_preferred_style#, q#apply_user_preferred_style#, q#select_user_preferred_mode#], q#view_resource#, [q#styles_wiki_html#, q#styles_wiki_xml#, q#select_user_preferred_style#, q#apply_user_preferred_style#, q#select_user_preferred_mode#]}, q#viewfragment#, [{q#Name#, q#ht__stylesheets_html#}, {q#Name#, q#ht__pre_element_content#}, {q#Name#, q#ws__footer#}], q#viewdef#, [{q#Description#, [q#CSS Style Sheet#, q#en#, q##], q#Name#, q#css#}, {q#Description#, [q#Generate static version#, q#en#, q##], q#Name#, q#ss__no_static#}]};
781    
782     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24