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