Skip to topic | Skip to bottom
TWiki.EditContribr1.1 - 07 Mar 2005 - 15:15 - TWikiGuesttopic end

Start of topic | Skip to actions
Provides subroutines useful in writing plugins that edit and save parts of topics.

Summary of Contents

This contrib provides subroutines that come in handy when editing and saving parts of topics (refered to as sections).

  • passFormForEdit supports editing a topic or parts of a topic without showing the form
  • savemulti is an adaption of TWiki::UI::Save::savemulti
  • quoteForXml encodes sensitive characters before using text as URL variable
  • edit sets up the section for editing
  • bin/savesection is an adaption of bin/save
  • templates/editsection.pattern.tmpl and templates/editsection.tmpl are templates supporting editing of sections.

This contrib is used by TWiki:Plugins/SectionalEditPlugin, TWiki:Plugins/MultiEditPlugin, and TWiki:Plugins/ThreadedDiscussionPlugin. Examining these plugins will provide guidance of how to use these subroutines in implementing your own plugin.

Detailed Documentation

The use of this contrib follows closely the pattern used in TWiki core when editing a topic. A plugin implementing editing of a section of a topic has to

  • Implement code called during view which would provide appropriate controls for edting a section, and identify the section to be edited by differentiating
    • the part of the topic before the section,
    • the section to be edited, and
    • the part of the topic following the section.
  • Pass this information into the edit script in URL variables (see below) upon invocation of the edit
  • Implement the edit script to obtain that information from the URL variables and render the edit topic.
The contrib provides the rest of the plumbing (save script, edit templates).

passFormForEdit ( $web, $topic, $form, $meta, $query, @fieldsInfo )

To be used instead of TWiki::Forms::renderForEdit when editing a topic should not display the forms for editing. In this case, form values are passed through to the save script unchanged. This would allow, for example, separating the editing of the form from editing the text of the topic.

savemulti ( $web, $topic, $user, $query, $editlink )

Works identical to TWiki::UI::Save::savemulti except

  • redirects to $editlink when "Checkpoint" is selected (thus a custom edit script can be called)
  • additional text can be passed via the pretxt and postxt URL parameters. These will be prepended and appended to the text coming from the edit box, respectively.

quoteForXml ( $text )

Quotes characters in $text so that they can be passed as URL variables.

edit ( )

Sets up a section of the topic for editing. This code is derived from bin/edit and lib/TWiki/UI/, but omits code related to topic creation (as the topic must exist for this function to be called).

Returns the current query object, the topic, web, the topic text passed into the script, as well as the appropriate template rendered with the exception of application specific text (these template variables must be substituted for by the client function):

Template variable Purpose
%TEXT% Text to be edited; shown in textarea
%PRETEXT% Text preceding the edited section
%POSTEXT% Text following the edited section
%PRETEXTFIELD% Rendered text preceding the edited section, shown above the textarea
%POSTEXTFIELD% Rendered text following the edited section, shown below the textarea
%EDIT% URL to be invoked to edit the section (used when "Checkpoint" is selected)
%EDITPARAMS% URL parameters to be passed when the section is edited


Works identical to bin/save except

  • invokes TWiki::Contrib::savemulti
  • constructs the edit link (see above) from the URL parameters edit and editparams. The former has to be the edit script to be invoked when "Checkpoint" is selected, the latter determines any additional URL parameters to be passed to the edit script (must include the leading &).

templates/editsection.tmpl, templates/editsection.pattern.tmpl

Templates supporting the editing of a section. The pretxt and postxt URL parameters (see savemulti) are generated by the two variables %PRETEXTFIELD% and %POSTEXTFIELD%. The size of the edit window is controlled by preference variables (see below).


  • Name of the perl package
    • Set STUB = TWiki::Contrib::EditContrib

Set the variables conrolling the size and style of the textara for editing in the desired preference topic, for example:

  • Edit Box Width, Height, Style (set to width: 99% for full width, auto to disable).
    • Set SECTIONEDITBOXSTYLE = width: 99%;

Installation Instructions

  • Download the ZIP file from the Plugin web (see below)
  • Unzip in your twiki installation directory. Content:
    File: Description:
    data/TWiki/EditContrib.txt Contrib topic
    data/TWiki/EditContrib.txt,v Contrib topic repository
    lib/TWiki/Contrib/ Contrib Perl module
    bin/savesection save script

Contrib Info

Author: TWiki:Main/ThomasWeigert
Copyright ©:  
License: GPL
Dependencies: none
Version: 12 Mar 2005
Change History:  
12 Mar 2005: Added subroutine setting up section for editing.
11 Mar 2005: Added templates for editing sections.
08 Mar 2005: Initial version

Related Topics: TWiki:Plugins/SectionalEditPlugin, TWiki:Plugins/MultiEditPlugin, TWiki:Plugins/ThreadedDiscussionPlugin

-- TWiki:Main/ThomasWeigert 08 Mar 2005
to top

You are here: TWiki > EditContrib

to top

All content is Copyright © 1999-2021 by, and the property of, the contributing authors.
Questions, comments, or concerns? Contact GNHLUG
Legal Notice (includes Terms of Service)