2005-01-05 01:14:36 +00:00
|
|
|
# Copyright (C) 2004, 2005 Alex Schroeder <alex@emacswiki.org>
|
2004-05-25 23:51:07 +00:00
|
|
|
#
|
|
|
|
|
# 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
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2004-05-25 23:51:07 +00:00
|
|
|
# (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
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-05-25 23:51:07 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Page, %Action, $IndexFile, $PageDir, $KeepDir, @MyAdminCode, $RefererDir);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('admin.pl', 'Admin Power Extension');
|
2004-05-25 23:51:07 +00:00
|
|
|
|
2004-05-26 00:43:56 +00:00
|
|
|
$Action{delete} = \&AdminPowerDelete;
|
|
|
|
|
$Action{rename} = \&AdminPowerRename;
|
2004-05-25 23:51:07 +00:00
|
|
|
|
|
|
|
|
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);
|
2004-06-12 11:24:57 +00:00
|
|
|
my $status = DeletePage($id);
|
|
|
|
|
if ($status) {
|
2015-10-14 12:32:25 +02:00
|
|
|
print $q->p(GetPageLink($id) . ' ' . T('not deleted:') . ' ' . $status);
|
2004-06-12 11:24:57 +00:00
|
|
|
} else {
|
|
|
|
|
print $q->p(GetPageLink($id) . ' ' . T('deleted'));
|
2005-01-05 01:14:36 +00:00
|
|
|
WriteRcLog($id, Ts('Deleted %s', $id), 0, $Page{revision},
|
2015-07-31 09:35:51 +02:00
|
|
|
GetParam('username', ''), $q->remote_addr(), $Page{languages},
|
2004-06-12 11:24:57 +00:00
|
|
|
GetCluster($Page{text}));
|
|
|
|
|
}
|
2005-01-05 01:14:36 +00:00
|
|
|
# Regenerate index on next request
|
2016-06-15 23:21:07 +02:00
|
|
|
Unlink($IndexFile);
|
2004-05-25 23:51:07 +00:00
|
|
|
ReleaseLock();
|
|
|
|
|
print $q->p(T('Main lock released.'));
|
|
|
|
|
PrintFooter();
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-26 00:43:56 +00:00
|
|
|
sub AdminPowerRename {
|
2005-01-05 01:14:36 +00:00
|
|
|
my $id = FreeToNormal(GetParam('id', ''));
|
2004-05-25 23:51:07 +00:00
|
|
|
ValidIdOrDie($id);
|
2005-01-05 01:14:36 +00:00
|
|
|
my $new = FreeToNormal(GetParam('new', ''));
|
2004-05-25 23:51:07 +00:00
|
|
|
ValidIdOrDie($new);
|
2004-05-26 00:43:56 +00:00
|
|
|
print GetHeader('', Tss('Renaming %1 to %2.', $id, $new), '');
|
2004-05-25 23:51:07 +00:00
|
|
|
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);
|
2016-06-15 23:21:07 +02:00
|
|
|
ReportError(Ts('The page %s does not exist', $id), '400 BAD REQUEST') unless IsFile($fname);
|
2005-01-05 01:14:36 +00:00
|
|
|
my $newfname = GetPageFile($new);
|
2016-06-15 23:21:07 +02:00
|
|
|
ReportError(Ts('The page %s already exists', $new), '400 BAD REQUEST') if IsFile($newfname);
|
2005-01-24 17:00:58 +00:00
|
|
|
# Regenerate index on next request -- remove this before errors can occur!
|
2016-06-15 23:21:07 +02:00
|
|
|
Unlink($IndexFile);
|
2005-01-24 17:00:58 +00:00
|
|
|
# page file
|
2014-06-23 12:54:39 +02:00
|
|
|
CreateDir($PageDir); # It might not exist yet
|
2016-06-22 15:37:04 +02:00
|
|
|
Rename($fname, $newfname)
|
2005-01-24 17:00:58 +00:00
|
|
|
or ReportError(Tss('Cannot rename %1 to %2', $fname, $newfname) . ": $!", '500 INTERNAL SERVER ERROR');
|
2004-05-25 23:51:07 +00:00
|
|
|
# keep directory
|
2005-01-24 17:00:58 +00:00
|
|
|
my $kdir = GetKeepDir($id);
|
|
|
|
|
my $newkdir = GetKeepDir($new);
|
2014-06-23 12:54:39 +02:00
|
|
|
CreateDir($KeepDir); # It might not exist yet (only the parent directory!)
|
2016-06-22 15:37:04 +02:00
|
|
|
Rename($kdir, $newkdir)
|
2005-01-24 17:00:58 +00:00
|
|
|
or ReportError(Tss('Cannot rename %1 to %2', $kdir, $newkdir) . ": $!", '500 INTERNAL SERVER ERROR')
|
2016-06-15 23:21:07 +02:00
|
|
|
if IsDir($kdir);
|
2004-05-25 23:51:07 +00:00
|
|
|
# refer file
|
2005-01-24 17:00:58 +00:00
|
|
|
if (defined(&GetRefererFile)) {
|
|
|
|
|
my $rdir = GetRefererFile($id);
|
|
|
|
|
my $newrdir = GetRefererFile($new);
|
2014-06-23 12:54:39 +02:00
|
|
|
CreateDir($RefererDir); # It might not exist yet
|
2016-06-22 15:37:04 +02:00
|
|
|
Rename($rdir, $newrdir)
|
2005-02-01 20:53:41 +00:00
|
|
|
or ReportError(Tss('Cannot rename %1 to %2', $rdir, $newrdir) . ": $!", '500 INTERNAL SERVER ERROR')
|
2016-06-15 23:21:07 +02:00
|
|
|
if IsDir($rdir);
|
2005-01-24 17:00:58 +00:00
|
|
|
}
|
2004-05-25 23:51:07 +00:00
|
|
|
# RecentChanges
|
2004-05-26 00:43:56 +00:00
|
|
|
OpenPage($new);
|
2004-05-25 23:51:07 +00:00
|
|
|
WriteRcLog($id, Ts('Renamed to %s', $new), 0, $Page{revision},
|
2015-07-31 09:35:51 +02:00
|
|
|
GetParam('username', ''), $q->remote_addr(), $Page{languages},
|
2004-05-25 23:51:07 +00:00
|
|
|
GetCluster($Page{text}));
|
|
|
|
|
WriteRcLog($new, Ts('Renamed from %s', $id), 0, $Page{revision},
|
2015-07-31 09:35:51 +02:00
|
|
|
GetParam('username', ''), $q->remote_addr(), $Page{languages},
|
2004-05-25 23:51:07 +00:00
|
|
|
GetCluster($Page{text}));
|
2004-05-26 00:43:56 +00:00
|
|
|
print $q->p(Tss('Renamed %1 to %2.', GetPageLink($id), GetPageLink($new)));
|
2004-05-25 23:51:07 +00:00
|
|
|
ReleaseLock();
|
|
|
|
|
print $q->p(T('Main lock released.'));
|
|
|
|
|
PrintFooter();
|
|
|
|
|
}
|
2004-05-26 00:43:56 +00:00
|
|
|
|
2005-01-05 01:14:36 +00:00
|
|
|
push(@MyAdminCode, \&AdminPower);
|
2004-05-26 00:43:56 +00:00
|
|
|
|
2005-01-05 01:14:36 +00:00
|
|
|
sub AdminPower {
|
|
|
|
|
return unless UserIsAdmin();
|
|
|
|
|
my ($id, $menuref, $restref) = @_;
|
|
|
|
|
my $name = $id;
|
|
|
|
|
$name =~ s/_/ /g;
|
2004-05-26 00:43:56 +00:00
|
|
|
if ($id) {
|
2006-08-06 11:44:55 +00:00
|
|
|
push(@$menuref, ScriptLink('action=delete;id=' . $id, Ts('Immediately delete %s', $name), 'delete'));
|
2005-01-05 01:14:36 +00:00
|
|
|
push(@$menuref, GetFormStart()
|
2006-08-06 11:44:55 +00:00
|
|
|
. $q->label({-for=>'new'}, Ts('Rename %s to:', $name) . ' ')
|
2005-01-05 01:14:36 +00:00
|
|
|
. GetHiddenValue('action', 'rename')
|
|
|
|
|
. GetHiddenValue('id', $id)
|
|
|
|
|
. $q->textfield(-name=>'new', -size=>20)
|
|
|
|
|
. $q->submit('Do it'));
|
2004-05-26 00:43:56 +00:00
|
|
|
}
|
|
|
|
|
}
|