* Add the linkify and scan hooks. These hooks can be used to implement

custom, first-class types of wikilinks.
* Move standard wikilink implementation to a new wikilink plugin, which
  will of course be enabled by default.
master
Joey Hess 2008-02-11 22:48:27 -05:00
parent 5163646e26
commit 4763514861
9 changed files with 215 additions and 119 deletions

View File

@ -37,21 +37,6 @@ sub defaultconfig () { #{{{
qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//,
qr/(^|\/)_MTN\//,
qr/\.dpkg-tmp$/],
wiki_link_regexp => qr{
\[\[(?=[^!]) # beginning of link
(?:
([^\]\|]+) # 1: link text
\| # followed by '|'
)? # optional
([^\n\r\]#]+) # 2: page to link to
(?:
\# # '#', beginning of anchor
([^\s\]]+) # 3: anchor text
)? # optional
\]\] # end of link
}x,
wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/,
verbose => 0,
@ -89,8 +74,8 @@ sub defaultconfig () { #{{{
setup => undef,
adminuser => undef,
adminemail => undef,
plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
lockedit conditional recentchanges}],
plugin => [qw{mdwn link inline htmlscrubber passwordauth openid
signinedit lockedit conditional recentchanges}],
libdir => undef,
timeformat => '%c',
locale => undef,
@ -147,24 +132,6 @@ sub checkconfig () { #{{{
umask(possibly_foolish_untaint($config{umask}));
}
if (!$config{prefix_directives}) {
$config{wiki_link_regexp} = qr{
\[\[ # beginning of link
(?:
([^\]\|\n\s]+) # 1: link text
\| # followed by '|'
)? # optional
([^\s\]#]+) # 2: page to link to
(?:
\# # '#', beginning of anchor
([^\s\]]+) # 3: anchor text
)? # optional
\]\] # end of link
}x,
}
run_hooks(checkconfig => sub { shift->() });
return 1;
@ -684,21 +651,17 @@ sub htmlize ($$$) { #{{{
} #}}}
sub linkify ($$$) { #{{{
my $lpage=shift; # the page containing the links
my $page=shift; # the page the link will end up on (different for inline)
my $page=shift;
my $destpage=shift;
my $content=shift;
$content =~ s{(\\?)$config{wiki_link_regexp}}{
defined $2
? ( $1
? "[[$2|$3".($4 ? "#$4" : "")."]]"
: htmllink($lpage, $page, linkpage($3),
anchor => $4, linktext => pagetitle($2)))
: ( $1
? "[[$3".($4 ? "#$4" : "")."]]"
: htmllink($lpage, $page, linkpage($3),
anchor => $4))
}eg;
run_hooks(linkify => sub {
$content=shift->(
page => $page,
destpage => $page,
content => $content,
);
});
return $content;
} #}}}

View File

@ -0,0 +1,83 @@
#!/usr/bin/perl
package IkiWiki::Plugin::link;
use warnings;
use strict;
use IkiWiki 2.00;
my $link_regexp;
sub import { #{{{
hook(type => "checkconfig", id => "link", call => \&checkconfig);
hook(type => "linkify", id => "link", call => \&linkify);
hook(type => "scan", id => "link", call => \&scan);
} # }}}
sub checkconfig () { #{{{
if ($config{prefix_directives}) {
$link_regexp = qr{
\[\[(?=[^!]) # beginning of link
(?:
([^\]\|]+) # 1: link text
\| # followed by '|'
)? # optional
([^\n\r\]#]+) # 2: page to link to
(?:
\# # '#', beginning of anchor
([^\s\]]+) # 3: anchor text
)? # optional
\]\] # end of link
}x;
}
else {
$link_regexp = qr{
\[\[ # beginning of link
(?:
([^\]\|\n\s]+) # 1: link text
\| # followed by '|'
)? # optional
([^\s\]#]+) # 2: page to link to
(?:
\# # '#', beginning of anchor
([^\s\]]+) # 3: anchor text
)? # optional
\]\] # end of link
}x,
}
} #}}}
sub linkify (@) { #{{{
my %params=@_;
my $page=$params{page};
my $destpage=$params{destpage};
$params{content} =~ s{(\\?)$link_regexp}{
defined $2
? ( $1
? "[[$2|$3".($4 ? "#$4" : "")."]]"
: htmllink($page, $destpage, IkiWiki::linkpage($3),
anchor => $4, linktext => IkiWiki::pagetitle($2)))
: ( $1
? "[[$3".($4 ? "#$4" : "")."]]"
: htmllink($page, $destpage, IkiWiki::linkpage($3),
anchor => $4))
}eg;
return $params{content};
} #}}}
sub scan (@) { #{{{
my %params=@_;
my $page=$params{page};
my $content=$params{content};
while ($content =~ /(?<!\\)$link_regexp/g) {
push @{$links{$page}}, IkiWiki::linkpage($2);
}
} # }}}
1

