1 # Blosxom Plugin: wikieditish
2 # Author(s): Rael Dornfest <rael@oreilly.com>
4 # Documentation: See the bottom of this file or type: perldoc wikieditish
8 # --- Configurable variables -----
10 # Should I attempt to preserve the last modified date/time when
11 # editing an existing file? (May not work on your operating system.)
12 # 0 = no (default), 1 = yes
13 $preserve_lastmodified = 0;
15 # Should editing this blog require a password?
16 # 0 = no, 1 = yes (default)
17 $require_password = 1;
19 # What is the password for editing this blog?
20 my $blog_password = '';
22 # Should editing this blog be restricted to a particular set of IPs?
23 # 0 = no (default), 1 = yes
26 # To what IPs should editing this blog be restricted?
27 @ips = qw/ 127.0.0.1 /;
29 # What file extension should I use for edited pages?
30 # (Not sure why you'd change this, but just in case...)
31 my $file_extension = $blosxom::file_extension;
33 # --------------------------------
35 # Response to wikieditish; use as $wikieditish::response in
39 # The raw title and body
40 ($title, $body) = ('', '');
42 # The password entered into the form (for prepopulating the form upon Save)
45 # --------------------------------
47 use vars qw/$require_password/;
49 use CGI qw/:standard/;
52 my $fh = new FileHandle;
54 # Strip potentially confounding bits from user-configurable variables
55 $file_extension =~ s!^\.!!;
59 # Only spring into action if POSTing to the wikieditish plug-in
60 if ( request_method() eq 'POST' and param('plugin') eq 'wikieditish' ) {
62 my($path,$fn) = $blosxom::path_info =~ m!^(?:(.*)/)?(.*)\.$blosxom::flavour!;
63 $path =~ m!^/! or $path = "/$path";
65 $password = param('password');
66 $title = param('title');
67 $body = param('body');
69 # Something's fishy with the path
71 and warn "blosxom : wikieditish plugin : something's fishy with the path, $path\n"
72 and $response = "Something didn't go as expected; page not saved."
75 # password required, but not set
76 $require_password and !$blog_password
77 and warn "blosxom : wikieditish plugin : password required but is not yet set; trying to > $blosxom::datadir$path/$fn.file_extension\n"
78 and $response = "A password is required to edit this page but one has not yet been set; page not saved."
81 # password required, set, but not correctly supplied
82 $require_password and (!param('password') or (param('password') and param('password') ne $blog_password))
83 and warn "blosxom : wikieditish plugin : incorrect password supplied for > $blosxom::datadir$path/$fn.file_extension\n"
84 and $response = "Incorrect password supplied; page not saved."
88 $restrict_by_ip and !grep(/^\Q$ENV{'REMOTE_ADDR'}\E$/, @ips)
89 and warn "blosxom : wikieditish plugin : incorrect IP address > $blosxom::datadir$path/$fn.file_extension\n"
90 and $response = "Incorrect IP address; page not saved."
93 # blosxom's $datadir is not writeable
95 and warn "blosxom : wikieditish plugin > \$blosxom::datadir, $blosxom::datadir, is not writeable.\n"
96 and $response = "Something didn't go as expected; page not saved."
99 # the destination directory for this blog entry does not yet exist
100 unless ( -d "$blosxom::datadir$path" and -w "$blosxom::datadir$path" ) {
101 warn "blosxom : wikieditish plugin : mkdir $blosxom::datadir$path\n";
102 foreach ( ('', split /\//, $path) ) {
105 -d "$blosxom::datadir/$p" or mkdir "$blosxom::datadir/$p", 0755
106 or ( warn "blosxom : wikieditish plugin : couldn't mkdir $blosxom::datadir/$p." and return 1 );
110 # If file already exists, memorize the lastmodified date/time
111 my $mtime = (stat "$blosxom::datadir$path/$fn.$file_extension")[9];
113 # If file is writeable
114 if ( $fh->open("> $blosxom::datadir$path/$fn.$file_extension") ) {
115 print $fh join "\n", $title, $body;
117 $response = "Page saved successfully.";
119 # reset lastmodified date/time to memorized value (if possible)
120 $preserve_lastmodified
121 and utime(time, $mtime, "$blosxom::datadir$path/$fn.$file_extension")
122 ? $response .= " Preserved last modified date/time."
123 : warn "blosxom : wikieditish plugin : couldn't reset lastmodified time on $blosxom::datadir$path/$fn.$file_extension.";
126 warn "couldn't > $blosxom::datadir$path/$fn.file_extension";
127 $response = "There was a problem saving this page.";
135 my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
137 unless ( param('plugin') eq 'wikieditish' ) {
139 ($title, @body) = split /\n/, $blosxom::raw;
140 $body = join "\n", @body;
153 Blosxom Plug-in: wikieditish
157 Edit a Blosxom blog wiki-style, from right in the browser.
161 Drop this wikieditish plug-in file into your plug-ins directory
162 (whatever you set as $plugin_dir in blosxom.cgi).
164 Wikieditish, being a well-behaved plug-in, won't do anything until you
165 either set a password or turn off the password requirement
166 (set $require_password = 0).
168 Move the contents of the flavours folder included in this distribution
169 into your Blosxom data directory (whatever you set as $datadir in blosxom.cgi).
170 Don't move the folder itself, only the files it contains! If you don't
171 have the the sample flavours handy, you can download them from:
173 http://www.raelity.org/apps/blosxom/downloads/plugins/wikieditish.zip
175 Point your browser at one of your Blosxom entries, specifying the wikieditish
176 flavour (e.g. http://localhost/cgi-bin/blosxom.cgi/path/to/a/post.wikieditish)
178 Edit the entry, supply your password (if required -- the default), and hit the Save button to save your changes.
180 You can just as easily create a new blog entry by pointing your browser at a non-existent filename, potentially on a non-existent path (e.g. http://localhost/cgi-bin/blosxom.cgi/path/to/a/nonexistent_post.wikieditish). Give the entry a
181 title and body, supply your password (again, if required), and hit the Save
182 button. The wikieditish plug-in will create a new blog entry for you on
183 your specified path, creating the supplied path's directory structure for you
184 on the fly if necessary.
190 =head2 SAMPLE FLAVOUR TEMPLATES
192 I've made sample flavour templates available to you to help with any
193 learning curve this plug-in might require.
195 Take a gander at the source HTML for:
197 =item * head.wikieditish, a basic head template -- nothing special.
199 =item * story.wikieditish, a basic story template -- nothing special.
201 =item * foot.wikieditish, a basic foot template just about like any other.
202 The big difference is the "edit this blog" form for editing the current
203 blog entry or creating a fresh one.
205 NOTE: The wikieditish plug-in requires the presence of a "plugin" form
206 variable with the value set to "wikieditish"; this tells the plug-in
207 that it should handle the incoming POSTing data rather than leaving it
212 =head2 FLAVOURING WIKIEDITISH
214 While there's not much in the way of template variables and the sample
215 foot.wikieditish provides about everything you'll need, here's a list of
216 variables and their purposes for your reference:
218 =item * $wikieditish::title and $wikieditish::body prepopulate the form with the values from the existing blog entry file.
220 =item * $wikieditish::password is prepopulated with the password you just entered into and submitted in the "edit this blog" form or preferences stored in a 'wikieditish' cookie, if you've the cookie plug-in installed and enabled.
224 =head2 INVITING CONTRIBUTIONS
226 The wikieditish plug-in serves dual purposes: as a browser-based editor for
227 your Blosxom blog and as a wiki-style community blog, allowing contributions
228 by a particular group of bloggers (using a shared password) or passers-by
229 (without need of a password -- true Wiki-style).
231 If you'd like to invite contribution, you can assocate an "edit" button with
234 <a href="$url$path/$fn.wikieditish">edit this blog</a>
240 Drop wikieditish into your plug-ins directory ($blosxom::plugin_dir).
244 =head2 PRESERVING LAST MODIFIED DATE/TIME ON EDITED ENTRY
246 The wikieditish plug-in can attempt to maintain the last modified date/time
247 stamp on any blog entry you're editing. Otherwise, editing an entry will
248 cause it to rise to the top of your blog like so much cream.
250 I say "attempt" since this doesn't work on every operating system
251 (it doesn't do any harm, though).
253 To turn this feature on -- it's off by default -- set the
254 $preserve_lastmodified variable to 1.
256 =head2 RESTRICTING BY PASSWORD
258 By default, the wikieditish plug-in requires a password. You'll need to
259 set one before being able to edit anything. Set the $blog_password
260 configuration variable to anything you wish
261 (e.g. my $blog_password = 'abc123';). Just be
262 sure to use something you'll remember and other's won't guess.
264 You can disable password-protection if you wish, allowing passers-by to
265 contribute to your blog, Wiki-style. Be sure this is something you want to
266 do. It has some possible security implications, anyone being able to write
267 to your server's hard drive, post to your public-facing blog, and edit
268 (read: alter, spindle, contort) any blog postings. Those warning's out of
269 the way, to turn off password-protection, set $require_password to 0.
271 =head2 RESTRICTING BY IP
273 You can alternatively decide to restrict editing to a particular IP address
274 or addresses -- those in your office, for example, or the machine actually
275 running Blosxom (127.0.0.1).
277 To do so, set $restrict_by_ip to 1 (it's off, or 0, by default), and
278 populate the @ips array with a list of approved IP addresses. By default,
279 this is set to "this machine", the machine running Blosxom; shorthand for
280 "this machine" in IP-speak is 127.0.0.1. The following example restricts
281 editing to those coming from three IPs, including 127.0.0.1:
283 # Should editing this blog be restricted to a particular set of IPs?
284 # 0 = no (default), 1 = yes
287 # To what IPs should editing this blog be restricted?
288 @ips = qw/ 127.0.0.1 10.0.0.3 140.101.22.10/;
290 Of course, you can use a combination of password-protection and IP
291 restriction if you so wish.
297 Version number is the date on which this version of the plug-in was created.
301 Rael Dornfest <rael@oreilly.com>, http://www.raelity.org/
305 The wikieditish plug-in plays nicely with the wikiwordish plug-in
306 [http://www.raelity.org/apps/blosxom/plugins/text/wikiwordish.individual]
307 for wiki-style linking action. And for wiki-style markup, be sure to try the
308 textile [http://www.raelity.org/apps/blosxom/plugins/text/textile.individual]
309 or tiki [http://www.raelity.org/apps/blosxom/plugins/text/tiki.individual]
312 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
314 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
318 Address bug reports and comments to the Blosxom mailing list
319 [http://www.yahoogroups.com/group/blosxom].
323 Blosxom and this Blosxom Plug-in
324 Copyright 2003, Rael Dornfest
326 Permission is hereby granted, free of charge, to any person obtaining a
327 copy of this software and associated documentation files (the "Software"),
328 to deal in the Software without restriction, including without limitation
329 the rights to use, copy, modify, merge, publish, distribute, sublicense,
330 and/or sell copies of the Software, and to permit persons to whom the
331 Software is furnished to do so, subject to the following conditions:
333 The above copyright notice and this permission notice shall be included
334 in all copies or substantial portions of the Software.
336 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
337 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
338 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
339 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
340 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
341 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
342 OTHER DEALINGS IN THE SOFTWARE.