Files
oddmuse/modules/admin.pl
Alex Schroeder c92cd663ea new
2004-05-25 23:51:07 +00:00

78 lines
2.9 KiB
Perl

# Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
#
# 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
$ModulesDescription .= '<p>$Id: admin.pl,v 1.1 2004/05/25 23:51:07 as Exp $</p>';
$Action{delete} = \$AdminPowerDelete;
$Action{update} = \$AdminPowerUpdate;
sub AdminPowerDelete {
my $id = GetParam('id', '');
ValidIdOrDie($id);
print GetHeader('', Ts('Deleting %s', $id), '');
return unless UserIsAdminOrError();
RequestLockOrError();
print $q->p(T('Main lock obtained.'));
OpenPage($id);
WriteRcLog($id, Ts('Deleted %s', $new), 0, $Page{revision},
GetParam('username', ''), GetRemoteHost(), $Page{languages},
GetCluster($Page{text}));
DeletePage($id);
print $q->p(GetPageLink($id) . ' ' . T('deleted'));
ReleaseLock();
print $q->p(T('Main lock released.'));
PrintFooter();
}
sub AdminPowerUpdate {
my $id = GetParam('id', '');
ValidIdOrDie($id);
my $new = GetParam('new', '');
ValidIdOrDie($new);
print GetHeader('', Tss('Renaming %1 to %2.', $id), '');
return unless UserIsAdminOrError();
RequestLockOrError();
print $q->p(T('Main lock obtained.'));
# page file -- only check for existing or missing pages here
my $fname = GetPageFile($id);
ReportError(Ts('The page %s does not exist', $id), '400 BAD REQUEST') unless -f $fname;
my $newfname = GetPageFile($new);
ReportError(Ts('The page %s already exists', $new), '400 BAD REQUEST') if -f $new;
CreatePageDir($PageDir, $new); # It might not exist yet
rename($fname, $newfname);
# keep directory
CreatePageDir($KeepDir, $new); # It might not exist yet
rename(GetKeepDir($id), GetKeepDir($new));
# refer file
CreatePageDir($RefererDir, $new); # It might not exist yet
rename(GetRefererFile($id), GetRefererFile($new));
# Regenerate index on next request
unlink($IndexFile);
# RecentChanges
OpenPage($id);
WriteRcLog($id, Ts('Renamed to %s', $new), 0, $Page{revision},
GetParam('username', ''), GetRemoteHost(), $Page{languages},
GetCluster($Page{text}));
WriteRcLog($new, Ts('Renamed from %s', $id), 0, $Page{revision},
GetParam('username', ''), GetRemoteHost(), $Page{languages},
GetCluster($Page{text}));
ReleaseLock();
print $q->p(T('Main lock released.'));
PrintFooter();
}