responses and reorg
[ikiwiki.git] / doc / patchqueue / atomfeed.mdwn
1 diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/IkiWiki/Plugin/inline.pm ikiwiki--devo--1.0--patch-9/IkiWiki/Plugin/inline.pm
2 --- ikiwiki--upstream--1.0--patch-26/IkiWiki/Plugin/inline.pm   2006-09-17 16:08:18.969109484 -0400
3 +++ ikiwiki--devo--1.0--patch-9/IkiWiki/Plugin/inline.pm        2006-09-16 13:38:36.336193934 -0400
4 @@ -26,6 +26,7 @@
5  
6  my %toping;
7  my %rsslinks;
8 +my %atomlinks;
9  
10  sub yesno ($) { #{{{
11         my $val=shift;
12 @@ -41,6 +42,7 @@
13         my $raw=yesno($params{raw});
14         my $archive=yesno($params{archive});
15         my $rss=exists $params{rss} ? yesno($params{rss}) : 1;
16 +       my $atom=exists $params{atom} ? yesno($params{atom}) : 1;
17         if (! exists $params{show} && ! $archive) {
18                 $params{show}=10;
19         }
20 @@ -67,6 +69,7 @@
21         add_depends($params{page}, $params{pages});
22  
23         my $rssurl=rsspage(basename($params{page}));
24 +       my $atomurl=atompage(basename($params{page}));
25         my $ret="";
26  
27         if (exists $params{rootpage} && $config{cgiurl}) {
28 @@ -77,6 +80,9 @@
29                 if ($config{rss}) {
30                         $formtemplate->param(rssurl => $rssurl);
31                 }
32 +               if ($config{atom}) {
33 +                       $formtemplate->param(atomurl => $atomurl);
34 +               }
35                 $ret.=$formtemplate->output;
36         }
37         elsif ($config{rss} && $rss) {
38 @@ -85,6 +91,12 @@
39                 $linktemplate->param(rssurl => $rssurl);
40                 $ret.=$linktemplate->output;
41         }
42 +       elsif ($config{atom} && $atom) {
43 +               # Add a Atom link button.
44 +               my $linktemplate=template("atomlink.tmpl", blind_cache => 1);
45 +               $linktemplate->param(atomurl => $atomurl);
46 +               $ret.=$linktemplate->output;
47 +       }
48  
49         my $template=template(
50                 ($archive ? "inlinepagetitle.tmpl" : "inlinepage.tmpl"),
51 @@ -149,10 +161,16 @@
52         # only supports listing one file per page.
53         if ($config{rss} && $rss) {
54                 writefile(rsspage($params{page}), $config{destdir},
55 -                       genrss($desc, $params{page}, @list));
56 +                       genfeed("rss", $rssurl, $desc, $params{page}, @list));
57                 $toping{$params{page}}=1 unless $config{rebuild};
58                 $rsslinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
59         }
60 +       if ($config{atom} && $atom) {
61 +               writefile(atompage($params{page}), $config{destdir},
62 +                       genfeed("atom", $atomurl, $desc, $params{page}, @list));
63 +               $toping{$params{page}}=1 unless $config{rebuild};
64 +               $atomlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
65 +       }
66  
67         return $ret;
68  } #}}}
69 @@ -164,6 +182,8 @@
70  
71         $template->param(rsslink => $rsslinks{$page})
72                 if exists $rsslinks{$page} && $template->query(name => "rsslink");
73 +       $template->param(atomlink => $atomlinks{$page})
74 +               if exists $atomlinks{$page} && $template->query(name => "atomlink");
75  } #}}}
76  
77  sub get_inline_content ($$) { #{{{
78 @@ -195,6 +215,17 @@
79         return $ret;
80  } #}}}
81  
82 +sub date_3339 ($) { #{{{
83 +       my $time=shift;
84 +
85 +       eval q{use POSIX};
86 +       my $lc_time= POSIX::setlocale(&POSIX::LC_TIME);
87 +       POSIX::setlocale(&POSIX::LC_TIME, "C");
88 +       my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", localtime($time));
89 +       POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
90 +       return $ret;
91 +} #}}}
92 +
93  sub absolute_urls ($$) { #{{{
94         # sucky sub because rss sucks
95         my $content=shift;
96 @@ -213,15 +244,24 @@
97         return $page.".rss";
98  } #}}}
99  
100 -sub genrss ($$@) { #{{{
101 +sub atompage ($) { #{{{
102 +       my $page=shift;
103 +
104 +       return $page.".atom";
105 +} #}}}
106 +
107 +sub genfeed ($$$$@) { #{{{
108 +       my $feedtype=shift;
109 +       my $feedurl=shift;
110         my $desc=shift;
111         my $page=shift;
112         my @pages=@_;
113  
114         my $url=URI->new(encode_utf8($config{url}."/".htmlpage($page)));
115  
116 -       my $itemtemplate=template("rssitem.tmpl", blind_cache => 1);
117 +       my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
118         my $content="";
119 +       my $lasttime;
120         foreach my $p (@pages) {
121                 next unless exists $renderedfiles{$p};
122  
123 @@ -232,6 +272,7 @@
124                         url => $u,
125                         permalink => $u,
126                         pubdate => date_822($pagectime{$p}),
127 +                       atompubdate => date_3339($pagectime{$p}),
128                         content => absolute_urls(get_inline_content($p, $page), $url),
129                 );
130                 run_hooks(pagetemplate => sub {
131 @@ -241,15 +282,19 @@
132  
133                 $content.=$itemtemplate->output;
134                 $itemtemplate->clear_params;
135 +
136 +               $lasttime = $pagectime{$p};
137         }
138  
139 -       my $template=template("rsspage.tmpl", blind_cache => 1);
140 +       my $template=template($feedtype."page.tmpl", blind_cache => 1);
141         $template->param(
142                 title => $config{wikiname},
143                 wikiname => $config{wikiname},
144                 pageurl => $url,
145                 content => $content,
146                 rssdesc => $desc,
147 +               feeddate => date_3339($lasttime),
148 +               feedurl => $feedurl,
149         );
150         run_hooks(pagetemplate => sub {
151                 shift->(page => $page, destpage => $page,
152 diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atomitem.tmpl ikiwiki--devo--1.0--patch-9/templates/atomitem.tmpl
153 --- ikiwiki--upstream--1.0--patch-26/templates/atomitem.tmpl    1969-12-31 19:00:00.000000000 -0500
154 +++ ikiwiki--devo--1.0--patch-9/templates/atomitem.tmpl 2006-09-16 02:56:56.075533012 -0400
155 @@ -0,0 +1,20 @@
156 +<entry>
157 +       <title><TMPL_VAR TITLE ESCAPE=HTML></title>
158 +       <TMPL_IF NAME="AUTHOR">
159 +       <author><TMPL_VAR AUTHOR ESCAPE=HTML></author>
160 +       <TMPL_ELSE>
161 +       </TMPL_IF>
162 +       <id><TMPL_VAR URL></id>
163 +       <link href="<TMPL_VAR PERMALINK>"/>
164 +       <TMPL_IF NAME="CATEGORIES">
165 +       <TMPL_LOOP NAME="CATEGORIES">
166 +       <category><TMPL_VAR CATEGORY></category>
167 +       </TMPL_LOOP>
168 +       </TMPL_IF>
169 +       <updated><TMPL_VAR ATOMPUBDATE></updated>
170 +       <content type="xhtml" xml:lang="en">
171 +        <div xmlns="http://www.w3.org/1999/xhtml">
172 +        ![CDATA[<TMPL_VAR CONTENT>]]
173 +        </div>
174 +       </content>
175 +</entry>
176 diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atomlink.tmpl ikiwiki--devo--1.0--patch-9/templates/atomlink.tmpl
177 --- ikiwiki--upstream--1.0--patch-26/templates/atomlink.tmpl    1969-12-31 19:00:00.000000000 -0500
178 +++ ikiwiki--devo--1.0--patch-9/templates/atomlink.tmpl 2006-09-16 02:56:56.079533423 -0400
179 @@ -0,0 +1,5 @@
180 +<div id="atomlink">
181 +<TMPL_IF NAME="ATOMURL">
182 +<a class="atombutton" type="application/atom+xml" href="<TMPL_VAR NAME=ATOMURL>">Atom</a>
183 +</TMPL_IF>
184 +</div>
185 diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atompage.tmpl ikiwiki--devo--1.0--patch-9/templates/atompage.tmpl
186 --- ikiwiki--upstream--1.0--patch-26/templates/atompage.tmpl    1969-12-31 19:00:00.000000000 -0500
187 +++ ikiwiki--devo--1.0--patch-9/templates/atompage.tmpl 2006-09-16 02:56:56.079533423 -0400
188 @@ -0,0 +1,15 @@
189 +<?xml version="1.0" encoding="utf-8"?>
190 +
191 +<feed xmlns="http://www.w3.org/2005/Atom">
192 + <title><TMPL_VAR TITLE ESCAPE=HTML></title>
193 + <link href="<TMPL_VAR PAGEURL>"/>
194 + <link href="<TMPL_VAR FEEDURL>" rel="self"/>
195 + <author> 
196 +  <name>John Doe</name>
197 + </author> 
198 + <id><TMPL_VAR PAGEURL></id>
199 + <subtitle type="html"><TMPL_VAR RSSDESC ESCAPE=HTML></subtitle>
200 + <generator uri="http://ikiwiki.kitenet.net/" version="1.0">ikiwiki</generator>
201 + <updated><TMPL_VAR FEEDDATE></updated>
202 +<TMPL_VAR CONTENT>
203 +</feed>