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