Refactor redirection to a specific URL for renamed journals.

        Patch by kareila. 

diffs (73 lines):

diff -r 15398892e6bc -r 8efc50a6349e cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm        Fri Jun 11 15:56:55 2010 +0800
+++ b/cgi-bin/LJ/User.pm        Fri Jun 11 16:06:25 2010 +0800
@@ -1098,6 +1098,16 @@ sub record_login {
 }
 
 
+sub redirect_rename {
+    my ( $u, $uri ) = @_;
+    return undef unless $u->is_redirect;
+    my $renamedto = $u->prop( 'renamedto' ) or return undef;
+    my $ru = LJ::load_user( $renamedto ) or return undef;
+    $uri ||= '';
+    return BML::redirect( $ru->journal_base . $uri );
+}
+
+
 # my $sess = $u->session           (returns current session)
 # my $sess = $u->session($sessid)  (returns given session id for user)
 sub session {
diff -r 15398892e6bc -r 8efc50a6349e htdocs/talkpost.bml
--- a/htdocs/talkpost.bml       Fri Jun 11 15:56:55 2010 +0800
+++ b/htdocs/talkpost.bml       Fri Jun 11 16:06:25 2010 +0800
@@ -72,11 +72,9 @@ body<=
 
     # redirect if account was renamed
     if ( $u->is_redirect ) {
-        $u->preload_props( "renamedto" );
-        if ($u->{'renamedto'} ne "") {
-            my $id = $FORM{'itemid'}+0;
-            return BML::redirect(LJ::journal_base($u->{'renamedto'}) . 
"/$id.html?mode=reply");
-        }
+        my $id = $FORM{'itemid'} + 0;
+        my $redirect = $u->redirect_rename( "/$id.html?mode=reply" );
+        return $redirect if $redirect;
     }
 
     LJ::Hooks::run_hooks("need_res_for_journals", $u);
diff -r 15398892e6bc -r 8efc50a6349e htdocs/talkread.bml
--- a/htdocs/talkread.bml       Fri Jun 11 15:56:55 2010 +0800
+++ b/htdocs/talkread.bml       Fri Jun 11 16:06:25 2010 +0800
@@ -95,10 +95,8 @@ body<=
 
     # redirect if account was renamed
     if ( $u->is_redirect ) {
-        $u->preload_props( "renamedto" );
-        if ($u->{'renamedto'} ne "") {
-            return BML::redirect(LJ::journal_base($u->{'renamedto'}) . 
"/$ditemid.html");
-        }
+        my $redirect = $u->redirect_rename( "/$ditemid.html" );
+        return $redirect if $redirect;
     }
 
     # now check for init->error, since we know the account wasn't renamed
diff -r 15398892e6bc -r 8efc50a6349e htdocs/view/index.bml
--- a/htdocs/view/index.bml     Fri Jun 11 15:56:55 2010 +0800
+++ b/htdocs/view/index.bml     Fri Jun 11 16:06:25 2010 +0800
@@ -59,11 +59,10 @@ _c?>
     }
 
     if ( $u->is_redirect ) {
-        $u->preload_props( "renamedto" );
-        if ( $u->{'renamedto'} ) {
-            return BML::redirect( sprintf( LJ::journal_base( $u->{'renamedto'} 
)
-                                         . "/%04d/%02d/", $FORM{'y'}, 
$FORM{'m'} ) );
-        }
+        my $redirect = $u->redirect_rename(
+                         sprintf( "/%04d/%02d/", $FORM{'y'}, $FORM{'m'} )
+                       );
+        return $redirect if $redirect;
     }
 
     my $remote = LJ::get_remote();
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to