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