Add facility to fix HTML escaping.

This commit is contained in:
Alex Schroeder
2013-10-20 20:00:30 +02:00
parent 2936ace022
commit 7c52b7b4c2
3 changed files with 54 additions and 11 deletions

View File

@@ -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')));
}
}

View File

@@ -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

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2012 Alex Schroeder <alex@gnu.org>
# Copyright (C) 20122013 Alex Schroeder <alex@gnu.org>
#
# 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', '&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;',
'borked escaping'),
'&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;');
test_page(get_page('action=fix-escaping id=Example'),
'Location: http://localhost/wiki.pl/Example');
test_page(get_page('Example'),
'&lt;b&gt;bold&lt;/b&gt;');
test_page(get_page('action=rc showedit=1'),
'Fix HTML escapes');