/** * @param $fileName String * @param $fileuploader WikiaTempFilesUpload * @return bool|int|MediaTransformOutput */ protected function storeInTempImage($fileName, $fileuploader) { wfProfileIn(__METHOD__); if (filesize($fileName) > self::AVATAR_MAX_SIZE) { wfProfileOut(__METHOD__); return UPLOAD_ERR_FORM_SIZE; } $tempName = $fileuploader->tempFileName($this->wg->User); $title = Title::makeTitle(NS_FILE, $tempName); $localRepo = RepoGroup::singleton()->getLocalRepo(); /** * @var $ioh ImageOperationsHelper */ $ioh = new ImageOperationsHelper(); $out = $ioh->postProcessFile($fileName); if ($out !== true) { wfProfileOut(__METHOD__); return $out; } $file = new FakeLocalFile($title, $localRepo); $status = $file->upload($fileName, '', ''); if ($status->ok) { $width = min(self::AVATAR_DEFAULT_SIZE, $file->width); $height = min(self::AVATAR_DEFAULT_SIZE, $file->height); $thumbnail = $file->transform(['height' => $height, 'width' => $width]); } else { $errors = $status->getErrorsArray(); $errMsg = 'Unable to upload temp file fo avatar. Error(s): '; foreach ($errors as $error) { $errMsg .= $error[0] . ', '; } $errMsg = rtrim($errMsg, ', '); wfDebugLog(__METHOD__, $errMsg); $thumbnail = false; } wfProfileOut(__METHOD__); return $thumbnail; }