Changeset 2498


Ignore:
Timestamp:
02/14/09 15:36:06 (4 years ago)
Author:
ArthurClemens
Message:

Item909: VIEW_TEMPLATE overrides preview template, leaving out all topic actions: fix for Preview.tmpl to load the topic content (in TMPL:DEF 'content') inside the preview template; ran perltidy

Location:
trunk/core/lib/Foswiki
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/Foswiki/Meta.pm

    r1779 r2498  
    7878sub new { 
    7979    my ( $class, $session, $web, $topic, $text ) = @_; 
     80 
    8081    # $text - optional raw text to convert to meta-data form 
    8182    my $this = bless( { _session => $session }, $class ); 
     
    140141 
    141142sub web { 
    142     my ($this, $web) = @_; 
     143    my ( $this, $web ) = @_; 
    143144    $this->{_web} = $web if defined $web; 
    144145    return $_[0]->{_web}; 
     
    155156 
    156157sub topic { 
    157     my ($this, $topic) = @_; 
     158    my ( $this, $topic ) = @_; 
    158159    $this->{_topic} = $topic if defined $topic; 
    159160    return $this->{_topic}; 
     
    635636=begin TML 
    636637 
    637 ---++ ObjectMethod renderFormForDisplay() -> $html 
     638---++ ObjectMethod renderFormForDisplay( $templates ) -> $html 
    638639 
    639640Render the form contained in the meta for display. 
     
    642643 
    643644sub renderFormForDisplay { 
    644     my $this = shift; 
     645    my ( $this, $templates ) = @_; 
     646 
     647    # NOTE: param $templates is not used 
    645648 
    646649    my $fname = $this->getFormName(); 
     
    695698    if ($fname) { 
    696699        require Foswiki::Form; 
    697         my $form = new Foswiki::Form( $this->{_session}, $this->{_web}, $fname ); 
     700        my $form = 
     701          new Foswiki::Form( $this->{_session}, $this->{_web}, $fname ); 
    698702        if ($form) { 
    699703            my $field = $form->getField($name); 
  • trunk/core/lib/Foswiki/Templates.pm

    r1794 r2498  
    109109$tmpls->expandTemplate('"blah"); 
    110110$tmpls->expandTemplate('context="view" then="sigh" else="humph"'); 
     111</verbatim> 
    111112 
    112113=cut 
     
    247248            } 
    248249            $key = $1; 
     250 
    249251            # SMELL: unchecked implicit untaint? 
    250252            $val = $2; 
     
    257259            $key                  = ''; 
    258260            $val                  = ''; 
     261 
    259262            # SMELL: unchecked implicit untaint? 
    260263            $result .= $1; 
     
    303306    my $userdirname = $name; 
    304307    if ( $name =~ /^(.+)\.(.+?)$/ ) { 
     308 
    305309        # ucfirst taints if use locale is in force 
    306         $userdirweb  = Foswiki::Sandbox::untaintUnchecked(ucfirst($1)); 
    307         $userdirname = Foswiki::Sandbox::untaintUnchecked(ucfirst($2)); 
     310        $userdirweb  = Foswiki::Sandbox::untaintUnchecked( ucfirst($1) ); 
     311        $userdirname = Foswiki::Sandbox::untaintUnchecked( ucfirst($2) ); 
    308312 
    309313        # if the name can be parsed into $web.$name, then this is an attempt 
     
    320324    } 
    321325    else { 
     326 
    322327        # ucfirst taints if use locale is in force 
    323        $userdirweb  = Foswiki::Sandbox::untaintUnchecked(ucfirst($userdirweb)); 
    324        $userdirname = Foswiki::Sandbox::untaintUnchecked(ucfirst($userdirname)); 
     328        $userdirweb = 
     329          Foswiki::Sandbox::untaintUnchecked( ucfirst($userdirweb) ); 
     330        $userdirname = 
     331          Foswiki::Sandbox::untaintUnchecked( ucfirst($userdirname) ); 
    325332    } 
    326333 
     
    329336 
    330337    my @templatePath = split( /\s*,\s*/, $Foswiki::cfg{TemplatePath} ); 
    331     if (($Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{Enabled}) 
    332         && (lc($name) eq 'foswiki') 
    333         && defined($Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{TemplatePath}) 
    334          ) { 
     338    if ( 
     339           ( $Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{Enabled} ) 
     340        && ( lc($name) eq 'foswiki' ) 
     341        && defined( 
     342            $Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{TemplatePath} 
     343        ) 
     344      ) 
     345    { 
     346 
    335347        #TWikiCompatibility, need to test to see if there is a twiki.skin tmpl 
    336         @templatePath = @{$Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{TemplatePath}}; 
     348        @templatePath = 
     349          @{ $Foswiki::cfg{Plugins}{TWikiCompatibilityPlugin}{TemplatePath} }; 
    337350    } 
    338351 
  • trunk/core/lib/Foswiki/UI/Preview.pm

    r1779 r2498  
    2525    # Note: param(formtemplate) has already been decoded by buildNewTopic 
    2626    # so the $meta entry reflects if it was used. 
     27    # get form fields to pass on 
    2728    my $formFields = ''; 
    2829    my $form = $meta->get('FORM') || ''; 
     30    my $formName; 
    2931    if ($form) { 
    30         $form = $form->{name};    # used later on as well 
     32        $formName = $form->{name};    # used later on as well 
    3133        require Foswiki::Form; 
    32         my $formDef = new Foswiki::Form( $session, $web, $form ); 
     34        my $formDef = new Foswiki::Form( $session, $web, $formName ); 
    3335        unless ($formDef) { 
    3436            throw Foswiki::OopsException( 
     
    3739                web    => $session->{webName}, 
    3840                topic  => $session->{topicName}, 
    39                 params => [ $web, $form ] 
     41                params => [ $web, $formName ] 
    4042            ); 
    4143        } 
     
    4547    $session->{plugins}->dispatch( 'afterEditHandler', $text, $topic, $web ); 
    4648 
    47     my $skin = $session->getSkin(); 
    48     my $template = 
    49       $session->{prefs}->getPreferencesValue('VIEW_TEMPLATE') 
     49    my $skin     = $session->getSkin(); 
     50    my $template = $session->{prefs}->getPreferencesValue('VIEW_TEMPLATE') 
    5051      || 'preview'; 
    5152    my $tmpl = $session->templates->readTemplate( $template, $skin ); 
     
    5657        $tmpl = $session->templates->readTemplate( 'preview', $skin ); 
    5758    } 
     59 
     60    my $content = ''; 
     61    if ( $template eq 'preview' ) { 
     62        $content = $text; 
     63    } 
     64    else { 
     65 
     66        # only get the contents of TMPL:DEF{"content"} 
     67        $content = $session->templates->expandTemplate('content'); 
     68 
     69        # put the text we have inside this template's content 
     70        $content =~ s/%TEXT%/$text/go; 
     71         
     72        # now we are ready to put the expanded and styled topic content in the 
     73        # 'normal' preview template 
     74    } 
     75 
     76    $tmpl = $session->templates->readTemplate( 'preview', $skin ); 
    5877 
    5978    if ( $saveOpts->{minor} ) { 
     
    7594    $tmpl =~ s/%REDIRECTTO%/$redirectTo/go; 
    7695 
    77     $tmpl =~ s/%FORMTEMPLATE%/$form/g; 
     96    $tmpl =~ s/%FORMTEMPLATE%/$formName/g if $formName; 
    7897 
    7998    my $parent = $meta->get('TOPICPARENT'); 
     
    84103    $session->enterContext( 'can_render_meta', $meta ); 
    85104 
    86     my $dispText = $text; 
    87     $dispText = $session->handleCommonTags( $dispText, $web, $topic, $meta ); 
    88     $dispText = 
    89       $session->renderer->getRenderedVersion( $dispText, $web, $topic ); 
     105    my $displayText = $content; 
     106    $displayText = 
     107      $session->handleCommonTags( $displayText, $web, $topic, $meta ); 
     108    $displayText = 
     109      $session->renderer->getRenderedVersion( $displayText, $web, $topic ); 
    90110 
    91111    # Disable links and inputs in the text 
    92     $dispText =~ 
     112    $displayText =~ 
    93113      s#<a\s[^>]*>(.*?)</a>#<span class="foswikiEmulatedLink">$1</span>#gis; 
    94     $dispText =~ s/<(input|button|textarea) /<$1 disabled="disabled" /gis; 
    95     $dispText =~ s(</?form(|\s.*?)>)()gis; 
    96     $dispText =~ s/(<[^>]*\bon[A-Za-z]+=)('[^']*'|"[^"]*")/$1''/gis; 
     114    $displayText =~ s/<(input|button|textarea) /<$1 disabled="disabled" /gis; 
     115    $displayText =~ s(</?form(|\s.*?)>)()gis; 
     116    $displayText =~ s/(<[^>]*\bon[A-Za-z]+=)('[^']*'|"[^"]*")/$1''/gis; 
     117 
     118    # let templates know the context so they can act on it 
     119    $session->enterContext( 'preview', 1 ); 
     120 
     121    # note: preventing linkage in rendered form can only happen in templates 
     122    # see formtables.tmpl 
    97123 
    98124    $tmpl = $session->handleCommonTags( $tmpl, $web, $topic, $meta ); 
    99125    $tmpl = $session->renderer->getRenderedVersion( $tmpl, $web, $topic ); 
    100     $tmpl =~ s/%TEXT%/$dispText/go; 
     126    $tmpl =~ s/%TEXT%/$displayText/go; 
     127 
     128    # write the hidden form fields 
    101129    $tmpl =~ s/%FORMFIELDS%/$formFields/go; 
    102130 
     
    108136    $tmpl =~ s/<\/?(nop|noautolink)\/?>//gis; 
    109137 
    110  #I don't know _where_ these should be done, so I'll do them as late as possible 
     138    # I don't know _where_ these should be done, 
     139    # so I'll do them as late as possible 
    111140    my $originalrev = $query->param('originalrev');    # rev edit started on 
    112141         #ASSERT($originalrev ne '%ORIGINALREV%') if DEBUG; 
Note: See TracChangeset for help on using the changeset viewer.