コード例 #1
0
 protected static function getFileInfo($name)
 {
     $info = \WikiaDataAccess::cache(self::getFileKey($name), self::ICON_CACHE_TTL, function () use($name) {
         $file = \GlobalFile::newFromText($name . '.gif', \Wikia::NEWSLETTER_WIKI_ID);
         return ['name' => $name, 'url' => $file->getUrlGenerator()->url(), 'height' => $file->getHeight(), 'width' => $file->getWidth()];
     });
     return $info;
 }
コード例 #2
0
 public static function uploadFile(PromoImage $promoImage, GlobalTitle $sourceTitle, $sourceWikiId)
 {
     $sourceFile = \GlobalFile::newFromText($sourceTitle->getText(), $sourceWikiId);
     if (!$sourceFile->exists()) {
         echo "sourceFile doesn't exist" . PHP_EOL;
         return false;
     }
     $sourceImageUrl = $sourceFile->getUrl();
     $user = User::newFromName('WikiaBot');
     $imageData = new stdClass();
     $imageData->name = $promoImage->getPathname();
     $imageData->description = $imageData->comment = wfMessage('wikiahome-image-auto-uploaded-comment')->plain();
     $result = ImagesService::uploadImageFromUrl($sourceImageUrl, $imageData, $user);
     if (!$result['status']) {
         var_dump($result['errors'], $sourceImageUrl);
     }
     return $result['status'];
 }
コード例 #3
0
 public static function getImageSrcByTitle($cityId, $articleTitle, $width = null, $height = null)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     $imageKey = wfSharedMemcKey('image_url_from_wiki', $cityId . $articleTitle . $width . $height);
     $imageSrc = $wgMemc->get($imageKey);
     if ($imageSrc === false) {
         $globalFile = GlobalFile::newFromText($articleTitle, $cityId);
         if ($globalFile->exists()) {
             $imageSrc = $globalFile->getCrop($width, $height);
         } else {
             $imageSrc = null;
         }
         $wgMemc->set($imageKey, $imageSrc, 60 * 60 * 24 * 3);
     }
     wfProfileOut(__METHOD__);
     return $imageSrc;
 }
コード例 #4
0
ファイル: GlobalFileTest.php プロジェクト: Tjorriemorrie/app
 /**
  * @dataProvider testNewFromTextDbNameMatchProvider
  * @group UsingDB
  */
 public function testNewFromTextDbNameMatch($row, $cityId)
 {
     $this->getSelectRowMock()->expects($this->any())->method('selectRow')->will($this->returnCallback(function ($table, $vars, $conds, $fname) use($row) {
         if ($fname == 'GlobalFile::loadData') {
             if ($conds['img_name'] == $row->img_name) {
                 return $row;
             } else {
                 return false;
             }
         } else {
             // don't mess with WikiFactory accessing database
             return $this->getCurrentInvocation()->callOriginal();
         }
     }));
     $dbName = $row->img_name;
     $name = str_replace("_", " ", $dbName);
     $file = GlobalFile::newFromText($dbName, $cityId);
     $file2 = GlobalFile::newFromText($name, $cityId);
     $file3 = GlobalFile::newFromText("Not-existing-Image.jpg", $cityId);
     $this->assertTrue($file->exists());
     $this->assertTrue($file2->exists());
     $this->assertFalse($file3->exists());
 }
コード例 #5
0
 /**
  * @param int $imageId
  * @param string $destinationName
  * @param int $targetWikiId
  * @param int $sourceWikiId
  * @return array
  */
 public function uploadSingleImage($imageId, $destinationName, $targetWikiId, $sourceWikiId)
 {
     global $IP;
     $imageTitle = \GlobalTitle::newFromId($imageId, $sourceWikiId);
     $sourceFile = \GlobalFile::newFromText($imageTitle->getText(), $sourceWikiId);
     if ($sourceFile->exists()) {
         $sourceImageUrl = $sourceFile->getUrl();
     } else {
         $this->error('image is not accessible', ['city_id' => $sourceWikiId, 'title' => $imageTitle->getText()]);
         return ['status' => 1];
     }
     $cityUrl = \WikiFactory::getVarValueByName("wgServer", $targetWikiId);
     if (empty($cityUrl)) {
         $this->error('unable to get wgServer', ['wiki_id' => $targetWikiId]);
         return ['status' => 1];
     }
     $destinationName = \PromoImage::fromPathname($destinationName)->ensureCityIdIsSet($sourceWikiId)->getPathname();
     $command = "SERVER_ID={$targetWikiId} php {$IP}/maintenance/wikia/ImageReview/PromoteImage/upload.php" . ' --originalimageurl=' . escapeshellarg($sourceImageUrl) . ' --destimagename=' . escapeshellarg($destinationName) . ' --wikiid=' . escapeshellarg($sourceWikiId);
     $output = wfShellExec($command, $exitStatus);
     if ($exitStatus) {
         $this->error('uploadSingleImage error', ['command' => $command, 'city_url' => $cityUrl, 'output' => $output, 'exitStatus' => $exitStatus]);
     } else {
         $this->info('uploadSingleImage success', ['output' => $output, 'src_img_url' => $sourceImageUrl, 'dest_name' => $destinationName]);
     }
     $output = json_decode($output);
     return ['status' => $exitStatus, 'name' => $output->name, 'id' => $output->id];
 }
コード例 #6
0
ファイル: Wikia.php プロジェクト: Tjorriemorrie/app
 public static function getFaviconFullUrl()
 {
     global $wgMemc;
     $mMemcacheKey = wfMemcKey(self::FAVICON_URL_CACHE_KEY);
     $mData = $wgMemc->get($mMemcacheKey);
     $faviconFilename = 'Favicon.ico';
     if (empty($mData)) {
         $localFaviconTitle = Title::newFromText($faviconFilename, NS_FILE);
         #FIXME: Checking existance of Title in order to use File. #VID-1744
         if ($localFaviconTitle->exists()) {
             $localFavicon = wfFindFile($faviconFilename);
         }
         if ($localFavicon) {
             $favicon = $localFavicon->getURL();
         } else {
             $favicon = GlobalFile::newFromText($faviconFilename, self::COMMUNITY_WIKI_ID)->getURL();
         }
         $wgMemc->set($mMemcacheKey, $favicon, 86400);
     }
     return $mData;
 }
コード例 #7
0
 /**
  * Get thumbnail for given image.
  *
  * @param $fileName
  * @param $cityId
  */
 protected function getThumbData($fileName, $cityId)
 {
     $f = GlobalFile::newFromText($fileName, $cityId);
     if ($f instanceof GlobalFile && $f->exists()) {
         return ['url' => $f->getUrl(), 'width' => $f->getWidth(), 'height' => $f->getHeight()];
     } else {
         return ['url' => '', 'width' => null, 'height' => null];
     }
 }
コード例 #8
0
 /**
  * @param $outputModel
  * @return mixed
  */
 protected function getImage($wikiId, $articleId)
 {
     $dbName = '';
     try {
         $row = \WikiFactory::getWikiByID($wikiId);
         if ($row) {
             $dbName = $row->city_dbname;
             if (!empty($dbName)) {
                 $db = wfGetDB(DB_SLAVE, [], $dbName);
                 // throws if database does not exits.
                 $imageServing = new \ImageServing([$articleId], self::IMAGE_SIZE, self::IMAGE_SIZE, $db);
                 $isResult = $imageServing->getImages(1);
                 $images = isset($isResult[$articleId]) ? $isResult[$articleId] : false;
                 if ($images && sizeof($images) > 0) {
                     $imageName = $images[0]['name'];
                     $file = \GlobalFile::newFromText($imageName, $wikiId);
                     if ($file->exists()) {
                         return $imageServing->getUrl($file, $file->getWidth(), $file->getHeight());
                     }
                 }
             }
         }
     } catch (\DBConnectionError $ex) {
         // Swallow this exception. there is no simple way of telling if database does not exist other than catching exception.
         // Or am I wrong ?
         \Wikia::log(__METHOD__, false, "Cannot get database connection to " . $dbName);
     }
     return null;
 }
コード例 #9
0
 /**
  * @param string $imageName
  * @param string $lang
  * @param int $wikiId
  * @return GlobalFile|null
  */
 protected function findGlobalFileImage($imageName, $lang, $wikiId)
 {
     //try to find image on lang specific corporate wiki
     $f = null;
     $visualizationModel = new CityVisualization();
     $cityList = $visualizationModel->getVisualizationWikisData();
     if (isset($cityList[$lang])) {
         $f = GlobalFile::newFromText($imageName, $cityList[$lang]['wikiId']);
     } else {
         //if image wasn't found, try to find it on wiki itself
         $promoImage = (new PromoImage(PromoImage::MAIN))->setCityId($wikiId);
         $f = $promoImage->getOriginFile();
     }
     return $f;
 }
コード例 #10
0
 function uploadSingleImage($imageId, $destinationName, $targetWikiId, $sourceWikiId)
 {
     global $IP, $wgWikiaLocalSettingsPath;
     $retval = "";
     $imageTitle = GlobalTitle::newFromId($imageId, $sourceWikiId);
     $sourceImageUrl = null;
     $sourceFile = \GlobalFile::newFromText($imageTitle->getText(), $sourceWikiId);
     if ($sourceFile->exists()) {
         $sourceImageUrl = $sourceFile->getUrl();
     } else {
         $this->log('Apparently the image from city_id=' . $sourceWikiId . ' ' . $imageTitle->getText() . ' is unaccessible');
         return array('status' => 1);
     }
     $city_url = WikiFactory::getVarValueByName("wgServer", $targetWikiId);
     if (empty($city_url)) {
         $this->log('Apparently the server for ' . $targetWikiId . ' is not available via WikiFactory');
         return array('status' => 1);
     }
     $destinationName = PromoImage::fromPathname($destinationName)->ensureCityIdIsSet($sourceWikiId)->getPathname();
     $sCommand = "SERVER_ID={$targetWikiId} php {$IP}/maintenance/wikia/ImageReview/PromoteImage/upload.php";
     $sCommand .= " --originalimageurl=" . escapeshellarg($sourceImageUrl);
     $sCommand .= " --destimagename=" . escapeshellarg($destinationName);
     $sCommand .= " --wikiid=" . escapeshellarg($sourceWikiId);
     $sCommand .= " --conf {$wgWikiaLocalSettingsPath}";
     $logdata = ['command' => $sCommand, 'city_url' => $city_url];
     $output = wfShellExec($sCommand, $retval);
     $logdata['output'] = $output;
     $logdata['retval'] = $retval;
     if ($retval) {
         $this->log('Upload error! (' . $city_url . '). Error code returned: ' . $retval . ' Error was: ' . $output);
     } else {
         $this->log('Upload successful: ' . $output);
     }
     $output = json_decode($output);
     return array('status' => $retval, 'name' => $output->name, 'id' => $output->id);
 }
コード例 #11
0
 /**
  * Get interstitial data.  If format is json, returns data only.  Has template.
  * @requestParam integer wikiId
  * @responseParam array wikiAdminAvatars
  * @responseParam array wikiTopEditorAvatars
  * @responseParam array wikiStats
  * @responseParam array wikiInfo
  */
 public function getInterstitial()
 {
     $this->response->setCacheValidity(WikiaResponse::CACHE_SHORT);
     $wikiId = $this->request->getVal('wikiId', 0);
     $domain = $this->request->getVal('domain', null);
     if ($wikiId == 0 && $domain != null) {
         // This is not guaranteed valid for all domains, but the custom domains in use have aliases set up
         $domain = "{$domain}.wikia.com";
         $wikiId = WikiFactory::DomainToId($domain);
         if ($wikiId == 0) {
             throw new InvalidParameterApiException("domain");
         }
     }
     if ($wikiId == 0) {
         throw new MissingParameterApiException("wikiId or domain");
     }
     $this->wikiAdminAvatars = $this->helper->getWikiAdminAvatars($wikiId);
     $this->wikiTopEditorAvatars = $this->helper->getWikiTopEditorAvatars($wikiId);
     $tempArray = array();
     foreach ($this->helper->getWikiStats($wikiId) as $key => $value) {
         $tempArray[$key] = $this->wg->Lang->formatNum($value);
     }
     $this->wikiStats = $tempArray;
     $this->wikiInfo = $this->helper->getWikiInfoForVisualization($wikiId, $this->wg->contLang->getCode());
     $images = array();
     foreach ($this->wikiInfo['images'] as $image) {
         $images[] = $this->helper->getImageDataForSlider($wikiId, $image);
     }
     if (!empty($images[0])) {
         $this->wikiMainImageUrl = $images[0]['image_url'];
     } else {
         $this->wikiMainImageUrl = $this->wg->blankImgUrl;
     }
     if (!empty($this->app->wg->EnableWAMPageExt)) {
         $wamModel = new WAMPageModel();
         $this->wamUrl = $wamModel->getWAMMainPageUrl();
         $this->wikiWamScore = $this->helper->getWamScore($wikiId);
     }
     $this->imagesSlider = $this->sendRequest('WikiaMediaCarouselController', 'renderSlider', array('data' => $images));
     $wordmarkUrl = '';
     try {
         $title = GlobalTitle::newFromText('Wiki-wordmark.png', NS_FILE, $wikiId);
         if ($title !== null) {
             $file = new GlobalFile($title);
             if ($file !== null) {
                 $wordmarkUrl = $file->getUrl();
             }
         }
     } catch (Exception $e) {
     }
     $this->wordmark = $wordmarkUrl;
 }
コード例 #12
0
 protected function saveAdditionalFiles($additionalImagesNames)
 {
     $unchangedTypes = array();
     $imagesToProcess = array();
     $allFiles = array();
     foreach ($additionalImagesNames as $singleFileName) {
         $promoImage = PromoImage::fromPathname($singleFileName);
         if (!$promoImage->isType(PromoImage::INVALID)) {
             // check if file exists, if not do not add it to processed files, effectively removing it
             $file = GlobalFile::newFromText($promoImage->getPathname(), $this->wg->cityId);
             if ($file->exists()) {
                 array_push($promoImages, $promoImage);
             }
             if (in_array($unchangedTypes, $promoImage->getType())) {
                 WikiaLogger::instance()->info("SpecialPromote additional files duplicated type", ['method' => __METHOD__, 'type_duplicated' => $promoImage->getType()]);
             } else {
                 array_push($unchangedTypes, $promoImage->getType());
             }
             array_push($allFiles, $promoImage);
         } else {
             array_push($imagesToProcess, $singleFileName);
         }
     }
     $freeImageTypeSlots = array_diff(PromoImage::listAllAdditionalTypes(), $unchangedTypes);
     foreach ($imagesToProcess as $uploadedImageFileName) {
         $imageType = array_shift($freeImageTypeSlots);
         if (!empty($imageType)) {
             $promoImage = new PromoImage($imageType, $this->wg->DBname);
             $promoImage->processUploadedFile($uploadedImageFileName);
             array_push($allFiles, $promoImage);
         } else {
             WikiaLogger::instance()->info("SpecialPromote too many uploaded files", ['method' => __METHOD__]);
             break;
         }
     }
     foreach ($freeImageTypeSlots as $imageType) {
         $promoImage = new PromoImage($imageType, $this->wg->DBname);
         // attempt to delete leftover image types from current wiki
         if ($promoImage->getOriginFile(F::app()->wg->cityId)->exists()) {
             $promoImage->deleteImage();
         }
         // attempt to delete leftover image types from corporate wiki
         if ($promoImage->corporateFileByLang($this->wg->ContLanguageCode)->exists()) {
             $promoImage->deleteImageFromCorporate();
         }
     }
     return $allFiles;
 }
コード例 #13
0
 public static function fileExists(PromoImage $promoImage, $cityId)
 {
     $f = GlobalFile::newFromText($promoImage->getPathname(), $cityId);
     $title = GlobalTitle::newFromText($promoImage->getPathname(), NS_FILE, $cityId);
     return $title->exists() && $f->exists();
 }
コード例 #14
0
 /**
  * get image list
  * @return array imageList
  */
 public function getImageList($timestamp, $state = ImageReviewStatuses::STATE_UNREVIEWED, $order = self::ORDER_LATEST)
 {
     wfProfileIn(__METHOD__);
     $oDB = $this->getDatawareDB(DB_MASTER);
     $oDatabaseHelper = $this->getDatabaseHelper();
     $oResults = $oDatabaseHelper->selectImagesForList($this->getOrder($order), self::LIMIT_IMAGES_FROM_DB, $state);
     $rows = array();
     $updateWhere = array();
     $iconsWhere = array();
     while ($row = $oDB->fetchObject($oResults)) {
         $rows[] = $row;
         $updateWhere[] = "(wiki_id = {$row->wiki_id} and page_id = {$row->page_id})";
     }
     $oDB->freeResult($oResults);
     # update records
     if (count($updateWhere) > 0) {
         $review_start = wfTimestamp(TS_DB, $timestamp);
         switch ($state) {
             case ImageReviewStatuses::STATE_QUESTIONABLE:
                 $target_state = ImageReviewStatuses::STATE_QUESTIONABLE_IN_REVIEW;
                 break;
             case ImageReviewStatuses::STATE_REJECTED:
                 $target_state = ImageReviewStatuses::STATE_REJECTED_IN_REVIEW;
                 break;
             default:
                 $target_state = ImageReviewStatuses::STATE_IN_REVIEW;
         }
         $values = array('reviewer_id' => $this->user_id, 'review_start' => $review_start, 'state' => $target_state);
         if ($state == ImageReviewStatuses::STATE_QUESTIONABLE || $state == ImageReviewStatuses::STATE_REJECTED) {
             $values[] = "review_end = '0000-00-00 00:00:00'";
         }
         $oDB->update('image_review', $values, array(implode(' OR ', $updateWhere)), __METHOD__);
     }
     $oDB->commit();
     $imageList = $unusedImages = $aDeleteFromQueueList = [];
     foreach ($rows as $row) {
         $record = "(wiki_id = {$row->wiki_id} and page_id = {$row->page_id})";
         if (count($imageList) < self::LIMIT_IMAGES) {
             $bDisplayImage = true;
             $oImagePage = GlobalTitle::newFromId($row->page_id, $row->wiki_id);
             if ($oImagePage instanceof GlobalTitle !== true) {
                 $bDisplayImage = false;
                 $sReason = 'Page does not exist';
             } elseif ($oImagePage->isRedirect() === true) {
                 $bDisplayImage = false;
                 $sReason = 'Page is a redirect';
             } else {
                 $oImageGlobalFile = new GlobalFile($oImagePage);
                 if ($oImageGlobalFile->exists() === false) {
                     $bDisplayImage = false;
                     $sReason = 'File does not exist';
                 }
             }
             if ($bDisplayImage === true && $oImageGlobalFile instanceof GlobalFile) {
                 $sThumbUrl = $oImageGlobalFile->getUrlGenerator()->width(self::IMAGE_REVIEW_THUMBNAIL_SIZE)->height(self::IMAGE_REVIEW_THUMBNAIL_SIZE)->thumbnailDown()->url();
                 $aImageInfo = array('src' => $sThumbUrl, 'page' => $oImagePage->getFullUrl(), 'extension' => $oImageGlobalFile->getMimeType());
                 if (strpos('ico', $aImageInfo['extension'])) {
                     $iconsWhere[] = $record;
                     continue;
                 } else {
                     $isThumb = true;
                     // Vignette handles .gif and .svg files
                     $wikiRow = WikiFactory::getWikiByID($row->wiki_id);
                     $imageList[] = array('wikiId' => $row->wiki_id, 'pageId' => $row->page_id, 'state' => $row->state, 'src' => $aImageInfo['src'], 'url' => $aImageInfo['page'], 'priority' => $row->priority, 'flags' => $row->flags, 'isthumb' => $isThumb, 'wiki_url' => isset($wikiRow->city_url) ? $wikiRow->city_url : '');
                 }
             } else {
                 $aDeleteFromQueueList[] = ['wiki_id' => $row->wiki_id, 'page_id' => $row->page_id, 'reason' => $sReason];
                 continue;
             }
         } else {
             $unusedImages[] = $record;
         }
     }
     /**
      * Invalid images
      */
     if (!empty($aDeleteFromQueueList)) {
         $this->createDeleteFromQueueTask($aDeleteFromQueueList);
     }
     /**
      * Icons
      */
     if (!empty($iconsWhere)) {
         $aIconsValues = ['state' => ImageReviewStatuses::STATE_ICO_IMAGE];
         $aIconsWhere = [implode('OR', $iconsWhere)];
         $this->imageListAdditionalAction('icons', $oDB, $aIconsValues, $aIconsWhere);
     }
     /**
      * Unused images
      */
     if (!empty($unusedImages)) {
         $aUnusedValues = ['reviewer_id = null', 'state' => $state];
         $aUnusedWhere = [implode('OR', $unusedImages)];
         $this->imageListAdditionalAction('unused', $oDB, $aUnusedValues, $aUnusedWhere);
     }
     /**
      * Return valid images list
      */
     WikiaLogger::instance()->info("ImageReviewLog", ['method' => __METHOD__, 'message' => 'Fetched ' . count($imageList) . ' new images']);
     wfProfileOut(__METHOD__);
     return $imageList;
 }
コード例 #15
0
 public function corporateFileByLang($lang)
 {
     $wiki_id = (new WikiaCorporateModel())->getCorporateWikiIdByLang($lang);
     return GlobalFile::newFromText($this->getPathname(), $wiki_id);
 }
コード例 #16
0
ファイル: NjordUsage.php プロジェクト: Tjorriemorrie/app
 /**
  * @param $cityId
  * @param $data
  * @return array
  */
 private function formatOutputRowHTML($cityId, $data)
 {
     $njordProps = $this->getNjordPropIds();
     $row = [];
     $row["wiki_url"] = $this->getWikiaDataById($cityId)->city_url;
     $row[self::NJORD_ARTICLE_PROP_TITLE] = $data[$njordProps[self::NJORD_ARTICLE_PROP_TITLE]];
     $row[self::NJORD_ARTICLE_PROP_DESCR] = $data[$njordProps[self::NJORD_ARTICLE_PROP_DESCR]];
     if (!empty($data[$njordProps[self::NJORD_ARTICLE_PROP_IMAGE]])) {
         $heroImageTitle = $data[$njordProps[self::NJORD_ARTICLE_PROP_IMAGE]];
         $image = GlobalFile::newFromText($heroImageTitle, $cityId);
         $row[self::NJORD_ARTICLE_PROP_IMAGE] = $image->getUrlGenerator()->original()->url();
     } else {
         $row[self::NJORD_ARTICLE_PROP_IMAGE] = null;
     }
     return $row;
 }