public function verifyUpload() { $this->getTitle(); //will fill in final destination and extension $details = parent::verifyUpload(); if ($details['status'] == self::OK) { // check file type (just by extension) if ($this->checkFileExtension($this->mFinalExtension, array('png', 'jpg', 'jpeg', 'gif'))) { $tempPath = $this->getTempPath(); // check if file is correct file size $imageFileSize = filesize($tempPath); if ($imageFileSize <= self::FILESIZE_LIMIT) { // center image if wider than 1050, otherwise left align $imageSize = getimagesize($tempPath); if ($imageSize[0] > 1050) { $this->mImageAlign = "center"; } else { $this->mImageAlign = "left"; } } else { $details['status'] = self::FILESIZE_ERROR; } } else { $details['status'] = self::FILETYPE_ERROR; } } return $details; }
public function verifyUpload() { global $wgVerifyMimeType; //Avoid extension->mime mismatch since //we're forcing wathever image format to be saved as a PNG $origVerifyMimeTypeValue = $wgVerifyMimeType; $wgVerifyMimeType = false; parent::verifyUpload(); $wgVerifyMimeType = $origVerifyMimeTypeValue; }
public function verifyUpload() { $this->getTitle(); //will fill in final destination and extension $details = parent::verifyUpload(); if ($details['status'] == self::OK) { // check file type (just by extension) if (!$this->checkFileExtension($this->mFinalExtension, array('ico'))) { $details['status'] = self::FILETYPE_ERROR; } } return $details; }
public function verifyUpload() { $this->getTitle(); //will fill in final destination and extension $details = parent::verifyUpload(); if ($details['status'] == self::OK) { $imageSize = getimagesize($this->getTempPath()); // Currently the image size needs to be the same for main and additional if ($imageSize[0] < self::VISUALIZATION_MAIN_IMAGE_MIN_WIDTH || $imageSize[1] < self::VISUALIZATION_MAIN_IMAGE_MIN_HEIGHT) { $details['status'] = self::FILEDIMENSIONS_ERROR; } // check file type (just by extension) if (!$this->checkFileExtension($this->mFinalExtension, array('png'))) { $details['status'] = self::FILETYPE_ERROR; } } return $details; }
public function verifyUpload() { $this->getTitle(); //will fill in final destination and extension $details = parent::verifyUpload(); if ($details['status'] == self::OK) { // check file type (just by extension) if ($this->checkFileExtension($this->mFinalExtension, array('png'))) { $imageSize = getimagesize($this->getTempPath()); if ($imageSize[0] > 250 || $imageSize[1] > 65) { $details['status'] = self::FILEDIMENSIONS_ERROR; } } else { $details['status'] = self::FILETYPE_ERROR; } } return $details; }
public function verifyUpload() { $this->getTitle(); //will fill in final destination and extension $details = parent::verifyUpload(); if ($details['status'] == self::OK) { // check file type (just by extension) if ($this->checkFileExtension($this->mFinalExtension, array('png', 'jpg', 'jpeg', 'gif'))) { $tempPath = $this->getTempPath(); // check if file is correct file size $imageFileSize = filesize($tempPath); if ($imageFileSize > self::FILESIZE_LIMIT) { $details['status'] = self::FILESIZE_ERROR; } } else { $details['status'] = self::FILETYPE_ERROR; } } return $details; }
function upload() { $details = null; $this->content = 'error'; $up = new UploadFromFile(); $up->initializeFromRequest($this->wg->request); $permErrors = $up->verifyPermissions($this->wg->user); 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 { $titleText = $this->request->getVal('title'); $sectionNumber = $this->request->getVal('section', 0); $this->status = $up->performUpload('', '', '', $this->wg->user); $mainArticle = new Article(Title::newFromText($titleText)); if ($sectionNumber == 0) { $mainArticle->updateArticle($this->getWikiText($up->getTitle()->getText(), self::LEFT) . $mainArticle->getRawText(), '', false, false); } else { $firstSectionText = $mainArticle->getSection($mainArticle->getRawText(), $sectionNumber); $matches = array(); if (preg_match('/={2,3}[^=]+={2,3}/', $firstSectionText, $matches)) { $firstSectionText = trim(str_replace($matches[0], '', $firstSectionText)); $newSectionText = $mainArticle->replaceSection($sectionNumber, $matches[0] . "\n" . $this->getWikiText($up->getTitle()->getText(), self::LEFT) . $firstSectionText); $mainArticle->updateArticle($newSectionText, '', false, false); } } $this->content = $this->renderImage($up->getTitle()->getText(), self::LEFT); } } } }
/** * Perform image name check */ public function checkImageName($imageName, $uploadFieldName) { global $wgRequest, $wgUser; $upload = new UploadFromFile(); $upload->initializeFromRequest($wgRequest); $permErrors = $upload->verifyPermissions($wgUser); if ($permErrors !== true) { return self::USER_PERMISSION_ERROR; } $ret = $upload->verifyUpload(); // this hook is used by WikiaTitleBlackList extension if (!wfRunHooks('WikiaMiniUpload:BeforeProcessing', array($imageName))) { $this->log(__METHOD__, 'Hook "WikiaMiniUpload:BeforeProcessing" broke processing the file'); wfProfileOut(__METHOD__); return UploadBase::VERIFICATION_ERROR; } if (is_array($ret)) { return $ret['status']; } else { return $ret; } }
/** * @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; }
/** * Perform image check * * @return array|int */ function checkImage() { global $wgRequest, $wgUser; $mSrcName = stripslashes($wgRequest->getFileName('wpUploadFile')); $upload = new UploadFromFile(); $upload->initializeFromRequest($wgRequest); $permErrors = $upload->verifyPermissions($wgUser); if ($permErrors !== true) { return self::USER_PERMISSION_ERROR; } $ret = $upload->verifyUpload(); if (!wfRunHooks('WikiaMiniUpload:BeforeProcessing', array($mSrcName))) { wfDebug("Hook 'WikiaMiniUpload:BeforeProcessing' broke processing the file."); return UploadBase::VERIFICATION_ERROR; } if (is_array($ret)) { return $ret['status']; } else { return $ret; } }
/** * Returns upload details * * @return array */ public function getUploadDetails() { return parent::verifyUpload(); }
/** * @return array */ public function uploadFromFile() { $webRequest = $this->getContext()->getRequest(); $uploader = new UploadFromFile(); $uploader->initialize($webRequest->getFileName('file'), $webRequest->getUpload('file')); $verified = $uploader->verifyUpload(); if ($verified['status'] == 0 || $verified['status'] == 10) { return [$uploader->getTempPath(), true]; } else { return [$uploader->getTempPath(), false, $this->getUploadFileErrorMessage($uploader, $verified)]; } }
/** * 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 }
} } } if (isset($_POST['kat'][$ids])) { #kategorie gesetzt $comment = "[[" . $_POST['kat_hidden'] . "]]"; } $mUpload->initialize($filename, $_FILES['Filedata']['tmp_name'], $_FILES['Filedata']['size']); } //if isset $permErrors = $mUpload->verifyPermissions($wgUser); if ($permErrors !== true) { $error = "missing permissions"; print_r($permErrors); } $verification = $mUpload->verifyUpload(); #print_r($verification['status']); /* if ( $verification['status'] !== UploadBase::OK ) { $result['result'] = 'Failure'; switch( $verification['status'] ) { case UploadBase::EMPTY_FILE: echo"bad1"; #$this->dieUsage( 'The file you submitted was empty', 'empty-file' ); break; case UploadBase::FILETYPE_MISSING: echo"bad1"; #$this->dieUsage( 'The file is missing an extension', 'filetype-missing' ); break; case UploadBase::FILETYPE_BADTYPE: