Changeset 156

Show
Ignore:
Timestamp:
05/14/03 22:29:51 (6 years ago)
Author:
kake
Message:

0.12 14 May 2003

Added OpenGuides::CGI to manage cookies and things, used this to
do more code tidying. Added edit box position option to preferences.

Location:
trunk
Files:
2 added
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r154 r156  
    4949  variable => "stylesheet_url" 
    5050}, 
    51 { question => "what's the wiki called?", 
     51{ question => "what's the wiki called? (should be unique)", 
    5252  variable => "site_name", 
    5353  default  => "OpenGuides Wiki" 
  • trunk/Changes

    r154 r156  
    1 0.11     
     10.12    14 May 2003 
     2        Added OpenGuides::CGI to manage cookies and things, used this to 
     3        do more code tidying.  Added edit box position option to preferences. 
     4 
     50.11    14 May 2003 
    26        Added newpage.cgi for an easy way to create new pages. 
    37 
  • trunk/INSTALL

    r85 r156  
    9595  "What's the wiki called?" 
    9696 
    97 This is a title which will appear at the top of every page. 
     97This is a title which will appear at the top of every page.  If you have 
     98more than one OpenGuides installation at the same site then each should 
     99have a unique name, since this name is used to manage user preferences. 
    98100 
    99101 
  • trunk/MANIFEST

    r155 r156  
    88TROUBLESHOOTING 
    99lib/OpenGuides/Build.pm 
     10lib/OpenGuides/CGI.pm 
    1011lib/OpenGuides/Diff.pm 
    1112lib/OpenGuides/RDF.pm 
     
    4243t/01_add_test_data.t 
    4344t/11_utils.t 
     45t/13_cookies.t 
    4446t/15_template.t 
    4547t/21_rdf.t 
  • trunk/lib/OpenGuides.pm

    r154 r156  
    44use vars qw( $VERSION ); 
    55 
    6 $VERSION = '0.11'; 
     6$VERSION = '0.12'; 
    77 
    88=head1 NAME 
  • trunk/lib/OpenGuides/Template.pm

    r152 r156  
    33use strict; 
    44use vars qw( $VERSION ); 
    5 $VERSION = '0.02'; 
     5$VERSION = '0.03'; 
    66 
    77use Carp qw( croak ); 
     
    4848                                      template     => "node.tt", 
    4949                                      content_type => "text/html", 
     50                                      cookies      => $cookie, 
    5051                                      vars         => { foo => "bar" } 
    5152  ); 
     
    8586    my $header = ""; 
    8687    unless ( defined $args{content_type} and $args{content_type} eq "" ) { 
    87         $header = "Content-Type: text/html\n\n"; 
     88        $header = CGI::header( -cookie => $args{cookies} ); 
    8889    } 
    8990    my $output; 
  • trunk/preferences.cgi

    r52 r156  
    33use strict; 
    44use CGI; 
    5 use CGI::Cookie; 
    65use Config::Tiny; 
    7 use Template; 
     6use OpenGuides::CGI; 
     7use OpenGuides::Utils; 
     8use OpenGuides::Template; 
    89 
     10my $config = Config::Tiny->read("wiki.conf"); 
     11my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 
    912my $cgi = CGI->new(); 
    1013my $action = $cgi->param('action') || ''; 
     
    1922 
    2023sub set_preferences { 
    21     my $username = $cgi->param("username") || ""; 
    22     my $gc_link  = $cgi->param('include_geocache_link') || 0, 
    23     my @cookies; 
    24     push @cookies, CGI::Cookie->new( -name    => 'username', 
    25                                      -value   => $username, 
    26                                      -expires => '+12M', 
     24    my $username  = $cgi->param("username") || ""; 
     25    my $gc_link   = $cgi->param('include_geocache_link') || 0; 
     26    my $pre_above = $cgi->param('preview_above_edit_box') || 0; 
     27    my $cookie = OpenGuides::CGI->make_prefs_cookie( 
     28        config => $config, 
     29        username => $username, 
     30        include_geocache_link => $gc_link, 
     31        preview_above_edit_box => $pre_above 
    2732    ); 
    28  
    29     push @cookies, CGI::Cookie->new( -name    => 'include_geocache_link', 
    30                                      -value   => $gc_link, 
    31                                      -expires => '+12M', 
     33    print OpenGuides::Template->output( 
     34        wiki     => $wiki, 
     35        config   => $config, 
     36        template => "preferences.tt", 
     37        cookies  => $cookie, 
     38        vars     => { not_editable           => 1, 
     39                      username               => $username, 
     40                      include_geocache_link  => $gc_link, 
     41                      preview_above_edit_box => $pre_above 
     42                    } 
    3243    ); 
    33     print $cgi->header( -cookie => \@cookies ); 
    34  
    35     process_prefs_template( username              => $username, 
    36                             include_geocache_link => $gc_link ); 
    3744} 
    38  
    3945 
    4046sub show_form { 
    4147    # Get defaults for form fields from cookies. 
    42     my %cookies = CGI::Cookie->fetch; 
    43     my $username = $cookies{"username"} ? $cookies{"username"}->value : ""; 
    44     my $gc_link  = $cookies{"include_geocache_link"} ? $cookies{"include_geocache_link"}->value : 0; 
     48    my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); 
    4549 
    46     print $cgi->header; 
    47     process_prefs_template( show_form             => 1, 
    48                             username              => $username, 
    49                             include_geocache_link => $gc_link ); 
     50    print OpenGuides::Template->output( 
     51        wiki     => $wiki, 
     52        config   => $config, 
     53        template => "preferences.tt", 
     54        vars     => { %prefs, 
     55                      not_editable => 1, 
     56                      show_form    => 1 
     57                    } 
     58    ); 
    5059} 
    51  
    52  
    53 sub process_prefs_template { 
    54     # Some TT params are passed in to the sub. 
    55     my %tt_vars = @_; 
    56  
    57     # Others are global and we get them from the config file. 
    58     my $config = Config::Tiny->read("wiki.conf"); 
    59     foreach my $param ( qw( site_name stylesheet_url script_name home_name 
    60                             ) ) { 
    61         $tt_vars{$param} = $config->{_}->{$param}; 
    62     } 
    63  
    64     # This isn't a page you can edit. 
    65     $tt_vars{not_editable} = 1; 
    66  
    67     my %tt_conf = ( INCLUDE_PATH => $config->{_}->{template_path}, 
    68     ); 
    69  
    70     my $tt = Template->new( \%tt_conf ); 
    71     $tt->process( "preferences.tt", \%tt_vars ) or warn $tt->error; 
    72 } 
    73   
  • trunk/t/15_template.t

    r143 r156  
    11use strict; 
    2 use Test::More tests => 16; 
     2use Test::More tests => 17; 
    33use Config::Tiny; 
    44use Cwd; 
     5use CGI::Cookie; 
    56use CGI::Wiki::Formatter::UseMod; 
    67use Test::MockObject; 
     
    8081like( $output, qr/NODE PARAM: Test_Node/, "node_param var set" ); 
    8182 
     83# Test that cookies go in. 
     84my $cookie = CGI::Cookie->new( -name => "x", -value => "y" ); 
     85$output = OpenGuides::Template->output( 
     86    config   => $config, 
     87    template => "15_test.tt", 
     88    cookies  => $cookie 
     89); 
     90like( $output, qr/Set-Cookie: $cookie/, "cookie in header" ); 
  • trunk/templates/edit_form.tt

    r116 r156  
    33<h1 align="center">Edit "[% node_name %]"</h1> 
    44 
     5[% IF preview_html AND preview_above_edit_box %] 
     6  <h2>Preview</h2> 
     7  [% INCLUDE display_metadata.tt %] 
     8 
     9  [% preview_html %] 
     10 
     11  <br clear="all" /> 
     12 
     13  [% INCLUDE display_categories.tt %] 
     14 
     15[% END %] 
     16 
    517<form action="[% cgi_url %]" method="POST" enctype="application/x-www-form-urlencoded"> 
    618<table> 
     19        <tr> 
     20                <td align="center"><input type="submit" name="preview" value="Preview changes" /></td> 
     21                <td align="center"><input type="submit" name="Save" value="Save changes" /></td> 
     22        </tr> 
     23        <tr> 
     24                <td colspan="2" align="center"><a href="[% cgi_url %]?[% node_param %]">(cancel edit)</a></td> 
     25        </tr> 
    726        <tr> 
    827                <td colspan="2"> 
     
    94113</form> 
    95114 
    96 [% IF preview_html %] 
     115[% IF preview_html AND NOT preview_above_edit_box %] 
    97116  <h2>Preview</h2> 
    98117  [% INCLUDE display_metadata.tt %] 
     
    105124 
    106125[% END %] 
     126 
    107127[% INCLUDE footer.tt %] 
  • trunk/templates/preferences.tt

    r52 r156  
    2020 
    2121    <h1>Preferences</h1> 
     22 
     23    <p>Check this to put the preview above the edit area when previewing 
     24    a page edit:</p> 
     25    [% IF preview_above_edit_box %] 
     26      <input type="checkbox" name="preview_above_edit_box" value="1" checked /> 
     27    [% ELSE %] 
     28      <input type="checkbox" name="preview_above_edit_box" value="1" /> 
     29    [% END %] 
     30    <br /> 
     31 
    2232    <p>Check this to include &#8220;Look for nearby geocaches&#8221; link in navbar:</p> 
    2333    [% IF include_geocache_link %] 
     
    2636      <input type="checkbox" name="include_geocache_link" value="1" /> 
    2737    [% END %] 
     38    <br /> 
    2839 
    29     <br /> 
    3040    <input type="submit" value="Set it"> 
    3141    <input type="hidden" name="action" value="set_preferences"> 
     
    3848  <p>Username set to &#8220;[% username %]&#8221;</p> 
    3949 
     50  <p>Preview area shown 
     51    [% IF preview_above_edit_box %] 
     52      above 
     53    [% ELSE %] 
     54      below 
     55    [% END %] 
     56  edit box.</p> 
     57 
    4058  <p>&#8220;Look for nearby geocaches&#8221; link 
    4159    [% UNLESS include_geocache_link %] not [% END %] 
    4260  included in navbar</p> 
    4361 
    44   <p><a href="[% script_name %]">Return to the wiki</a></p> 
     62  <p><a href="[% cgi_url %]">Return to the wiki</a></p> 
    4563 
    4664[% END %] 
  • trunk/wiki.cgi

    r154 r156  
    55 
    66use vars qw( $VERSION ); 
    7 $VERSION = '0.11'; 
     7$VERSION = '0.12'; 
    88 
    99use CGI qw/:standard/; 
    1010use CGI::Carp qw(croak); 
    11 use CGI::Cookie; 
    1211use CGI::Wiki; 
    1312use CGI::Wiki::Search::SII; 
     
    1817use Geography::NationalGrid; 
    1918use Geography::NationalGrid::GB; 
     19use OpenGuides::CGI; 
    2020use OpenGuides::RDF; 
    2121use OpenGuides::Utils; 
     
    352352 
    353353    if ($wiki->verify_checksum($node, $checksum)) { 
    354         my %tt_vars = ( content      => $q->escapeHTML($content), 
    355                         %tt_metadata_vars, 
    356                         preview_html => $wiki->format($content), 
    357                         checksum     => $q->escapeHTML($checksum) ); 
    358  
     354        my %tt_vars = ( 
     355            %tt_metadata_vars, 
     356            content                => $q->escapeHTML($content), 
     357            preview_html           => $wiki->format($content), 
     358            preview_above_edit_box => get_cookie( "preview_above_edit_box" ), 
     359            checksum               => $q->escapeHTML($checksum) 
     360        ); 
    359361        process_template("edit_form.tt", $node, \%tt_vars); 
    360362    } else { 
     
    399401 
    400402sub get_cookie { 
    401     my $cookie_name = shift or return ""; 
    402     my %defaults = ( username              => "Anonymous", 
    403                      include_geocache_link => 0 ); 
    404     my %cookies = fetch CGI::Cookie; 
    405     if ($cookies{$cookie_name}) { 
    406         return $cookies{$cookie_name}->value; 
    407     } 
    408     else { 
    409         return $defaults{$cookie_name}; 
    410     } 
     403    my $pref_name = shift or return ""; 
     404warn "[$pref_name]"; 
     405    my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); 
     406warn "[$cookie_data{$pref_name}]"; 
     407    return $cookie_data{$pref_name}; 
    411408} 
    412409