Changeset 156
- Timestamp:
- 05/14/03 22:29:51 (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 modified
-
Build.PL (modified) (1 diff)
-
Changes (modified) (1 diff)
-
INSTALL (modified) (1 diff)
-
MANIFEST (modified) (2 diffs)
-
lib/OpenGuides.pm (modified) (1 diff)
-
lib/OpenGuides/CGI.pm (added)
-
lib/OpenGuides/Template.pm (modified) (3 diffs)
-
preferences.cgi (modified) (2 diffs)
-
t/13_cookies.t (added)
-
t/15_template.t (modified) (2 diffs)
-
templates/edit_form.tt (modified) (3 diffs)
-
templates/preferences.tt (modified) (3 diffs)
-
wiki.cgi (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Build.PL
r154 r156 49 49 variable => "stylesheet_url" 50 50 }, 51 { question => "what's the wiki called? ",51 { question => "what's the wiki called? (should be unique)", 52 52 variable => "site_name", 53 53 default => "OpenGuides Wiki" -
trunk/Changes
r154 r156 1 0.11 1 0.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 5 0.11 14 May 2003 2 6 Added newpage.cgi for an easy way to create new pages. 3 7 -
trunk/INSTALL
r85 r156 95 95 "What's the wiki called?" 96 96 97 This is a title which will appear at the top of every page. 97 This is a title which will appear at the top of every page. If you have 98 more than one OpenGuides installation at the same site then each should 99 have a unique name, since this name is used to manage user preferences. 98 100 99 101 -
trunk/MANIFEST
r155 r156 8 8 TROUBLESHOOTING 9 9 lib/OpenGuides/Build.pm 10 lib/OpenGuides/CGI.pm 10 11 lib/OpenGuides/Diff.pm 11 12 lib/OpenGuides/RDF.pm … … 42 43 t/01_add_test_data.t 43 44 t/11_utils.t 45 t/13_cookies.t 44 46 t/15_template.t 45 47 t/21_rdf.t -
trunk/lib/OpenGuides.pm
r154 r156 4 4 use vars qw( $VERSION ); 5 5 6 $VERSION = '0.1 1';6 $VERSION = '0.12'; 7 7 8 8 =head1 NAME -
trunk/lib/OpenGuides/Template.pm
r152 r156 3 3 use strict; 4 4 use vars qw( $VERSION ); 5 $VERSION = '0.0 2';5 $VERSION = '0.03'; 6 6 7 7 use Carp qw( croak ); … … 48 48 template => "node.tt", 49 49 content_type => "text/html", 50 cookies => $cookie, 50 51 vars => { foo => "bar" } 51 52 ); … … 85 86 my $header = ""; 86 87 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} ); 88 89 } 89 90 my $output; -
trunk/preferences.cgi
r52 r156 3 3 use strict; 4 4 use CGI; 5 use CGI::Cookie;6 5 use Config::Tiny; 7 use Template; 6 use OpenGuides::CGI; 7 use OpenGuides::Utils; 8 use OpenGuides::Template; 8 9 10 my $config = Config::Tiny->read("wiki.conf"); 11 my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 9 12 my $cgi = CGI->new(); 10 13 my $action = $cgi->param('action') || ''; … … 19 22 20 23 sub 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 27 32 ); 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 } 32 43 ); 33 print $cgi->header( -cookie => \@cookies );34 35 process_prefs_template( username => $username,36 include_geocache_link => $gc_link );37 44 } 38 39 45 40 46 sub show_form { 41 47 # 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 ); 45 49 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 ); 50 59 } 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_name60 ) ) {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 1 1 use strict; 2 use Test::More tests => 1 6;2 use Test::More tests => 17; 3 3 use Config::Tiny; 4 4 use Cwd; 5 use CGI::Cookie; 5 6 use CGI::Wiki::Formatter::UseMod; 6 7 use Test::MockObject; … … 80 81 like( $output, qr/NODE PARAM: Test_Node/, "node_param var set" ); 81 82 83 # Test that cookies go in. 84 my $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 ); 90 like( $output, qr/Set-Cookie: $cookie/, "cookie in header" ); -
trunk/templates/edit_form.tt
r116 r156 3 3 <h1 align="center">Edit "[% node_name %]"</h1> 4 4 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 5 17 <form action="[% cgi_url %]" method="POST" enctype="application/x-www-form-urlencoded"> 6 18 <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> 7 26 <tr> 8 27 <td colspan="2"> … … 94 113 </form> 95 114 96 [% IF preview_html %]115 [% IF preview_html AND NOT preview_above_edit_box %] 97 116 <h2>Preview</h2> 98 117 [% INCLUDE display_metadata.tt %] … … 105 124 106 125 [% END %] 126 107 127 [% INCLUDE footer.tt %] -
trunk/templates/preferences.tt
r52 r156 20 20 21 21 <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 22 32 <p>Check this to include “Look for nearby geocaches” link in navbar:</p> 23 33 [% IF include_geocache_link %] … … 26 36 <input type="checkbox" name="include_geocache_link" value="1" /> 27 37 [% END %] 38 <br /> 28 39 29 <br />30 40 <input type="submit" value="Set it"> 31 41 <input type="hidden" name="action" value="set_preferences"> … … 38 48 <p>Username set to “[% username %]”</p> 39 49 50 <p>Preview area shown 51 [% IF preview_above_edit_box %] 52 above 53 [% ELSE %] 54 below 55 [% END %] 56 edit box.</p> 57 40 58 <p>“Look for nearby geocaches” link 41 59 [% UNLESS include_geocache_link %] not [% END %] 42 60 included in navbar</p> 43 61 44 <p><a href="[% script_name%]">Return to the wiki</a></p>62 <p><a href="[% cgi_url %]">Return to the wiki</a></p> 45 63 46 64 [% END %] -
trunk/wiki.cgi
r154 r156 5 5 6 6 use vars qw( $VERSION ); 7 $VERSION = '0.1 1';7 $VERSION = '0.12'; 8 8 9 9 use CGI qw/:standard/; 10 10 use CGI::Carp qw(croak); 11 use CGI::Cookie;12 11 use CGI::Wiki; 13 12 use CGI::Wiki::Search::SII; … … 18 17 use Geography::NationalGrid; 19 18 use Geography::NationalGrid::GB; 19 use OpenGuides::CGI; 20 20 use OpenGuides::RDF; 21 21 use OpenGuides::Utils; … … 352 352 353 353 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 ); 359 361 process_template("edit_form.tt", $node, \%tt_vars); 360 362 } else { … … 399 401 400 402 sub 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 ""; 404 warn "[$pref_name]"; 405 my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); 406 warn "[$cookie_data{$pref_name}]"; 407 return $cookie_data{$pref_name}; 411 408 } 412 409
