Implemented: Flag for edit script to avoid overwrite of existing topic text and form data
This pages describes a workaround for accidential overwriting of Form data when using HTML forms to create new topics
1 Problem
If you use a HTML form to associate a
TWiki Form with
a
TWiki template (as described in
TWiki Topic templates in Action)
you will
without warning overwrite existing TWiki Form data, if you accidentially enter an exiting Topic name.
See
TWikiTemplates#TemplateTopicOverwritingExisting for
HansruediHaenni original problem describtion.
2 Quick patch
2.1 Idea
Add CGI parameter to TWiki edit script, making it possible to abandon edit, if topic exists.
2.2 The patch
2.2.a Patch .../twiki/bin/edit script
Locate the edit script.
Right after the text:
if( ! &TWiki::Store::webExists( $webName ) ) {
my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsnoweb" );
TWiki::redirect( $query, $url );
return;
}
You add:
# Prevent editing existing topic?
if($query->param( 'onlynewtopic' ) && &TWiki::Store::topicExists( $webName, $topic ))
{
# Topic exists and user requested oops if it exists
my $url = &TWiki::getOopsUrl( $webName, $topic, "oopscreatenewtopic" );
print $query->redirect( $url );
return;
}
2.2.b Create new oops template
In your
.../twiki/templates directory create a template file called
oopscreatenewtopic.tmpl with the following content:
%TMPL:INCLUDE{"twiki"}%
%TMPL:DEF{"titleaction"}%(oops, topic exists)%TMPL:END%
%TMPL:DEF{"webaction"}% *Attention* %TMPL:END%
%TMPL:DEF{"heading"}%The "%TOPIC%" topic already exists%TMPL:END%
%TMPL:DEF{"message"}%
Cannot create %TOPIC% because it already exists.
Please go _back_ in browser and try a new name %TMPL:END%
%TMPL:DEF{"topicaction"}% %TMPL:END%
3 Then the workaround becomes...
Instead of writing
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%"}%/">
* New example topic:
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" />
<input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />
<input type="hidden" name="topicparent" value="%TOPIC%" />
<input type="hidden" name="onlywikiname" value="on" />
<input type="submit" value="Create" />
(date format is <nop>YYYYxMMxDD)
</form>
as described in
TWiki Topic templates in Action write:
<form name="new" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%INTURLENCODE{"%WEB%"}%/">
* New example topic:
<input type="text" name="topic" value="ExampleTopic%SERVERTIME{$yearx$mox$day}%" size="23" />
<input type="hidden" name="templatetopic" value="ExampleTopicTemplate" />
<input type="hidden" name="topicparent" value="%TOPIC%" />
<input type="hidden" name="onlywikiname" value="on" />
<input type="hidden" name="onlynewtopic" value="on" />
<input type="submit" value="Create" />
(date format is <nop>YYYYxMMxDD)
</form>
Now you will get an error, if you try to create an already existing topic
Contributors:
--
NielsKoldso - 30 Dec 2003
--
PeterThoeny - 31 Dec 2003
Discussions
Thanks Niels for the patch. Good idea, can be taken into the core code. Changes I did:
- Moved the topic from the TWiki web to the Codev web
- Changed the name of the flag from
existsoops to onlynewtopic to make it consistent with the onlywikiname flag name
- Renamed
oopstopicexists2.tmpl to oopsonlynewtopic.tmpl
--
PeterThoeny - 31 Dec 2003
This is now in
TWikiAlphaRelease and TWiki.org.
--
PeterThoeny - 31 Dec 2003