Question
Is there a way to create a page directly from another page without going through the edit page first? The reason I want to do this is that I have an html form that creates a new page using a template, and the new page is intended to be edited using the
EditTablePlugin. However when users create the page using the html form, they are dropped into the edit page first, and so start editing the content directly, not realizing the plugin is there.
I tried calling createtopic instead of edit from the form, but that did not work.
--
MartinWatt - 04 Oct 2002
Answer
This is currently not possible. It could be hacked into the edit script, for example a
directsave URL parameter could trigger that.
--
PeterThoeny - 12 Oct 2002
I hate to contradict
PeterThoeny, but I believe it is possible to do what
MartinWatt wants to accomplish, at least in the manner he is trying to use this in
XpTrackerPlugin. The following will create the page and save it, assuming
$dataweb,
$datatopic,
$text,
$meta,
$saveCmd,
$unlock, and
$dontNotify contain the pointers for web, topic, html text, meta data, ' ', 'on', and ' ', respectively...
my $error = TWiki::Store::saveTopic($dataweb,
$datatopic,
$text,
$meta,
$saveCmd,
$unlock,
$dontNotify);
I have tried this from a script, but I would assume this is also possible from the code for a plugin?
--
ThomasWeigert - 27 Oct 2002
This is probably correct. Keep in mind though that this call is not documented and will likely change in a future release, especially with pending changes like
SimplifyInternalMetaDataHandling
--
PeterThoeny - 28 Oct 2002
Discussion re above use of function not recommended for plugins moved to PluginsWithNonFuncCode
--
ThomasWeigert - 30 Oct 2002
I figured out a way to do this, just want to check this is ok-ish - MW
I've been trying to implement this for
XpTrackerPlugin (begging forgiveness from the TWiki gods and promising to do it properly once there is an approved way of doing this.) The plugin creates a page with an html form to allow creation of new pages. I want the user to enter the page name, press
create and have the page appear immediately. The code to create the form is something like this:
$list .= "<form name=\"new\">\n"; # note - no action here
$list .= "<input type=\"text\" name=\"topic\" value=\"".$value."\" size=\"30\" />\n";
$list .= "<input type=\"hidden\" name=\"templatetopic\" value=\"".$template."\" />\n";
$list .= "<input type=\"hidden\" name=\"parent\" value=\"%TOPIC%\" />\n";
$list .= "<input type=\"submit\" name =\"xpsave\" value=\"".$prompt."\" />\n";
$list .= "</form>\n";
In the plugin commonTagsHandler I have this to pick up the new page creation request:
if( $query->param( 'xpsave' ) ) {
xpSavePage($_[1], $web);
}
and the method to save the page is:
sub xpSavePage()
{
my ( $title, $web ) = @_;
my $text = $query->param( 'templatetopic' );
my( $meta, $text ) = &TWiki::Store::readTopic( $web, $text );
my $error = &TWiki::Store::saveTopic( $web, $title, $text, $meta );
TWiki::redirect( $query, &TWiki::getViewUrl( "", $topic ) );
&TWiki::Store::lockTopic( $theTopic, "on" );
if( $error ) {
$url = &TWiki::Func::getOopsUrl( $theWeb, $theTopic, "oopssaveerr", $error );
TWiki::redirect( $query, $url );
}
}
This does the job, but I'm wondering how dubious it is to do something like this? Will this be ok for now?
--
MartinWatt - 05 Nov 2002
Not the cleanest way since the Plugin API is not sufficient. Should basically work. Some issues:
- The Plugin's commonTagsHandler gets called more then once, save topic only if topic does not already exist.
- Don't assume that $query is set, e.g. it is not if topic rendering is called by a cron job. Needs a check if the variable exists:
my $query = &TWiki::Func::getCgiQuery();
if( $query && $query->param( 'xpsave' ) ) { #etc.
--
PeterThoeny - 09 Nov 2002
This is now possible in TWiki 4
Support.HowToCreateTopicWithoutEdit
The save script supports this directly - just replace edit with save in the form.
<form action='%SCRIPTURLPATH{"save"}%/%WEB%' method='post'>
Topic:
<input type="text" name="topic" value="YourNewTopic" />
<input type="hidden" name="templatetopic" value="YourTemplate" />
<input type="hidden" name="onlynewtopic" value="on" />
...
</form>
Thanks to
--
VickiBrown - 27 Dec 2007