|
Cookbook /
FoxTextReplaceSummary: replace text strings on multiple pages
Version: 2008-12-08
Prerequisites: Pmwiki 2.2.0, Fox, PowerTools
Status: experimental
Maintainer: HansB
Questions answered by this recipe
DescriptionThis recipe uses a Fox form to let you replace text strings on multiple pages. Prerequisites: install Fox and PowerTools.
PowerTools is needed to let the user enter target pages with wiki wildcards (see PowerTools#plist for details). Create a page with this Fox form:
(:foxmessage:)
(:fox frm foxaction=replace put=all target='{$$(plist {$$pat})}' foxtemplate="{$$new}" mark='{$$mk}':)
||table width=600px
|| Replace text string:||(:input text mk size=40:) ||
|| With this string:||(:input text new size=40:) ||
|| On Target Pages:||(:input text pat size=40:) ||
|| ||(:input submit post 'Replace Now':) ||
Notes: you can specify several target pages,\\
or use wiki wildcards (* and ?) in target page names.\\
Example:\\
'''Test.*''' to replace string on all pages in ''Test'' group.
(:foxend frm:)
The form will look somewhat like this (non-functional example):
Notes: you can specify several target pages,
or use wiki wildcards (* and ?) in target page names. Example: Test.* to replace string on all pages in Test group. The target field accepts wiki wildcard target names. Make sure not too many pages are targeted, because otherwise Fox will be stopped before ending with an PHP timeout error. Make sure Fox is permitted to perform a replace foxaction on the target pages. You may need to set $FoxPagePermissions for this in config.php (see Fox#security). Be aware of the security risks of allowing such action. All occurences of the text string found will be replaced. If you only wish to replace the first occurence in a page, you should replace in the form put=all with put=string NotesRelease Notes
See AlsoContributorsCommentsIncompatibilityFrom: R. D. Jones, May 8, 2012:
This is a very useful tool but it is incompatible with Cookbook.RequireSummary. If each edit is required to have a summary added (as the RequireSummary recipe requires), then FoxTextReplace will not replace anything. The workaround is to comment out RequireSummary in the config.php and then run your FoxTextReplace, and then reinstall RequireSummary. But this is clunky to have to change the config every time I want to do a bulk TextReplace, and besides, each edit using TextReplace is not identified with an edit summary (and I'd like to know that a bulk replace had been made when looking at the page history). Is there an easy way to set the change summary in FoxTextReplace so that if a summary is required, a summary is provided? HansB: I think you just need to add a hidden field named csum to the Fox form, with some value of what you want the /summary to say, like (:input hidden csum "Text Replace":)
Modificationwow, this is extremely useful. here's my own version of the recipe - it contains a form for practicing deriving your wildcard target names; an 'Add Text' form where you can toggle between adding text to the top or bottom of pages, and a 'Replace Text' form where you can toggle between all occurrences, first occurrence, and regex. i'm including this on my SiteAdmin.ReplaceText. overtones99 December 23, 2009, at 06:17 AM
(:fox listpages foxaction=display:)
(:foxtemplate ">>lframe padding=10px bgcolor=#ddffdd<<\n'''Pages to be affected:''' \n->{$$(plist {$$pat} sep="\n->")}\n>><<[[<<]]":)
>>lframe width=55pct padding=10px<<
'''List Pages'''
Practice your plist expressions here first. You can specify several target pages (with a space between each), and use wiki wildcards (* and ?).
''Example:'' '''Test.*''' to replace a string on all pages in ''Test'' group.
GroupPattern: (:input default request=1 :)(:input text pat:) (:input submit post 'List Pages':)
(:foxdisplay listpages:)
(:foxend listpages:)
>><<
[[<<]]
>>lframe width=55pct bgcolor=#ffeeee padding=10px<<
'''Add Text to Pages'''
(:fox addtext target='{$$(plist {$$pat})}' foxtemplate="{$$new}":)
||
|| Add text to the:||(:input default put top:)(:input radio put top:) top (:input radio put bottom:) bottom ||
|| Add text string:||(:input text new size=40:) ||
|| To Target Pages:||(:input text pat size=40:) ||
|| ||(:input submit post 'Add Text Now':) ||
(:foxend addtext:)
>><<
[[<<]]
>>lframe width=55pct bgcolor=#ffeeee padding=10px<<
'''Replace Text'''
(:fox frm foxaction=replace target='{$$(plist {$$pat})}' foxtemplate="{$$new}" mark='{$$mk}':)
||
|| Replace:||(:input default put all:)(:input radio put all:) all instances (:input radio put string:) first instance (:input radio put regex:) regex ||
|| Replace text string:||(:input text mk size=40:) ||
|| With this string:||(:input text new size=40:) ||
|| On Target Pages:||(:input text pat size=40:) ||
|| ||(:input submit post 'Replace Now':) ||
>><<
[[<<]]
>>lframe<<
'''Results:'''
(:foxmessage:)
>><<
(:foxend frm:)
[[<<]]
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |