summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/inline.pm
blob: cebd9037cc65c6095bca009c99663d2894223dd4 (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=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. }
  182. else {
  183. add_depends($params{page}, $params{pages}, presence => $quick);
  184. @list = pagespec_match_list(
  185. [ grep { $_ ne $params{page} } keys %pagesources ],
  186. $params{pages}, location => $params{page});
  187. if (exists $params{sort} && $params{sort} eq 'title') {
  188. @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
  189. }
  190. elsif (exists $params{sort} && $params{sort} eq 'title_natural') {
  191. eval q{use Sort::Naturally};
  192. if ($@) {
  193. error(gettext("Sort::Naturally needed for title_natural sort"));
  194. }
  195. @list=sort { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) } @list;
  196. }
  197. elsif (exists $params{sort} && $params{sort} eq 'mtime') {
  198. @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
  199. }
  200. elsif (! exists $params{sort} || $params{sort} eq 'age') {
  201. @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
  202. }
  203. else {
  204. error sprintf(gettext("unknown sort type %s"), $params{sort});
  205. }
  206. }
  207. if (yesno($params{reverse})) {
  208. @list=reverse(@list);
  209. }
  210. if (exists $params{skip}) {
  211. @list=@list[$params{skip} .. scalar @list - 1];
  212. }
  213. my @feedlist;
  214. if ($feeds) {
  215. if (exists $params{feedshow} &&
  216. $params{feedshow} && @list > $params{feedshow}) {
  217. @feedlist=@list[0..$params{feedshow} - 1];
  218. }
  219. else {
  220. @feedlist=@list;
  221. }
  222. }
  223. if ($params{show} && @list > $params{show}) {
  224. @list=@list[0..$params{show} - 1];
  225. }
  226. # Explicitly add all currently displayed pages as dependencies, so
  227. # that if they are removed, the inline will be sure to be updated.
  228. foreach my $p ($#list >= $#feedlist ? @list : @feedlist) {
  229. add_depends($params{page}, $p, presence => $quick);
  230. }
  231. if ($feeds && exists $params{feedpages}) {
  232. @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page});
  233. }
  234. my ($feedbase, $feednum);
  235. if ($feeds) {
  236. # Ensure that multiple feeds on a page go to unique files.
  237. # Feedfile can lead to conflicts if usedirs is not enabled,
  238. # so avoid supporting it in that case.
  239. delete $params{feedfile} if ! $config{usedirs};
  240. # Tight limits on legal feedfiles, to avoid security issues
  241. # and conflicts.
  242. if (defined $params{feedfile}) {
  243. if ($params{feedfile} =~ /\// ||
  244. $params{feedfile} !~ /$config{wiki_file_regexp}/) {
  245. error("illegal feedfile");
  246. }
  247. $params{feedfile}=possibly_foolish_untaint($params{feedfile});
  248. }
  249. $feedbase=targetpage($params{destpage}, "", $params{feedfile});
  250. my $feedid=join("\0", $feedbase, map { $_."\0".$params{$_} } sort keys %params);
  251. if (exists $knownfeeds{$feedid}) {
  252. $feednum=$knownfeeds{$feedid};
  253. }
  254. else {
  255. if (exists $page_numfeeds{$params{destpage}}{$feedbase}) {
  256. if ($feeds) {
  257. $feednum=$knownfeeds{$feedid}=++$page_numfeeds{$params{destpage}}{$feedbase};
  258. }
  259. }
  260. else {
  261. $feednum=$knownfeeds{$feedid}="";
  262. if ($feeds) {
  263. $page_numfeeds{$params{destpage}}{$feedbase}=1;
  264. }
  265. }
  266. }
  267. }
  268. my $rssurl=abs2rel($feedbase."rss".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $rss;
  269. my $atomurl=abs2rel($feedbase."atom".$feednum, dirname(htmlpage($params{destpage}))) if $feeds && $atom;
  270. my $ret="";
  271. if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
  272. (exists $params{postform} && yesno($params{postform}))) &&
  273. IkiWiki->can("cgi_editpage")) {
  274. # Add a blog post form, with feed buttons.
  275. my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
  276. $formtemplate->param(cgiurl => $config{cgiurl});
  277. $formtemplate->param(rootpage => rootpage(%params));
  278. $formtemplate->param(rssurl => $rssurl) if $feeds && $rss;
  279. $formtemplate->param(atomurl => $atomurl) if $feeds && $atom;
  280. if (exists $params{postformtext}) {
  281. $formtemplate->param(postformtext =>
  282. $params{postformtext});
  283. }
  284. else {
  285. $formtemplate->param(postformtext =>
  286. gettext("Add a new post titled:"));
  287. }
  288. $ret.=$formtemplate->output;
  289. # The post form includes the feed buttons, so
  290. # emptyfeeds cannot be hidden.
  291. $emptyfeeds=1;
  292. }
  293. elsif ($feeds && !$params{preview} && ($emptyfeeds || @feedlist)) {
  294. # Add feed buttons.
  295. my $linktemplate=template("feedlink.tmpl", blind_cache => 1);
  296. $linktemplate->param(rssurl => $rssurl) if $rss;
  297. $linktemplate->param(atomurl => $atomurl) if $atom;
  298. $ret.=$linktemplate->output;
  299. }
  300. if (! $feedonly) {
  301. require HTML::Template;
  302. my @params=IkiWiki::template_params($params{template}.".tmpl", blind_cache => 1);
  303. if (! @params) {
  304. error sprintf(gettext("nonexistant template %s"), $params{template});
  305. }
  306. my $template=HTML::Template->new(@params) unless $raw;
  307. foreach my $page (@list) {
  308. my $file = $pagesources{$page};
  309. my $type = pagetype($file);
  310. if (! $raw || ($raw && ! defined $type)) {
  311. unless ($archive && $quick) {
  312. # Get the content before populating the
  313. # template, since getting the content uses
  314. # the same template if inlines are nested.
  315. my $content=get_inline_content($page, $params{destpage});
  316. $template->param(content => $content);
  317. }
  318. $template->param(pageurl => urlto($page, $params{destpage}));
  319. $template->param(inlinepage => $page);
  320. $template->param(title => pagetitle(basename($page)));
  321. $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}));
  322. $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
  323. $template->param(first => 1) if $page eq $list[0];
  324. $template->param(last => 1) if $page eq $list[$#list];
  325. if ($actions) {
  326. my $file = $pagesources{$page};
  327. my $type = pagetype($file);
  328. if ($config{discussion}) {
  329. if ($page !~ /.*\/\Q$config{discussionpage}\E$/ &&
  330. (length $config{cgiurl} ||
  331. exists $links{$page."/".$config{discussionpage}})) {
  332. $template->param(have_actions => 1);
  333. $template->param(discussionlink =>
  334. htmllink($page,
  335. $params{destpage},
  336. $config{discussionpage},
  337. noimageinline => 1,
  338. forcesubpage => 1));
  339. }
  340. }
  341. if (length $config{cgiurl} && defined $type) {
  342. $template->param(have_actions => 1);
  343. $template->param(editurl => cgiurl(do => "edit", page => $page));
  344. }
  345. }
  346. run_hooks(pagetemplate => sub {
  347. shift->(page => $page, destpage => $params{destpage},
  348. template => $template,);
  349. });
  350. $ret.=$template->output;
  351. $template->clear_params;
  352. }
  353. else {
  354. if (defined $type) {
  355. $ret.="\n".
  356. linkify($page, $params{destpage},
  357. preprocess($page, $params{destpage},
  358. filter($page, $params{destpage},
  359. readfile(srcfile($file)))));
  360. }
  361. }
  362. }
  363. }
  364. if ($feeds && ($emptyfeeds || @feedlist)) {
  365. if ($rss) {
  366. my $rssp=$feedbase."rss".$feednum;
  367. will_render($params{destpage}, $rssp);
  368. if (! $params{preview}) {
  369. writefile($rssp, $config{destdir},
  370. genfeed("rss",
  371. $config{url}."/".$rssp, $desc, $params{guid}, $params{destpage}, @feedlist));
  372. $toping{$params{destpage}}=1 unless $config{rebuild};
  373. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/rss+xml" title="$desc (RSS)" href="$rssurl" />};
  374. }
  375. }
  376. if ($atom) {
  377. my $atomp=$feedbase."atom".$feednum;
  378. will_render($params{destpage}, $atomp);
  379. if (! $params{preview}) {
  380. writefile($atomp, $config{destdir},
  381. genfeed("atom", $config{url}."/".$atomp, $desc, $params{guid}, $params{destpage}, @feedlist));
  382. $toping{$params{destpage}}=1 unless $config{rebuild};
  383. $feedlinks{$params{destpage}}.=qq{<link rel="alternate" type="application/atom+xml" title="$desc (Atom)" href="$atomurl" />};
  384. }
  385. }
  386. }
  387. return $ret if $raw || $nested;
  388. push @inline, $ret;
  389. return "<div class=\"inline\" id=\"$#inline\"></div>\n\n";
  390. }
  391. sub pagetemplate_inline (@) {
  392. my %params=@_;
  393. my $page=$params{page};
  394. my $template=$params{template};
  395. $template->param(feedlinks => $feedlinks{$page})
  396. if exists $feedlinks{$page} && $template->query(name => "feedlinks");
  397. }
  398. sub get_inline_content ($$) {
  399. my $page=shift;
  400. my $destpage=shift;
  401. my $file=$pagesources{$page};
  402. my $type=pagetype($file);
  403. if (defined $type) {
  404. $nested++;
  405. my $ret=htmlize($page, $destpage, $type,
  406. linkify($page, $destpage,
  407. preprocess($page, $destpage,
  408. filter($page, $destpage,
  409. readfile(srcfile($file))))));
  410. $nested--;
  411. return $ret;
  412. }
  413. else {
  414. return "";
  415. }
  416. }
  417. sub date_822 ($) {
  418. my $time=shift;
  419. my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
  420. POSIX::setlocale(&POSIX::LC_TIME, "C");
  421. my $ret=POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
  422. POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
  423. return $ret;
  424. }
  425. sub date_3339 ($) {
  426. my $time=shift;
  427. my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
  428. POSIX::setlocale(&POSIX::LC_TIME, "C");
  429. my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time));
  430. POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
  431. return $ret;
  432. }
  433. sub absolute_urls ($$) {
  434. # sucky sub because rss sucks
  435. my $content=shift;
  436. my $baseurl=shift;
  437. my $url=$baseurl;
  438. $url=~s/[^\/]+$//;
  439. # what is the non path part of the url?
  440. my $top_uri = URI->new($url);
  441. $top_uri->path_query(""); # reset the path
  442. my $urltop = $top_uri->as_string;
  443. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(#[^"]+)"/$1 href="$baseurl$2"/mig;
  444. # relative to another wiki page
  445. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^\/][^"]*)"/$1 href="$url$2"/mig;
  446. $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)([^\/][^"]*)"/$1 src="$url$2"/mig;
  447. # relative to the top of the site
  448. $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)(\/[^"]*)"/$1 href="$urltop$2"/mig;
  449. $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)(\/[^"]*)"/$1 src="$urltop$2"/mig;
  450. return $content;
  451. }
  452. sub genfeed ($$$$$@) {
  453. my $feedtype=shift;
  454. my $feedurl=shift;
  455. my $feeddesc=shift;
  456. my $guid=shift;
  457. my $page=shift;
  458. my @pages=@_;
  459. my $url=URI->new(encode_utf8(urlto($page,"",1)));
  460. my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
  461. my $content="";
  462. my $lasttime = 0;
  463. foreach my $p (@pages) {
  464. my $u=URI->new(encode_utf8(urlto($p, "", 1)));
  465. my $pcontent = absolute_urls(get_inline_content($p, $page), $url);
  466. $itemtemplate->param(
  467. title => pagetitle(basename($p)),
  468. url => $u,
  469. permalink => $u,
  470. cdate_822 => date_822($pagectime{$p}),
  471. mdate_822 => date_822($pagemtime{$p}),
  472. cdate_3339 => date_3339($pagectime{$p}),
  473. mdate_3339 => date_3339($pagemtime{$p}),
  474. );
  475. if (exists $pagestate{$p}) {
  476. if (exists $pagestate{$p}{meta}{guid}) {
  477. $itemtemplate->param(guid => $pagestate{$p}{meta}{guid});
  478. }
  479. if (exists $pagestate{$p}{meta}{updated}) {
  480. $itemtemplate->param(mdate_822 => date_822($pagestate{$p}{meta}{updated}));
  481. $itemtemplate->param(mdate_3339 => date_3339($pagestate{$p}{meta}{updated}));
  482. }
  483. }
  484. if ($itemtemplate->query(name => "enclosure")) {
  485. my $file=$pagesources{$p};
  486. my $type=pagetype($file);
  487. if (defined $type) {
  488. $itemtemplate->param(content => $pcontent);
  489. }
  490. else {
  491. my $size=(srcfile_stat($file))[8];
  492. my $mime="unknown";
  493. eval q{use File::MimeInfo};
  494. if (! $@) {
  495. $mime = mimetype($file);
  496. }
  497. $itemtemplate->param(
  498. enclosure => $u,
  499. type => $mime,
  500. length => $size,
  501. );
  502. }
  503. }
  504. else {
  505. $itemtemplate->param(content => $pcontent);
  506. }
  507. run_hooks(pagetemplate => sub {
  508. shift->(page => $p, destpage => $page,
  509. template => $itemtemplate);
  510. });
  511. $content.=$itemtemplate->output;
  512. $itemtemplate->clear_params;
  513. $lasttime = $pagemtime{$p} if $pagemtime{$p} > $lasttime;
  514. }
  515. my $template=template($feedtype."page.tmpl", blind_cache => 1);
  516. $template->param(
  517. title => $page ne "index" ? pagetitle($page) : $config{wikiname},
  518. wikiname => $config{wikiname},
  519. pageurl => $url,
  520. content => $content,
  521. feeddesc => $feeddesc,
  522. guid => $guid,
  523. feeddate => date_3339($lasttime),
  524. feedurl => $feedurl,
  525. version => $IkiWiki::version,
  526. );
  527. run_hooks(pagetemplate => sub {
  528. shift->(page => $page, destpage => $page,
  529. template => $template);
  530. });
  531. return $template->output;
  532. }
  533. sub pingurl (@) {
  534. return unless @{$config{pingurl}} && %toping;
  535. eval q{require RPC::XML::Client};
  536. if ($@) {
  537. debug(gettext("RPC::XML::Client not found, not pinging"));
  538. return;
  539. }
  540. # daemonize here so slow pings don't slow down wiki updates
  541. defined(my $pid = fork) or error("Can't fork: $!");
  542. return if $pid;
  543. chdir '/';
  544. POSIX::setsid() or error("Can't start a new session: $!");
  545. open STDIN, '/dev/null';
  546. open STDOUT, '>/dev/null';
  547. open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
  548. # Don't need to keep a lock on the wiki as a daemon.
  549. IkiWiki::unlockwiki();
  550. foreach my $page (keys %toping) {
  551. my $title=pagetitle(basename($page), 0);
  552. my $url=urlto($page, "", 1);
  553. foreach my $pingurl (@{$config{pingurl}}) {
  554. debug("Pinging $pingurl for $page");
  555. eval {
  556. my $client = RPC::XML::Client->new($pingurl);
  557. my $req = RPC::XML::request->new('weblogUpdates.ping',
  558. $title, $url);
  559. my $res = $client->send_request($req);
  560. if (! ref $res) {
  561. error("Did not receive response to ping");
  562. }
  563. my $r=$res->value;
  564. if (! exists $r->{flerror} || $r->{flerror}) {
  565. error("Ping rejected: ".(exists $r->{message} ? $r->{message} : "[unknown reason]"));
  566. }
  567. };
  568. if ($@) {
  569. error "Ping failed: $@";
  570. }
  571. }
  572. }
  573. exit 0; # daemon done
  574. }
  575. sub rootpage (@) {
  576. my %params=@_;
  577. my $rootpage;
  578. if (exists $params{rootpage}) {
  579. $rootpage=bestlink($params{page}, $params{rootpage});
  580. if (!length $rootpage) {
  581. $rootpage=$params{rootpage};
  582. }
  583. }
  584. else {
  585. $rootpage=$params{page};
  586. }
  587. return $rootpage;
  588. }
  589. 1