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