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