| 1 |
wakaba |
1.1 |
Name: |
| 2 |
|
|
Image |
| 3 |
|
|
FullName: |
| 4 |
|
|
SuikaWikiImage |
| 5 |
|
|
URI: |
| 6 |
|
|
IW:SuikaWiki:WikiAdmin |
| 7 |
wakaba |
1.2 |
Require: |
| 8 |
|
|
SuikaWiki::Plugin::SuikaWiki09 main SuikaWiki::Plugin::WikiPlugin |
| 9 |
wakaba |
1.1 |
|
| 10 |
|
|
{ |
| 11 |
|
|
Name: |
| 12 |
|
|
wikiformat/SuikaWikiImage/0.9-to-HTML |
| 13 |
|
|
FullName: |
| 14 |
|
|
SuikaWikiImage/0.9 document format -> HTML |
| 15 |
|
|
URI: |
| 16 |
|
|
IW:SuikaWiki:SuikaWiki |
| 17 |
|
|
Format: |
| 18 |
|
|
my $c = $o->{content}; |
| 19 |
|
|
$c =~ s(\x0D?\x0A__IMAGE__\x0D?\x0A.+$){}s; |
| 20 |
|
|
my $embed = '[[#embed:IMG:'.$o->{page}.']]'; |
| 21 |
|
|
unless (index ($c, $embed) > -1) { |
| 22 |
|
|
$c = $embed . "\n" . $c; |
| 23 |
|
|
} |
| 24 |
|
|
if ($c !~ /\[\[\#comment/ && $o->{p}->{comment} && $o->{magic} !~ /obsoleted="yes"/ && !$main::database->meta (IsFrozen => $o->{page})) { |
| 25 |
|
|
$c .= qq(\n[[#comment]]); |
| 26 |
|
|
} |
| 27 |
|
|
$r = SuikaWiki::Plugin::SuikaWiki09::text_to_html ($c, %$o); |
| 28 |
|
|
} |
| 29 |
|
|
{ |
| 30 |
|
|
Name: |
| 31 |
|
|
wikiformat/SuikaWikiImage/0.9-to-image-png |
| 32 |
|
|
FullName: |
| 33 |
|
|
SuikaWikiImage/0.9 document format -> PNG image |
| 34 |
|
|
URI: |
| 35 |
|
|
IW:SuikaWiki:SuikaWiki |
| 36 |
|
|
Format: |
| 37 |
|
|
if ($o->{content} =~ /\x0D?\x0A__IMAGE__\x0D?\x0A(.+)$/s) { |
| 38 |
|
|
require MIME::Base64; |
| 39 |
|
|
$r = MIME::Base64::decode ($1); |
| 40 |
|
|
if ($o->{magic} =~ m#image-type="(image/[0-9a-z_.+-]+)"#) { |
| 41 |
|
|
my $type = $1; |
| 42 |
|
|
$r = convert_image_type ($o, $r, $Type{$type} => $Type{'image/png'}) |
| 43 |
|
|
if $type ne 'image/png' && ref $Type{$type}; |
| 44 |
|
|
} |
| 45 |
|
|
} |
| 46 |
|
|
} |
| 47 |
|
|
{ |
| 48 |
|
|
Name: |
| 49 |
|
|
wikiformat/SuikaWikiImage/0.9-to-image-jpeg |
| 50 |
|
|
FullName: |
| 51 |
|
|
SuikaWikiImage/0.9 document format -> JPEG image |
| 52 |
|
|
URI: |
| 53 |
|
|
IW:SuikaWiki:SuikaWiki |
| 54 |
|
|
Format: |
| 55 |
|
|
if ($o->{content} =~ /\x0D?\x0A__IMAGE__\x0D?\x0A(.+)$/s) { |
| 56 |
|
|
require MIME::Base64; |
| 57 |
|
|
$r = MIME::Base64::decode ($1); |
| 58 |
|
|
if ($o->{magic} =~ m#image-type="(image/[0-9a-z_.+-]+)"#) { |
| 59 |
|
|
my $type = $1; |
| 60 |
|
|
$r = convert_image_type ($o, $r, $Type{$type} => $Type{'image/jpeg'}) |
| 61 |
|
|
if $type ne 'image/jpeg' && ref $Type{$type}; |
| 62 |
|
|
} |
| 63 |
|
|
} |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
{ |
| 67 |
|
|
Name: |
| 68 |
|
|
wikiformat/SuikaWikiImage/0.9-to-image-x-icon |
| 69 |
|
|
FullName: |
| 70 |
|
|
SuikaWikiImage/0.9 document format -> Windows icon |
| 71 |
|
|
URI: |
| 72 |
|
|
IW:SuikaWiki:"Wiki//Icon" |
| 73 |
|
|
Format: |
| 74 |
|
|
if ($o->{magic} =~ m#image-type="image/x-icon"#) { |
| 75 |
|
|
if ($o->{content} =~ /\x0D?\x0A__IMAGE__\x0D?\x0A(.+)$/s) { |
| 76 |
|
|
require MIME::Base64; |
| 77 |
|
|
$r = MIME::Base64::decode ($1); |
| 78 |
|
|
} |
| 79 |
|
|
} |
| 80 |
|
|
} |
| 81 |
|
|
{ |
| 82 |
|
|
Name: |
| 83 |
|
|
wikiformat/SuikaWikiImage/0.9-to-HTML-fragment |
| 84 |
|
|
FullName: |
| 85 |
|
|
SuikaWikiImage/0.9 document format -> HTML fragment |
| 86 |
|
|
URI: |
| 87 |
|
|
IW:SuikaWiki:SuikaWiki |
| 88 |
|
|
Format: |
| 89 |
|
|
if ($o->{magic} =~ m#image-type="([^"]+)"#) { |
| 90 |
|
|
my $type = $1; $type =~ tr/\x00-\x20\x7F//d; |
| 91 |
|
|
$type =~ s/[^0-9A-Za-z_]/_/g; |
| 92 |
wakaba |
1.2 |
if ($type eq 'image_png' |
| 93 |
|
|
&& $o->user_agent_names =~ m#Mozilla/[0-4]\.#) { |
| 94 |
|
|
$type = 'image_jpeg'; |
| 95 |
|
|
} |
| 96 |
wakaba |
1.1 |
my $uri = $o->uri('wiki'); my $epage = $o->encode($o->{page}); |
| 97 |
|
|
my $alt = ''; $alt = $1 if $o->{magic} =~ /image-alt="([^"]+)"/; |
| 98 |
|
|
$r = qq(<img src="$uri?mypage=$epage;mycmd=$type" alt="$alt" title="@{[$o->escape($o->{page})]}" longdesc="$uri?$epage" class="embed" />); |
| 99 |
|
|
} else { |
| 100 |
|
|
$r = qq(<span class="error-embed-image">).$o->resource('Embed:ImageNotFound',escape=>1).q(</span>); |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
{ |
| 104 |
|
|
Name: |
| 105 |
|
|
wikiview/link-favicon |
| 106 |
|
|
FullName: |
| 107 |
|
|
Returns LINK element for favicon |
| 108 |
|
|
Format: |
| 109 |
|
|
my $page = $p->{page} || 'Wiki//Icon'; |
| 110 |
|
|
$page = get_icon_page_name ($o, $page) if $p->{use_page_icon}; |
| 111 |
|
|
if ($o->_database_exist ($page)) { |
| 112 |
|
|
my ($magic, $content) = $o->magic_and_content ($main::database{$page}); |
| 113 |
|
|
if ($magic =~ m!^\#\?SuikaWikiImage/0\.9! && $magic =~ m#image-type="([^"]+)"#) { |
| 114 |
|
|
my ($type0,$type) = ($1,$1); $type =~ tr/\x00-\x20\x7F//d; |
| 115 |
|
|
$type =~ s/[^0-9A-Za-z_]/_/g; |
| 116 |
|
|
my $alt = ''; $alt = $1 if $magic =~ /image-alt="([^"]+)"/; |
| 117 |
|
|
$r = qq(<link rel="icon" type="@{[$o->escape($type0)]}" href="@{[$o->uri('wiki')]}?mypage=@{[$o->encode($page)]};mycmd=$type" title="$alt" class="favicon" />); |
| 118 |
|
|
} |
| 119 |
|
|
} else { |
| 120 |
|
|
$r = qq(<!-- icon (@{[$o->escape($page)]}) not exist -->); |
| 121 |
|
|
} |
| 122 |
|
|
} |
| 123 |
|
|
{ |
| 124 |
|
|
Name: |
| 125 |
|
|
wikiview/img-favicon |
| 126 |
|
|
FullName: |
| 127 |
|
|
Returns IMG element for favicon |
| 128 |
|
|
Format: |
| 129 |
|
|
my $page = $p->{page} || 'Wiki//Icon'; |
| 130 |
|
|
$page = get_icon_page_name ($o, $page) if $p->{use_page_icon}; |
| 131 |
|
|
if ($o->_database_exist ($page)) { |
| 132 |
|
|
my ($magic, $content) = $o->magic_and_content ($main::database{$page}); |
| 133 |
|
|
if ($magic =~ m!^\#\?SuikaWikiImage/0\.9! && $magic =~ m#image-type="([^"]+)"#) { |
| 134 |
|
|
my ($type0,$type) = ($1,$1); $type =~ tr/\x00-\x20\x7F//d; |
| 135 |
|
|
$type =~ s/[^0-9A-Za-z_]/_/g; |
| 136 |
|
|
$r = qq(<img type="@{[$o->escape($type0)]}" src="@{[$o->uri('wiki')]}?mypage=@{[$o->encode($page)]};mycmd=$type" class="favicon" alt=" " />); |
| 137 |
|
|
} |
| 138 |
|
|
} |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
|
|
Initialize: |
| 142 |
|
|
our %Type; |
| 143 |
|
|
|
| 144 |
|
|
MODULE: |
| 145 |
|
|
$Type{'image/png'} = { |
| 146 |
|
|
type => 'image/png', |
| 147 |
|
|
suffix => 'png', |
| 148 |
|
|
}; |
| 149 |
|
|
$Type{'image/jpeg'} = { |
| 150 |
|
|
type => 'image/jpeg', |
| 151 |
wakaba |
1.2 |
suffix => 'jpg', |
| 152 |
wakaba |
1.1 |
}; |
| 153 |
|
|
$Type{'image/j2k'} = { |
| 154 |
|
|
type => 'image/j2k', |
| 155 |
|
|
suffix => 'j2k', |
| 156 |
|
|
}; |
| 157 |
|
|
$Type{'image/jng'} = { |
| 158 |
|
|
type => 'image/jng', |
| 159 |
|
|
suffix => 'jng', |
| 160 |
|
|
}; |
| 161 |
|
|
$Type{'image/svg+xml'} = { |
| 162 |
|
|
type => 'image/svg+xml', |
| 163 |
|
|
suffix => 'svg', |
| 164 |
|
|
}; |
| 165 |
|
|
$Type{'image/x-icon'} = { |
| 166 |
|
|
type => 'image/x-icon', |
| 167 |
|
|
suffix => 'ico', |
| 168 |
|
|
}; |
| 169 |
|
|
sub get_icon_page_name ($$) { |
| 170 |
|
|
my ($o, $page) = @_; |
| 171 |
|
|
my @name = SuikaWiki::Name::Space::split_name ($o->{page}); |
| 172 |
|
|
for (my $i = $#name; $i >= 0; $i--) { |
| 173 |
|
|
my $p_name = &SuikaWiki::Name::Space::join_names ([@name[0..$i]]); |
| 174 |
|
|
my ($pmagic) = $o->magic_and_content ($main::database{$p_name}); |
| 175 |
|
|
if ($pmagic =~ m!\#\?SuikaWiki! && $pmagic =~ m#page-icon="([^"]+)"#) { |
| 176 |
|
|
$page = $1; |
| 177 |
|
|
last; |
| 178 |
|
|
} else { |
| 179 |
|
|
$p_name = &SuikaWiki::Name::Space::join_names ([@name[0..$i], 'Icon']); |
| 180 |
|
|
if ($o->_database_exist ($p_name)) { |
| 181 |
|
|
$page = $p_name; last; |
| 182 |
|
|
} |
| 183 |
|
|
} |
| 184 |
|
|
} |
| 185 |
|
|
$page; |
| 186 |
|
|
} |
| 187 |
wakaba |
1.2 |
|
| 188 |
|
|
$main::PathTo{convert} ||= 'convert'; |
| 189 |
wakaba |
1.1 |
sub convert_image_type ($$$$) { |
| 190 |
|
|
my ($o, $r, $from => $to) = @_; |
| 191 |
|
|
$from ||= {}; $to ||= {}; |
| 192 |
|
|
if ($from->{type} && $to->{type}) { |
| 193 |
|
|
my $fname = $o->_path_to ('TempPrefix').time.'.tmp.'; |
| 194 |
wakaba |
1.2 |
open ORG, '>', $fname . $from->{suffix}; |
| 195 |
|
|
binmode ORG; local $| = 1; |
| 196 |
|
|
print ORG $r; |
| 197 |
wakaba |
1.3 |
close ORG; |
| 198 |
wakaba |
1.2 |
system ($main::PathTo{convert}, $fname . $from->{suffix} |
| 199 |
|
|
=> $fname . $to->{suffix}); |
| 200 |
wakaba |
1.1 |
if ($fname . $to->{suffix}) { |
| 201 |
wakaba |
1.2 |
open NEW, $fname . $to->{suffix}; { |
| 202 |
|
|
binmode NEW; |
| 203 |
wakaba |
1.1 |
local $/ = undef; |
| 204 |
wakaba |
1.2 |
$r = <NEW>; |
| 205 |
|
|
} close NEW; |
| 206 |
wakaba |
1.1 |
} else { |
| 207 |
|
|
$r = ''; |
| 208 |
|
|
} |
| 209 |
wakaba |
1.2 |
#unlink $fname . $from->{suffix}; |
| 210 |
|
|
#unlink $fname . $to->{suffix}; |
| 211 |
wakaba |
1.1 |
} else { |
| 212 |
|
|
$r = ''; |
| 213 |
|
|
} |
| 214 |
|
|
$r; |
| 215 |
|
|
} |
| 216 |
|
|
SuikaWiki::View->template ('links')->add_line (q(%link-favicon(use-page-icon);)); |
| 217 |
|
|
## TODO: Provide better check function |
| 218 |
|
|
SuikaWiki::View->definition (image_jpeg => { |
| 219 |
|
|
media => {type => 'image/jpeg', expires => 240*3600}, |
| 220 |
|
|
check => sub { ref ($_[0]->format_converter ($_[0]->{magic} => 'image_jpeg')) |
| 221 |
|
|
&& $_[0]->{magic} =~ m#image-type="image/# ? 1 : 0 }, |
| 222 |
|
|
template => '%read(to=>image_jpeg);'}); |
| 223 |
|
|
SuikaWiki::View->definition (image_png => { |
| 224 |
|
|
media => {type => 'image/png', expires => 240*3600}, |
| 225 |
|
|
check => sub { ref ($_[0]->format_converter ($_[0]->{magic} => 'image_png')) |
| 226 |
|
|
&& $_[0]->{magic} =~ m#image-type="image/# ? 1 : 0 }, |
| 227 |
|
|
template => '%read(to=>image_png);'}); |
| 228 |
|
|
SuikaWiki::View->definition (image_x_icon => { |
| 229 |
|
|
media => {type => 'image/x-icon', expires => 240*3600}, |
| 230 |
|
|
check => sub { ref ($_[0]->format_converter ($_[0]->{magic} => 'image_x_icon')) |
| 231 |
|
|
&& $_[0]->{magic} =~ m#image-type="image/# ? 1 : 0 }, |
| 232 |
|
|
template => '%read(to=>image_x_icon);'}); |
| 233 |
|
|
|
| 234 |
|
|
POD:LICENSE: |
| 235 |
|
|
Copyright 2003 Wakaba <w@suika.fam.cx> |
| 236 |
|
|
|
| 237 |
|
|
%%GNUGPL2%% |