예제 #1
0
 private function executeImage()
 {
     if (empty($this->mParams['tempName'])) {
         $this->dieUsageMsg('The tempName parameter must be set');
     }
     $tempFile = new FakeLocalFile(Title::newFromText($this->mParams['tempName'], 6), RepoGroup::singleton()->getLocalRepo());
     $duplicate = $this->getFileDuplicate($tempFile->getLocalRefPath());
     if ($duplicate) {
         return array('title' => $duplicate->getTitle()->getText());
     } else {
         $title = $this->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title']));
         if (isset($this->mParams['license'])) {
             $pageText = SpecialUpload::getInitialPageText('', $this->mParams['license']);
         }
         $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
         $file->upload($tempFile->getPath(), '', $pageText ? $pageText : '');
         return array('title' => $file->getTitle()->getText());
     }
 }
예제 #2
0
     $flags = 0;
     $publishOptions = array();
     $handler = MediaHandler::getHandler($props['mime']);
     if ($handler) {
         $publishOptions['headers'] = $handler->getStreamHeaders($props['metadata']);
     } else {
         $publishOptions['headers'] = array();
     }
     $archive = $image->publish($file, $flags, $publishOptions);
     if (!$archive->isGood()) {
         echo "failed. (" . $archive->getWikiText() . ")\n";
         $failed++;
         continue;
     }
 }
 $commentText = SpecialUpload::getInitialPageText($commentText, $license);
 if (!isset($options['summary'])) {
     $summary = $commentText;
 }
 if (isset($options['dry'])) {
     echo "done.\n";
 } elseif ($image->recordUpload2($archive->value, $summary, $commentText, $props, $timestamp)) {
     # We're done!
     echo "done.\n";
     $doProtect = false;
     global $wgRestrictionLevels;
     $protectLevel = isset($options['protect']) ? $options['protect'] : null;
     if ($protectLevel && in_array($protectLevel, $wgRestrictionLevels)) {
         $doProtect = true;
     }
     if (isset($options['unprotect'])) {
예제 #3
0
 /**
  * Record a file upload in the upload log and the image table
  * @param string $oldver
  * @param string $desc
  * @param string $license
  * @param string $copyStatus
  * @param string $source
  * @param bool $watch
  * @param string|bool $timestamp
  * @param User|null $user User object or null to use $wgUser
  * @return bool
  */
 function recordUpload($oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false, $timestamp = false, User $user = null)
 {
     if (!$user) {
         global $wgUser;
         $user = $wgUser;
     }
     $pageText = SpecialUpload::getInitialPageText($desc, $license, $copyStatus, $source);
     if (!$this->recordUpload2($oldver, $desc, $pageText, false, $timestamp, $user)) {
         return false;
     }
     if ($watch) {
         $user->addWatch($this->getTitle());
     }
     return true;
 }
	/**
	 * This method hacks the normal nirvana dispatcher chain because of AIM and application/json mimetype incompatibility
	 * Talk to Hyun or Inez
	 */
	public function executeUpload($params) {
		wfProfileIn(__METHOD__);
		global $wgRequest, $wgUser;

		if(!$wgUser->isLoggedIn()) {
			echo 'Not logged in';
			exit();
		}

		$this->watchthis = $wgRequest->getBool('wpWatchthis') && $wgUser->isLoggedIn();
		$this->license = $wgRequest->getText('wpLicense');
		$this->copyrightstatus = $wgRequest->getText('wpUploadCopyStatus');
		$this->copyrightsource = $wgRequest->getText('wpUploadSource');
		$this->ignorewarning = $wgRequest->getCheck('wpIgnoreWarning');
		$this->overwritefile = $wgRequest->getCheck('wpDestFileWarningAck');
		$this->defaultcaption = $wgRequest->getText('wpUploadDescription');
		$details = null;
		$up = new UploadFromFile();
		$up->initializeFromRequest($wgRequest);
		$permErrors = $up->verifyPermissions($wgUser);

		if ( $permErrors !== true ) {
			$this->status = self::UPLOAD_PERMISSION_ERROR;
			$this->statusMessage = $this->uploadMessage( $this->status, null );
		} else if (empty($this->wg->EnableUploads)) {
			// BugId:6122
			$this->statusMessage = wfMsg('uploaddisabled');
		} else {
			$details = $up->verifyUpload();

			$this->status = (is_array($details) ? $details['status'] : UploadBase::UPLOAD_VERIFICATION_ERROR);
			$this->statusMessage = '';

			if ($this->status > 0) {
				$this->statusMessage = $this->uploadMessage($this->status, $details);
			} else {
				$warnings = array();
				if(!$this->ignorewarning) {
					$warnings = $up->checkWarnings();

					// BugId:3325 - add handling for "Overwrite File" checkbox
					if ($this->overwritefile && !empty($warnings['exists'])) {
						unset($warnings['exists']);
					}

					if(!empty($warnings)) {
						$this->status = self::UPLOAD_WARNING;
						$this->statusMessage .= $this->uploadWarning($warnings);
					}
				}
				if(empty($warnings)) {
					$pageText = SpecialUpload::getInitialPageText( $this->defaultcaption, $this->license,
						$this->copyrightstatus, $this->copyrightsource );
					$status = $up->performUpload( $this->defaultcaption, $pageText, $this->watchthis, $wgUser );
					if ($status->isGood()) {
						$aPageProps = array ( 'default_caption' => $this->defaultcaption );
						Wikia::setProps( $up->getTitle()->getArticleID(), $aPageProps );
					} else {
						$this->statusMessage .= "something is wrong with upload";
					}
				}
			}
		}

		echo json_encode($this->getResponse()->getData());
		header('content-type: text/plain; charset=utf-8');

		wfProfileOut(__METHOD__);

		exit();	//end hack
	}