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