mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2010-05-02 05:35 am

[dw-free] Warning for Bad Markup

[commit: http://hg.dwscoalition.org/dw-free/rev/ae3c6b7debb8]

http://bugs.dwscoalition.org/show_bug.cgi?id=1579

Give the user a warning message when they edit/post an entry that will
trigger the 'zomg\!bad\!markup\!' error.

Patch by [personal profile] fu.

Files modified:
  • bin/upgrading/en.dat
  • cgi-bin/LJ/CleanHTML.pm
  • cgi-bin/ljprotocol.pl
  • htdocs/editjournal.bml
  • htdocs/editjournal.bml.text
  • htdocs/update.bml
--------------------------------------------------------------------------------
diff -r 7524d97ab0cf -r ae3c6b7debb8 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Sun May 02 05:29:15 2010 +0000
+++ b/bin/upgrading/en.dat	Sun May 02 05:35:12 2010 +0000
@@ -2329,6 +2329,8 @@ protocol.must_revalidate=You need to val
 
 protocol.not_validated=You are currently not validated.  You may continue to use [[sitename]], but please validate your email address for continued use.  See the instructions that were mailed to you when you created your journal, or see [[siteroot]]/support/ for more information.
 
+protocol.parseerror=Your entry has invalid HTML and cannot be displayed properly. It will be hidden behind a cut on your journal and on other people's read pages until you edit your entry and fix it.
+
 protocol.readonly=Your account is temporarily in read-only mode.  Some operations will fail for a few minutes.
 
 s2theme.autogenerated.warning<<
diff -r 7524d97ab0cf -r ae3c6b7debb8 cgi-bin/LJ/CleanHTML.pm
--- a/cgi-bin/LJ/CleanHTML.pm	Sun May 02 05:29:15 2010 +0000
+++ b/cgi-bin/LJ/CleanHTML.pm	Sun May 02 05:35:12 2010 +0000
@@ -141,6 +141,7 @@ sub clean
     my $unsuspend_supportid = $opts->{'unsuspend_supportid'} || 0;
     my $to_external_site = $opts->{to_external_site} || 0;
     my $remove_positioning = $opts->{'remove_positioning'} || 0;
+    my $errref = $opts->{errref};
 
     my @canonical_urls; # extracted links
     my %action = ();
@@ -220,6 +221,7 @@ sub clean
         }
 
         $extra_text = "<div class='ljparseerror'>$extra_text</div>";
+        $$errref = "parseerror" if $errref;
     };
 
     my $htmlcleaner = HTMLCleaner->new(valid_stylesheet => \&LJ::valid_stylesheet_url);
@@ -1330,6 +1332,7 @@ sub clean_event
         'suspend_msg' => $opts->{'suspend_msg'} ? 1 : 0,
         'unsuspend_supportid' => $opts->{'unsuspend_supportid'},
         to_external_site => $opts->{to_external_site} ? 1 : 0,
+        errref => $opts->{errref},
     });
 }
 
diff -r 7524d97ab0cf -r ae3c6b7debb8 cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl	Sun May 02 05:29:15 2010 +0000
+++ b/cgi-bin/ljprotocol.pl	Sun May 02 05:35:12 2010 +0000
@@ -1481,6 +1481,12 @@ sub postevent
     LJ::MemCache::set([$ownerid,"logtext:$clusterid:$ownerid:$jitemid"],
                       [ $req->{'subject'}, $event ]);
 
+    # warn the user of any bad markup errors
+    my $clean_event = $event;
+    my $errref;
+    LJ::CleanHTML::clean_event( \$clean_event, { errref => \$errref } );
+    $res->{message} = translate( $u, $errref, { aopts => "href='$LJ::SITEROOT/editjournal?journal=" . $uowner->user . "&itemid=$ditemid'" } ) if $errref;
+
     # keep track of custom security stuff in other table.
     if ($uselogsec) {
         $uowner->do("INSERT INTO logsec2 (journalid, jitemid, allowmask) ".
@@ -1618,7 +1624,7 @@ sub editevent
 sub editevent
 {
     my ($req, $err, $flags) = @_;
-    my $res;
+    my $res = {};
     my $deleted = 0;
     un_utf8_request($req);
 
@@ -1933,6 +1939,11 @@ sub editevent
         $uowner->dudata_set('L', $itemid, $bytes);
     }
 
+    my $clean_event = $event;
+    my $errref;
+    LJ::CleanHTML::clean_event( \$clean_event, { errref => \$errref } );
+    $res->{message} = translate( $u, $errref, { aopts => "href='$LJ::SITEROOT/editjournal?journal=" . $uowner->user . "&itemid=$ditemid'" } ) if $errref;
+
     # up the revision number
     $req->{'props'}->{'revnum'} = ($curprops{$itemid}->{'revnum'} || 0) + 1;
     $req->{'props'}->{'revtime'} = time();
@@ -1998,7 +2009,7 @@ sub editevent
 
     $uowner->clear_daycounts( $oldevent->{allowmask} + 0 || $oldevent->{security}, $req->{allowmask} + 0 || $req->{security} );
 
-    $res = { itemid => $itemid };
+    $res->{itemid} = $itemid;
     if (defined $oldevent->{'anum'}) {
         $res->{'anum'} = $oldevent->{'anum'};
         $res->{'url'} = LJ::item_link($uowner, $itemid, $oldevent->{'anum'});
@@ -3491,6 +3502,7 @@ sub editevent
         return 0;
     }
 
+    $res->{message} = $rs->{message} if $rs->{message};
     $res->{'success'} = "OK";
     $res->{'itemid'} = $rs->{'itemid'};
     $res->{'anum'} = $rs->{'anum'} if defined $rs->{'anum'};
diff -r 7524d97ab0cf -r ae3c6b7debb8 htdocs/editjournal.bml
--- a/htdocs/editjournal.bml	Sun May 02 05:29:15 2010 +0000
+++ b/htdocs/editjournal.bml	Sun May 02 05:35:12 2010 +0000
@@ -261,6 +261,7 @@ body<=
                 my $j_base = $journalu->journal_base;
                 my $entry_url = LJ::item_link($journalu, $itemid, $res{anum});
                 my $edititemlink = "/editjournal?itemid=$ditemid";
+                my $edit_url = $edititemlink . "&journal=" . $journalu->user;
 
                 # update crosspost if we're posting to our own journal and have
                 # selected crosspost.
@@ -296,6 +297,8 @@ body<=
                 my $result = "<?h1 $ML{'.success.head'} h1?>";
                 $result .= "<table border='0' width='100%'><tr valign='top'><td>";
 
+                my $message;
+
                 if ($deleted) {
                     $result .= "<?p $ML{'.success.delete'} p?>";
                     $result .= "<?p $ML{'.success.deletespam'} p?>" if $POST{'action:deletespam'};
@@ -304,7 +307,9 @@ body<=
                     my $deleted_extras = LJ::Hooks::run_hook('entry_deleted_page_extras');
                     $result .= $deleted_extras if defined $deleted_extras;
                 } else {
+                    $message = LJ::auto_linkify( LJ::ehtml( $res{message} ) );
                     $result .= "<?p $ML{'.success.edited'} p?>";
+                    $result .= "<?p $message p?>" if $message;
                     $result .= $xpost_result;
                     # open a request about the unsuspension if one doesn't already exist
                     if ($POST{'action:saveunsuspend'} && !$entry_obj->prop("unsuspend_supportid") && $LJ::UNSUSPENSION_REQUEST_SPCATID) {
@@ -332,6 +337,7 @@ body<=
 
                 $result .= "<div id='fromhere'>$ML{'.success.fromhere'}<ul>";
                 $result .= "<li><a href='$entry_url'>$ML{'.success.fromhere.viewentry'}</a></li>" unless $deleted;
+                $result .= "<li><a href='$edit_url'>$ML{'.success.fromhere.editentry'}</a></li>" if $message;
                 $result .= "<li><a href='$j_base'>$ML{'.success.fromhere.viewentries'}</a></li>";
                 $result .= "<li><a href='$LJ::SITEROOT/editjournal'>$ML{'.success.fromhere.manageentries'}</a></li>";
                 $result .= "</ul></div>";
diff -r 7524d97ab0cf -r ae3c6b7debb8 htdocs/editjournal.bml.text
--- a/htdocs/editjournal.bml.text	Sun May 02 05:29:15 2010 +0000
+++ b/htdocs/editjournal.bml.text	Sun May 02 05:35:12 2010 +0000
@@ -37,6 +37,8 @@
 
 .success.fromhere=From here you can:
 
+.success.fromhere.editentry=Edit this entry again
+
 .success.fromhere.manageentries=Manage your journal entries
 
 .success.fromhere.viewentries=View journal entries
diff -r 7524d97ab0cf -r ae3c6b7debb8 htdocs/update.bml
--- a/htdocs/update.bml	Sun May 02 05:29:15 2010 +0000
+++ b/htdocs/update.bml	Sun May 02 05:35:12 2010 +0000
@@ -412,9 +412,9 @@ _c?>
 
         if (!$errors) {
             # examine response
-            my $update_message;
+            my $protocol_message;
             if ($res{'success'} eq "OK" && $res{'message'}) {
-                $update_message = LJ::auto_linkify(LJ::ehtml($res{'message'}));
+                $protocol_message = LJ::auto_linkify(LJ::ehtml($res{'message'}));
             }
 
             if ($res{'success'} ne 'OK') {
@@ -467,6 +467,7 @@ _c?>
                     }
 
                     $$body .= BML::ml( $updatemessage, {'aopts' => "href='" . $ju->journal_base . "/'"} );
+                    $$body .= "<br />$protocol_message" if $protocol_message;
                     my $juser = $ju->{'user'};
                     my ($itemid, $anum) = ($res{'itemid'}, $res{'anum'});
                     $itemlink = LJ::item_link($ju, $itemid, $anum);
--------------------------------------------------------------------------------
john: British Dr Who Dalek in WWII era poster (To Victory!)

[personal profile] john 2010-05-02 04:08 pm (UTC)(link)
Here via [community profile] the_dw_herald to say how much I want to subscribe to this patch's newsletter. \o/
turlough: large orange flowers in lush green grass ((dw) dreaming of music)

[personal profile] turlough 2010-05-02 04:08 pm (UTC)(link)
Nice!