2 package IkiWiki
::Plugin
::cutpaste
;
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
);
26 sub preprocess_cut
(@
) {
29 foreach my $param (qw{id text
}) {
30 if (! exists $params{$param}) {
31 error
sprintf(gettext
('%s parameter is required'), $param);
35 $savedtext{$params{page
}} = {} if not exists $savedtext{$params{"page"}};
36 $savedtext{$params{page
}}->{$params{id
}} = $params{text
};
38 return "" if defined wantarray;
41 sub preprocess_copy
(@
) {
44 foreach my $param (qw{id text
}) {
45 if (! exists $params{$param}) {
46 error
sprintf(gettext
('%s parameter is required'), $param);
50 $savedtext{$params{page
}} = {} if not exists $savedtext{$params{"page"}};
51 $savedtext{$params{page
}}->{$params{id
}} = $params{text
};
53 return IkiWiki
::preprocess
($params{page
}, $params{destpage
},
54 IkiWiki
::filter
($params{page
}, $params{destpage
}, $params{text
})) if defined wantarray;
57 sub preprocess_paste
(@
) {
60 foreach my $param (qw{id
}) {
61 if (! exists $params{$param}) {
62 error
sprintf(gettext
('%s parameter is required'), $param);
66 if (! exists $savedtext{$params{page
}}) {
67 error gettext
('no text was copied in this page');
69 if (! exists $savedtext{$params{page
}}->{$params{id
}}) {
70 error
sprintf(gettext
('no text was copied in this page with id %s'), $params{id
});
73 return IkiWiki
::preprocess
($params{page
}, $params{destpage
},
74 IkiWiki
::filter
($params{page
}, $params{destpage
}, $savedtext{$params{page
}}->{$params{id
}}));