View File

@ -14,6 +14,8 @@ sub import { #{{{
hook(type => "needsbuild", id => "skeleton", call => \&needsbuild);
hook(type => "preprocess", id => "skeleton", call => \&preprocess);
hook(type => "filter", id => "skeleton", call => \&filter);
hook(type => "linkify", id => "skeleton", call => \&linkify);
hook(type => "scan", id => "skeleton", call => \&scan);
hook(type => "htmlize", id => "skeleton", call => \&htmlize);
hook(type => "sanitize", id => "skeleton", call => \&sanitize);
hook(type => "format", id => "skeleton", call => \&format);
@ -57,6 +59,20 @@ sub filter (@) { #{{{
return $params{content};
} # }}}
sub linkify (@) { #{{{
my %params=@_;
debug("skeleton plugin running as linkify");
return $params{content};
} # }}}
sub scan (@) { #{{{a
my %params=@_;
debug("skeleton plugin running as scan");
} # }}}
sub htmlize (@) { #{{{
my %params=@_;

View File

@ -166,16 +166,21 @@ sub scan ($) { #{{{
# to the content.
$content=filter($page, $page, $content);
my @links;
while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
push @links, linkpage($2);
}
if ($config{discussion}) {
# Discussion links are a special case since they're
# not in the text of the page, but on its template.
push @links, $page."/".gettext("discussion");
$links{$page}=[ $page."/".gettext("discussion") ];
}
$links{$page}=\@links;
else {
$links{$page}=[];
}
run_hooks(scan => sub {
shift->(
page => $page,
content => $content,
);
});
# Preprocess in scan-only mode.
preprocess($page, $page, $content, 1);

4
debian/changelog vendored
View File

@ -14,6 +14,10 @@ ikiwiki (2.40) UNRELEASED; urgency=low
of XML::RPC's default of us-ascii. Allows interoperation with
python's xmlrpc library, which threw invalid encoding exceptions and
caused the rst plugin to hang.
* Add the linkify and scan hooks. These hooks can be used to implement
custom, first-class types of wikilinks.
* Move standard wikilink implementation to a new wikilink plugin, which
will of course be enabled by default.
-- Josh Triplett <josh@freedesktop.org> Sun, 10 Feb 2008 13:18:58 -0800

View File

@ -0,0 +1,4 @@
[[template id=plugin name=link core=1 author="[[Joey]]"]]
[[tag type/link]]
This plugin implements standard [[WikiLinks|WikiLink]].

View File

@ -142,6 +142,28 @@ format at preprocessor time. Text output by a preprocessor directive will
be linkified and passed through markdown (or whatever engine is used to
htmlize the page) along with the rest of the page.
### linkify
hook(type => "linkify", id => "foo", call => \&linkify);
This hook is called to convert [[WikiLinks|WikiLink]] on the page into html
links. The function is passed named parameters "page", "destpage", and
"content". It should return the linkified content.
Plugins that implement linkify must also implement a scan hook, that scans
for the links on the page and adds them to `%links`.
### scan
hook(type => "scan", id => "foo", call => \&scan);
This hook is called early in the process of building the wiki, and is used
as a first pass scan of the page, to collect metadata about the page. It's
mostly used to scan the page for WikiLinks, and add them to `%links`.
The function is passed named parameters "page" and "content". Its return
value is ignored.
### htmlize
hook(type => "htmlize", id => "ext", call => \&htmlize);

View File

@ -1,4 +1,3 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
@ -8,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ikiwiki\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-02-03 14:52-0500\n"
"POT-Creation-Date: 2008-02-11 00:48-0500\n"
"PO-Revision-Date: 2008-02-11 00:12+0100\n"
"Last-Translator: Jonas Smedegaard <dr@jones.dk>\n"
"Language-Team: Danish <dansk@klid.dk>\n"
@ -48,89 +47,89 @@ msgstr "Indstillinger gemt"
msgid "%s is not an editable page"
msgstr "%s er ikke en redigérbar side"
#: ../IkiWiki/CGI.pm:382 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:241 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/CGI.pm:384 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:242 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:95
#: ../IkiWiki/Render.pm:175
#: ../IkiWiki/Render.pm:176
msgid "discussion"
msgstr "diskussion"
#: ../IkiWiki/CGI.pm:429
#: ../IkiWiki/CGI.pm:431
#, perl-format
msgid "creating %s"
msgstr "opretter %s"
#: ../IkiWiki/CGI.pm:447 ../IkiWiki/CGI.pm:466 ../IkiWiki/CGI.pm:476
#: ../IkiWiki/CGI.pm:510 ../IkiWiki/CGI.pm:554
#: ../IkiWiki/CGI.pm:449 ../IkiWiki/CGI.pm:467 ../IkiWiki/CGI.pm:477
#: ../IkiWiki/CGI.pm:511 ../IkiWiki/CGI.pm:555
#, perl-format
msgid "editing %s"
msgstr "redigerer %s"
#: ../IkiWiki/CGI.pm:643
#: ../IkiWiki/CGI.pm:644
msgid "You are banned."
msgstr "Du er banlyst."
#: ../IkiWiki/Plugin/aggregate.pm:72
#: ../IkiWiki/Plugin/aggregate.pm:101
#, perl-format
msgid "missing %s parameter"
msgstr "mangler parametren %s"
#: ../IkiWiki/Plugin/aggregate.pm:100
#: ../IkiWiki/Plugin/aggregate.pm:128
msgid "new feed"
msgstr "ny fødning"
#: ../IkiWiki/Plugin/aggregate.pm:114
#: ../IkiWiki/Plugin/aggregate.pm:142
msgid "posts"
msgstr "indlæg"
#: ../IkiWiki/Plugin/aggregate.pm:116
#: ../IkiWiki/Plugin/aggregate.pm:144
msgid "new"
msgstr "nyt"
#: ../IkiWiki/Plugin/aggregate.pm:232
#: ../IkiWiki/Plugin/aggregate.pm:309
#, perl-format
msgid "expiring %s (%s days old)"
msgstr "udløber %s (%s dage gammel)"
#: ../IkiWiki/Plugin/aggregate.pm:239
#: ../IkiWiki/Plugin/aggregate.pm:316
#, perl-format
msgid "expiring %s"
msgstr "udløber %s"
#: ../IkiWiki/Plugin/aggregate.pm:265
#: ../IkiWiki/Plugin/aggregate.pm:345
#, perl-format
msgid "processed ok at %s"
msgstr "korrekt dannet ved %s"
#: ../IkiWiki/Plugin/aggregate.pm:270
#: ../IkiWiki/Plugin/aggregate.pm:349
#, perl-format
msgid "checking feed %s ..."
msgstr "undersøger fødning %s ..."
#: ../IkiWiki/Plugin/aggregate.pm:275
#: ../IkiWiki/Plugin/aggregate.pm:354
#, perl-format
msgid "could not find feed at %s"
msgstr "kunne ikke finde fødning ved %s"
#: ../IkiWiki/Plugin/aggregate.pm:290
#: ../IkiWiki/Plugin/aggregate.pm:369
msgid "feed not found"
msgstr "fødning ikke fundet"
#: ../IkiWiki/Plugin/aggregate.pm:301
#: ../IkiWiki/Plugin/aggregate.pm:380
#, perl-format
msgid "(invalid UTF-8 stripped from feed)"
msgstr "(defekt UTF-8 fjernet fra fødning)"
#: ../IkiWiki/Plugin/aggregate.pm:307
#: ../IkiWiki/Plugin/aggregate.pm:386
#, perl-format
msgid "(feed entities escaped)"
msgstr "(fødningselementer omgået (escaped))"
#: ../IkiWiki/Plugin/aggregate.pm:313
#: ../IkiWiki/Plugin/aggregate.pm:392
msgid "feed crashed XML::Feed!"
msgstr "fødning fik XML::Feed til at bryde sammen!"
#: ../IkiWiki/Plugin/aggregate.pm:387
#: ../IkiWiki/Plugin/aggregate.pm:466
#, perl-format
msgid "creating new page %s"
msgstr "opretter ny side %s"
@ -203,29 +202,29 @@ msgstr "Ændring af størrelse mislykkedes: %s"
msgid "failed to determine size of image %s"
msgstr "Vurdering af størrelse på billede mislykkedes: %s"
#: ../IkiWiki/Plugin/inline.pm:42
#: ../IkiWiki/Plugin/inline.pm:44
msgid "Must specify url to wiki with --url when using --rss or --atom"
msgstr "Skal angive url til wiki med --url når --rss eller --atom anvendes"
#: ../IkiWiki/Plugin/inline.pm:135
#: ../IkiWiki/Plugin/inline.pm:136
#, perl-format
msgid "unknown sort type %s"
msgstr "ukendt sorteringsform %s"
#: ../IkiWiki/Plugin/inline.pm:200
#: ../IkiWiki/Plugin/inline.pm:201
msgid "Add a new post titled:"
msgstr "Tilføj nyt indlæg med følgende titel:"
#: ../IkiWiki/Plugin/inline.pm:216
#: ../IkiWiki/Plugin/inline.pm:217
#, perl-format
msgid "nonexistant template %s"
msgstr "ikke-eksisterende skabelon: %s"
#: ../IkiWiki/Plugin/inline.pm:249 ../IkiWiki/Render.pm:99
#: ../IkiWiki/Plugin/inline.pm:250 ../IkiWiki/Render.pm:99
msgid "Discussion"
msgstr "Diskussion"
#: ../IkiWiki/Plugin/inline.pm:463
#: ../IkiWiki/Plugin/inline.pm:468
msgid "RPC::XML::Client not found, not pinging"
msgstr "RPC::XML::Client ikke fundet, pinger ikke"
@ -245,15 +244,15 @@ msgstr ""
"Indlæsning af perl-modulet Markdown.pm (%s) eller /usr/bin/markdown (%s) "
"mislykkedes"
#: ../IkiWiki/Plugin/meta.pm:119
#: ../IkiWiki/Plugin/meta.pm:132
msgid "stylesheet not found"
msgstr "stilsnit (stylesheet) ikke fundet"
#: ../IkiWiki/Plugin/meta.pm:143
#: ../IkiWiki/Plugin/meta.pm:158
msgid "redir page not found"
msgstr "henvisningsside ikke fundet"
#: ../IkiWiki/Plugin/meta.pm:156
#: ../IkiWiki/Plugin/meta.pm:171
msgid "redir cycle is not allowed"
msgstr "ring af henvisninger er ikke tilladt"
@ -517,47 +516,47 @@ msgstr "(kan ikke omskiftes i et smugkig)"
msgid "getctime not implemented"
msgstr "getctime ikke implementeret"
#: ../IkiWiki/Render.pm:273 ../IkiWiki/Render.pm:294
#: ../IkiWiki/Render.pm:274 ../IkiWiki/Render.pm:295
#, perl-format
msgid "skipping bad filename %s"
msgstr "udelader forkert filnavn %s"
#: ../IkiWiki/Render.pm:343
#: ../IkiWiki/Render.pm:350
#, perl-format
msgid "removing old page %s"
msgstr "fjerner gammel side %s"
#: ../IkiWiki/Render.pm:384
#: ../IkiWiki/Render.pm:391
#, perl-format
msgid "scanning %s"
msgstr "gennemlæser %s"
#: ../IkiWiki/Render.pm:389
#: ../IkiWiki/Render.pm:396
#, perl-format
msgid "rendering %s"
msgstr "danner %s"
#: ../IkiWiki/Render.pm:410
#: ../IkiWiki/Render.pm:417
#, perl-format
msgid "rendering %s, which links to %s"
msgstr "danner %s, som henviser til %s"
#: ../IkiWiki/Render.pm:431
#: ../IkiWiki/Render.pm:438
#, perl-format
msgid "rendering %s, which depends on %s"
msgstr "danner %s, som afhænger af %s"
#: ../IkiWiki/Render.pm:470
#: ../IkiWiki/Render.pm:477
#, perl-format
msgid "rendering %s, to update its backlinks"
msgstr "danner %s, for at opdatere dens krydshenvisninger (backlinks)"
#: ../IkiWiki/Render.pm:482
#: ../IkiWiki/Render.pm:489
#, perl-format
msgid "removing %s, no longer rendered by %s"
msgstr "fjerner %s, ikke længere dannet af %s"
#: ../IkiWiki/Render.pm:508
#: ../IkiWiki/Render.pm:515
#, perl-format
msgid "ikiwiki: cannot render %s"
msgstr "ikiwiki: kan ikke danne %s"
@ -621,15 +620,15 @@ msgstr "Korrekt bygget %s"
msgid "usage: ikiwiki [options] source dest"
msgstr "brug: ikiwiki [valg] kilde mål"
#: ../ikiwiki.in:81
#: ../ikiwiki.in:82
msgid "usage: --set var=value"
msgstr "brug: --set var=værdi"
#: ../IkiWiki.pm:127
#: ../IkiWiki.pm:130
msgid "Must specify url to wiki with --url when using --cgi"
msgstr "Skal angive url til wiki med --url når der bruges --cgi"
#: ../IkiWiki.pm:196 ../IkiWiki.pm:197
#: ../IkiWiki.pm:217 ../IkiWiki.pm:218
msgid "Error"
msgstr "Fejl"
@ -637,7 +636,7 @@ msgstr "Fejl"
#. translators: preprocessor directive name,
#. translators: the second a page name, the
#. translators: third a number.
#: ../IkiWiki.pm:750
#: ../IkiWiki.pm:772
#, perl-format
msgid "%s preprocessing loop detected on %s at depth %i"
msgstr "%s forudberegningssløkke fundet på %s ved dybde %i"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-02-09 23:08-0500\n"
"POT-Creation-Date: 2008-02-11 22:46-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -48,7 +48,7 @@ msgstr ""
#: ../IkiWiki/CGI.pm:384 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:242 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:95
#: ../IkiWiki/Render.pm:176
#: ../IkiWiki/Render.pm:172
msgid "discussion"
msgstr ""
@ -240,15 +240,15 @@ msgstr ""
msgid "failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"
msgstr ""
#: ../IkiWiki/Plugin/meta.pm:119
#: ../IkiWiki/Plugin/meta.pm:132
msgid "stylesheet not found"
msgstr ""
#: ../IkiWiki/Plugin/meta.pm:143
#: ../IkiWiki/Plugin/meta.pm:158
msgid "redir page not found"
msgstr ""
#: ../IkiWiki/Plugin/meta.pm:156
#: ../IkiWiki/Plugin/meta.pm:171
msgid "redir cycle is not allowed"
msgstr ""
@ -512,47 +512,47 @@ msgstr ""
msgid "getctime not implemented"
msgstr ""
#: ../IkiWiki/Render.pm:274 ../IkiWiki/Render.pm:295
#: ../IkiWiki/Render.pm:279 ../IkiWiki/Render.pm:300
#, perl-format
msgid "skipping bad filename %s"
msgstr ""
#: ../IkiWiki/Render.pm:350
#: ../IkiWiki/Render.pm:355
#, perl-format
msgid "removing old page %s"
msgstr ""
#: ../IkiWiki/Render.pm:391
#: ../IkiWiki/Render.pm:396
#, perl-format
msgid "scanning %s"
msgstr ""
#: ../IkiWiki/Render.pm:396
#: ../IkiWiki/Render.pm:401
#, perl-format
msgid "rendering %s"
msgstr ""
#: ../IkiWiki/Render.pm:417
#: ../IkiWiki/Render.pm:422
#, perl-format
msgid "rendering %s, which links to %s"
msgstr ""
#: ../IkiWiki/Render.pm:438
#: ../IkiWiki/Render.pm:443
#, perl-format
msgid "rendering %s, which depends on %s"
msgstr ""
#: ../IkiWiki/Render.pm:477
#: ../IkiWiki/Render.pm:482
#, perl-format
msgid "rendering %s, to update its backlinks"
msgstr ""
#: ../IkiWiki/Render.pm:489
#: ../IkiWiki/Render.pm:494
#, perl-format
msgid "removing %s, no longer rendered by %s"
msgstr ""
#: ../IkiWiki/Render.pm:515
#: ../IkiWiki/Render.pm:520
#, perl-format
msgid "ikiwiki: cannot render %s"
msgstr ""
@ -616,15 +616,15 @@ msgstr ""
msgid "usage: ikiwiki [options] source dest"
msgstr ""
#: ../ikiwiki.in:81
#: ../ikiwiki.in:82
msgid "usage: --set var=value"
msgstr ""
#: ../IkiWiki.pm:129
#: ../IkiWiki.pm:115
msgid "Must specify url to wiki with --url when using --cgi"
msgstr ""
#: ../IkiWiki.pm:198 ../IkiWiki.pm:199
#: ../IkiWiki.pm:184 ../IkiWiki.pm:185
msgid "Error"
msgstr ""
@ -632,7 +632,7 @@ msgstr ""
#. translators: preprocessor directive name,
#. translators: the second a page name, the
#. translators: third a number.
#: ../IkiWiki.pm:752
#: ../IkiWiki.pm:735
#, perl-format
msgid "%s preprocessing loop detected on %s at depth %i"
msgstr ""