Fox Text Replace

Summary: replace text strings on multiple pages Version: 2008-12-08 Prerequisites: Pmwiki 2.2.0, Fox, PowerTools Status: experimental Maintainer: HansB? Categories: Fox Administration Editing

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

This 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):

Replace text string:
With this string:
On Target Pages:
 

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

Notes

Release Notes

  • 2008-12-08: initial release

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

See Also

Contributors

Comments

wow, 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:)
[[<<]]