view release on metacpan or search on metacpan
'Data::Validate::URI' => 0,
'Net::Netmask' => 0,
'List::Util' => 0,
'Geo::Coordinates::UTM' => 0,
'Geo::Coordinates::OSGB' => 0,
'Geo::Coordinates::ITM' => 0,
});
$build->add_to_cleanup( "t/indexes/" );
$build->add_to_cleanup( "t/node.db" );
$build->add_to_cleanup( "t/prefs.db" );
$build->add_to_cleanup( "t/templates/tmp/" );
# Tell OpenGuides::Build which additional scripts and templates to install.
$build->config_data( __extra_scripts =>
[ "wiki.conf", "preferences.cgi", "search.cgi",
"newpage.cgi" ] );
$build->config_data( __templates => [
"admin_home.tt",
"admin_revert_user.tt",
"autocreate_content.tt",
for details).
Added new macro - used as eg @INDEX_LIST [[Locale Fulham]]
Also fixed the RSS reader macro - use this as eg
@RSS http://london.openguides.org/?action=rss;username=Kake
More semantic markup for metadata display - see README.CSS.
0.40 18 September 2004
Recent Changes now shows changes in the past 24 hours, past week,
past fortnight, and past 30 days.
New preferences option to allow Recent Changes visit tracking.
Preferences now has an option for when your prefs expire.
Navbar added to diff and history pages.
The "omit help links" preference now actually works.
Set some pages to non-editable and non-deletable that should have been.
Recent Changes RSS fixed so "wiki:importance" is set correctly.
New "ignore_minor_edits" option for Recent Changes RSS.
Added RSS feeds for contributors, locales and categories.
0.39 15 September 2004
Split commit_node out into OpenGuides.pm in preparation for spam filter
Added option of using Plucene for searching. If you want to do this
div#navbar
Used in: navbar.tt
Purpose: The navigation bar
div#navbar_help
Used in: navbar_help.tt
Purpose: Display help links, if user has them turned on.
div#navbar_options
Used in: navbar_options.tt
Purpose: Display links to options such as "Set username/prefs".
div#navbar_search
Used in: navbar_search.tt
Purpose: Display search box and link to advanced search.
div#navbar_this_page
Used in: navbar_this_page.tt
Purpose: Display links to this-page stuff such as "Edit this page", if
the current page is an editable one.
div#navbar_tools
Used in: navbar_tools.tt
Purpose: Display links to tools such as "Recent Changes", "Random Page".
Purpose: A short message indicating that your reached a node via a redirect
table#wanted_pages
Used in: wanted_pages.tt
Purpose: A list of all unlinked nodes
div#banner
Used in: node.tt
Purpose: A one-line summary of what the node is
ul#prefs_saved_extra_nav
Used in: preferences.tt
Purpose: Offer links to return to site or to edit preferences again.
lib/OpenGuides.pm view on Meta::CPAN
=cut
sub display_edit_form {
my ($self, %args) = @_;
my $return_output = $args{return_output} || 0;
my $config = $self->config;
my $wiki = $self->wiki;
my $node = $args{id};
my %node_data = $wiki->retrieve_node($node);
my ($content, $checksum) = @node_data{ qw( content checksum ) };
my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config);
my $username = $self->get_cookie( "username" );
my $edit_type = $self->get_cookie( "default_edit_type" ) eq "normal"
? "Normal edit"
: "Minor tidying";
my %metadata_vars = OpenGuides::Template->extract_metadata_vars(
wiki => $wiki,
config => $config,
metadata => $node_data{metadata} );
lib/OpenGuides.pm view on Meta::CPAN
} else {
return $self->_handle_edit_conflict(
id => $node,
content => $content,
new_metadata => \%new_metadata,
return_output => $return_output,
);
}
}
=item B<display_prefs_form>
$guide->display_prefs_form;
Displays a form that lets the user view and set their preferences. The
C<return_output> and C<return_tt_vars> parameters can be used to return
the output or template variables, instead of printing the output to STDOUT.
The C<noheaders> parameter can also be used in conjunction with
C<return_output>, if you wish to omit all HTTP headers.
=cut
sub display_prefs_form {
my ($self, %args) = @_;
my $config = $self->config;
my $wiki = $self->wiki;
my $from = $ENV{HTTP_REFERER} || "";
my $url_base = $config->script_url . $config->script_name;
if ( $from !~ /^$url_base/ ) {
$from = "";
}
lib/OpenGuides.pm view on Meta::CPAN
$redir_param .= ";oldid=$oldid" if $oldid;
my $q = CGI->new;
return $q->redirect( $redir_param );
}
sub get_cookie {
my $self = shift;
my $config = $self->config;
my $pref_name = shift or return "";
my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config);
return $cookie_data{$pref_name};
}
=back
=head1 BUGS AND CAVEATS
UTF8 data are currently not handled correctly throughout.
Other bugs are documented at
lib/OpenGuides/CGI.pm view on Meta::CPAN
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,
lib/OpenGuides/CGI.pm view on Meta::CPAN
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;
lib/OpenGuides/CGI.pm view on Meta::CPAN
$new_q->param( -name => "id", -value => $real_param );
}
my $url = $new_q->self_url;
# Escaped commas are ugly.
$url =~ s/%2C/,/g;
return $url;
}
=item B<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 L<OpenGuides::Config> object is supplied as C<config>.
Acceptable values for C<cookie_expires> are C<never>, C<month>,
C<year>; anything else will default to C<month>.
=cut
sub make_prefs_cookie {
my ($class, %args) = @_;
my $config = $args{config} or croak "No config object supplied";
croak "Config object not an OpenGuides::Config"
unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
my $cookie_name = $class->_get_cookie_name( config => $config );
my $expires;
if ( $args{cookie_expires} and $args{cookie_expires} eq "never" ) {
# Gosh, a hack. YES I AM ASHAMED OF MYSELF.
# Putting no expiry date means cookie expires when browser closes.
# Putting a date later than 2037 makes it wrap round, at least on Linux
lib/OpenGuides/CGI.pm view on Meta::CPAN
exp => $args{cookie_expires},
trackrc => $args{track_recent_changes_views} || 0,
gmaps => $args{display_google_maps} || 0,
admin => $args{is_admin} || 0
},
-expires => $expires,
);
return $cookie;
}
=item B<get_prefs_from_cookie>
my %prefs = OpenGuides::CGI->get_prefs_from_cookie(
config => $config,
cookies => \@cookies
);
Croaks unless an L<OpenGuides::Config> object is supplied as C<config>.
Returns default values for any parameter not specified in cookie.
If C<cookies> is provided, and includes a preferences cookie, this overrides
any preferences cookie submitted by the browser.
=cut
sub get_prefs_from_cookie {
my ($class, %args) = @_;
my $config = $args{config} or croak "No config object supplied";
croak "Config object not an OpenGuides::Config"
unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
my $cookie_name = $class->_get_cookie_name( config => $config );
my %cookies;
if ( my $cookies = $args{cookies} ) {
if (ref $cookies ne 'ARRAY') {
$cookies = [ $cookies ];
}
lib/OpenGuides/CGI.pm view on Meta::CPAN
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",
admin => "is_admin",
);
my %long_data = map { $long_forms{$_} => $data{$_} } keys %long_forms;
return $class->get_prefs_from_hash( %long_data );
}
sub get_prefs_from_hash {
my ($class, %data) = @_;
my %defaults = (
username => "Anonymous",
include_geocache_link => 0,
preview_above_edit_box => 0,
latlong_traditional => 0,
omit_help_links => 0,
# This has been set to 1 to work around
# Wiki::Toolkit bug #41 - consider reverting this
# when that bug gets fixed
lib/OpenGuides/CGI.pm view on Meta::CPAN
);
=cut
sub make_recent_changes_cookie {
my ($class, %args) = @_;
my $config = $args{config} or croak "No config object supplied";
croak "Config object not an OpenGuides::Config"
unless UNIVERSAL::isa( $config, "OpenGuides::Config" );
my $cookie_name = $class->_get_rc_cookie_name( config => $config );
# See explanation of expiry date hack above in make_prefs_cookie.
my $expires;
if ( $args{clear_cookie} ) {
$expires = "-1M";
} else {
$expires = "Thu, 31-Dec-2037 22:22:22 GMT";
}
my $cookie = CGI::Cookie->new(
-name => $cookie_name,
-value => {
time => time,
},
-expires => $expires,
);
return $cookie;
}
=item B<get_last_recent_changes_visit_from_cookie>
my %prefs = OpenGuides::CGI->get_last_recent_changes_visit_from_cookie(
config => $config
);
Croaks unless an L<OpenGuides::Config> object is supplied as C<config>.
Returns the time (as seconds since epoch) of the user's last visit to
Recent Changes.
=cut
sub get_last_recent_changes_visit_from_cookie {
lib/OpenGuides/CGI.pm view on Meta::CPAN
%data = $cookies{$cookie_name}->value; # call ->value in list context
}
return $data{time};
}
sub _get_cookie_name {
my ($class, %args) = @_;
my $site_name = $args{config}->site_name
or croak "No site name in config";
return $site_name . "_userprefs";
}
sub _get_rc_cookie_name {
my ($class, %args) = @_;
my $site_name = $args{config}->site_name
or croak "No site name in config";
return $site_name . "_last_rc_visit";
}
=item B<make_index_form_dropdowns>
lib/OpenGuides/JSON.pm view on Meta::CPAN
recent_changes_link => $self->{config}->script_url . '?action=rc',
software_name => 'OpenGuides',
software_homepage => 'http://openguides.org/',
software_version => $self->{og_version},
);
}
return $self->{json_maker};
}
sub make_prefs_json {
my $self = shift;
my %prefs = OpenGuides::CGI->get_prefs_from_cookie(
config => $self->{config} );
return encode_json( \%prefs );
}
sub make_recentchanges_json {
my ( $self, %args ) = @_;
$self->json_maker->recent_changes(%args);
}
sub json_timestamp {
my ( $self, %args ) = @_;
lib/OpenGuides/JSON.pm view on Meta::CPAN
=item B<opening_hours_text> - A freeform text field.
=back
=item B<json_maker>
Returns a raw L<Wiki::Toolkit::Plugin::JSON> object created with the values you
invoked this module with.
=item B<make_prefs_json>
my $json_writer = OpenGuides::JSON->new( wiki => $wiki,
config => $config );
print $json_writer->make_prefs_json();
Retrieves the preferences from any stored preferences cookie, supplies
defaults for any preferences not set, returns the result as JSON.
=item B<make_recentchanges_json>
# Ten most recent changes.
print "Content-Type: application/javascript\n";
print "Last-Modified: " . $json_writer->json_timestamp( items => 10 ) . "\n\n";
print $json_writer->make_recentchanges_json( items => 10 );
lib/OpenGuides/Template.pm view on Meta::CPAN
=item * C<home_name>
=item * C<gmaps_api_key>
=item * C<licence_name>
=item * C<licence_url>
=item * C<licence_info_url>
=item * C<prefs> (the preferences from the user cookie)
=back
If C<node> is supplied:
=over
=item * C<node_name>
=item * C<node_param> (the node name escaped for use in URLs)
lib/OpenGuides/Template.pm view on Meta::CPAN
{ INCLUDE_PATH => "$custom_template_path:$template_path" } );
my $script_name = $config->script_name;
my $script_url = $config->script_url;
my $default_city = $config->default_city;
# Check cookie to see if we need to set the formatting_rules_link.
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,
cookies => $args{cookies},
);
if ( $cookie_data{omit_help_links} ) {
$omit_help_links = 1;
} else {
if (( $formatting_rules_node ) and !( $formatting_rules_link )){
$formatting_rules_link = $script_url . $script_name . "?"
. uri_escape($args{wiki}->formatter->node_name_to_node_param($formatting_rules_node));
}
lib/OpenGuides/Template.pm view on Meta::CPAN
) {
$enable_page_deletion = 1;
}
my $is_admin = 0;
if ( $cookie_data{is_admin} ) {
$is_admin = 1;
}
my $tt_vars = {
config => $config,
prefs => \%cookie_data,
site_name => $config->site_name,
cgi_url => $script_name,
script_url => $script_url,
full_cgi_url => $script_url . $script_name,
contact_email => $config->contact_email,
stylesheet => $config->stylesheet_url,
home_link => $script_url . $script_name,
home_name => $config->home_name,
navbar_on_home_page => $config->navbar_on_home_page,
omit_help_links => $omit_help_links,
lib/OpenGuides/Template.pm view on Meta::CPAN
$args{wiki}->formatter->node_name_to_node_param( $args{node} ) );
}
# Now set further TT variables if explicitly supplied - do this after the
# above auto-setting as these override auto-set ones.
$tt_vars = { %$tt_vars, %{ $args{vars} || {} } };
# Finally, dig out the username from the cookie if we haven't already
# been sent it in vars.
if ( !$tt_vars->{username} ) {
my %prefs = OpenGuides::CGI->get_prefs_from_cookie(config => $config);
# If there's nothing in there, it defaults to "Anonymous".
if ( $prefs{username} ne "Anonymous" ) {
$tt_vars->{username} = $prefs{username};
}
}
my $header = "";
unless ( $args{noheaders} ) {
my %cgi_header_args;
if ( defined $args{content_type} and $args{content_type} eq "" ) {
$cgi_header_args{'-type'} = '';
lib/OpenGuides/Template.pm view on Meta::CPAN
coord_field_2_name => "Longitude (decimal)",
coord_field_1_value => $lat,
coord_field_2_value => $long,
);
}
}
}
# Check whether we need to munge lat and long.
# Store them unmunged as well so commit_node can get hold of them.
my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config );
if ( $prefs{latlong_traditional} ) {
foreach my $var ( qw( latitude longitude ) ) {
next unless defined $vars{$var} && length $vars{$var};
$vars{$var."_unmunged"} = $vars{$var};
$vars{$var} = _deg2string($vars{$var});
}
}
return %vars;
}
preferences.cgi view on Meta::CPAN
my $cgi = CGI->new();
my $action = $cgi->param('action') || '';
my $format = $cgi->param('format') || '';
if ( $action eq "set_preferences" ) {
set_preferences();
} elsif ( $action eq "show" && $format eq "json" ) {
my $json_writer = OpenGuides::JSON->new( wiki => $wiki,
config => $config );
print "Content-type: text/javascript\n\n";
print $json_writer->make_prefs_json();
} else {
$guide->display_prefs_form;
}
sub set_preferences {
my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars );
my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
%prefs,
);
my @cookies = ( $prefs_cookie );
# If they've asked not to have their recent changes visits tracked,
# clear any existing recentchanges cookie.
if ( ! $prefs{track_recent_changes_views} ) {
my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie(
config => $config,
clear_cookie => 1,
);
push @cookies, $rc_cookie;
}
# We have to send the username to OpenGuides::Template because they might
# have changed it, in which case it won't be in the cookie yet.
print OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "preferences.tt",
cookies => \@cookies,
vars => {
not_editable => 1,
not_deletable => 1,
username => $prefs{username},
return_to_url => $cgi->param( "return_to_url" ) || "",
}
);
}
static/openguides-base.css view on Meta::CPAN
form#preferences_form div.set_username input {
padding: 0.5em;
margin: 0.5em 0;
}
form#preferences_form input#submit {
padding: 0.5em;
}
ul#prefs_saved_extra_nav {
padding: 1em;
}
ul#prefs_saved_extra_nav li {
padding-top: 1em;
}
table#wanted_pages tbody tr td {
padding-top: 1em;
vertical-align: top;
}
table#wanted_pages tbody tr td#action {
padding-top: 0.7em;
t/103_cookies.t view on Meta::CPAN
use strict;
use OpenGuides::Config;
use OpenGuides::CGI;
use Time::Piece;
use Time::Seconds;
use Test::More tests => 30;
eval { OpenGuides::CGI->make_prefs_cookie; };
ok( $@, "->make_prefs_cookie dies if no config object supplied" );
eval { OpenGuides::CGI->make_prefs_cookie( config => "foo" ); };
ok( $@, "...or if config isn't an OpenGuides::Config" );
my $config = OpenGuides::Config->new( vars => { site_name => "Test Site" } );
eval { OpenGuides::CGI->make_prefs_cookie( config => $config ); };
is( $@, "", "...but not if it is" );
# Use nonsense values here to make sure the test is a good one regardless
# of defaults - can't do this for cookie_expires, unfortunately.
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "un_pref",
include_geocache_link => "gc_pref",
preview_above_edit_box => "pv_pref",
latlong_traditional => "ll_pref",
omit_help_links => "hl_pref",
show_minor_edits_in_rc => "me_pref",
default_edit_type => "et_pref",
cookie_expires => "never",
track_recent_changes_views => "rc_pref",
display_google_maps => "gm_pref",
is_admin => "admin_pref",
);
isa_ok( $cookie, "CGI::Cookie", "->make_prefs_cookie returns a cookie" );
my $expiry_string = $cookie->expires;
# Hack off the timezone bit since strptime can't parse it portably.
# Timezones taken from RFC 822.
$expiry_string =~ s/ (UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|1[A-IK-Z]|\+\d\d\d\d|-\d\d\d\d)$//;
print "# (String hacked to $expiry_string)\n";
my $expiry = Time::Piece->strptime( $expiry_string, "%a, %d-%b-%Y %T");
print "# Expires: " . $cookie->expires . ", ie $expiry\n";
my $now = localtime;
print "# cookie should still be valid in a year, ie " . ($now + ONE_YEAR) . "\n";
ok( $expiry - ( $now + ONE_YEAR ) > 0, "cookie expiry date correct" );
$ENV{HTTP_COOKIE} = $cookie;
eval { OpenGuides::CGI->get_prefs_from_cookie; };
ok( $@, "->get_prefs_from_cookie dies if no config object supplied" );
eval { OpenGuides::CGI->get_prefs_from_cookie( config => "foo" ); };
ok( $@, "...or if config isn't an OpenGuides::Config" );
eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); };
is( $@, "", "...but not if it is" );
my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config );
is( $prefs{username}, "un_pref", "get_prefs_from_cookie can find username" );
is( $prefs{include_geocache_link}, "gc_pref", "...and geocache prefs" );
is( $prefs{preview_above_edit_box}, "pv_pref", "...and preview prefs" );
is( $prefs{latlong_traditional}, "ll_pref", "...and latlong prefs" );
is( $prefs{omit_help_links}, "hl_pref", "...and help link prefs" );
is( $prefs{show_minor_edits_in_rc}, "me_pref", "...and minor edits prefs" );
is( $prefs{default_edit_type}, "et_pref", "...and default edit prefs" );
is( $prefs{cookie_expires}, "never", "...and requested cookie expiry" );
is( $prefs{track_recent_changes_views}, "rc_pref",
"...and recent changes tracking" );
is( $prefs{display_google_maps}, "gm_pref",
"...and map display preference" );
is( $prefs{is_admin}, "admin_pref",
"...and admin preference" );
# Now make sure that true/false preferences are taken account of when
# they're false.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
include_geocache_link => 0,
preview_above_edit_box => 0,
latlong_traditional => 0,
omit_help_links => 0,
show_minor_edits_in_rc => 0,
track_recent_changes_views => 0,
display_google_maps => 0,
is_admin => 0,
);
$ENV{HTTP_COOKIE} = $cookie;
%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config );
ok( !$prefs{include_geocache_link}, "geocache prefs taken note of when false");
ok( !$prefs{preview_above_edit_box}, "...and preview prefs" );
ok( !$prefs{latlong_traditional}, "...and latlong prefs" );
ok( !$prefs{omit_help_links}, "...and help link prefs" );
ok( !$prefs{show_minor_edits_in_rc}, "...and minor edits prefs" );
ok( !$prefs{track_recent_changes_views}, "...and recent changes prefs" );
ok( !$prefs{display_google_maps}, "...and Google Maps prefs" );
ok( !$prefs{is_admin}, "...and admin prefs" );
# Check that cookie parsing fails nicely if no cookie set.
delete $ENV{HTTP_COOKIE};
%prefs = eval { OpenGuides::CGI->get_prefs_from_cookie( config => $config ); };
is( $@, "", "->get_prefs_from_cookie doesn't die if no cookie set" );
is( keys %prefs, 11, "...and returns ten default values" );
# Check that the prefs cookie is still looked for even if we send along a
# non-prefs cookie.
my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie(
config => $config );
my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config, is_admin => 1 );
$ENV{HTTP_COOKIE} = $prefs_cookie;
%prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config,
cookies => [ $rc_cookie ] );
ok( $prefs{is_admin},
"->get_prefs_from_cookie still works with ENV if we send RC cookie" );
t/104_recent_changes_cookies.t view on Meta::CPAN
ok( $@, "...or if config isn't an OpenGuides::Config" );
eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); };
is( $@, "", "...but not if it is" );
# Check that cookie parsing fails nicely if no cookie set.
delete $ENV{HTTP_COOKIE};
eval { OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); };
is( $@, "", "->get_last_recent_changes_visit_from_cookie doesn't die if no cookie set" );
# Now test that the prefs option is taken note of.
my $have_sqlite = 1;
my $sqlite_error;
eval { require DBD::SQLite; };
if ( $@ ) {
($sqlite_error) = $@ =~ /^(.*?)\n/;
$have_sqlite = 0;
}
SKIP: {
t/104_recent_changes_cookies.t view on Meta::CPAN
site_name => "Test Site",
template_path => "./templates",
home_name => "Home",
}
);
eval { require Wiki::Toolkit::Search::Plucene; };
if ( $@ ) { $config->use_plucene ( 0 ) };
my $guide = OpenGuides->new( config => $config );
my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
track_recent_changes_views => 1,
);
my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie(
config => $config
);
$ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie;
my $output = $guide->display_node(
id => "RecentChanges",
return_output => 1,
);
like( $output, qr/Set-Cookie:/, "recent changes cookie set when asked" );
$prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
track_recent_changes_views => 0,
);
$ENV{HTTP_COOKIE} = $prefs_cookie . "; " . $rc_cookie;
$output = $guide->display_node(
id => "RecentChanges",
return_output => 1,
);
unlike( $output, qr/Set-Cookie:/, "...and not when not" );
}
t/105_template.t view on Meta::CPAN
}
);
$output = OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "105_test.tt"
);
like( $output, qr/FULL CGI URL: http:\/\/wiki.example.com\/wiki.cgi/,
"full_cgi_url OK when trailing '/' missed off script_url" );
# Test that TT vars are picked up from user cookie prefs.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
omit_formatting_link => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "105_test.tt"
);
like( $output, qr/FORMATTING RULES LINK: /,
t/401_deletion.t view on Meta::CPAN
my $output = OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "node.tt",
);
unlike( $output, qr/action=delete/,
"doesn't offer page deletion link by default" );
$config->enable_page_deletion( "y" );
# set is_admin to 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/406_map_in_node_display.t view on Meta::CPAN
OpenGuides::Test->write_data(
guide => $guide,
node => "Red Lion",
os_x => 530000,
os_y => 180000,
);
# Maps shouldn't show up if there's no API key and we're not using Leaflet.
$config->show_gmap_in_node_display( 1 );
$config->use_leaflet( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
t/406_map_in_node_display.t view on Meta::CPAN
$config->gmaps_api_key( "This is not a real API key." );
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::tag_ok( $output, "div", { id => "map" },
"Map shown on node if we have a Google API key");
# But not if the user doesn't want them.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 0,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
"...but not if the user turned it off" );
# And not if the admin doesn't want them.
$config->show_gmap_in_node_display( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
"...and not if the admin turned it off" );
# Now test with Leaflet.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config, display_google_maps => 1 );
$ENV{HTTP_COOKIE} = $cookie;
$config->gmaps_api_key( "I still have a key but don't expect to use it" );
$config->show_gmap_in_node_display( 1 );
$config->use_leaflet( 1 );
# Shouldn't get any of the GMap stuff.
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
t/406_map_in_node_display.t view on Meta::CPAN
$config->gmaps_api_key( "" );
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::tag_ok( $output, "div", { id => "node_map_canvas" },
"Map shown on node if using Leaflet");
# But not if the user doesn't want them.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 0,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
"...but not if the user turned it off" );
# And not if the admin doesn't want them.
$config->show_gmap_in_node_display( 0 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_node(
id => "Red Lion",
return_output => 1,
);
$output =~ s/^Content-Type.*[\r\n]+//m;
Test::HTML::Content::no_tag( $output, "div", { id => "map" },
t/508_navbar_common_locales_categories.t view on Meta::CPAN
my ($guide) = @_;
my $output = $guide->display_recent_changes( return_output => 1 );
$output =~ s/^Content-Type.*[\r\n]+//m;
return $output;
}
sub get_preferences {
my $guide = shift;
return $guide->display_prefs_form( return_output => 1, noheaders => 1 );
}
my %pages = (
recent_changes => \&get_recent_changes,
preferences => \&get_preferences,
);
plan tests => 4 * keys %pages;
my ( $config, $guide, $wiki, $output );
t/509_preferences.t view on Meta::CPAN
my $guide = OpenGuides->new( config => $config );
my $wiki = $guide->wiki;
# Make sure "return_to" TT var is set iff referrer domain is correct.
$config->script_url( "http://example.com/" );
$config->script_name( "wiki.cgi" );
my $good_return_to = "http://example.com/wiki.cgi?Test_Page";
my $evil_return_to = "http://example.org/naughty-script";
$ENV{HTTP_REFERER} = $good_return_to;
my %tt_vars = $guide->display_prefs_form( return_tt_vars => 1 );
is( $tt_vars{return_to_url}, $good_return_to,
"Return URL set when referrer matches script URL/name" );
my $output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"input", { type => "hidden", name => "return_to_url" },
"...corresponding hidden input is there in the form" );
Test::HTML::Content::tag_ok( $output,
"input", { type => "hidden", name => "return_to_url",
value => $good_return_to },
"...with correct value" );
$ENV{HTTP_REFERER} = $evil_return_to;
%tt_vars = $guide->display_prefs_form( return_tt_vars => 1 );
ok( !$tt_vars{return_to_url},
"Return URL not set when referrer doesn't match script URL/name" );
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::no_tag( $output,
"input", { type => "hidden", name => "return_to_url" },
"...and no corresponding hidden input in form" );
# If we have a google API key and node maps are enabled, we should see the
# checkbox for this pref.
$config->gmaps_api_key( "This is not a real API key." );
$config->show_gmap_in_node_display( 1 );
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"Node map preference checkbox shown when we have a GMaps API key." );
# But not if the node map is globally disabled
$config->show_gmap_in_node_display( 0 );
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::no_tag( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"...but not when node maps are globally disabled." );
# Now test with Leaflet enabled and no Google API key.
$config->gmaps_api_key( "" );
$config->show_gmap_in_node_display( 1 );
$config->use_leaflet( 1 );
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
display_google_maps => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"Node map preference checkbox shown when we're using Leaflet." );
$config->show_gmap_in_node_display( 0 );
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::no_tag( $output,
"input", { type => "checkbox", name => "display_google_maps" },
"...but not when node maps are globally disabled." );
# Make sure the default is for preferences to never expire.
delete $ENV{HTTP_COOKIE};
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"option", { value => "never", "selected" => "1" },
"Default for preferences expiry choice is \"never\"." );
$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config,
cookie_expires => "never" );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"option", { value => "never", "selected" => "1" },
"...choice set to \"never\" if already set as such in cookie" );
$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config,
cookie_expires => "year" );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"option", { value => "year", "selected" => "1" },
"...choice set to \"year\" if already set as such in cookie" );
$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config,
cookie_expires => "month" );
$ENV{HTTP_COOKIE} = $cookie;
$output = $guide->display_prefs_form( return_output => 1, noheaders => 1 );
Test::HTML::Content::tag_ok( $output,
"option", { value => "month", "selected" => "1" },
"...choice set to \"month\" if already set as such in cookie" );
# Test JSON version of prefs page.
my $json_writer = OpenGuides::JSON->new( wiki => $wiki,
config => $config );
delete $ENV{HTTP_COOKIE};
$output = eval {
$json_writer->make_prefs_json();
};
ok( !$@, "->make_prefs_json() doesn't die when no cookie set." );
if ( $@ ) { warn "# Error was: $@"; }
# Need to strip out the Content-Type: header or the decoder gets confused.
$output =~ s/^Content-Type:.*\n//s;
my $parsed = eval {
local $SIG{__WARN__} = sub { die $_[0]; };
decode_json( $output );
};
ok( !$@, "...and its output looks like JSON." );
if ( $@ ) { warn "# Warning was: $@"; }
ok( $parsed->{username}, "...and a username is included in the output" );
#use Data::Dumper; print Dumper $parsed; exit 0;
$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config );
$output = eval {
$json_writer->make_prefs_json();
};
ok( !$@, "->make_prefs_json() doesn't die when cookie set with all defaults.");
if ( $@ ) { warn "# Error was: $@"; }
$output =~ s/^Content-Type:.*\n//s;
$parsed = eval {
local $SIG{__WARN__} = sub { die $_[0]; };
decode_json( $output );
};
ok( !$@, "...and its output looks like JSON." );
if ( $@ ) { warn "# Warning was: $@"; }
# We don't get a username set in this case.
$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie( config => $config,
username => "Kake" );
$output = eval {
$json_writer->make_prefs_json();
};
ok( !$@,
"->make_prefs_json() doesn't die when cookie set with given username.");
if ( $@ ) { warn "# Error was: $@"; }
$output =~ s/^Content-Type:.*\n//s;
$parsed = eval {
local $SIG{__WARN__} = sub { die $_[0]; };
decode_json( $output );
};
ok( !$@, "...and its output looks like JSON." );
if ( $@ ) { warn "# Warning was: $@"; }
is( $parsed->{username}, "Kake",
"...and the correct username is included in the output" );
t/510_show_index_omits_deletion_link.t view on Meta::CPAN
# Clear out the database from any previous runs.
OpenGuides::Test::refresh_db();
my $config = OpenGuides::Test->make_basic_config;
$config->script_name( "wiki.cgi" );
$config->script_url( "http://example.com/" );
my $guide = OpenGuides->new( config => $config );
# Set is_admin to 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
is_admin => 1,
);
$ENV{HTTP_COOKIE} = $cookie;
# Put in some test data.
my $wiki = $guide->wiki;
$wiki->write_node( "Test Page", "foo", undef,
{ category => "Alpha", locale => "Assam" } )
t/606_bug_latlong_representation.t view on Meta::CPAN
}
);
# Plucene is the recommended searcher now.
eval { require Wiki::Toolkit::Search::Plucene; };
if ( $@ ) { $config->use_plucene( 0 ) };
my $guide = OpenGuides->new( config => $config );
# Set preferences to have lat/long displayed in deg/min/sec.
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "Kake",
include_geocache_link => 1,
preview_above_edit_box => 1,
latlong_traditional => 1, # this is the important bit
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
t/606_bug_latlong_representation.t view on Meta::CPAN
OpenGuides::Test->write_data(
guide => $guide,
node => "Test Page",
latitude => 51.368,
longitude => -0.0973,
);
my %data = $guide->wiki->retrieve_node( "Test Page" );
my $lat = $data{metadata}{latitude}[0];
unlike( $lat, qr/d/,
"lat not stored in dms format even if prefs set to display that way" );
# Check the distance search form has unmunged lat/long.
my $output = $guide->display_node(
return_output => 1,
id => "Test Page",
);
unlike( $output, qr/name="latitude"\svalue="[-0-9]*d/,
"latitude in non-dms format in distance search form" );
# Now write a node with no location data, and check that it doesn't
# claim to have any when we display it.
eval {
local $SIG{__WARN__} = sub { die $_[0]; };
OpenGuides::Test->write_data(
guide => $guide,
node => "Locationless Page",
);
};
is( $@, "",
"commit doesn't warn when prefs say dms format and node has no loc data" );
$output = $guide->display_node(
return_output => 1,
id => "Locationless Page",
);
unlike( $output, qr/latitude:/i,
"node with no location data doesn't display a latitude" );
t/803_show_delete_to_admins_only.t view on Meta::CPAN
# Clear out the database from any previous runs.
OpenGuides::Test::refresh_db();
# Make a guide
$config = OpenGuides::Test->make_basic_config;
$config->enable_page_deletion( 1 );
$guide = OpenGuides->new( config => $config );
# set is_admin to 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/803_show_delete_to_admins_only.t view on Meta::CPAN
"delete link in footer for admin" );
$output = $guide->list_all_versions(
return_output => 1,
id => "Test Page",
);
like( $output, qr/version=1;action=delete/,
"delete links on history page" );
# set is_admin to 0
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 0,
t/804_navbar_admin.t view on Meta::CPAN
my ( $config, $guide, $wiki, $output );
# Clear out the database from any previous runs.
OpenGuides::Test::refresh_db();
# Make a guide
$config = OpenGuides::Test->make_basic_config;
$guide = OpenGuides->new( config => $config );
# set is_admin to 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/804_navbar_admin.t view on Meta::CPAN
return_output => 1,
noheaders => 1,
id => "Test Page",
);
# check navbar_admin div is shown.
Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_admin" },
"admin section displayed in navbar" );
# set is_admin to 0
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 0,
t/806_recent_changes.t view on Meta::CPAN
# Check all went in OK.
my %red = $wiki->retrieve_node( "Red Lion" );
my %blue = $wiki->retrieve_node( "Blue Lion" );
ok( $wiki->node_exists( "Red Lion" ), "Red Lion written." );
ok( $wiki->node_exists( "Blue Lion" ), "Blue Lion written." );
is( $red{version}, 4, "Correct Red version." );
is( $blue{version}, 4, "Correct Blue version." );
# Check recent changes output when minor edits switched on.
my $cookie = OpenGuides::CGI->make_prefs_cookie( config => $config,
show_minor_edits_in_rc => 1 );
$ENV{HTTP_COOKIE} = $cookie;
# First check default display.
my %tt_vars = $guide->display_recent_changes( return_tt_vars => 1 );
my @nodes = extract_nodes( %tt_vars );
my @names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes;
is_deeply( \@names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ],
"With minor edits: nodes returned only once however many times changed." );
diag( "Found: " . join( ", ", @names_vers ) );
t/806_recent_changes.t view on Meta::CPAN
my $fourdays = $now - ( ONE_DAY * 4 );
%tt_vars = $guide->display_recent_changes( return_tt_vars => 1,
since => $fourdays->epoch );
@nodes = extract_nodes( %tt_vars );
@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes;
is_deeply( \@names_vers, [ "Blue Lion (v4)", "Red Lion (v4)" ],
"...and past 4 days" );
diag( "Found: " . join( ", ", @names_vers ) );
# Now test with minor edits switched off.
$cookie = OpenGuides::CGI->make_prefs_cookie( config => $config,
show_minor_edits_in_rc => 0 );
$ENV{HTTP_COOKIE} = $cookie;
# First check default display.
%tt_vars = $guide->display_recent_changes( return_tt_vars => 1 );
@nodes = extract_nodes( %tt_vars );
@names_vers = sort map { "$_->{name} (v$_->{version})" } @nodes;
is_deeply( \@names_vers, [ "Blue Lion (v3)", "Red Lion (v3)" ],
"Without minor edits: node returned only once however many times changed." );
diag( "Found: " . join( ", ", @names_vers ) );
t/806_recent_changes.t view on Meta::CPAN
# Recent Changes output with minor edits and admin links switched on.
# We can't use OG::Test->write_data() for this, because it calls
# make_cgi_object(), which overwrites REMOTE_ADDR (and we want to test
# output of IP address).
my $q = OpenGuides::Test->make_cgi_object();
$q->param( -name => "username", -value => "Anonymous" );
$q->param( -name => "locales", -value => "London" );
my $test_host = "198.51.100.255";
$ENV{REMOTE_ADDR} = $test_host;
$guide->commit_node( id => "A Pub", cgi_obj => $q, return_output => 1 );
$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie(
config => $config, show_minor_edits_in_rc => 1, is_admin => 1 );
my $output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr|Auto\s+Create|,
"Auto Create stuff shown on Recent Changes." );
unlike( $output, qr|host=;action=userstats|,
"...and no spurious link to host userstats" );
# Make sure IP addresses always show up for anonymous edits.
$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie(
config => $config, is_admin => 1 );
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr|$test_host|,
"IP addresses show for anon edits when admin links switched on" );
$ENV{HTTP_COOKIE} = OpenGuides::CGI->make_prefs_cookie(
config => $config, is_admin => 0 );
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr|$test_host|,
"...also when admin links switched off" );
sub setup_pages {
# We write directly to the database because that way we can fake the pages
# having been written in the past. Copied from test 062 in Wiki::Toolkit.
my $dbh = $wiki->store->dbh;
my $content_sth = $dbh->prepare( "INSERT INTO content
t/807_more_recent_changes.t view on Meta::CPAN
my @nodes = $wiki->list_recent_changes( days => 1 );
is( scalar @nodes, 1,
"By default each node returned only once however many times changed" );
@nodes = $wiki->list_recent_changes( days => 1, include_all_changes => 1 );
is( scalar @nodes, 3,
"...returned more than once when 'include_all_changes' set" );
# when minor_edits = 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/807_more_recent_changes.t view on Meta::CPAN
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr/<td class="recentchanges_node_name"/,
"expecting a table definition for an edit" );
like ($output, qr/Third edit/, "showing the most recent minor edit");
unlike ($output, qr/First edit/, "showing a page edit twice when show minor edits enabled. ");
# set show_minor_edits to 0.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 0,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/808_recent_changes_overtime.t view on Meta::CPAN
is( scalar @nodes, 1,
"node edited between 14 to 30 days ago" );
@nodes = $wiki->list_recent_changes( between_days => [7, 14] );
is( scalar @nodes, 1,
"node edited between 7 to 14 days ago" );
@nodes = $wiki->list_recent_changes( between_days => [1, 6] );
is( scalar @nodes, 1,
"node edited between 1 to 7 days ago" );
# when minor_edits = 1
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
);
my $output = $guide->display_recent_changes( return_output => 1 );
# check recent changes renders properly
unlike ($output, qr/24 hours/, "no pages changed in the last 24 hours");
like ($output, qr/last week/, "edits in the last week");
like ($output, qr/last fortnight/, "edits in the last fornight");
like ($output, qr/last 30 days/, "edits in the last 30 days");
# set show_minor_edits to 0.
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 0,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/808_recent_changes_overtime.t view on Meta::CPAN
%node = $wiki->retrieve_node("Echidnas");
is( $node{version}, 2, "Second version" );
$output = $guide->display_recent_changes( return_output => 1 );
# check recent changes renders properly
like ($output, qr/24 hours/, "pages changed in the last 24 hours");
unlike ($output, qr/Echidnas rock/, "not showing multiple edits");
like ($output, qr/last week/, "edits in the last week");
like ($output, qr/last fortnight/, "edits in the last fornight");
unlike ($output, qr/last 30 days/, "no edits in the last 30 days");
$cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "bob",
include_geocache_link => 1,
preview_above_edit_box => 1,
omit_help_links => 1,
show_minor_edits_in_rc => 1,
default_edit_type => "tidying",
cookie_expires => "never",
track_recent_changes_views => 1,
is_admin => 1,
t/809_recent_changes_ip_addr.t view on Meta::CPAN
# Clear out the database from any previous runs.
OpenGuides::Test::refresh_db();
my $config = OpenGuides::Test->make_basic_config;
my $guide = OpenGuides->new( config => $config );
my $wiki = $guide->wiki;
# First we need to make sure that the preferences are accessible
# from the recent changes view. Can't test this using return_tt_vars
# because the prefs TT var is set in OpenGuides::Template->output(),
# and if return_tt_vars is set then execution never gets that far.
# So write a custom navbar template that just prints the variable we're
# interested in.
$config->custom_template_path( cwd . "/t/templates/" );
eval {
unlink cwd . "/t/templates/navbar.tt";
};
open( FILE, ">", cwd . "/t/templates/navbar.tt" )
or die $!;
print FILE <<EOF;
PREFS_IS_ADMIN: [% prefs.is_admin %]
EOF
close FILE or die $!;
$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1 );
my $output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr/PREFS_IS_ADMIN:\s+1/,
"prefs available as TT var on recent changes" );
# Make sure this still works when they have a recent changes tracking cookie.
$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 );
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr/PREFS_IS_ADMIN:\s+1/,
"...even when there's a recent changes tracking cookie set" );
# Clean up.
unlink cwd . "/t/templates/navbar.tt";
t/809_recent_changes_ip_addr.t view on Meta::CPAN
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr/">198.51.100.255/, "Full IP address shown if short enough" );
$ENV{HTTP_COOKIE} = make_cookie( is_admin => 1, track_rc => 1 );
$output = $guide->display_recent_changes( return_output => 1 );
like( $output, qr/">198.51.100.255/,
"...also if recent changes tracking is on" );
sub make_cookie {
my %args = @_;
my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "Kake",
is_admin => $args{is_admin} || 0,
track_recent_changes_views => $args{track_rc} || 0,
);
if ( $args{track_rc} ) {
my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie(
config => $config,
);
my @prefs_bits = split( qr/\s*;\s*/, $prefs_cookie );
my @rc_bits = split( qr/\s*;\s*/, $rc_cookie );
return $prefs_bits[0] . "; " . $rc_bits[0];
}
return $prefs_cookie;
}
t/901_username_in_templates.t view on Meta::CPAN
[% IF username %]
You are logged in as [% username %].
[% ELSE %]
You are not logged in.
[% END %]
</div>
EOF
close $fh or die $!;
# Set a username in the cookie.
my $cookie = OpenGuides::CGI->make_prefs_cookie(
config => $config,
username => "Kake",
);
$ENV{HTTP_COOKIE} = $cookie;
# Check that username appears if cookie is set.
my $output = $guide->display_node( id => "Ship Of Fools", return_output => 1 );
like( $output, qr/You are logged in as Kake./,
"username sent to templates if set in prefs cookie" );
# Check that username doesn't appear if cookie not set.
delete $ENV{HTTP_COOKIE};
$output = $guide->display_node( id => "Ship Of Fools", return_output => 1 );
like( $output, qr/You are not logged in./,
"...but not if no username is set." );
templates/navbar_options.tt view on Meta::CPAN
<div id="navbar_options">
<div class="navbar_group_title">Options:</div>
<ul>
<li><a href="[% script_url %]preferences.cgi">Set username/prefs</a></li>
</ul>
</div>
templates/navbar_tools.tt view on Meta::CPAN
<div id="navbar_tools">
<div class="navbar_group_title">Tools:</div>
<ul>
<li><a href="[% full_cgi_url %]?action=rc">Recent Changes</a></li>
[% UNLESS read_only %]
<li><a href="[% script_url %]newpage.cgi">Create New Page</a></li>
[% END %]
<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 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>
templates/preferences.tt view on Meta::CPAN
[% INCLUDE navbar.tt %]
[% END %]
<div id="maincontent">
[% IF show_form %]
<form id="preferences_form" action="preferences.cgi" method="post">
<div class="set_username">
<h2>Username</h2>
<label for="username">How you wish to be identified in Recent Changes:</label>
<input type="text" size="20" id="username" name="username" value="[% prefs.username %]" />
</div>
<div class="set_preferences">
<h2>Preferences</h2>
<p>
[% IF prefs.preview_above_edit_box %]
<input type="checkbox" id="preview_above" name="preview_above_edit_box" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="preview_above" name="preview_above_edit_box" value="1" />
[% END %]
<label for="preview_above">Put the preview above the edit area when previewing a page edit.</label>
</p>
<p>
[% IF prefs.include_geocache_link %]
<input type="checkbox" id="geocache" name="include_geocache_link" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="geocache" name="include_geocache_link" value="1" />
[% END %]
<label for="geocache">Include “Look for nearby geocaches” link in navbar.</label>
</p>
<p>
[% IF prefs.latlong_traditional %]
<input type="checkbox" id="latlong" name="latlong_traditional" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="latlong" name="latlong_traditional" value="1" />
[% END %]
<label for="latlong">Display latitude and longitude as degrees and minutes instead of decimal.</label>
</p>
<p>
[% IF prefs.omit_help_links %]
<input type="checkbox" id="omit_help" name="omit_help_links" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="omit_help" name="omit_help_links" value="1" />
[% END %]
<label for="omit_help">Omit help links from navbar.</label>
</p>
<p>
[% IF prefs.show_minor_edits_in_rc %]
<input type="checkbox" id="show_minor" name="show_minor_edits_in_rc" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="show_minor" name="show_minor_edits_in_rc" value="1" />
[% END %]
<label for="show_minor">Include “minor edits” in Recent Changes.</label>
</p>
<p>
[% IF prefs.is_admin %]
<input type="checkbox" id="is_admin" name="is_admin" value="1" checked="1" />
[% ELSE %]
<input type="checkbox" id="is_admin" name="is_admin" value="1" />
[% END %]
<label for="is_admin">Show admin related links</label>
</p>
<p>
[% 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" />
[% END %]
<label for="track_recent_changes_views">Track my visits to Recent Changes and offer me a link for “changes since I last viewed Recent Changes”.</label>
</p>
[% IF ( config.use_leaflet OR gmaps_api_key )
AND config.show_gmap_in_node_display %]
<p>
[% 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" />
[% END %]
<label for="display_google_maps">Display a map on every page with geodata.</label>
</p>
[% END %]
<p>
<label for="default_edit_type">Default edit type:</label>
<select name="default_edit_type" id="default_edit_type">
[% IF prefs.default_edit_type == 'normal' %]
<option value="normal" selected="1">Normal edit</option>
<option value="tidying">Minor tidying</option>
[% ELSE %]
<option value="normal">Normal edit</option>
<option value="tidying" selected="1">Minor tidying</option>
[% END %]
</select>
</p>
<p>
<label for="cookie_expires">Preferences expire:</label>
<select name="cookie_expires" id="cookie_expires">
[% IF prefs.cookie_expires == 'month' %]
<option value="month" selected="1">in one month</option>
<option value="year">in one year</option>
<option value="never">never</option>
[% 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>
[% ELSE %]
<option value="month">in one month</option>
<option value="year">in one year</option>
<option value="never" selected="1">never</option>
[% END %]
</select>
</p>
templates/preferences.tt view on Meta::CPAN
[% IF return_to_url %]
<input type="hidden" name="return_to_url"
value="[% return_to_url | html %]" />
[% END %]
</form>
[% ELSE %]
<h1>Username/preferences saved</h1>
<p>Username set to “[% prefs.username %]”.</p>
<p>Preview area shown
[% IF prefs.preview_above_edit_box %]
above
[% ELSE %]
below
[% END %]
edit box.</p>
<p>“Look for nearby geocaches” link
[% UNLESS prefs.include_geocache_link %] not [% END %]
included in navbar.</p>
<p>Latitude and longitude displayed as
[% IF prefs.latlong_traditional %]
degrees and minutes.
[% ELSE %]
decimal.
[% END %]
</p>
<p>Help links will
[% IF prefs.omit_help_links %] not [% END %]
be included in navbar.
</p>
<p>Admin links will
[% UNLESS prefs.is_admin %] not [% END %]
be included in navbar.
</p>
<p>Minor edits
[% UNLESS show_minor_edits_in_rc %] not [% END %]
included in Recent Changes.</p>
<p>Your visits to Recent Changes will
[% UNLESS prefs.track_recent_changes_views %] not [% END %]
be tracked.</p>
[% IF ( config.use_leaflet OR gmaps_api_key )
AND config.show_gmap_in_node_display %]
<p>Maps will
[% UNLESS prefs.display_google_maps %] not [% END %]
be displayed on pages with geodata.</p>
[% END %]
<p>Default edit type set to
[% IF prefs.default_edit_type == 'normal' %]
“Normal edit”.
[% ELSE %]
“Minor tidying”.
[% END %]
</p>
<p>Your preferences will
[% IF prefs.cookie_expires == 'never' %]
never expire.
[% ELSIF prefs.cookie_expires == 'year' %]
expire in one year.
[% ELSE %]
expire in one month.
[% END %]
</p>
<ul id="prefs_saved_extra_nav">
<li><a href="[% IF return_to_url %][% return_to_url | html %][% ELSE %][% full_cgi_url %][% END %]">Return to [% site_name %]</a></li>
<li><a href="preferences.cgi">Change preferences</a></li>
</ul>
[% END %]
</div>
[% IF config.content_above_navbar_in_html %]
[% INCLUDE navbar.tt %]
[% END %]
my %tt_vars = ( last_five_nodes => \@nodes,
username => $username,
username_param => $wiki->formatter->node_name_to_node_param($username),
host => $host,
);
process_template("userstats.tt", "", \%tt_vars);
}
sub get_cookie {
my $pref_name = shift or return "";
my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config);
return $cookie_data{$pref_name};
}
sub display_node_rdf {
my %args = @_;
my $rdf_writer = OpenGuides::RDF->new( wiki => $wiki,
config => $config );
print "Content-type: application/rdf+xml\n\n";
print $rdf_writer->emit_rdfxml( node => $args{node} );
}