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
# 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
2012-04-19 02:18:45 +02:00
$ ModulesDescription . = '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/admin.pl">admin.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Admin_Power_Extension">Admin Power Extension</a></p>' ;
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 ) {
2004-07-16 01:02:02 +00: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 } ,
2004-06-12 11:24:57 +00:00
GetParam ( 'username' , '' ) , GetRemoteHost ( ) , $ Page { languages } ,
GetCluster ( $ Page { text } ) ) ;
}
2005-01-05 01:14:36 +00:00
# Regenerate index on next request
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 ) ;
ReportError ( Ts ( 'The page %s does not exist' , $ id ) , '400 BAD REQUEST' ) unless - f $ fname ;
2005-01-05 01:14:36 +00:00
my $ newfname = GetPageFile ( $ new ) ;
2004-05-29 20:51:34 +00:00
ReportError ( Ts ( 'The page %s already exists' , $ new ) , '400 BAD REQUEST' ) if - f $ newfname ;
2005-01-24 17:00:58 +00:00
# Regenerate index on next request -- remove this before errors can occur!
unlink ( $ IndexFile ) ;
# page file
2004-05-25 23:51:07 +00:00
CreatePageDir ( $ PageDir , $ new ) ; # It might not exist yet
2005-01-24 17:00:58 +00:00
rename ( $ fname , $ newfname )
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 ) ;
CreatePageDir ( $ KeepDir , $ new ) ; # It might not exist yet (only the parent directory!)
rename ( $ kdir , $ newkdir )
or ReportError ( Tss ( 'Cannot rename %1 to %2' , $ kdir , $ newkdir ) . ": $!" , '500 INTERNAL SERVER ERROR' )
if - d $ 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 ) ;
CreatePageDir ( $ RefererDir , $ new ) ; # It might not exist yet
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' )
2005-01-24 17:00:58 +00:00
if - d $ rdir ;
}
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 } ,
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 } ) ) ;
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
}
}