fix-encoding.pl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012 Alex Schroeder <alex@gnu.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('fix-encoding.pl', 'Fix Encoding');
  18. our (%Action, %Page, @MyAdminCode);
  19. $Action{'fix-encoding'} = \&FixEncoding;
  20. sub FixEncoding {
  21. my $id = shift;
  22. ValidIdOrDie($id);
  23. RequestLockOrError();
  24. OpenPage($id);
  25. my $text = decode_utf8($Page{text});
  26. Save($id, $text, T('Fix character encoding'), 1) if $text ne $Page{text};
  27. ReleaseLock();
  28. ReBrowsePage($id);
  29. }
  30. $Action{'fix-escaping'} = \&FixEscaping;
  31. sub FixEscaping {
  32. my $id = shift;
  33. ValidIdOrDie($id);
  34. RequestLockOrError();
  35. OpenPage($id);
  36. my $text = UnquoteHtml($Page{text});
  37. Save($id, $text, T('Fix HTML escapes'), 1) if $text ne $Page{text};
  38. ReleaseLock();
  39. ReBrowsePage($id);
  40. }
  41. push(@MyAdminCode, \&FixEncodingMenu);
  42. sub FixEncodingMenu {
  43. my ($id, $menuref, $restref) = @_;
  44. if ($id && GetParam('username')) {
  45. push(@$menuref,
  46. ScriptLink('action=fix-encoding;id=' . UrlEncode($id),
  47. T('Fix character encoding')));
  48. push(@$menuref,
  49. ScriptLink('action=fix-escaping;id=' . UrlEncode($id),
  50. T('Fix HTML escapes')));
  51. }
  52. }