summaryrefslogtreecommitdiff
path: root/IkiWiki/CGI.pm
blob: c2dacf78d46253a74015cd67155bbb33fc34ad70 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use IkiWiki;
  5. use IkiWiki::UserInfo;
  6. use open qw{:utf8 :std};
  7. use Encode;
  8. package IkiWiki;
  9. sub printheader ($) { #{{{
  10. my $session=shift;
  11. if ($config{sslcookie}) {
  12. print $session->header(-charset => 'utf-8',
  13. -cookie => $session->cookie(-secure => 1));
  14. } else {
  15. print $session->header(-charset => 'utf-8');
  16. }
  17. } #}}}
  18. sub showform ($$$$) { #{{{
  19. my $form=shift;
  20. my $buttons=shift;
  21. my $session=shift;
  22. my $cgi=shift;
  23. if (exists $hooks{formbuilder}) {
  24. run_hooks(formbuilder => sub {
  25. shift->(form => $form, cgi => $cgi, session => $session,
  26. buttons => $buttons);
  27. });
  28. }
  29. printheader($session);
  30. print misctemplate($form->title, $form->render(submit => $buttons));
  31. }
  32. sub redirect ($$) { #{{{
  33. my $q=shift;
  34. my $url=shift;
  35. if (! $config{w3mmode}) {
  36. print $q->redirect($url);
  37. }
  38. else {
  39. print "Content-type: text/plain\n";
  40. print "W3m-control: GOTO $url\n\n";
  41. }
  42. } #}}}
  43. sub check_canedit ($$$;$) { #{{{
  44. my $page=shift;
  45. my $q=shift;
  46. my $session=shift;
  47. my $nonfatal=shift;
  48. my $canedit;
  49. run_hooks(canedit => sub {
  50. return if defined $canedit;
  51. my $ret=shift->($page, $q, $session);
  52. if (defined $ret && $ret eq "") {
  53. $canedit=1;
  54. }
  55. elsif (defined $ret) {
  56. $canedit=0;
  57. error($ret) unless $nonfatal;
  58. }
  59. });
  60. return $canedit;
  61. } #}}}
  62. sub decode_form_utf8 ($) { #{{{
  63. my $form = shift;
  64. foreach my $f ($form->field) {
  65. next if Encode::is_utf8(scalar $form->field($f));
  66. $form->field(name => $f,
  67. value => decode_utf8($form->field($f)),
  68. force => 1,
  69. );
  70. }
  71. } #}}}
  72. sub cgi_recentchanges ($) { #{{{
  73. my $q=shift;
  74. # Optimisation: building recentchanges means calculating lots of
  75. # links. Memoizing htmllink speeds it up a lot (can't be memoized
  76. # during page builds as the return values may change, but they
  77. # won't here.)
  78. eval q{use Memoize};
  79. error($@) if $@;
  80. memoize("htmllink");
  81. eval q{use Time::Duration};
  82. error($@) if $@;
  83. my $changelog=[rcs_recentchanges(100)];
  84. foreach my $change (@$changelog) {
  85. $change->{when} = concise(ago($change->{when}));
  86. $change->{user} = userlink($change->{user});
  87. my $is_excess = exists $change->{pages}[10]; # limit pages to first 10
  88. delete @{$change->{pages}}[10 .. @{$change->{pages}}] if $is_excess;
  89. $change->{pages} = [
  90. map {
  91. $_->{link} = htmllink("", "", $_->{page},
  92. noimageinline => 1,
  93. linktext => pagetitle($_->{page}));
  94. $_;
  95. } @{$change->{pages}}
  96. ];
  97. push @{$change->{pages}}, { link => '...' } if $is_excess;
  98. }
  99. my $template=template("recentchanges.tmpl");
  100. $template->param(
  101. title => "RecentChanges",
  102. indexlink => indexlink(),
  103. wikiname => $config{wikiname},
  104. changelog => $changelog,
  105. baseurl => baseurl(),
  106. );
  107. run_hooks(pagetemplate => sub {
  108. shift->(page => "", destpage => "", template => $template);
  109. });
  110. print $q->header(-charset => 'utf-8'), $template->output;
  111. } #}}}
  112. # Check if the user is signed in. If not, redirect to the signin form and
  113. # save their place to return to later.
  114. sub needsignin ($$) { #{{{
  115. my $q=shift;
  116. my $session=shift;
  117. if (! defined $session->param("name") ||
  118. ! userinfo_get($session->param("name"), "regdate")) {
  119. if (! defined $session->param("postsignin")) {
  120. $session->param(postsignin => $ENV{QUERY_STRING});
  121. }
  122. cgi_signin($q, $session);
  123. cgi_savesession($session);
  124. exit;
  125. }
  126. } #}}}
  127. sub cgi_signin ($$) { #{{{
  128. my $q=shift;
  129. my $session=shift;
  130. eval q{use CGI::FormBuilder};
  131. error($@) if $@;
  132. my $form = CGI::FormBuilder->new(
  133. title => "signin",
  134. name => "signin",
  135. charset => "utf-8",
  136. method => 'POST',
  137. required => 'NONE',
  138. javascript => 0,
  139. params => $q,
  140. action => $config{cgiurl},
  141. header => 0,
  142. template => {type => 'div'},
  143. stylesheet => baseurl()."style.css",
  144. );
  145. my $buttons=["Login"];
  146. if ($q->param("do") ne "signin" && !$form->submitted) {
  147. $form->text(gettext("You need to log in first."));
  148. }
  149. $form->field(name => "do", type => "hidden", value => "signin",
  150. force => 1);
  151. decode_form_utf8($form);
  152. run_hooks(formbuilder_setup => sub {
  153. shift->(form => $form, cgi => $q, session => $session,
  154. buttons => $buttons);
  155. });
  156. if ($form->submitted) {
  157. $form->validate;
  158. }
  159. showform($form, $buttons, $session, $q);
  160. } #}}}
  161. sub cgi_postsignin ($$) { #{{{
  162. my $q=shift;
  163. my $session=shift;
  164. # Continue with whatever was being done before the signin process.
  165. if (defined $session->param("postsignin")) {
  166. my $postsignin=CGI->new($session->param("postsignin"));
  167. $session->clear("postsignin");
  168. cgi($postsignin, $session);
  169. cgi_savesession($session);
  170. exit;
  171. }
  172. else {
  173. # This can occur, for example, if a user went to the signin
  174. # url via a bookmark.
  175. redirect($q, $config{url});
  176. }
  177. } #}}}
  178. sub cgi_prefs ($$) { #{{{
  179. my $q=shift;
  180. my $session=shift;
  181. needsignin($q, $session);
  182. eval q{use CGI::FormBuilder};
  183. error($@) if $@;
  184. my $form = CGI::FormBuilder->new(
  185. title => "preferences",
  186. name => "preferences",
  187. header => 0,
  188. charset => "utf-8",
  189. method => 'POST',
  190. validate => {
  191. email => 'EMAIL',
  192. },
  193. required => 'NONE',
  194. javascript => 0,
  195. params => $q,
  196. action => $config{cgiurl},
  197. template => {type => 'div'},
  198. stylesheet => baseurl()."style.css",
  199. fieldsets => [
  200. [login => gettext("Login")],
  201. [preferences => gettext("Preferences")],
  202. [admin => gettext("Admin")]
  203. ],
  204. );
  205. my $buttons=["Save Preferences", "Logout", "Cancel"];
  206. decode_form_utf8($form);
  207. run_hooks(formbuilder_setup => sub {
  208. shift->(form => $form, cgi => $q, session => $session,
  209. buttons => $buttons);
  210. });
  211. $form->field(name => "do", type => "hidden");
  212. $form->field(name => "email", size => 50, fieldset => "preferences");
  213. $form->field(name => "subscriptions", size => 50,
  214. fieldset => "preferences",
  215. comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
  216. $form->field(name => "banned_users", size => 50,
  217. fieldset => "admin");
  218. my $user_name=$session->param("name");
  219. if (! is_admin($user_name)) {
  220. $form->field(name => "banned_users", type => "hidden");
  221. }
  222. if (! $form->submitted) {
  223. $form->field(name => "email", force => 1,
  224. value => userinfo_get($user_name, "email"));
  225. $form->field(name => "subscriptions", force => 1,
  226. value => userinfo_get($user_name, "subscriptions"));
  227. if (is_admin($user_name)) {
  228. $form->field(name => "banned_users", force => 1,
  229. value => join(" ", get_banned_users()));
  230. }
  231. }
  232. if ($form->submitted eq 'Logout') {
  233. $session->delete();
  234. redirect($q, $config{url});
  235. return;
  236. }
  237. elsif ($form->submitted eq 'Cancel') {
  238. redirect($q, $config{url});
  239. return;
  240. }
  241. elsif ($form->submitted eq 'Save Preferences' && $form->validate) {
  242. foreach my $field (qw(email subscriptions)) {
  243. if (defined $form->field($field) && length $form->field($field)) {
  244. userinfo_set($user_name, $field, $form->field($field)) ||
  245. error("failed to set $field");
  246. }
  247. }
  248. if (is_admin($user_name)) {
  249. set_banned_users(grep { ! is_admin($_) }
  250. split(' ',
  251. $form->field("banned_users"))) ||
  252. error("failed saving changes");
  253. }
  254. $form->text(gettext("Preferences saved."));
  255. }
  256. showform($form, $buttons, $session, $q);
  257. } #}}}
  258. sub cgi_editpage ($$) { #{{{
  259. my $q=shift;
  260. my $session=shift;
  261. my @fields=qw(do rcsinfo subpage from page type editcontent comments);
  262. my @buttons=("Save Page", "Preview", "Cancel");
  263. eval q{use CGI::FormBuilder};
  264. error($@) if $@;
  265. my $form = CGI::FormBuilder->new(
  266. title => "editpage",
  267. fields => \@fields,
  268. charset => "utf-8",
  269. method => 'POST',
  270. required => [qw{editcontent}],
  271. javascript => 0,
  272. params => $q,
  273. action => $config{cgiurl},
  274. header => 0,
  275. table => 0,
  276. template => scalar template_params("editpage.tmpl"),
  277. wikiname => $config{wikiname},
  278. );
  279. decode_form_utf8($form);
  280. run_hooks(formbuilder_setup => sub {
  281. shift->(form => $form, cgi => $q, session => $session,
  282. buttons => \@buttons);
  283. });
  284. # This untaint is safe because titlepage removes any problematic
  285. # characters.
  286. my ($page)=$form->field('page');
  287. $page=titlepage(possibly_foolish_untaint($page));
  288. if (! defined $page || ! length $page ||
  289. file_pruned($page, $config{srcdir}) || $page=~/^\//) {
  290. error("bad page name");
  291. }
  292. my $from;
  293. if (defined $form->field('from')) {
  294. ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
  295. }
  296. my $file;
  297. my $type;
  298. if (exists $pagesources{$page} && $form->field("do") ne "create") {
  299. $file=$pagesources{$page};
  300. $type=pagetype($file);
  301. if (! defined $type) {
  302. error(sprintf(gettext("%s is not an editable page"), $page));
  303. }
  304. if (! $form->submitted) {
  305. $form->field(name => "rcsinfo",
  306. value => rcs_prepedit($file), force => 1);
  307. }
  308. $form->field(name => "editcontent", validate => '/.*/');
  309. }
  310. else {
  311. $type=$form->param('type');
  312. if (defined $type && length $type && $hooks{htmlize}{$type}) {
  313. $type=possibly_foolish_untaint($type);
  314. }
  315. elsif (defined $from) {
  316. # favor the type of linking page
  317. $type=pagetype($pagesources{$from});
  318. }
  319. $type=$config{default_pageext} unless defined $type;
  320. $file=$page.".".$type;
  321. if (! $form->submitted) {
  322. $form->field(name => "rcsinfo", value => "", force => 1);
  323. }
  324. $form->field(name => "editcontent", validate => '/.+/');
  325. }
  326. $form->field(name => "do", type => 'hidden');
  327. $form->field(name => "from", type => 'hidden');
  328. $form->field(name => "rcsinfo", type => 'hidden');
  329. $form->field(name => "subpage", type => 'hidden');
  330. $form->field(name => "page", value => pagetitle($page, 1), force => 1);
  331. $form->field(name => "type", value => $type, force => 1);
  332. $form->field(name => "comments", type => "text", size => 80);
  333. $form->field(name => "editcontent", type => "textarea", rows => 20,
  334. cols => 80);
  335. $form->tmpl_param("can_commit", $config{rcs});
  336. $form->tmpl_param("indexlink", indexlink());
  337. $form->tmpl_param("helponformattinglink",
  338. htmllink("", "", "ikiwiki/formatting",
  339. noimageinline => 1,
  340. linktext => "FormattingHelp"));
  341. $form->tmpl_param("baseurl", baseurl());
  342. if ($form->submitted eq "Cancel") {
  343. if ($form->field("do") eq "create" && defined $from) {
  344. redirect($q, "$config{url}/".htmlpage($from));
  345. }
  346. elsif ($form->field("do") eq "create") {
  347. redirect($q, $config{url});
  348. }
  349. else {
  350. redirect($q, "$config{url}/".htmlpage($page));
  351. }
  352. return;
  353. }
  354. elsif ($form->submitted eq "Preview") {
  355. my $content=$form->field('editcontent');
  356. run_hooks(editcontent => sub {
  357. $content=shift->(
  358. content => $content,
  359. page => $page,
  360. cgi => $q,
  361. session => $session,
  362. );
  363. });
  364. $form->tmpl_param("page_preview",
  365. htmlize($page, $type,
  366. linkify($page, "",
  367. preprocess($page, $page,
  368. filter($page, $page, $content), 0, 1))));
  369. }
  370. elsif ($form->submitted eq "Save Page") {
  371. $form->tmpl_param("page_preview", "");
  372. }
  373. $form->tmpl_param("page_conflict", "");
  374. if ($form->submitted ne "Save Page" || ! $form->validate) {
  375. if ($form->field("do") eq "create") {
  376. my @page_locs;
  377. my $best_loc;
  378. if (! defined $from || ! length $from ||
  379. $from ne $form->field('from') ||
  380. file_pruned($from, $config{srcdir}) ||
  381. $from=~/^\// ||
  382. $form->submitted eq "Preview") {
  383. @page_locs=$best_loc=$page;
  384. }
  385. else {
  386. my $dir=$from."/";
  387. $dir=~s![^/]+/+$!!;
  388. if ((defined $form->field('subpage') && length $form->field('subpage')) ||
  389. $page eq gettext('discussion')) {
  390. $best_loc="$from/$page";
  391. }
  392. else {
  393. $best_loc=$dir.$page;
  394. }
  395. push @page_locs, $dir.$page;
  396. push @page_locs, "$from/$page";
  397. while (length $dir) {
  398. $dir=~s![^/]+/+$!!;
  399. push @page_locs, $dir.$page;
  400. }
  401. }
  402. push @page_locs, "$config{userdir}/$page"
  403. if length $config{userdir};
  404. @page_locs = grep {
  405. ! exists $pagecase{lc $_}
  406. } @page_locs;
  407. if (! @page_locs) {
  408. # hmm, someone else made the page in the
  409. # meantime?
  410. redirect($q, "$config{url}/".htmlpage($page));
  411. return;
  412. }
  413. my @editable_locs = grep {
  414. check_canedit($_, $q, $session, 1)
  415. } @page_locs;
  416. if (! @editable_locs) {
  417. # let it throw an error this time
  418. map { check_canedit($_, $q, $session) } @page_locs;
  419. }
  420. my @page_types;
  421. if (exists $hooks{htmlize}) {
  422. @page_types=keys %{$hooks{htmlize}};
  423. }
  424. $form->tmpl_param("page_select", 1);
  425. $form->field(name => "page", type => 'select',
  426. options => [ map { pagetitle($_, 1) } @editable_locs ],
  427. value => pagetitle($best_loc, 1));
  428. $form->field(name => "type", type => 'select',
  429. options => \@page_types);
  430. $form->title(sprintf(gettext("creating %s"), pagetitle($page)));
  431. }
  432. elsif ($form->field("do") eq "edit") {
  433. check_canedit($page, $q, $session);
  434. if (! defined $form->field('editcontent') ||
  435. ! length $form->field('editcontent')) {
  436. my $content="";
  437. if (exists $pagesources{$page}) {
  438. $content=readfile(srcfile($pagesources{$page}));
  439. $content=~s/\n/\r\n/g;
  440. }
  441. $form->field(name => "editcontent", value => $content,
  442. force => 1);
  443. }
  444. $form->tmpl_param("page_select", 0);
  445. $form->field(name => "page", type => 'hidden');
  446. $form->field(name => "type", type => 'hidden');
  447. $form->title(sprintf(gettext("editing %s"), pagetitle($page)));
  448. }
  449. showform($form, \@buttons, $session, $q);
  450. saveindex();
  451. }
  452. else {
  453. # save page
  454. check_canedit($page, $q, $session);
  455. my $exists=-e "$config{srcdir}/$file";
  456. if ($form->field("do") ne "create" && ! $exists &&
  457. ! eval { srcfile($file) }) {
  458. $form->tmpl_param("page_gone", 1);
  459. $form->field(name => "do", value => "create", force => 1);
  460. $form->tmpl_param("page_select", 0);
  461. $form->field(name => "page", type => 'hidden');
  462. $form->field(name => "type", type => 'hidden');
  463. $form->title(sprintf(gettext("editing %s"), $page));
  464. showform($form, \@buttons, $session, $q);
  465. return;
  466. }
  467. elsif ($form->field("do") eq "create" && $exists) {
  468. $form->tmpl_param("creation_conflict", 1);
  469. $form->field(name => "do", value => "edit", force => 1);
  470. $form->tmpl_param("page_select", 0);
  471. $form->field(name => "page", type => 'hidden');
  472. $form->field(name => "type", type => 'hidden');
  473. $form->title(sprintf(gettext("editing %s"), $page));
  474. $form->field("editcontent",
  475. value => readfile("$config{srcdir}/$file").
  476. "\n\n\n".$form->field("editcontent"),
  477. force => 1);
  478. showform($form, \@buttons, $session, $q);
  479. return;
  480. }
  481. my $content=$form->field('editcontent');
  482. run_hooks(editcontent => sub {
  483. $content=shift->(
  484. content => $content,
  485. page => $page,
  486. cgi => $q,
  487. session => $session,
  488. );
  489. });
  490. $content=~s/\r\n/\n/g;
  491. $content=~s/\r/\n/g;
  492. $content.="\n" if $content !~ /\n$/;
  493. $config{cgi}=0; # avoid cgi error message
  494. eval { writefile($file, $config{srcdir}, $content) };
  495. $config{cgi}=1;
  496. if ($@) {
  497. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  498. force => 1);
  499. $form->tmpl_param("failed_save", 1);
  500. $form->tmpl_param("error_message", $@);
  501. $form->field("editcontent", value => $content, force => 1);
  502. $form->tmpl_param("page_select", 0);
  503. $form->field(name => "page", type => 'hidden');
  504. $form->field(name => "type", type => 'hidden');
  505. $form->title(sprintf(gettext("editing %s"), $page));
  506. showform($form, \@buttons, $session, $q);
  507. return;
  508. }
  509. my $conflict;
  510. if ($config{rcs}) {
  511. my $message="";
  512. if (defined $form->field('comments') &&
  513. length $form->field('comments')) {
  514. $message=$form->field('comments');
  515. }
  516. if (! $exists) {
  517. rcs_add($file);
  518. }
  519. # Prevent deadlock with post-commit hook by
  520. # signaling to it that it should not try to
  521. # do anything (except send commit mails).
  522. disable_commit_hook();
  523. $conflict=rcs_commit($file, $message,
  524. $form->field("rcsinfo"),
  525. $session->param("name"), $ENV{REMOTE_ADDR});
  526. enable_commit_hook();
  527. rcs_update();
  528. }
  529. # Refresh even if there was a conflict, since other changes
  530. # may have been committed while the post-commit hook was
  531. # disabled.
  532. require IkiWiki::Render;
  533. # Reload index, since the first time it's loaded is before
  534. # the wiki is locked, and things may have changed in the
  535. # meantime.
  536. loadindex();
  537. refresh();
  538. saveindex();
  539. if (defined $conflict) {
  540. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  541. force => 1);
  542. $form->tmpl_param("page_conflict", 1);
  543. $form->field("editcontent", value => $conflict, force => 1);
  544. $form->field("do", "edit", force => 1);
  545. $form->tmpl_param("page_select", 0);
  546. $form->field(name => "page", type => 'hidden');
  547. $form->field(name => "type", type => 'hidden');
  548. $form->title(sprintf(gettext("editing %s"), $page));
  549. showform($form, \@buttons, $session, $q);
  550. return;
  551. }
  552. else {
  553. # The trailing question mark tries to avoid broken
  554. # caches and get the most recent version of the page.
  555. redirect($q, "$config{url}/".htmlpage($page)."?updated");
  556. }
  557. }
  558. } #}}}
  559. sub cgi_getsession ($) { #{{{
  560. my $q=shift;
  561. eval q{use CGI::Session};
  562. CGI::Session->name("ikiwiki_session_".encode_utf8($config{wikiname}));
  563. my $oldmask=umask(077);
  564. my $session = CGI::Session->new("driver:DB_File", $q,
  565. { FileName => "$config{wikistatedir}/sessions.db" });
  566. umask($oldmask);
  567. return $session;
  568. } #}}}
  569. sub cgi_savesession ($) { #{{{
  570. my $session=shift;
  571. # Force session flush with safe umask.
  572. my $oldmask=umask(077);
  573. $session->flush;
  574. umask($oldmask);
  575. } #}}}
  576. sub cgi (;$$) { #{{{
  577. my $q=shift;
  578. my $session=shift;
  579. if (! $q) {
  580. eval q{use CGI};
  581. error($@) if $@;
  582. $q=CGI->new;
  583. run_hooks(cgi => sub { shift->($q) });
  584. }
  585. my $do=$q->param('do');
  586. if (! defined $do || ! length $do) {
  587. my $error = $q->cgi_error;
  588. if ($error) {
  589. error("Request not processed: $error");
  590. }
  591. else {
  592. error("\"do\" parameter missing");
  593. }
  594. }
  595. # Things that do not need a session.
  596. if ($do eq 'recentchanges') {
  597. cgi_recentchanges($q);
  598. return;
  599. }
  600. # Need to lock the wiki before getting a session.
  601. lockwiki();
  602. if (! $session) {
  603. $session=cgi_getsession($q);
  604. }
  605. # Auth hooks can sign a user in.
  606. if ($do ne 'signin' && ! defined $session->param("name")) {
  607. run_hooks(auth => sub {
  608. shift->($q, $session)
  609. });
  610. if (defined $session->param("name")) {
  611. # Make sure whatever user was authed is in the
  612. # userinfo db.
  613. if (! userinfo_get($session->param("name"), "regdate")) {
  614. userinfo_setall($session->param("name"), {
  615. email => "",
  616. password => "",
  617. regdate => time,
  618. }) || error("failed adding user");
  619. }
  620. }
  621. }
  622. if (defined $session->param("name") &&
  623. userinfo_get($session->param("name"), "banned")) {
  624. print $q->header(-status => "403 Forbidden");
  625. $session->delete();
  626. print gettext("You are banned.");
  627. cgi_savesession($session);
  628. }
  629. run_hooks(sessioncgi => sub { shift->($q, $session) });
  630. if ($do eq 'signin') {
  631. cgi_signin($q, $session);
  632. cgi_savesession($session);
  633. }
  634. elsif (defined $session->param("postsignin")) {
  635. cgi_postsignin($q, $session);
  636. }
  637. elsif ($do eq 'prefs') {
  638. cgi_prefs($q, $session);
  639. }
  640. elsif ($do eq 'create' || $do eq 'edit') {
  641. cgi_editpage($q, $session);
  642. }
  643. elsif ($do eq 'postsignin') {
  644. error(gettext("login failed, perhaps you need to turn on cookies?"));
  645. }
  646. else {
  647. error("unknown do parameter");
  648. }
  649. } #}}}
  650. sub userlink ($) { #{{{
  651. my $user=shift;
  652. eval q{use CGI 'escapeHTML'};
  653. error($@) if $@;
  654. if ($user =~ m!^https?://! &&
  655. eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
  656. # Munge user-urls, as used by eg, OpenID.
  657. my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
  658. my $display=$oid->display;
  659. # Convert "user.somehost.com" to "user [somehost.com]".
  660. if ($display !~ /\[/) {
  661. $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
  662. }
  663. # Convert "http://somehost.com/user" to "user [somehost.com]".
  664. if ($display !~ /\[/) {
  665. $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
  666. }
  667. $display=~s!^https?://!!; # make sure this is removed
  668. return "<a href=\"$user\">".escapeHTML($display)."</a>";
  669. }
  670. else {
  671. return htmllink("", "", escapeHTML(
  672. length $config{userdir} ? $config{userdir}."/".$user : $user
  673. ), noimageinline => 1);
  674. }
  675. } #}}}
  676. 1