예제 #1
0
 public static function factory($url, $options = null)
 {
     if (!Http::$httpEngine) {
         Http::$httpEngine = function_exists('curl_init') ? 'curl' : 'php';
     } elseif (Http::$httpEngine == 'curl' && !function_exists('curl_init')) {
         throw new MWException(__METHOD__ . ': curl (http://php.net/curl) is not installed, but' . 'Http::$httpEngine is set to "curl"');
     }
     switch (Http::$httpEngine) {
         case 'curl':
             return new CurlHttpRequestTester($url, $options);
         case 'php':
             if (!wfIniGetBool('allow_url_fopen')) {
                 throw new MWException(__METHOD__ . ': allow_url_fopen needs to be enabled for pure PHP' . ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.');
             }
             return new PhpHttpRequestTester($url, $options);
         default:
     }
 }
예제 #2
0
 function testCookieRequestCurl()
 {
     if (!self::$has_curl) {
         $this->markTestIncomplete("This test requires curl.");
     }
     Http::$httpEngine = 'curl';
     self::runCookieRequests();
 }
예제 #3
0
 /**
  * Pushes the image to the specified wiki.
  *
  * @since 0.5
  *
  * @param Title $title
  * @param string $target
  * @param string $token
  */
 protected function pushToTarget(Title $title, $target, $token)
 {
     global $egPushDirectFileUploads;
     $imagePage = new ImagePage($title);
     $requestData = array('action' => 'upload', 'format' => 'json', 'token' => $token, 'filename' => $title->getText(), 'ignorewarnings' => '1');
     if ($egPushDirectFileUploads) {
         $file = $imagePage->getFile();
         $be = $file->getRepo()->getBackend();
         $localFile = $be->getLocalReference(array('src' => $file->getPath()));
         $requestData['file'] = '@' . $localFile->getPath();
     } else {
         $requestData['url'] = $imagePage->getDisplayedFile()->getFullUrl();
     }
     $reqArgs = array('method' => 'POST', 'timeout' => 'default', 'postData' => $requestData);
     if ($egPushDirectFileUploads) {
         if (!function_exists('curl_init')) {
             $this->dieUsage(wfMsg('push-api-err-nocurl'), 'image-push-nocurl');
         } elseif (!defined('CurlHttpRequest::SUPPORTS_FILE_POSTS') || !CurlHttpRequest::SUPPORTS_FILE_POSTS) {
             $this->dieUsage(wfMsg('push-api-err-nofilesupport'), 'image-push-nofilesupport');
         } else {
             $httpEngine = Http::$httpEngine;
             Http::$httpEngine = 'curl';
             $req = MWHttpRequest::factory($target, $reqArgs);
             Http::$httpEngine = $httpEngine;
         }
     } else {
         $req = PushFunctions::getHttpRequest($target, $reqArgs);
     }
     if (array_key_exists($target, $this->cookieJars)) {
         $req->setCookieJar($this->cookieJars[$target]);
     }
     $status = $req->execute();
     if ($status->isOK()) {
         $response = $req->getContent();
         $this->getResult()->addValue(null, null, FormatJson::decode($response));
         Hooks::run('PushAPIAfterImagePush', array($title, $target, $token, $response));
     } else {
         $this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed');
     }
 }
예제 #4
0
 /**
  * Generate a new request object
  * @param string $url Url to use
  * @param array $options (optional) extra params to pass (see Http::request())
  * @param string $caller The method making this request, for profiling
  * @throws MWException
  * @return CurlHttpRequest|PhpHttpRequest
  * @see MWHttpRequest::__construct
  */
 public static function factory($url, $options = null, $caller = __METHOD__)
 {
     if (!Http::$httpEngine) {
         Http::$httpEngine = function_exists('curl_init') ? 'curl' : 'php';
     } elseif (Http::$httpEngine == 'curl' && !function_exists('curl_init')) {
         throw new MWException(__METHOD__ . ': curl (http://php.net/curl) is not installed, but' . ' Http::$httpEngine is set to "curl"');
     }
     if (!is_array($options)) {
         $options = [];
     }
     if (!isset($options['logger'])) {
         $options['logger'] = LoggerFactory::getInstance('http');
     }
     switch (Http::$httpEngine) {
         case 'curl':
             return new CurlHttpRequest($url, $options, $caller, Profiler::instance());
         case 'php':
             if (!wfIniGetBool('allow_url_fopen')) {
                 throw new MWException(__METHOD__ . ': allow_url_fopen ' . 'needs to be enabled for pure PHP http requests to ' . 'work. If possible, curl should be used instead. See ' . 'http://php.net/curl.');
             }
             return new PhpHttpRequest($url, $options, $caller, Profiler::instance());
         default:
             throw new MWException(__METHOD__ . ': The setting of Http::$httpEngine is not valid.');
     }
 }
 protected function doFilesUpload($aPostData, $aErrors = array())
 {
     global $bsgUEModulePDFCURLOptions;
     $aOptions = array('timeout' => 120);
     $aOptions = array_merge_recursive($aOptions, $bsgUEModulePDFCURLOptions);
     $sType = $aPostData['fileType'];
     if (!empty($aErrors)) {
         wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Error trying to fetch files:' . "\n" . var_export($aErrors, true));
     }
     wfRunHooks('BSUEModulePDFUploadFilesBeforeSend', array($this, &$aPostData, $sType));
     $aOptions['postData'] = $aPostData;
     $vHttpEngine = Http::$httpEngine;
     Http::$httpEngine = 'curl';
     $sResponse = Http::post($this->aParams['soap-service-url'] . '/UploadAsset', $aOptions);
     Http::$httpEngine = $vHttpEngine;
     if ($sResponse != false) {
         wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Successfully added "' . $sType . '"');
         wfDebugLog('BS::UEModulePDF', FormatJson::encode(FormatJson::decode($sResponse), true));
     } else {
         wfDebugLog('BS::UEModulePDF', 'BsPDFServlet::uploadFiles: Failed adding "' . $sType . '"');
     }
 }