1 This is a plugin that prompts the user for a title for a post, and then
2 redirects the user to post in a hierarchically organized directory
3 structure. It supports limiting blog posts only to certain users, and
4 this applies to creating new as well as editing old ones. It's a little
7 * Although Joey said specifically not to, I export the printheader
8 function so that the plugin can create a form.
9 * The form doesn't invoke the formbuilder hooks; I couldn't figure
10 out a way to do that easily from inside the plugin (unless I
11 exported run_hooks and that didn't seem right).
12 * This invokes a new hook, authcgi, although Joey said that
13 "the best approach was adding a flag that makes a cgi hook get
14 postponed and called after a session is set up". I don't know
15 if this is a good idea; authenticated CGI plugins need sessions,
16 and unauthenticated CGI plugins don't, so it seems like a new hook
18 * This creates a lot of broken parents unless you use something
19 like [[missingparents.pm]].
21 I don't expect that this will be applied; it's more like a first draft.
22 I would like to hear good ideas on how to solve the first two problems.
23 Maybe make the hook return a form, which is printed by CGI.pm? --Ethan
27 ===================================================================
28 --- IkiWiki/CGI.pm (revision 3968)
29 +++ IkiWiki/CGI.pm (working copy)
34 + run_hooks(authcgi => sub { shift->($q, $session); });
35 + my $do=$q->param('do'); # in case the hook changed it
37 if (defined $session->param("name") &&
38 userinfo_get($session->param("name"), "banned")) {
39 print $q->header(-status => "403 Forbidden");
40 Index: IkiWiki/Plugin/blogpost.pm
41 ===================================================================
42 --- IkiWiki/Plugin/blogpost.pm (revision 0)
43 +++ IkiWiki/Plugin/blogpost.pm (revision 0)
46 +# blogpost plugin: interprets cgi "blogpost" commands as create commands.
47 +package IkiWiki::Plugin::blogpost;
55 + hook(type => "checkconfig", id => "blogpost", call => \&checkconfig);
56 + hook(type => "authcgi", id => "blogpost", call => \&authcgi);
57 + hook(type => "canedit", id => "blogpost", call => \&canedit);
60 +sub checkconfig () { #{{{
61 + if (! defined $config{blogformat}){
62 + $config{blogformat} = 'posts/%Y/%m/%d/$title';
65 + if (! defined $config{blogpagespec}){
66 + my $spec = $config{blogformat};
68 + $spec =~ s/\$title/*/;
69 + $config{blogpagespec} = "$spec and ! $spec/*";
72 + if (! defined $config{blogusers}) {
73 + $config{blogusers} = (); # disallow all posting by default
77 +sub authcgi ($$) { #{{{
81 + return unless (defined $cgi->param('do') && $cgi->param('do') eq "blogpost");
82 + my $user=$session->param("name");
83 + error ("not allowed to blog, $user") unless
84 + $config{blogusers} eq "*" ||
85 + grep {$_ eq $user} $config{blogusers};
86 + eval q{use CGI::FormBuilder};
88 + my @fields=qw(title);
89 + my $form = CGI::FormBuilder->new(
91 + title => "post title",
92 + name => "post title",
99 + action => $config{cgiurl},
101 + template => {type => 'div'},
102 + stylesheet => $config{url}."/style.css",
104 + my $buttons=["Blog!"];
105 + $form->field(name => "do", type => "hidden", value => "blogpost",
107 + if (! $form->submitted){
108 + printheader($session);
109 + print misctemplate($form->title, $form->render(submit => $buttons));
113 + my $page = blogpage($form->field("title"));
114 + $cgi->param("do", "create");
115 + $cgi->param("page", $page);
120 +sub blogpage ($) { #{{{
122 + my $page=POSIX::strftime $config{blogformat}, localtime;
123 + $page =~ s/\$title/$title/;
127 +sub canedit ($$$) { #{{{
132 + return undef unless pagespec_match($page, $config{blogpagespec});
133 + my $user=$session->param("name");
134 + IkiWiki::needsignin($cgi, $session) unless defined $user;
136 + return "" if ($config{blogusers} eq "*" ||
137 + grep {$_ eq $user} $config{blogusers});
138 + return ("not allowed to blog, $user");
143 ===================================================================
144 --- IkiWiki.pm (revision 3968)
145 +++ IkiWiki.pm (working copy)
147 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
148 bestlink htmllink readfile writefile pagetype srcfile pagename
149 displaytime will_render gettext urlto targetpage
150 + misctemplate printheader
151 %config %links %renderedfiles %pagesources %destsources);
152 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
153 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE