Пример #1
0
 /**
  * Insert an image upload into the mediawiki database tables.  If the
  * image insert was successful, a page showing the wiki text for their
  * image is shown.  Otherwise, if the image file name already exists in 
  * the database, a conflict page is returned to the user.
  *
  * @param $type string with either 'overwrite' or blank -- specifies
  *   whether to force-overwrite an existing image
  * @param $name filename chosen by user for uploaded image
  * @param $mwname filename of the file in mediawiki DB
  * @param $fromIIA true iff source of call is Special:IntroImageAdder
  * @param $image_comment a comment attached to the image upload (only
  *   used if $fromIIA == true)
  * @return outputs either a wikitext results page (if image filename 
  *   didn't exist or force overwrite was selected) or a conflict page.
  *   Returns an error string or empty string if no error.
  */
 private function insertImage($type, $name, $mwname, $fromIIA = false, $image_comment = '')
 {
     global $wgRequest, $wgUser, $wgOut, $wgFileExtensions;
     if (!$fromIIA) {
         $license = $wgRequest->getVal('wpLicense', '');
         if (!empty($license)) {
             $attrib = $wgRequest->getVal('attribution');
             $comment = '{{' . $license . (!empty($attrib) ? '|' . $attrib : '') . '}}';
             if ($license != '') {
                 $wgUser->setOption('image_license', $license);
                 $wgUser->saveSettings();
             }
         } else {
             $comment = $wgRequest->getVal('ImageAttribution', '');
         }
     } else {
         $comment = $image_comment;
     }
     if (wfReadOnly()) {
         return wfMsg('eiu-readonly');
     }
     if (!empty($mwname) && !empty($name)) {
         $name = urldecode($name);
         $name = preg_replace('/[^' . Title::legalChars() . ']|[:\\/\\\\]|\\?/', '-', $name);
         $name = preg_replace('@&@', '&', $name);
         $name = trim($name);
         // did they give no extension at all when they changed the name?
         list($first, $ext) = self::splitFilenameExt($name);
         $ext = strtolower($ext);
         $title = Title::makeTitleSafe(NS_IMAGE, $name);
         if (is_null($title) || !in_array($ext, $wgFileExtensions)) {
             return wfMsg('eiu-filetype-incorrect');
         }
         $newFile = true;
         $titleExists = $title->exists();
         if (!$titleExists || $fromIIA) {
             //
             // DB entry for file doesn't exist. User renamed their
             // upload or it never existed.
             //
             if ($titleExists) {
                 $suggestedName = self::generateNewFilename($name);
                 $title = Title::makeTitleSafe(NS_IMAGE, $suggestedName);
             }
             // is the target protected?
             $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
             $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
             if ($permErrors || $permErrorsUpload) {
                 return wfMsg('This image is protected');
             }
             $temp_file = new LocalFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
             $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
             $file->upload($temp_file->getPath(), $comment, $comment);
             $temp_file->delete('');
         } elseif ($type == 'overwrite') {
             //
             // DB entry exists and user selected to overwrite it
             //
             $title = Title::newFromText($name, NS_IMAGE);
             // is the target protected?
             $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
             $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
             $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
             if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                 return wfMsg('This image is protected');
             }
             $file_name = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
             $file_mwname = new TempLocalFile(Title::newFromText($mwname, NS_IMAGE), RepoGroup::singleton()->getLocalRepo());
             $file_name->upload($file_mwname->getPath(), $comment, $comment);
             $file_mwname->delete('');
             $newFile = false;
         } elseif ($type == 'existing') {
             //
             // DB entry exists and user doesn't want to overwrite or
             // rename, so they use the existing file from the DB.
             //
             $title = Title::newFromText($name, NS_IMAGE);
         } else {
             //
             // There was a conflict with an existing file in the
             // DB.  Title exists and overwrite action not taken yet.
             //
             $data = array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => '');
             $form = new UploadForm(new FauxRequest($data, true));
             // generate title if current one is taken
             $suggestedName = self::generateNewFilename($name);
             // extensions check
             list($first, $ext) = self::splitFilenameExt($suggestedName);
             $title = Title::newFromText($name, NS_IMAGE);
             $file = wfFindFile($title);
             $vars = array('suggestedFirstPart' => $first, 'extension' => strtolower($ext), 'name' => $name, 'mwname' => $mwname, 'file' => $file, 'image_comment' => $comment);
             $wgOut->setStatusCode(200);
             $wgOut->addHTML(EasyTemplate::html('eiu_conflict.tmpl.php', $vars));
             // return no error
             return '';
         }
         // add watch to file is user needs it
         if ($wgUser->getOption('watchdefault') || $newFile && $wgUser->getOption('watchcreations')) {
             $wgUser->addWatch($title);
         }
         $db =& wfGetDB(DB_MASTER);
         $db->commit();
     } elseif (empty($mwname)) {
         $title = Title::makeTitleSafe(NS_IMAGE, $name);
     } elseif ($name !== null) {
         return WfMsg('eiu-warn3');
     } else {
         // name === null
         $title = Title::newFromText($mwname, NS_IMAGE);
     }
     $file = wfFindFile($title);
     if (!is_object($file)) {
         return wfMsg('File not found');
     }
     $details = self::splitValuePairs($wgRequest->getVal('image-details'));
     $tag = self::makeImageWikiTag($title, $file, $details);
     $vars = array('tag' => $tag, 'file' => $file, 'width' => $details['chosen-width'], 'height' => $details['chosen-height'], 'imageFilename' => $title->getText());
     if (!$fromIIA) {
         $vars['details'] = $details;
         $html = EasyTemplate::html('eiu_upload_summary.tmpl.php', $vars);
     } else {
         $html = IntroImageAdder::addIntroImage($vars);
     }
     $wgOut->setStatusCode(200);
     $wgOut->addHTML($html);
     // return no error
     return '';
 }
