#!/usr/bin/env perl
use strict;
use v5.10;
# ====================[ logout.pl ]====================
=head1 NAME
logout - An Oddmuse module for logging out the current Oddmuse user.
=head1 SYNOPSIS
logout logs out the current Oddmuse user from the current Oddmuse Wiki by
clearing that user's client-side, Oddmuse-specific HTML cookie. As this cookie
persists that user's username and and (optional) password for this Oddmuse Wiki,
clearing this cookie effectively logs that user off this Oddmuse Wiki.
Viola!
=head1 INSTALLATION
logout is easily installable: move this file into the B
directory of your Oddmuse Wiki.
=cut
AddModuleDescription('logout.pl', 'Logout Extension');
our ($q, %Action, $CommentsPrefix, $Message, $LinkPattern, $FreeLinks, $FreeLinkPattern, $SiteName, %CookieParameters);
# ....................{ CONFIGURATION }....................
=head1 CONFIGURATION
logout is easily configurable: set these variables in the B
file for your Oddmuse Wiki.
=cut
our ($CommentsSuffix,
$LogoutIsDebugging);
=head2 $CommentsSuffix
A string that, unless blank, supplants that default
"${CommentsPrefix}${PageName}" link (e.g., "Comment on Logout_Extension")
in the edit bar with a new, page-agnostic
"${CommentsPrefix}${CommentsSuffix}" link (e.g., "Comment on this page"). Since
this string is blank, by default, it performs no such replacement. Enable it by
setting the string to some non-blank value in your B file; e.g.,
$CommentsSuffix = 'this page';
If you do set this variable, please also ensure that you have set the
C<$CommentsPrefix> variable. (If that variable is not set, but this variable is,
this variable is rudely ignored. Such is life in the insensate code trenches!)
This variable's intent is to lend some minute uniformity to the edit bar. All
the edit bar's other links ("Edit this page," "View other revisions",
"Administration," and so on) are page-agnostic; these links do not reference
the current page's name. Why, then, should the comment link be any different?
While an admittedly minor point, it is a point... This variable addresses it.
Lastly. Although this variable has, clearly, little relation to the cookie-
clearing implementation of the rest of this module, this module's author
conspired no better place for it - and therefore placed it here. (Do with it
what thou wilt, museful wrangler!)
=cut
#$CommentsSuffix = 'this page';
$CommentsSuffix = '';
=head2 $LogoutIsDebugging
A boolean that, if true, prints all key-value pairs (composing the currently
requested URL query and current user's cookie) with each Oddmuse Wiki page; and,
if false, does nothing. This boolean defaults to false.
Key-value pairs are printed by appending their contents onto Oddmuse's
C<$Message> variable, which Oddmuse then tacks onto the header for each page.
=cut
$LogoutIsDebugging = '';
# ....................{ ACTIONS }....................
$Action{logout} = \&DoLogout;
=head1 ACTIONS
=head2 DoLogout
Logs the current user "out."
This erases every entry in that user's client-side, site-specific cookie, which
has several unnerving effects:
=over
=item The user's currently cached username is discarded. As the username, in
the Oddmuse security model, is an aesthetic artifice having no relation
to whether that user is an editor, administrator, or merely 'visitor',
this doesn't do very much.
=item The user's currently cached password is discarded. If the user was logged
in as editor or administrator, that user is now logged off and, hereafter,
merely considered a 'visitor'.
=item All other key-value pairs are discarded. (This might serve as a decent
mechanism for testing cookie-specific functionality in your own module,
elsewhere.)
=back
=cut
sub DoLogout {
my $id = shift;
SetParam('username', $CookieParameters{username});
SetParam('pwd', $CookieParameters{pwd});
print
GetHeader('', Ts('Logged out of %s', $SiteName), '') .
$q->div({-class=> 'content'}, $q->p(T('You are now logged out.'), $id ? $q->p(ScriptLink('action=browse;id=' . UrlEncode($id) . '&time=' . time, Ts('Return to %s', NormalToFree($id)))) : ''));
PrintFooter();
}
# ....................{ FUNCTIONS }....................
*GetFooterLinksLogoutOld = \&GetFooterLinks;
*GetFooterLinks = \&GetFooterLinksLogout;
=head1 FUNCTIONS
=head2 GetFooterLinksLogout
Appends a "Logout" link onto the edit bar in the footer of each page.
=cut
sub GetFooterLinksLogout {
my ($id, $rev) = @_;
my $footer_links = GetFooterLinksLogoutOld(@_);
if ($CommentsPrefix and $CommentsSuffix) {
$footer_links =~ s
/(\Q