fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-10-27 10:49 am

[dw-free] Consolidate *all* the places that generate a "this person is deleted" page

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

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

Consolidate the messages for the "this person is deleted" into one place.
Also consolidates the error messages so they all say *the same thing*

Patch by [personal profile] exor674.

Files modified:
  • bin/upgrading/deadphrases.dat
  • bin/upgrading/en.dat
  • cgi-bin/DW/Template.pm
  • cgi-bin/LJ/User.pm
  • htdocs/profile.bml
  • htdocs/profile.bml.text
  • htdocs/talkpost.bml
  • htdocs/talkread.bml
  • htdocs/tools/memories.bml
  • htdocs/view/index.bml
  • views/journal/deleted.tt
  • views/journal/deleted.tt.text
--------------------------------------------------------------------------------
diff -r 1b1e25f28bc8 -r 7a4b5facefdd bin/upgrading/deadphrases.dat
--- a/bin/upgrading/deadphrases.dat	Wed Oct 26 15:00:38 2011 +0800
+++ b/bin/upgrading/deadphrases.dat	Thu Oct 27 18:50:21 2011 +0800
@@ -1482,3 +1482,12 @@
 general /directorysearch.bml.use_this_dir2
 general /directorysearch.bml.week
 general /directorysearch.bml.years_old
+
+general error.deleted.leavecomm
+general error.deleted.name
+general error.deleted.text
+general error.deleted.text.withreason
+general error.deleted.title
+general talk.error.deleted
+general talk.error.deleted.title
+general /profile.bml.error.deleted.purgenotification
diff -r 1b1e25f28bc8 -r 7a4b5facefdd bin/upgrading/en.dat
--- a/bin/upgrading/en.dat	Wed Oct 26 15:00:38 2011 +0800
+++ b/bin/upgrading/en.dat	Thu Oct 27 18:50:21 2011 +0800
@@ -850,16 +850,6 @@
 
 error.dberror=A database error occurred:
 
-error.deleted.leavecomm=If you want, you can <a [[aopts]]>leave the community</a>.
-
-error.deleted.name=Deleted
-
-error.deleted.text=Deleted journal.  If you're [[user]], you have 30 days from the date of deletion to restore the journal.  After 30 days we'll delete all content permanently from our servers.
-
-error.deleted.text.withreason=This journal has been deleted by [[user]], with a reason of: "[[reason]]".  If you are [[user]], you have a period of 30 days from the deletion time to undelete the journal.  After 30 days we will delete all content permanently from our servers.
-
-error.deleted.title=Deleted Account
-
 error.expiredchal=Your login window has expired.  Please try again.
 
 error.guidelines.none=[[user]] has not defined an entry for their community guidelines. See <a [[aopts]]>their profile</a> for further information about the community.
@@ -3875,10 +3865,6 @@
 
 talk.error.comm_deleted=This comment has been deleted.
 
-talk.error.deleted=This journal has been deleted.
-
-talk.error.deleted.title=Deleted
-
 talk.error.mustlogin=You must be logged in to view this protected entry.
 
 talk.error.nocomment=This comment doesn't exist.
diff -r 1b1e25f28bc8 -r 7a4b5facefdd cgi-bin/DW/Template.pm
--- a/cgi-bin/DW/Template.pm	Wed Oct 26 15:00:38 2011 +0800
+++ b/cgi-bin/DW/Template.pm	Thu Oct 27 18:50:21 2011 +0800
@@ -218,6 +218,75 @@
     return $class->render_string( $out, $extra );
 }
 
