Esempio n. 1
0
 /**
  * Checks that the user has permissions to perform this revert.
  * Dies with usage message on inadequate permissions.
  * @param $user User The user to check.
  */
 protected function checkPermissions($user)
 {
     $title = $this->file->getTitle();
     $permissionErrors = array_merge($title->getUserPermissionsErrors('edit', $user), $title->getUserPermissionsErrors('upload', $user));
     if ($permissionErrors) {
         $this->dieUsageMsg($permissionErrors[0]);
     }
 }
Esempio n. 2
0
 /**
  * Do the upload.
  * Checks are made in SpecialUpload::execute()
  */
 protected function processUpload()
 {
     // Fetch the file if required
     $status = $this->mUpload->fetchFile();
     if (!$status->isOK()) {
         $this->showUploadError($this->getOutput()->parse($status->getWikiText()));
         return;
     }
     if (!Hooks::run('UploadForm:BeforeProcessing', array(&$this))) {
         wfDebug("Hook 'UploadForm:BeforeProcessing' broke processing the file.\n");
         // This code path is deprecated. If you want to break upload processing
         // do so by hooking into the appropriate hooks in UploadBase::verifyUpload
         // and UploadBase::verifyFile.
         // If you use this hook to break uploading, the user will be returned
         // an empty form with no error message whatsoever.
         return;
     }
     // Upload verification
     $details = $this->mUpload->verifyUpload();
     if ($details['status'] != UploadBase::OK) {
         $this->processVerificationError($details);
         return;
     }
     // Verify permissions for this title
     $permErrors = $this->mUpload->verifyTitlePermissions($this->getUser());
     if ($permErrors !== true) {
         $code = array_shift($permErrors[0]);
         $this->showRecoverableUploadError($this->msg($code, $permErrors[0])->parse());
         return;
     }
     $this->mLocalFile = $this->mUpload->getLocalFile();
     // Check warnings if necessary
     if (!$this->mIgnoreWarning) {
         $warnings = $this->mUpload->checkWarnings();
         if ($this->showUploadWarning($warnings)) {
             return;
         }
     }
     // This is as late as we can throttle, after expected issues have been handled
     if (UploadBase::isThrottled($this->getUser())) {
         $this->showRecoverableUploadError($this->msg('actionthrottledtext')->escaped());
         return;
     }
     // Get the page text if this is not a reupload
     if (!$this->mForReUpload) {
         $pageText = self::getInitialPageText($this->mComment, $this->mLicense, $this->mCopyrightStatus, $this->mCopyrightSource, $this->getConfig());
     } else {
         $pageText = false;
     }
     $status = $this->mUpload->performUpload($this->mComment, $pageText, $this->mWatchthis, $this->getUser());
     if (!$status->isGood()) {
         $this->showUploadError($this->getOutput()->parse($status->getWikiText()));
         return;
     }
     // Success, redirect to description page
     $this->mUploadSuccessful = true;
     Hooks::run('SpecialUploadComplete', array(&$this));
     $this->getOutput()->redirect($this->mLocalFile->getTitle()->getFullURL());
 }
 /**
  * Clear cache of video info specific to given file
  * @param LocalFile $file
  * @return bool
  */
 public static function purgeVideoInfoCache(\LocalFile $file)
 {
     $mediaService = new MediaQueryService();
     $mediaService->clearCacheTotalVideos();
     if (!$file->isLocal()) {
         $mediaService->clearCacheTotalPremiumVideos();
     }
     if (!empty(F::app()->wg->UseVideoVerticalFilters)) {
         VideoInfoHooksHelper::clearCategories($file->getTitle());
     }
     return true;
 }
Esempio n. 4
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());
     }
 }
 protected function purgeFromArchiveTable(LocalRepo $repo, LocalFile $file)
 {
     $dbr = $repo->getSlaveDB();
     $res = $dbr->select('filearchive', array('fa_archive_name'), array('fa_name' => $file->getName()), __METHOD__);
     foreach ($res as $row) {
         if ($row->fa_archive_name === null) {
             // Was not an old version (current version names checked already)
             continue;
         }
         $ofile = $repo->newFromArchiveName($file->getTitle(), $row->fa_archive_name);
         // If there is an orphaned storage file still there...delete it
         if (!$file->exists() && $repo->fileExists($ofile->getPath())) {
             $dpath = $this->getDeletedPath($repo, $ofile);
             if ($repo->fileExists($dpath)) {
                 // Sanity check to avoid data loss
                 $repo->getBackend()->delete(array('src' => $ofile->getPath()));
                 $this->output("Deleted orphan file: {$ofile->getPath()}.\n");
             } else {
                 $this->error("File was not deleted: {$ofile->getPath()}.\n");
             }
         }
         $file->purgeOldThumbnails($row->fa_archive_name);
     }
 }
 protected function insertImage($name, $mwname, $result)
 {
     global $wgRequest, $wgImageMagickConvertCommand, $wgServer;
     if (!$result) {
         $result = array();
     } elseif ($result['error']) {
         return $result;
     }
     $fromPage = $wgRequest->getVal('viapage');
     if (!empty($mwname) && !empty($name)) {
         $name = trim(urldecode($name));
         $dateTime = new DateTime();
         $mwDate = wfTimestamp(TS_MW);
         // Mediawiki timestamp: 'YmdHis'
         list($first, $ext) = self::splitFilenameExt($name);
         $ext = strtolower($ext);
         $validExts = array('GIF', 'JPG', 'JPEG', 'PNG');
         if (!in_array(strtoupper($ext), $validExts)) {
             $result['error'] = 'Error: Invalid file extension ' . strtoupper($ext) . '. Valid extensions are:';
             foreach ($validExts as $validExt) {
                 $result['error'] .= ' ' . strtoupper($validExt);
             }
             $result['error'] .= '.';
             return $result;
         }
         $saveName = false;
         $titleExists = false;
         $suffixNum = 1;
         while (!$saveName || $titleExists) {
             $saveName = 'User Completed Image ' . $fromPage . ' ' . $dateTime->format('Y.m.d H.i.s') . ' ' . $suffixNum . '.' . $ext;
             $title = Title::makeTitleSafe(NS_IMAGE, $saveName);
             $newFile = true;
             $titleExists = $title->exists();
             $suffixNum++;
         }
         $temp_file = new TempLocalImageFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
         if (!$temp_file || !$temp_file->exists()) {
             $result['error'] = 'Error: A server error has occurred. Please try again.';
             return $result;
         }
         // 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);
         // Use a CC license
         $comment = '{{Self}}';
         $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
         $file->upload($tempFilePath, $comment, $comment);
         if (!$file || !$file->exists()) {
             $result['error'] = 'Error: A server error has occurred. Please try again.';
             return $result;
         }
         $temp_file->delete('');
         $fileTitle = $file->getTitle();
         $fileURL = $file->url;
         $thumbURL = '';
         $thumb = $file->getThumbnail(200, -1, true, true);
         if (!$thumb) {
             $result['error'] = 'Error: A server error has occurred. Please try again.';
             $file->delete('');
             return $result;
         }
         $thumbURL = $thumb->url;
         $result['titleText'] = $fileTitle->getText();
         $result['titleDBkey'] = substr($fileTitle->getDBkey(), 21);
         // Only keep important info
         $result['titlePreText'] = '/' . $fileTitle->getPrefixedText();
         $result['titleArtID'] = $fileTitle->getArticleID();
         $result['timestamp'] = $mwDate;
         $result['fromPage'] = $wgRequest->getVal('viapage');
         $result['thumbURL'] = $thumbURL;
         $result['fileURL'] = $wgServer . $fileURL;
     }
     return $result;
 }
 public function saveHeroData()
 {
     wfProfileIn(__METHOD__);
     $success = false;
     $this->getResponse()->setFormat('json');
     $wikiData = $this->request->getVal('wikiData', []);
     $wikiDataModel = new WikiDataModel(Title::newMainPage()->getText());
     $wikiDataModel->setFromAttributes($wikiData);
     $imageChanged = !empty($wikiData['imagechanged']);
     $imageName = !empty($wikiData['imagename']) ? $wikiData['imagename'] : null;
     if ($imageChanged && $imageName) {
         wfProfileIn(__METHOD__ . '::uploadStart');
         $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
         $temp_file = $stash->getFile($imageName);
         $file = new LocalFile(static::HERO_IMAGE_FILENAME, RepoGroup::singleton()->getLocalRepo());
         $status = $file->upload($temp_file->getPath(), '', '');
         wfProfileIn(__METHOD__ . '::uploadEnd');
         if ($status->isOK()) {
             $wikiDataModel->setImageName($file->getTitle()->getDBKey());
             $wikiDataModel->setImagePath($file->getFullUrl());
             $success = $this->setWikiData($wikiDataModel);
             //clean up stash
             $stash->removeFile($imageName);
         }
     } else {
         $wikiDataModel->setImageNameFromProps();
         $success = $this->setWikiData($wikiDataModel);
     }
     if (!$success) {
         $wikiDataModel->getFromProps();
     }
     $this->getResponse()->setVal('success', $success);
     $this->getResponse()->setVal('wikiData', $wikiDataModel);
     wfProfileOut(__METHOD__);
 }
 /**
  * Hook: delete video and clear cache when file is deleted
  * @param LocalFile $file
  * @param $oldimage
  * @param $article
  * @param User $user
  * @param $reason
  * @return true
  */
 public static function onFileDeleteComplete(&$file, $oldimage, $article, $user, $reason)
 {
     if (!F::build('VideoInfoHelper', array(), 'videoInfoExists')) {
         return true;
     }
     $title = $file->getTitle();
     if ($title instanceof Title && F::build('WikiaFileHelper', array($file), 'isFileTypeVideo')) {
         if ($file->isLocal()) {
             $videoData = array('videoTitle' => $title->getDBKey());
             $videoInfo = F::build('VideoInfo', array($videoData));
             $videoInfo->deleteVideo();
             $mediaService = F::build('MediaQueryService');
             $mediaService->clearCacheTotalVideos();
         }
     }
     return true;
 }