aboutsummaryrefslogtreecommitdiff
path: root/doc/todo/Default_text_for_new_pages.mdwn
blob: db4c4b0555ac5287c943abb18413ed5057a1ff0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
The [[ikiwiki/directive/inline]] directive allows the creation of new pages.
It would be nice if it was possible to specify default text for the new post.
For example:

    \[[!inline pages="blog/* and !*/Discussion" postform="yes" newposttemplate="blogtemplate.mdwn"]]

This would allow you to create a new blog post.  When you hit the `Edit` button, the system presents
you with an edit form as normal, but rather than being empty, it has the text from `blogtemplate.mdwn`.

Inline below is a [[patch]] that implements this:

----

    diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
    index bb21ed2..10c985c 100644
    --- a/IkiWiki/Plugin/editpage.pm
    +++ b/IkiWiki/Plugin/editpage.pm
    @@ -60,7 +60,7 @@ sub cgi_editpage ($$) { #{{{
     
     	decode_cgi_utf8($q);
     
    -	my @fields=qw(do rcsinfo subpage from page type editcontent comments);
    +	my @fields=qw(do rcsinfo subpage from page type editcontent comments templatepage);
     	my @buttons=("Save Page", "Preview", "Cancel");
     	eval q{use CGI::FormBuilder};
     	error($@) if $@;
    @@ -117,9 +117,20 @@ sub cgi_editpage ($$) { #{{{
     	}
     	else {
     		$type=$form->param('type');
    +		
    +		my $defaultContent = "";
    +		my $templatepage = $form->param('templatepage');
    +		if ($templatepage && $pagesources{$templatepage}) {
    +			$defaultContent = readfile(IkiWiki::srcfile($pagesources{$templatepage}));
    +		}
    +		
     		if (defined $type && length $type && $hooks{htmlize}{$type}) {
     			$type=possibly_foolish_untaint($type);
     		}
    +		elsif ($templatepage && $pagesources{$templatepage}) {
    +			# favor the type of the template page
    +			$type=pagetype($pagesources{$templatepage});
    +		}
     		elsif (defined $from && exists $pagesources{$from}) {
     			# favor the type of linking page
     			$type=pagetype($pagesources{$from});
    @@ -129,7 +140,7 @@ sub cgi_editpage ($$) { #{{{
     		if (! $form->submitted) {
     			$form->field(name => "rcsinfo", value => "", force => 1);
     		}
    -		$form->field(name => "editcontent", validate => '/.+/');
    +		$form->field(name => "editcontent", value => $defaultContent, force => 0, validate => '/.+/');
     	}
     
     	$form->field(name => "do", type => 'hidden');
    diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
    index 8efef3f..075d7d8 100644
    --- a/IkiWiki/Plugin/inline.pm
    +++ b/IkiWiki/Plugin/inline.pm
    @@ -271,6 +271,7 @@ sub preprocess_inline (@) { #{{{
     			$rootpage=$params{page};
     		}
     		$formtemplate->param(rootpage => $rootpage);
    +		$formtemplate->param(templatepage => $params{newposttemplate}) if $params{newposttemplate};
     		$formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
     		$formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
     		if (exists $params{postformtext}) {
    diff --git a/templates/blogpost.tmpl b/templates/blogpost.tmpl
    index 7eeede6..5c8b34c 100644
    --- a/templates/blogpost.tmpl
    +++ b/templates/blogpost.tmpl
    @@ -8,6 +8,9 @@
     </TMPL_IF>
     <input type="hidden" name="do" value="blog" />
     <input type="hidden" name="from" value="<TMPL_VAR ROOTPAGE>" />
    +<TMPL_IF NAME="TEMPLATEPAGE">
    +<input type="hidden" name="templatepage" value="<TMPL_VAR TEMPLATEPAGE>" />
    +</TMPL_IF>
     <input type="hidden" name="subpage" value="1" />
     <TMPL_VAR POSTFORMTEXT>
     <input name="title" size="40" />

---

Perhaps I'm misunderstanding something, but can't you use already existing
in-house means instead of this patch; use a procedure as I do in the Hurd wiki?
<http://www.bddebian.com/~wiki/config_edittemplate/> with one template:
<http://www.bddebian.com/~wiki/config_edittemplate/regular_page/>.
-- [[tschwinge]]