wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / edit-cluster.pl
blob069041e991a64d8eb8124a738fe764e309f1341d
1 $EditCluster = 'EditCluster';
3 sub GetRc {
4 my $printDailyTear = shift;
5 my $printRCLine = shift;
6 my @outrc = @_;
7 my %extra = ();
8 my %changetime = ();
9 # note that minor edits have no effect!
10 foreach my $rcline (@outrc) {
11 my ($ts, $pagename) = split(/$FS/, $rcline);
12 $changetime{$pagename} = $ts;
14 my $date = '';
15 my $all = GetParam('all', 0);
16 my ($idOnly, $userOnly, $hostOnly, $clusterOnly, $filterOnly, $match, $lang) =
17 map { GetParam($_, ''); }
18 ('rcidonly', 'rcuseronly', 'rchostonly', 'rcclusteronly',
19 'rcfilteronly', 'match', 'lang');
20 my @clusters = $q->param('clusters'); # the clusters the user is interested in
21 my $ordinary = 0;
22 my %wanted_clusters = ();
23 foreach (@clusters) {
24 if ($_ eq T('ordinary changes')) {
25 $ordinary = 1;
26 } else {
27 $wanted_clusters{$_} = 1;
30 $wanted_clusters{$clusterOnly} = $clusterOnly;
31 @outrc = reverse @outrc if GetParam('newtop', $RecentTop);
32 my @filters;
33 @filters = SearchTitleAndBody($filterOnly) if $filterOnly;
34 foreach my $rcline (@outrc) {
35 my ($ts, $pagename, $minor, $summary, $host, $username, $revision, $languages, $cluster)
36 = split(/$FS/, $rcline);
37 next if not $all and $ts < $changetime{$pagename};
38 next if $idOnly and $idOnly ne $pagename;
39 next if $match and $pagename !~ /$match/i;
40 next if $hostOnly and $host !~ /$hostOnly/i;
41 next if $filterOnly and not grep(/^$pagename$/, @filters);
42 next if ($userOnly and $userOnly ne $username);
43 my @languages = split(/,/, $languages);
44 next if ($lang and @languages and not grep(/$lang/, @languages));
45 # meatball summary clustering
46 my %cluster = (); # the clusters of the page
47 $cluster{$cluster} = 1 if $cluster;
48 while ($summary =~ /^\[(.*)\]/g) {
49 my $group = $1;
50 $group = join(',', sort(split(/\s*,\s*/, $group)));
51 $cluster{$group} = 1;
53 # user wants no cluster but page has cluster
54 next if not %wanted_clusters and %cluster;
55 # users wants clusters, so must match with clusters of the page;
56 # if page has no clusters and user wants ordinary pages, skip the
57 # test.
58 if ($ordinary and not %cluster) {
59 # don't skip it
60 } elsif (%wanted_clusters) {
61 my $show = 1;
62 foreach my $cluster (keys %cluster) { # assuming "fr,CopyEdit"
63 foreach $member (split(/,/, $cluster)) { # eg. "fr"
64 if ($cluster{$cluster}) {
65 $show = 1;
66 last;
67 } else {
69 next unless $show;
73 if ($date ne CalcDay($ts)) {
74 $date = CalcDay($ts);
75 &$printDailyTear($date);
77 &$printRCLine($pagename, $ts, $host, $username, $summary, 0, $revision,
78 \@languages, $cluster);
82 *EditClusterOldRcHeader = *RcHeader;
83 *RcHeader = *EditClusterNewRcHeader;
85 sub EditClusterNewRcHeader {
86 if (GetParam('from', 0)) {
87 print $q->h2(Ts('Updates since %s', TimeToText(GetParam('from', 0))));
88 } else {
89 print $q->h2((GetParam('days', $RcDefault) != 1)
90 ? Ts('Updates in the last %s days', GetParam('days', $RcDefault))
91 : Ts('Updates in the last %s day', GetParam('days', $RcDefault)))
93 my $action;
94 my ($idOnly, $userOnly, $hostOnly, $clusterOnly, $filterOnly, $match, $lang) =
95 map {
96 my $val = GetParam($_, '');
97 print $q->p($q->b('(' . Ts('for %s only', $val) . ')')) if $val;
98 $action .= ";$_=$val" if $val; # remember these parameters later!
99 $val;
101 ('rcidonly', 'rcuseronly', 'rchostonly', 'rcclusteronly',
102 'rcfilteronly', 'match', 'lang');
103 if ($clusterOnly) {
104 $action = GetPageParameters('browse', $clusterOnly) . $action;
105 } else {
106 $action = "action=rc$action";
108 my $days = GetParam('days', $RcDefault);
109 my $all = GetParam('all', 0);
110 my @menu;
111 if ($all) {
112 push(@menu, ScriptLink("$action;days=$days;all=0",
113 T('List latest change per page only'),'','','','',1));
114 } else {
115 push(@menu, ScriptLink("$action;days=$days;all=1",
116 T('List all changes'),'','','','',1));
118 print $q->p((map { ScriptLink("$action;days=$_;all=$all",
119 ($_ != 1) ? Ts('%s days', $_) : Ts('%s days', $_),'','','','',1);
120 } @RcDays), $q->br(), @menu, $q->br(),
121 ScriptLink($action . ';from=' . ($LastUpdate + 1) . ";all=$all",
122 T('List later changes')));
123 my @clusters = ((map { /\* (\S+)/; $1; }
124 grep(/^\* /, split(/\n/, GetPageContent($EditCluster)))),
125 T('ordinary changes'));
126 return unless @clusters;
127 my $form = GetFormStart(undef, 'get') . $q->checkbox_group('clusters', \@clusters);
128 $form .= $q->input({-type=>'hidden', -name=>'action', -value=>'rc'});
129 $form .= $q->input({-type=>'hidden', -name=>'all', -value=>1}) if $all;
130 $form .= $q->input({-type=>'hidden', -name=>'days', -value=>$days}) if $days != $RcDefault;
131 $form .= $q->input({-type=>'hidden', -name=>'rcfilteronly', -value=>$rcfilteronly}) if $rcfilteronly;
132 $form .= $q->input({-type=>'hidden', -name=>'rcuseronly', -value=>$rcuseronly}) if $rcuseronly;
133 $form .= $q->input({-type=>'hidden', -name=>'rchostonly', -value=>$rchostonly}) if $rchostonly;
134 $form .= $q->input({-type=>'hidden', -name=>'match', -value=>$match}) if $match;
135 $form .= $q->input({-type=>'hidden', -name=>'lang', -value=>$lang}) if $lang;
136 print $form, ' ', $q->submit(T('Go!')), $q->end_form();