OpenGuides::CGI(3) An OpenGuides helper for CGI-related things.

DESCRIPTION

Does CGI stuff for OpenGuides. Distributed and installed as part of the OpenGuides project, not intended for independent installation. This documentation is probably only useful to OpenGuides developers.

SYNOPSIS

Saving preferences in a cookie:


use OpenGuides::CGI;
use OpenGuides::Config;
use OpenGuides::Template;
use OpenGuides::Utils;
my $config = OpenGuides::Config->new( file => "wiki.conf" );
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "Kake",
include_geocache_link => 1,
preview_above_edit_box => 1,
latlong_traditional => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
display_google_maps => 1,
is_admin => 1
);
my $wiki = OpenGuides::Utils->make_wiki_object( config => $config );
print OpenGuides::Template->output( wiki => $wiki,
config => $config,
template => "preferences.tt",
cookies => $cookie
);
# and to retrive prefs later:
my %prefs = OpenGuides::CGI->get_prefs_from_cookie(
config => $config
);

Tracking visits to Recent Changes:

  use OpenGuides::CGI;
  use OpenGuides::Config;
  use OpenGuides::Template;
  use OpenGuides::Utils;
  my $config = OpenGuides::Config->new( file => "wiki.conf" );
  my $cookie = OpenGuides::CGI->make_recent_changes_cookie(
      config => $config,
  );

METHODS

extract_node_param
    my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf";
    my $config = OpenGuides::Config->new( file => $config_file );
    my $guide = OpenGuides->new( config => $config );
    my $wiki = $guide->wiki;
    my $q = CGI->new;
    my $node_param = OpenGuides::CGI->extract_node_param(
                        wiki => $wiki, cgi_obj => $q );

Returns the title, id, or keywords parameter from the URL. Normally this will be something like ``British_Museum'', i.e. with underscores instead of spaces. However if the URL does contain spaces (encoded as %20 or +), the return value will be e.g. ``British Museum'' instead.

Croaks unless a Wiki::Toolkit object is supplied as "wiki" and a CGI object is supplied as "cgi_obj".

extract_node_name
    my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf";
    my $config = OpenGuides::Config->new( file => $config_file );
    my $guide = OpenGuides->new( config => $config );
    my $wiki = $guide->wiki;
    my $q = CGI->new;
    my $node_name = OpenGuides::CGI->extract_node_name(
                        wiki => $wiki, cgi_obj => $q );

Returns the name of the node the user wishes to display/manipulate, as we expect it to be stored in the database. Normally this will be something like ``British Museum'', i.e. with spaces in. Croaks unless a Wiki::Toolkit object is supplied as "wiki" and a CGI object is supplied as "cgi_obj".

check_spaces_redirect
    my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf";
    my $config = OpenGuides::Config->new( file => $config_file );
    my $guide = OpenGuides->new( config => $config );
    my $q = CGI->new;
    my $url = OpenGuides::CGI->check_spaces_redirect(
                                 wiki => $wiki, cgi_obj => $q );

If the user seems to have typed a URL with spaces in the node param instead of underscores, this method will return the URL with the underscores put in. Otherwise, it returns false.

make_prefs_cookie
  my $cookie = OpenGuides::CGI->make_prefs_cookie(
      config                     => $config,
      username                   => "Kake",
      include_geocache_link      => 1,
      preview_above_edit_box     => 1,
      latlong_traditional        => 1,
      omit_help_links            => 1,
      show_minor_edits_in_rc     => 1,
      default_edit_type          => "tidying",
      cookie_expires             => "never",
      track_recent_changes_views => 1,
      display_google_maps        => 1,
      is_admin                   => 1
  );

Croaks unless an OpenGuides::Config object is supplied as "config". Acceptable values for "cookie_expires" are "never", "month", "year"; anything else will default to "month".

get_prefs_from_cookie
  my %prefs = OpenGuides::CGI->get_prefs_from_cookie(
      config => $config,
      cookies => \@cookies
  );

Croaks unless an OpenGuides::Config object is supplied as "config". Returns default values for any parameter not specified in cookie.

If "cookies" is provided, and includes a preferences cookie, this overrides any preferences cookie submitted by the browser.

make_recent_changes_cookie
  my $cookie = OpenGuides::CGI->make_recent_changes_cookie(
      config => $config,
  );

Makes a cookie that stores the time now as the time of the latest visit to Recent Changes. Or, if "clear_cookie" is specified and true, makes a cookie with an expiration date in the past:

  my $cookie = OpenGuides::CGI->make_recent_changes_cookie(
      config       => $config,
      clear_cookie => 1,
  );
get_last_recent_changes_visit_from_cookie
  my %prefs = OpenGuides::CGI->get_last_recent_changes_visit_from_cookie(
      config => $config
  );

Croaks unless an OpenGuides::Config object is supplied as "config". Returns the time (as seconds since epoch) of the user's last visit to Recent Changes.

make_index_form_dropdowns
    my @dropdowns = OpenGuides::CGI->make_index_form_dropdowns (
        guide    => $guide,
        selected => [
                      { type => "category", value => "pubs" },
                      { type => "locale", value => "holborn" },
                    ],
    );
    %tt_vars = ( %tt_vars, dropdowns => \@dropdowns );
    # In the template
    [% FOREACH dropdown = dropdowns %]
      [% dropdown.type.ucfirst | html %]:
      [% dropdown.html %]
      <br />
    [% END %]

Makes HTML dropdown selects suitable for passing to an indexing template.

The "selected" argument is optional; if supplied, it gives default values for the dropdowns. At least one category and one locale dropdown will be returned; if no defaults are given for either then they'll default to everything/everywhere.

AUTHOR

The OpenGuides Project ([email protected])

COPYRIGHT

     Copyright (C) 2003-2013 The OpenGuides Project.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.