Пример #2
0
 public function saveSettings($settings, $cityId = null)
 {
     global $wgCityId, $wgUser;
     $cityId = empty($cityId) ? $wgCityId : $cityId;
     // Verify wordmark length ( CONN-116 )
     if (!empty($settings['wordmark-text'])) {
         $settings['wordmark-text'] = trim($settings['wordmark-text']);
     }
     if (empty($settings['wordmark-text'])) {
         // Do not save wordmark if its empty.
         unset($settings['wordmark-text']);
     } else {
         if (mb_strlen($settings['wordmark-text']) > 50) {
             $settings['wordmark-text'] = mb_substr($settings['wordmark-text'], 0, 50);
         }
     }
     if (isset($settings['favicon-image-name']) && strpos($settings['favicon-image-name'], 'Temp_file_') === 0) {
         $temp_file = new LocalFile(Title::newFromText($settings['favicon-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
         $file = new LocalFile(Title::newFromText(self::FaviconImageName, 6), RepoGroup::singleton()->getLocalRepo());
         $file->upload($temp_file->getPath(), '', '');
         $temp_file->delete('');
         Wikia::invalidateFavicon();
         $settings['favicon-image-url'] = $file->getURL();
         $settings['favicon-image-name'] = $file->getName();
         $file->repo->forceMaster();
         $history = $file->getHistory(1);
         if (count($history) == 1) {
             $oldFaviconFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
         }
     }
     if (isset($settings['wordmark-image-name']) && strpos($settings['wordmark-image-name'], 'Temp_file_') === 0) {
         $temp_file = new LocalFile(Title::newFromText($settings['wordmark-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
         $file = new LocalFile(Title::newFromText(self::WordmarkImageName, 6), RepoGroup::singleton()->getLocalRepo());
         $file->upload($temp_file->getPath(), '', '');
         $temp_file->delete('');
         $settings['wordmark-image-url'] = $file->getURL();
         $settings['wordmark-image-name'] = $file->getName();
         $file->repo->forceMaster();
         $history = $file->getHistory(1);
         if (count($history) == 1) {
             $oldFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
         }
     }
     if (isset($settings['background-image-name']) && strpos($settings['background-image-name'], 'Temp_file_') === 0) {
         $temp_file = new LocalFile(Title::newFromText($settings['background-image-name'], 6), RepoGroup::singleton()->getLocalRepo());
         $file = new LocalFile(Title::newFromText(self::BackgroundImageName, 6), RepoGroup::singleton()->getLocalRepo());
         $file->upload($temp_file->getPath(), '', '');
         $temp_file->delete('');
         $settings['background-image'] = $file->getURL();
         $settings['background-image-name'] = $file->getName();
         $settings['background-image-width'] = $file->getWidth();
         $settings['background-image-height'] = $file->getHeight();
         $imageServing = new ImageServing(null, 120, array("w" => "120", "h" => "65"));
         $settings['user-background-image'] = $file->getURL();
         $settings['user-background-image-thumb'] = wfReplaceImageServer($file->getThumbUrl($imageServing->getCut($file->getWidth(), $file->getHeight(), "origin") . "-" . $file->getName()));
         $file->repo->forceMaster();
         $history = $file->getHistory(1);
         if (count($history) == 1) {
             $oldBackgroundFile = array('url' => $history[0]->getURL(), 'name' => $history[0]->getArchiveName());
         }
     }
     $reason = wfMsg('themedesigner-reason', $wgUser->getName());
     // update history
     if (!empty($GLOBALS[self::WikiFactoryHistory])) {
         $history = $GLOBALS[self::WikiFactoryHistory];
         $lastItem = end($history);
         $revisionId = intval($lastItem['revision']) + 1;
     } else {
         $history = array();
         $revisionId = 1;
     }
     // #140758 - Jakub
     // validation
     // default color values
     foreach (ThemeDesignerHelper::getColorVars() as $sColorVar => $sDefaultValue) {
         if (!isset($settings[$sColorVar]) || !ThemeDesignerHelper::isValidColor($settings[$sColorVar])) {
             $settings[$sColorVar] = $sDefaultValue;
         }
     }
     // update WF variable with current theme settings
     WikiFactory::setVarByName(self::WikiFactorySettings, $cityId, $settings, $reason);
     // add entry
     $history[] = array('settings' => $settings, 'author' => $wgUser->getName(), 'timestamp' => wfTimestampNow(), 'revision' => $revisionId);
     // limit history size to last 10 changes
     $history = array_slice($history, -self::HistoryItemsLimit);
     if (count($history) > 1) {
         for ($i = 0; $i < count($history) - 1; $i++) {
             if (isset($oldFaviconFile) && isset($history[$i]['settings']['favicon-image-name'])) {
                 if ($history[$i]['settings']['favicon-image-name'] == self::FaviconImageName) {
                     $history[$i]['settings']['favicon-image-name'] = $oldFaviconFile['name'];
                     $history[$i]['settings']['favicon-image-url'] = $oldFaviconFile['url'];
                 }
             }
             if (isset($oldFile) && isset($history[$i]['settings']['wordmark-image-name'])) {
                 if ($history[$i]['settings']['wordmark-image-name'] == self::WordmarkImageName) {
                     $history[$i]['settings']['wordmark-image-name'] = $oldFile['name'];
                     $history[$i]['settings']['wordmark-image-url'] = $oldFile['url'];
                 }
             }
             if (isset($oldBackgroundFile) && isset($history[$i]['settings']['background-image-name'])) {
                 if ($history[$i]['settings']['background-image-name'] == self::BackgroundImageName) {
                     $history[$i]['settings']['background-image-name'] = $oldBackgroundFile['name'];
                 }
             }
         }
     }
     WikiFactory::setVarByName(self::WikiFactoryHistory, $cityId, $history, $reason);
 }
Пример #3
0
 public static function copyFile($params)
 {
     $apiManager = new ApiManager();
     $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
     $cloudspace = false;
     $cloudOrig = isset($params['cloud']['origin']) && strlen($params['cloud']['origin']) > 0 ? $params['cloud']['origin'] : null;
     $cloudDestination = isset($params['cloud']['destination']) && strlen($params['cloud']['destination']) > 0 ? $params['cloud']['destination'] : null;
     $pathCloud = "home://~" . $user->getName() . "/Cloudspaces/";
     $pathOrig = null;
     if ($cloudOrig) {
         if ($pathCloud . $cloudOrig == $params['orig']) {
             $pathOrig = "/";
         } else {
             $pathOrig = substr($params['orig'], strlen($pathCloud . $cloudOrig)) . "/";
         }
     }
     if ($cloudDestination) {
         $cloudspace = true;
     }
     $file = null;
     $isFolder = true;
     $tmpFile = null;
     $filename = null;
     $pathinfo = null;
     $pathAbsolute = null;
     if (!$params['file']['is_folder']) {
         $isFolder = false;
         $tmpFile = new LocalFile('/var/tmp/' . date('Y_m_d_H_i_s') . '_' . $user->getId());
         $pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($tmpFile->getAbsolutePath());
         if (array_key_exists('id', $params['file'])) {
             $token = $_SESSION['access_token_' . $cloudOrig . '_v2'];
             $resourceUrl = null;
             if (isset($params['file']['resource_url'])) {
                 $token = new stdClass();
                 $token->key = $params['access_token_key'];
                 $token->secret = $params['access_token_secret'];
                 $resourceUrl = $params['resource_url'];
             }
             $metadata = $apiManager->downloadMetadata($token, $params['file']['id'], $pathAbsolute, $user->getId(), true, $cloudOrig, $resourceUrl);
             if ($metadata['status'] == 'KO') {
                 if ($metadata['error'] == 403) {
                     $denied = self::permissionDeniedCloud($cloudOrig);
                     $metadata['path'] = $denied['path'];
                 }
                 return $metadata;
             } else {
                 if (isset($metadata['local'])) {
                     $file = FSI::getFile($params['file']['pathEyeos']);
                     $tmpFile->putContents($file->getContents());
                 }
             }
         } else {
             $file = FSI::getFile($params['file']['path']);
             $tmpFile->putContents($file->getContents());
         }
     }
     if ($pathOrig) {
         if ($params['file']['path'] == $pathOrig) {
             $pathinfo = pathinfo($params['file']['filename']);
         }
     } else {
         if ($params['file']['parent'] == null) {
             $pathinfo = pathinfo($params['file']['filename']);
         }
     }
     if ($pathinfo) {
         $nameForCheck = $pathinfo['filename'];
         $extension = null;
         if (isset($pathinfo['extension'])) {
             $extension = $pathinfo['extension'];
             $nameForCheck .= '.' . $extension;
         }
         $number = 1;
         $newFile = FSI::getFile($params['dest'] . "/" . $nameForCheck);
         while ($newFile->exists()) {
             $futureName = array($pathinfo['filename'], $number);
             $nameForCheck = implode(' ', $futureName);
             if ($extension) {
                 $nameForCheck .= '.' . $extension;
             }
             $number++;
             $newFile = FSI::getFile($params['dest'] . "/" . $nameForCheck);
             $params['filenameChange'] = $nameForCheck;
             if (!array_key_exists('parent', $params['file'])) {
                 $params['pathChange'] = substr($params['orig'], strlen($pathCloud . $cloudOrig));
             }
         }
         $filename = $newFile->getName();
     } else {
         $filename = $params['file']['filename'];
     }
     if ($cloudspace) {
         $pathParent = substr($params['dest'], strlen($pathCloud . $cloudDestination));
         if (array_key_exists('parent', $params['file'])) {
             if (strlen($pathParent) == 0 && !$params['file']['parent']) {
                 $pathParent = '/';
             }
             if ($params['file']['parent']) {
                 $pathParent .= $params['file']['parent'];
             }
         } else {
             $pathParent .= '/' . substr($params['file']['path'], strlen($pathOrig));
             if (strlen($pathParent) > 1) {
                 $pathParent = substr($pathParent, 0, -1);
             }
         }
         $folder = NULL;
         if ($pathParent !== '/') {
             $pos = strrpos($pathParent, '/');
             $folder = substr($pathParent, $pos + 1);
             $pathParent = substr($pathParent, 0, $pos + 1);
         }
         $parentId = false;
         if ($folder) {
             $path = $pathParent . $folder . '/';
             $lista = new stdClass();
             $lista->cloud = $cloudDestination;
             $lista->path = $pathParent;
             $lista->filename = $folder;
             $lista->user_eyeos = $user->getId();
             $u1db = json_decode($apiManager->callProcessU1db('parent', $lista));
             if ($u1db !== NULL && count($u1db) > 0) {
                 $parentId = $u1db[0]->id;
                 if ($parentId === 'null') {
                     $parentId = '0';
                 }
             }
         } else {
             $parentId = '0';
             $path = $pathParent;
         }
         if ($parentId !== false) {
             $token = $_SESSION['access_token_' . $cloudDestination . '_v2'];
             $resourceUrl = null;
             if (isset($params['resource_url'])) {
                 $token = new stdClass();
                 $token->key = $params['access_token_key'];
                 $token->secret = $params['access_token_secret'];
                 $resourceUrl = $params['resource_url'];
             }
             $metadata = $apiManager->createMetadata($cloudDestination, $token, $user->getId(), !$isFolder, $filename, $parentId, $path, $pathAbsolute, $resourceUrl);
             if ($metadata['status'] == 'KO') {
                 if ($metadata['error'] == 403) {
                     $denied = self::permissionDeniedCloud($cloudDestination);
                     $metadata['path'] = $denied['path'];
                 }
                 return $metadata;
             }
         }
     }
     $pathDest = null;
     if (array_key_exists('parent', $params['file'])) {
         if ($params['file']['parent']) {
             $pathDest = $params['dest'] . $params['file']['parent'] . '/';
         } else {
             $pathDest = $params['dest'] . '/';
         }
     } else {
         if ($pathOrig == $params['file']['path']) {
             $pathDest = $params['dest'] . '/';
         } else {
             $pathDest = $params['dest'] . '/' . substr($params['file']['path'], strlen($pathOrig));
         }
     }
     $pathDest .= $filename;
     $newFile = FSI::getFile($pathDest);
     if ($isFolder) {
         $newFile->mkdir();
     } else {
         $tmpFile->copyTo($newFile);
     }
     if ($tmpFile) {
         $tmpFile->delete();
     }
     return $params;
 }
Пример #4
0
 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;
 }
Пример #5
0
 function insertImage()
 {
     global $wgRequest, $wgUser, $wgContLang;
     $type = $wgRequest->getVal('type');
     $name = $wgRequest->getVal('name');
     $mwname = $wgRequest->getVal('mwname');
     $tempid = $wgRequest->getVal('tempid');
     '' != $wgRequest->getVal('gallery') ? $gallery = $wgRequest->getVal('gallery') : ($gallery = '');
     '' != $wgRequest->getVal('article') ? $title_main = urldecode($wgRequest->getVal('article')) : ($title_main = '');
     '' != $wgRequest->getCheck('fck') ? $fck = $wgRequest->getCheck('ns') : ($fck = false);
     '' != $wgRequest->getVal('ns') ? $ns = $wgRequest->getVal('ns') : ($ns = '');
     '' != $wgRequest->getVal('link') ? $link = urldecode($wgRequest->getVal('link')) : ($link = '');
     $extraId = $wgRequest->getVal('extraId');
     $newFile = true;
     if ($name !== NULL) {
         $name = urldecode($name);
         if ($name == '') {
             header('X-screen-type: error');
             return WfMsg('wmu-warn3');
         } else {
             $name = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $name);
             // did they give no extension at all when they changed the name?
             $ext = explode('.', $name);
             array_shift($ext);
             if (count($ext)) {
                 $finalExt = $ext[count($ext) - 1];
             } else {
                 $finalExt = '';
             }
             if ('' == $finalExt) {
                 header('X-screen-type: error');
                 return wfMsg('wmu-filetype-missing');
             }
             $title = Title::makeTitleSafe(NS_IMAGE, $name);
             if (is_null($title)) {
                 header('X-screen-type: error');
                 return wfMsg('wmu-filetype-incorrect');
             }
             if ($title->exists()) {
                 if ($type == 'overwrite') {
                     $title = Title::newFromText($name, 6);
                     // is the target protected?
                     $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
                     $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
                     $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
                     if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                         header('X-screen-type: error');
                         return wfMsg('wmu-file-protected');
                     }
                     $file_name = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
                     $file_mwname = new FakeLocalFile(Title::newFromText($mwname, 6), RepoGroup::singleton()->getLocalRepo());
                     if (!empty($extraId)) {
                         $flickrResult = $this->getFlickrPhotoInfo($extraId);
                         $nsid = $flickrResult['owner']['nsid'];
                         // e.g. 49127042@N00
                         $username = $flickrResult['owner']['username'];
                         // e.g. bossa67
                         $license = $flickrResult['license'];
                         $caption = '{{MediaWiki:Flickr' . intval($license) . '|1=' . wfEscapeWikiText($extraId) . '|2=' . wfEscapeWikiText($nsid) . '|3=' . wfEscapeWikiText($username) . '}}';
                     } else {
                         $caption = '';
                     }
                     $file_name->upload($file_mwname->getPath(), '', $caption);
                     $file_mwname->delete('');
                     $this->tempFileClearInfo($tempid);
                     $newFile = false;
                 } else {
                     if ($type == 'existing') {
                         $file = wfFindFile(Title::newFromText($name, 6));
                         if (!empty($file)) {
                             header('X-screen-type: existing');
                             $props = array();
                             $props['file'] = $file;
                             $props['mwname'] = $name;
                             $props['default_caption'] = Wikia::getProps($file->getTitle()->getArticleID(), 'default_caption');
                             return $this->detailsPage($props);
                         } else {
                             header('X-screen-type: error');
                             return wfMsg('wmu-file-error');
                         }
                     } else {
                         header('X-screen-type: conflict');
                         $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
                         // extensions check
                         list($partname, $ext) = UploadBase::splitExtensions($name);
                         if (count($ext)) {
                             $finalExt = $ext[count($ext) - 1];
                         } else {
                             $finalExt = '';
                         }
                         // for more than one "extension"
                         if (count($ext) > 1) {
                             for ($i = 0; $i < count($ext) - 1; $i++) {
                                 $partname .= '.' . $ext[$i];
                             }
                         }
                         $tmpl->set_vars(array('partname' => $partname, 'extension' => strtolower($finalExt), 'mwname' => $mwname, 'extraId' => $extraId));
                         return $tmpl->render('conflict');
                     }
                 }
             } else {
                 // is the target protected?
                 $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
                 $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
                 $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
                 if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                     header('X-screen-type: error');
                     wfMsg('wmu-file-protected');
                 }
                 $temp_file = new LocalFile(Title::newFromText($mwname, 6), RepoGroup::singleton()->getLocalRepo());
                 $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
                 if (!empty($extraId)) {
                     $flickrResult = $this->getFlickrPhotoInfo($extraId);
                     $nsid = $flickrResult['owner']['nsid'];
                     // e.g. 49127042@N00
                     $username = $flickrResult['owner']['username'];
                     // e.g. bossa67
                     $license = $flickrResult['license'];
                     $caption = '{{MediaWiki:Flickr' . intval($license) . '|1=' . wfEscapeWikiText($extraId) . '|2=' . wfEscapeWikiText($nsid) . '|3=' . wfEscapeWikiText($username) . '}}';
                 } else {
                     // get the supplied license value
                     $license = $wgRequest->getVal('ImageUploadLicense');
                     if ($license != '') {
                         $caption = '== ' . wfMsgForContent('license') . " ==\n" . '{{' . $license . '}}' . "\n";
                     } else {
                         $caption = "";
                     }
                 }
                 $file->upload($temp_file->getPath(), '', $caption);
                 $temp_file->delete('');
                 $this->tempFileClearInfo($tempid);
             }
             if ($wgUser->getOption('watchdefault') || $newFile && $wgUser->getOption('watchcreations')) {
                 $wgUser->addWatch($title);
             }
             $db =& wfGetDB(DB_MASTER);
             $db->commit();
         }
     } else {
         $title = Title::newFromText($mwname, 6);
     }
     $file = wfFindFile($title);
     if (!is_object($file)) {
         header('X-screen-type: error');
         return 'File was not found!';
     }
     if (-2 == $gallery && !$fck) {
         // this went in from the single placeholder...
         $name = $title->getText();
         $size = $wgRequest->getVal('size');
         $width = $wgRequest->getVal('width');
         $layout = $wgRequest->getVal('layout');
         // clear the old caption for upload
         $caption = $wgRequest->getVal('caption');
         $slider = $wgRequest->getVal('slider');
         $ns_vid = $wgContLang->getFormattedNsText(NS_FILE);
         $ns_img = ImagePlaceholderTranslateNsImage();
         $title_obj = Title::newFromText($title_main, $ns);
         $article_obj = new Article($title_obj);
         $text = $article_obj->getContent();
         wfRunHooks('WikiaMiniUpload::fetchTextForImagePlaceholder', array(&$title_obj, &$text));
         '' != $wgRequest->getVal('box') ? $box = $wgRequest->getVal('box') : ($box = '');
         $placeholder_msg = wfMsgForContent('imgplc-placeholder');
         $transl_v_t = '\\[\\[' . $ns_vid . ':' . $placeholder_msg . '[^\\]]*\\]\\]';
         $transl_i_t = '\\[\\[' . $ns_img . ':' . $placeholder_msg . '[^\\]]*\\]\\]';
         $success = false;
         preg_match_all('/' . $transl_v_t . '|' . $transl_i_t . '/si', $text, $matches, PREG_OFFSET_CAPTURE);
         if (is_array($matches) && $box < count($matches[0])) {
             $our_gallery = $matches[0][$box][0];
             $gallery_split = explode(':', $our_gallery);
             $thumb = false;
             $tag = $gallery_split[0] . ":" . $name;
             if ($size != 'full') {
                 $tag .= '|thumb';
                 $thumb = true;
             }
             if (isset($width)) {
                 $tag .= '|' . $width;
             }
             $tag .= '|' . $layout;
             if ($link != '') {
                 $tag .= '|link=' . $link;
             }
             if ($caption != '') {
                 $tag .= '|' . $caption;
             }
             $tag .= "]]";
             $text = substr_replace($text, $tag, $matches[0][$box][1], strlen($our_gallery));
             // return the proper embed code with all fancies around it
             $embed_code = $this->generateImage($file, $name, $title_obj, $thumb, (int) str_replace('px', '', $width), $layout, $caption);
             $message = wfMsg('wmu-success');
             Wikia::setVar('EditFromViewMode', true);
             $summary = wfMsg('wmu-added-from-plc');
             $success = $article_obj->doEdit($text, $summary);
         }
         if ($success) {
             header('X-screen-type: summary');
         } else {
             // failure signal opens js alert (BugId:4935)
             // header('X-screen-type: error');
         }
     } else {
         header('X-screen-type: summary');
         $size = $wgRequest->getVal('size');
         $width = $wgRequest->getVal('width');
         $layout = $wgRequest->getVal('layout');
         $caption = $wgRequest->getVal('caption');
         $slider = $wgRequest->getVal('slider');
         $ns_img = $wgContLang->getFormattedNsText(NS_IMAGE);
         $tag = '[[' . $ns_img . ':' . $title->getDBkey();
         if ($size != 'full' && ($file->getMediaType() == 'BITMAP' || $file->getMediaType() == 'DRAWING')) {
             $tag .= '|thumb';
             if ($layout != 'right') {
                 $tag .= '|' . $layout;
             }
             if ($slider == 'true') {
                 $tag .= '|' . $width;
             }
         }
         if ($link != '' && $size == 'full') {
             $tag .= '|link=' . $link;
         }
         if ($caption != '') {
             if ($size == 'full') {
                 $tag .= '|frame';
             }
             $tag .= '|' . $caption . ']]';
         } else {
             $tag .= ']]';
         }
     }
     $message = wfMsg('wmu-success');
     if ($wgRequest->getVal('update_caption') == 'on') {
         Wikia::setProps($title->getArticleID(), array('default_caption' => $caption));
     }
     $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $tmpl->set_vars(array('tag' => $tag, 'filename' => $ns_img . ':' . $title->getDBkey(), 'message' => $message, 'code' => isset($embed_code) ? $embed_code : ''));
     return $tmpl->render('summary');
 }
Пример #6
0
 protected function deleteImageHelper($imageName)
 {
     $title = Title::newFromText($imageName, NS_FILE);
     $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
     $visualization = new CityVisualization();
     $visualization->removeImageFromReview($this->wg->cityId, $title->getArticleId(), $this->wg->contLang->getCode());
     if ($file->exists()) {
         $file->delete('no longer needed');
     }
 }
Пример #7
0
 /**
  * @param bool $recursive
  * @param bool $onlyContents In the case of a directory, only delete the files it contains if TRUE
  * or the entire directory otherwise
  * @return bool TRUE if the file has been successfully deleted, FALSE otherwise
  */
 public function delete($recursive = false, $onlyContents = false)
 {
     $this->checkDeletePermission();
     return parent::delete($recursive, $onlyContents);
 }