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