jenkins-bot has submitted this change and it was merged.

Change subject: Logging opera-detection cleanup
......................................................................


Logging opera-detection cleanup

Change-Id: Id056974a0157720035511e6874bb1918fc264cca
---
M includes/PageRendering.php
1 file changed, 58 insertions(+), 53 deletions(-)

Approvals:
  Dr0ptp4kt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/PageRendering.php b/includes/PageRendering.php
index a1ce08d..bea628a 100644
--- a/includes/PageRendering.php
+++ b/includes/PageRendering.php
@@ -596,7 +596,7 @@
                                list( $lang, $subdomain, $project ) = 
$this->getWikiInfo();
                                $this->config->setContext(
                                        $ipset,
-                                       $this->getRequest()->getHeader( 
'X-Forwarded-By' ),
+                                       $this->getRequest()->getHeader( 
'X-FORWARDED-BY' ),
                                        $this->getRequest()->getProtocol() === 
'https',
                                        $subdomain . '.' . $project, $lang, 
$this->getRequest()->getCheck( 'X-CS' ) );
                        }
@@ -897,8 +897,8 @@
                        $dbg[] = $request->getIP();
                }
                $host = implode( '.', $this->getWikiInfo() );
-               $dbg[] = ( $request->getHeader( 'X-Forwarded-Proto' ) ?: 'http' 
) . '://' . $host;
-               $dbg[] = $request->getRawQueryString();
+               $dbg[] = ( $request->getHeader( 'X-FORWARDED-PROTO' ) ?: 'http' 
) . '://' . $host;
+               $dbg[] = urldecode( $request->getRawQueryString() );
                $dbg = implode( "\t", $dbg );
 
                if ( !$printedHeaders ) {
@@ -988,27 +988,28 @@
         */
        private function logWarnings( $isZeroTraffic ) {
                $req = $this->getRequest();
-               $configId2 = $req->getHeader( 'X-CS2' );
                $ua = $req->getHeader( 'USER-AGENT' );
-               $isBot =
-                       $req->getHeader( 'FROM' ) === 
'googlebot(at)googlebot.com' ||
-                       strpos( $ua, 'Googlebot' ) !== false || strpos( $ua, 
'bingbot' ) !== false ||
-                       strpos( $ua, 'YandexBot' ) !== false || strpos( $ua, 
'msnbot' ) !== false;
-               if ( !$isBot ) {
-                       $warn = array();
-                       foreach ( array(
-                                         'acceptbilling',
-                                         'renderwarning',
-                                         'renderZeroRatedBanner',
-                                         'renderZeroRatedRedirect'
-                                 ) as $check ) {
-                               if ( $req->getCheck( $check ) ) {
-                                       $warn[] = $check;
-                               }
+               if ( $req->getHeader( 'FROM' ) === 'googlebot(at)googlebot.com' 
||
+                    strpos( $ua, 'Googlebot' ) !== false || strpos( $ua, 
'bingbot' ) !== false ||
+                    strpos( $ua, 'YandexBot' ) !== false || strpos( $ua, 
'msnbot' ) !== false
+               ) {
+                       return;
+               }
+               $xcs = $req->getHeader( 'X-CS2' ) ?: $req->getHeader( 'X-CS' );
+               $warn = array();
+               foreach ( array(
+                                 'acceptbilling',
+                                 'renderwarning',
+                                 'renderZeroRatedBanner',
+                                 'renderZeroRatedRedirect'
+                         ) as $check ) {
+                       if ( $req->getCheck( $check ) ) {
+                               $warn[] = $check;
                        }
-                       if ( $warn ) {
-                               $warn = array( 'obsoleteFlags' => implode( '|', 
$warn ) );
-                       }
+               }
+               if ( $warn ) {
+                       $warn = array( 'obsoleteFlags' => implode( '|', $warn ) 
);
+               }
 
 //                     if ( $this->isZeroSubdomain ) {
 //                             $referer = $request->getHeader( 'REFERER' );
@@ -1017,39 +1018,43 @@
 //                             }
 //                     }
 
-                       // For Zero traffic, either it should come from Opera 
AND have slot, or should be neither.
-                       // For non-Zero traffic, it should not have opera route
-                       $forwardedByOpera = $req->getHeader( 'X-Forwarded-By' ) 
=== 'Opera';
-                       $slot = $req->getHeader( 'X-OPERAMINI-ROUTE' );
-                       if ( !$forwardedByOpera && $slot ) {
-                               if ( $req->getHeader( 'X-Forwarded-By2' ) === 
'Opera' ) {
-                                       if ( $configId2 ) {
-                                               // Opera traffic, and opera has 
marked it with a slot, but we are not marking as zero
-                                               $warn['opera-slot-not-zero'] = 
$configId2;
-                                       } else {
-                                               // Opera traffic, and opera has 
marked it with a slot, but we don't know who this is
-                                               $warn['opera-slot-unknown'] = 
$req->getHeader( 'X-Forwarded-For' );
-                                       }
-                               } else {
-                                       // Opera has marked it with a slot, but 
we didn't recognize it as opera traffic
-                                       $warn['not-opera-slot2'] = 
$req->getHeader( 'X-Forwarded-For' );
-                               }
-                       } elseif ( $forwardedByOpera ) {
-                               if ( !$slot && $isZeroTraffic ) {
-                                       // We think it has been zero-rated, but 
opera has not marked it with a slot
-                                       $warn['opera-no-slot'] = $configId2;
-                               } elseif ( $slot && !$configId2 ) {
-                                       // Opera has a slot for it, but we 
don't know who this is
-                                       $warn['opera-slot-no-partner'] = 
$req->getHeader( 'X-Forwarded-For' );
-                               } elseif ( $slot && !$isZeroTraffic ) {
-                                       // Opera has a slot for it, and the 
partner is known, but we didn't zero-rate this request
-                                       $warn['opera-slot-incomplete'] = 
$configId2;
-                               }
-                       }
+               if ( $this->isZeroSpecial && $req->getVal( 'zcmd' ) && !$xcs ) {
+                       $warn['special'] = 'unknown-xcs';
+                       $warn['xff'] = $req->getHeader( 'X-FORWARDED-FOR' );
+               }
 
-                       if ( $warn ) {
-                               $this->logDebug( $req, $warn );
+               // For Zero traffic, either it should come from Opera AND have 
slot, or should be neither.
+               // For non-Zero traffic, it should not have opera slot
+               $forwardedBy = $req->getHeader( 'X-FORWARDED-BY' ) ?: 
$req->getHeader( 'X-FORWARDED-BY2' );
+               // route could be 0, which is the same as not having it.
+               $slot = $req->getHeader( 'X-OPERAMINI-ROUTE' );
+               if ( $forwardedBy === 'Opera' ) {
+                       if ( $slot ) {
+                               if ( !$xcs ) {
+                                       // Opera has a slot for it, but we 
don't know who this is
+                                       $warn['opera'] = 'slot-no-partner';
+                                       $warn['slot'] = $slot;
+                                       $warn['xff'] = $req->getHeader( 
'X-FORWARDED-FOR' );
+                               } elseif ( !$isZeroTraffic ) {
+                                       // Opera has a slot for it, and the 
partner is known, but we didn't zero-rate this request
+                                       $warn['opera'] = 'slot-incomplete';
+                                       $warn['slot'] = $slot;
+                                       $warn['xcs'] = $xcs;
+                               }
+                       } elseif ( $isZeroTraffic ) {
+                               // We think it has been zero-rated, but opera 
has not marked it with a slot
+                               $warn['opera'] = 'no-slot';
+                               $warn['xcs'] = $xcs;
                        }
+               } elseif ( $slot ) {
+                       // Opera has marked it with a slot, but we didn't 
recognize it as opera traffic
+                       $warn['opera'] = 'slot-no-opera';
+                       $warn['slot'] = $slot;
+                       $warn['xff'] = $req->getHeader( 'X-FORWARDED-FOR' );
+               }
+
+               if ( $warn ) {
+                       $this->logDebug( $req, $warn );
                }
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/149296
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id056974a0157720035511e6874bb1918fc264cca
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ZeroBanner
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to