Author: ilmari Date: 2007-06-17 00:57:32 +0100 (Sun, 17 Jun 2007) New Revision: 1085
Modified: trunk/Changes trunk/lib/OpenGuides/CGI.pm trunk/lib/OpenGuides/Template.pm trunk/preferences.cgi trunk/t/59_preferences.t trunk/templates/navbar_tools.tt trunk/templates/preferences.tt Log: Clean up fallout from prefs cleanup - Make OpenGuides::Template->output pass the provided cookies to OpenGuides::CGI->get_prefs_from_cookie, where this overrides any browser-supplied cookie. - Use the prefs hash explcitly where needed (fixes #216).
=== Targets to commit (you may delete items from it) === M /home/ilmari/src/openguides-trunk/lib/Changes.pm M /home/ilmari/src/openguides-trunk/lib/OpenGuides/CGI.pm M /home/ilmari/src/openguides-trunk/lib/OpenGuides/Template.pm M /home/ilmari/src/openguides-trunk/preferences.cgi M /home/ilmari/src/openguides-trunk/t/59_preferences.t M /home/ilmari/src/openguides-trunk/templates/preferences.tt M /home/ilmari/src/openguides-trunk/templates/navbar_tools.tt
Modified: trunk/Changes =================================================================== --- trunk/Changes 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/Changes 2007-06-16 23:57:32 UTC (rev 1085) @@ -20,6 +20,8 @@ someone tries to view a nonexistent node. Validate input geodata (#22) List all contributors in RDF version of nodes (#106). + The "Look for nearby geocaches" preference and link now actually work + (#216).
0.60 13 May 2007 Removed footer search from edit page (shouldn't have been there).
Modified: trunk/lib/OpenGuides/CGI.pm =================================================================== --- trunk/lib/OpenGuides/CGI.pm 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/lib/OpenGuides/CGI.pm 2007-06-16 23:57:32 UTC (rev 1085) @@ -136,12 +136,16 @@ =item B<get_prefs_from_cookie>
my %prefs = OpenGuides::CGI->get_prefs_from_cookie( - config => $config + config => $config, + cookies => @cookies );
Croaks unless an LOpenGuides::Config object is supplied as C<config>. Returns default values for any parameter not specified in cookie.
+If C<cookies> is provided, this overrides any cookies submitted by the +browser. + =cut
sub get_prefs_from_cookie { @@ -149,14 +153,37 @@ my $config = $args{config} or croak "No config object supplied"; croak "Config object not an OpenGuides::Config" unless UNIVERSAL::isa( $config, "OpenGuides::Config" ); - my %cookies = CGI::Cookie->fetch; my $cookie_name = $class->_get_cookie_name( config => $config ); + my %cookies; + if ( my $cookies = $args{cookies} ) { + if (ref $cookies ne 'ARRAY') { + $cookies = [ $cookies ]; + } + %cookies = map { $_->name => $_ } @{ $cookies }; + } + else { + %cookies = CGI::Cookie->fetch; + } my %data; if ( $cookies{$cookie_name} ) { %data = $cookies{$cookie_name}->value; # call ->value in list context }
- return $class->get_prefs_from_hash( %data ); + my %long_forms = ( + user => "username", + gclink => "include_geocache_link", + prevab => "preview_above_edit_box", + lltrad => "latlong_traditional", + omithlplks => "omit_help_links", + rcmined => "show_minor_edits_in_rc", + defedit => "default_edit_type", + exp => "cookie_expires", + trackrc => "track_recent_changes_views", + gmaps => "display_google_maps", + ); + my %long_data = map { $long_forms{$_} => $data{$_} } keys %long_forms; + + return $class->get_prefs_from_hash( %long_data ); }
sub get_prefs_from_hash { @@ -173,27 +200,11 @@ track_recent_changes_views => 0, display_google_maps => 1, ); - my %long_forms = ( - user => "username", - gclink => "include_geocache_link", - prevab => "preview_above_edit_box", - lltrad => "latlong_traditional", - omithlplks => "omit_help_links", - rcmined => "show_minor_edits_in_rc", - defedit => "default_edit_type", - exp => "cookie_expires", - trackrc => "track_recent_changes_views", - gmaps => "display_google_maps", - ); my %return; - foreach my $key ( keys %long_forms ) { - my $long_key = $long_forms{$key}; - if ( defined $data{$key} ) { - $return{$long_key} = $data{$key}; - } else { - $return{$long_key} = $defaults{$long_key}; - } + foreach my $key ( keys %data ) { + $return{$key} = defined $data{$key} ? $data{$key} : $defaults{$key}; } + return %return; }
Modified: trunk/lib/OpenGuides/Template.pm =================================================================== --- trunk/lib/OpenGuides/Template.pm 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/lib/OpenGuides/Template.pm 2007-06-16 23:57:32 UTC (rev 1085) @@ -131,7 +131,9 @@ my ($formatting_rules_link, $omit_help_links); my $formatting_rules_node = $config->formatting_rules_node; $formatting_rules_link = $config->formatting_rules_link; - my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); + my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config, + cookies => $args{cookies}, + ); if ( $cookie_data{omit_help_links} ) { $omit_help_links = 1; } else {
Modified: trunk/preferences.cgi =================================================================== --- trunk/preferences.cgi 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/preferences.cgi 2007-06-16 23:57:32 UTC (rev 1085) @@ -30,7 +30,7 @@ my @cookies = ( $prefs_cookie ); # If they've asked not to have their recent changes visits tracked, # clear any existing recentchanges cookie. - if ( ! $track_rc ) { + if ( ! $prefs{track_recent_changes_views} ) { my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( config => $config, clear_cookie => 1, @@ -42,9 +42,8 @@ config => $config, template => "preferences.tt", cookies => @cookies, - vars => { - not_editable => 1, - %prefs, + vars => { + not_editable => 1, } ); }
Modified: trunk/t/59_preferences.t =================================================================== --- trunk/t/59_preferences.t 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/t/59_preferences.t 2007-06-16 23:57:32 UTC (rev 1085) @@ -60,7 +60,7 @@ config => $config, template => "preferences.tt", content_type => '', - vars => { OpenGuides::CGI->get_prefs_from_cookie( config => $config ), + vars => { not_editable => 1, show_form => 1 },
Modified: trunk/templates/navbar_tools.tt =================================================================== --- trunk/templates/navbar_tools.tt 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/templates/navbar_tools.tt 2007-06-16 23:57:32 UTC (rev 1085) @@ -5,8 +5,8 @@ <li><a href="[% script_url %]newpage.cgi">Create New Page</a></li> <li><a href="[% full_cgi_url %]?action=random">Random Page</a></li> <li><a href="[% full_cgi_url %]?action=show_wanted_pages">Wanted Pages</a></li> - [% IF geocache_link AND wgs84_lat AND wgs84_long %] - <li><a href="http://www.geocaching.com/seek/nearest_cache.asp?origin_lat=[% wgs84_lat %];origin_long=[% wgs84_long %]">Look for nearby geocaches</a></li> + [% IF prefs.include_geocache_link AND wgs84_lat AND wgs84_long %] + <li><a href="http://www.geocaching.com/seek/nearest_cache.asp?origin_lat=[% wgs84_lat %]&origin_long=[% wgs84_long %]">Look for nearby geocaches</a></li> [% END %] </ul> </div>
Modified: trunk/templates/preferences.tt =================================================================== --- trunk/templates/preferences.tt 2007-06-16 21:33:16 UTC (rev 1084) +++ trunk/templates/preferences.tt 2007-06-16 23:57:32 UTC (rev 1085) @@ -8,7 +8,7 @@ <form action="preferences.cgi" method="post"> <h1>Username</h1> <p><label for="username">How you wish to be identified in Recent Changes:</label></p> - <input type="text" size="20" id="username" name="username" value="[% username %]" /> + <input type="text" size="20" id="username" name="username" value="[% prefs.username %]" />
<h1>Preferences</h1>
@@ -117,7 +117,7 @@
<h1>Username/preferences saved</h1>
- <p>Username set to “[% username %]”.</p> + <p>Username set to “[% prefs.username %]”.</p>
<p>Preview area shown [% IF prefs.preview_above_edit_box %] @@ -128,7 +128,7 @@ edit box.</p>
<p>“Look for nearby geocaches” link - [% UNLESS include_geocache_link %] not [% END %] + [% UNLESS prefs.include_geocache_link %] not [% END %] included in navbar.</p>
<p>Latitude and longitude displayed as @@ -149,7 +149,7 @@ included in Recent Changes.</p>
<p>Your visits to Recent Changes will - [% UNLESS track_recent_changes_views %] not [% END %] + [% UNLESS prefs.track_recent_changes_views %] not [% END %] be tracked.</p>
[% IF prefs.gmaps_api_key AND config.show_gmap_in_node_display %]
openguides-commits@lists.openguides.org