Skip to content

Commit

Permalink
Item1262: Port TopicCreatePlugin to Foswiki and rebrand. Plugin works…
Browse files Browse the repository at this point in the history
… but code can do with some clean up before release

git-svn-id: http://svn.foswiki.org/trunk/TopicCreatePlugin@3268 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Mar 25, 2009
1 parent b5f3629 commit 8dd278d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 132 deletions.
@@ -1,26 +1,26 @@
%META:TOPICINFO{author="StanleyKnutson" date="1132609510" format="1.0" version="1.3"}%
%META:TOPICINFO{author="ProjectContributor" date="1132609510" format="1.1" version="$Rev: 3036 $"}%
---+!! Topic Create Plugin

This Plugin allows you to automatically create topics or attach files at topic save time. This is typically used by TWiki applications to create a set of template based topics.
This Plugin allows you to automatically create topics or attach files at topic save time. This is typically used by Foswiki applications to create a set of template based topics.

%TOC%

---++ <nop>TOPICCREATE - Automatically Create a Set of TWiki Topics
---++ <nop>TOPICCREATE - Automatically Create a Set of Foswiki Topics

* The =%<nop>TOPICCREATE{}%= <nop>TWikiVariable is useful for creating topics based on templates
* The =%<nop>TOPICCREATE{}%= Macro is useful for creating topics based on templates
* Example scenario: You have a notebook application where users can create new notebooks based on a notebook template topic. Each time a user creates a new notebook you would like to create a set of child topics, each based on a separate template.
* Syntax: =%<nop>TOPICCREATE{ &lt;attributes&gt; }%=
* Attributes recognized
| *Attribute* | *Meaning* | *Valid input* | *Default* |
| =template=""= | Name of TWiki topic to be used as template | Any valid TWiki topic | (required) |
| =topic=""= | Name of new TWiki topic to create | Any valid <nop>WikiWord | (required) |
| =template=""= | Name of Foswiki topic to be used as template | Any valid Foswiki topic | (required) |
| =topic=""= | Name of new Foswiki topic to create | Any valid <nop>WikiWord | (required) |
| =disable=""= | Name of the template topic containing this use of TOPICCREATE | Any valid topic name (<nop>WikiWord) | _recommended_ |
| =parameters=""= | List of parameters to pass to a child topic to initialize any urlparams.| Following syntax:%BR% =&lt;parameter-name&gt;=&lt;parameter-value&gt;= followed by any number of parameter name, value pairs separated by =&= | No Parameters |
* The action to create the TWiki topic will not occur until one hits the =Save Changes= button in preview
* The action to create the Foswiki topic will not occur until one hits the =Save Changes= button in preview
* The =%<nop>TOPICCREATE{}%= variable will be removed upon saving of the topic
* Any attachments that are in the =template= will also be copied to the new topic
* =%<nop>TOPICCREATE%= is recursive
* Write =%<nop>TOPICCREATE{ template="<nop>MyTemplate" topic="<nop>%<nop>TOPIC%MyNewTopicName" parameters="MyParameterName=MyParameterValue&Hello=Goodbye" }%= to create a twiki topic based on another topic =<nop>MyTemplate= with the name =<nop>%<nop>TOPIC%MyNewTopicName=. Any =%<nop>URLPARAM{}%= with the name =MyParameterName= and =Hello= present in =MyTemplate= will be replaced with =MyParameterValue= and =Goodbye=.
* Write =%<nop>TOPICCREATE{ template="<nop>MyTemplate" topic="<nop>%<nop>TOPIC%MyNewTopicName" parameters="MyParameterName=MyParameterValue&Hello=Goodbye" }%= to create a foswiki topic based on another topic =<nop>MyTemplate= with the name =<nop>%<nop>TOPIC%MyNewTopicName=. Any =%<nop>URLPARAM{}%= with the name =MyParameterName= and =Hello= present in =MyTemplate= will be replaced with =MyParameterValue= and =Goodbye=.
* To prevent the action from happening in your template topic you should either include the =disable= argument, or escape it: =%<nop>TOPICCRE%<nop>NOP%ATE{...}%=. The =%<nop>NOP%= gets removed when a topic gets instantiated based on a template.