+=head2 C<< $class->render_template_misc( $filename, $opts, $extra ) >>
+
+Render a template inside the sitescheme or alone.
+This can also be safely called ( with some work on the other side )
+from a BML context and still spit the content where required.
+( Note, the "alone" bit will be ignored from BML contexts )
+
+Can safely directly return this from either trans/Controller, internal journal page generation or (most) BML contexts.
+
+$extra can contain:
+
+=over
+
+=item B< no_sitescheme > == render alone
+
+=item B< title / windowtitle / head / bodyopts / ... > == text to get thrown in the section if inside sitescheme
+
+=item B< content_type > = content type
+
+=item B< status > = HTTP status code
+
+=item B< scope > = Scope, accepts nothing, 'bml', or 'journal'
+
+=item B< scope_data > = Depends on B< scope >
+
+=over
+
+=item B< bml > Hashref of scalar-refs of where to throw the sections
+
+=item B< journal > $opts hashref passed into LJ::make_journal and beyond.
+
+=back 
+
+=back
+
+=cut
+
+# FIXME(dre): Remove this method when BML is completely dead
+#   and refactor the journal scope bits up into render_template or render_string.
+sub render_template_misc {
+    my ( $class, $filename, $opts, $extra ) = @_;
+
+    $extra ||= {};
+    my $out = $class->template_string( $filename, $opts, $extra );
+
+    my $scope = $extra->{scope};
+
+    if ( $scope eq 'bml' ) {
+        my $r = DW::Request->get;
+        my $bml = $extra->{scope_data};
+
+        $r->status( $extra->{status} ) if $extra->{status};
+        $r->content_type( $extra->{content_type} ) if $extra->{content_type};
+
+        for my $item ( qw(title windowtitle head bodyopts) ) {
+            ${$bml->{$item}} = $extra->{$item} || "";
+        }
+        return $out;
+    }
+
+    my $rv =  $class->render_string( $out, $extra );
+    if ( $scope eq 'journal' ) {
+        $extra->{scope_data}->{handler_return} = $rv;
+        return;
+    } else {
+        return $rv;
+    }
+}
+
 =head2 C<< $class->render_string( $string, $extra ) >>
 
 Render a string inside the sitescheme or alone.
diff -r 1b1e25f28bc8 -r 7a4b5facefdd cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Wed Oct 26 15:00:38 2011 +0800
+++ b/cgi-bin/LJ/User.pm	Thu Oct 27 18:50:21 2011 +0800
@@ -5608,6 +5608,31 @@
 =head2 Styles and S2-Related Functions
 =cut
 
+sub display_journal_deleted {
+    my ( $u, $remote, %opts ) = @_;
+    return undef unless LJ::isu( $u );
+
+    my $r = DW::Request->get;
+
+    my $extra = {};
+    if ( $opts{bml} ) {
+        $extra->{scope} = 'bml';
+        $extra->{scope_data} = $opts{bml};
+    } elsif ( $opts{journal_opts} ) {
+        $extra->{scope} = 'journal';
+        $extra->{scope_data} = $opts{journal_opts};
+    }
+
+    my $data = {
+        reason => $u->prop( 'delete_reason' ),
+        u => $u,
+
+        is_member_of => $u->is_community && $u->trusts_or_has_member( $remote ),
+        is_protected => LJ::User->is_protected_username( $u->user ),
+    };
+
+    return DW::Template->render_template_misc( "journal/deleted.tt", $data, $extra );
+}
 # returns undef on error, or otherwise arrayref of arrayrefs,
 # each of format [ year, month, day, count ] for all days with
 # non-zero count.  examples:
@@ -9086,19 +9111,8 @@
 
     unless ( $geta->{'viewall'} && $remote && $remote->has_priv( "canview", "suspended" ) ||
              $opts->{'pathextra'} =~ m!/(\d+)/stylesheet$! ) { # don't check style sheets
-        if ( $u->is_deleted ) {
-            my $warning;
-
-            if ( $u->prop( 'delete_reason' ) ) {
-                $warning = BML::ml( 'error.deleted.text.withreason', { user => $u->display_name, reason => $u->prop( 'delete_reason' ) } );
-            } else {
-                $warning = BML::ml( 'error.deleted.text', { user => $u->display_name } );
-            }
-
-            $warning .= "&nbsp;" . BML::ml( 'error.deleted.leavecomm', { aopts => "href='$LJ::SITEROOT/community/leave?comm=" . $u->user . "'" } ) if $u->is_community && $u->trusts_or_has_member( $remote );
-
-            return $error->( $warning, "404 Not Found", BML::ml( 'error.deleted.name' ) );
-        }
+        return $u->display_journal_deleted( $remote, journal_opts => $opts ) if $u->is_deleted;
+
         if ( $u->is_suspended ) {
             my $warning = BML::ml( 'error.suspended.text', { user => $u->ljuser_display, sitename => $LJ::SITENAME } );
             return $error->( $warning, "403 Forbidden", BML::ml( 'error.suspended.name' ) );
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/profile.bml
--- a/htdocs/profile.bml	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/profile.bml	Thu Oct 27 18:50:21 2011 +0800
@@ -136,22 +136,10 @@
             return "<?h1 $ML{'error.suspended.name'} h1?><?p " . BML::ml( 'error.suspended.text', { user => $u->ljuser_display, sitename => $LJ::SITENAME } ) . " p?>";
         }
         if ( $u->is_deleted ) {
-            BML::set_status(404); # 404 Not Found
-            $title = $ML{'error.deleted.title'};
-            my $del_body = "<?p ";
-
-            if ( $u->prop( 'delete_reason' ) ) {
-                $del_body .= BML::ml( 'error.deleted.text.withreason', { user => $u->display_name, reason => $u->prop( 'delete_reason' ) } );
-            } else {
-                $del_body .= BML::ml( 'error.deleted.text', { user => $u->display_name } );
-            }
-
-            $del_body .= "&nbsp;" . BML::ml( 'error.deleted.leavecomm', { aopts => "href='$LJ::SITEROOT/community/leave?comm=" . $u->user . "'" } ) if $u->is_community && $u->trusts_or_has_member( $remote );
-
-            $del_body .= " p?>";
-            $del_body .= BML::ml( '.error.deleted.purgenotification', { aopts => "href='$LJ::SITEROOT/manage/tracking/user?journal=" . $u->user . "'" } )
-                unless LJ::User->is_protected_username( $u->user );
-            return $del_body;
+            return $u->display_journal_deleted( $remote, bml => {
+                    title => \$title,
+                    windowtitle => \$windowtitle,
+                    head => \$headextra } );
         }
     }
 
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/profile.bml.text
--- a/htdocs/profile.bml.text	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/profile.bml.text	Thu Oct 27 18:50:21 2011 +0800
@@ -137,8 +137,6 @@
 
 .details.warning.explicit=This journal contains content only suitable for those over the age of 18.
 
-.error.deleted.purgenotification=If you'd like to rename your account with this account name, <a [[aopts]]>you can be notified</a> when the account is purged.
-
 .error.malfname=Malformed username.
 
 .feeds.header=Feeds
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/talkpost.bml	Thu Oct 27 18:50:21 2011 +0800
@@ -17,7 +17,7 @@
 <?_code
 {
     use strict;
-    use vars qw($head %FORM %ML %GET $title_user $title_subject);
+    use vars qw($head %FORM %ML %GET $title_user $title_subject $title);
 
     $head = "";  # not local, used to build <link> tags
 
@@ -182,8 +182,11 @@
         if $u->is_readonly;
 
     # check deleted
-    return "<?h1 $ML{'talk.error.deleted.title'} h1?><?p $ML{'talk.error.deleted'} p?>"
-        if ($u->is_deleted);
+    if ( $u->is_deleted ) {
+        return $u->display_journal_deleted( $remote, bml => {
+                title => \$title,
+                head => \$head } );
+    }
 
     # check suspended entry
     # reply page of suspended entry cannot be accessed by anyone, even entry poster
@@ -401,9 +404,10 @@
 _code?>
 
 <=body
+title=> <?_code return $title _code?>
 head<=
 <?_code return $head _code?>
 <?_code return (! $LJ::REQ_HEAD_HAS{'chalresp_js'}++) ? $LJ::COMMON_CODE{'chalresp_js'} : ""; _code?>
 <=head
-windowtitle=> <?_code "$title_user : $title_subject $ML{'.title'}" _code?>
+windowtitle=> <?_code $title ? "" : "$title_user : $title_subject $ML{'.title'}" _code?>
 page?>
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/talkread.bml
--- a/htdocs/talkread.bml	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/talkread.bml	Thu Oct 27 18:50:21 2011 +0800
@@ -17,7 +17,7 @@
 <?_code
 {
     use strict;
-    use vars qw($r_head $r_title %GET %ML $r_bodyopts);
+    use vars qw($actual_title $r_head $r_title %GET %ML $r_bodyopts);
 
     # make refs to both title and head, that work in cached or non-cached contexts
     # $_[0] is the BML $req object, $_[1] is a pre-request scratch area.
@@ -174,8 +174,12 @@
             if ($u->is_suspended || $up->is_suspended);
 
         # check deleted
-        return "<?h1 $ML{'talk.error.deleted.title'} h1?><?p $ML{'talk.error.deleted'} p?>"
-            if ($u->is_deleted);
+        if ( $u->is_deleted ) {
+            $$title = "";
+            return $u->display_journal_deleted( $remote, bml => {
+                title => \$actual_title,
+                head => $head } );
+        }
 
         # check suspended entry
         return "<?h1 $ML{'talk.error.suspended.title'} h1?><?p " . BML::ml('talk.error.suspendedentry', { aopts => "href='" . $u->journal_base . "/'" }) . " p?>"
@@ -880,6 +884,7 @@
 }
 _code?>
 <=body
+title=><?_code return $actual_title; _code?>
 windowtitle=><?_code return $_[1] ? $_[1]->{'title'} : $r_title _code?>
 head=><?_code return $_[1] ? $_[1]->{'head'} : $r_head _code?>
 bodyopts=><?_code return "id='page_talkread' class='self_wrap'" . $_[1]->{'bodyopts'}; _code?>
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/tools/memories.bml
--- a/htdocs/tools/memories.bml	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/tools/memories.bml	Thu Oct 27 18:50:21 2011 +0800
@@ -107,8 +107,9 @@
  }
 
  if ($u->is_deleted) {
-     $title = $ML{'error.deleted.title'};
-     $body = "<?h1 $ML{'error.deleted.name'} h1?><?p " . BML::ml('error.deleted.text',{'user'=>$user}) . " p?>";
+     $body = $u->display_journal_deleted( $remote, bml => {
+         title => \$title,
+         head => \$head } );
      return;
  }
 
diff -r 1b1e25f28bc8 -r 7a4b5facefdd htdocs/view/index.bml
--- a/htdocs/view/index.bml	Wed Oct 26 15:00:38 2011 +0800
+++ b/htdocs/view/index.bml	Thu Oct 27 18:50:21 2011 +0800
@@ -84,7 +84,9 @@
 
         # check deleted
         if ($u->is_deleted) {
-            $body = "<?h1 $ML{'talk.error.deleted.title'} h1?><?p $ML{'talk.error.deleted'} p?>";
+            $body = $u->display_journal_deleted( $remote, bml => {
+                title => \$title,
+                head => \$head } );
             return;
         }
     }
diff -r 1b1e25f28bc8 -r 7a4b5facefdd views/journal/deleted.tt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/journal/deleted.tt	Thu Oct 27 18:50:21 2011 +0800
@@ -0,0 +1,14 @@
+[%- sections.title = '.title' | ml -%]
+<p>
+[%- IF reason -%]
+  [%- '.text.withreason' | ml( user = u.display_name, reason = reason ) -%]
+[%- ELSE -%]
+  [%- '.text' | ml( user = u.display_name ) -%]
+[%- END -%]
+[%- IF is_member_of -%]
+    [% '.leavecomm' | ml( aopts = "href='$site.root/community/leave?comm=$u.user'" ) -%]
+[%- END -%]
+</p>
+[%- UNLESS is_protected -%]
+    <p>[% '.purgenotification' | ml( aopts = "href='$site.root/manage/tracking/user?journal=$u.user'" ) -%]</p>
+[%- END -%]
\ No newline at end of file
diff -r 1b1e25f28bc8 -r 7a4b5facefdd views/journal/deleted.tt.text
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/journal/deleted.tt.text	Thu Oct 27 18:50:21 2011 +0800
@@ -0,0 +1,9 @@
+.leavecomm=If you want, you can <a [[aopts]]>leave the community</a>.
+
+.purgenotification=If you'd like to rename your account with this account name, <a [[aopts]]>you can be notified</a> when the account is purged.
+
+.text=Deleted journal.  If you're [[user]], you have 30 days from the date of deletion to restore the journal.  After 30 days we'll delete all content permanently from our servers.
+
+.text.withreason=This journal has been deleted by [[user]], with a reason of: "[[reason]]".  If you are [[user]], you have a period of 30 days from the deletion time to undelete the journal.  After 30 days we will delete all content permanently from our servers.
+
+.title=Deleted Account
--------------------------------------------------------------------------------