Ticket #198: earle-banned-wordlist.patch
| File earle-banned-wordlist.patch, 5.6 kB (added by dom, 20 months ago) |
|---|
-
templates/banned_content.tt
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 <html> 4 <head> 5 <title>Edit Forbidden</title> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 </head> 8 <body> 9 <h1>Edit Forbidden</h1> 10 <p> 11 Sorry. Somewhere in the edit you just tried to make, there was a word or phrase 12 that the site's administrator has chosen to prohibit. Please contact the site 13 administrator at <a href="mailto:[% contact_email %]">[% contact_email %]</a> 14 with the <strong>complete</strong> text of your edit (including both the main 15 content and any optional details you entered) for assistance. 16 </p> 17 </body> 18 </html> 19 No newline at end of file -
lib/OpenGuides/Config.pm
20 20 centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 21 21 licence_name licence_url licence_info_url moderation_requires_password 22 22 enable_node_image enable_common_categories enable_common_locales 23 banned_content 23 24 ); 24 25 my @questions = map { $_ . "__qu" } @variables; 25 26 OpenGuides::Config->mk_accessors( @variables ); … … 180 181 google_analytics_key => "Do you have a Google Analytics key to use with this guide? If you enter it here, then Google Analytics functionality will be automatically enabled.", 181 182 licence_name => "What licence will you use for the guide?", 182 183 licence_url => "What is the URL to your licence?", 183 licence_info_url => "What is the URL to your local page about your licensing policy?" 184 licence_info_url => "What is the URL to your local page about your licensing policy?", 185 banned_content => "What words or phrases are forbidden in edits? Space-separated list, use _ to represent a space in a phrase.", 184 186 ); 185 187 186 188 foreach my $var ( keys %questions ) { … … 301 303 302 304 =item * licence_info_url 303 305 306 =item * banned_content 307 304 308 =back 305 309 306 310 =head1 AUTHOR -
lib/OpenGuides.pm
1175 1175 cgi_obj => $q 1176 1176 ); 1177 1177 1178 foreach my $var ( qw( summary username comment edit_type ) ) { 1179 $new_metadata{$var} = $q->param($var) || ""; 1180 } 1181 1182 $new_metadata{host} = $ENV{REMOTE_ADDR}; 1183 1178 1184 delete $new_metadata{website} if $new_metadata{website} eq 'http://'; 1179 1185 1180 1186 $new_metadata{opening_hours_text} = $q->param("hours_text") || ""; … … 1186 1192 $new_metadata{longitude} = delete $new_metadata{longitude_unmunged} 1187 1193 if $new_metadata{longitude_unmunged}; 1188 1194 1195 # Here we examine content and metadata for banned strings. 1196 my $banned_content = $self->banned_content; 1197 1198 foreach my $banned_string (keys %$banned_content) { 1199 return $self->_banned_content_abort({ 1200 node => $node, 1201 where => 'content', 1202 string => $banned_string, 1203 host => $new_metadata{host}, 1204 return_output => $return_output, 1205 }) if $content =~ /$banned_string/im; 1206 } 1207 1208 while ( my ($md_type, $md_val) = each %new_metadata ) { 1209 foreach my $banned_string (keys %$banned_content) { 1210 return $self->_banned_content_abort({ 1211 node => $node, 1212 where => $md_type, 1213 string => $banned_string, 1214 host => $new_metadata{host}, 1215 return_output => $return_output, 1216 }) if $md_val =~ /$banned_string/im; 1217 } 1218 } 1219 1189 1220 # Check to make sure all the indexable nodes are created 1190 1221 # Skip this for nodes needing moderation - this occurs for them once 1191 1222 # they've been moderated … … 1196 1227 ); 1197 1228 } 1198 1229 1199 foreach my $var ( qw( summary username comment edit_type ) ) {1200 $new_metadata{$var} = $q->param($var) || "";1201 }1202 $new_metadata{host} = $ENV{REMOTE_ADDR};1203 1204 1230 # Wiki::Toolkit::Plugin::RSS::ModWiki wants "major_change" to be set. 1205 1231 $new_metadata{major_change} = ( $new_metadata{edit_type} eq "Normal edit" ) 1206 1232 ? 1 … … 1905 1931 return $cookie_data{$pref_name}; 1906 1932 } 1907 1933 1934 # Retrieve banned strings from config and convert them to unmunged form. 1935 sub banned_content { 1936 my $self = shift; 1937 1938 my $banned_content; 1939 1940 # Strings have underscores as spaces due to Config::Tiny limitations. 1941 foreach (split(' ', $self->config->banned_content)) { 1942 $_ =~ s/_/ /g; 1943 $banned_content->{$_} = 1; 1944 } 1945 1946 $banned_content; 1947 } 1908 1948 1949 # Kill an edit if we detect banned content. 1950 sub _banned_content_abort { 1951 my ($self, $args) = @_; 1952 1953 # Don't tell the editor what was banned; ask them to get in touch. Best not 1954 # to give spammers any ideas about how our spam detection works. 1955 my $output = $self->process_template( 1956 template => 'banned_content.tt', 1957 ); 1958 1959 # Put something in the logs. 1960 warn "Edit aborted, banned content detected.\nHost: $args->{host}; node: $args->{node}; where: $args->{where}; string: $args->{string}."; 1961 1962 return $output if $args->{return_output}; 1963 print $output; 1964 } 1965 1909 1966 =head1 BUGS AND CAVEATS 1910 1967 1911 1968 UTF8 data are currently not handled correctly throughout.
