public function checkWarnings()
 {
     $warnings = parent::checkWarnings();
     unset($warnings['exists']);
     unset($warnings['duplicate']);
     unset($warnings['duplicate-archive']);
     unset($warnings['badfilename']);
     return $warnings;
 }
 public function checkWarnings()
 {
     $warnings = parent::checkWarnings();
     //for wordmark we allow overwriting and don't care of
     //filname mismatch for FakeLocalFile (see UploadBase::checkWarnings)
     unset($warnings['exists']);
     unset($warnings['duplicate']);
     unset($warnings['duplicate-archive']);
     unset($warnings['badfilename']);
     return $warnings;
 }
 /**
  * @static
  * @return AjaxResponse
  * @throws MWException
  */
 public static function uploadImage()
 {
     global $wgRequest, $wgUser, $wgFileExtensions, $wgLang;
     if ($wgRequest->wasPosted()) {
         $ret = array();
         $upload = new UploadFromFile();
         $upload->initializeFromRequest($wgRequest);
         $permErrors = $upload->verifyPermissions($wgUser);
         if ($permErrors !== true) {
             $ret['error'] = true;
             $ret['message'] = wfMsg('badaccess');
         } else {
             $details = $upload->verifyUpload();
             if ($details['status'] != UploadBase::OK) {
                 $ret['error'] = true;
                 switch ($details['status']) {
                     /** Statuses that only require name changing **/
                     case UploadBase::MIN_LENGTH_PARTNAME:
                         $ret['message'] = wfMsgHtml('minlength1');
                         break;
                     case UploadBase::ILLEGAL_FILENAME:
                         $ret['message'] = wfMsgExt('illegalfilename', 'parseinline', $details['filtered']);
                         break;
                     case UploadBase::OVERWRITE_EXISTING_FILE:
                         $ret['message'] = wfMsgExt($details['overwrite'], 'parseinline');
                         break;
                     case UploadBase::FILETYPE_MISSING:
                         $ret['message'] = wfMsgExt('filetype-missing', 'parseinline');
                         break;
                     case UploadBase::EMPTY_FILE:
                         $ret['message'] = wfMsgHtml('emptyfile');
                         break;
                     case UploadBase::FILETYPE_BADTYPE:
                         $finalExt = $details['finalExt'];
                         $ret['message'] = wfMsgExt('filetype-banned-type', array('parseinline'), htmlspecialchars($finalExt), implode(wfMsgExt('comma-separator', array('escapenoentities')), $wgFileExtensions), $wgLang->formatNum(count($wgFileExtensions)));
                         break;
                     case UploadBase::VERIFICATION_ERROR:
                         unset($details['status']);
                         $code = array_shift($details['details']);
                         $ret['message'] = wfMsgExt($code, 'parseinline', $details['details']);
                         break;
                     case UploadBase::HOOK_ABORTED:
                         if (is_array($details['error'])) {
                             # allow hooks to return error details in an array
                             $args = $details['error'];
                             $error = array_shift($args);
                         } else {
                             $error = $details['error'];
                             $args = null;
                         }
                         $ret['message'] = wfMsgExt($error, 'parseinline', $args);
                         break;
                     default:
                         throw new MWException(__METHOD__ . ": Unknown value `{$details['status']}`");
                 }
             } else {
                 $warnings = $upload->checkWarnings();
                 if ($warnings) {
                     if (!empty($warnings['exists']) || !empty($warnings['duplicate']) || !empty($warnings['duplicate-archive'])) {
                         $ret['conflict'] = true;
                         $ret['message'] = wfMsg('toplists-error-image-already-exists');
                     } else {
                         $ret['error'] = true;
                         $ret['message'] = '';
                         foreach ($warnings as $warning => $args) {
                             if ($args === true) {
                                 $args = array();
                             } elseif (!is_array($args)) {
                                 $args = array($args);
                             }
                             $ret['message'] .= wfMsgExt($warning, 'parseinline', $args) . "/n";
                         }
                     }
                 } else {
                     $status = $upload->performUpload('/* comment */', '/* page text */', false, $wgUser);
                     if (!$status->isGood()) {
                         $ret['error'] = true;
                         $ret['message'] = wfMsg('toplists-upload-error-unknown');
                     } else {
                         $ret['success'] = true;
                         $file = $upload->getLocalFile();
                         if (!empty($file)) {
                             $thumb = $file->transform(array('width' => 120), 0);
                             $pictureName = $upload->getTitle()->getText();
                             $pictureUrl = $thumb->getUrl();
                         }
                         $ret['name'] = $pictureName;
                         $ret['url'] = $pictureUrl;
                     }
                 }
             }
         }
         $response = new AjaxResponse('<script type="text/javascript">window.document.responseContent = ' . json_encode($ret) . ';</script>');
         $response->setContentType('text/html; charset=utf-8');
         return $response;
     }
 }
 protected function uploadImage()
 {
     global $wgImageMagickConvertCommand, $wgServer;
     $request = $this->getRequest();
     $result = array();
     $fromPage = $request->getVal('viapage');
     // sanity check on the page to link to
     $title = Title::newFromText($fromPage, NS_MAIN);
     if (!$title->exists()) {
         $result['error'] = "Error: No article {$fromPage} found to link image.";
         return $result;
     }
     // try to get a unique file name by appending a suffix and the current time to the save name here
     $dateTime = new DateTime();
     $webUpload = $request->getUpload('wpUploadImage');
     $info = new SplFileInfo($webUpload->getName());
     $ext = $info->getExtension();
     $info = new SplFileInfo($request->getVal("name"));
     for ($i = 0; $i < 100; $i++) {
         $saveName = "User Completed Image {$fromPage} {$dateTime->format('Y.m.d H.i.s')}.{$i}.{$ext}";
         $title = Title::newFromText($saveName, NS_IMAGE);
         if (!$title->getArticleID()) {
             break;
         }
     }
     // if the title still exists, show an error
     if ($title->getArticleID()) {
         $result['error'] = 'file with this name already exists';
         return $result;
     }
     $upload = new UploadFromFile();
     $upload->initialize($saveName, $webUpload);
     $verification = $upload->verifyUpload();
     if ($verification['status'] !== UploadBase::OK) {
         $result['error'] = "verification error: " . $verification['status'];
         return $result;
     }
     $warnings = $upload->checkWarnings();
     if ($warnings) {
         $result['warnings'] = $warnings;
         // todo this should be toggled on off for testings perhaps
         // since it might get kind of annoying
         if ($warnings['duplicate']) {
             $result['debug'][] = $warnings['duplicate-archive'];
             $result['error'] = "this file was already uploaded";
             return $result;
         }
     }
     $comment = '{{Self}}';
     $status = $upload->performUpload($comment, '', true, $this->getUser());
     if (!$status->isGood()) {
         $error = $status->getErrorsArray();
         $result['error'] = 'perform upload error: ' . $error;
         return $result;
     }
     $upload->cleanupTempFile();
     // todo - do this part after the single file upload
     // Image orientation is a bit wonky on some mobile devices; use ImageMagick's auto-orient to try fixing it.
     //$tempFilePath = $temp_file->getPath();
     //$cmd = $wgImageMagickConvertCommand . ' ' . $tempFilePath . ' -auto-orient ' . $tempFilePath;
     //exec($cmd);
     $file = $upload->getLocalFile();
     $thumb = $file->getThumbnail(200, -1, true, true);
     if (!$thumb) {
         $result['error'] = 'file thumbnail does not exist';
         $file->delete('');
         return $result;
     }
     $fileTitle = $file->getTitle();
     $result['titleText'] = $fileTitle->getText();
     $result['titleDBkey'] = substr($fileTitle->getDBkey(), 21);
     // Only keep important info
     $result['titlePreText'] = '/' . $fileTitle->getPrefixedText();
     $result['titleArtID'] = $fileTitle->getArticleID();
     $result['timestamp'] = wfTimestamp(TS_MW);
     $result['fromPage'] = $request->getVal('viapage');
     $result['thumbURL'] = $thumb->getUrl();
     $result['fileURL'] = $wgServer . $file->getUrl();
     $this->addToDB($result);
     return $result;
 }
	/**
	 * 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
	}
Beispiel #6
0
		case UploadBase::HOOK_ABORTED:
			echo"bad1",
          #$this->dieUsage( "The modification you tried to make was aborted by an extension hook",
			#		'hookaborted', 0, array( 'error' => $verification['error'] ) );
			break;
		default:
			echo"bad1",
          #$this->dieUsage( 'An unknown error occurred', 'unknown-error',
			#		0, array( 'code' =>  $verification['status'] ) );
			break;
	}
	#return $result;
}
*/
if (!$ignorewarnings) {
    $warnings = $mUpload->checkWarnings();
    $sessionKey = $mUpload->stashSession();
    /*
    if ( $warnings ) {
    	// Add indices
    	$this->getResult()->setIndexedTagName( $warnings, 'warning' );
    
    	if ( isset( $warnings['duplicate'] ) ) {
    		$dupes = array();
    		foreach ( $warnings['duplicate'] as $key => $dupe )
    			$dupes[] = $dupe->getName();
    		$this->getResult()->setIndexedTagName( $dupes, 'duplicate' );
    		$warnings['duplicate'] = $dupes;
    	}