OpenGuides
view release on metacpan or search on metacpan
lib/OpenGuides.pm view on Meta::CPAN
metadata_type => "category",
metadata_value => "locales",
ignore_case => 1,
);
foreach my $omit ( @locs ) {
delete $all_nodes{$omit};
}
}
@nodes = keys %all_nodes;
}
my $node = $nodes[ rand @nodes ];
my $output;
if ( $node ) {
$output = $self->redirect_to_node( $node );
} else {
my %tt_vars = (
category => $args{category},
locale => $args{locale},
);
$output = OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "random_page_failure.tt",
vars => \%tt_vars,
);
}
return $output if $args{return_output};
print $output;
}
=item B<display_edit_form>
$guide->display_edit_form(
id => "Vivat Bacchus",
vars => \%vars,
content => $content,
metadata => \%metadata,
checksum => $checksum
);
Display an edit form for the specified node. As with other methods, the
C<return_output> parameter can be used to return the output instead of
printing it to STDOUT.
If this is to redisplay an existing edit, the content, metadata
and checksum may be supplied in those arguments
Extra template variables may be supplied in the vars argument
=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} );
$metadata_vars{website} ||= 'http://';
my $moderate = $wiki->node_required_moderation($node);
my %tt_vars = ( content => CGI->escapeHTML($content),
checksum => CGI->escapeHTML($checksum),
%metadata_vars,
config => $config,
username => $username,
edit_type => $edit_type,
moderate => $moderate,
deter_robots => 1,
read_only => $config->read_only,
);
# Override some things if we were supplied with them
$tt_vars{content} = $args{content} if $args{content};
$tt_vars{checksum} = $args{checksum} if $args{checksum};
if (defined $args{vars}) {
my %supplied_vars = %{$args{vars}};
foreach my $key ( keys %supplied_vars ) {
$tt_vars{$key} = $supplied_vars{$key};
}
}
if (defined $args{metadata}) {
my %supplied_metadata = %{$args{metadata}};
foreach my $key ( keys %supplied_metadata ) {
$tt_vars{$key} = $supplied_metadata{$key};
}
}
my $output = $self->process_template(
id => $node,
template => "edit_form.tt",
tt_vars => \%tt_vars,
);
return $output if $return_output;
print $output;
}
=item B<preview_edit>
$guide->preview_edit(
id => "Vivat Bacchus",
cgi_obj => $q,
);
Preview the edited version of the specified node. As with other methods, the
C<return_output> parameter can be used to return the output instead of
printing it to STDOUT.
=cut
sub preview_edit {
my ($self, %args) = @_;
my $node = $args{id};
my $q = $args{cgi_obj};
my $return_output = $args{return_output};
my $wiki = $self->wiki;
my $config = $self->config;
my $content = $q->param('content');
$content =~ s/\r\n/\n/gs;
my $checksum = $q->param('checksum');
my %new_metadata = OpenGuides::Template->extract_metadata_vars(
wiki => $wiki,
config => $config,
cgi_obj => $q,
set_coord_field_vars => 1,
);
foreach my $var ( qw( username comment edit_type ) ) {
$new_metadata{$var} = $q->escapeHTML(scalar $q->param($var));
}
if ($wiki->verify_checksum($node, $checksum)) {
my $moderate = $wiki->node_required_moderation($node);
my %tt_vars = (
%new_metadata,
config => $config,
content => $q->escapeHTML($content),
preview_html => $wiki->format($content),
preview_above_edit_box => $self->get_cookie(
"preview_above_edit_box" ),
checksum => $q->escapeHTML($checksum),
moderate => $moderate,
read_only => $config->read_only,
);
my $output = $self->process_template(
id => $node,
template => "edit_form.tt",
tt_vars => \%tt_vars,
);
return $output if $args{return_output};
print $output;
} 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 = "";
}
my %tt_vars = (
not_editable => 1,
show_form => 1,
not_deletable => 1,
return_to_url => $from,
);
return %tt_vars if $args{return_tt_vars};
my $output = OpenGuides::Template->output(
wiki => $wiki,
config => $config,
template => "preferences.tt",
vars => \%tt_vars,
noheaders => $args{noheaders},
);
return $output if $args{return_output};
print $output;
}
=item B<display_recent_changes>
$guide->display_recent_changes;
As with other methods, the C<return_output> parameter can be used to
return the output instead of printing it to STDOUT.
=cut
sub display_recent_changes {
my ($self, %args) = @_;
my $config = $self->config;
my $wiki = $self->wiki;
my $minor_edits = $self->get_cookie( "show_minor_edits_in_rc" );
my $id = $args{id} || $self->config->home_name;
my $return_output = $args{return_output} || 0;
my (%tt_vars, %recent_changes);
# NB the $q stuff below should be removed - we should _always_ do this via
# an argument to the method.
my $q = CGI->new;
my $since = $args{since} || $q->param("since");
if ( $since ) {
$tt_vars{since} = $since;
my $t = localtime($since); # overloaded by Time::Piece
$tt_vars{since_string} = $t->strftime;
my %criteria = ( since => $since );
$criteria{metadata_was} = { edit_type => "Normal edit" }
unless $minor_edits;
my @rc = $self->_get_recent_changes(
config => $config, criteria => \%criteria );
if ( scalar @rc ) {
lib/OpenGuides.pm view on Meta::CPAN
node => $args{id},
template => $args{template},
vars => $args{tt_vars},
cookies => $args{cookies},
http_status => $args{http_status},
noheaders => $args{noheaders},
);
if ( $args{content_type} ) {
$output_conf{content_type} = $args{content_type};
}
return OpenGuides::Template->output( %output_conf );
}
# Redirection for legacy URLs.
sub redirect_index_search {
my ( $self, %args ) = @_;
my $type = lc( $args{type} || "" );
my $value = lc( $args{value} || "" );
my $format = lc( $args{format} || "" );
my $script_url = $self->config->script_url;
my $script_name = $self->config->script_name;
my $url = "$script_url$script_name?action=index";
if ( $type eq "category" ) {
$url .= ";cat=$value";
} elsif ( $type eq "locale" ) {
$url .= ";loc=$value";
}
if ( $format ) {
$url .= ";format=$format";
}
return CGI->redirect( -uri => $url, -status => 301 );
}
sub redirect_to_node {
my ($self, $node, $redirected_from) = @_;
my $script_url = $self->config->script_url;
my $script_name = $self->config->script_name;
my $formatter = $self->wiki->formatter;
my $id = $formatter->node_name_to_node_param( $node );
my $oldid;
$oldid = $formatter->node_name_to_node_param( $redirected_from ) if $redirected_from;
my $redir_param = "$script_url$script_name?";
$redir_param .= 'id=' if $oldid;
$redir_param .= $id;
$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
L<https://github.com/OpenGuides/OpenGuides/issues>
=head1 SEE ALSO
=over 4
=item * The Randomness Guide to London, at L<http://london.randomness.org.uk/>, the largest OpenGuides site.
=item * The list of live OpenGuides installs at L<http://openguides.org/>.
=item * L<Wiki::Toolkit>, the Wiki toolkit which does the heavy lifting for OpenGuides.
=back
=head1 FEEDBACK
If you have a question, a bug report, or a patch, or you're interested
in joining the development team, please contact openguides-dev@lists.openguides.org
(moderated mailing list, will reach all current developers but you'll have
to wait for your post to be approved) or file a bug report at
L<https://github.com/OpenGuides/OpenGuides/issues>
=head1 AUTHOR
The OpenGuides Project (openguides-dev@lists.openguides.org)
=head1 COPYRIGHT
Copyright (C) 2003-2020 The OpenGuides Project. All Rights Reserved.
The OpenGuides distribution is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.
=head1 CREDITS
Programming by Dominic Hargreaves, Earle Martin, Kake Pugh, and Ivor
Williams. Testing and bug reporting by Billy Abbott, Jody Belka,
Kerry Bosworth, Simon Cozens, Cal Henderson, Steve Jolly, and Bob
Walker (among others). Much of the Module::Build stuff copied from
the Siesta project L<http://siesta.unixbeard.net/>
=cut
1;
( run in 1.327 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )