]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/cutpaste.pm
avoid setting default value in websetup_force_plugins
[ikiwiki.git] / IkiWiki / Plugin / cutpaste.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::cutpaste;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7 use UNIVERSAL;
8
9 my %savedtext;
10
11 sub import { #{{{
12         hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1);
13         hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1);
14         hook(type => "preprocess", id => "paste", call => \&preprocess_paste);
15 } # }}}
16
17 sub preprocess_cut (@) { #{{{
18         my %params=@_;
19
20         foreach my $param (qw{id text}) {
21                 if (! exists $params{$param}) {
22                         error sprintf(gettext('%s parameter is required'), $param);
23                 }
24         }
25
26         $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
27         $savedtext{$params{page}}->{$params{id}} = $params{text};
28
29         return "" if defined wantarray;
30 } # }}}
31
32 sub preprocess_copy (@) { #{{{
33         my %params=@_;
34
35         foreach my $param (qw{id text}) {
36                 if (! exists $params{$param}) {
37                         error sprintf(gettext('%s parameter is required'), $param);
38                 }
39         }
40
41         $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
42         $savedtext{$params{page}}->{$params{id}} = $params{text};
43
44         return IkiWiki::preprocess($params{page}, $params{destpage}, 
45                 IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
46 } # }}}
47
48 sub preprocess_paste (@) { #{{{
49         my %params=@_;
50
51         foreach my $param (qw{id}) {
52                 if (! exists $params{$param}) {
53                         error sprintf(gettext('%s parameter is required'), $param);
54                 }
55         }
56
57         if (! exists $savedtext{$params{page}}) {
58                 error gettext('no text was copied in this page');
59         }
60         if (! exists $savedtext{$params{page}}->{$params{id}}) {
61                 error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
62         }
63
64         return IkiWiki::preprocess($params{page}, $params{destpage}, 
65                 IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));
66 } # }}}
67
68 1;