diff --git a/modules/fix-encoding.pl b/modules/fix-encoding.pl index 3d0f68fa..7834e828 100644 --- a/modules/fix-encoding.pl +++ b/modules/fix-encoding.pl @@ -24,7 +24,20 @@ sub FixEncoding { OpenPage($id); my $text = $Page{text}; utf8::decode($text); - Save($id, $text, 'fix encoding', 1) if $text ne $Page{text}; + Save($id, $text, T('Fix character encoding'), 1) if $text ne $Page{text}; + ReleaseLock(); + ReBrowsePage($id); +} + +$Action{'fix-escaping'} = \&FixEscaping; + +sub FixEscaping { + my $id = shift; + ValidIdOrDie($id); + RequestLockOrError(); + OpenPage($id); + my $text = UnquoteHtml($Page{text}); + Save($id, $text, T('Fix HTML escapes'), 1) if $text ne $Page{text}; ReleaseLock(); ReBrowsePage($id); } @@ -35,6 +48,10 @@ sub FixEncodingMenu { my ($id, $menuref, $restref) = @_; if ($id) { push(@$menuref, - ScriptLink('action=fix-encoding;id=' . UrlEncode($id), T('Fix page encoding'))); + ScriptLink('action=fix-encoding;id=' . UrlEncode($id), + T('Fix character encoding'))); + push(@$menuref, + ScriptLink('action=fix-escaping;id=' . UrlEncode($id), + T('Fix HTML escapes'))); } } diff --git a/modules/translations/german-utf8.pl b/modules/translations/german-utf8.pl index fabcb33a..d0640b38 100644 --- a/modules/translations/german-utf8.pl +++ b/modules/translations/german-utf8.pl @@ -672,7 +672,7 @@ ordinary changes normale Änderungen Matching page names: Übereinstimmende Seitennamen: -Fix page encoding +Fix character encoding Zeichenkodierung korrigieren no summary available keine Zusammenfassug vorhanden diff --git a/t/fix-encoding.t b/t/fix-encoding.t index 2ce03408..a7a8efd7 100644 --- a/t/fix-encoding.t +++ b/t/fix-encoding.t @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Alex Schroeder +# Copyright (C) 2012–2013 Alex Schroeder # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software @@ -14,7 +14,7 @@ require 't/test.pl'; package OddMuse; -use Test::More tests => 12; +use Test::More tests => 20; use utf8; # tests contain UTF-8 characters and it matters clear_pages(); @@ -26,14 +26,19 @@ test_page_negative(get_page('action=admin'), 'action=fix-encoding'); # make sure no menu shows up if the page does not exists -test_page(get_page('action=admin id=foo'), 'action=fix-encoding;id=foo'); +test_page(get_page('action=admin id=foo'), + 'action=fix-encoding;id=foo', + 'action=fix-escaping;id=foo'); # make sure nothing is saved if the page does not exist test_page(get_page('action=fix-encoding id=Example'), 'Location: http://localhost/wiki.pl/Example'); -test_page_negative(get_page('action=rc showedit=1'), 'fix encoding'); +test_page(get_page('action=fix-escaping id=Example'), + 'Location: http://localhost/wiki.pl/Example'); + +test_page_negative(get_page('action=rc all=1 showedit=1'), 'fix'); # make sure nothing is saved if there is no change @@ -43,14 +48,19 @@ test_page(update_page('Example', 'Pilgerstätte für die Göttin'), test_page(get_page('action=fix-encoding id=Example'), 'Location: http://localhost/wiki.pl/Example'); -test_page_negative(get_page('action=rc showedit=1'), 'fix encoding'); +test_page(get_page('action=fix-escaping id=Example'), + 'Location: http://localhost/wiki.pl/Example'); + +test_page_negative(get_page('action=rc all=1 showedit=1'), + 'Fix Character encoding'); # the menu shows up if the page exists test_page(get_page('action=admin id=Example'), - 'action=fix-encoding;id=Example'); + 'action=fix-encoding;id=Example', + 'action=fix-escaping;id=Example'); -# here is an actual page you need to fix +# here is an actual page with a character encoding error you need to fix test_page(update_page('Example', 'Pilgerstätte für die Göttin', 'borked encoding'), @@ -62,4 +72,20 @@ test_page(get_page('action=fix-encoding id=Example'), test_page(get_page('Example'), 'Pilgerstätte für die Göttin'); -test_page(get_page('action=rc showedit=1'), 'fix encoding'); +test_page(get_page('action=rc showedit=1'), + 'Fix character encoding'); + +# here is an actual page with an HTML escaping error you need to fix + +test_page(update_page('Example', '&lt;b&gt;bold&lt;/b&gt;', + 'borked escaping'), + '&lt;b&gt;bold&lt;/b&gt;'); + +test_page(get_page('action=fix-escaping id=Example'), + 'Location: http://localhost/wiki.pl/Example'); + +test_page(get_page('Example'), + '<b>bold</b>'); + +test_page(get_page('action=rc showedit=1'), + 'Fix HTML escapes');