#!/usr/bin/perl # TmNetWiki version 0.4 (September 11, 2002) # Copyright (C) 2002 Adam Brate # # Based on the GPLed UseModWiki 0.92 # Copyright (C) 2000-2001 Clifford A. Adams # or # Based on the GPLed AtisWiki 0.3 (C) 1998 Markus Denker # # ...which was based on # the LGPLed CVWiki CVS-patches (C) 1997 Peter Merel # and The Original WikiWikiWeb (C) Ward Cunningham # (code reused with permission) # Email and ThinLine options by Jim Mahoney # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc. # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 USA package Wiki::editprefs; use strict; # needs subs Wiki::login: DoNewLogin # Wiki::translate: T # Wiki::template: GetHeader, GetFormStart, GetFormText, # GetFormCheck,GetGotoBar, GetMinimumFooter, GetCommonFooter # Wiki::utility: GetParam, FreeToNormal # Wiki::calc: TimeToText # Wiki::user: UserIsAdmin, UserIsEditor, SaveUserData # Wiki::lock: RequestLock, ReleaseLock # needs consts $RCName, $EmailNotify, $ShowEdits, $RecentTop, $Now # needs vars $UserID, %UserData use base 'Exporter'; use Wiki::consts; use Wiki::login; use Wiki::translate; use Wiki::template; use Wiki::utility; use Wiki::calc; use Wiki::user; use Wiki::lock; #if ($^V and $^V gt v5.6.0) { # our @EXPORT; #else { use vars qw(@EXPORT); #} @EXPORT = qw( DoEditPrefs DoUpdatePrefs ); sub UpdateEmailList; sub UpdatePrefCheckbox; sub UpdatePrefNumber; sub DoEditPrefs { my ($check, $recentName, %labels); $recentName = $Consts->{RCName}; $recentName =~ s/_/ /g; &DoNewLogin() if ($UserID < 400); print &GetHeader('', T('Editing Preferences'), "",'editprefs'); print &GetFormStart(); print GetHiddenValue("edit_prefs", 1), "\n"; print '' . T('User Information:') . "\n"; print '
' . Ts('Your User ID number: %s', $UserID) . "\n"; print '
' . T('User Name:') . ' ', &GetFormText('username', "", 20, 50); print ' ' . T('(blank to remove, or valid page name)'); if (&GetParam("username","") ne "") { my $username = &GetParam("username"); print '

