wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r8115: Initial commit for refactoring to Apache...

Committer: gprochaev
Initial commit for refactoring to Apache2

U   branches/modernize2/cgi-bin/LJ/Hooks/ControlStrip.pm
U   branches/modernize2/cgi-bin/LJ/Hooks/Homepage.pm
U   branches/modernize2/cgi-bin/LJ/Hooks/S2Styles.pm
U   branches/modernize2/cgi-bin/LJ/Hooks/SUP.pm
U   branches/modernize2/cgi-bin/LJ/SUP/RPC/Command/comments_tree.pm
U   branches/modernize2/cgi-bin/LJ/SUP.pm
U   branches/modernize2/cgi-bin/bml/scheme/dystopia.look
U   branches/modernize2/cgi-bin/ljcom.pl
U   branches/modernize2/cgi-bin/phonepost.pl
Modified: branches/modernize2/cgi-bin/LJ/Hooks/ControlStrip.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Hooks/ControlStrip.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/Hooks/ControlStrip.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -2,6 +2,7 @@
 
 use strict;
 use Class::Autouse qw(LJ::CProd::ControlStrip);
+use LJ::Request;
 
 # logic to make sure control strip props are in order and
 # do business logic to turn on control strip.
@@ -84,11 +85,10 @@
     } elsif ($opts->{'user'}) {
         $u = LJ::load_user($opts->{'user'});
     } else {
-        my $r = Apache->request;
-        $u = LJ::load_userid($r->notes("journalid"));
+        $u = LJ::load_userid(LJ::Request->notes("journalid"));
     }
 
-    my %GET = Apache->request->args;
+    my %GET = LJ::Request->args;
 
     # logic here:
     # if the journal has it set to show, show it
@@ -116,15 +116,14 @@
     } elsif ($opts->{'user'}) {
         $u = LJ::load_user($opts->{'user'});
     } else {
-        my $r = Apache->request;
-        $u = LJ::load_userid($r->notes("journalid"));
+        $u = LJ::load_userid(LJ::Request->notes("journalid"));
     }
 
     LJ::need_res('stc/controlstrip.css');
 
     my $color;
 
