[pmwiki-users] modifying wikish renaming pages/groups scripts to update links with spaces

Alex Eftimiades alexeftimiades at gmail.com
Tue Jul 24 17:32:26 CDT 2012


Actually, the link fixing part should make renaming a page quite  
reversible. One simply renames it back, and all the damage that was  
done would be fixed in the same way.
This is the code I put in WikiSh.Rename:
//start code
{(wikish source {$FullName}#RenamePage)}

(:if false:)
[[#RenamePage]]
wikish_form process
if test -n ${Submit}
then
   if test "${NewPage}" ~= "/^[\sa-z0-9-]+(\.|\/)[\sa-z0-9-]+$/i"
   then
     if test "${OldPage}" != "/^([\sa-z0-9-]+)(\.|\/)\1$/i"
     then
       set -s NewPagePN = `echo ${NewPage}|sed 's|\s||gi' | sed 's|/| 
\.|gi'`
       set -s OldPagePN = `echo ${OldPage}|sed 's|\s||gi' | sed 's|/| 
\.|gi'`
       set -s OldPageR = `echo ${OldPage}|sed 's|\s+|\\s*|gi'| sed  
's|/|/|gi'`
       echo "${OldPageR}"
       echo "${NewPage}"
       sed -i 's%${OldPageR}%${NewPage}%gi' `pagelist link=$ 
{OldPagePN} sep=\n`
       mv ${OldPagePN} ${NewPagePN}
       wikish_form redirect target=${NewPagePN}
     fi
   fi
fi
[[#RenamePage]]
(:ifend:)
//end code
This is the code I put in PageActions:
//start code
(:if equal {$Action} "edit":)
* %item rel=nofollow% (:input form action="index.php" method="GET":) 
(:input hidden name=n value="WikiSh.Rename":)(:input hidden  
name=OldPage value="{*$Groupspaced}/{*$Namespaced}":)Enter New Name: 
(:input text name=NewPage value="{*$Groupspaced}/{*$Namespaced}"  
size=30:)(:input submit Submit value="Rename":)(:input end:)
(:ifend:)
//end code

This actually works quite well except for the fact that only admin can  
rename pages. I would like editors to be able to rename pages so long  
as they have edit permissions for both the old page and the new page.  
Right now, you need to enter an admin password to run the script. The  
relevent portion of my config.php looks like this:
//start code
include_once("$FarmD/cookbook/toolbox.php");
include_once("$FarmD/cookbook/WikiSh.php");
if ($group == 'WikiSh')
    include_once("$FarmD/cookbook/WikiShCL.php");
include_once("$FarmD/cookbook/SecLayer.php"); // note this includes  
stdconfig.php
$EnableWikiShWritePage = true;
$EnableWikiShCreatePage = true;
$EnableWikiShOverwritePage = true;
$EnableWikiShRemove = true;
if (CondAuth($pagename, "admin")) {
    slAddAuth($wshAuthPage, "*.*",  
"read,create,insert,overwrite,append,prepend,attr,delete");
    $EnableWikiShDeletePage = true;
    $EnableWikiShChmod = true;
} else {
    slAddAuth($wshAuthPage, "*.*", "read,create");
    slAddAuth($wshAuthPage, "Test.*",  
"insert,overwrite,append,prepend,delete");
}
# cookbook/powertools.php is *very* helpful in the wikish environment  
but is optional.
# If you decide to install it you will need to go that page and  
download it and install
# it as follows:
include_once("$FarmD/cookbook/powertools.php");
//end code

I tried modifying the CondAuth line with an "or $group=='WikiSh'" for  
starters, but that did not seem to make a difference. I am quite  
confused as to how to go about doing this.

Thanks,
Alex



On Jul 23, 2012, at 2:46 PM, tamouse mailing lists wrote:

>
> On Jul 22, 2012 11:01 PM, "Alex Eftimiades"  
> <alexeftimiades at gmail.com> wrote:
> >
> > Hi again, I tried making this a page action as follows (in  
> Site.PageActions)
> > * %item rel=nofollow% {(wikish source  
> {$SiteGroup}.PageActions#RenamePage)}Rename Page:(:input text  
> name=NewPage value={$FullName} size=30:)(:input submit name=submit  
> value=Rename:)(:input end:)
> >
> > (:if false:)
> > [[#RenamePage]]
> > wikish_form quickform process
> > if test -n "${submit}"
> > then
> >   if test "${NewPage}" ~= "/^[a-z0-9-]+(\.|\/)[a-z0-9-]+$/i"
> >   then
> >     if test {$Name}!={$Group}
> >       then
> >       set -s NewPagePN = `echo ${NewPage} | sed 's|\s||gi' | sed  
> 's|/|\.|gi'`
> >       sed -i 's%({$Group}|{$Groupspaced})(/|\.)({$Name}| 
> {$NameSpaced})%${NewPage}%g' `pagelist link={$FullName} sep=\n`
> >       mv {$FullName} ${NewPagePN}
> >       wikish_form redirect target=${NewPagePN}
> >   fi
> > fi
> > [[#RenamePage]]
> > (:ifend:)
> >
> > But with this setup the rename button is disabled. Could anyone  
> tell me what part of this I need to fix? Perhaps I am going about  
> this wrong.
> >
> > Thanks,
> > Alex
> >
> >
> >
> > On Jul 21, 2012, at 10:16 PM, Alex Eftimiades wrote:
> >
> >> Yes this seems to work now. Thank you very much. I am going to  
> try to modify this into a page action and for renaming groups.
> >>
> >> Thanks
> >> Alex
> >>
> >> On Jul 21, 2012, at 12:53 PM, Peter Bowers wrote:
> >>
> >>> No that's fine.  If it's an action you do on a regular basis then
> >>> you'll probably want to put the code on a page and put it together
> >>> with a form, but that can easily be a future step.  Doing it in  
> the
> >>> ControlPanel is a good way to get things working...
> >>>
> >>> I loaded the first command from your command history and noticed  
> that
> >>> you have a newline in the middle of the line that should read like
> >>> this:
> >>>
> >>> sed -i 's|${OldGroup}([./]\)?)${OldPage}|${NewGroup}$1${NewPage}| 
> gi'
> >>> `pagelist link=${OldGroupPN}.${OldPagePN} sep=\n`
> >>>
> >>> That should all be on one line with no newline before the  
> `pagelist...
> >>>
> >>> It may have gotten confusing because the email may have  
> automatically
> >>> wordwrapped it when I sent it to you.
> >>>
> >>> Anyway, I certainly don't want to come anywhere close to actually
> >>> running code like this on someone else's system, so I'm just  
> letting
> >>> you know what needs to happen and then leave it up to you.
> >>>
> >>> If that works, please report back to the list that it was just a
> >>> newline due to the email wordwrapping.  If it doesn't work then  
> let me
> >>> know and I'll take another look -- just give me the exact error
> >>> message since I'm wanting to avoid actually executing anything  
> on your
> >>> system.
> >>>
> >>> -Peter
> >>
> >>
> >
> >
> > _______________________________________________
> > pmwiki-users mailing list
> > pmwiki-users at pmichaud.com
> > http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>
> Something about the idea of putting sort of thing in PageActions  
> like this scares me. It seems like a chance for vandalization to  
> occur of a sort that would be hard to recover from. Wikish may be  
> highly useful, but I think this action would be better raised to a  
> first-class recipe with attendant authorization and validation, if  
> one is going to make available on PageActions. Just my deux centimes.
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20120724/86b6f431/attachment.html>


More information about the pmwiki-users mailing list