File Coverage

blib/lib/Kwiki/RenamePage.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::RenamePage;
2              
3 1     1   20238 use warnings;
  1         2  
  1         27  
4 1     1   4 use strict;
  1         2  
  1         58  
5              
6             =head1 NAME
7              
8             Kwiki::RenamePage - Better Names for Misnamed Kwiki Pages
9              
10             =head1 VERSION
11              
12             Version 0.01
13              
14             =cut
15              
16             our $VERSION = '0.02';
17              
18             =head1 SYNOPSIS
19              
20             Moves content of OldPage to NewName, replacing it with the message, "This page has moved to NewName." Text in other pages which could have been a link to OldPage is changed to link to NewName, but with the old text left parenthesized as, "(Old name: OldPage)".
21              
22             =cut
23              
24 1     1   486 use Kwiki::Plugin '-Base';
  0            
  0            
25             use mixin 'Kwiki::NewPage';
26             use mixin 'Kwiki::Installer';
27              
28             =head1 class_id
29              
30             Unmodifiable Class id accessor
31              
32             =cut
33              
34             const class_id => 'rename_page';
35              
36             =head1 cgi_class
37              
38             Unmodifiable Class class accessor
39              
40             =cut
41              
42             const cgi_class => 'Kwiki::RenamePage::CGI';
43              
44             =head1 screen_template
45              
46             unmodifiable screen_template accessor
47              
48             =cut
49              
50             const screen_template => 'rename_page_content.html';
51              
52             =head1 old_page_name
53              
54             Modifiable old_page_name accessor
55              
56             =cut
57              
58             field 'old_page_name';
59              
60             =head1 old_page_content
61              
62             Modifiable old_page_content accessor
63              
64             =cut
65              
66             field 'old_page_content';
67              
68             # field 'page_time';
69              
70             =head1 METHODS
71              
72             =over 8
73              
74             =item B
75              
76             Plug the plugin in.
77              
78             =cut
79              
80             sub register {
81             my $registry = shift;
82             $registry->add( action => 'rename_page' );
83             $registry->add( toolbar => 'rename_page_button',
84             template => 'rename_page_button.html' );
85             }
86              
87             =item B
88              
89             Rename the page.
90              
91             =cut
92              
93             sub rename_page {
94             my $page = $self->pages->current;
95             my $old_name = $self->cgi->old_page_name;
96             my $new_name = $self->cgi->new_page_name;
97             $self->old_page_name( $self->cgi->page_name );
98             my $error_msg = '';
99             my $page_uri;
100             if ( $self->cgi->button ) {
101             $error_msg = $self->check_page_name or do {
102             my $old_page = $self->pages->new_from_name( $old_name );
103             my $new_page = $self->pages->new_from_name( $new_name );
104             return $self->redirect( $new_page->uri )
105             unless $new_page->is_writable;
106             my $current = $self->pages->current($old_page);
107             my $yanked_content = $current->content;
108             $current->content("This page has moved to $new_name.");
109             if ( $current->modified_time != $self->cgi->page_time )
110             {
111             return("action=edit_contention;page_name=$current->uri");
112             }
113             $current->update->store;
114             my $link = qr/$old_name/;
115             for my $page ( $self->pages->all )
116             {
117             # my $current = $self->pages->current($page);
118             my $content = $page->content;
119             $content =~ s/$old_name/$new_name (Old name: $old_name)/g;
120             $page->content($content);
121             $page->update->store;
122             }
123             $current = $self->pages->current($new_page);
124             $current->content($yanked_content);
125             $current->update->store;
126             return $self->redirect($current->uri);
127             }
128             }
129             return $self->render_screen( error_msg => $error_msg ) if $error_msg;
130             return $self->render_screen( old_page_name => $self->old_page_name,
131             page_time => $page->modified_time);
132             }
133              
134             package Kwiki::RenamePage::CGI;
135             use Kwiki::CGI '-base';
136              
137             cgi 'new_page_name';
138             cgi 'old_page_name';
139             cgi 'page_name';
140             cgi 'page_time';
141              
142             1;
143              
144             package Kwiki::RenamePage;
145              
146             =back
147              
148             =head1 AUTHOR
149              
150             Dr Bean, C<< >>
151              
152             =head1 BUGS
153              
154             Please report any bugs or feature requests to
155             C, or through the web interface at
156             L.
157             I will be notified, and then you'll automatically be notified of progress on
158             your bug as I make changes.
159              
160             =head1 SUPPORT
161              
162             You can find documentation for this module with the perldoc command.
163              
164             perldoc Kwiki::RenamePage
165              
166             You can also look for information at:
167              
168             =over 4
169              
170             =item * AnnoCPAN: Annotated CPAN documentation
171              
172             L
173              
174             =item * CPAN Ratings
175              
176             L
177              
178             =item * RT: CPAN's request tracker
179              
180             L
181              
182             =item * Search CPAN
183              
184             L
185              
186             =back
187              
188             =head1 ACKNOWLEDGEMENTS
189              
190             =head1 COPYRIGHT & LICENSE
191              
192             Copyright 2006 Dr Bean, all rights reserved.
193              
194             This program is free software; you can redistribute it and/or modify it
195             under the same terms as Perl itself.
196              
197             =cut
198              
199             1; # End of Kwiki::RenamePage
200              
201             __DATA__