123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- use strict;
- use v5.10;
- AddModuleDescription('journal-rss.pl', 'Journal RSS Extension');
- our ($OpenPageName, $CollectingJournal, %Page, %Action, @MyInitVariables, $DeletedPage, %NearLinksException,
- $RecentLink, $SiteName, $SiteDescription, $ScriptName, $RssRights);
- $Action{journal} = \&DoJournalRss;
- sub DoJournalRss {
- return if $CollectingJournal;
- local $CollectingJournal = 1;
-
- local *GetRcLines = \&JournalRssGetRcLines;
- local *RcSelfWebsite = \&JournalRssSelfWebsite;
- local *RcSelfAction = \&JournalRssSelfAction;
- local *RcPreviousAction = \&JournalRssPreviousAction;
- local *RcLastAction = \&JournalRssLastAction;
- SetParam('full', 1);
- if (GetParam('raw', 0)) {
- print GetHttpHeader('text/plain');
- print RcTextItem('title', $SiteName),
- RcTextItem('description', $SiteDescription), RcTextItem('link', $ScriptName),
- RcTextItem('generator', 'Oddmuse'), RcTextItem('rights', $RssRights);
- ProcessRcLines(sub {}, \&RcTextRevision);
- } else {
- print GetHttpHeader('application/xml') . GetRcRss();
- }
- }
- sub JournalRssParameters {
- my $more = '';
- foreach (@_, qw(rsslimit match search reverse monthly)) {
- my $val = GetParam($_, '');
- $more .= ";$_=" . UrlEncode($val) if $val;
- }
- return $more;
- }
- sub JournalRssSelfWebsite {
- my $more = '';
- my $search = GetParam('rcfilteronly', '');
- $more .= ";search=" . UrlEncode($search) if $search;
- my $match = GetParam('match', '');
- $more .= ";match=" . UrlEncode($match) if $match;
- return $more;
- }
- sub JournalRssSelfAction {
- return "action=journal" . JournalRssParameters(qw(offset));
- }
- sub JournalRssPreviousAction {
- my $num = GetParam('rsslimit', 10);
- my $offset = GetParam('offset', 0) + $num;
- return "action=journal;offset=$offset" . JournalRssParameters();
- }
- sub JournalRssLastAction {
- return "action=journal" . JournalRssParameters();
- }
- sub JournalRssGetRcLines {
- my $num = GetParam('rsslimit', 10);
- my $match = GetParam('match', '^\d\d\d\d-\d\d-\d\d');
- my $search = GetParam('search', '');
- my $reverse = GetParam('reverse', 0);
- my $monthly = GetParam('monthly', 0);
- my $offset = GetParam('offset', 0);
- my @pages = sort JournalSort (Matched($match, $search ? SearchTitleAndBody($search) : AllPagesList()));
- if ($monthly and not $match) {
- my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime();
- $match = '^' . sprintf("%04d-%02d", $year+1900, $mon+1) . '-\d\d';
- }
- if ($reverse) {
- @pages = reverse @pages;
- }
-
- my @result = ();
- my $n = 0;
- foreach my $id (@pages) {
-
- local %Page;
- local $OpenPageName = '';
- OpenPage($id);
-
-
-
-
- if ($Page{minor} and $Page{lastmajor}) {
- my %major = GetKeptRevision($Page{lastmajor});
- $Page{ts} = $major{ts} if $major{ts};
- }
- next if $Page{text} =~ /^\s*$/;
- next if $DeletedPage && substr($Page{text}, 0, length($DeletedPage))
- eq $DeletedPage;
-
- $n++;
- next if $n <= $offset;
-
-
-
-
-
- my @languages = split(/,/, $Page{languages});
- push (@result, [$Page{ts}, $id, $Page{minor}, $Page{summary}, $Page{host},
- $Page{username}, $Page{revision}, \@languages,
- GetCluster($Page{text})]);
- last if @result >= $num;
- }
- return @result;
- }
- push(@MyInitVariables, sub {
- $NearLinksException{journal} = 1;
- });
|