Exemple #1
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) {
         $requestData['file'] = '@' . $imagePage->getFile()->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 {
             $req = new CurlHttpRequest($target, $reqArgs);
         }
     } 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));
         wfRunHooks('PushAPIAfterImagePush', array($title, $target, $token, $response));
     } else {
         $this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed');
     }
 }
Exemple #2
0
 /**
  * Pushes the page content to the specified wiki.
  *
  * @since 0.3
  *
  * @param Title $title
  * @param array $revision
  * @param string $target
  * @param string $token
  */
 protected function pushToTarget(Title $title, array $revision, $target, $token)
 {
     global $wgSitename;
     $summary = wfMsgExt('push-import-revision-message', 'parsemag', $wgSitename);
     $requestData = array('action' => 'edit', 'title' => $title->getFullText(), 'format' => 'json', 'summary' => $summary, 'text' => $revision['*'], 'token' => $token);
     $req = PushFunctions::getHttpRequest($target, array('method' => 'POST', 'timeout' => 'default', 'postData' => $requestData));
     if (array_key_exists($target, $this->cookieJars)) {
         $req->setCookieJar($this->cookieJars[$target]);
     }
     $status = $req->execute();
     if ($status->isOK()) {
         $response = $req->getContent();
         $this->editResponses[] = $response;
         Hooks::run('PushAPIAfterPush', array($title, $revision, $target, $token, $response));
     } else {
         $this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed');
     }
 }