We relaunched the TWiki.org project with an expanded TWiki charter, and we invite you to participate! The TWiki.org Code of Conduct agreement took effect on 27 Oct 2008. We ask existing twiki.org users to opt-in. You need to opt-in to participate in the Blog, Codev, Plugins and TWiki webs. -- PeterThoeny - 27 Oct 2008
You are here: TWiki> Plugins Web>GlobalReplacePlugin (31 Aug 2008, PeterThoeny)
Tags:
admin_tool1Add my vote for this tag automation1Add my vote for this tag editing1Add my vote for this tag findability1Add my vote for this tag productivity1Add my vote for this tag search2Add my vote for this tag create new tag
, view all tags

Global Replace Plugin

The Global Replace Plugin is designed to:

  1. Search through topics with user supplied criteria
  2. Find strings within the topics found
  3. Provide a mechanism to pick and choose which hits will be replaced
  4. Replace the hit with a user supplied expressions

Please go to GlobalSearchAndReplace to perform a global replace operation.

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %GLOBALREPLACEPLUGIN_SHORTDESCRIPTION%

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = Global search and replace functionality across all topics in a web

  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0

Examples

Example 1: Changing a string

  1. Click Edit from a page
  2. Copy the string you want to change to the "Replace search string" field. This is the field you want to replace.
  3. Select web and a search string ( Sandbox, TestTopic )
  4. Replace any other non-numeric and non-alphabetic [character] with [\character], e.g. [}] with [\}]. This applies to "Replace search string" field only.
    • E.g. \%EDITCELL\{checkbox, 3, Input data exchange, ... \}\%
  5. Copy-paste the string to the "Replace string" field and modify it as you choose
  6. Press the "Search"-button and verify that the replaced and replacing strings are as expected
  7. Set all the checkboxes of the strings you want to replace. You can also select "Set all"
  8. Click "Replace all check-marked hits"

Example 2: Inserting a line under another line

  1. Follow the previous example to the point where "Replace search string" is inserted
  2. Use [(\n)] in the "Replace search string", at the end of the line. This will be stored for use in the "Replace string". You can reference it by [$x], where [x] is a number 1-9.
    • E.g. We want to replace a line which ends to a string [Shutdown}% |]. "Replace search string": Shutdown\}\% \|(\n) and "Replace string": Shutdown}% |$1Something$1asdf$1
  • Note: Using this trick you can also insert a line before another line, by writing:
    • E.g. We want to insert a line before another line, which begins with a string [| Keywords: |]. "Replace search string": \| \*Keywords\:\* \|(.*?)(\n) and "Replace string": Something $2| *Keywords: |$1$2
    • E.g. We want to replace a line which begins with a string [| Keywords: |] and ends with or contains the string [Interrupt}%]. "Replace search string": \| \*Keywords\:\* \|(.*?)Interrupt\}\%(.*?)(\n) and "Replace string": Something $3| *Keywords: |$1Interrupt}%$2$3

Known Issues

  • This Plugin ignores locked topics, it writes over locked topics
  • This Plugin is potentially dangerous. Security measures:
    1. The operations of this Plugin is restricted to the group which can edit the TWikiPreferences (usually TWikiAdminGroup)
    2. For public sites, it is recommended to enable this Plugin only for the short time when needed (it is installed if the following variable shows "installed": %GLOBALREPLACE{func="check"}%)
  • This Plugin has been tested. However, it does not have ANY WARRANTY, does not even have the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the Plugin on the server where TWiki is running.

  • Download the ZIP file from the Plugin web (see below)
  • Unzip GlobalReplacePlugin.zip in your twiki installation directory. Content:
File: Description:
data/TWiki/GlobalReplacePlugin.txt Plugin topic
data/TWiki/GlobalReplacePlugin.txt,v Plugin topic repository
data/TWiki/GlobalSearchAndReplace.txt Search replace form topic
data/TWiki/GlobalSearchAndReplace.txt,v Its repository
data/TWiki/GlobalSearchAndReplaceHelp.txt Help topic
data/TWiki/GlobalSearchAndReplaceHelp.txt,v Its repository
data/TWiki/GlobalSearchAndReplaceTopics.txt Replace result topic
data/TWiki/GlobalSearchAndReplaceTopics.txt,v Its repository
lib/TWiki/Plugins/GlobalReplacePlugin.pm Plugin Perl module
pub/TWiki/Plugins/GlobalSearchAndReplaceHelp/GSR.gif Screenshot
  • Test if the installation was successful:
    • Plugin is installed if the following variable shows "installed": %GLOBALREPLACE{func="check"}%
  • To disable the Plugin rename the lib/TWiki/Plugins/%TOPIC.pm file, or edit the file and return 0 in sub initPlugin.

Plugin Info

Plugin Author: TWiki:Main/PaulineCheung
Plugin Version: 03 Nov 2004 (V1.002)
Change History:  
31 Oct 2005: MikkoLaakso: Added some examples, tested on W2K? .
03 Nov 2004: TWiki:Main/PeterThoeny: Added $topic to replace string
16 Mar 2004: Fixed bug where topics with underlines did not get handled properly
07 Feb 2004: Initial version
CPAN Dependencies: none
Other Dependencies: TWiki:Plugins/SpreadSheetPlugin
Perl Version: 5.005
TWiki:Plugins/Benchmark: GoodStyle 99%, FormattedSearch 99%, GlobalReplacePlugin 99%
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/GlobalReplacePlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/GlobalReplacePluginDev

Related Topics: TWikiPreferences, TWikiPlugins

-- TWiki:Main/PeterThoeny - 03 Nov 2004

Topic attachments
I Attachment Action Size Date Who Comment
zipzip GlobalReplacePlugin.zip manage 30.8 K 03 Nov 2004 - 08:45 PeterThoeny Plugin version 03 Nov 2004
Topic revision: r9 - 31 Aug 2008 - 08:50:33 - PeterThoeny
 
TWIKI.NET
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback