sabifoo.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('sabifoo.pl', 'Sabifoo');
  18. our (%IndexHash, @MyInitVariables);
  19. our ($SummaryDefaultLength);
  20. push(@MyInitVariables, \&SabiFooInit);
  21. sub SabiFooInit {
  22. my $text = UnquoteHtml(GetParam('sabifoo_message', ''));
  23. if ($text) {
  24. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
  25. my $today = sprintf("%02d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  26. my $title = '';
  27. if ($text =~ m/^\s*==\s*(.*?)\s*==\s*(.*)/) {
  28. $title = $1;
  29. $text = $2;
  30. }
  31. # base summary on the text added this time only, without title
  32. my $summary = $text;
  33. if (length($summary) > $SummaryDefaultLength) {
  34. $summary = substr($summary, 0, $SummaryDefaultLength);
  35. $summary =~ s/\s*\S*$/ . . ./;
  36. }
  37. # append to existing page!
  38. $title = FreeToNormal($today . ' ' . $title);
  39. if ($IndexHash{$title}) {
  40. $text = GetPageContent($title) . "\n\n" . $text;
  41. }
  42. my $username = GetParam('sabifoo_author');
  43. $username =~ s/@.*//;
  44. SetParam('title', $title);
  45. SetParam('text', $text);
  46. SetParam('username', $username);
  47. SetParam('summary', 'x' . $summary);
  48. }
  49. }