]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge branch 'master' into dependency-types
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 11 Oct 2009 20:54:23 +0000 (16:54 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Sun, 11 Oct 2009 20:54:23 +0000 (16:54 -0400)
Conflicts:
debian/changelog
doc/plugins/calendar.mdwn

debian/changelog
doc/examples/blog.mdwn
doc/ikiwiki-calendar.mdwn [new file with mode: 0644]
doc/ikiwiki/directive/calendar.mdwn
doc/plugins/calendar.mdwn
doc/plugins/contrib/groupfile.mdwn [new file with mode: 0644]
doc/plugins/lockedit/discussion.mdwn [new file with mode: 0644]
doc/sandbox.mdwn
ikiwiki-calendar [new file with mode: 0755]
templates/calendarmonth.tmpl [new file with mode: 0644]
templates/calendaryear.tmpl [new file with mode: 0644]

index 442619b3bcdbf62d240be336f861f9bc1120797f..0e288dd08a2aaba2b7846dff4e430aa7c9e34abe 100644 (file)
@@ -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
 
index 2155d7feab627bb733b681eb2f494678b0b8f0c5..f542cad0cc7f0eda437975610f804d284f552a43 100644 (file)
@@ -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 (file)
index 0000000..e2cc612
--- /dev/null
@@ -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
index 8a257d6ebe2ee5bdc4c74e58c9dff206381d4555..b2ac75b11694eed8cc67178cf2508814ee30f96d 100644 (file)
@@ -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
 
index 8ade7000444694a2269164a03f31ca9607f1b38d..bc1bc6c716b6101ecd36c1bab472e8d03668b042 100644 (file)
@@ -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 (file)
index 0000000..e5c0ded
--- /dev/null
@@ -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 (file)
index 0000000..b058b2b
--- /dev/null
@@ -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;
+    }
index 242ffb3278ed502ea98d5dafe84c58604df08808..8aedcbb9e6beafb9dfff37d14161acb47e34fbb9 100644 (file)
@@ -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 (executable)
index 0000000..ec572cb
--- /dev/null
@@ -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 (file)
index 0000000..37ad78c
--- /dev/null
@@ -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 (file)
index 0000000..714bd6d
--- /dev/null
@@ -0,0 +1 @@
+[[!calendar type=year year=<TMPL_VAR YEAR> pages="<TMPL_VAR PAGESPEC>"]]