BatchEdit plugin

Compatible with DokuWiki

2009-02-14

plugin Edit wiki pages using regular expressions

Last updated on
2009-02-14
Provides
Admin
Repository
Source

Tagged with editing, regexp, replace, search

BatchEdit is an admin plugin that allows you to use regular expressions to search and replace text on DokuWiki pages. As it works with raw DokuWiki text, the plugin can be also used to modify markup of the pages. This can be very helpful when there are multiple pages with similar markup. For example, you can update pages created from a namespace template if you decide to change the template.

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to plugins on how to install plugins manually.

User Interface

Screenshot

After installation BatchEdit shows up on the Administration page.

When started, the plugin displays a form with four edit fields:

  • Namespace — allows you to select a top level namespace that contains pages to search in. All the namespaces below the selected one will be included in the search as well. Standard name resolution of the namespaces applies here (e.g. ”.” stands for the current namespace, etc.). If the namespace is not provided, BatchEdit will search through the entire wiki.
  • Regular expression — fully qualified regular expression including the modifiers. BatchEdit uses PHP PCRE extension to do the matching.
  • Replacement — the replacement pattern. For the syntax see preg_replace documentation.
  • Summary — summary of the replacement. This field has the same purpose as the Summary field of the DokuWiki text editor.

Below the edit fields there are two buttons:

  • Preview – shows the search results with corresponding replacements but does not do the replacement itself.
  • Apply – replaces selected (see below) matches. If there are no selected matches it acts identical to the Preview button.

BatchEdit displays every match of the search results in a separate box. On top of the box the plugin shows a check box with the page name and a character offset where the match occurred. The check box is used to select matches for the replacement. To the right from the page name there are two icons: the first one links to the page itself and the second one to the editor. The rest of the box is split in two parts: matched text with some context on the left side; and the same fragment with applied replacement on the right. Both the matched text and the replacement are highlighted.

After the replacement, the matches show up with no check box in the caption and replaced text is highlighted with green.

Technical details

Performance

BatchEdit does not rely on any caching to do the search, so every time Preview or Apply button is clicked the DokuWiki server reads all the pages from a hard drive. To reduce the server load and search time use Namespace field that limits the search scope.

Page locking

While BatchEdit locks pages during replacement, there is still a small possibility for the data corruption. The replacement is performed in two stages:

  1. BatchEdit searches for the regular expression matches in all the pages. For every match the plugin records character offset in the page where the match occurs.
  2. On the second stage BatchEdit compares matches found during the first pass with a list of matches selected for replacement. For the matches found in both lists BatchEdit locks the page and performs the replacement using the offset.

If the page is modified between these two stages, BatchEdit will apply the replacement to random data in the updated page. Though the chances of such corruption are rather small, the administrators should take care to minimize DokuWiki activity when Batchedit is used.

Page lookup

BatchEdit uses DokuWiki page index to get the list of existing pages instead of going through the data directories. If the index is incomplete the plugin will not see some pages. This also applies to the “special” pages, for example, namespace templates.

Version History

2009-02-14

  • Added View and Edit links to matched pages.

2008-12-07

  • Fixes in regular expression validation

2008-10-27

  • First public release

Bugs / Feature Requests

Please report bugs or feature requests at the bug tracker.

Discussion

Syntax error on line 89

Added via the plugin manager. Got following error message when trying to load the Admin page:

Parse error: syntax error, unexpected '{' in .../plugins/batchedit/admin.php on line 89

Back-paged and deleted the plugin. Sorry. — Anonymous 2009/03/21


Let me guess: PHP4? — Mykola Ostrovskyy 2009/03/29 12:47

PHP Warning on line 291

Enter the following in the regexp field

'|'a'

click on Preview and you get this warning:

PHP Warning:  preg_match_all() [<a href='function.preg-match-all'>function.preg-match-all</a>]: Unknown modifier 'a' in \lib\plugins\batchedit\admin.php on line 291

Anonymous 2009/09/25 17:09


First of all it's an invalid regexp. You shouldn't do that :-)

That said, it's, of course, not nice to throw PHP warnings in the face of unsuspecting user. It will be fixed in the next release, thanks for reporting. — Mykola Ostrovskyy 2009/10/01 19:19

Some tips

first: this is a very usable plugin, thank you, Mykola! when you use this plugin for the first time, consider this:

  • you may want to temporarily disable mailing when doing large batchedits (look for notify in inc/common.php around line 1000)
  • you may want to use a bookmarklet to tick all checkboxes when doing large batchedits (find one at this site)
  • when creating a multiline replacement the batchedit form isn't usable (it's a text edit field, it allows only one line), you have to edit batchedit to create a textarea for replacement — Igorette 2009/05/18 05:01

Suggestions for helping rookies

Would you please be so kind and provide a simple example for both a DokuWiki text and a full set of parameters for your plugin, so that any non-regexpression expert can check if the plugin is properly installed? The given example in the graphics cannot be “typed in” by a rookie user, as it is graphics, and the search string might even be too long so that it is not displayed completely. So a much more simple example “as text” would be great. Rolf Hemmerling 2010/01/02 08:46

Would you please be so kind and tell the rookie users, how to detect if the necessary PHP extension is loaded on his server. (a) by a look at conf/http.conf (b) if http.conf is not accessable. Rolf Hemmerling 2010/01/02 08:46


I believe that if you follow the links in the user interface description you will find enough information about both regexp syntax and the extension (it's a built-in one, no installation needed) — Mykola Ostrovskyy 2010/01/14 08:18

plugin/batchedit.txt · Last modified: 2010/01/20 19:17 by pan One
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate