]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/cutpaste.pm
typo
[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 => "getsetup", id => "cutpaste", call => \&getsetup);
13         hook(type => "preprocess", id => "cut", call => \&preprocess_cut, scan => 1);
14         hook(type => "preprocess", id => "copy", call => \&preprocess_copy, scan => 1);
15         hook(type => "preprocess", id => "paste", call => \&preprocess_paste);
16 } # }}}
17
18 sub getsetup () { #{{{
19         return
20                 plugin => {
21                         safe => 1,
22                         rebuild => undef,
23                 },
24 } #}}}
25
26 sub preprocess_cut (@) { #{{{
27         my %params=@_;
28
29         foreach my $param (qw{id text}) {
30                 if (! exists $params{$param}) {
31                         error sprintf(gettext('%s parameter is required'), $param);
32                 }
33         }
34
35         $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
36         $savedtext{$params{page}}->{$params{id}} = $params{text};
37
38         return "" if defined wantarray;
39 } # }}}
40
41 sub preprocess_copy (@) { #{{{
42         my %params=@_;
43
44         foreach my $param (qw{id text}) {
45                 if (! exists $params{$param}) {
46                         error sprintf(gettext('%s parameter is required'), $param);
47                 }
48         }
49
50         $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}};
51         $savedtext{$params{page}}->{$params{id}} = $params{text};
52
53         return IkiWiki::preprocess($params{page}, $params{destpage}, 
54                 IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray;
55 } # }}}
56
57 sub preprocess_paste (@) { #{{{
58         my %params=@_;
59
60         foreach my $param (qw{id}) {
61                 if (! exists $params{$param}) {
62                         error sprintf(gettext('%s parameter is required'), $param);
63                 }
64         }
65
66         if (! exists $savedtext{$params{page}}) {
67                 error gettext('no text was copied in this page');
68         }
69         if (! exists $savedtext{$params{page}}->{$params{id}}) {
70                 error sprintf(gettext('no text was copied in this page with id %s'), $params{id});
71         }
72
73         return IkiWiki::preprocess($params{page}, $params{destpage}, 
74                 IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}}));
75 } # }}}
76
77 1;