* Support for looking in multiple directories for underlay files.

* Plugins can add new directories to the search path with the add_underlay
  function.
* Split out smiley underlay files into a separate underlay, so if the plugin
  isn't used, the wiki isn't bloated with all those files.
master
joey 2007-08-28 01:59:01 +00:00
parent 21c4bd8444
commit 9c5f4761d8
57 changed files with 142 additions and 89 deletions

View File

@ -17,6 +17,7 @@ use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
bestlink htmllink readfile writefile pagetype srcfile pagename bestlink htmllink readfile writefile pagetype srcfile pagename
displaytime will_render gettext urlto targetpage displaytime will_render gettext urlto targetpage
add_underlay
%config %links %renderedfiles %pagesources %destsources); %config %links %renderedfiles %pagesources %destsources);
our $VERSION = 2.00; # plugin interface version, next is ikiwiki version our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
@ -83,6 +84,7 @@ sub defaultconfig () { #{{{
pingurl => [], pingurl => [],
templatedir => "$installdir/share/ikiwiki/templates", templatedir => "$installdir/share/ikiwiki/templates",
underlaydir => "$installdir/share/ikiwiki/basewiki", underlaydir => "$installdir/share/ikiwiki/basewiki",
underlaydirs => [],
setup => undef, setup => undef,
adminuser => undef, adminuser => undef,
adminemail => undef, adminemail => undef,
@ -285,11 +287,26 @@ sub srcfile ($) { #{{{
my $file=shift; my $file=shift;
return "$config{srcdir}/$file" if -e "$config{srcdir}/$file"; return "$config{srcdir}/$file" if -e "$config{srcdir}/$file";
return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file"; foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
error("internal error: $file cannot be found in $config{srcdir} or $config{underlaydir}"); return "$dir/$file" if -e "$dir/$file";
}
error("internal error: $file cannot be found in $config{srcdir} or underlay");
return; return;
} #}}} } #}}}
sub add_underlay ($) { #{{{
my $dir=shift;
if ($dir=~/^\//) {
unshift @{$config{underlaydirs}}, $dir;
}
else {
unshift @{$config{underlaydirs}}, "$config{underlaydir}/../$dir";
}
return 1;
} #}}}
sub readfile ($;$$) { #{{{ sub readfile ($;$$) { #{{{
my $file=shift; my $file=shift;
my $binary=shift; my $binary=shift;

View File

@ -335,7 +335,8 @@ sub cgi_editpage ($$) { #{{{
# characters. # characters.
my ($page)=$form->field('page'); my ($page)=$form->field('page');
$page=titlepage(possibly_foolish_untaint($page)); $page=titlepage(possibly_foolish_untaint($page));
if (! defined $page || ! length $page || file_pruned($page, $config{srcdir}) || $page=~/^\//) { if (! defined $page || ! length $page ||
file_pruned($page, $config{srcdir}) || $page=~/^\//) {
error("bad page name"); error("bad page name");
} }
@ -512,8 +513,8 @@ sub cgi_editpage ($$) { #{{{
my $exists=-e "$config{srcdir}/$file"; my $exists=-e "$config{srcdir}/$file";
if ($form->field("do") ne "create" && if ($form->field("do") ne "create" && ! $exists &&
! $exists && ! -e "$config{underlaydir}/$file") { ! eval { srcfile($file) }) {
$form->tmpl_param("page_gone", 1); $form->tmpl_param("page_gone", 1);
$form->field(name => "do", value => "create", force => 1); $form->field(name => "do", value => "create", force => 1);
$form->tmpl_param("page_select", 0); $form->tmpl_param("page_select", 0);

View File

@ -9,6 +9,7 @@ my %smileys;
my $smiley_regexp; my $smiley_regexp;
sub import { #{{{ sub import { #{{{
add_underlay("smiley");
hook(type => "filter", id => "smiley", call => \&filter); hook(type => "filter", id => "smiley", call => \&filter);
} # }}} } # }}}

View File

@ -270,11 +270,12 @@ sub refresh () { #{{{
} }
}, },
}, $config{srcdir}); }, $config{srcdir});
foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
find({ find({
no_chdir => 1, no_chdir => 1,
wanted => sub { wanted => sub {
$_=decode_utf8($_); $_=decode_utf8($_);
if (file_pruned($_, $config{underlaydir})) { if (file_pruned($_, $dir)) {
$File::Find::prune=1; $File::Find::prune=1;
} }
elsif (! -d $_ && ! -l $_) { elsif (! -d $_ && ! -l $_) {
@ -283,9 +284,10 @@ sub refresh () { #{{{
warn(sprintf(gettext("skipping bad filename %s"), $_)."\n"); warn(sprintf(gettext("skipping bad filename %s"), $_)."\n");
} }
else { else {
# Don't add pages that are in the $f=~s/^\Q$dir\E\/?//;
# srcdir. # avoid underlaydir
$f=~s/^\Q$config{underlaydir}\E\/?//; # override attacks; see
# security.mdwn
if (! -e "$config{srcdir}/$f" && if (! -e "$config{srcdir}/$f" &&
! -l "$config{srcdir}/$f") { ! -l "$config{srcdir}/$f") {
my $page=pagename($f); my $page=pagename($f);
@ -297,7 +299,8 @@ sub refresh () { #{{{
} }
} }
}, },
}, $config{underlaydir}); }, $dir);
};
my %rendered; my %rendered;

View File

@ -32,7 +32,7 @@ ikiwiki.out: ikiwiki.in
extra_build: ikiwiki.out extra_build: ikiwiki.out
LANG= perl -I. $(extramodules) $(tflag) ikiwiki.out doc html --templatedir=templates \ LANG= perl -I. $(extramodules) $(tflag) ikiwiki.out doc html --templatedir=templates \
--underlaydir=basewiki --nousedirs\ --underlaydir=underlays/basewiki --nousedirs\
--wikiname="ikiwiki" --verbose \ --wikiname="ikiwiki" --verbose \
--exclude=/discussion --no-discussion --userdir=users \ --exclude=/discussion --no-discussion --userdir=users \
--plugin=goodstuff \ --plugin=goodstuff \
@ -49,7 +49,13 @@ extra_clean:
extra_install: extra_install:
install -d $(DESTDIR)$(PREFIX)/share/ikiwiki install -d $(DESTDIR)$(PREFIX)/share/ikiwiki
for dir in `find basewiki templates -follow -type d ! -regex '.*\.svn.*'`; do \ for dir in `cd underlays && find . -follow -type d ! -regex '.*\.svn.*'`; do \
install -d $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \
for file in `find underlays/$$dir -follow -maxdepth 1 -type f`; do \
install -m 644 $$file $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \
done; \
done
for dir in `find templates -follow -type d ! -regex '.*\.svn.*'`; do \
install -d $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \ install -d $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \
for file in `find $$dir -follow -maxdepth 1 -type f`; do \ for file in `find $$dir -follow -maxdepth 1 -type f`; do \
install -m 644 $$file $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \ install -m 644 $$file $(DESTDIR)$(PREFIX)/share/ikiwiki/$$dir; \

View File

@ -1 +0,0 @@
../doc/blog.mdwn

View File

@ -1 +0,0 @@
../doc/favicon.ico

View File

@ -1 +0,0 @@
../doc/helponformatting.mdwn

View File

@ -1 +0,0 @@
../doc/basewiki/index.mdwn

View File

@ -1 +0,0 @@
../doc/local.css

View File

@ -1 +0,0 @@
../doc/markdown.mdwn

View File

@ -1 +0,0 @@
../doc/openid.mdwn

View File

@ -1 +0,0 @@
../doc/pagespec.mdwn

View File

@ -1 +0,0 @@
../doc/preprocessordirective.mdwn

View File

@ -1 +0,0 @@
../doc/basewiki/sandbox.mdwn

View File

@ -1 +0,0 @@
../doc/shortcuts.mdwn

View File

@ -1 +0,0 @@
../doc/smileys

View File

@ -1 +0,0 @@
../doc/smileys.mdwn

View File

@ -1 +0,0 @@
../doc/style.css

View File

@ -1 +0,0 @@
../doc/subpage

View File

@ -1 +0,0 @@
../doc/subpage.mdwn

View File

@ -1 +0,0 @@
../doc/templates.mdwn

View File

@ -1 +0,0 @@
../../doc/templates/note.mdwn

View File

@ -1 +0,0 @@
../../doc/templates/popup.mdwn

View File

@ -1 +0,0 @@
../doc/wikiicons

View File

@ -1 +0,0 @@
../doc/wikilink.mdwn

9
debian/changelog vendored
View File

@ -1,8 +1,13 @@
ikiwiki (2.6.2) UNRELEASED; urgency=low ikiwiki (2.7) UNRELEASED; urgency=low
* Add an editcontent hook. * Add an editcontent hook.
* Support for looking in multiple directories for underlay files.
* Plugins can add new directories to the search path with the add_underlay
function.
* Split out smiley underlay files into a separate underlay, so if the plugin
isn't used, the wiki isn't bloated with all those files.
-- Joey Hess <joeyh@debian.org> Sun, 26 Aug 2007 16:50:24 -0400 -- Joey Hess <joeyh@debian.org> Mon, 27 Aug 2007 20:48:51 -0400
ikiwiki (2.6.1) unstable; urgency=low ikiwiki (2.6.1) unstable; urgency=low

View File

@ -13,7 +13,6 @@ It currently includes these pages:
* [[pagespec]] * [[pagespec]]
* [[PreprocessorDirective]] * [[PreprocessorDirective]]
* [[shortcuts]] * [[shortcuts]]
* [[smileys]]
* [[subpage]] * [[subpage]]
* [[wikilink]] * [[wikilink]]

View File

@ -67,7 +67,7 @@ directive:
* `quick` - Build archives in quick mode, without reading page contents for * `quick` - Build archives in quick mode, without reading page contents for
metadata. By default, this also turns off generation of any feeds. metadata. By default, this also turns off generation of any feeds.
* `template` - Specifies the template to fill out to display each inlined * `template` - Specifies the template to fill out to display each inlined
page. By default the `inlinepage` [[template|wikitemplates]] is used, while page. By default the `inlinepage` template is used, while
the `archivepage` template is used for archives. Set this parameter to the `archivepage` template is used for archives. Set this parameter to
use some other, custom template, such as the `titlepage` template that use some other, custom template, such as the `titlepage` template that
only shows post titles. Note that you should still set `archive=yes` if only shows post titles. Note that you should still set `archive=yes` if

View File

@ -0,0 +1,6 @@
The [[plugin/brokenlinks]] plugin falsely complains that
[[helponformatting]] has a broken link to [[smileys]], if the smiley plgin
is disabled. While the helponformatting page links to it inside a
conditional, and so doesn't show the link in this case, ikiwiki scans for
links w/o looking at conditionals and so still thinks the page contains the
link.

View File

@ -461,8 +461,16 @@ that corresponds to that file.
#### `srcfile($)` #### `srcfile($)`
Given the name of a source file in the wiki, searches for the file in Given the name of a source file in the wiki, searches for the file in
the source directory and the underlay directory, and returns the full the source directory and the underlay directories (most recently added
path to the first file found. underlays first), and returns the full path to the first file found.
#### `add_underlay($)`
Adds a directory to the set of underlay directories that ikiwiki will
search for files.
If the directory name is not absolute, ikiwiki will assume it is in
the parent directory of the configured underlaydir.
#### `displaytime($)` #### `displaytime($)`

View File

@ -1,7 +1,3 @@
[[if test="enabled(smiley)"
then="This wiki has smileys **enabled**."
else="This wiki has smileys **disabled**."]]
This page is used to control what smileys are supported by the wiki. This page is used to control what smileys are supported by the wiki.
Just write the text of a smiley to display it. Just write the text of a smiley to display it.

View File

@ -21,4 +21,9 @@ hackish.
> plugins were enabled. > plugins were enabled.
> >
> Using the conditionals in a page to control what other pages get built > Using the conditionals in a page to control what other pages get built
> feels complex to me, --[[Joey]] > feels complex to me.
>
> Instead, this has been implmented as the `add_underlay()` function.
> [[done]]
> --[[Joey]]

View File

@ -70,6 +70,9 @@ changes.diff:
you have something pretty specific in mind. I can talk to you about that more you have something pretty specific in mind. I can talk to you about that more
on IRC later(assuming my internet is working right). on IRC later(assuming my internet is working right).
* Basically the idea is to change `$config{underlaydir}` to an array.. * Basically the idea is to change `$config{underlaydir}` to an array..
Ok, take a look at the new `add_underlay()` function. You can now just
`add_underlay("wikiwyg")` and it'll look in
/usr/share/ikiwiki/wikiwyg/ for the files.
* When is the WIKIWYG variable in misc.tmpl used? * When is the WIKIWYG variable in misc.tmpl used?
* The WIKIWYG variable in misc.tmpl is used for the edit page. I believe that is what * The WIKIWYG variable in misc.tmpl is used for the edit page. I believe that is what
you wanted me to do (Check [Revision 3840][]). you wanted me to do (Check [Revision 3840][]).

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-08-26 13:39-0400\n" "POT-Creation-Date: 2007-08-27 21:24-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -36,34 +36,34 @@ msgstr ""
msgid "Preferences saved." msgid "Preferences saved."
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:353 #: ../IkiWiki/CGI.pm:354
#, perl-format #, perl-format
msgid "%s is not an editable page" msgid "%s is not an editable page"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:432 ../IkiWiki/Plugin/brokenlinks.pm:24 #: ../IkiWiki/CGI.pm:441 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:209 ../IkiWiki/Plugin/opendiscussion.pm:17 #: ../IkiWiki/Plugin/inline.pm:209 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:99 #: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:99
#: ../IkiWiki/Render.pm:179 #: ../IkiWiki/Render.pm:179
msgid "discussion" msgid "discussion"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:478 #: ../IkiWiki/CGI.pm:487
#, perl-format #, perl-format
msgid "creating %s" msgid "creating %s"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:496 ../IkiWiki/CGI.pm:514 ../IkiWiki/CGI.pm:524 #: ../IkiWiki/CGI.pm:505 ../IkiWiki/CGI.pm:523 ../IkiWiki/CGI.pm:533
#: ../IkiWiki/CGI.pm:550 ../IkiWiki/CGI.pm:594 #: ../IkiWiki/CGI.pm:566 ../IkiWiki/CGI.pm:610
#, perl-format #, perl-format
msgid "editing %s" msgid "editing %s"
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:688 #: ../IkiWiki/CGI.pm:704
msgid "You are banned." msgid "You are banned."
msgstr "" msgstr ""
#: ../IkiWiki/CGI.pm:708 #: ../IkiWiki/CGI.pm:724
msgid "login failed, perhaps you need to turn on cookies?" msgid "login failed, perhaps you need to turn on cookies?"
msgstr "" msgstr ""
@ -374,7 +374,7 @@ msgstr ""
msgid "shortcut %s points to <i>%s</i>" msgid "shortcut %s points to <i>%s</i>"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/smiley.pm:22 #: ../IkiWiki/Plugin/smiley.pm:23
msgid "failed to parse any smileys" msgid "failed to parse any smileys"
msgstr "" msgstr ""
@ -476,47 +476,47 @@ msgid ""
"notifications" "notifications"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:263 ../IkiWiki/Render.pm:283 #: ../IkiWiki/Render.pm:263 ../IkiWiki/Render.pm:284
#, perl-format #, perl-format
msgid "skipping bad filename %s" msgid "skipping bad filename %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:323 #: ../IkiWiki/Render.pm:326
#, perl-format #, perl-format
msgid "removing old page %s" msgid "removing old page %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:356 #: ../IkiWiki/Render.pm:359
#, perl-format #, perl-format
msgid "scanning %s" msgid "scanning %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:361 #: ../IkiWiki/Render.pm:364
#, perl-format #, perl-format
msgid "rendering %s" msgid "rendering %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:373 #: ../IkiWiki/Render.pm:376
#, perl-format #, perl-format
msgid "rendering %s, which links to %s" msgid "rendering %s, which links to %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:390 #: ../IkiWiki/Render.pm:393
#, perl-format #, perl-format
msgid "rendering %s, which depends on %s" msgid "rendering %s, which depends on %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:428 #: ../IkiWiki/Render.pm:431
#, perl-format #, perl-format
msgid "rendering %s, to update its backlinks" msgid "rendering %s, to update its backlinks"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:440 #: ../IkiWiki/Render.pm:443
#, perl-format #, perl-format
msgid "removing %s, no longer rendered by %s" msgid "removing %s, no longer rendered by %s"
msgstr "" msgstr ""
#: ../IkiWiki/Render.pm:466 #: ../IkiWiki/Render.pm:469
#, perl-format #, perl-format
msgid "ikiwiki: cannot render %s" msgid "ikiwiki: cannot render %s"
msgstr "" msgstr ""
@ -593,11 +593,11 @@ msgstr ""
msgid "usage: --set var=value" msgid "usage: --set var=value"
msgstr "" msgstr ""
#: ../IkiWiki.pm:126 #: ../IkiWiki.pm:128
msgid "Must specify url to wiki with --url when using --cgi" msgid "Must specify url to wiki with --url when using --cgi"
msgstr "" msgstr ""
#: ../IkiWiki.pm:191 ../IkiWiki.pm:192 #: ../IkiWiki.pm:193 ../IkiWiki.pm:194
msgid "Error" msgid "Error"
msgstr "" msgstr ""
@ -605,7 +605,7 @@ msgstr ""
#. translators: preprocessor directive name, #. translators: preprocessor directive name,
#. translators: the second a page name, the #. translators: the second a page name, the
#. translators: third a number. #. translators: third a number.
#: ../IkiWiki.pm:688 #: ../IkiWiki.pm:705
#, perl-format #, perl-format
msgid "%s preprocessing loop detected on %s at depth %i" msgid "%s preprocessing loop detected on %s at depth %i"
msgstr "" msgstr ""

View File

@ -1,9 +1,12 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use Test::More tests => 3; use Test::More 'no_plan';
ok(! system("make ikiwiki.out")); ok(! system("mkdir t/tmp"));
ok(! system("LANG=C perl -T -I. ./ikiwiki.out -plugin brokenlinks -rebuild -underlaydir=basewiki -templatedir=templates t/basewiki_brokenlinks t/basewiki_brokenlinks/out")); ok(! system("make -q ikiwiki.out"));
ok(`grep 'no broken links' t/basewiki_brokenlinks/out/index.html`); ok(! system("make extra_install DESTDIR=t/tmp/install PREFIX=/usr >/dev/null"));
system("rm -rf t/basewiki_brokenlinks/out t/basewiki_brokenlinks/.ikiwiki"); ok(! system("LANG= perl -T -I. ./ikiwiki.out -plugin smiley -plugin brokenlinks -rebuild -underlaydir=t/tmp/install/usr/share/ikiwiki/basewiki -templatedir=templates t/basewiki_brokenlinks t/tmp/out"));
ok(`grep 'no broken links' t/tmp/out/index.html`);
ok(-e "t/tmp/out/style.css");
ok(! system("rm -rf t/tmp t/basewiki_brokenlinks/.ikiwiki"));

View File

@ -0,0 +1 @@
../../doc/blog.mdwn

View File

@ -0,0 +1 @@
../../doc/favicon.ico

View File

@ -0,0 +1 @@
../../doc/helponformatting.mdwn

View File

@ -0,0 +1 @@
../../doc/basewiki/index.mdwn

View File

@ -0,0 +1 @@
../../doc/local.css

View File

@ -0,0 +1 @@
../../doc/markdown.mdwn

View File

@ -0,0 +1 @@
../../doc/openid.mdwn

View File

@ -0,0 +1 @@
../../doc/pagespec.mdwn

View File

@ -0,0 +1 @@
../../doc/preprocessordirective.mdwn

View File

@ -0,0 +1 @@
../../doc/basewiki/sandbox.mdwn

View File

@ -0,0 +1 @@
../../doc/shortcuts.mdwn

View File

@ -0,0 +1 @@
../../doc/style.css

View File

@ -0,0 +1 @@
../../doc/subpage

View File

@ -0,0 +1 @@
../../doc/subpage.mdwn

View File

@ -0,0 +1 @@
../../doc/templates.mdwn

View File

@ -0,0 +1 @@
../../../doc/templates/note.mdwn

View File

@ -0,0 +1 @@
../../../doc/templates/popup.mdwn

View File

@ -0,0 +1 @@
../../doc/wikiicons

View File

@ -0,0 +1 @@
../../doc/wikilink.mdwn

View File

@ -0,0 +1 @@
../../doc/smileys

View File

@ -0,0 +1 @@
../../doc/smileys.mdwn