*** save Sun Aug 4 04:13:55 2002 --- savemulti Thu Aug 29 10:55:14 2002 *************** *** 17,22 **** --- 17,30 ---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html + # + # CN 28 Feb 2002 + # this save script can be invoked with "action" var being: + # Save - save the topic, go back to view mode + # QuietSave - save but do not email people on notification list + # Preview - preview the page the old way + # Checkpoint - save and re-edit immediately + # Cancel - cancel edit, release lock # Set library paths in @INC, at compile time BEGIN { require './setlib.cfg'; } *************** *** 36,41 **** --- 44,50 ---- my $theRemoteUser = $query->remote_user(); my $theTopic = $query->param( 'topic' ); my $theUrl = $query->url; + my $saveaction = $query->param( 'action' ); ( $topic, $webName, $dummy, $userName ) = &TWiki::initialize( $thePathInfo, $theRemoteUser, $theTopic, $theUrl, $query ); *************** *** 77,82 **** --- 86,101 ---- my $text = $query->param( "text" ); my $unlock = $query->param( "unlock" ) || ""; my $dontNotify = $query->param( "dontnotify" ) || ""; + if ( $saveaction eq "Checkpoint" ) { + $dontNotify = "checked"; + $unlock = ""; + } elsif ( $saveaction eq "QuietSave" ) { + $dontNotify = "checked"; + } elsif ( $saveaction eq "Cancel" ) { + my $viewURL = &TWiki::getScriptUrl( $webName, $topic, "view" ); + TWiki::redirect( $query, "$viewURL?unlock=on" ); + return; + } # PTh 06 Nov 2000: check if proper use of save script if( ! ( defined $text ) ) { *************** *** 95,100 **** --- 114,125 ---- &TWiki::Form::changeForm( $webName, $topic, $query ); return; } + + # CN implementation of Preview as a button + if( $saveaction eq "Preview" ) { + &preview(); + return; + } $text = &TWiki::decodeSpecialChars( $text ); $text =~ s/ {3}/\t/go; *************** *** 110,115 **** --- 135,141 ---- # parent setting my $theParent = $query->param( 'topicparent' ) || ""; + $theParent = "" if( $theParent eq "%TOPICPARENT%" ); # means keep same if( $theParent ) { $meta->put( "TOPICPARENT", ( "name" => $theParent ) ); } *************** *** 130,135 **** --- 156,271 ---- my $url = &TWiki::getOopsUrl( $webName, $topic, "oopssaveerr", $error ); TWiki::redirect( $query, $url ); } else { + if( $saveaction eq "Checkpoint" ) { + my $editURL = &TWiki::getScriptUrl( $webName, $topic, "edit" ); + TWiki::redirect( $query, "$editURL?t=".time() ); + } else { TWiki::redirect( $query, &TWiki::getViewUrl( "", $topic ) ); + } + } + } + + ## CN 28 feb 2002 - Preview code, copied/adapted from preview script + sub preview + { + my $tmpl = ""; + my $ptext = ""; + my $meta = ""; + my $formFields = ""; + + # reset lock time, this is to prevent contention in case of a long edit session + &TWiki::Store::lockTopic( $topic ); + + my $skin = $query->param( "skin" ) || &TWiki::Prefs::getPreferencesValue( "SKIN" ); + + # Is user looking to change the form used? Sits oddly in preview, but to avoid Javascript and pick + # up text on edit page it has to be in preview. + my $changeform = $query->param( 'submitChangeForm' ) || ""; + if( $changeform ) { + &TWiki::Form::changeForm( $webName, $topic, $query ); + return; + } + + # get view template, standard view or a view with a different skin + $tmpl = &TWiki::Store::readTemplate( "preview", $skin ); + my $dontNotify = $query->param( "dontnotify" ) || ""; + $tmpl =~ s/%DONTNOTIFY%/$dontNotify/go; + my $saveCmd = $query->param( "cmd" ) || ""; + if( $saveCmd ) { + if( ! &TWiki::Access::userIsInGroup( $wikiUserName, $TWiki::superAdminGroup ) ) { + # user has no permission to execute undocumented cmd=... parameter + my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsaccessgroup", "$TWiki::mainWebname.$TWiki::superAdminGroup" ); + TWiki::redirect( $query, $url ); + return; + } + $tmpl =~ s/\(preview\)/\(preview cmd=$saveCmd\)/go; } + $tmpl =~ s/%CMD%/$saveCmd/go; + + if( $saveCmd ne "repRev" ) { + my $dummy = ""; + ( $meta, $dummy ) = &TWiki::Store::readTopic( $webName, $topic ); + + # parent setting + my $theParent = $query->param( 'topicparent' ) || ""; + $theParent = "" if( $theParent eq "%TOPICPARENT%" ); # means keep same + if( $theParent ) { + $tmpl =~ s/%TOPICPARENT%/$theParent/go; + $meta->put( "TOPICPARENT", ( "name" => $theParent ) ); + } + $tmpl =~ s/%TOPICPARENT%/$theParent/; + + my $formTemplate = $query->param( "formtemplate" ); + if( $formTemplate ) { + $meta->remove( "FORM" ); + $meta->put( "FORM", ( name => $formTemplate ) ) if( $formTemplate ne "none" ); + $tmpl =~ s/%FORMTEMPLATE%/$formTemplate/go; + } else { + $tmpl =~ s/%FORMTEMPLATE%//go; + } + + # get the edited text and combine text, form and attachments for preview + &TWiki::Form::fieldVars2Meta( $webName, $query, $meta ); + $text = $query->param( "text" ); + if( ! $text ) { + # empty topic not allowed + my $url = &TWiki::getOopsUrl( $webName, $topic, "oopsempty" ); + print $query->redirect( $url ); + return; + } + $ptext = $text; + + if( $meta->count( "FORM" ) ) { + $formFields = &TWiki::Form::getFieldParams( $meta ); + } + } else { + $text = $query->param( "text" ); # text to save + ( $meta, $ptext ) = &TWiki::Store::_extractMetaData( $webName, $topic, $text ); + $text =~ s/%_(.)_%/%__$1__%/go; + } + + my @verbatim = (); + $ptext = &TWiki::takeOutVerbatim( $ptext, \@verbatim ); + $ptext =~ s/ {3}/\t/go; + $ptext = &TWiki::handleCommonTags( $ptext, $topic ); + $ptext = &TWiki::getRenderedVersion( $ptext ); + + # do not allow click on link before save: + $ptext =~ s@(href=".*?")@href="%SCRIPTURLPATH%/oops%SCRIPTSUFFIX%/%WEB%/%TOPIC%\?template=oopspreview"@goi; + $ptext = &TWiki::handleCommonTags( $ptext, $topic ); + $ptext = &TWiki::putBackVerbatim( $ptext, "pre", @verbatim ); + + $tmpl = &TWiki::handleCommonTags( $tmpl, $topic ); + $tmpl = &TWiki::handleMetaTags( $webName, $topic, $tmpl, $meta ); + $tmpl = &TWiki::getRenderedVersion( $tmpl ); + $tmpl =~ s/%TEXT%/$ptext/go; + + $text = &TWiki::encodeSpecialChars( $text ); + + $tmpl =~ s/%HIDDENTEXT%/$text/go; + $tmpl =~ s/%FORMFIELDS%/$formFields/go; + $tmpl =~ s|( ?) *\n?|$1|gois; # remove tags (PTh 06 Nov 2000) + + &TWiki::writeHeader( $query ); + print $tmpl; }