Author: ilmari
Date: 2007-06-16 22:33:16 +0100 (Sat, 16 Jun 2007)
New Revision: 1084
Modified:
trunk/lib/OpenGuides/CGI.pm
trunk/preferences.cgi
trunk/templates/preferences.tt
Log:
Preferences cleanup
- Separate preference defaulting from cookie parsing.
- Remove duplicate preference defaulting from the cgi.
- Use the prefs template variable in the template.
Modified: trunk/lib/OpenGuides/CGI.pm
===================================================================
--- trunk/lib/OpenGuides/CGI.pm 2007-06-16 21:28:40 UTC (rev 1083)
+++ trunk/lib/OpenGuides/CGI.pm 2007-06-16 21:33:16 UTC (rev 1084)
@@ -155,6 +155,12 @@
if ( $cookies{$cookie_name} ) {
%data = $cookies{$cookie_name}->value; # call ->value in list context
}
+
+ return $class->get_prefs_from_hash( %data );
+}
+
+sub get_prefs_from_hash {
+ my ($class, %data) = @_;
my %defaults = (
username => "Anonymous",
include_geocache_link => 0,
Modified: trunk/preferences.cgi
===================================================================
--- trunk/preferences.cgi 2007-06-16 21:28:40 UTC (rev 1083)
+++ trunk/preferences.cgi 2007-06-16 21:33:16 UTC (rev 1084)
@@ -22,28 +22,10 @@
}
sub set_preferences {
- my $username = $cgi->param("username") || "";
- my $gc_link = $cgi->param("include_geocache_link") || 0;
- my $pre_above = $cgi->param("preview_above_edit_box") || 0;
- my $latlong_trad = $cgi->param("latlong_traditional") || 0;
- my $omit_hlplnks = $cgi->param("omit_help_links") || 0;
- my $rc_minor_eds = $cgi->param("show_minor_edits_in_rc") || 0;
- my $edit_type = $cgi->param("default_edit_type") || "normal";
- my $expires = $cgi->param("cookie_expires") || "month";
- my $track_rc = $cgi->param("track_recent_changes_views") || 0;
- my $gmaps = $cgi->param("display_google_maps") || 0;
+ my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars );
my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
- username => $username,
- include_geocache_link => $gc_link,
- preview_above_edit_box => $pre_above,
- latlong_traditional => $latlong_trad,
- omit_help_links => $omit_hlplnks,
- show_minor_edits_in_rc => $rc_minor_eds,
- default_edit_type => $edit_type,
- cookie_expires => $expires,
- track_recent_changes_views => $track_rc,
- display_google_maps => $gmaps
+ %prefs,
);
my @cookies = ( $prefs_cookie );
# If they've asked not to have their recent changes visits tracked,
@@ -62,29 +44,17 @@
cookies => \@cookies,
vars => {
not_editable => 1,
- username => $username,
- include_geocache_link => $gc_link,
- preview_above_edit_box => $pre_above,
- latlong_traditional => $latlong_trad,
- omit_help_links => $omit_hlplnks,
- show_minor_edits_in_rc => $rc_minor_eds,
- default_edit_type => $edit_type,
- cookie_expires => $expires,
- track_recent_changes_views => $track_rc,
- display_google_maps => $gmaps
+ %prefs,
}
);
}
sub show_form {
- # Get defaults for form fields from cookies.
- my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config );
-
print OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "preferences.tt",
- vars => { %prefs,
+ vars => {
not_editable => 1,
show_form => 1
}
Modified: trunk/templates/preferences.tt
===================================================================
--- trunk/templates/preferences.tt 2007-06-16 21:28:40 UTC (rev 1083)
+++ trunk/templates/preferences.tt 2007-06-16 21:33:16 UTC (rev 1084)
@@ -13,7 +13,7 @@
<h1>Preferences</h1>
<p>
- [% IF preview_above_edit_box %]
+ [% IF prefs.preview_above_edit_box %]
<input type="checkbox" id="preview_above" name="preview_above_edit_box" value="1" checked />
[% ELSE %]
<input type="checkbox" id="preview_above" name="preview_above_edit_box" value="1" />
@@ -22,7 +22,7 @@
</p>
<p>
- [% IF include_geocache_link %]
+ [% IF prefs.include_geocache_link %]
<input type="checkbox" id="geocache" name="include_geocache_link" value="1" checked />
[% ELSE %]
<input type="checkbox" id="geocache" name="include_geocache_link" value="1" />
@@ -31,7 +31,7 @@
</p>
<p>
- [% IF latlong_traditional %]
+ [% IF prefs.latlong_traditional %]
<input type="checkbox" id="latlong" name="latlong_traditional" value="1" checked />
[% ELSE %]
<input type="checkbox" id="latlong" name="latlong_traditional" value="1" />
@@ -40,7 +40,7 @@
</p>
<p>
- [% IF omit_help_links %]
+ [% IF prefs.omit_help_links %]
<input type="checkbox" id="omit_help" name="omit_help_links" value="1" checked />
[% ELSE %]
<input type="checkbox" id="omit_help" name="omit_help_links" value="1" />
@@ -49,7 +49,7 @@
</p>
<p>
- [% IF show_minor_edits_in_rc %]
+ [% IF prefs.show_minor_edits_in_rc %]
<input type="checkbox" id="show_minor" name="show_minor_edits_in_rc" value="1" checked />
[% ELSE %]
<input type="checkbox" id="show_minor" name="show_minor_edits_in_rc" value="1" />
@@ -58,7 +58,7 @@
</p>
<p>
- [% IF track_recent_changes_views %]
+ [% IF prefs.track_recent_changes_views %]
<input type="checkbox" id="track_recent_changes_views" name="track_recent_changes_views" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="track_recent_changes_views" name="track_recent_changes_views" value="1" />
@@ -68,7 +68,7 @@
[% IF gmaps_api_key AND config.show_gmap_in_node_display %]
<p>
- [% IF display_google_maps %]
+ [% IF prefs.display_google_maps %]
<input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" />
@@ -80,7 +80,7 @@
<p>
<label for="default_edit_type">Default edit type:</label>
<select name="default_edit_type" id="default_edit_type">
- [% IF default_edit_type == 'normal' %]
+ [% IF prefs.default_edit_type == 'normal' %]
<option value="normal" selected="1">Normal edit</option>
<option value="tidying">Minor tidying</option>
[% ELSE %]
@@ -93,11 +93,11 @@
<p>
<label for="cookie_expires">Preferences expire:</label>
<select name="cookie_expires" id="cookie_expires">
- [% IF cookie_expires == 'never' %]
+ [% IF prefs.cookie_expires == 'never' %]
<option value="month">in one month</option>
<option value="year">in one year</option>
<option value="never" selected="1">never</option>
- [% ELSIF cookie_expires == "year" %]
+ [% ELSIF prefs.cookie_expires == "year" %]
<option value="month">in one month</option>
<option value="year" selected="1">in one year</option>
<option value="never">never</option>
@@ -120,7 +120,7 @@
<p>Username set to “[% username %]”.</p>
<p>Preview area shown
- [% IF preview_above_edit_box %]
+ [% IF prefs.preview_above_edit_box %]
above
[% ELSE %]
below
@@ -132,7 +132,7 @@
included in navbar.</p>
<p>Latitude and longitude displayed as
- [% IF latlong_traditional %]
+ [% IF prefs.latlong_traditional %]
degrees and minutes.
[% ELSE %]
decimal.
@@ -140,7 +140,7 @@
</p>
<p>Help links will
- [% IF omit_help_links %] not [% END %]
+ [% IF prefs.omit_help_links %] not [% END %]
be included in navbar.
</p>
@@ -152,14 +152,14 @@
[% UNLESS track_recent_changes_views %] not [% END %]
be tracked.</p>
- [% IF gmaps_api_key AND config.show_gmap_in_node_display %]
+ [% IF prefs.gmaps_api_key AND config.show_gmap_in_node_display %]
<p>Google Maps will
[% UNLESS display_google_maps %] not [% END %]
be displayed.</p>
[% END %]
<p>Default edit type set to
- [% IF default_edit_type == 'normal' %]
+ [% IF prefs.default_edit_type == 'normal' %]
“Normal edit”.
[% ELSE %]
“Minor tidying”.
@@ -167,9 +167,9 @@
</p>
<p>Your preferences will
- [% IF cookie_expires == 'never' %]
+ [% IF prefs.cookie_expires == 'never' %]
never expire.
- [% ELSIF cookie_expires == 'year' %]
+ [% ELSIF prefs.cookie_expires == 'year' %]
expire in one year.
[% ELSE %]
expire in one month.