-    my %GET = Apache->request->args;
+    my %GET = LJ::Request->args;
     my $stylemine = $GET{'style'} eq 'mine' && $remote && $u->id != $remote->id;
 
     if ($u->prop('show_control_strip') && !$stylemine) {

Modified: branches/modernize2/cgi-bin/LJ/Hooks/Homepage.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Hooks/Homepage.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/Hooks/Homepage.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -6,9 +6,8 @@
 
     ## special hack: to allow members of lj_core view
     ## reskined pages
-    my $r = eval {Apache->request};
-    if ($r) {
-        my %args = $r->args;
+    if (LJ::Request->is_inited) {
+        my %args = LJ::Request->args;
         if ($args{xbox_reskining}) {
             if ($LJ::IS_DEV_SERVER) {
                 return 1;
@@ -50,9 +49,8 @@
     my $params = shift;
     
     ## allow to disable reskining in query string args
-    my $r = eval {Apache->request};
-    if ($r) {
-        my %args = $r->args;
+    if (LJ::Request->is_inited) {
+        my %args = LJ::Request->args;
         return 0 if $args{no_ny_2010};
         return 1 if $args{ny_2010};
     }
@@ -71,13 +69,12 @@
     my $params = shift;
     
     ## allow to enable reskining in query string args
-    my $r = eval {Apache->request};
-    if ($r) {
-        my %args = $r->args;
+    if (LJ::Request->is_inited) {
+        my %args = LJ::Request->args;
         return 1 if $args{nokia_2010};
         
         # Show this skin only on /index.bml
-        return 0 unless $r->uri =~ m!^/(?:index\.bml)?$!; 
+        return 0 unless LJ::Request->uri =~ m!^/(?:index\.bml)?$!; 
     } else {
         # no real request => no reskining
         return 0;

Modified: branches/modernize2/cgi-bin/LJ/Hooks/S2Styles.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Hooks/S2Styles.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/Hooks/S2Styles.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -5,7 +5,7 @@
 
 LJ::register_hook('s2_head_content_extra', sub {
     my ($str_ref, $u, $r) = @_;
-    $$str_ref .= expresslane_html_comment($u, $r);
+    $$str_ref .= expresslane_html_comment($u);
 });
 
 LJ::register_hook('s2_can_use_layer', sub {

Modified: branches/modernize2/cgi-bin/LJ/Hooks/SUP.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Hooks/SUP.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/Hooks/SUP.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -6,6 +6,7 @@
 use Storable qw/freeze thaw/;
 use LJ::S2Theme;
 use LJ::HomepageItems;
+use LJ::Request;
 
 my $udp_log;
 
@@ -31,7 +32,7 @@
                 $params->{state} = $comment->state;
             };
 
-            my $rec = eval { LJ::AccessLogRecord->new( Apache->request ) } || {};
+            my $rec = eval { LJ::AccessLogRecord->new() } || {};
 
             # Convert LJ::AccessLogRecord object into hash for output
             my @rec_array = map { $_ . '="' . $udp_log->escape($rec->{$_}) . '"' } $rec->keys();
@@ -62,7 +63,7 @@
         if ($poll_log) {
 
             # Convert LJ::AccessLogRecord object into hash for output
-            my $rec = eval { LJ::AccessLogRecord->new( Apache->request ) } || {};
+            my $rec = eval { LJ::AccessLogRecord->new() } || {};
             my @rec_array = map { $_ . '="' . $poll_log->escape($rec->{$_}) . '"' } $rec->keys();
 
             # Don't log password field
@@ -113,8 +114,8 @@
 LJ::register_hook('set_alternate_statimg', sub {
     return 0; # disable this hook for now
 
-    my $r = eval { Apache->request } or return 0;
-    my $ip = $r->connection->remote_ip;
+    return 0 unless LJ::Request->is_inited;
+    my $ip = LJ::Request->connection->remote_ip;
     my $ipclass = LJ::LJcom::ip_class($ip);
     return unless $ipclass;
 
@@ -348,11 +349,10 @@
     
     # This P3P header should be set to enable login when login page is in <iframe> tag on the other site
     eval{
-        my $r = Apache->request;
         my $header_name = 'P3P';
         my $header_body = 'CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA"';
-        $r->header_out($header_name, $header_body);
-        $r->err_header_out($header_name, $header_body);
+        LJ::Request->header_out($header_name, $header_body);
+        LJ::Request->err_header_out($header_name, $header_body);
     };
 });
                                    
@@ -385,7 +385,7 @@
     ## Redirect user to that page next time.
     ## If there is a flag in URL (?force=1), then do not redirect and remember the page
 
-    my $called_from = Apache->request->uri;
+    my $called_from = LJ::Request->uri;
     my $prop_name = 'last_chosen_mobile_page';
     my $preferred_mobile_page = $remote->prop($prop_name);
     if (!$preferred_mobile_page) {
@@ -601,7 +601,7 @@
 ##
 LJ::register_hook('show_thread_expander', sub {
     return 0 if $LJ::DISABLED{thread_expander};
-    my $u = LJ::load_userid(Apache->request->notes("journalid"));
+    my $u = LJ::load_userid(LJ::Request->notes("journalid"));
     return 1 if $u && $u->get_cap('thread_expander');
     my $remote = LJ::get_remote();
     return 1 if $remote && $remote->get_cap('thread_expander');
@@ -754,7 +754,7 @@
     ## to URL of embedded iframe
     return unless $journalu && $drugoi_campaign_journals{ $journalu->{userid} };
   
-    my %getargs = eval { Apache->request->args };
+    my %getargs = eval { LJ::Request->args };
     $params->{pID}   = $getargs{'photoId'};
     $params->{uNAME} = $remote->{user} if $remote;
 });

Modified: branches/modernize2/cgi-bin/LJ/SUP/RPC/Command/comments_tree.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/SUP/RPC/Command/comments_tree.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/SUP/RPC/Command/comments_tree.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -49,7 +49,7 @@
     my $opts   = {
                     ljentry => LJ::Entry->new($journal, ditemid => $ditemid),
                     getargs => { page => $page, thread => $thread, view => $view },
-                    r       => Apache->request,
+                    r       => LJ::Request->r,
                     };
 
 

Modified: branches/modernize2/cgi-bin/LJ/SUP.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/SUP.pm	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/LJ/SUP.pm	2010-01-18 10:12:45 UTC (rev 8115)
@@ -110,8 +110,7 @@
 
     # debug/testing options
     my %flags;
-    my $r = eval { Apache->request };
-    if ($LJ::IS_DEV_SERVER && $r && $r->args && $r->args =~ /supads=([\w:]+)/) {
+    if ($LJ::IS_DEV_SERVER && LJ::Request->is_inited && LJ::Request->get_params && LJ::Request->get_params =~ /supads=([\w:]+)/) {
         %flags = map { $_ => 1 } split(/:/, $1);
         $ip_class = "russia" if $flags{ip_russia};
     }
@@ -168,7 +167,7 @@
 
     $params{i1}     = $u->id if $u;
     $params{i2}     = $remote->id if $remote;
-    $params{cp}     = eval { Apache->notes("codepath") } || "";
+    $params{cp}     = eval { LJ::Request->notes("codepath") } || "";
     $params{vid}    = $LJ::SUP_REQUEST_ID;
     $params{srv}    = 1;
 

Modified: branches/modernize2/cgi-bin/bml/scheme/dystopia.look
===================================================================
--- branches/modernize2/cgi-bin/bml/scheme/dystopia.look	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/bml/scheme/dystopia.look	2010-01-18 10:12:45 UTC (rev 8115)
@@ -131,7 +131,7 @@
 <?_code
 {
     my $remote = LJ::get_remote(); # will be requested later and returned from cache
-    return LJ::LJcom::expresslane_html_comment($remote, $_[0]->{r});
+    return LJ::LJcom::expresslane_html_comment($remote);
 }
 _code?>
 <head>

Modified: branches/modernize2/cgi-bin/ljcom.pl
===================================================================
--- branches/modernize2/cgi-bin/ljcom.pl	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/ljcom.pl	2010-01-18 10:12:45 UTC (rev 8115)
@@ -27,6 +27,8 @@
                       LJ::GeoLocation
                       );
 
+use LJ::Request;
+
 LJ::clear_hooks();
 
 @LJ::USER_TABLES_LOCAL = ("phonepostentry", "phoneposttrans", "vgifts",
@@ -213,10 +215,10 @@
 }
 
 sub expresslane_html_comment {
-    my ($u, $r) = @_;
-    return '' unless $r && $u && LJ::get_cap($u, 'paid');
+    my $u = shift;
+    return '' unless LJ::Request->is_inited && $u && LJ::get_cap($u, 'paid');
 
-    my ($free_ct, $free_age) = ($r->header_in('X-Queue-Count')+0, $r->header_in('X-Queue-Age')+0);
+    my ($free_ct, $free_age) = (LJ::Request->header_in('X-Queue-Count')+0, LJ::Request->header_in('X-Queue-Age')+0);
     return "<!-- LiveJournal ExpressLane: You received this page before $free_ct free users" .
            ($free_age > 0 ? ", saving approximately $free_age seconds" : '') . "! -->\n";
 }
@@ -568,10 +570,9 @@
 }
 
 LJ::register_hook("ssl_check", sub {
-    my $r = $_[0]{r};
     return
-        $r->header_in("X-LJ-SSL") ||
-        ($LJ::IS_DEV_SERVER && $r->header_in("Host") eq $LJ::SSLDOMAIN);
+        LJ::Request->header_in("X-LJ-SSL") ||
+        ($LJ::IS_DEV_SERVER && LJ::Request->header_in("Host") eq $LJ::SSLDOMAIN);
 });
 
 # when cancelling an account be sure to revoke promos
@@ -638,9 +639,8 @@
     if ($pathextra =~ m#^/(\d+)\.(mp3|ogg|wav)$#) {
         my $dppid = $1;
         return sub {
-            my $r = shift;
             my $u = LJ::load_user($user);
-            return LJ::PhonePost::apache_content($r, $u, $dppid);
+            return LJ::PhonePost::apache_content($u, $dppid);
         };
     }
     return undef;
@@ -652,11 +652,10 @@
     if ($pathextra =~ m#^/(\d+)\.(mp3|ogg|wav)$#) {
         my ($dppid, $ext) = ($1, $2);
         return sub {
-            my $r = shift;
             my $u = LJ::load_user($user);
             my $dataurl = $u->journal_base . "/data/phonepost/$dppid.$ext";
-            $r->header_out(Location => $dataurl);
-            return Apache::Constants::REDIRECT();
+            LJ::Request->header_out(Location => $dataurl);
+            return LJ::Request::REDIRECT;
         };
     }
     return undef;
@@ -1050,7 +1049,7 @@
             'posterid' => $up->{'userid'},
             'journalid' => $uo->{'userid'},
             'remote_ip' => LJ::get_remote_ip(),
-            'remote_ua' => LJ::is_web_context() ? Apache->request->header_in('User-Agent') : undef,
+            'remote_ua' => LJ::is_web_context() ? LJ::Request->instance->header_in('User-Agent') : undef,
             'remote_uniq' => LJ::UniqCookie->current_uniq,
         }) if ($rand <= $LJ::POST_SAMPLE && !$LJ::DISABLED{'tp_antispam_test'});
     }
@@ -1116,9 +1115,8 @@
 });
 
 LJ::register_hook("forbid_request", sub {
-    my $r = shift;
-    my $ua = $r->header_in("User-Agent");
-    my $ip = $r->connection->remote_ip;
+    my $ua = LJ::Request->header_in("User-Agent");
+    my $ip = LJ::Request->connection->remote_ip;
     # @BAN_UA can be either scalar substrings of user-agents, or
     # an arrayref of [ $substr, $ip ] which makes the substring
     # match conditional on it matching that IP
@@ -1373,7 +1371,7 @@
 
     my $uniq = '';
     eval {
-        $uniq = Apache->request->notes('uniq');
+        $uniq = LJ::Request->instance->notes('uniq');
     };
     my $ip = LJ::get_remote_ip();
 
@@ -1503,7 +1501,6 @@
     my $opts = shift;
 
     my $interface = delete $opts->{'int'};
-    my $r = delete $opts->{'r'};
     my $bml_handler = delete $opts->{'bml_handler'};
 
     if ($interface eq 'm365_mo') {
@@ -1776,9 +1773,8 @@
     my $ret;
 
     return unless LJ::is_web_context();
-    my $r = Apache->request;
     # Friends pages has a different message for first post
-    if ($r->notes('view') eq "friends") {
+    if (LJ::Request->notes('view') eq "friends") {
         $ret .= BML::ml('ljcom.lj-replace.first_post.friends', {
                     'addfriend'    => "src='$LJ::IMGPREFIX/btn_addfriend.gif'",
                     'userhead'     => "src='$LJ::IMGPREFIX/userinfo.gif'",

Modified: branches/modernize2/cgi-bin/phonepost.pl
===================================================================
--- branches/modernize2/cgi-bin/phonepost.pl	2010-01-18 09:12:51 UTC (rev 8114)
+++ branches/modernize2/cgi-bin/phonepost.pl	2010-01-18 10:12:45 UTC (rev 8115)
@@ -64,7 +64,7 @@
 }
 
 sub apache_content {
-    my ($r, $u, $dppid) = @_;
+    my ($u, $dppid) = @_;
     my $bid = int($dppid/256);
     my $ppe = get_phonepost_entry($u, $bid);
     return 404 unless $ppe && $ppe->{jitemid} && $ppe->{anum} == $dppid % 256;
@@ -78,7 +78,7 @@
         # from Akamai/Speedera/etc and the IP won't match
         my $remote = LJ::get_remote({ ignore_ip => 1 });
 
-        my %GET = $r->args;
+        my %GET = LJ::Request->get_params;
 
         my $viewall = 0;
         my $viewsome = 0;
@@ -96,19 +96,19 @@
     }
 
     # future:  if length is NULL, then it's an external reference and we redirect
-    $r->header_out("Cache-Control", "must-revalidate, private");
-    $r->header_out("Content-Length", $ppe->{length});
-    $r->content_type( $datatypes->{ $ppe->{filetype} }->{mime} );
+    LJ::Request->header_out("Cache-Control", "must-revalidate, private");
+    LJ::Request->header_out("Content-Length", $ppe->{length});
+    LJ::Request->content_type( $datatypes->{ $ppe->{filetype} }->{mime} );
 
     # handle IMS requests
     my $last_mod = LJ::time_to_http($ppe->{posttime});
-    if (my $ims = $r->header_in("If-Modified-Since")) {
+    if (my $ims = LJ::Request->header_in("If-Modified-Since")) {
         return 304 if $ims eq $last_mod;
     }
 
-    $r->header_out("Last-Modified", $last_mod);
-    if ($r->header_only) {
-        $r->send_http_header();
+    LJ::Request->header_out("Last-Modified", $last_mod);
+    if (LJ::Request->header_only) {
+        LJ::Request->send_http_header();
         return 200;
     }
 
@@ -116,41 +116,41 @@
     if ($ppe->{location} eq 'mogile') {
         # Mogile
         if ( !$LJ::REPROXY_DISABLE{phoneposts} &&
-             $r->header_in('X-Proxy-Capabilities') &&
-             $r->header_in('X-Proxy-Capabilities') =~ /\breproxy-file\b/i )
+             LJ::Request->header_in('X-Proxy-Capabilities') &&
+             LJ::Request->header_in('X-Proxy-Capabilities') =~ /\breproxy-file\b/i )
         {
             my @paths = LJ::mogclient()->get_paths( "pp:$u->{userid}:$bid", 1 );
 
             # reproxy url
             if ($paths[0] =~ m/^http:/) {
-                $r->header_out('X-REPROXY-URL', join(' ', @paths));
+                LJ::Request->header_out('X-REPROXY-URL', join(' ', @paths));
             }
             # reproxy file
             else {
-                $r->header_out('X-REPROXY-FILE', $paths[0]);
+                LJ::Request->header_out('X-REPROXY-FILE', $paths[0]);
             }
-            $r->send_http_header();
+            LJ::Request->send_http_header();
         }
         else {
             $buffer = LJ::mogclient()->get_file_data("pp:$u->{userid}:$bid");
-            $r->send_http_header();
+            LJ::Request->send_http_header();
             return 500 unless $buffer && ref $buffer;
-            $r->print($$buffer);
+            LJ::Request->print($$buffer);
         }
 
     }
     else {
         # BlobServer
-        $r->send_http_header();
+        LJ::Request->send_http_header();
         my $ret = LJ::Blob::get_stream($u, 'phonepost',
                                        $datatypes->{ $ppe->{filetype} }->{ext}, $bid, sub {
             $buffer .= $_[0];
             if (length($buffer) > 50_000) {
-                $r->print($buffer);
+                LJ::Request->print($buffer);
                 undef $buffer;
             }
         });
-        $r->print($buffer) if length($buffer);
+        LJ::Request->print($buffer) if length($buffer);
         return 500 unless $ret;
     }
 

Tags: ljcom, look, pl, pm, wisest-owl
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments