diff --git a/wiki.pl b/wiki.pl index 7e02af1b..4bddfee7 100755 --- a/wiki.pl +++ b/wiki.pl @@ -1,5 +1,5 @@ #! /usr/bin/perl -# Version $Id: wiki.pl,v 1.940 2010/10/09 23:20:56 as Exp $ +# Version $Id: wiki.pl,v 1.941 2010/11/07 02:11:53 as Exp $ # Copyleft 2008 Brian Curry # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 # Alex Schroeder @@ -36,7 +36,7 @@ use CGI::Carp qw(fatalsToBrowser); use vars qw($VERSION); local $| = 1; # Do not buffer output (localized for mod_perl) -$VERSION=(split(/ +/, q{$Revision: 1.940 $}))[1]; # for MakeMaker +$VERSION=(split(/ +/, q{$Revision: 1.941 $}))[1]; # for MakeMaker # Options: use vars qw($RssLicense $RssCacheHours @RcDays $TempDir $LockDir $DataDir @@ -290,7 +290,7 @@ sub InitRequest { sub InitVariables { # Init global session variables for mod_perl! $WikiDescription = $q->p($q->a({-href=>'http://www.oddmuse.org/'}, 'Oddmuse'), $Counter++ > 0 ? Ts('%s calls', $Counter) : '') - . $q->p(q{$Id: wiki.pl,v 1.940 2010/10/09 23:20:56 as Exp $}); + . $q->p(q{$Id: wiki.pl,v 1.941 2010/11/07 02:11:53 as Exp $}); $WikiDescription .= $ModulesDescription if $ModulesDescription; $PrintedHeader = 0; # Error messages don't print headers unless necessary $ReplaceForm = 0; # Only admins may search and replace @@ -395,7 +395,7 @@ sub InitLinkPatterns { $QDelim = '(?:"")?'; # Optional quote delimiter (removed from the output) $WikiWord = '[A-Z]+[a-z\x80-\xff]+[A-Z][A-Za-z\x80-\xff]*'; $LinkPattern = "($WikiWord)$QDelim"; - $FreeLinkPattern = "([-,.()' _1-9A-Za-z\x80-\xff]|[-,.()' _0-9A-Za-z\x80-\xff][-,.()' _0-9A-Za-z\x80-\xff]+)"; # disallow "0" + $FreeLinkPattern = "([-,.()'%&?;<> _1-9A-Za-z\x80-\xff]|[-,.()'%&?;<> _0-9A-Za-z\x80-\xff][-,.()'%&?;<> _0-9A-Za-z\x80-\xff]+)"; # disallow "0" and must match HTML and plain text (ie. > and >) # Intersites must start with uppercase letter to avoid confusion with URLs. $InterSitePattern = '[A-Z\x80-\xff]+[A-Za-z\x80-\xff]+'; $InterLinkPattern = "($InterSitePattern:[-a-zA-Z0-9\x80-\xff_=!?#\$\@~`\%&*+\\/:;.,]*[-a-zA-Z0-9\x80-\xff_=#\$\@~`\%&*+\\/])$QDelim"; @@ -470,7 +470,7 @@ sub ApplyRules { $Includes{$OpenPageName} = 1; local $OpenPageName = FreeToNormal($uri); if ($type eq 'text') { - print $q->pre({class=>"include $OpenPageName"},QuoteHtml(GetPageContent($OpenPageName))); + print $q->pre({class=>"include $OpenPageName"}, QuoteHtml(GetPageContent($OpenPageName))); } elsif (not $Includes{$OpenPageName}) { # with a starting tag, watch out for recursion print $q->start_div({class=>"include $OpenPageName"}); ApplyRules(QuoteHtml(GetPageContent($OpenPageName)), $locallinks, $withanchors, undef, 'p'); @@ -616,7 +616,7 @@ sub LinkRules { or m/\G(\[\[image:$FreeLinkPattern\|([^]|]+)\]\])/cog)) { # [[image:Free Link]], [[image:Free Link|alt text]] Dirty($1); - print GetDownloadLink($2, 1, undef, UnquoteHtml($3)); + print GetDownloadLink(FreeToNormal($2), 1, undef, UnquoteHtml($3)); } elsif ($FreeLinks && $locallinks && ($BracketWiki && m/\G(\[\[$FreeLinkPattern\|([^\]]+)\]\])/cog or m/\G(\[\[\[$FreeLinkPattern\]\]\])/cog @@ -797,6 +797,7 @@ sub UnquoteHtml { $html =~ s/<//g; $html =~ s/&/&/g; + $html =~ s/%26/&/g; return $html; } @@ -936,76 +937,76 @@ sub RSS { my $data = $data{$uri}; if (not $data) { $str .= $q->p({-class=>'error'}, $q->strong(Ts('%s returned no data, or LWP::UserAgent is not available.', - $q->a({-href=>$uri}, $uri)))); + $q->a({-href=>$uri}, $uri)))); } else { my $rss = new XML::RSS; eval { local $SIG{__DIE__}; $rss->parse($data); }; if ($@) { - $str .= $q->p({-class=>'error'}, $q->strong(Ts('RSS parsing failed for %s', $q->a({-href=>$uri}, $uri)) . ': ' . $@)); + $str .= $q->p({-class=>'error'}, $q->strong(Ts('RSS parsing failed for %s', $q->a({-href=>$uri}, $uri)) . ': ' . $@)); } else { - my $interwiki; - if (@uris > 1) { - RssInterwikiTranslateInit(); # not needed anywhere else thus init only now and not in ReInit - $interwiki = $rss->{channel}->{$wikins}->{interwiki}; - $interwiki =~ s/^\s+//; # when RDF is used, sometimes whitespace remains, - $interwiki =~ s/\s+$//; # which breaks the test for an existing $interwiki below - if (!$interwiki) { - $interwiki = $rss->{channel}->{$rdfns}->{value}; - } - $interwiki = $RssInterwikiTranslate{$interwiki} if $RssInterwikiTranslate{$interwiki}; - $interwiki = $RssInterwikiTranslate{$uri} unless $interwiki; - } - my $num = 999; - $str .= $q->p({-class=>'error'}, $q->strong(Ts('No items found in %s.', $q->a({-href=>$uri}, $uri)))) - unless @{$rss->{items}}; - foreach my $i (@{$rss->{items}}) { - my $line; - my $date = $i->{dc}->{date}; - if (not $date and $i->{pubDate}) { - $date = $i->{pubDate}; - my %mon = (Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6, - Jul=>7, Aug=>8, Sep=>9, Oct=>10, Nov=>11, Dec=>12); - $date =~ s/^(?:[A-Z][a-z][a-z], )?(\d\d?) ([A-Z][a-z][a-z]) (\d\d(?:\d\d)?)/ # pubDate uses RFC 822 - sprintf('%04d-%02d-%02d', ($3 < 100 ? 1900 + $3 : $3), $mon{$2}, $1)/e; - } - $date = sprintf("%03d", $num--) unless $date; # for RSS 0.91 feeds without date, descending - my $title = $i->{title}; - my $description = $i->{description}; - if (not $title and $description) { # title may be missing in RSS 2.00 - $title = $description; - $description = ''; - } - $title = $i->{link} if not $title and $i->{link}; # if description and title are missing - $line .= ' (' . $q->a({-href=>$i->{$wikins}->{diff}}, $tDiff) . ')' - if $i->{$wikins}->{diff}; - $line .= ' (' . $q->a({-href=>$i->{$wikins}->{history}}, $tHistory) . ')' - if $i->{$wikins}->{history}; - if ($title) { - if ($i->{link}) { - $line .= ' ' . $q->a({-href=>$i->{link}, -title=>$date}, - ($interwiki ? $interwiki . ':' : '') . $title); - } else { - $line .= ' ' . $title; - } - } - my $contributor = $i->{dc}->{contributor}; - $contributor = $i->{$wikins}->{username} unless $contributor; - $contributor =~ s/^\s+//; - $contributor =~ s/\s+$//; - $contributor = $i->{$rdfns}->{value} unless $contributor; - $line .= $q->span({-class=>'contributor'}, $q->span(T(' . . . . ')) . $contributor) if $contributor; - if ($description) { - if ($description =~ /div({-class=>'description'}, $description); - } else { - $line .= $q->span({class=>'dash'}, ' – ') . $q->strong({-class=>'description'}, $description); - } - } - while ($lines{$date}) { - $date .= ' '; - } # make sure this is unique - $lines{$date} = $line; - } + my $interwiki; + if (@uris > 1) { + RssInterwikiTranslateInit(); # not needed anywhere else thus init only now and not in ReInit + $interwiki = $rss->{channel}->{$wikins}->{interwiki}; + $interwiki =~ s/^\s+//; # when RDF is used, sometimes whitespace remains, + $interwiki =~ s/\s+$//; # which breaks the test for an existing $interwiki below + if (!$interwiki) { + $interwiki = $rss->{channel}->{$rdfns}->{value}; + } + $interwiki = $RssInterwikiTranslate{$interwiki} if $RssInterwikiTranslate{$interwiki}; + $interwiki = $RssInterwikiTranslate{$uri} unless $interwiki; + } + my $num = 999; + $str .= $q->p({-class=>'error'}, $q->strong(Ts('No items found in %s.', $q->a({-href=>$uri}, $uri)))) + unless @{$rss->{items}}; + foreach my $i (@{$rss->{items}}) { + my $line; + my $date = $i->{dc}->{date}; + if (not $date and $i->{pubDate}) { + $date = $i->{pubDate}; + my %mon = (Jan=>1, Feb=>2, Mar=>3, Apr=>4, May=>5, Jun=>6, + Jul=>7, Aug=>8, Sep=>9, Oct=>10, Nov=>11, Dec=>12); + $date =~ s/^(?:[A-Z][a-z][a-z], )?(\d\d?) ([A-Z][a-z][a-z]) (\d\d(?:\d\d)?)/ # pubDate uses RFC 822 + sprintf('%04d-%02d-%02d', ($3 < 100 ? 1900 + $3 : $3), $mon{$2}, $1)/e; + } + $date = sprintf("%03d", $num--) unless $date; # for RSS 0.91 feeds without date, descending + my $title = $i->{title}; + my $description = $i->{description}; + if (not $title and $description) { # title may be missing in RSS 2.00 + $title = $description; + $description = ''; + } + $title = $i->{link} if not $title and $i->{link}; # if description and title are missing + $line .= ' (' . $q->a({-href=>$i->{$wikins}->{diff}}, $tDiff) . ')' + if $i->{$wikins}->{diff}; + $line .= ' (' . $q->a({-href=>$i->{$wikins}->{history}}, $tHistory) . ')' + if $i->{$wikins}->{history}; + if ($title) { + if ($i->{link}) { + $line .= ' ' . $q->a({-href=>$i->{link}, -title=>$date}, + ($interwiki ? $interwiki . ':' : '') . $title); + } else { + $line .= ' ' . $title; + } + } + my $contributor = $i->{dc}->{contributor}; + $contributor = $i->{$wikins}->{username} unless $contributor; + $contributor =~ s/^\s+//; + $contributor =~ s/\s+$//; + $contributor = $i->{$rdfns}->{value} unless $contributor; + $line .= $q->span({-class=>'contributor'}, $q->span(T(' . . . . ')) . $contributor) if $contributor; + if ($description) { + if ($description =~ /div({-class=>'description'}, $description); + } else { + $line .= $q->span({class=>'dash'}, ' – ') . $q->strong({-class=>'description'}, $description); + } + } + while ($lines{$date}) { + $date .= ' '; + } # make sure this is unique + $lines{$date} = $line; + } } } } @@ -1017,9 +1018,9 @@ sub RSS { if ($key =~ /(\d\d\d\d(?:-\d?\d)?(?:-\d?\d)?)(?:[T ](\d?\d:\d\d))?/) { my ($day, $time) = ($1, $2); if ($day ne $date) { - $str .= '' if $date; # close ul except for the first time where no open ul exists - $date = $day; - $str .= $q->p($q->strong($day)) . '' if $date; # close ul except for the first time where no open ul exists + $date = $day; + $str .= $q->p($q->strong($day)) . '