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