edit-cluster.pl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # Copyright (C) 2005–2015 Alex Schroeder <alex@gnu.org>
  2. # Copyright (C) 2014–2015 Aleks-Daniel Jakimenko <alex.jakimenko@gmail.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation; either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('edit-cluster.pl', 'Edit Cluster Extension');
  18. our ($q, $FS, $RcDefault, @RcDays, $RecentTop, $LastUpdate, $ShowAll);
  19. our $EditCluster = 'EditCluster';
  20. sub GetRc {
  21. my $printDailyTear = shift;
  22. my $printRCLine = shift;
  23. my @outrc = @_;
  24. my %extra = ();
  25. my %changetime = ();
  26. # note that minor edits have no effect!
  27. foreach my $rcline (@outrc) {
  28. my ($ts, $pagename) = split(/$FS/, $rcline);
  29. $changetime{$pagename} = $ts;
  30. }
  31. my $date = '';
  32. my $all = GetParam('all', $ShowAll);
  33. my ($idOnly, $userOnly, $hostOnly, $clusterOnly, $filterOnly, $match, $lang) =
  34. map { GetParam($_, ''); }
  35. ('rcidonly', 'rcuseronly', 'rchostonly', 'rcclusteronly',
  36. 'rcfilteronly', 'match', 'lang');
  37. my @clusters = $q->param('clusters'); # the clusters the user is interested in
  38. my $ordinary = 0;
  39. my %wanted_clusters = ();
  40. foreach (@clusters) {
  41. if ($_ eq T('ordinary changes')) {
  42. $ordinary = 1;
  43. } else {
  44. $wanted_clusters{$_} = 1;
  45. }
  46. }
  47. $wanted_clusters{$clusterOnly} = $clusterOnly;
  48. @outrc = reverse @outrc;
  49. my @filters;
  50. @filters = SearchTitleAndBody($filterOnly) if $filterOnly;
  51. foreach my $rcline (@outrc) {
  52. my ($ts, $pagename, $minor, $summary, $host, $username, $revision, $languages, $cluster)
  53. = split(/$FS/, $rcline);
  54. next if not $all and $ts < $changetime{$pagename};
  55. next if $idOnly and $idOnly ne $pagename;
  56. next if $match and $pagename !~ /$match/i;
  57. next if $hostOnly and $host !~ /$hostOnly/i;
  58. next if $filterOnly and not grep(/^$pagename$/, @filters);
  59. next if ($userOnly and $userOnly ne $username);
  60. my @languages = split(/,/, $languages);
  61. next if ($lang and @languages and not grep(/$lang/, @languages));
  62. # meatball summary clustering
  63. my %cluster = (); # the clusters of the page
  64. $cluster{$cluster} = 1 if $cluster;
  65. while ($summary =~ /^\[(.*)\]/g) {
  66. my $group = $1;
  67. $group = join(',', sort(split(/\s*,\s*/, $group)));
  68. $cluster{$group} = 1;
  69. }
  70. # user wants no cluster but page has cluster
  71. next if not %wanted_clusters and %cluster;
  72. # users wants clusters, so must match with clusters of the page;
  73. # if page has no clusters and user wants ordinary pages, skip the
  74. # test.
  75. if ($ordinary and not %cluster) {
  76. # don't skip it
  77. } elsif (%wanted_clusters) {
  78. my $show = 1;
  79. foreach my $cluster (keys %cluster) { # assuming "fr,CopyEdit"
  80. foreach my $member (split(/,/, $cluster)) { # eg. "fr"
  81. if ($cluster{$cluster}) {
  82. $show = 1;
  83. last;
  84. } else {
  85. }
  86. next unless $show;
  87. }
  88. }
  89. }
  90. if ($date ne CalcDay($ts)) {
  91. $date = CalcDay($ts);
  92. &$printDailyTear($date);
  93. }
  94. &$printRCLine($pagename, $ts, $host, $username, $summary, 0, $revision,
  95. \@languages, $cluster);
  96. }
  97. }
  98. *EditClusterOldRcHeader = \&RcHeader;
  99. *RcHeader = \&EditClusterNewRcHeader;
  100. sub EditClusterNewRcHeader {
  101. if (GetParam('from', 0)) {
  102. print $q->h2(Ts('Updates since %s', TimeToText(GetParam('from', 0))));
  103. } else {
  104. print $q->h2((GetParam('days', $RcDefault) != 1)
  105. ? Ts('Updates in the last %s days', GetParam('days', $RcDefault))
  106. : Ts('Updates in the last day'))
  107. }
  108. my $action;
  109. my ($idOnly, $userOnly, $hostOnly, $clusterOnly, $filterOnly, $match, $lang) =
  110. map {
  111. my $val = GetParam($_, '');
  112. print $q->p($q->b('(' . Ts('for %s only', $val) . ')')) if $val;
  113. $action .= ";$_=$val" if $val; # remember these parameters later!
  114. $val;
  115. }
  116. ('rcidonly', 'rcuseronly', 'rchostonly', 'rcclusteronly',
  117. 'rcfilteronly', 'match', 'lang');
  118. if ($clusterOnly) {
  119. $action = GetPageParameters('browse', $clusterOnly) . $action;
  120. } else {
  121. $action = "action=rc$action";
  122. }
  123. my $days = GetParam('days', $RcDefault);
  124. my $all = GetParam('all', $ShowAll);
  125. my @menu;
  126. if ($all) {
  127. push(@menu, ScriptLink("$action;days=$days;all=0",
  128. T('List latest change per page only'),'','','','',1));
  129. } else {
  130. push(@menu, ScriptLink("$action;days=$days;all=1",
  131. T('List all changes'),'','','','',1));
  132. }
  133. print $q->p((map { ScriptLink("$action;days=$_;all=$all",
  134. ($_ != 1) ? Ts('%s days', $_) : Ts('%s days', $_),'','','','',1);
  135. } @RcDays), $q->br(), @menu, $q->br(),
  136. ScriptLink($action . ';from=' . ($LastUpdate + 1) . ";all=$all",
  137. T('List later changes')));
  138. my @clusters = ((map { /\* (\S+)/; $1; }
  139. grep(/^\* /, split(/\n/, GetPageContent($EditCluster)))),
  140. T('ordinary changes'));
  141. return unless @clusters;
  142. my $form = GetFormStart(undef, 'get') . $q->checkbox_group('clusters', \@clusters);
  143. $form .= $q->input({-type=>'hidden', -name=>'action', -value=>'rc'});
  144. $form .= $q->input({-type=>'hidden', -name=>'all', -value=>1}) if $all;
  145. $form .= $q->input({-type=>'hidden', -name=>'days', -value=>$days}) if $days != $RcDefault;
  146. $form .= $q->input({-type=>'hidden', -name=>'rcfilteronly', -value=>$filterOnly}) if $filterOnly;
  147. $form .= $q->input({-type=>'hidden', -name=>'rcuseronly', -value=>$userOnly}) if $userOnly;
  148. $form .= $q->input({-type=>'hidden', -name=>'rchostonly', -value=>$hostOnly}) if $hostOnly;
  149. $form .= $q->input({-type=>'hidden', -name=>'match', -value=>$match}) if $match;
  150. $form .= $q->input({-type=>'hidden', -name=>'lang', -value=>$lang}) if $lang;
  151. print $form, ' ', $q->submit(T('Go!')), $q->end_form();
  152. }