---++ <nop>TOPICATTACH - Automatically Copy Attachments to a Topic
Expand All @@ -29,42 +29,20 @@ This Plugin allows you to automatically create topics or attach files at topic s
* Syntax: =%<nop>TOPICATTACH{ &lt;attributes&gt; }%=
* Attributes recognized
| *Attribute* | *Meaning* | *Valid input* | *Default* |
| =fromtopic=""= | Topic (or Web.Topic) that contains the attachment | Any valid TWiki topic | (required) |
| =fromtopic=""= | Topic (or Web.Topic) that contains the attachment | Any valid Foswiki topic | (required) |
| =fromfile=""= | The attachment to copy from | Any attached file from =fromtopic= | (required) |
| =disable=""= | Name of the template topic containing this use of TOPICATTACH | Any valid topic name (<nop>WikiWord) | (required) |
| =comment=""= | Comment to appear for the attachment within this topic, replacing the comment that was in the =fromtopic= | a one line string | {omit parameter if no change desired} |
* Write =%<nop>TOPICATTACH{ fromtopic="<nop>SourceTopic" fromfile="Sample.jpg" name="Snoopy.jpg" disable="..."}%= to attach =Sample.jpg= from topic =<nop>SourceTopic= as =Snoopy.jpg=
* The parameter value comment is used to change the comment (description) that shows for the topic in the table of attachments
* The "hidden" attribute of the topic is removed: the attachment can be hidden in the =fromtopic= if desired
* The =fromtopic= can specify a different web if desired. For example =TWiki<nop>.Some<nop>Template= would be valid as a =fromtopic=
* The =fromtopic= can specify a different web if desired. For example =Foswiki<nop>.Some<nop>Template= would be valid as a =fromtopic=
* To prevent the action from happening in your template topic you *must* provide the =disable= parameter with the topic name containing the =%<nop>TOPICATTACH%=.

Limitations/TODO:
* There should be a =name= argument to rename the topic as it is copied
* The =TOPICATTACH= must be in the 'top level' topic being saved by a =TOPICCREATE=. It can not be in a recursive/subordinate topic invoked by the TOPICCREATE.

<!--

PATCH is not yet working properly in Cairo release

3. Replace a form fields within a Topic

* Example scenario: You would like to modify the value of a form field based on a URL input parameter. This is usually done for a topic that was just created via TOPICCREATE as described above.
* Syntax: =%<nop>TOPICPATH{ &lt;attributes&gt; }%=
* Attributes recognized
| *Attribute* | *Meaning* | *Valid input* | *Default* |
| =topic=""= | Topic to be modified | Any valid TWiki topic | (required) |
| =action=""= | Either "replace" or "append" to specify the action to do to a form field value in =topic= | (required) |
| =formfield=""= | Form Field Name to be modified | value | (required) |

not Finished!

* Write =%<nop>TOPICATTACH{ fromtopic="<nop>SourceTopic" fromfile="Sample.jpg" name="Snoopy.jpg" }%= to attach =Sample.jpg= from topic =<nop>SourceTopic= as =Snoopy.jpg=
* The parameter values
* To prevent the action from happening in your template topic you can escape it: =%<nop>TOPICATT%<nop>NOP%ACH{...}%=. The =%<nop>NOP%= gets removed when a topic gets instantiated based on a template.

-->

---++ Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write ==%<nop>&lt;plugin&gt;_&lt;setting&gt;%==, i.e. ==%<nop>TOPICCREATEPLUGIN_SHORTDESCRIPTION%==
Expand All @@ -79,51 +57,36 @@ Plugin settings are stored as preferences variables. To reference a plugin setti

* This Plugin is Unix specific and depends on the Unix utilities =cp= and =mkdir=.
* For safety reasons, the path to the utilities is hardcoded in the Plugin module. The path might need to be changed depending on your environment.
* Precautions have been taken to make this Plugin safe. It does not have ANY WARRANTY, does not even have the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is up to the administrator to decide if this Plugin is safe for a public TWiki site.

