| blib/lib/Kwiki/Edit/ContentionManagement.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 7 | 9 | 77.7 |
| branch | n/a | ||
| condition | n/a | ||
| subroutine | 3 | 3 | 100.0 |
| pod | n/a | ||
| total | 10 | 12 | 83.3 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Kwiki::Edit::ContentionManagement; | ||||||
| 2 | |||||||
| 3 | 1 | 1 | 22190 | use warnings; | |||
| 1 | 3 | ||||||
| 1 | 35 | ||||||
| 4 | 1 | 1 | 6 | use strict; | |||
| 1 | 7 | ||||||
| 1 | 40 | ||||||
| 5 | 1 | 1 | 484 | use Kwiki::Plugin '-Base'; | |||
| 0 | |||||||
| 0 | |||||||
| 6 | use mixin 'Kwiki::Installer'; | ||||||
| 7 | our $VERSION = '0.01'; | ||||||
| 8 | |||||||
| 9 | const class_title => 'Contention Management'; | ||||||
| 10 | const class_id => 'contention_management'; | ||||||
| 11 | |||||||
| 12 | sub register { | ||||||
| 13 | my $registry = shift; | ||||||
| 14 | |||||||
| 15 | $registry->add(hook => 'edit:edit', | ||||||
| 16 | pre => 'contention_check' | ||||||
| 17 | ); | ||||||
| 18 | } | ||||||
| 19 | |||||||
| 20 | sub contention_check { | ||||||
| 21 | my $hook = pop; | ||||||
| 22 | return if $self->cgi->button ne $self->config->edit_save_button_text; | ||||||
| 23 | |||||||
| 24 | my $page = $self->pages->current; | ||||||
| 25 | if ($page->modified_time != $self->cgi->page_time) { | ||||||
| 26 | my $ret = $self->render_screen( | ||||||
| 27 | page_time => $page->modified_time); | ||||||
| 28 | my $warning = Kwiki::Edit::ContentionManagement::warning( | ||||||
| 29 | $self, $page); | ||||||
| 30 | $ret =~ s/\ | ||||||
| 31 | $hook->cancel; | ||||||
| 32 | return $ret; | ||||||
| 33 | } | ||||||
| 34 | } | ||||||
| 35 | |||||||
| 36 | sub warning { | ||||||
| 37 | my $page = shift; | ||||||
| 38 | my $edituser = $page->metadata->edit_by || 'UnknownUser'; | ||||||
| 39 | my $edittime = $page->edit_time; | ||||||
| 40 | |||||||
| 41 | return < | ||||||
| 42 | $edituser edited this file on $edittime! |
||||||
| 43 | |||||||
| 44 | While you were editing this page $edituser saved changes to it. You can |
||||||
| 45 | continue with your save but you will overwrite the changes made by the | ||||||
| 46 | $edituser. | ||||||
| 47 | |||||||
| 48 | You may also get this message if you saved some changes and then used |
||||||
| 49 | your browser's back button to return to the Edit screen and make more | ||||||
| 50 | changes. Always use the Kwiki Edit button to get to the Edit screen. | ||||||
| 51 | |||||||
| 52 | WARNING | ||||||
| 53 | } | ||||||
| 54 | |||||||
| 55 | 1; # End of Kwiki::Edit::ContentionManagement | ||||||
| 56 | |||||||
| 57 | __DATA__ |