summaryrefslogtreecommitdiff
path: root/IkiWiki/CGI.pm
blob: 1471ae926631aef72356917c669546a1ade7f9d7 (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. );
  283. run_hooks(formbuilder_setup => sub {
  284. shift->(form => $form, cgi => $q, session => $session);
  285. });
  286. decode_form_utf8($form);
  287. # This untaint is safe because titlepage removes any problematic
  288. # characters.
  289. my ($page)=$form->field('page');
  290. $page=titlepage(possibly_foolish_untaint($page));
  291. if (! defined $page || ! length $page || file_pruned($page, $config{srcdir}) || $page=~/^\//) {
  292. error("bad page name");
  293. }
  294. my $from;
  295. if (defined $form->field('from')) {
  296. ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
  297. }
  298. my $file;
  299. my $type;
  300. if (exists $pagesources{$page} && $form->field("do") ne "create") {
  301. $file=$pagesources{$page};
  302. $type=pagetype($file);
  303. if (! defined $type) {
  304. error(sprintf(gettext("%s is not an editable page"), $page));
  305. }
  306. if (! $form->submitted) {
  307. $form->field(name => "rcsinfo",
  308. value => rcs_prepedit($file), force => 1);
  309. }
  310. }
  311. else {
  312. $type=$form->param('type');
  313. if (defined $type && length $type && $hooks{htmlize}{$type}) {
  314. $type=possibly_foolish_untaint($type);
  315. }
  316. elsif (defined $from) {
  317. # favor the type of linking page
  318. $type=pagetype($pagesources{$from});
  319. }
  320. $type=$config{default_pageext} unless defined $type;
  321. $file=$page.".".$type;
  322. if (! $form->submitted) {
  323. $form->field(name => "rcsinfo", value => "", force => 1);
  324. }
  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("", "", "HelpOnFormatting", noimageinline => 1));
  339. $form->tmpl_param("baseurl", baseurl());
  340. if ($form->submitted eq "Cancel") {
  341. if ($form->field("do") eq "create" && defined $from) {
  342. redirect($q, "$config{url}/".htmlpage($from));
  343. }
  344. elsif ($form->field("do") eq "create") {
  345. redirect($q, $config{url});
  346. }
  347. else {
  348. redirect($q, "$config{url}/".htmlpage($page));
  349. }
  350. return;
  351. }
  352. elsif ($form->submitted eq "Preview") {
  353. $form->tmpl_param("page_preview",
  354. htmlize($page, $type,
  355. linkify($page, "",
  356. preprocess($page, $page,
  357. filter($page, $form->field('editcontent')), 0, 1))));
  358. }
  359. else {
  360. $form->tmpl_param("page_preview", "");
  361. }
  362. $form->tmpl_param("page_conflict", "");
  363. if (! $form->submitted || $form->submitted eq "Preview" ||
  364. ! $form->validate) {
  365. if ($form->field("do") eq "create") {
  366. my @page_locs;
  367. my $best_loc;
  368. if (! defined $from || ! length $from ||
  369. $from ne $form->field('from') ||
  370. file_pruned($from, $config{srcdir}) ||
  371. $from=~/^\// ||
  372. $form->submitted eq "Preview") {
  373. @page_locs=$best_loc=$page;
  374. }
  375. else {
  376. my $dir=$from."/";
  377. $dir=~s![^/]+/+$!!;
  378. if ((defined $form->field('subpage') && length $form->field('subpage')) ||
  379. $page eq gettext('discussion')) {
  380. $best_loc="$from/$page";
  381. }
  382. else {
  383. $best_loc=$dir.$page;
  384. }
  385. push @page_locs, $dir.$page;
  386. push @page_locs, "$from/$page";
  387. while (length $dir) {
  388. $dir=~s![^/]+/+$!!;
  389. push @page_locs, $dir.$page;
  390. }
  391. }
  392. push @page_locs, "$config{userdir}/$page"
  393. if length $config{userdir};
  394. @page_locs = grep {
  395. ! exists $pagecase{lc $_}
  396. } @page_locs;
  397. if (! @page_locs) {
  398. # hmm, someone else made the page in the
  399. # meantime?
  400. redirect($q, "$config{url}/".htmlpage($page));
  401. return;
  402. }
  403. my @editable_locs = grep {
  404. check_canedit($_, $q, $session, 1)
  405. } @page_locs;
  406. if (! @editable_locs) {
  407. # let it throw an error this time
  408. map { check_canedit($_, $q, $session) } @page_locs;
  409. }
  410. my @page_types;
  411. if (exists $hooks{htmlize}) {
  412. @page_types=keys %{$hooks{htmlize}};
  413. }
  414. $form->tmpl_param("page_select", 1);
  415. $form->field(name => "page", type => 'select',
  416. options => [ map { pagetitle($_, 1) } @editable_locs ],
  417. value => pagetitle($best_loc, 1));
  418. $form->field(name => "type", type => 'select',
  419. options => \@page_types);
  420. $form->title(sprintf(gettext("creating %s"), pagetitle($page)));
  421. }
  422. elsif ($form->field("do") eq "edit") {
  423. check_canedit($page, $q, $session);
  424. if (! defined $form->field('editcontent') ||
  425. ! length $form->field('editcontent')) {
  426. my $content="";
  427. if (exists $pagesources{$page}) {
  428. $content=readfile(srcfile($pagesources{$page}));
  429. $content=~s/\n/\r\n/g;
  430. }
  431. $form->field(name => "editcontent", value => $content,
  432. force => 1);
  433. }
  434. $form->tmpl_param("page_select", 0);
  435. $form->field(name => "page", type => 'hidden');
  436. $form->field(name => "type", type => 'hidden');
  437. $form->title(sprintf(gettext("editing %s"), pagetitle($page)));
  438. }
  439. print $form->render(submit => \@buttons);
  440. }
  441. else {
  442. # save page
  443. check_canedit($page, $q, $session);
  444. if (! -e "$config{srcdir}/$file" &&
  445. $form->field("do") ne "create") {
  446. $form->tmpl_param("page_gone", 1);
  447. $form->field(name => "do", value => "create", force => 1);
  448. $form->tmpl_param("page_select", 0);
  449. $form->field(name => "page", type => 'hidden');
  450. $form->field(name => "type", type => 'hidden');
  451. $form->title(sprintf(gettext("editing %s"), $page));
  452. print $form->render(submit => \@buttons);
  453. return;
  454. }
  455. elsif (-e "$config{srcdir}/$file" &&
  456. $form->field("do") eq "create") {
  457. $form->tmpl_param("creation_conflict", 1);
  458. $form->field(name => "do", value => "edit", force => 1);
  459. $form->tmpl_param("page_select", 0);
  460. $form->field(name => "page", type => 'hidden');
  461. $form->field(name => "type", type => 'hidden');
  462. $form->title(sprintf(gettext("editing %s"), $page));
  463. $form->field("editcontent",
  464. value => readfile("$config{srcdir}/$file").
  465. "\n\n\n".$form->field("editcontent"),
  466. force => 1);
  467. print $form->render(submit => \@buttons);
  468. return;
  469. }
  470. my $content=$form->field('editcontent');
  471. $content=~s/\r\n/\n/g;
  472. $content=~s/\r/\n/g;
  473. $config{cgi}=0; # avoid cgi error message
  474. eval { writefile($file, $config{srcdir}, $content) };
  475. $config{cgi}=1;
  476. if ($@) {
  477. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  478. force => 1);
  479. $form->tmpl_param("failed_save", 1);
  480. $form->tmpl_param("error_message", $@);
  481. $form->field("editcontent", value => $content, force => 1);
  482. $form->tmpl_param("page_select", 0);
  483. $form->field(name => "page", type => 'hidden');
  484. $form->field(name => "type", type => 'hidden');
  485. $form->title(sprintf(gettext("editing %s"), $page));
  486. print $form->render(submit => \@buttons);
  487. return;
  488. }
  489. my $conflict;
  490. if ($config{rcs}) {
  491. my $message="";
  492. if (defined $form->field('comments') &&
  493. length $form->field('comments')) {
  494. $message=$form->field('comments');
  495. }
  496. if ($form->field("do") eq "create") {
  497. rcs_add($file);
  498. }
  499. # Prevent deadlock with post-commit hook by
  500. # signaling to it that it should not try to
  501. # do anything (except send commit mails).
  502. disable_commit_hook();
  503. $conflict=rcs_commit($file, $message,
  504. $form->field("rcsinfo"),
  505. $session->param("name"), $ENV{REMOTE_ADDR});
  506. enable_commit_hook();
  507. rcs_update();
  508. }
  509. # Refresh even if there was a conflict, since other changes
  510. # may have been committed while the post-commit hook was
  511. # disabled.
  512. require IkiWiki::Render;
  513. refresh();
  514. saveindex();
  515. if (defined $conflict) {
  516. $form->field(name => "rcsinfo", value => rcs_prepedit($file),
  517. force => 1);
  518. $form->tmpl_param("page_conflict", 1);
  519. $form->field("editcontent", value => $conflict, force => 1);
  520. $form->field("do", "edit", force => 1);
  521. $form->tmpl_param("page_select", 0);
  522. $form->field(name => "page", type => 'hidden');
  523. $form->field(name => "type", type => 'hidden');
  524. $form->title(sprintf(gettext("editing %s"), $page));
  525. print $form->render(submit => \@buttons);
  526. return;
  527. }
  528. else {
  529. # The trailing question mark tries to avoid broken
  530. # caches and get the most recent version of the page.
  531. redirect($q, "$config{url}/".htmlpage($page)."?updated");
  532. }
  533. }
  534. } #}}}
  535. sub cgi_getsession ($) { #{{{
  536. my $q=shift;
  537. eval q{use CGI::Session};
  538. CGI::Session->name("ikiwiki_session_".encode_utf8($config{wikiname}));
  539. my $oldmask=umask(077);
  540. my $session = CGI::Session->new("driver:DB_File", $q,
  541. { FileName => "$config{wikistatedir}/sessions.db" });
  542. umask($oldmask);
  543. return $session;
  544. } #}}}
  545. sub cgi_savesession ($) { #{{{
  546. my $session=shift;
  547. # Force session flush with safe umask.
  548. my $oldmask=umask(077);
  549. $session->flush;
  550. umask($oldmask);
  551. } #}}}
  552. sub cgi (;$$) { #{{{
  553. my $q=shift;
  554. my $session=shift;
  555. if (! $q) {
  556. eval q{use CGI};
  557. error($@) if $@;
  558. $q=CGI->new;
  559. run_hooks(cgi => sub { shift->($q) });
  560. }
  561. my $do=$q->param('do');
  562. if (! defined $do || ! length $do) {
  563. my $error = $q->cgi_error;
  564. if ($error) {
  565. error("Request not processed: $error");
  566. }
  567. else {
  568. error("\"do\" parameter missing");
  569. }
  570. }
  571. # Things that do not need a session.
  572. if ($do eq 'recentchanges') {
  573. cgi_recentchanges($q);
  574. return;
  575. }
  576. elsif ($do eq 'hyperestraier') {
  577. cgi_hyperestraier();
  578. }
  579. # Need to lock the wiki before getting a session.
  580. lockwiki();
  581. if (! $session) {
  582. $session=cgi_getsession($q);
  583. }
  584. # Auth hooks can sign a user in.
  585. if ($do ne 'signin' && ! defined $session->param("name")) {
  586. run_hooks(auth => sub {
  587. shift->($q, $session)
  588. });
  589. if (defined $session->param("name")) {
  590. # Make sure whatever user was authed is in the
  591. # userinfo db.
  592. if (! userinfo_get($session->param("name"), "regdate")) {
  593. userinfo_setall($session->param("name"), {
  594. email => "",
  595. password => "",
  596. regdate => time,
  597. }) || error("failed adding user");
  598. }
  599. }
  600. }
  601. if (defined $session->param("name") &&
  602. userinfo_get($session->param("name"), "banned")) {
  603. print $q->header(-status => "403 Forbidden");
  604. $session->delete();
  605. print gettext("You are banned.");
  606. cgi_savesession($session);
  607. }
  608. elsif ($do eq 'signin') {
  609. cgi_signin($q, $session);
  610. cgi_savesession($session);
  611. }
  612. elsif (defined $session->param("postsignin")) {
  613. cgi_postsignin($q, $session);
  614. }
  615. elsif ($do eq 'prefs') {
  616. cgi_prefs($q, $session);
  617. }
  618. elsif ($do eq 'create' || $do eq 'edit') {
  619. cgi_editpage($q, $session);
  620. }
  621. elsif ($do eq 'blog') {
  622. my $page=decode_utf8($q->param('title'));
  623. $page=~s/\///g; # no slashes in blog posts
  624. # if the page already exists, munge it to be unique
  625. my $from=$q->param('from');
  626. my $add="";
  627. while (exists $pagecase{lc($from."/".titlepage($page).$add)}) {
  628. $add=1 unless length $add;
  629. $add++;
  630. }
  631. $q->param('page', $page.$add);
  632. # now run same as create
  633. $q->param('do', 'create');
  634. cgi_editpage($q, $session);
  635. }
  636. elsif ($do eq 'postsignin') {
  637. error(gettext("login failed, perhaps you need to turn on cookies?"));
  638. }
  639. else {
  640. error("unknown do parameter");
  641. }
  642. } #}}}
  643. sub userlink ($) { #{{{
  644. my $user=shift;
  645. eval q{use CGI 'escapeHTML'};
  646. error($@) if $@;
  647. if ($user =~ m!^https?://! &&
  648. eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
  649. # Munge user-urls, as used by eg, OpenID.
  650. my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
  651. my $display=$oid->display;
  652. # Convert "user.somehost.com" to "user [somehost.com]".
  653. if ($display !~ /\[/) {
  654. $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
  655. }
  656. # Convert "http://somehost.com/user" to "user [somehost.com]".
  657. if ($display !~ /\[/) {
  658. $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
  659. }
  660. $display=~s!^https?://!!; # make sure this is removed
  661. return "<a href=\"$user\">".escapeHTML($display)."</a>";
  662. }
  663. else {
  664. return htmllink("", "", escapeHTML(
  665. length $config{userdir} ? $config{userdir}."/".$user : $user
  666. ), noimageinline => 1);
  667. }
  668. } #}}}
  669. 1