]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/cutpaste.pm
moved non-openid signin form into same page as openid selector; show/hide as buttons...
[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 3.00;
7
8 my %savedtext;
9
10 sub import {
11         hook(type => "getsetup", id => "cutpaste", call => \&getsetup);
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 getsetup () {
18         return
19                 plugin => {
20                         safe => 1,
21                         rebuild => undef,
22                         section => "widget",
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;