---++ 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 ==%TOPIC%.zip== in your twiki installation directory. Content:
| *File:* | *Description:* |
| ==data/System/%TOPIC%.txt== | Plugin topic |
| ==data/System/%TOPIC%.txt,v== | Plugin topic repository |
| ==lib/Foswiki/Plugins/%TOPIC%.pm== | Plugin Perl module |
| ==lib/Foswiki/Plugins/%TOPIC%/Func.pm== | Perl utilities |
* Test if the installation was successful (Option A) - pollutes you sandbox, but easiest to try
* Unzip the 'sandbox test' attachment in your twiki installation directory
* Go to the topic =Sandbox.Create<nop>ClientNotebook=
* Enter a name like "MyTest" and press 'create topics'
* Press "save" on the page that appears
* This will perform these operations:
* Create three topics =MyTest<nop>= =MyTestEnvironment= and =<nop>MyTestTripLog=
* Copy an attachment from the =Create<nop>ClientNotebook= topic to the created trip log
* Test if the installation was successful (Option B)
* Create a test topic called =TestTopicCreate<nop>= with this content: %BR%
=%<nop>TOPICCREATE{ template="%SYSTEMWEB%.WikiWord" topic="<nop>%<nop>TOPIC%Child" }%=
* After saving =TestTopicCreate= you should get a new topic =TestTopicCreateChild= with the content of %SYSTEMWEB%.WikiWord.
* Precautions have been taken to make this Plugin safe. It does not have ANY WARRANTY, does not even have the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is up to the administrator to decide if this Plugin is safe for a public Foswiki site.

---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%

---++ Plugin Files

| *File:* | *Description:* |
%$MANIFEST%

---++ Plugin Info

| Plugin Author: | TWiki:Main.StanleyKnutson, TWiki:Main.PeterThoeny, TWiki:Main.PaulineCheung |
| Plugin Version: | 21 Nov 2005 (V1.01) |
| Plugin Author(s): | Foswiki:Main.AndrewJones |
| Previous Author(s): | TWiki:Main.StanleyKnutson, TWiki:Main.PeterThoeny, TWiki:Main.PaulineCheung |
| Copyright: | &copy; 2009, Andrew Jones, &copy; 2005 - 2006, Peter Thoeny |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Release: | %$RELEASE% |
| Plugin Version: | %$VERSION% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
| 11686 | TWikibug:Item2956 - Freeze TWikiRelease04x00 and copy it to new branch MAIN |
| 11686 | TWikibug:Item2956 - Freeze !TWikiRelease04x00 and copy it to new branch MAIN |
| 10613 | TWikibug:Item2473 - files in pub and data directories shouldn't be marked executable in svn (Ordnung muss sein) |
| 7960 | TWikibug:Item1238 - plugins cleanup: added BuildContrib support/infrastructure |
| 7585 | TWikibug:Item1016 - initial import of TopicCreatePlugin (thanks TWiki:Main.StanleyKnutson and others) |
| 21 Nov 2005: | Initial TOPICCATTACH |
| 30 Apr 2005: | Initial version |
| TWiki Dependency: | $TWiki::Plugins::VERSION 1.024 |
| CPAN Dependencies: | none |
| Dependencies: | %$DEPENDENCIES% |
| Other Dependencies: | Unix utilities =cp= and =mkdir= |
| Perl Version: | 5.005 |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Home: | http://foswiki.org/Extensions/%TOPIC% |
| Feedback: | http://foswiki.org/Extensions/%TOPIC%Dev |
| Support: | http://foswiki.org/Support/%TOPIC% |

__Related Topics:__ %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences, [[%SYSTEMWEB%.Plugins][Plugins]]

-- TWiki:Main.StanleyKnutson - 21 Nov 2005
@@ -1,8 +1,9 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009 Andrew Jones, andrewjones86@gmail.com
# Copyright (C) 2005-2006 Peter Thoeny, peter@thoeny.org
#
# For licensing info read LICENSE file in the TWiki root.
# For licensing info read LICENSE file in the Foswiki root.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
Expand All @@ -16,35 +17,34 @@
#
# As per the GPL, removal of this notice is prohibited.

package TWiki::Plugins::TopicCreatePlugin;
package Foswiki::Plugins::TopicCreatePlugin;


# =========================
use vars qw(
$web $topic $user $installWeb $VERSION $debug $doInit
$web $topic $user $installWeb $debug $doInit $VERSION $RELEASE $SHORTDESCRIPTION $pluginName $NO_PREFS_IN_TOPIC
);

