aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-10-11 16:54:23 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-10-11 16:54:23 -0400
commita7cb3090902e23e2b0f2371539ade7ec5a4ba01b (patch)
tree1f97182b72da88c2f3d49980101242b8b5d073a2
parent5dba91cdc88c01ac1d314f24b12eb2cda651e206 (diff)
parent665da89c270f98e93b1eaa89e729f3975973ab8f (diff)
downloadikiwiki-a7cb3090902e23e2b0f2371539ade7ec5a4ba01b.tar
ikiwiki-a7cb3090902e23e2b0f2371539ade7ec5a4ba01b.tar.gz
Merge branch 'master' into dependency-types
Conflicts: debian/changelog doc/plugins/calendar.mdwn
-rw-r--r--debian/changelog4
-rw-r--r--doc/examples/blog.mdwn4
-rw-r--r--doc/ikiwiki-calendar.mdwn51
-rw-r--r--doc/ikiwiki/directive/calendar.mdwn29
-rw-r--r--doc/plugins/calendar.mdwn8
-rw-r--r--doc/plugins/contrib/groupfile.mdwn105
-rw-r--r--doc/plugins/lockedit/discussion.mdwn21
-rw-r--r--doc/sandbox.mdwn9
-rwxr-xr-xikiwiki-calendar59
-rw-r--r--templates/calendarmonth.tmpl3
-rw-r--r--templates/calendaryear.tmpl1
11 files changed, 272 insertions, 22 deletions
diff --git a/debian/changelog b/debian/changelog
index 442619b3b..0e288dd08 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,8 +26,10 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low
The old interface will be removed soon, and a warning will be printed
if any plugins try to use it.
* Transitive dependencies are now correctly supported.
+ * ikiwiki-calendar: New command automates creation of archive pages
+ using the calendar plugin.
- -- Joey Hess <joeyh@debian.org> Fri, 09 Oct 2009 20:13:27 -0400
+ -- Joey Hess <joeyh@debian.org> Fri, 09 Oct 2009 19:53:50 -0400
ikiwiki (3.20091009) unstable; urgency=low
diff --git a/doc/examples/blog.mdwn b/doc/examples/blog.mdwn
index 2155d7fea..f542cad0c 100644
--- a/doc/examples/blog.mdwn
+++ b/doc/examples/blog.mdwn
@@ -23,3 +23,7 @@ Some additional configuration you might want to do:
enable comments to posts to the blog:
comments_pagespec => 'blog/posts/* and !*/Discussion',
+
+* Enable the [[calendar|plugins/calendar]] plugin and run the
+ [[ikiwiki-calendar]] command from cron daily to get an interlinked
+ set of calendar archives.
diff --git a/doc/ikiwiki-calendar.mdwn b/doc/ikiwiki-calendar.mdwn
new file mode 100644
index 000000000..e2cc612f3
--- /dev/null
+++ b/doc/ikiwiki-calendar.mdwn
@@ -0,0 +1,51 @@
+# NAME
+
+ikiwiki-calendar - create calendar archive pages
+
+# SYNOPSIS
+
+ikiwiki-calendar [-f] your.setup [pagespec] [year]
+
+# DESCRIPTION
+
+`ikiwiki-calendar` creates pages that use the [[ikiwiki/directive/calendar]]
+directive, allowing the archives to be browsed one month
+at a time, with calendar-based navigation.
+
+You must specify the setup file for your wiki. The pages will
+be created inside its `srcdir`, beneath the `archivebase`
+directory used by the calendar plugin (default "archives").
+
+You will probably want to specify a [[ikiwiki/PageSpec]]
+to control which pages are included on the calendars. The
+default is all pages. To limit it to only posts in a blog,
+use something like "posts/* and !*/Discussion".
+
+It defaults to creating calendar pages for the current
+year, as well as the previous year, and the next year.
+If you specify a year, it will create pages for that year.
+
+Existing pages will not be overwritten by this command by default.
+Use the `-f` switch to force it to overwrite any existing pages.
+
+## CRONTAB
+
+While this command only needs to be run once a year to update
+the archive pages for each new year, you are recommended to set up
+a cron job to run it daily, at midnight. Then it will also update
+the calendars to highlight the current day.
+
+An example crontab:
+
+ 0 0 * * * ikiwiki-calendar ~/ikiwiki.setup "posts/* and !*/Discussion"
+
+# TEMPLATES
+
+This command uses two [[template|wikitemplates]] to generate
+the pages, `calendarmonth.tmpl` and `calendaryear.tmpl`.
+
+# AUTHOR
+
+Joey Hess <joey@ikiwiki.info>
+
+Warning: this page is automatically made into ikiwiki-calendar's man page, edit with care
diff --git a/doc/ikiwiki/directive/calendar.mdwn b/doc/ikiwiki/directive/calendar.mdwn
index 8a257d6eb..b2ac75b11 100644
--- a/doc/ikiwiki/directive/calendar.mdwn
+++ b/doc/ikiwiki/directive/calendar.mdwn
@@ -1,5 +1,4 @@
The `calendar` directive is supplied by the [[!iki plugins/calendar desc=calendar]] plugin.
-This plugin requires extra setup. See the plugin documentation for details.
This directive displays a calendar, similar to the typical calendars shown on
some blogs.
@@ -12,16 +11,28 @@ some blogs.
\[[!calendar type="year" year="2005" pages="blog/* and !*/Discussion"]]
+## setup
+
The calendar is essentially a fancy front end to archives of previous
pages, usually used for blogs. It can produce a calendar for a given month,
-or a list of months for a given year.
-
-The month format calendar simply links to any page posted on each
-day of the month. The year format calendar links to archive pages, with
-names like `archives/2007` (for all of 2007) and `archives/2007/01`
-(for January, 2007). For this to work, you'll need to create these archive
-pages. They typically use [[inline]] to display or list pages created in
-the given time frame.
+or a list of months for a given year. The month format calendar simply
+links to any page posted on each day of the month. The year format calendar
+links to archive pages, with names like `archives/2007` (for all of 2007)
+and `archives/2007/01` (for January, 2007).
+
+While you can insert calendar directives anywhere on your wiki, including
+in the sidebar, you'll also need to create these archive pages. They
+typically use this directive to display a calendar, and also use [[inline]]
+to display or list pages created in the given time frame.
+
+The `ikiwiki-calendar` command can be used to automatically generate the
+archive pages. It also refreshes the wiki, updating the calendars to
+highlight the current day. This command is typically run at midnight from
+cron. An example crontab:
+
+An example crontab:
+
+ 0 0 * * * ikiwiki-calendar ~/ikiwiki.setup "posts/* and !*/Discussion"
## usage
diff --git a/doc/plugins/calendar.mdwn b/doc/plugins/calendar.mdwn
index 8ade70004..bc1bc6c71 100644
--- a/doc/plugins/calendar.mdwn
+++ b/doc/plugins/calendar.mdwn
@@ -3,13 +3,9 @@
This plugin provides a [[ikiwiki/directive/calendar]] [[ikiwiki/directive]].
The directive displays a calendar, similar to the typical calendars shown on
-some blogs.
+some blogs.
-Since ikiwiki is a wiki compiler, to keep the calendar up-to-date,
-wikis that include it need to be periodically refreshed, typically by cron
-at midnight. Example crontab:
-
- 0 0 * * * ikiwiki -setup ~/ikiwiki.setup -refresh
+The [[ikiwiki-calendar]] command is used to keep the calendar up-to-date.
## CSS
diff --git a/doc/plugins/contrib/groupfile.mdwn b/doc/plugins/contrib/groupfile.mdwn
new file mode 100644
index 000000000..e5c0ded42
--- /dev/null
+++ b/doc/plugins/contrib/groupfile.mdwn
@@ -0,0 +1,105 @@
+[[!template id=plugin name=groupfile core=0 author="[[Jogo]]"]]
+
+This plugin add a `group(groupname)` function to [[ikiwiki/PageSpec]], which is true
+only if the actual user is member of the group named `groupname`.
+
+Groups membership are read from a file. The syntax of this file is very close to
+usual `/etc/passwd` Unix file : the group's name, followed by a colon, followed by
+a coma separated list of user's names. For exemple :
+
+ dev:toto,foo
+ i18n:zorba
+
+-----
+
+ #!/usr/bin/perl
+ # GroupFile plugin.
+ # by Joseph Boudou <jogo at matabio dot net>
+
+ package IkiWiki::Plugin::groupfile;
+
+ use warnings;
+ use strict;
+ use IkiWiki 3.00;
+
+ sub import {
+ hook(type => 'getsetup', id => 'groups', call => \&get_setup);
+ }
+
+ sub get_setup () {
+ return (
+ plugin => {
+ safe => 0,
+ rebuild => 0,
+ },
+ group_file => {
+ type => 'string',
+ example => '/etc/ikiwiki/group',
+ description => 'group file location',
+ safe => 0,
+ rebuild => 0,
+ },
+ );
+ }
+
+ my $users_of = 0;
+
+ sub get_groups () {
+ if (not $users_of) {
+
+ if (not defined $config{group_file}) {
+ return 'group_file option not set';
+ }
+
+ open my $file, '<', $config{group_file}
+ or return 'Unable to open group_file';
+
+ $users_of = {};
+ READ:
+ while (<$file>) {
+ next READ if (/^\s*$/);
+
+ if (/^(\w+):([\w,]+)/) {
+ %{ $users_of->{$1} } = map { $_ => 1 } split /,/, $2;
+ }
+ else {
+ $users_of = "Error at group_file:$.";
+ last READ;
+ }
+ }
+
+ close $file;
+ }
+
+ return $users_of;
+ }
+
+ package IkiWiki::PageSpec;
+
+ sub match_group ($$;@) {
+ shift;
+ my $group = shift;
+ my %params = @_;
+
+ if (not exists $params{user}) {
+ return IkiWiki::ErrorReason->new('no user specified');
+ }
+ if (not defined $params{user}) {
+ return IkiWiki::FailReason->new('not logged in');
+ }
+
+ my $users_of = IkiWiki::Plugin::groupfile::get_groups();
+ if (not ref $users_of) {
+ return IkiWiki::ErrorReason->new($users_of);
+ }
+
+ if (exists $users_of->{$group}{ $params{user} }) {
+ return IkiWiki::SuccessReason->new("user is member of $group");
+ }
+ else {
+ return IkiWiki::FailReason->new(
+ "user $params{user} isn't member of $group");
+ }
+ }
+
+ 1
diff --git a/doc/plugins/lockedit/discussion.mdwn b/doc/plugins/lockedit/discussion.mdwn
new file mode 100644
index 000000000..b058b2b07
--- /dev/null
+++ b/doc/plugins/lockedit/discussion.mdwn
@@ -0,0 +1,21 @@
+This plugin not only locks pages but ensures too a user is logged in. This seems to me redundant with signedit. I propose :
+
+ sub canedit ($$) {
+ my $page=shift;
+ my $cgi=shift;
+ my $session=shift;
+
+ my $user=$session->param("name");
+ return undef if defined $user && IkiWiki::is_admin($user);
+
+ if (defined $config{locked_pages} && length $config{locked_pages} &&
+ pagespec_match($page, $config{locked_pages},
+ user => $session->param("name"),
+ ip => $ENV{REMOTE_ADDR},
+ )) {
+ return sprintf(gettext("%s is locked and cannot be edited"),
+ htmllink("", "", $page, noimageinline => 1));
+ }
+
+ return undef;
+ }
diff --git a/doc/sandbox.mdwn b/doc/sandbox.mdwn
index 242ffb327..8aedcbb9e 100644
--- a/doc/sandbox.mdwn
+++ b/doc/sandbox.mdwn
@@ -1,10 +1,5 @@
This is the [[SandBox]], a page anyone can edit to try out ikiwiki (version [[!version ]]).
-Here's a paragraph.
-
-Here's another one with *emphasised* text.
-
-test 2
# Header
@@ -57,8 +52,10 @@ Bulleted list
[[!progress percent=27]]
+[[!progress percent=78]]
+
-----
-This SandBox is also a [[blog]]!
+This **SandBox** is also a [[blog]]!
[[!inline pages="sandbox/* and !*/Discussion" rootpage="sandbox" show="4" archive="yes"]]
diff --git a/ikiwiki-calendar b/ikiwiki-calendar
new file mode 100755
index 000000000..ec572cb7c
--- /dev/null
+++ b/ikiwiki-calendar
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use IkiWiki;
+use IkiWiki::Setup;
+use Getopt::Long;
+
+sub usage () {
+ die gettext("usage: ikiwiki-calendar [-f] your.setup [pagespec] [year]"), "\n";
+}
+
+my $force=0;
+GetOptions(
+ "force" => \$force,
+) || usage();
+my $setup=shift || usage();
+my $pagespec=shift || "*";
+my $year=shift || 1900+(localtime(time))[5];
+
+%config=IkiWiki::defaultconfig();
+IkiWiki::Setup::load($setup);
+IkiWiki::loadplugins();
+IkiWiki::checkconfig();
+
+my $archivebase = 'archives';
+$archivebase = $config{archivebase} if defined $config{archivebase};
+
+sub writearchive ($$;$) {
+ my $template=template(shift);
+ my $year=shift;
+ my $month=shift;
+
+ my $page=defined $month ? "$year/$month" : $year;
+
+ my $pagefile=newpagefile("$archivebase/$page", $config{default_pageext});
+ $template->param(pagespec => $pagespec);
+ $template->param(year => $year);
+ $template->param(month => $month) if defined $month;
+
+ if ($force || ! -e "$config{srcdir}/$pagefile") {
+ writefile($pagefile, $config{srcdir}, $template->output);
+ IkiWiki::rcs_add($pagefile) if $config{rcs};
+ }
+}
+
+IkiWiki::lockwiki();
+
+foreach my $y ($year-1, $year, $year+1) {
+ writearchive("calendaryear.tmpl", $y);
+ foreach my $m (qw{01 02 03 04 05 06 07 08 09 10 11 12}) {
+ writearchive("calendarmonth.tmpl", $y, $m);
+ }
+}
+
+IkiWiki::rcs_commit_staged(gettext("calendar update"), undef, undef)
+ if $config{rcs};
+IkiWiki::unlockwiki();
+
+system("ikiwiki", "-setup", $setup, "-refresh");
diff --git a/templates/calendarmonth.tmpl b/templates/calendarmonth.tmpl
new file mode 100644
index 000000000..37ad78c5c
--- /dev/null
+++ b/templates/calendarmonth.tmpl
@@ -0,0 +1,3 @@
+[[!calendar type=month month=<TMPL_VAR MONTH> year=<TMPL_VAR YEAR> pages="<TMPL_VAR PAGESPEC>"]]
+
+[[!inline pages="creation_month(<TMPL_VAR MONTH>) and creation_year(<TMPL_VAR YEAR>) and <TMPL_VAR PAGESPEC>" show=0 feeds=no reverse=yes]]
diff --git a/templates/calendaryear.tmpl b/templates/calendaryear.tmpl
new file mode 100644
index 000000000..714bd6d47
--- /dev/null
+++ b/templates/calendaryear.tmpl
@@ -0,0 +1 @@
+[[!calendar type=year year=<TMPL_VAR YEAR> pages="<TMPL_VAR PAGESPEC>"]]