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