summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/inline.pm
blob: 7c5da7343907d9d0f41ed65e2573942e3b6cbb9b (plain)
  1. #!/usr/bin/perl
  2. # Page inlining and blogging.
  3. package IkiWiki::Plugin::inline;
  4. use warnings;
  5. use strict;
  6. use Encode;
  7. use IkiWiki 3.00;
  8. use URI;
  9. my %knownfeeds;
  10. my %page_numfeeds;
  11. my @inline;
  12. my $nested=0;
  13. sub import {
  14. hook(type => "getopt", id => "inline", call => \&getopt);
  15. hook(type => "getsetup", id => "inline", call => \&getsetup);
  16. hook(type => "checkconfig", id => "inline", call => \&checkconfig);
  17. hook(type => "sessioncgi", id => "inline", call => \&sessioncgi);
  18. hook(type => "preprocess", id => "inline",
  19. call => \&IkiWiki::preprocess_inline);
  20. hook(type => "pagetemplate", id => "inline",
  21. call => \&IkiWiki::pagetemplate_inline);
  22. hook(type => "format", id => "inline", call => \&format, first => 1);
  23. # Hook to change to do pinging since it's called late.
  24. # This ensures each page only pings once and prevents slow
  25. # pings interrupting page builds.
  26. hook(type => "change", id => "inline", call => \&IkiWiki::pingurl);
  27. }
  28. sub getopt () {
  29. eval q{use Getopt::Long};
  30. error($@) if $@;
  31. Getopt::Long::Configure('pass_through');
  32. GetOptions(
  33. "rss!" => \$config{rss},
  34. "atom!" => \$config{atom},
  35. "allowrss!" => \$config{allowrss},
  36. "allowatom!" => \$config{allowatom},
  37. "pingurl=s" => sub {
  38. push @{$config{pingurl}}, $_[1];
  39. },
  40. );
  41. }
  42. sub getsetup () {
  43. return
  44. plugin => {
  45. safe => 1,
  46. rebuild => undef,
  47. section => "core",
  48. },
  49. rss => {
  50. type => "boolean",
  51. example => 0,
  52. description => "enable rss feeds by default?",
  53. safe => 1,
  54. rebuild => 1,
  55. },
  56. atom => {
  57. type => "boolean",
  58. example => 0,
  59. description => "enable atom feeds by default?",
  60. safe => 1,
  61. rebuild => 1,
  62. },
  63. allowrss => {
  64. type => "boolean",
  65. example => 0,
  66. description => "allow rss feeds to be used?",
  67. safe => 1,
  68. rebuild => 1,
  69. },
  70. allowatom => {
  71. type => "boolean",
  72. example => 0,
  73. description => "allow atom feeds to be used?",
  74. safe => 1,
  75. rebuild => 1,
  76. },
  77. pingurl => {
  78. type => "string",
  79. example => "http://rpc.technorati.com/rpc/ping",
  80. description => "urls to ping (using XML-RPC) on feed update",
  81. safe => 1,
  82. rebuild => 0,
  83. },
  84. }
  85. sub checkconfig () {
  86. if (($config{rss} || $config{atom}) && ! length $config{url}) {
  87. error(gettext("Must specify url to wiki with --url when using --rss or --atom"));
  88. }
  89. if ($config{rss}) {
  90. push @{$config{wiki_file_prune_regexps}}, qr/\.rss$/;
  91. }
  92. if ($config{atom}) {
  93. push @{$config{wiki_file_prune_regexps}}, qr/\.atom$/;
  94. }
  95. if (! exists $config{pingurl}) {
  96. $config{pingurl}=[];
  97. }
  98. }
  99. sub format (@) {
  100. my %params=@_;
  101. # Fill in the inline content generated earlier. This is actually an
  102. # optimisation.
  103. $params{content}=~s{<div class="inline" id="([^"]+)"></div>}{
  104. delete @inline[$1,]
  105. }eg;
  106. return $params{content};
  107. }
  108. sub sessioncgi ($$) {
  109. my $q=shift;
  110. my $session=shift;
  111. if ($q->param('do') eq 'blog') {
  112. my $page=titlepage(decode_utf8($q->param('title')));
  113. $page=~s/(\/)/"__".ord($1)."__"/eg; # don't create subdirs
  114. # if the page already exists, munge it to be unique
  115. my $from=$q->param('from');
  116. my $add="";
  117. while (exists $IkiWiki::pagecase{lc($from."/".$page.$add)}) {
  118. $add=1 unless length $add;
  119. $add++;
  120. }
  121. $q->param('page', "/$from/$page$add");
  122. # now go create the page
  123. $q->param('do', 'create');
  124. # make sure the editpage plugin is loaded
  125. if (IkiWiki->can("cgi_editpage")) {
  126. IkiWiki::cgi_editpage($q, $session);
  127. }
  128. else {
  129. error(gettext("page editing not allowed"));
  130. }
  131. exit;
  132. }
  133. }
  134. # Back to ikiwiki namespace for the rest, this code is very much
  135. # internal to ikiwiki even though it's separated into a plugin.
  136. package IkiWiki;
  137. my %toping;
  138. my %feedlinks;
  139. sub preprocess_inline (@) {
  140. my %params=@_;
  141. if (! exists $params{pages} && ! exists $params{pagenames}) {
  142. error gettext("missing pages parameter");
  143. }
  144. my $raw=yesno($params{raw});
  145. my $archive=yesno($params{archive});
  146. my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss};
  147. my $atom=(($config{atom} || $config{allowatom}) && exists $params{atom}) ? yesno($params{atom}) : $config{atom};
  148. my $quick=exists $params{quick} ? yesno($params{quick}) : 0;
  149. my $feeds=exists $params{feeds} ? yesno($params{feeds}) : !$quick && ! $raw;
  150. my $emptyfeeds=exists $params{emptyfeeds} ? yesno($params{emptyfeeds}) : 1;
  151. my $feedonly=yesno($params{feedonly});
  152. if (! exists $params{show} && ! $archive) {
  153. $params{show}=10;
  154. }
  155. if (! exists $params{feedshow} && exists $params{show}) {
  156. $params{feedshow}=$params{show};
  157. }
  158. my $desc;
  159. if (exists $params{description}) {
  160. $desc = $params{description}
  161. }
  162. else {
  163. $desc = $config{wikiname};
  164. }
  165. my $actions=yesno($params{actions});
  166. if (exists $params{template}) {
  167. $params{template}=~s/[^-_a-zA-Z0-9]+//g;
  168. }
  169. else {
  170. $params{template} = $archive ? "archivepage" : "inlinepage";
  171. }
  172. my @list;
  173. if (exists $params{pagenames}) {
  174. foreach my $p (qw(sort pages)) {
  175. if (exists $params{$p}) {
  176. error sprintf(gettext("the %s and %s parameters cannot be used together"),
  177. "pagenames", $p);
  178. }
  179. }
  180. @list = map { bestlink($params{page}, $_) }
  181. split ' ', $params{pagenames};
  182. if (yesno($params{reverse})) {
  183. @list=reverse(@list);
  184. }
  185. foreach my $p (@list) {
  186. add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
  187. }
  188. }
  189. else {
  190. my $num=0;
  191. if ($params{show}) {
  192. $num=$params{show};
  193. }
  194. if ($params{feedshow} && $num < $params{feedshow} && $num > 0) {
  195. $num=$params{feedshow};
  196. }
  197. if ($params{skip} && $num) {
  198. $num+=$params{skip};
  199. }
  200. @list = pagespec_match_list($params{page}, $params{pages},
  201. deptype => deptype($quick ? "presence" : "content"),
  202. filter => sub { $_[0] eq $params{page} },
  203. sort => exists $params{sort} ? $params{sort} : "age",
  204. reverse => yesno($params{reverse}),
  205. ($num ? (num => $num) : ()),
  206. );
  207. }
  208. if (exists $params{skip}) {
  209. @list=@list[$params{skip} .. $#list];
  210. }
  211. my @feedlist;
  212. if ($feeds) {
  213. if (exists $params{feedshow} &&
  214. $params{feedshow} && @list > $params{feedshow}) {
  215. @feedlist=@list[0..$params{feedshow} - 1];
  216. }
  217. else {
  218. @feedlist=@list;
  219. }
  220. }
  221. if ($params{show} && @list > $params{show}) {
  222. @list=@list[0..$params{show} - 1];
  223. }
  224. if ($feeds && exists $params{feedpages}) {
  225. @feedlist = pagespec_match_list(
  226. $params{page}, "($params{pages}) and ($params{feedpages})",
  227. deptype => deptype($quick ? "presence" : "content"),
  228. list => \@feedlist,
  229. );
  230. }
  231. my ($feedbase, $feednum);
  232. if ($feeds) {
  233. # Ensure that multiple feeds on a page go to unique files.
  234. # Feedfile can lead to conflicts if usedirs is not enabled,
  235. # so avoid supporting it in that case.
  236. delete $params{feedfile} if ! $config{usedirs};
  237. # Tight limits on legal feedfiles, to avoid security issues
  238. # and conflicts.
  239. if (defined $params{feedfile}) {
  240. if ($params{feedfile} =~ /\// ||
  241. $params{feedfile} !~ /$config{wiki_file_regexp}/) {
  242. error("illegal feedfile");
  243. }
  244. $params{feedfile}=possibly_foolish_untaint($params{feedfile});
  245. }
  246. $feedbase=targetpage($params{page}, "", $params{feedfile});
  247. my $feedid=join("\0", $feedbase, map { $_."\0".$params{$_} } sort keys %params);
  248. if (exists $knownfeeds{$feedid}) {
  249. $feednum=$knownfeeds{$feedid};
  250. }
  251. else {
  252. if (exists $page_numfeeds{$params{destpage}}{$feedbase}) {
  253. if ($feeds) {
  254. $feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}}{$feedbase};
  255. }
  256. }
  257. else {
  258. $feednum=$knownfeeds{$feedid}="";
  259. if ($feeds) {
  260. $page_numfeeds{$params{destpage}}{$feedbase}=1;
  261. }
  262. }
  263. }
  264. }
  265. my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
  266. my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
  267. my $ret="";
  268. if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
  269. (exists $params{postform} && yesno($params{postform}))) &&
  270. IkiWiki->can("cgi_editpage")) {
  271. # Add a blog post form, with feed buttons.
  272. my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
  273. $formtemplate->param(cgiurl => IkiWiki::cgiurl());
  274. $formtemplate->param(rootpage => rootpage(%params));
  275. $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
  276. $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
  277. if (exists $params{postformtext}) {
  278. $formtemplate->param(postformtext =>
  279. $params{postformtext});
  280. }
  281. else {
  282. $formtemplate->param(postformtext =>
  283. gettext("Add a new post titled:"));
  284. }
  285. $ret.=$formtemplate->output;
  286. # The post form includes the feed buttons, so
  287. # emptyfeeds cannot be hidden.
  288. $emptyfeeds=1;
  289. }
  290. elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
  291. # Add feed buttons.
  292. my $linktemplate=template_depends("feedlink.tmpl", $params{page}, blind_cache => 1);
  293. $linktemplate->param(rssurl => $rssurl) if $rss;
  294. $linktemplate->param(atomurl => $atomurl) if $atom;
  295. $ret.=$linktemplate->output;
  296. }
  297. if (! $feedonly) {
  298. my $template;
  299. if (! $raw) {
  300. # cannot use wiki pages as templates; template not sanitized due to
  301. # format hook hack
  302. eval {
  303. $template=template_depends($params{template}.".tmpl", $params{page},
  304. blind_cache => 1);
  305. };
  306. if ($@) {
  307. error sprintf(gettext("failed to process template %s"), $params{template}.".tmpl").": $@";
  308. }
  309. }
  310. my $needcontent=$raw || (!($archive && $quick) && $template->query(name => 'content'));
  311. foreach my $page (@list) {
  312. my $file = $pagesources{$page};
  313. my $type = pagetype($file);
  314. if (! $raw) {
  315. if ($needcontent) {
  316. # Get the content before populating the
  317. # template, since getting the content uses
  318. # the same template if inlines are nested.
  319. my $content=get_inline_content($page, $params{destpage});
  320. $template->param(content => $content);
  321. }
  322. $template->param(pageurl => urlto($page, $params{destpage}));
  323. $template->param(inlinepage => $page);
  324. $template->param(title => pagetitle(basename($page)));
  325. $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}, 1));
  326. $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
  327. $template->param(first => 1) if $page eq $list[0];
  328. $template->param(last => 1) if $page eq $list[$#list];
  329. $template->param(html5 => $config{html5});
  330. if ($actions) {
  331. my $file = $pagesources{$page};
  332. my $type = pagetype($file);
  333. if ($config{discussion}) {
  334. if ($page !~ /.*\/\Q$config{discussionpage}\E$/i &&
  335. (length $config{cgiurl} ||
  336. exists $pagesources{$page."/".lc($config{discussionpage})})) {
  337. $template->param(have_actions => 1);
  338. $template->param(discussionlink =>
  339. htmllink($page,
  340. $params{destpage},
  341. $config{discussionpage},
  342. noimageinline => 1,
  343. forcesubpage => 1));
  344. }
  345. }
  346. if (length $config{cgiurl} &&
  347. defined $type &&
  348. IkiWiki->can("cgi_editpage")) {
  349. $template->param(have_actions => 1);
  350. $template->param(editurl => cgiurl(do => "edit", page => $page));
  351. }
  352. }
  353. run_hooks(pagetemplate => sub {
  354. shift->(page => $page, destpage => $params{destpage},
  355. template => $template,);
  356. });
  357. $ret.=$template->output;
  358. $template->clear_params;
  359. }
  360. else {
  361. if (defined $type) {
  362. $ret.="\n".
  363. linkify($page, $params{destpage},
  364. preprocess($page, $params{destpage},
  365. filter($page, $params{destpage},
  366. readfile(srcfile($file)))));
  367. }
  368. else {
  369. $ret.="\n".
  370. readfile(srcfile($file));
  371. }
  372. }
  373. }
  374. }
  375. if ($feeds && ($emptyfeeds || @feedlist)) {
  376. if ($rss) {
  377. my $rssp=$feedbase."rss".$feednum;
  378. will_render($params{destpage}, $rssp);
  379. if (! $params{preview}) {
  380. writefile($rssp, $config{destdir},
  381. genfeed("rss",
  382. $config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist));
  383. $toping{$params{destpage}}=1 unless $config{rebuild};
  384. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$desc (RSS)" href="$rssurl" />};
  385. }
  386. }
  387. if ($atom) {
  388. my $atomp=$feedbase."atom".$feednum;
  389. will_render($params{destpage}, $atomp);
  390. if (! $params{preview}) {
  391. writefile($atomp, $config{destdir},
  392. genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist));
  393. $toping{$params{destpage}}=1 unless $config{rebuild};
  394. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$desc (Atom)" href="$atomurl" />};
  395. }
  396. }
  397. }
  398. clear_inline_content_cache();
  399. return $ret if $raw || $nested;
  400. push @inline, $ret;
  401. return "<div class=\"inline\" id=\"$#inline\"></div>\n\n";
  402. }
  403. sub pagetemplate_inline (@) {
  404. my %params=@_;
  405. my $page=$params{page};
  406. my $template=$params{template};
  407. $template->param(feedlinks => $feedlinks{$page})
  408. if exists $feedlinks{$page} && $template->query(name => "feedlinks");
  409. }
  410. {
  411. my %inline_content;
  412. my $cached_destpage="";
  413. sub get_inline_content ($$) {
  414. my $page=shift;
  415. my $destpage=shift;
  416. if (exists $inline_content{$page} && $cached_destpage eq $destpage) {
  417. return $inline_content{$page};
  418. }
  419. my $file=$pagesources{$page};
  420. my $type=pagetype($file);
  421. my $ret="";
  422. if (defined $type) {
  423. $nested++;
  424. $ret=htmlize($page, $destpage, $type,
  425. linkify($page, $destpage,
  426. preprocess($page, $destpage,
  427. filter($page, $destpage,
  428. readfile(srcfile($file))))));
  429. $nested--;
  430. if (isinternal($page)) {
  431. # make inlined text of internal pages searchable
  432. run_hooks(indexhtml => sub {
  433. shift->(page => $page, destpage => $page,
  434. content => $ret);
  435. });
  436. }
  437. }
  438. if ($cached_destpage ne $destpage) {
  439. clear_inline_content_cache();
  440. $cached_destpage=$destpage;
  441. }
  442. return $inline_content{$page}=$ret;
  443. }
  444. sub clear_inline_content_cache () {
  445. %inline_content=();
  446. }
  447. }
  448. sub date_822 ($) {
  449. my $time=shift;
  450. my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
  451. POSIX::setlocale(&POSIX::LC_TIME, "C");
  452. my $ret=POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
  453. POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
  454. return $ret;
  455. }
  456. sub absolute_urls ($$) {
  457. # needed because rss sucks
  458. my $html=shift;
  459. my $baseurl=shift;
  460. my $url=$baseurl;
  461. $url=~s/[^\/]+$//;
  462. my $urltop; # calculated if needed
  463. my $ret="";
  464. eval q{use HTML::Parser; use HTML::Tagset};
  465. die $@ if $@;
  466. my $p = HTML::Parser->new(api_version => 3);
  467. $p->handler(default => sub { $ret.=join("", @_) }, "text");
  468. $p->handler(start => sub {
  469. my ($tagname, $pos, $text) = @_;
  470. if (ref $HTML::Tagset::linkElements{$tagname}) {
  471. while (4 <= @$pos) {
  472. # use attribute sets from right to left
  473. # to avoid invalidating the offsets
  474. # when replacing the values
  475. my ($k_offset, $k_len, $v_offset, $v_len) =
  476. splice(@$pos, -4);
  477. my $attrname = lc(substr($text, $k_offset, $k_len));
  478. next unless grep { $_ eq $attrname } @{$HTML::Tagset::linkElements{$tagname}};
  479. next unless $v_offset; # 0 v_offset means no value
  480. my $v = substr($text, $v_offset, $v_len);
  481. $v =~ s/^([\'\"])(.*)\1$/$2/;
  482. if ($v=~/^#/) {
  483. $v=$baseurl.$v; # anchor
  484. }
  485. elsif ($v=~/^(?!\w+:)[^\/]/) {
  486. $v=$url.$v; # relative url
  487. }
  488. elsif ($v=~/^\//) {
  489. if (! defined $urltop) {
  490. # what is the non path part of the url?
  491. my $top_uri = URI->new($url);
  492. $top_uri->path_query(""); # reset the path
  493. $urltop = $top_uri->as_string;
  494. }
  495. $v=$urltop.$v; # url relative to top of site
  496. }
  497. $v =~ s/\"/&quot;/g; # since we quote with ""
  498. substr($text, $v_offset, $v_len) = qq("$v");
  499. }
  500. }
  501. $ret.=$text;
  502. }, "tagname, tokenpos, text");
  503. $p->parse($html);
  504. $p->eof;
  505. return $ret;
  506. }
  507. sub genfeed ($$$$$@) {
  508. my $feedtype=shift;
  509. my $feedurl=shift;
  510. my $feeddesc=shift;
  511. my $guid=shift;
  512. my $page=shift;
  513. my @pages=@_;
  514. my $url=URI->new(encode_utf8(urlto($page,"",1)));
  515. my $itemtemplate=template_depends($feedtype."item.tmpl", $page, blind_cache => 1);
  516. my $content="";
  517. my $lasttime = 0;
  518. foreach my $p (@pages) {
  519. my $u=URI->new(encode_utf8(urlto($p, "", 1)));
  520. my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
  521. $itemtemplate->param(
  522. title => pagetitle(basename($p)),
  523. url => $u,
  524. permalink => $u,
  525. cdate_822 => date_822($pagectime{$p}),
  526. mdate_822 => date_822($pagemtime{$p}),
  527. cdate_3339 => date_3339($pagectime{$p}),
  528. mdate_3339 => date_3339($pagemtime{$p}),
  529. );
  530. if (exists $pagestate{$p}) {
  531. if (exists $pagestate{$p}{meta}{guid}) {
  532. eval q{use HTML::Entities};
  533. $itemtemplate->param(guid => HTML::Entities::encode_numeric($pagestate{$p}{meta}{guid}));
  534. }
  535. if (exists $pagestate{$p}{meta}{updated}) {
  536. $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
  537. $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
  538. }
  539. }
  540. if ($itemtemplate->query(name => "enclosure")) {
  541. my $file=$pagesources{$p};
  542. my $type=pagetype($file);
  543. if (defined $type) {
  544. $itemtemplate->param(content => $pcontent);
  545. }
  546. else {
  547. my $size=(srcfile_stat($file))[8];
  548. my $mime="unknown";
  549. eval q{use File::MimeInfo};
  550. if (! $@) {
  551. $mime = mimetype($file);
  552. }
  553. $itemtemplate->param(
  554. enclosure => $u,
  555. type => $mime,
  556. length => $size,
  557. );
  558. }
  559. }
  560. else {
  561. $itemtemplate->param(content => $pcontent);
  562. }
  563. run_hooks(pagetemplate => sub {
  564. shift->(page => $p, destpage => $page,
  565. template => $itemtemplate);
  566. });
  567. $content.=$itemtemplate->output;
  568. $itemtemplate->clear_params;
  569. $lasttime = $pagemtime{$p} if $pagemtime{$p} > $lasttime;
  570. }
  571. my $template=template_depends($feedtype."page.tmpl", $page, blind_cache => 1);
  572. $template->param(
  573. title => $page ne "index" ? pagetitle($page) : $config{wikiname},
  574. wikiname => $config{wikiname},
  575. pageurl => $url,
  576. content => $content,
  577. feeddesc => $feeddesc,
  578. guid => $guid,
  579. feeddate => date_3339($lasttime),
  580. feedurl => $feedurl,
  581. version => $IkiWiki::version,
  582. );
  583. run_hooks(pagetemplate => sub {
  584. shift->(page => $page, destpage => $page,
  585. template => $template);
  586. });
  587. return $template->output;
  588. }
  589. sub pingurl (@) {
  590. return unless @{$config{pingurl}} && %toping;
  591. eval q{require RPC::XML::Client};
  592. if ($@) {
  593. debug(gettext("RPC::XML::Client not found, not pinging"));
  594. return;
  595. }
  596. # daemonize here so slow pings don't slow down wiki updates
  597. defined(my $pid = fork) or error("Can't fork: $!");
  598. return if $pid;
  599. chdir '/';
  600. POSIX::setsid() or error("Can't start a new session: $!");
  601. open STDIN, '/dev/null';
  602. open STDOUT, '>/dev/null';
  603. open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
  604. # Don't need to keep a lock on the wiki as a daemon.
  605. IkiWiki::unlockwiki();
  606. foreach my $page (keys %toping) {
  607. my $title=pagetitle(basename($page), 0);
  608. my $url=urlto($page, "", 1);
  609. foreach my $pingurl (@{$config{pingurl}}) {
  610. debug("Pinging $pingurl for $page");
  611. eval {
  612. my $client = RPC::XML::Client->new($pingurl);
  613. my $req = RPC::XML::request->new('weblogUpdates.ping',
  614. $title, $url);
  615. my $res = $client->send_request($req);
  616. if (! ref $res) {
  617. error("Did not receive response to ping");
  618. }
  619. my $r=$res->value;
  620. if (! exists $r->{flerror} || $r->{flerror}) {
  621. error("Ping rejected: ".(exists $r->{message} ? $r->{message} : "[unknown reason]"));
  622. }
  623. };
  624. if ($@) {
  625. error "Ping failed: $@";
  626. }
  627. }
  628. }
  629. exit 0; # daemon done
  630. }
  631. sub rootpage (@) {
  632. my %params=@_;
  633. my $rootpage;
  634. if (exists $params{rootpage}) {
  635. $rootpage=bestlink($params{page}, $params{rootpage});
  636. if (!length $rootpage) {
  637. $rootpage=$params{rootpage};
  638. }
  639. }
  640. else {
  641. $rootpage=$params{page};
  642. }
  643. return $rootpage;
  644. }
  645. 1