'.T('Personal page: ').&GetAuthorLink('',$username,$UserID).'
'; } print '
' . T('Set Password:') . ' ', $q->password_field(-name=>'p_password', -value=>'*', -size=>15, -maxlength=>50), ' ', T('(blank to remove password)'), '
(', T('Passwords allow sharing preferences between multiple systems by '), &ScriptLink("action=login",'logging in'), ' with your User ID number. ', T('Passwords are completely optional.'), ')'; if ($Consts->{AdminPass} ne '') { print '
', T('Administrator Password:'), ' ', $q->password_field(-name=>'p_adminpw', -value=>'*', -size=>15, -maxlength=>50), ' ', T('(blank to remove password)'), '
', T('(Administrator passwords are used for special maintenance.)'); } if (&Wiki::user::UserIsAdmin()) { print "\n
  • ".&ScriptLink("action=editlinks",'edit links'); print "\n
  • ".&ScriptLink("action=editlock",'set global edit lock'); print "\n
  • ".&ScriptLink("action=editlock&set=0",'remove global edit lock'); print "\n
  • ".&ScriptLink("action=editbanned",'edit banned IP list'); print "\n
    Outside tools:"; print "\n
  • ".'Logger'; print "\n
  • ".'Quotes'; } if ($EmailNotify) { print "
    "; print &GetFormCheck('notify', 1, T('Include this address in the site email list.')), ' ', T('(Uncheck the box to remove the address.)'); print '
    ', T('Email Address:'), ' ', &GetFormText('email', "", 30, 60); } if (&Wiki::user::UserCanEdit()) { print "
    $recentName:\n"; print '
    ', T('Default days to display:'), ' ', &GetFormText('rcdays', $RcDefault, 4, 9); print "
    ", &GetFormCheck('rcnewtop', $RecentTop, T('Most recent changes on top')); print "
    ", &GetFormCheck('rcall', 0, T('Show all changes (not just most recent)')); %labels = (0=>T('Hide minor edits'), 1=>T('Show minor edits'), 2=>T('Show only minor edits')); print '
    ', T('Minor edit display:'), ' '; print $q->popup_menu(-name=>'p_rcshowedit', -values=>[0,1,2], -labels=>\%labels, -default=>&GetParam("rcshowedit", $ShowEdits)); print "
    ", &GetFormCheck('rcchangehist', 1, T('Use "changes" as link to history')); if ($UseDiff) { print '
    ', T('Differences:'), "\n"; print "
    ", &GetFormCheck('diffrclink', 1, Ts('Show (diff) links on %s', $recentName)); print "
    ", &GetFormCheck('alldiff', 0, T('Show differences on all pages')); print " (", &GetFormCheck('norcdiff', 1, Ts('No differences on %s', $recentName)), ")"; %labels = (1=>T('Major'), 2=>T('Minor'), 3=>T('Author')); print '
    ', T('Default difference type:'), ' '; print $q->popup_menu(-name=>'p_defaultdiff', -values=>[1,2,3], -labels=>\%labels, -default=>&GetParam("defaultdiff", 1)); } print '
    ', T('Misc:'), "\n"; # Note: TZ offset is added by TimeToText, so pre-subtract to cancel. print '
    ', T('Server time:'), ' ', &TimeToText($Now-$TimeZoneOffset); print '
    ', T('Time Zone offset (hours):'), ' ', &GetFormText('tzoffset', 0, 4, 9); print '
    ', &GetFormCheck('editwide', 1, T('Use 100% wide edit area (if supported)')); print '
    ', T('Edit area rows:'), ' ', &GetFormText('editrows', 20, 4, 4), ' ', T('columns:'), ' ', &GetFormText('editcols', 65, 4, 4); print '
    ', &GetFormCheck('toplinkbar', 1, T('Show link bar on top')); print '
    ', &GetFormCheck('linkrandom', 0, T('Add "Random Page" link to link bar')); } print '
    ', $q->submit(-name=>'Save', -value=>T('Save')), "\n"; print "
    \n"; print &GetGotoBar(''); print $q->endform; print &GetMinimumFooter(); } sub DoUpdatePrefs { my ($username, $password); # All link bar settings should be updated before printing the header &UpdatePrefCheckbox("toplinkbar"); &UpdatePrefCheckbox("linkrandom"); print &GetHeader('',T('Saving Preferences'), ''); print '
    '; if ($UserID < 1001) { print '', Ts('Invalid UserID %s, preferences not saved.', $UserID), ''; if ($UserID == 111) { print '
    ', T('(Preferences require cookies, but no cookie was sent.)'); } print &GetCommonFooter(); return; } $username = &GetParam("p_username", ""); if ($FreeLinks) { $username =~ s/^\[\[(.+)\]\]/$1/; # Remove [[ and ]] if added $username = &FreeToNormal($username); $username =~ s/_/ /g; } if ($username eq "") { print T('UserName removed.'), '
    '; undef $UserData{'username'}; } elsif ((!$FreeLinks) && (!($username =~ /^$LinkPattern$/))) { print Ts('Invalid UserName %s: not saved.', $username), "
    \n"; } elsif ($FreeLinks && (!($username =~ /^$FreeLinkPattern$/))) { print Ts('Invalid UserName %s: not saved.', $username), "
    \n"; } elsif (length($username) > 50) { # Too long print T('UserName must be 50 characters or less. (not saved)'), "
    \n"; } else { print Ts('UserName %s saved.', $username), '
    '; $UserData{'username'} = $username; } $password = &GetParam("p_password", ""); if ($password eq "") { print T('Password removed.'), '
    '; undef $UserData{'password'}; } elsif ($password ne "*") { print T('Password changed.'), '
    '; $UserData{'password'} = $password; } if ($AdminPass ne "") { $password = &GetParam("p_adminpw", ""); if ($password eq "") { print T('Administrator password removed.'), '
    '; undef $UserData{'adminpw'}; } elsif ($password ne "*") { print T('Administrator password changed.'), '
    '; $UserData{'adminpw'} = $password; if (&UserIsAdmin()) { print T('User has administrative abilities.'), '
    '; } elsif (&UserIsEditor()) { print T('User has editor abilities.'), '
    '; } else { print T('User does not have administrative abilities.'), ' ', T('(Password does not match administrative password(s).)'), '
    '; } } } if ($EmailNotify) { &UpdatePrefCheckbox("notify"); &UpdateEmailList(); } &UpdatePrefNumber("rcdays", 0, 0, 999999); &UpdatePrefCheckbox("rcnewtop"); &UpdatePrefCheckbox("rcall"); &UpdatePrefCheckbox("rcchangehist"); &UpdatePrefCheckbox("editwide"); if ($UseDiff) { &UpdatePrefCheckbox("norcdiff"); &UpdatePrefCheckbox("diffrclink"); &UpdatePrefCheckbox("alldiff"); &UpdatePrefNumber("defaultdiff", 1, 1, 3); } &UpdatePrefNumber("rcshowedit", 1, 0, 2); &UpdatePrefNumber("tzoffset", 0, -999, 999); &UpdatePrefNumber("editrows", 1, 1, 999); &UpdatePrefNumber("editcols", 1, 1, 999); print T('Server time:'), ' ', &TimeToText($Now-$TimeZoneOffset), '
    '; $TimeZoneOffset = &GetParam("tzoffset", 0) * (60 * 60); print T('Local time:'), ' ', &TimeToText($Now), '
    '; &SaveUserData(); print '', T('Preferences saved.'), ''; print &GetCommonFooter(); } # add or remove email address from preferences to $DataDir/emails sub UpdateEmailList { my (@old_emails); local $/ = "\n"; # don't slurp whole files in this sub. if (my $new_email = $UserData{'email'} = &GetParam("p_email", "")) { my $notify = $UserData{'notify'}; if (-f "$DataDir/emails") { open(NOTIFY, "$DataDir/emails") or die(Ts('Could not read from %s:', "$DataDir/emails") . " $!\n"); @old_emails = ; close(NOTIFY); } else { @old_emails = (); } my $already_in_list = grep /$new_email/, @old_emails; if ($notify and (not $already_in_list)) { &RequestLock() or die(T('Could not get mail lock')); open(NOTIFY, ">>$DataDir/emails") or die(Ts('Could not append to %s:', "$DataDir/emails") . " $!\n"); print NOTIFY $new_email, "\n"; close(NOTIFY); &ReleaseLock(); } elsif ((not $notify) and $already_in_list) { &RequestLock() or die(T('Could not get mail lock')); open(NOTIFY, ">$DataDir/emails") or die(Ts('Could not overwrite %s:', "$DataDir/emails") . " $!\n"); foreach (@old_emails) { print NOTIFY "$_" unless /$new_email/; } close(NOTIFY); &ReleaseLock(); } } } sub UpdatePrefCheckbox { my ($param) = @_; my $temp = &GetParam("p_$param", "*"); $UserData{$param} = 1 if ($temp eq "on"); $UserData{$param} = 0 if ($temp eq "*"); # It is possible to skip updating by using another value, like "2" } sub UpdatePrefNumber { my ($param, $integer, $min, $max) = @_; my $temp = &GetParam("p_$param", "*"); return if ($temp eq "*"); $temp =~ s/[^-\d\.]//g; $temp =~ s/\..*// if ($integer); return if ($temp eq ""); return if (($temp < $min) || ($temp > $max)); $UserData{$param} = $temp; # Later consider returning status? }