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