Simple/NoTemplates.pm

filter: Statementstmt 100% 6 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 8 / 8 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Simple.pm ↑ Summary
1 package CGI::Wiki::Simple::NoTemplates;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use base 'CGI::Wiki::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 use vars qw($VERSION);
6 $VERSION = 0.09;
7
8 =head1 NAME
9
10 CGI::Wiki::Simple::NoTemplates - A simple wiki without templates
11
12 =head1 DESCRIPTION
13
14 This is an instant wiki.
15
16 =head1 SYNOPSIS
17
18 It might be the case that you don't want to use HTML::Template,
19 and in fact, no templates at all. Then you can simple use the
20 following example as your wiki, which does not rely on
21 HTML::Template to prepare the content :
22
23 =for example begin
24
25 use strict;
26 use CGI::Wiki::Simple::NoTemplates;
27 use CGI::Wiki::Store::MySQL; # Change this to match your setup
28
29 my $store = CGI::Wiki::Store::MySQL->new( dbname => "test",
30 dbuser => "master",
31 dbpass => "master" );
32
33
34 my $search = undef;
35 my $wiki = CGI::Wiki::Simple::NoTemplates
36 ->new( PARAMS => {
37 store => $store,
38 })->run;
39
40 =for example end
41
42 =cut
43
44 sub make_edit_form {
45 my ($self,$raw_content,%actions) = @_;
46
47 my ($url_title) = $self->param("url_node_title");
48 #my $prefix = $self->query->script_name;
49
50 return "<form method='post' enctype='multipart/form-data' action='".
51 $self->node_url(node => $self->param("node_title"), mode => 'commit')."'>"
52 . "<textarea name='content' cols='60' rows='20'>"
53 . HTML::Entities::encode_entities($raw_content)
54 . "</textarea><br />"
55 . $self->actions(node=>$url_title,%actions)
56 . "</form>";
57 };
58
59 sub make_header {
60 my ($self,$version) = @_;
61 $self->header_props( -title => $self->param("node_title"), -content_type => "text/html" );
62
63 if ($version) {
64 $version = " (v $version)"
65 } else {
66 $version = "";
67 };
68
69 return
70 "<html><head><title>" . $self->param("node_title") . "</title>".$self->param("cgi_wiki_simple_style")."</head><body>"
71 . "<table width='100%'><tr><td>" . $self->param("cgi_wiki_simple_header") . $self->param("html_node_title")
72 . "$version</td></tr></table><hr />";
73 };
74
75 sub make_footer {
76 my ($self) = @_;
77
78 my $template = $self->load_tmpl("footer.templ", die_on_bad_params => 0 );
79 return $self->param("cgi_wiki_simple_footer"),
80 };
81
82 sub make_checksum {
83 my ($self) = @_;
84 return "<input type='hidden' name='checksum' value='" . $self->param('checksum') . "' />";
85 };
86
87 sub actions {
88 my ($self,%args) = @_;
89 #my $node = $self->param("url_node_title");
90 my $node = $self->param("node_title");
91 my $checksum = $self->make_checksum();
92
93 my $prefix = $self->query->script_name;
94
95 my @result;
96
97 # First, make the "display" link
98 if (delete $args{display}) {
99 push @result, $self->inside_link( node => $node, mode => 'display', title => 'display' );
100 #push @result, "<a href='$prefix/display/$node'>display</a>";
101 };
102
103 # and then the "preview" link
104 if (delete $args{preview}) {
105 push @result, $self->inside_link( node => $node, mode => 'preview', title => 'preview' );
106 #push @result, "<a href='$prefix/preview/$node'>edit</a>";
107 };
108
109 # and then the "save" link
110 if (delete $args{commit}) {
111 push @result, "<input type='submit' name='save' value='commit'>$checksum";
112 };
113
114 # Further actions will have to go here
115
116 join " | ", @result;
117 };
118
119 sub render_display {
120 my ($self) = @_;
121 my $node = $self->param("node_title");
122 my $html_node_title = $self->param("html_node_title");
123 return $self->make_header()
124 . $self->param('content')
125 . "<hr />"
126 . $self->actions( preview => 1, node => $html_node_title )
127 . $self->param("cgi_wiki_simple_footer"),
128 . "</body></html>";
129 };
130
131 sub render_editform {
132 my ($self) = @_;
133 return $self->make_header()
134 . $self->param("content")
135 . "<hr />"
136 . $self->make_edit_form($self->param("raw"),commit=>1,display=>1 )
137 . $self->param("cgi_wiki_simple_footer")
138 . "</body></html>"
139 };
140
141 sub render_conflict {
142 my ($self) = @_;
143 return $self->make_header()
144 . $self->param("content")
145 . "<hr />"
146 . "<p class='errorMessage'>While you were editing this node, somebody else changed it already. Please integrate your changes into the changed node text to resolve the conflict.</p>"
147 . "<hr />"
148 . "<p>Your content:</p>"
149 . "<pre>"
150 . HTML::Entities::encode_entities($self->param("submitted_content"))
151 . "</pre>"
152 . "<p>Current node content:</p>"
153 . $self->make_edit_form($self->param("raw"),commit=>1,display=>1,preview=>1 )
154 . $self->{cgi_wiki_simple_footer}
155 . "</body></html>";
156 };
157
158 1;
« Simple.pm ↑ Summary