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

Change subject: Generate parsoid cookies from the flow manager
......................................................................


Generate parsoid cookies from the flow manager

When the $wgFlowParsoidForwardCookies flag is set that means parsoid
needs a Cookie header passed or it will be unable to make requests
back to the wiki.  From maintenance scripts there is no cookie to forward,
so this tries to mock one up only when PHP_SAPI === 'cli'.

Change-Id: I9775385a6091cb4e5d9bcdba789a7494447fff6e
(cherry picked from commit cce3eb5434062c25b2e01c0c481162f1a9f1e94a)
---
M includes/Parsoid/Utils.php
1 file changed, 36 insertions(+), 3 deletions(-)

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



diff --git a/includes/Parsoid/Utils.php b/includes/Parsoid/Utils.php
index 6fa833f..ea8ae42 100644
--- a/includes/Parsoid/Utils.php
+++ b/includes/Parsoid/Utils.php
@@ -4,14 +4,17 @@
 
 use DOMDocument;
 use DOMNode;
+use FauxResponse;
+use Flow\Container;
+use Flow\Exception\FlowException;
+use Flow\Exception\InvalidDataException;
 use Flow\Exception\NoParsoidException;
+use Flow\Exception\WikitextException;
 use Language;
 use OutputPage;
 use RequestContext;
 use Title;
 use User;
-use Flow\Exception\WikitextException;
-use Flow\Exception\InvalidDataException;
 
 abstract class Utils {
        /**
@@ -102,7 +105,13 @@
                        )
                );
                if ( $parsoidForwardCookies && !User::isEveryoneAllowed( 'read' 
) ) {
-                       $request->setHeader( 'Cookie', 
RequestContext::getMain()->getRequest()->getHeader( 'Cookie' ) );
+                       if ( PHP_SAPI === 'cli' ) {
+                               // From the command line we need to generate a 
cookie
+                               $cookies = 
self::generateForwardedCookieForCli();
+                       } else {
+                               $cookies = 
RequestContext::getMain()->getRequest()->getHeader( 'Cookie' );
+                       }
+                       $request->setHeader( 'Cookie', $cookies );
                }
                $status = $request->execute();
                if ( !$status->isOK() ) {
@@ -297,4 +306,28 @@
 
                return Title::newFromText( $text );
        }
+
+       public static function generateForwardedCookieForCli() {
+               $user = Container::get( 'occupation_controller' 
)->getTalkpageManager();
+               // This takes a request object, but doesnt set the cookies 
against it.
+               // patch at https://gerrit.wikimedia.org/r/177403
+               $user->setCookies();
+               $response = RequestContext::getMain()->getRequest()->response();
+               if ( !$response instanceof FauxResponse ) {
+                       throw new FlowException( 'Expected a FauxResponse in 
CLI environment' );
+               }
+               // FauxResponse does not yet expose the full set of cookies
+               $reflProp = new \ReflectionProperty( $response, 'cookies' );
+               $reflProp->setAccessible( true );
+               $cookies = $reflProp->getValue( $response );
+
+               // now we need to convert the array into the cookie format of
+               // foo=bar; baz=bang
+               $output = array();
+               foreach ( $cookies as $key => $value ) {
+                       $output[] = "$key=$value";
+               }
+
+               return implode( '; ', $output );
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9775385a6091cb4e5d9bcdba789a7494447fff6e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.25wmf11
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to