inline: Fix regression in feed titles. Closes: #610878 (Thanks, Paul Wise)
[ikiwiki.git] / IkiWiki / Plugin / cutpaste.pm
blob0f6ea0b1f3798650219f7a08a66fa77f85151401
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::cutpaste;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
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);
16 sub getsetup () {
17 return
18 plugin => {
19 safe => 1,
20 rebuild => undef,
21 section => "widget",
25 sub needsbuild (@) {
26 my $needsbuild=shift;
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
33 # on rebuild.
34 delete $pagestate{$page}{cutpaste};
38 return $needsbuild;
41 sub preprocess_cut (@) {
42 my %params=@_;
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 (@) {
56 my %params=@_;
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})
67 if defined wantarray;
70 sub preprocess_paste (@) {
71 my %params=@_;
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}});