wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / rc-simple.pl
blob5692be67e1af187b585c8395010ce2426c722618
1 # Copyright (C) 2004 Tilmann Holst
2 # Copyright (C) 2004, 2005, 2007 Alex Schroeder <alex@emacswiki.org>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/rc-simple.pl">rc-simple.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Rc_Simple_Extension">Rc Simple Extension</a></p>';
19 sub RcSimpleHtml {
20 my $maxEntries = shift;
21 my @html = ();
22 # Optimize param fetches and translations out of main loop
23 my $all = GetParam('all', 0);
24 my $printRCLine = sub {
25 my($id, $ts, $host, $username, $summary, $minor, $revision,
26 $languages, $cluster, $last) = @_;
27 my $all_revision = $last ? undef : $revision; # no revision for the last one
28 my $pagelink = '';
29 if ($all) {
30 $pagelink = GetOldPageLink('browse', $id, $all_revision, $id, $cluster);
31 } elsif ($cluster) {
32 $pagelink = GetOldPageLink('browse', $id, $revision, $id, $cluster);
33 } else {
34 $pagelink = GetPageLink($id, $cluster);
36 push (@html, $pagelink);
38 ProcessRcLines(sub {}, $printRCLine);
39 my $to = GetParam('from', $Now - GetParam('days', $RcDefault) * 86400);
40 my $from = $to - GetParam('days', $RcDefault) * 86400;
41 my $more = "action=rc;from=$from;upto=$to";
42 foreach (qw(all showedit rollback rcidonly rcuseronly rchostonly
43 rcclusteronly rcfilteronly match lang followup)) {
44 my $val = GetParam($_, '');
45 $more .= ";$_=$val" if $val;
47 push(@html, $q->p({-class=>'more'}, ScriptLink($more, T('More...'), 'more')));
48 return (@html <= $maxEntries) ? @html : @html[0..$maxEntries-1];
51 push(@MyRules, \&RcSimpleRule);
53 sub RcSimpleRule {
54 if (m/\G(\&lt;rc(:(\d+))?\&gt;)/gci) {
55 my $maxEntries = $3;
56 return unless $maxEntries;
57 return if ($maxEntries <= 0);
58 my @recentPages = RcSimpleHtml($maxEntries);
59 Clean(CloseHtmlEnvironments());
60 Dirty($1);
61 print $q->div({-class=>'rc'}, $q->span(\@recentPages));
62 return AddHtmlEnvironment('p');
64 return undef;