Name:
WikiLinking
FullName:
Wiki (one-to-one) hyperlinking support
URI:
IW:SuikaWiki:"SuikaWiki"
Initialize:
my $NS_XHTML1 = 'http://www.w3.org/1999/xhtml';
{
Name:
wikiview/link-to-wikipage
wikiview-resource/link-to-wikipage
wikiform-input/link-to-wikipage
FullName:
Link to a WikiPage
Format:
$r = __PACKAGE__->to_wikipage_in_html ({
label => ($p->{label}),
} => {
base => ($p->{base_page}||$o->{page}),
page_name_relative => $p->{page},
page_anchor_no => $p->{page_anchor_no},
page_title => $p->{page_title},
wiki_mode => $p->{mode},
}, {
o => $o,
});
}
{
Name:
wikipage-link/link-to-it
FullName:
Link (make a source anchor) to "it"
Format:
$r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'a');
$r->set_attribute (href => $o->{link}->{dest}->{uri});
$r->append_node ($p->{label}, node_or_text => 1);
$r->set_attribute (title => $p->{description}) if $p->{description};
my @class = split /\s+/, $p->{class};
if (substr ($o->{link}->{dest}->{uri}, 0, length ($o->uri ('wiki')))
eq $o->uri ('wiki')) {
push @class, 'wiki'; ## Link to the page within the Wiki
}
$r->set_attribute (class => join ' ', @class) if @class;
}
{
Name:
wikipage-link/link-base-page
FullName:
Base WikiPage of the link
Format:
$r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{base});
}
{
Name:
wikipage-link/link-dest-anchor-no
FullName:
The number of destination anchor of the link
Format:
$r = SuikaWiki::Markup::XML->new (type => '#text', value => $o->{link}->{dest}->{page_anchor_no});
}
{
Name:
wikipage-link/if-linked-wikipage-exist
FullName:
If, if not WikiPage of the link is exist...
Format:
my $formatter = SuikaWiki::Plugin->formatter ('page_link');
return $formatter->replace (($o->_database_exist ($o->{link}->{dest}->{page_name}) ? $p->{true} : $p->{false}), $o, {formatter => $formatter});
}
{
Name:
wikipage-link/if-link-has-dest-anchor-no
FullName:
If, if not WikiPage of the link has the number of the destination anchor...
Format:
my $formatter = SuikaWiki::Plugin->formatter ('page_link');
return $formatter->replace (($o->{link}->{dest}->{page_anchor_no} ? $p->{true} : $p->{false}), $o, {formatter => $formatter});
}
{
Name:
wikipage-link/-bare-text
FullName:
#text
Format:
$r = SuikaWiki::Markup::XML->new (type => '#text', value => $p->{-bare_text});
}
MODULE:
## Public functions
sub to_wikipage_in_html ($$$;$) {
my (undef, $src, $dest, $option) = @_;
$dest->{page_name} = SuikaWiki::Plugin::WikiNamespace->resolve_relative_name
($dest->{base} => $dest->{page_name_relative});
$dest->{uri} = SuikaWiki::Plugin->_uri_wiki_page ## TODO: use formal API
($dest->{page_name}, mode => $dest->{wiki_mode},
anchor => $dest->{page_anchor_no}, up_to_date => $dest->{_up_to_date},
with_lm => $dest->{_with_lm});
## Making label/description from template
my $o = $option->{o};
$o->{link} = {
src => $src,
dest => $dest,
option => $option,
};
$src->{label} = SuikaWiki::Plugin->resource ('Link:toWikiPage:SourceLabel')
unless defined $src->{label};
my $formatter = SuikaWiki::Plugin->formatter ('page_link');
return $formatter->replace ($src->{label}, $o, {formatter => $formatter});
}
## Obsolete (but still used) public functions
package main;
our (%interwiki, %uri, %database, %fmt, %PageName);
## %option
## -- page options: mode, with_lm, up_to_date, anchor,
## add_param (discouraged), href (discouraged),
## base
## -- source anchor options: label, anchor
sub make_wikilink ($%) {
my ($name, %option) = @_;
my $dname = length $option{label} ? $option{label} : $name;
$name = SuikaWiki::Plugin::WikiNamespace->resolve_relative_name ($option{base} => $name);
#$name ||= $PageName{FrontPage};
my $r = SuikaWiki::Markup::XML->new (namespace_uri => $NS_XHTML1, local_name => 'a');
$r->set_attribute (href => SuikaWiki::Plugin->_uri_wiki_page ($name, %option));
if ($main::database{$name}) {
if ($option{anchor}) {
$r->append_text (qq($dname>>$option{anchor}));
} else {
$r->append_text ($dname);
}
$r->set_attribute (title => $name.SuikaWiki::Plugin::WikiPage->_get_subjectline ($name));
$r->set_attribute (class => 'wiki');
} else {
$r->set_attribute (class => 'wiki not-exist');
$r->set_attribute (title => $name.SuikaWiki::Plugin->resource ('Title-Summary Delimiter').SuikaWiki::Plugin->resource('JumpAndEditWikiPage'));
$r->append_text ($dname);
## TODO: In pure XML mode, don't output this (should be displayed by style sheet!)
for ($r->append_new_node (namespace_uri => $NS_XHTML1, local_name => 'span')) {
$_->set_attribute (class => 'mark');
$_->append_text (SuikaWiki::Plugin->resource('JumpAndEditWikiPageMark'));
}
}
return $r;
}
sub make_urilink ($;%) {
require URI;
my $uri = shift;
if ($uri =~ s/^IW://) { ## InterWiki (not URI)
$uri = SuikaWiki::Plugin->unescape ($uri);
if ($uri =~ /^([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+"):([^\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+|"(?:\\.|[^"\\])+")$/) {
my ($site, $name) = ($1, $2);
for ($site, $name) {
if (s/^"//) { s/"$//; s/\\(.)/$1/g }
}
&init_InterWikiName () unless $interwiki{'[[]]'};
if ($interwiki{$site}) {
my $fmt = SuikaWiki::Plugin->formatter ('interwiki');
my $uri = SuikaWiki::Plugin->escape ($fmt->replace ($interwiki{$site} => {site => $site, name => $name}));
$site = SuikaWiki::Plugin->escape ($site);
$name = SuikaWiki::Plugin->escape ($name);
qq(<$site:$name>);
} else {
qq(<@{[SuikaWiki::Plugin->resource('Error:UnknownInterWikiName=',escape=>1)]}@{[SuikaWiki::Plugin->escape ($site)]}>);
}
} else {
qq(<@{[SuikaWiki::Plugin->resource('Error:InvalidInterWiki=',escape=>1)]}@{[SuikaWiki::Plugin->escape($uri)]}>);
}
} elsif ($uri =~ /^urn:/) { ## URN
my $uri2 = SuikaWiki::Plugin->escape (URI->new ('/uri-res/N2L?'.SuikaWiki::Plugin->unescape ($uri), 'http')->canonical);
qq(<$uri>);
} elsif ($uri =~ s/^MAIL://) { ## mail address (not URI)
my $uri2 = SuikaWiki::Plugin->escape (URI->new ('mailto:'.SuikaWiki::Plugin->unescape ($uri))->canonical);
qq(<$uri>);
} elsif ($uri =~ s/^IMG(?:\([^)]+\))?://) { ## image (not URI itself)
my $uri2 = SuikaWiki::Plugin->escape (URI->new (SuikaWiki::Plugin->unescape ($uri))->canonical);
qq(
);
} else { ## misc. URI
CGI::Carp::warningsToBrowser (0);
my $uri2 = SuikaWiki::Plugin->escape (URI->new (SuikaWiki::Plugin->unescape ($uri))->canonical);
CGI::Carp::warningsToBrowser (1);
qq(<$uri>);
}
}
sub main::init_InterWikiName {
my @content = split /\n/, $main::database{$main::PageName{InterWikiName}};
for (@content) {
if (/^([^#]\S*)\s+(\S[^\x0A\x0D]+)/) {
$main::interwiki{$1} = $2;
}
}
$main::interwiki{'[[]]'} = 1; ## dummy
}
POD:SEE ALSO:
SuikaWiki::Plugin::WikiPage (Wiki page support),
SuikaWiki::Plugin::WikiNamespace (WikiNamespace support),
SuikaWiki::Plugin::Map (n-to-n linking and page-to-page relationship)
POD:LICENSE:
Copyright 2003 Wakaba
%%GNUGPL2%%