*** lib/safe_TWiki.pm Tue Feb 10 17:10:38 2004 --- lib/TWiki.pm Tue Feb 10 17:15:34 2004 *************** sub handleInternalTags *** 2096,2101 **** --- 2096,2121 ---- } + # Expand limited set of variables during new topic creation + # NOTE this function collects duplicate functionality from the edit, register + # and save scripts. It should really be in a more appropriate place than + # "TWiki.pm" - but there isn't one. + sub expandVariablesForTopicCreation { + my $text = shift; + my $webName = shift; + my $userName = shift; + my $wikiName = shift; + my $today = &TWiki::getGmDate(); + $text =~ s/%DATE%/$today/go; + $text =~ s/%USERNAME%/$userName/go; # "jdoe" + $text =~ s/%WIKINAME%/$wikiName/go; # "JonDoe" + $text =~ s/%WIKIUSERNAME%/$webName.$wikiName/go; # "Main.JonDoe" + $text =~ s/%URLPARAM{(.*?)}%/TWiki::handleUrlParam($1)/geo; # expand URL parameters + $text =~ s/%NOP{.*?}%//gos; # Remove filler: Use it to remove access control at time of + $text =~ s/%NOP%//go; # topic instantiation or to prevent search from hitting a template + return $text; + } + # ========================= sub takeOutVerbatim { *** bin/safe_edit Tue Feb 10 17:08:29 2004 --- bin/edit Tue Feb 10 17:15:36 2004 *************** sub main *** 175,191 **** $formTemplate = $args{"name"}; } ! # expand limited set of variables ! # NOTE: Keep it in sync with the register script (FIXME: Put in function) ! my $today = &TWiki::getGmDate(); ! my $wikiName = TWiki::userToWikiName( $userName, 1 ); ! $text =~ s/%DATE%/$today/go; ! $text =~ s/%USERNAME%/$userName/go; # "jdoe" ! $text =~ s/%WIKINAME%/$wikiName/go; # "JonDoe" ! $text =~ s/%WIKIUSERNAME%/$wikiUserName/go; # "Main.JonDoe" ! $text =~ s/%URLPARAM{(.*?)}%/TWiki::handleUrlParam($1)/geo; # expand URL parameters ! $text =~ s/%NOP{.*?}%//gos; # Remove filler: Use it to remove access control at time of ! $text =~ s/%NOP%//go; # topic instantiation or to prevent search from hitting a template } # parent setting --- 175,182 ---- $formTemplate = $args{"name"}; } ! ! $text = TWiki::expandVariablesForTopicCreation( $text, $webName, $userName, $wikiName ); } # parent setting *** bin/safe_register Tue Feb 10 17:09:26 2004 --- bin/register Tue Feb 10 17:15:42 2004 *************** sub main *** 193,209 **** } $text = "$before$after"; ! # expand limited set of variables ! # NOTE: Keep it in sync with the edit script (FIXME: Put in function) ! my $today = &TWiki::getGmDate(); ! my $userName = $remoteUser || $wikiName; ! $text =~ s/%DATE%/$today/go; ! $text =~ s/%USERNAME%/$userName/go; # "jdoe" ! $text =~ s/%WIKINAME%/$wikiName/go; # "JonDoe" ! $text =~ s/%WIKIUSERNAME%/$webName.$wikiName/go; # "Main.JonDoe" ! $text =~ s/%URLPARAM{(.*?)}%/TWiki::handleUrlParam($1)/geo; # expand URL parameters ! $text =~ s/%NOP{.*?}%//gos; # Remove filler: Use it to remove access control at time of ! $text =~ s/%NOP%//go; # topic instantiation or to prevent search from hitting a template $meta->put( "TOPICPARENT", ( "name" => $TWiki::wikiUsersTopicname ) ); &TWiki::Store::saveTopic( $webName, $wikiName, $text, $meta, "", 1 ); --- 193,199 ---- } $text = "$before$after"; ! $text = TWiki::expandVariablesForTopicCreation( $text, $webName, $userName, $wikiName ); $meta->put( "TOPICPARENT", ( "name" => $TWiki::wikiUsersTopicname ) ); &TWiki::Store::saveTopic( $webName, $wikiName, $text, $meta, "", 1 ); *** bin/safe_save Mon Nov 24 04:23:14 2003 --- bin/save Tue Feb 10 17:15:48 2004 *************** sub main *** 43,48 **** --- 43,56 ---- my $thePathInfo = $query->path_info(); my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); + + # Check for a "save as different topic" + my $topicoverride = $query->param( 'newtopic' ); + my $meta = ""; + if ($topicoverride) { + $theTopic = $topicoverride; + } + my $theUrl = $query->url; ( $topic, $webName, $dummy, $userName ) = *************** sub main *** 83,88 **** --- 91,106 ---- # get text and other parameters my $text = $query->param( "text" ); + + # A template was requested; read it, and expand URLPARAMs within the + # template using our CGI record + my $templatetopic = $query->param( "templatetopic"); + if ($templatetopic) { + ($meta, $text) = &TWiki::Store::readTopic( $webName, $templatetopic ); + my $wikiName = TWiki::userToWikiName( $userName, 1 ); + $text = TWiki::expandVariablesForTopicCreation( $text, $webName, $userName, $wikiName ); + } + my $unlock = $query->param( "unlock" ) || ""; my $dontNotify = $query->param( "dontnotify" ) || ""; *************** sub main *** 114,120 **** } else { # normal case: Get latest attachment from file for preview my $tmp; ! ( $meta, $tmp ) = &TWiki::Store::readTopic( $webName, $topic ); # parent setting my $theParent = $query->param( 'topicparent' ) || ""; --- 132,139 ---- } else { # normal case: Get latest attachment from file for preview my $tmp; ! # read meta (if not already read when reading template) ! ( $meta, $tmp ) = &TWiki::Store::readTopic( $webName, $topic ) unless $meta; # parent setting my $theParent = $query->param( 'topicparent' ) || ""; *************** sub main *** 130,136 **** $meta->put( "FORM", ( name => $formTemplate ) ) if( $formTemplate ne "none" ); } ! &TWiki::Form::fieldVars2Meta( $webName, $query, $meta ); $text = &TWiki::Prefs::updateSetFromForm( $meta, $text ); } --- 149,156 ---- $meta->put( "FORM", ( name => $formTemplate ) ) if( $formTemplate ne "none" ); } ! # Expand field variables, unless this new page is templated ! &TWiki::Form::fieldVars2Meta( $webName, $query, $meta ) unless $templatetopic; $text = &TWiki::Prefs::updateSetFromForm( $meta, $text ); } *************** sub main *** 141,146 **** my $url = &TWiki::getOopsUrl( $webName, $topic, "oopssaveerr", $error ); TWiki::redirect( $query, $url ); } else { ! TWiki::redirect( $query, &TWiki::getViewUrl( "", $topic ) ); } } --- 161,167 ---- my $url = &TWiki::getOopsUrl( $webName, $topic, "oopssaveerr", $error ); TWiki::redirect( $query, $url ); } else { ! # Note third parameter to getViewUrl is OWiki 'spacesOk' ! TWiki::redirect( $query, &TWiki::getViewUrl( "", $topic, 1 ) ); } }