Changeset 1084

Show
Ignore:
Timestamp:
06/16/07 22:33:16 (16 months ago)
Author:
ilmari
Message:

Preferences cleanup
- Separate preference defaulting from cookie parsing.
- Remove duplicate preference defaulting from the cgi.
- Use the prefs template variable in the template.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/CGI.pm

    r992 r1084  
    156156        %data = $cookies{$cookie_name}->value; # call ->value in list context 
    157157    } 
     158 
     159    return $class->get_prefs_from_hash( %data ); 
     160} 
     161 
     162sub get_prefs_from_hash { 
     163    my ($class, %data) = @_; 
    158164    my %defaults = ( 
    159165                     username                   => "Anonymous", 
  • trunk/preferences.cgi

    r752 r1084  
    2323 
    2424sub set_preferences { 
    25     my $username     = $cgi->param("username")                   || ""; 
    26     my $gc_link      = $cgi->param("include_geocache_link")      || 0; 
    27     my $pre_above    = $cgi->param("preview_above_edit_box")     || 0; 
    28     my $latlong_trad = $cgi->param("latlong_traditional")        || 0; 
    29     my $omit_hlplnks = $cgi->param("omit_help_links")            || 0; 
    30     my $rc_minor_eds = $cgi->param("show_minor_edits_in_rc")     || 0; 
    31     my $edit_type    = $cgi->param("default_edit_type")          || "normal"; 
    32     my $expires      = $cgi->param("cookie_expires")             || "month"; 
    33     my $track_rc     = $cgi->param("track_recent_changes_views") || 0; 
    34     my $gmaps        = $cgi->param("display_google_maps")        || 0; 
     25    my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars ); 
    3526    my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( 
    3627        config => $config, 
    37         username => $username, 
    38         include_geocache_link  => $gc_link, 
    39         preview_above_edit_box => $pre_above, 
    40         latlong_traditional    => $latlong_trad, 
    41         omit_help_links        => $omit_hlplnks, 
    42         show_minor_edits_in_rc => $rc_minor_eds, 
    43         default_edit_type      => $edit_type, 
    44         cookie_expires         => $expires, 
    45         track_recent_changes_views => $track_rc, 
    46         display_google_maps    => $gmaps 
     28        %prefs, 
    4729    ); 
    4830    my @cookies = ( $prefs_cookie ); 
     
    6345        vars     => { 
    6446                      not_editable               => 1, 
    65                       username                   => $username, 
    66                       include_geocache_link      => $gc_link, 
    67                       preview_above_edit_box     => $pre_above, 
    68                       latlong_traditional        => $latlong_trad, 
    69                       omit_help_links            => $omit_hlplnks, 
    70                       show_minor_edits_in_rc     => $rc_minor_eds, 
    71                       default_edit_type          => $edit_type, 
    72                       cookie_expires             => $expires, 
    73                       track_recent_changes_views => $track_rc, 
    74                       display_google_maps        => $gmaps 
     47                      %prefs, 
    7548                    } 
    7649    ); 
     
    7851 
    7952sub show_form { 
    80     # Get defaults for form fields from cookies. 
    81     my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); 
    82  
    8353    print OpenGuides::Template->output( 
    8454        wiki     => $wiki, 
    8555        config   => $config, 
    8656        template => "preferences.tt", 
    87         vars     => { %prefs, 
     57        vars     => {  
    8858                      not_editable => 1, 
    8959                      show_form    => 1 
  • trunk/templates/preferences.tt

    r1053 r1084  
    1414 
    1515    <p> 
    16     [% IF preview_above_edit_box %] 
     16    [% IF prefs.preview_above_edit_box %] 
    1717      <input type="checkbox" id="preview_above" name="preview_above_edit_box" value="1" checked /> 
    1818    [% ELSE %] 
     
    2323 
    2424    <p> 
    25     [% IF include_geocache_link %] 
     25    [% IF prefs.include_geocache_link %] 
    2626      <input type="checkbox" id="geocache" name="include_geocache_link" value="1" checked /> 
    2727    [% ELSE %] 
     
    3232 
    3333    <p> 
    34     [% IF latlong_traditional %] 
     34    [% IF prefs.latlong_traditional %] 
    3535      <input type="checkbox" id="latlong" name="latlong_traditional" value="1" checked /> 
    3636    [% ELSE %] 
     
    4141 
    4242    <p> 
    43     [% IF omit_help_links %] 
     43    [% IF prefs.omit_help_links %] 
    4444      <input type="checkbox" id="omit_help" name="omit_help_links" value="1" checked /> 
    4545    [% ELSE %] 
     
    5050 
    5151    <p> 
    52     [% IF show_minor_edits_in_rc %] 
     52    [% IF prefs.show_minor_edits_in_rc %] 
    5353      <input type="checkbox" id="show_minor" name="show_minor_edits_in_rc" value="1" checked /> 
    5454    [% ELSE %] 
     
    5959 
    6060    <p> 
    61       [% IF track_recent_changes_views %] 
     61      [% IF prefs.track_recent_changes_views %] 
    6262        <input type="checkbox" id="track_recent_changes_views" name="track_recent_changes_views" value="1" checked="1" /> 
    6363      [% ELSE %] 
     
    6969    [% IF gmaps_api_key AND config.show_gmap_in_node_display %] 
    7070      <p> 
    71         [% IF display_google_maps %] 
     71        [% IF prefs.display_google_maps %] 
    7272          <input type="checkbox" id="display_google_maps" name="display_google_maps" value="1" checked="1" /> 
    7373        [% ELSE %] 
     
    8181      <label for="default_edit_type">Default edit type:</label> 
    8282      <select name="default_edit_type" id="default_edit_type"> 
    83         [% IF default_edit_type == 'normal' %] 
     83        [% IF prefs.default_edit_type == 'normal' %] 
    8484          <option value="normal" selected="1">Normal edit</option> 
    8585          <option value="tidying">Minor tidying</option> 
     
    9494      <label for="cookie_expires">Preferences expire:</label> 
    9595      <select name="cookie_expires" id="cookie_expires"> 
    96         [% IF cookie_expires == 'never' %] 
     96        [% IF prefs.cookie_expires == 'never' %] 
    9797          <option value="month">in one month</option> 
    9898          <option value="year">in one year</option> 
    9999          <option value="never" selected="1">never</option> 
    100         [% ELSIF cookie_expires == "year" %] 
     100        [% ELSIF prefs.cookie_expires == "year" %] 
    101101          <option value="month">in one month</option> 
    102102          <option value="year" selected="1">in one year</option> 
     
    121121 
    122122  <p>Preview area shown 
    123     [% IF preview_above_edit_box %] 
     123    [% IF prefs.preview_above_edit_box %] 
    124124      above 
    125125    [% ELSE %] 
     
    133133 
    134134  <p>Latitude and longitude displayed as 
    135     [% IF latlong_traditional %] 
     135    [% IF prefs.latlong_traditional %] 
    136136      degrees and minutes. 
    137137    [% ELSE %] 
     
    141141 
    142142  <p>Help links will 
    143     [% IF omit_help_links %] not [% END %] 
     143    [% IF prefs.omit_help_links %] not [% END %] 
    144144    be included in navbar. 
    145145  </p> 
     
    153153  be tracked.</p> 
    154154 
    155   [% IF gmaps_api_key AND config.show_gmap_in_node_display %] 
     155  [% IF prefs.gmaps_api_key AND config.show_gmap_in_node_display %] 
    156156    <p>Google Maps will 
    157157      [% UNLESS display_google_maps %] not [% END %] 
     
    160160 
    161161  <p>Default edit type set to 
    162     [% IF default_edit_type == 'normal' %] 
     162    [% IF prefs.default_edit_type == 'normal' %] 
    163163      &#8220;Normal edit&#8221;. 
    164164    [% ELSE %] 
     
    168168 
    169169  <p>Your preferences will 
    170     [% IF cookie_expires == 'never' %] 
     170    [% IF prefs.cookie_expires == 'never' %] 
    171171      never expire. 
    172     [% ELSIF cookie_expires == 'year' %] 
     172    [% ELSIF prefs.cookie_expires == 'year' %] 
    173173      expire in one year. 
    174174    [% ELSE %]