line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::NewPage; |
2
|
1
|
|
|
1
|
|
31078
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
use Kwiki ':char_classes'; |
5
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
const class_id => 'new_page'; |
8
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::NewPage::CGI'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
|
|
|
|
|
|
my $registry = shift; |
12
|
|
|
|
|
|
|
$registry->add(action => 'new_page'); |
13
|
|
|
|
|
|
|
$registry->add(toolbar => 'new_page_button', |
14
|
|
|
|
|
|
|
template => 'new_page_button.html', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
$registry->add(prerequisite => 'edit'); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new_page { |
20
|
|
|
|
|
|
|
my $error_msg = ''; |
21
|
|
|
|
|
|
|
if ($self->cgi->button) { |
22
|
|
|
|
|
|
|
$error_msg = $self->check_page_name or do { |
23
|
|
|
|
|
|
|
my $page_uri = |
24
|
|
|
|
|
|
|
$self->pages->new_from_name($self->cgi->new_page_name)->uri; |
25
|
|
|
|
|
|
|
my $redirect = "action=edit&page_name=$page_uri"; |
26
|
|
|
|
|
|
|
return $self->redirect($redirect); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
$self->render_screen( |
30
|
|
|
|
|
|
|
error_msg => $error_msg, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub check_page_name { |
35
|
|
|
|
|
|
|
my $page_name = $self->cgi->new_page_name; |
36
|
|
|
|
|
|
|
return "There is already a page named '$page_name'." |
37
|
|
|
|
|
|
|
if $self->pages->new_from_name($page_name)->exists; |
38
|
|
|
|
|
|
|
return "'$page_name' is an invalid page name. Can't contain spaces." |
39
|
|
|
|
|
|
|
if $page_name =~ /\s/; |
40
|
|
|
|
|
|
|
return "'$page_name' is an invalid page name. Invalid characters." |
41
|
|
|
|
|
|
|
unless $page_name =~ /^[$ALPHANUM]+$/; |
42
|
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package Kwiki::NewPage::CGI; |
46
|
|
|
|
|
|
|
use Kwiki::CGI -base; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
cgi new_page_name => -utf8; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package Kwiki::NewPage; |
51
|
|
|
|
|
|
|
__DATA__ |