| 1 |
#?SuikaWikiConfig/2.0 |
| 2 |
|
| 3 |
Plugin: |
| 4 |
@Name: WikiLinking |
| 5 |
@Description: |
| 6 |
@@@: Wiki hyperlinking support |
| 7 |
@@lang:en |
| 8 |
@License: %%Perl%% |
| 9 |
@Author: |
| 10 |
@@Name: |
| 11 |
@@@@: Wakaba |
| 12 |
@@@lang:ja |
| 13 |
@@@script:Latn |
| 14 |
@@Mail[list]: w@suika.fam.cx |
| 15 |
@Date.RCS: |
| 16 |
$Date: 2004/04/26 00:53:45 $ |
| 17 |
@Use: |
| 18 |
use Message::Util::Error; |
| 19 |
our $NestLevel = 0; |
| 20 |
my $WIKIRESOURCE; |
| 21 |
my $ERROR; |
| 22 |
my $LINK_TO_RESOURCE; |
| 23 |
@Namespace: |
| 24 |
@@iw: |
| 25 |
http://suika.fam.cx/~wakaba/archive/2004/8/6/sw-iw# |
| 26 |
|
| 27 |
PluginConst: |
| 28 |
@NS_XHTML1: |
| 29 |
http://www.w3.org/1999/xhtml |
| 30 |
@NS_XHTML2: |
| 31 |
http://www.w3.org/2002/06/xhtml2 |
| 32 |
@NS_XLINK: |
| 33 |
http://www.w3.org/1999/xlink |
| 34 |
@NS_HLINK: |
| 35 |
http://www.w3.org/2002/06/hlink |
| 36 |
@ERROR: |
| 37 |
{($ERROR ||= SuikaWiki::Plugin->module_package ('Error'))} |
| 38 |
@LINK_TO_RESOURCE: |
| 39 |
{($LINK_TO_RESOURCE||=SuikaWiki::Plugin->formatter ('link_to_resource'))} |
| 40 |
@WIKIRESOURCE: |
| 41 |
{($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} |
| 42 |
|
| 43 |
FormattingRule: |
| 44 |
@Category[list]: |
| 45 |
view |
| 46 |
view-resource |
| 47 |
form-input |
| 48 |
page-link |
| 49 |
link-to-resource |
| 50 |
@Name: link-to-wikipage |
| 51 |
@Description: |
| 52 |
@@@: |
| 53 |
Creating "from" anchor field of a link whose "to" is a WikiPage |
| 54 |
@@lang: en |
| 55 |
@Parameter: |
| 56 |
@@Name: base-page |
| 57 |
@@Type: WikiName |
| 58 |
@@Default: (current) |
| 59 |
@@Description: |
| 60 |
@@@@:Base WikiName (Relative WikiName is resolved with) |
| 61 |
@@@lang:en |
| 62 |
@Parameter: |
| 63 |
@@Name: hreflang |
| 64 |
@@Type: |
| 65 |
HTML4:LanguageCode |
| 66 |
@@Default:(none) |
| 67 |
@@Description: |
| 68 |
@@@@:(Human) language the linked WikiPage written in |
| 69 |
@@@lang:en |
| 70 |
@Parameter: |
| 71 |
@@Name: hreftype |
| 72 |
@@Type: |
| 73 |
HTML4:ContentType |
| 74 |
@@Default:(none) |
| 75 |
@@Description: |
| 76 |
@@@@:Media type the linked WikiPage provided with |
| 77 |
@@@lang:en |
| 78 |
@Parameter: |
| 79 |
@@Name:label |
| 80 |
@@Type:CDATA |
| 81 |
@@Default:(auto) |
| 82 |
@@Description: |
| 83 |
@@@@:Source anchor label |
| 84 |
@@@lang:en |
| 85 |
@Parameter: |
| 86 |
@@Name: mode |
| 87 |
@@Type: WikiMode |
| 88 |
@@Default:(default) |
| 89 |
@@Description: |
| 90 |
@@@@:Mode of the Wiki linked to |
| 91 |
@@@lang:en |
| 92 |
@Parameter: |
| 93 |
@@Name: page |
| 94 |
@@Type: WikiName |
| 95 |
@@Default: (current) |
| 96 |
@@Description: |
| 97 |
@@@@:WikiPage linked to |
| 98 |
@@@lang:en |
| 99 |
@Parameter: |
| 100 |
@@Name: page-anchor-name |
| 101 |
@@Type: |
| 102 |
XML:ID |
| 103 |
@@Default: (none) |
| 104 |
@@Description: |
| 105 |
@@@@:Identifier in the WikiPage linked to |
| 106 |
@@@lang:en |
| 107 |
@Parameter: |
| 108 |
@@Name: page-anchor-no |
| 109 |
@@Type: |
| 110 |
SGML:NUMBER |
| 111 |
@@Default: (none) |
| 112 |
@@Description: |
| 113 |
@@@@:Numeral anchor index in the WikiPage linked to |
| 114 |
@@@lang:en |
| 115 |
@Parameter: |
| 116 |
@@Name: page-title |
| 117 |
@@Type:CDATA |
| 118 |
@@Default:(auto) |
| 119 |
@@Description: |
| 120 |
@@@@:Title of the WikiPage linked to |
| 121 |
@@@lang:en |
| 122 |
@Parameter: |
| 123 |
@@Name: rel |
| 124 |
@@Type: |
| 125 |
HTML4:LinkTypes |
| 126 |
@@Default:(none) |
| 127 |
@@Description: |
| 128 |
@@@@:Link relationships |
| 129 |
@@@lang:en |
| 130 |
@Parameter: |
| 131 |
@@Name: rev |
| 132 |
@@Type: |
| 133 |
HTML4:LinkTypes |
| 134 |
@@Default:(none) |
| 135 |
@@Description: |
| 136 |
@@@@:Link relationship (reverse) |
| 137 |
@@@lang:en |
| 138 |
@Parameter: |
| 139 |
@@Name: up-to-date |
| 140 |
@@Type: boolean |
| 141 |
@@Default: "0" |
| 142 |
@@Description: |
| 143 |
@@@@:Appends random "up-to-date" parameter to the URI reference |
| 144 |
@@@lang:en |
| 145 |
@Parameter: |
| 146 |
@@Name: with-lm |
| 147 |
@@Type: boolean |
| 148 |
@@Default:"0" |
| 149 |
@@Description: |
| 150 |
@@@@:Appends "last-modified" parameter to the URI reference |
| 151 |
@@@lang:en |
| 152 |
@Formatting: |
| 153 |
__ATTRNODE:%page_title__; |
| 154 |
__ATTRTEXT:%class__; |
| 155 |
__ATTRTEXT:%label__; |
| 156 |
__ATTRTEXT:%page__;__ATTRTEXT:%base_page__;__ATTRTEXT:%page_anchor_no__; |
| 157 |
__ATTRTEXT:%with_lm__;__ATTRTEXT:%up_to_date__; |
| 158 |
__ATTRTEXT:%page_anchor_name__; |
| 159 |
__ATTRTEXT:%hreflang__;__ATTRTEXT:%hreftype__; |
| 160 |
__ATTRTEXT:%mode__; |
| 161 |
__ATTRTEXT:%rel__;__ATTRTEXT:%rev__; |
| 162 |
__FUNCPACK__->to_wikipage_in_html ({ |
| 163 |
label => $p->{label}, |
| 164 |
} => { |
| 165 |
base => $o->{wiki}->name ($p->{base_page} || |
| 166 |
$o->{wiki}->{var}->{page}), |
| 167 |
page_name_relative => $o->{wiki}->name ($p->{page} || |
| 168 |
$o->{wiki}->{var}->{page}), |
| 169 |
page_anchor_no => $p->{page_anchor_no}, |
| 170 |
page_anchor_name => $p->{page_anchor_name}, |
| 171 |
page_title => $p->{page_title}, |
| 172 |
wiki_mode => $p->{mode}, |
| 173 |
_with_lm => $p->{with_lm}, |
| 174 |
_up_to_date => $p->{up_to_date}, |
| 175 |
-hreflang => $p->{hreflang}, |
| 176 |
-hreftype => $p->{type}, |
| 177 |
}, { |
| 178 |
o => $o, |
| 179 |
parent => $p->{-parent}, |
| 180 |
-rel => $p->{rel}, |
| 181 |
-rev => $p->{rev}, |
| 182 |
}); |
| 183 |
|
| 184 |
FormattingRule: |
| 185 |
@Category[list]: |
| 186 |
view |
| 187 |
view-resource |
| 188 |
form-input |
| 189 |
page-link |
| 190 |
link-to-resource |
| 191 |
@Name: link-to-resource |
| 192 |
@Description: |
| 193 |
@@@: |
| 194 |
Creating source anchor field of a link whose destination is a resource |
| 195 |
@@lang: en |
| 196 |
@Parameter |
| 197 |
@@Name: hreflang |
| 198 |
@@Type: |
| 199 |
HTML4:LanguageCode |
| 200 |
@@Default:(none) |
| 201 |
@@Description: |
| 202 |
@@@@:(Human) language the linked WikiPage written in (advisory) |
| 203 |
@@@lang:en |
| 204 |
@Parameter: |
| 205 |
@@Name: hreftype |
| 206 |
@@Type: |
| 207 |
HTML4:ContentType |
| 208 |
@@Default:(none) |
| 209 |
@@Description: |
| 210 |
@@@@:Media type the linked WikiPage provided with (advisory) |
| 211 |
@@@lang:en |
| 212 |
@Parameter: |
| 213 |
@@Name:label |
| 214 |
@@Type:CDATA |
| 215 |
@@Default:(auto) |
| 216 |
@@Description: |
| 217 |
@@@@:Source anchor label |
| 218 |
@@@lang:en |
| 219 |
@Parameter: |
| 220 |
@@Name: rel |
| 221 |
@@Type: |
| 222 |
HTML4:LinkTypes |
| 223 |
@@Default:(none) |
| 224 |
@@Description: |
| 225 |
@@@@:Link relationships |
| 226 |
@@@lang:en |
| 227 |
@Parameter: |
| 228 |
@@Name: rev |
| 229 |
@@Type: |
| 230 |
HTML4:LinkTypes |
| 231 |
@@Default:(none) |
| 232 |
@@Description: |
| 233 |
@@@@:Link relationship (reverse) |
| 234 |
@@@lang:en |
| 235 |
@Parameter: |
| 236 |
@@Name: uri |
| 237 |
@@Type: |
| 238 |
HTML4:URI |
| 239 |
@@Default:(required) |
| 240 |
@@Description: |
| 241 |
@@@@:URI reference of the resoruce referred to |
| 242 |
@@@lang:en |
| 243 |
@Formatting: |
| 244 |
__ATTRTEXT:%class__; |
| 245 |
__ATTRTEXT:%label__; |
| 246 |
__ATTRTEXT:%hreflang__;__ATTRTEXT:%hreftype__; |
| 247 |
__ATTRTEXT:%rel__;__ATTRTEXT:%rev__; |
| 248 |
__ATTRTEXT:%uri__; |
| 249 |
my $src = { |
| 250 |
label => $p->{label}, |
| 251 |
}; |
| 252 |
my $dest = { |
| 253 |
-hreflang => $p->{hreflang}, |
| 254 |
-hreftype => $p->{type}, |
| 255 |
}; |
| 256 |
my $opt = { |
| 257 |
o => $o, |
| 258 |
parent => $p->{-parent}, |
| 259 |
-rel => $p->{rel}, |
| 260 |
-rev => $p->{rev}, |
| 261 |
}; |
| 262 |
if (length $p->{uri}) { |
| 263 |
$dest->{uri} = $p->{uri}; |
| 264 |
} else { |
| 265 |
__ATTRTEXT:%iw_name__; |
| 266 |
if ($p->{iw_name}) { |
| 267 |
__ATTRTEXT:%iw_parameter__; |
| 268 |
$dest->{resource_scheme} = 'IW'; |
| 269 |
$dest->{resource_parameter} = undef; |
| 270 |
$dest->{-iw__name} = $p->{iw_name}; |
| 271 |
$dest->{-iw__parameter} = $p->{iw_parameter}; |
| 272 |
__FUNCPACK__->to_resource_in_html ($src => $dest, $opt); |
| 273 |
return; |
| 274 |
} else { |
| 275 |
$dest->{uri} = q<>; |
| 276 |
} |
| 277 |
} |
| 278 |
__FUNCPACK__->to_resource_by_uri_in_html ($src => $dest, $opt); |
| 279 |
|
| 280 |
FormattingRule: |
| 281 |
@Category[list]: |
| 282 |
page-link |
| 283 |
link-to-resource |
| 284 |
@Name: link-to-it |
| 285 |
@Description: |
| 286 |
@@@: |
| 287 |
Source anchor |
| 288 |
@@lang: en |
| 289 |
@Parameter: |
| 290 |
@@Name: class |
| 291 |
@@Type: |
| 292 |
HTML4:class |
| 293 |
@@Default: (none) |
| 294 |
@@Description: |
| 295 |
@@@@: Class names |
| 296 |
@@@lang:en |
| 297 |
@Parameter: |
| 298 |
@@Name: description |
| 299 |
@@Type: CDATA |
| 300 |
@@Default: (none) |
| 301 |
@@Description: |
| 302 |
@@@@: Description of the anchor or link |
| 303 |
@@@lang:en |
| 304 |
@Parameter: |
| 305 |
@@Name: label |
| 306 |
@@Type: CDATA |
| 307 |
@@Default: "" |
| 308 |
@@Description: |
| 309 |
@@@@: Source anchor label (content) |
| 310 |
@@@lang:en |
| 311 |
@Formatting: |
| 312 |
__ATTRTEXT:%class__; |
| 313 |
my $A = $p->{-parent}->append_new_node (type => '#element', |
| 314 |
namespace_uri => $NS_XHTML1, |
| 315 |
local_name => 'a'); |
| 316 |
$A->set_attribute (href => $o->{link}->{dest}->{uri}); |
| 317 |
|
| 318 |
__ATTRNODE:%label->{$A}__; |
| 319 |
if (length $p->{description}) { |
| 320 |
__ATTRTEXT:%description__; |
| 321 |
} else { |
| 322 |
if ($f->{-category_name} eq 'page_link') { |
| 323 |
$p->{description} = $WIKIRESOURCE->get |
| 324 |
(name => 'WikiLinking:LinkToIt:ToWikiPage:Description', |
| 325 |
o => $o, wiki => $o->{wiki}, |
| 326 |
formatter_context => $f->{-category_name}, |
| 327 |
formatter_option => {param => $o})->inner_text; |
| 328 |
} else { |
| 329 |
$p->{description} = $WIKIRESOURCE->get |
| 330 |
(name => 'WikiLinking:LinkToIt:ToResource:Description', |
| 331 |
o => $o, wiki => $o->{wiki}, |
| 332 |
formatter_context => $f->{-category_name}, |
| 333 |
formatter_option => {param => $o})->inner_text; |
| 334 |
} |
| 335 |
} |
| 336 |
$A->set_attribute (title => $p->{description}) if $p->{description}; |
| 337 |
my @class = split /\s+/, $p->{class}; |
| 338 |
if ($o->{wiki}->uri_is_part_of_wiki ($o->{link}->{dest}->{absolute_uri} or |
| 339 |
$o->{link}->{dest}->{uri})) { |
| 340 |
push @class, 'wiki'; ## Link to the page within the Wiki |
| 341 |
} |
| 342 |
$A->set_attribute (class => join ' ', @class) if @class; |
| 343 |
|
| 344 |
$A->set_attribute (rel => $o->{link}->{option}->{-rel}) |
| 345 |
if $o->{link}->{option}->{-rel}; |
| 346 |
$A->set_attribute (rev => $o->{link}->{option}->{-rev}) |
| 347 |
if $o->{link}->{option}->{-rev}; |
| 348 |
|
| 349 |
$A->set_attribute (hreflang => $o->{link}->{dest}->{-lang}) |
| 350 |
if $o->{link}->{dest}->{-lang}; |
| 351 |
$A->set_attribute (type => $o->{link}->{dest}->{-type}) |
| 352 |
if $o->{link}->{dest}->{-type}; |
| 353 |
|
| 354 |
FormattingRule: |
| 355 |
@Category[list]: |
| 356 |
page-link |
| 357 |
link-to-resource |
| 358 |
@Name: uri-reference |
| 359 |
@Description: |
| 360 |
@@@: URI Reference of destination anchor |
| 361 |
@@lang:en |
| 362 |
@Formatting: |
| 363 |
$p->{-parent}->append_text ($o->{link}->{dest}->{absolute_uri} or |
| 364 |
$o->{link}->{dest}->{uri}); |
| 365 |
|
| 366 |
FormattingRule: |
| 367 |
@Category[list]: link-to-resource |
| 368 |
@Name: link-resource-scheme |
| 369 |
@Description: |
| 370 |
@@@: Linking scheme (defined as ReferenceScheme in SuikaWiki/0.9 syntax) |
| 371 |
@@lang:en |
| 372 |
@Formatting: |
| 373 |
$p->{-parent}->append_text ($o->{link}->{dest}->{resource_scheme}); |
| 374 |
|
| 375 |
FormattingRule: |
| 376 |
@Category[list]: link-to-resource |
| 377 |
@Name: link-resource-parameters |
| 378 |
@Description: |
| 379 |
@@@: Linking parameters (defined as ReferenceParameter in SuikaWiki/0.9 syntax) |
| 380 |
@@lang:en |
| 381 |
@Formatting: |
| 382 |
$p->{-parent}->append_text ($o->{link}->{dest}->{resource_parameter}); |
| 383 |
|
| 384 |
FormattingRule: |
| 385 |
@Category[list]: page-link |
| 386 |
@Name: link-base-page-name |
| 387 |
@Description: |
| 388 |
@@@: Base WikiPage name |
| 389 |
@@lang: en |
| 390 |
@Formatting: |
| 391 |
$p->{-parent}->append_text |
| 392 |
($o->{link}->{dest}->{base}->stringify (wiki => $o->{wiki})); |
| 393 |
|
| 394 |
FormattingRule: |
| 395 |
@Category[list]: page-link |
| 396 |
@Name: link-dest-anchor-no |
| 397 |
@Description: |
| 398 |
@@@: Anchor number in the WikiPage linked to, if specified |
| 399 |
@@lang: en |
| 400 |
@Formatting: |
| 401 |
$p->{-parent}->append_text ($o->{link}->{dest}->{page_anchor_no}); |
| 402 |
|
| 403 |
FormattingRule: |
| 404 |
@Category[list]: link-to-resource |
| 405 |
@Name: if-link-resource-scheme |
| 406 |
@Description: |
| 407 |
@@@: If or if not resource pointing scheme matches to |
| 408 |
@@lang:en |
| 409 |
@Parameter: |
| 410 |
@@Name: name |
| 411 |
@@Type: |
| 412 |
SW09:name |
| 413 |
@@Default:(required) |
| 414 |
@@Description: |
| 415 |
@@@@: Scheme name |
| 416 |
@@@lang:en |
| 417 |
@Formatting: |
| 418 |
__ATTRTEXT:%name__; |
| 419 |
my $rule; |
| 420 |
if ($o->{link}->{dest}->{resource_scheme} eq $p->{name}) { |
| 421 |
$rule = __ATTRTEXT:%true__; |
| 422 |
} else { |
| 423 |
$rule = __ATTRTEXT:%false__; |
| 424 |
} |
| 425 |
SuikaWiki::Plugin->formatter ($f->{-category_name}) |
| 426 |
->replace ($rule, param => $o, -parent => $p->{-parent}); |
| 427 |
|
| 428 |
FormattingRule: |
| 429 |
@Category[list]: link-to-resource |
| 430 |
@Name: select-link-resource-scheme |
| 431 |
@Description: |
| 432 |
@@@: Selecting template by resource pointing scheme matches to |
| 433 |
@@lang:en |
| 434 |
@Parameter: |
| 435 |
@@Name: SCHEMENAME |
| 436 |
@@Type: |
| 437 |
template |
| 438 |
@@Default:(none) |
| 439 |
@@Description: |
| 440 |
@@@@: Template used when scheme name is SCHEMENAME |
| 441 |
@@@lang:en |
| 442 |
@Parameter: |
| 443 |
@@Name: otherwise |
| 444 |
@@Type: |
| 445 |
template |
| 446 |
@@Default:(none) |
| 447 |
@@Description: |
| 448 |
@@@@: Template used when no SCHEMENAME parameter matches |
| 449 |
@@@lang:en |
| 450 |
@Formatting: |
| 451 |
my $rule; |
| 452 |
if (defined $p->{$o->{link}->{dest}->{resource_scheme}}) { |
| 453 |
$rule = __ATTRTEXT:%{$o->{link}->{dest}->{resource_scheme}}__; |
| 454 |
} else { |
| 455 |
$rule = __ATTRTEXT:%otherwise__; |
| 456 |
} |
| 457 |
try { |
| 458 |
$f->replace ($rule, param => $o, -parent => $p->{-parent}); |
| 459 |
} catch Message::Util::Formatter::error with { |
| 460 |
my $err = shift; |
| 461 |
if ($err->{-object}->{-category_name} eq $f->{-category_name}) { |
| 462 |
my $wiki = $err->{option}->{param}->{wiki}; |
| 463 |
__FUNCPACK{Error}__->reporting_formatting_template_error |
| 464 |
($err, $wiki, |
| 465 |
template => $rule); |
| 466 |
} else { |
| 467 |
$err->throw; |
| 468 |
} |
| 469 |
}; |
| 470 |
|
| 471 |
FormattingRule: |
| 472 |
@Category[list]: page-link |
| 473 |
@Name: if-linked-wikipage-exist |
| 474 |
@Description: |
| 475 |
@@@: If or if not linked WikiPage exists, then |
| 476 |
@@lang: en |
| 477 |
@Formatting: |
| 478 |
my $page = $o->{link}->{dest}->{page_name}; |
| 479 |
my $rule; |
| 480 |
my $exists = 0; |
| 481 |
if ($o->{wiki}->{db}) { |
| 482 |
try { |
| 483 |
$exists = $o->{wiki}->{db}->exist (content => $page); |
| 484 |
} catch SuikaWiki::DB::Util::Error with { |
| 485 |
my $err = shift; |
| 486 |
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 487 |
}; |
| 488 |
}else {CORE::die Carp::longmess} |
| 489 |
if ($exists) { |
| 490 |
$rule = __ATTRTEXT:%true__; |
| 491 |
} else { |
| 492 |
$rule = __ATTRTEXT:%false__; |
| 493 |
} |
| 494 |
SuikaWiki::Plugin->formatter ('page_link') |
| 495 |
->replace ($rule, param => $o, -parent => $p->{-parent}); |
| 496 |
|
| 497 |
FormattingRule: |
| 498 |
@Category[list]: page-link |
| 499 |
@Name: if-link-has-dest-anchor-no |
| 500 |
@Description: |
| 501 |
@@@: If or if the link has destination numeral anchor |
| 502 |
@@lang: en |
| 503 |
@Formatting: |
| 504 |
my $rule; |
| 505 |
if ($o->{link}->{dest}->{page_anchor_no}) { |
| 506 |
$rule = __ATTRTEXT:%true__; |
| 507 |
} else { |
| 508 |
$rule = __ATTRTEXT:%false__; |
| 509 |
} |
| 510 |
SuikaWiki::Plugin->formatter ('page-link') |
| 511 |
->replace ($rule, param => $o, -parent => $p->{-parent}); |
| 512 |
|
| 513 |
FormattingRule: |
| 514 |
@Category[list]: |
| 515 |
page-link |
| 516 |
link-to-resource |
| 517 |
@Name:-bare-text |
| 518 |
@Formatting: |
| 519 |
$p->{-parent}->append_text ($p->{-bare_text}); |
| 520 |
|
| 521 |
Function: |
| 522 |
@Name: to_resource_in_html |
| 523 |
@Description: |
| 524 |
@@@Make a link to the resource (outputted in HTML) |
| 525 |
@@lang:en |
| 526 |
@Main: |
| 527 |
my (undef, $src => $dest, $opt) = @_; |
| 528 |
local $opt->{o}->{iwc__param}; ## For InterWikiCore module |
| 529 |
if ($dest->{resource_scheme} eq 'URI' or |
| 530 |
$dest->{resource_scheme} eq 'URL') { |
| 531 |
$dest->{uri} = URI->new ($dest->{resource_parameter}); |
| 532 |
} elsif ($dest->{resource_scheme} eq 'IW') { |
| 533 |
$dest->{uri} = __FUNCPACK{InterWikiCore}__ |
| 534 |
->interwikireference_to_urireference |
| 535 |
(packed => $dest->{resource_parameter}, |
| 536 |
name => $dest->{-iw__name}, |
| 537 |
param => $dest->{-iw__parameter}, |
| 538 |
o => $opt->{o}, |
| 539 |
wiki => $opt->{o}->{wiki}) |
| 540 |
|| URI->new (q<#err--error>); |
| 541 |
$src->{<Q:iw:label>} = __FUNCPACK{InterWikiCore}__ |
| 542 |
->interwikireference_to_sourcelabel |
| 543 |
(packed => $dest->{resource_parameter}, |
| 544 |
name => $dest->{-iw__name}, |
| 545 |
param => $dest->{-iw__parameter}, |
| 546 |
o => $opt->{o}, |
| 547 |
wiki => $opt->{o}->{wiki}); |
| 548 |
} elsif ($dest->{resource_scheme} eq 'MAIL') { |
| 549 |
$dest->{uri} = 'mailto:'.$dest->{resource_parameter}; |
| 550 |
} else { |
| 551 |
$ERROR->report_error_simple |
| 552 |
($opt->{o}->{wiki}, |
| 553 |
$WIKIRESOURCE->get_op ('Error:Condition', $opt->{o}) |
| 554 |
=> $WIKIRESOURCE->get_op |
| 555 |
('WikiLinking:ResourceScheme:Unknown:Description', |
| 556 |
$opt->{o}), |
| 557 |
$WIKIRESOURCE->get_op ('WikiLinking:ResourceScheme', $opt->{o}) |
| 558 |
=> $dest->{resource_scheme}, |
| 559 |
$WIKIRESOURCE->get_op ('WikiLinking:ResourceParameter', |
| 560 |
$opt->{o}) |
| 561 |
=> $dest->{resource_parameter}, |
| 562 |
); |
| 563 |
$dest->{uri} = URI->new (q<#err--error>); |
| 564 |
} |
| 565 |
__FUNCPACK__->to_resource_by_uri_in_html ($src => $dest, $opt); |
| 566 |
|
| 567 |
Function: |
| 568 |
@Name: to_resource_by_uri_in_html |
| 569 |
@Description: |
| 570 |
@@@:Make a link to the resource by URI reference (outputted in HTML) |
| 571 |
@@lang:en |
| 572 |
@Main: |
| 573 |
my (undef, $src => $dest, $opt) = @_; |
| 574 |
local $NestLevel = $NestLevel + 1; |
| 575 |
if (100 < $NestLevel) { |
| 576 |
$opt->{parent}->append_new_node (type => '#comment', |
| 577 |
value => $src->{label}); |
| 578 |
$ERROR->report_error_simple |
| 579 |
($opt->{o}->{wiki}, |
| 580 |
$WIKIRESOURCE->get_op ('Error:Condition', $opt->{o}) |
| 581 |
=> $WIKIRESOURCE->get_op |
| 582 |
('WikiLinking:Error:TooDeep', $opt->{o}), |
| 583 |
$WIKIRESOURCE->get_op ('Error:Formatter:Template', $opt->{o}) |
| 584 |
=> $src->{label}, |
| 585 |
-trace => 1, |
| 586 |
); |
| 587 |
return; |
| 588 |
} |
| 589 |
|
| 590 |
local $opt->{o}->{link} = { |
| 591 |
src => $src, |
| 592 |
dest => $dest, |
| 593 |
option => $opt, |
| 594 |
}; |
| 595 |
$dest->{uri} = ref $dest->{uri} ? $dest->{uri}->canonical |
| 596 |
: URI->new ($dest->{uri})->canonical; |
| 597 |
$src->{label} ||= $WIKIRESOURCE->get_text |
| 598 |
(name => 'Link:toResource:SourceLabel', |
| 599 |
param => $opt->{o}, |
| 600 |
wiki => $opt->{o}->{wiki}); |
| 601 |
try { |
| 602 |
$LINK_TO_RESOURCE |
| 603 |
->replace ($src->{label}, param => $opt->{o}, -parent => $opt->{parent}); |
| 604 |
} catch Message::Util::Formatter::error with { |
| 605 |
my $err = shift; |
| 606 |
if ($err->{-object}->{-category_name} eq 'link_to_resource') { |
| 607 |
my $wiki = $err->{option}->{param}->{wiki}; |
| 608 |
__FUNCPACK{Error}__->reporting_formatting_template_error |
| 609 |
($err, $wiki, |
| 610 |
template => $src->{label}); |
| 611 |
undef; |
| 612 |
} else { |
| 613 |
$err->throw; |
| 614 |
} |
| 615 |
}; |
| 616 |
|
| 617 |
Function: |
| 618 |
@Name: to_wikipage_in_html |
| 619 |
@Description: |
| 620 |
@@@:Make a link to the WikiPage (outputed in HTML) |
| 621 |
@@lang:en |
| 622 |
@Main: |
| 623 |
my (undef, $src => $dest, $opt) = @_; |
| 624 |
local $NestLevel = $NestLevel + 1; |
| 625 |
if (100 < $NestLevel) { |
| 626 |
$opt->{parent}->append_new_node (type => '#comment', |
| 627 |
value => $src->{label}); |
| 628 |
__FUNCPACK{Error}__->report_error_simple |
| 629 |
($opt->{o}->{wiki}, |
| 630 |
__FUNCPACK{WikiResource}__ |
| 631 |
->get_op ('Error:Condition', $opt->{o}) |
| 632 |
=> __FUNCPACK{WikiResource}__->get_op |
| 633 |
('WikiLinking:Error:TooDeep', $opt->{o}), |
| 634 |
__FUNCPACK{WikiResource}__ |
| 635 |
->get_op ('Error:Formatter:Template', $opt->{o}) |
| 636 |
=> $src->{label}, |
| 637 |
-trace => 1, |
| 638 |
); |
| 639 |
return; |
| 640 |
} |
| 641 |
$dest->{page_name} ||= $dest->{page_name_relative}->absolute |
| 642 |
(base => $dest->{base}, wiki => $opt->{o}->{wiki}); |
| 643 |
($dest->{uri}, $dest->{absolute_uri}) |
| 644 |
= $opt->{o}->{wiki}->uri_reference |
| 645 |
(page => $dest->{page_name}, |
| 646 |
mode => $dest->{wiki_mode}, |
| 647 |
anchor_no => $dest->{page_anchor_no}, |
| 648 |
up_to_date => $dest->{_up_to_date}, |
| 649 |
with_lm => $dest->{_with_lm}, |
| 650 |
param => $dest->{param} || {}, |
| 651 |
fragment => $dest->{page_anchor_name}, |
| 652 |
base => $dest->{-use_absolute_uri} ? undef: |
| 653 |
($src->{base_uri} || 1)); |
| 654 |
|
| 655 |
local $opt->{o}->{link} = { |
| 656 |
src => $src, |
| 657 |
dest => $dest, |
| 658 |
option => $opt, |
| 659 |
}; |
| 660 |
$src->{label} ||= SuikaWiki::Plugin->module_package ('WikiResource') |
| 661 |
->get_text (name => 'Link:toWikiPage:SourceLabel', |
| 662 |
param => $opt->{o}, |
| 663 |
wiki => $opt->{o}->{wiki}); |
| 664 |
try { |
| 665 |
SuikaWiki::Plugin->formatter ('page_link') |
| 666 |
->replace ($src->{label}, param => $opt->{o}, -parent => $opt->{parent}); |
| 667 |
} catch Message::Util::Formatter::error with { |
| 668 |
my $err = shift; |
| 669 |
if ($err->{-object}->{-category_name} eq 'page_link') { |
| 670 |
my $wiki = $err->{option}->{param}->{wiki}; |
| 671 |
SuikaWiki::Plugin->module_package ('Error') |
| 672 |
->reporting_formatting_template_error |
| 673 |
($err, $wiki, |
| 674 |
template => $src->{label}); |
| 675 |
undef; |
| 676 |
} else { |
| 677 |
$err->throw; |
| 678 |
} |
| 679 |
}; |
| 680 |
|
| 681 |
PluginCategory: |
| 682 |
@Name: page-link |
| 683 |
@Description: |
| 684 |
@@@: Source anchor label of link whose destination is a WikiPage |
| 685 |
@@lang:en |
| 686 |
|
| 687 |
PluginCategory: |
| 688 |
@Name: link-to-resource |
| 689 |
@Description: |
| 690 |
@@@: Source anchor label of link whose destination is a resource |
| 691 |
@@lang:en |
| 692 |
|
| 693 |
Resource: |
| 694 |
@Link:toResource:SourceLabel: |
| 695 |
@@@: |
| 696 |
%select-link-resource-scheme ( |
| 697 |
URI => {<%link-to-it( |
| 698 |
label => {%uri-reference;}p, |
| 699 |
);>}, |
| 700 |
IW => {%iw--source-label (default => {<%link-to-it ( |
| 701 |
label => {%link-resource-scheme;:%link-resource-parameters;}p, |
| 702 |
);});}, |
| 703 |
MAIL => {<%link-to-it( |
| 704 |
label => {%link-resource-parameters;}p, |
| 705 |
description |
| 706 |
=> {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p, |
| 707 |
);>}, |
| 708 |
otherwise => {<%link-to-it( |
| 709 |
label => {%link-resource-scheme;:%link-resource-parameters;}p, |
| 710 |
);>}, |
| 711 |
); |
| 712 |
@Link:toWikiPage:NotExist:Mark: |
| 713 |
@@@: ? |
| 714 |
@Link:toWikiPage:SourceLabel: |
| 715 |
@@@: |
| 716 |
%link-to-it( |
| 717 |
label=>{%page-title (relative);%if-linked-wikipage-exist( |
| 718 |
true=>{%if-link-has-dest-anchor-no(true=>{>>%link-dest-anchor-no;});}, |
| 719 |
false=>{%res(name=>{Link:toWikiPage:NotExist:Mark});} |
| 720 |
);}p, |
| 721 |
class=>{%if-linked-wikipage-exist(false=>{not-exist});}p, |
| 722 |
); |
| 723 |
@Link:MailAddress=: |
| 724 |
@@@: |
| 725 |
Internet Mail Address: |
| 726 |
@@lang:en |
| 727 |
@Link:URIReference=: |
| 728 |
@@@: |
| 729 |
URI Reference: |
| 730 |
@@lang:en |
| 731 |
@WikiLinking:Error:TooDeep: |
| 732 |
@@@: |
| 733 |
Link nesting too deep. |
| 734 |
@@lang: en |
| 735 |
@WikiLinking:LinkToIt:ToResource:Description: |
| 736 |
%res (name=>{Link:URIReference=});<%uri-reference;> |
| 737 |
@WikiLinking:LinkToIt:ToWikiPage:Description: |
| 738 |
%page-name(absolute);; %if-linked-wikipage-exist( |
| 739 |
true=>{%page-headline;}, |
| 740 |
false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)}, |
| 741 |
); |
| 742 |
@WikiLinking:ResourceParameter: |
| 743 |
@@@: Resource identification parameter |
| 744 |
@@lang: en |
| 745 |
@WikiLinking:ResourceScheme: |
| 746 |
@@@: Resource identification scheme |
| 747 |
@@lang: en |
| 748 |
@WikiLinking:ResourceScheme:Unknown:Description: |
| 749 |
@@@: |
| 750 |
Unknown resource identification scheme specified. |
| 751 |
@@lang: en |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|