[dw-free] S2 Entry code cleanup
[commit: http://hg.dwscoalition.org/dw-free/rev/d178217cf6d6]
http://bugs.dwscoalition.org/show_bug.cgi?id=2479
Code cleanup: refactor the code that handles the escaping of HTML when
viewing an entry with ?nohtml=1
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2479
Code cleanup: refactor the code that handles the escaping of HTML when
viewing an entry with ?nohtml=1
Patch by
Files modified:
- cgi-bin/LJ/CleanHTML.pm
- cgi-bin/LJ/S2.pm
- cgi-bin/LJ/S2/EntryPage.pm
- htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 648857570a1f -r d178217cf6d6 cgi-bin/LJ/CleanHTML.pm
--- a/cgi-bin/LJ/CleanHTML.pm Tue Apr 13 06:28:29 2010 -0700
+++ b/cgi-bin/LJ/CleanHTML.pm Tue Apr 13 07:15:22 2010 -0700
@@ -1440,4 +1440,13 @@ sub break_word {
return $word;
}
+sub quote_html {
+ my ( $string, $bool ) = @_;
+ return $string unless $bool;
+
+ # quote all non-LJ tags
+ $string =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
+ return $string;
+}
+
1;
diff -r 648857570a1f -r d178217cf6d6 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Tue Apr 13 06:28:29 2010 -0700
+++ b/cgi-bin/LJ/S2.pm Tue Apr 13 07:15:22 2010 -0700
@@ -1907,12 +1907,8 @@ sub Entry_from_entryobj
my $style_args = LJ::viewing_style_args( %$get, %opt_stylemine );
#load and prepare subject and text of entry
- my $subject = $entry_obj->subject_html;
- my $text = $entry_obj->event_raw;
- if ( $get->{nohtml} ) {
- $subject =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- $text =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ my $subject = LJ::CleanHTML::quote_html( $entry_obj->subject_html, $get->{nohtml} );
+ my $text = LJ::CleanHTML::quote_html( $entry_obj->event_raw, $get->{nohtml} );
LJ::item_toutf8( $journal, \$subject, \$text, $entry_obj->props ) if $LJ::UNICODE && $entry_obj->props->{unknown8bit};
my $suspend_msg = $entry_obj && $entry_obj->should_show_suspend_msg_to( $remote ) ? 1 : 0;
diff -r 648857570a1f -r d178217cf6d6 cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm Tue Apr 13 06:28:29 2010 -0700
+++ b/cgi-bin/LJ/S2/EntryPage.pm Tue Apr 13 07:15:22 2010 -0700
@@ -141,11 +141,7 @@ sub EntryPage
my $pu = $com->{'posterid'} ? $user{$com->{'posterid'}} : undef;
my $dtalkid = $com->{'talkid'} * 256 + $entry->anum;
- my $text = $com->{'body'};
- if ($get->{'nohtml'}) {
- # quote all non-LJ tags
- $text =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ my $text = LJ::CleanHTML::quote_html( $com->{body}, $get->{nohtml} );
LJ::CleanHTML::clean_comment(\$text, { 'preformatted' => $com->{'props'}->{'opt_preformatted'},
'anon_comment' => !$pu || ( $pu->is_identity && !$u->trusts_or_has_member( $pu ) ),
@@ -491,13 +487,8 @@ sub EntryPage_entry
@taglist = sort { $a->{name} cmp $b->{name} } @taglist;
}
- my $subject = $entry->subject_html;
- my $event = $entry->event_html;
- if ($get->{'nohtml'}) {
- # quote all non-LJ tags
- $subject =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- $event =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ my $subject = LJ::CleanHTML::quote_html( $entry->subject_html, $get->{nohtml} );
+ my $event = LJ::CleanHTML::quote_html( $entry->event_html, $get->{nohtml} );
if ($opts->{enable_tags_compatibility} && @taglist) {
$event .= LJ::S2::get_tags_text($opts->{ctx}, \@taglist);
diff -r 648857570a1f -r d178217cf6d6 htdocs/talkread.bml
--- a/htdocs/talkread.bml Tue Apr 13 06:28:29 2010 -0700
+++ b/htdocs/talkread.bml Tue Apr 13 07:15:22 2010 -0700
@@ -384,21 +384,14 @@ body<=
###
if ($item->{'subject'}) {
- my $subject = $item->{'subject'};
- if ($GET{'nohtml'}) {
- # quote all non-LJ tags
- $subject =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ my $subject = LJ::CleanHTML::quote_html( $item->{subject}, $GET{nohtml} );
LJ::CleanHTML::clean_subject(\$subject);
BML::ebml(\$subject);
$ret .= "<div id='entrysubj'>$subject</div><br />\n";
}
- if ($GET{'nohtml'}) {
- # quote all non-LJ tags
- $event =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ $event = LJ::CleanHTML::quote_html( $event, $GET{nohtml} );
$ret .= $event;
$ret .= "</div>";
@@ -692,11 +685,7 @@ body<=
'anon_comment' => !$pu || ( $pu->is_identity && !$u->trusts_or_has_member( $pu ) ),
});
BML::ebml(\$post->{'body'});
- my $event = $post->{'body'};
- if ($GET{'nohtml'}) {
- # quote all non-LJ tags
- $event =~ s{<(?!/?lj)(.*?)>} {<$1>}gi;
- }
+ my $event = LJ::CleanHTML::quote_html( $post->{body}, $GET{nohtml} );
my $edit_html = $edittime ? "<br /><br /><span class='edittime'><em>" . BML::ml('.edittime', { editreason => $editreason, edittime => $edittime }) . "</em></span>" : "";
$ret .= "$event$edit_html";
--------------------------------------------------------------------------------
