2 package IkiWiki
::Plugin
::cutpaste
;
9 hook
(type
=> "getsetup", id
=> "cutpaste", call
=> \
&getsetup
);
10 hook
(type
=> "needsbuild", id
=> "cutpaste", call
=> \
&needsbuild
);
11 hook
(type
=> "preprocess", id
=> "cut", call
=> \
&preprocess_cut
, scan
=> 1);
12 hook
(type
=> "preprocess", id
=> "copy", call
=> \
&preprocess_copy
, scan
=> 1);
13 hook
(type
=> "preprocess", id
=> "paste", call
=> \
&preprocess_paste
);
27 foreach my $page (keys %pagestate) {
28 if (exists $pagestate{$page}{cutpaste
}) {
29 if (exists $pagesources{$page} &&
30 grep { $_ eq $pagesources{$page} } @
$needsbuild) {
31 # remove state, will be re-added if
32 # the cut/copy directive is still present
34 delete $pagestate{$page}{cutpaste
};
41 sub preprocess_cut
(@
) {
44 foreach my $param (qw{id text
}) {
45 if (! exists $params{$param}) {
46 error
sprintf(gettext
('%s parameter is required'), $param);
50 $pagestate{$params{page
}}{cutpaste
}{$params{id
}} = $params{text
};
52 return "" if defined wantarray;
55 sub preprocess_copy
(@
) {
58 foreach my $param (qw{id text
}) {
59 if (! exists $params{$param}) {
60 error
sprintf(gettext
('%s parameter is required'), $param);
64 $pagestate{$params{page
}}{cutpaste
}{$params{id
}} = $params{text
};
66 return IkiWiki
::preprocess
($params{page
}, $params{destpage
}, $params{text
})
70 sub preprocess_paste
(@
) {
73 foreach my $param (qw{id
}) {
74 if (! exists $params{$param}) {
75 error
sprintf(gettext
('%s parameter is required'), $param);
79 if (! exists $pagestate{$params{page
}}{cutpaste
}) {
80 error gettext
('no text was copied in this page');
82 if (! exists $pagestate{$params{page
}}{cutpaste
}{$params{id
}}) {
83 error
sprintf(gettext
('no text was copied in this page with id %s'), $params{id
});
86 return IkiWiki
::preprocess
($params{page
}, $params{destpage
},
87 $pagestate{$params{page
}}{cutpaste
}{$params{id
}});