| 1 | package Kwiki::Edit; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Kwiki::Plugin -Base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use mixin 'Kwiki::Installer'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | const class_id => 'edit'; | ||||||||||||||||||||
| 6 | const class_title => 'Page Edit'; | ||||||||||||||||||||
| 7 | const cgi_class => 'Kwiki::Edit::CGI'; | ||||||||||||||||||||
| 8 | const config_file => 'edit.yaml'; | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 0 | ▶ | sub register { | ||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 11 | 0 | my $registry = shift; | |||||||||||||||||||
| 12 | 0 | $registry->add(action => 'edit'); | |||||||||||||||||||
| 13 | 0 | $registry->add(action => 'edit_contention'); | |||||||||||||||||||
| 14 | 0 | $registry->add(toolbar => 'edit_button', | |||||||||||||||||||
| 15 | template => 'edit_button.html', | ||||||||||||||||||||
| 16 | show_for => ['display', 'revisions', 'edit_contention'], | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | sub edit { | ||||||||||||||||||
|
Subroutine
edit: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 21 | 0 | my $page = $self->pages->current; | |||||||||||||||||||
| 22 | 0 | ▶ | return $self->redirect($page->uri) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | unless $page->is_writable; | ||||||||||||||||||||
| 24 | 0 | ▶ | return $self->save | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | if $self->cgi->button eq $self->config->edit_save_button_text; | ||||||||||||||||||||
| 26 | 0 | ▶ | return $self->preview | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | if $self->cgi->button eq $self->config->edit_preview_button_text; | ||||||||||||||||||||
| 28 | 0 | ▶ | my $content = $self->cgi->revision_id | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | ? $self->hub->archive->fetch($page, $self->cgi->revision_id) | ||||||||||||||||||||
| 30 | : $page->content; | ||||||||||||||||||||
| 31 | 0 | ▶ | $content ||= $self->config->default_content; | ||||||||||||||||||
|
Condition0%0/3
$content ||= $self->config->default_content
MC/DC0%0/2
$content ||= $self->config->default_content
$content
$self->config->default_content
Truth table0%0/3
A ||= B
A= $contentB= $self->config->default_content
| |||||||||||||||||||||
| 32 | 0 | $self->render_screen( | |||||||||||||||||||
| 33 | screen_title => $page->title, | ||||||||||||||||||||
| 34 | page_content => $content, | ||||||||||||||||||||
| 35 | page_time => $page->modified_time, | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | ▶ | sub save { | ||||||||||||||||||
|
Subroutine
save: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 40 | 0 | my $page = $self->pages->current; | |||||||||||||||||||
| 41 | 0 | $page->content($self->cgi->page_content); | |||||||||||||||||||
| 42 | 0 | ▶ | if ($page->modified_time != $self->cgi->page_time) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | my $page_uri = $page->uri; | |||||||||||||||||||
| 44 | 0 | return $self->redirect("action=edit_contention;page_name=$page_uri"); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | $page->update->store; | |||||||||||||||||||
| 47 | 0 | return $self->redirect($page->uri); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub preview { | ||||||||||||||||||
|
Subroutine
preview: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 51 | 0 | my $preview = $self->hub->formatter->text_to_html($self->cgi->page_content); | |||||||||||||||||||
| 52 | 0 | $self->render_screen( | |||||||||||||||||||
| 53 | preview_content => $preview, | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub edit_contention { | ||||||||||||||||||
|
Subroutine
edit_contention: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 58 | 0 | return $self->render_screen( | |||||||||||||||||||
| 59 | content_pane => 'edit_contention.html', | ||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | package Kwiki::Edit::CGI; | ||||||||||||||||||||
| 64 | 1 | ▶ | use base 'Kwiki::CGI'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | cgi 'page_content' => qw(-utf8 -newlines); | ||||||||||||||||||||
| 67 | cgi 'revision_id'; | ||||||||||||||||||||
| 68 | cgi 'page_time'; | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | package Kwiki::Edit; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | __DATA__ | ||||||||||||||||||||