source: trunk/preferences.cgi

Last change on this file was 1377, checked in by kake, 10 years ago

Made the prefs page return the user to the place they came from (fixes #94). Still need to move this from preferences.cgi into OpenGuides.pm and write some tests for it.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5use sigtrap die => 'normal-signals';
6use CGI;
7use OpenGuides;
8use OpenGuides::Config;
9use OpenGuides::CGI;
10use OpenGuides::JSON;
11use OpenGuides::Utils;
12use OpenGuides::Template;
13
14my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf";
15my $config = OpenGuides::Config->new( file => $config_file );
16my $guide = OpenGuides->new( config => $config );
17my $wiki = $guide->wiki;
18my $cgi = CGI->new();
19my $action = $cgi->param('action') || '';
20my $format = $cgi->param('format') || '';
21
22if ( $action eq "set_preferences" ) {
23    set_preferences();
24} elsif ( $action eq "show" && $format eq "json" ) {
25    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
26                                             config => $config );
27    print "Content-type: text/javascript\n\n";
28    print $json_writer->make_prefs_json();
29} else {
30    $guide->display_prefs_form;
31}
32
33sub set_preferences {
34    my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars );
35    my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
36        config => $config,
37        %prefs,
38    );
39    my @cookies = ( $prefs_cookie );
40    # If they've asked not to have their recent changes visits tracked,
41    # clear any existing recentchanges cookie.
42    if ( ! $prefs{track_recent_changes_views} ) {
43        my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie(
44            config       => $config,
45            clear_cookie => 1,
46        );
47        push @cookies, $rc_cookie;
48    }
49    # We have to send the username to OpenGuides::Template because they might
50    # have changed it, in which case it won't be in the cookie yet.
51    print OpenGuides::Template->output(
52        wiki     => $wiki,
53        config   => $config,
54        template => "preferences.tt",
55        cookies  => \@cookies,
56        vars     => {
57                      not_editable => 1,
58                      not_deletable => 1,
59                      username => $prefs{username},
60                      return_to_url => $cgi->param( "return_to_url" ) || "",
61                    }
62    );
63}
Note: See TracBrowser for help on using the repository browser.