$VERSION = '1.000'; # 30 Apr 2005
$doInit = 0;
our $VERSION = '$Rev$';
our $RELEASE = '1.0';
our $SHORTDESCRIPTION = 'Displays the hostname of the server serving Foswiki.';
our $NO_PREFS_IN_TOPIC = 0;
our $pluginName = 'TopicCreatePlugin';

our $doInit = 0;

# =========================
sub initPlugin
{
( $topic, $web, $user, $installWeb ) = @_;

# check for Plugins.pm versions
if( $TWiki::Plugins::VERSION < 1 ) {
TWiki::Func::writeWarning( "Version mismatch between TopicCreatePlugin and Plugins.pm" );
return 0;
}

# Get plugin debug flag
$debug = TWiki::Func::getPreferencesFlag( "TOPICCREATEPLUGIN_DEBUG" );
$debug = Foswiki::Func::getPreferencesFlag( "TOPICCREATEPLUGIN_DEBUG" );
#REMOVE THIS:
##$debug=1;

# Plugin correctly initialized
TWiki::Func::writeDebug( "- TWiki::Plugins::TopicCreatePlugin::initPlugin( $web.$topic ) is OK" ) if $debug;
Foswiki::Func::writeDebug( "- Foswiki::Plugins::TopicCreatePlugin::initPlugin( $web.$topic ) is OK" ) if $debug;
$doInit = 1;
return 1;
}
Expand All @@ -54,37 +54,37 @@ sub beforeSaveHandler
{
### my ( $text, $topic, $web ) = @_; # do not uncomment, use $_[0], $_[1]... instead

TWiki::Func::writeDebug( "- TopicCreatePlugin::beforeSaveHandler( $_[2].$_[1] )" ) if $debug;
Foswiki::Func::writeDebug( "- TopicCreatePlugin::beforeSaveHandler( $_[2].$_[1] )" ) if $debug;

unless( $_[0] =~ /%TOPIC(CREATE|ATTACH)\{.*?\}%/ ) {
# nothing to do
return;
}

require TWiki::Plugins::TopicCreatePlugin::Func;
require Foswiki::Plugins::TopicCreatePlugin::Func;

if( $doInit ) {
$doInit = 0;
TWiki::Plugins::TopicCreatePlugin::Func::init( $web, $topic, $user, $debug );
Foswiki::Plugins::TopicCreatePlugin::Func::init( $web, $topic, $user, $debug );
}

$_[0] =~ s/%TOPICCREATE{(.*)}%[\n\r]*/TWiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/geo;
$_[0] =~ s/%TOPICCREATE{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicCreate($1, $_[2], $_[1], $_[0] )/geo;

# To be tested and documented
# $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/TWiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/geo;
# $_[0] =~ s/%TOPICPATCH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicPatch($1, $_[2], $_[1], $_[0] )/geo;

if ($_[0] =~ /%TOPICATTACH/){
my @attachMetaData = ();
$_[0] =~ s/%TOPICATTACH{(.*)}%[\n\r]*/TWiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/geo;
$_[0] =~ s/%TOPICATTACH{(.*)}%[\n\r]*/Foswiki::Plugins::TopicCreatePlugin::Func::handleTopicAttach($1, \@attachMetaData)/geo;
my $fileName = "";
foreach my $fileMeta ( @attachMetaData ) {
$fileMeta =~ m/META:FILEATTACHMENT\{name\=\"(.*?)\"/;
$fileName = $1;
unless ($_[0] =~ m/META:FILEATTACHMENT\{name\=\"$fileName/ ) {
&TWiki::Func::writeDebug( "handleTopicAttach:: in unless $fileMeta") if $debug;
&Foswiki::Func::writeDebug( "handleTopicAttach:: in unless $fileMeta") if $debug;
$_[0] .= "\n$fileMeta";
} else {
&TWiki::Func::writeDebug( "handleTopicAttach:: in else $fileMeta") if $debug;
&Foswiki::Func::writeDebug( "handleTopicAttach:: in else $fileMeta") if $debug;
$_[0] =~ s/(%META:FILEATTACHMENT\{name=\"$fileName.*?\}%)/$fileMeta/;
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/TopicCreatePlugin/DEPENDENCIES
@@ -0,0 +1,3 @@
# Dependecies for TopicCreatePlugin
cp,>=0,unix,Required Unix utility
mkdir,>=0,unix,Required Unix utility

0 comments on commit 8dd278d

Please sign in to comment.