1
# See bottom of file for license and copyright information
3
package Foswiki::UI::Preview;
9
require Foswiki::UI::Save;
10
require Foswiki::OopsException;
17
my $query = $session->{request};
18
my $web = $session->{webName};
19
my $topic = $session->{topicName};
20
my $user = $session->{user};
22
my ( $meta, $text, $saveOpts, $merged ) =
23
Foswiki::UI::Save::buildNewTopic( $session, 'preview' );
25
# Note: param(formtemplate) has already been decoded by buildNewTopic
26
# so the $meta entry reflects if it was used.
27
# get form fields to pass on
29
my $form = $meta->get('FORM') || '';
32
$formName = $form->{name}; # used later on as well
33
require Foswiki::Form;
34
my $formDef = new Foswiki::Form( $session, $web, $formName );
36
throw Foswiki::OopsException(
39
web => $session->{webName},
40
topic => $session->{topicName},
41
params => [ $web, $formName ]
44
$formFields = $formDef->renderHidden( $meta, 0 );
47
$session->{plugins}->dispatch( 'afterEditHandler', $text, $topic, $web );
49
my $skin = $session->getSkin();
50
my $template = $session->{prefs}->getPreferencesValue('VIEW_TEMPLATE')
52
my $tmpl = $session->templates->readTemplate( $template, $skin );
54
# if a VIEW_TEMPLATE is set, but does not exist or is not readable,
55
# revert to 'preview' template (same code as View.pm)
56
if ( !$tmpl && $template ne 'preview' ) {
57
$tmpl = $session->templates->readTemplate( 'preview', $skin );
58
$template = 'preview';
62
if ( $template eq 'preview' ) {
67
# only get the contents of TMPL:DEF{"content"}
68
$content = $session->templates->expandTemplate('content');
70
# put the text we have inside this template's content
71
$content =~ s/%TEXT%/$text/go;
73
# now we are ready to put the expanded and styled topic content in the
74
# 'normal' preview template
77
$tmpl = $session->templates->readTemplate( 'preview', $skin );
79
if ( $saveOpts->{minor} ) {
80
$tmpl =~ s/%DONTNOTIFYCHECKBOX%/checked="checked"/go;
83
$tmpl =~ s/%DONTNOTIFYCHECKBOX%//go;
85
if ( $saveOpts->{forcenewrevision} ) {
86
$tmpl =~ s/%FORCENEWREVISIONCHECKBOX%/checked="checked"/go;
89
$tmpl =~ s/%FORCENEWREVISIONCHECKBOX%//go;
91
my $saveCmd = $query->param('cmd') || '';
92
$tmpl =~ s/%CMD%/$saveCmd/go;
94
my $redirectTo = $query->param('redirectto') || '';
95
$tmpl =~ s/%REDIRECTTO%/$redirectTo/go;
98
$tmpl =~ s/%FORMTEMPLATE%/$formName/g;
100
my $parent = $meta->get('TOPICPARENT');
101
$parent = $parent->{name} if ($parent);
103
$tmpl =~ s/%TOPICPARENT%/$parent/g;
105
$session->enterContext( 'can_render_meta', $meta );
107
my $displayText = $content;
109
$session->handleCommonTags( $displayText, $web, $topic, $meta );
111
$session->renderer->getRenderedVersion( $displayText, $web, $topic );
113
# Disable links and inputs in the text
115
s#<a\s[^>]*>(.*?)</a>#<span class="foswikiEmulatedLink">$1</span>#gis;
116
$displayText =~ s/<(input|button|textarea) /<$1 disabled="disabled" /gis;
117
$displayText =~ s(</?form(|\s.*?)>)()gis;
118
$displayText =~ s/(<[^>]*\bon[A-Za-z]+=)('[^']*'|"[^"]*")/$1''/gis;
120
# let templates know the context so they can act on it
121
$session->enterContext( 'preview', 1 );
123
# note: preventing linkage in rendered form can only happen in templates
124
# see formtables.tmpl
126
$tmpl = $session->handleCommonTags( $tmpl, $web, $topic, $meta );
127
$tmpl = $session->renderer->getRenderedVersion( $tmpl, $web, $topic );
128
$tmpl =~ s/%TEXT%/$displayText/go;
130
# write the hidden form fields
131
$tmpl =~ s/%FORMFIELDS%/$formFields/go;
133
# SMELL: this should be done using CGI::hidden
134
$text = Foswiki::entityEncode( $text, "\n" );
136
$tmpl =~ s/%HIDDENTEXT%/$text/go;
138
$tmpl =~ s/<\/?(nop|noautolink)\/?>//gis;
140
# I don't know _where_ these should be done,
141
# so I'll do them as late as possible
142
my $originalrev = $query->param('originalrev'); # rev edit started on
143
#ASSERT($originalrev ne '%ORIGINALREV%') if DEBUG;
144
$tmpl =~ s/%ORIGINALREV%/$originalrev/go;
145
my $templatetopic = $query->param('templatetopic');
147
#ASSERT($templatetopic ne '%TEMPLATETOPIC%') if DEBUG;
148
$tmpl =~ s/%TEMPLATETOPIC%/$templatetopic/go;
150
#this one's worrying, its special, and not set much at all
151
#$tmpl =~ s/%SETTINGSTOPIC%/$settingstopic/go;
152
my $newtopic = $query->param('newtopic');
154
#ASSERT($newtopic ne '%NEWTOPIC%') if DEBUG;
155
$tmpl =~ s/%NEWTOPIC%/$newtopic/go;
157
$session->writeCompletePage($tmpl);
162
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
164
# Copyright (C) 2008-2009 Foswiki Contributors. Foswiki Contributors
165
# are listed in the AUTHORS file in the root of this distribution.
166
# NOTE: Please extend that file, not this notice.
168
# Additional copyrights apply to some or all of the code in this
171
# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
172
# and TWiki Contributors. All Rights Reserved. TWiki Contributors
173
# are listed in the AUTHORS file in the root of this distribution.
175
# This program is free software; you can redistribute it and/or
176
# modify it under the terms of the GNU General Public License
177
# as published by the Free Software Foundation; either version 2
178
# of the License, or (at your option) any later version. For
179
# more details read LICENSE in the root of this distribution.
181
# This program is distributed in the hope that it will be useful,
182
# but WITHOUT ANY WARRANTY; without even the implied warranty of
183
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
185
# As per the GPL, removal of this notice is prohibited.