/**
  * get video data from file
  * @param File $file
  * @param boolean $premiumOnly
  * @return array|null  $video
  */
 public function getVideoDataByFile($file, $premiumOnly = false)
 {
     $app = F::app();
     $app->wf->ProfileIn(__METHOD__);
     $video = null;
     if ($file instanceof File && $file->exists() && F::build('WikiaFileHelper', array($file), 'isFileTypeVideo')) {
         if (!($premiumOnly && $file->isLocal())) {
             $fileMetadata = $file->getMetadata();
             $userId = $file->getUser('id');
             $addedAt = $file->getTimestamp() ? $file->getTimestamp() : $this->wf->Timestamp(TS_MW);
             $duration = 0;
             $hdfile = 0;
             if ($fileMetadata) {
                 $fileMetadata = unserialize($fileMetadata);
                 if (array_key_exists('duration', $fileMetadata)) {
                     $duration = $fileMetadata['duration'];
                 }
                 if (array_key_exists('hd', $fileMetadata)) {
                     $hdfile = $fileMetadata['hd'] ? 1 : 0;
                 }
             }
             $premium = $file->isLocal() ? 0 : 1;
             $video = array('videoTitle' => $file->getTitle()->getDBKey(), 'addedAt' => $addedAt, 'addedBy' => $userId, 'duration' => $duration, 'premium' => $premium, 'hdfile' => $hdfile);
         }
     }
     $app->wf->ProfileOut(__METHOD__);
     return $video;
 }
 /**
  * Indexes document that was set in __construct.
  */
 public function indexCrawledDocuments()
 {
     $sFileName = $this->oFile->getName();
     $oFileMinorDocType = $this->oDbr->selectRow('image', 'img_minor_mime', array('img_name' => $sFileName, 'img_major_mime' => 'application'));
     if ($oFileMinorDocType === false) {
         return;
     }
     $sFileDocType = $this->mimeDecoding($oFileMinorDocType->img_minor_mime, $sFileName);
     if (!$this->checkDocType($sFileDocType, $sFileName)) {
         return;
     }
     $sFileTimestamp = $this->oFile->getTimestamp();
     $sVirtualFilePath = $this->oFile->getPath();
     $oFileRepoLocalRef = $this->oFile->getRepo()->getLocalReference($sVirtualFilePath);
     if (!is_null($oFileRepoLocalRef)) {
         $sFilePath = $oFileRepoLocalRef->getPath();
     }
     if ($this->checkExistence($sVirtualFilePath, 'repo', $sFileTimestamp, $sFileName)) {
         return;
     }
     $sFileText = $this->getFileText($sFilePath, $sFileName);
     $doc = $this->makeRepoDocument($sFileDocType, $sFileName, $sFileText, $sFilePath, $sFileTimestamp, $sVirtualFilePath);
     if ($doc) {
         // mode and ERROR_MSG_KEY are only passed for the case when addDocument fails
         $this->oMainControl->addDocument($doc, $this->mode, self::S_ERROR_MSG_KEY);
     }
 }
Example #3
0
 /**
  * @return String: timestamp
  */
 function getTimestamp()
 {
     if ($this->mRevision) {
         return $this->mRevision->getTimestamp();
     } elseif ($this->mImage) {
         return $this->mImage->getTimestamp();
     }
     return '';
 }
 /**
  * Get the link to the file.
  * Overridden by RevDelArchivedFileItem.
  * @return string
  */
 protected function getLink()
 {
     $date = htmlspecialchars($this->list->getLanguage()->userTimeAndDate($this->file->getTimestamp(), $this->list->getUser()));
     if (!$this->isDeleted()) {
         # Regular files...
         return Html::rawElement('a', array('href' => $this->file->getUrl()), $date);
     }
     # Hidden files...
     if (!$this->canViewContent()) {
         $link = $date;
     } else {
         $link = Linker::link(SpecialPage::getTitleFor('Revisiondelete'), $date, array(), array('target' => $this->list->title->getPrefixedText(), 'file' => $this->file->getArchiveName(), 'token' => $this->list->getUser()->getEditToken($this->file->getArchiveName())));
     }
     return '<span class="history-deleted">' . $link . '</span>';
 }
Example #5
0
 /**
  * Get file-based metadata in standardized format.
  *
  * Note that for a remote file, this might return metadata supplied by extensions.
  *
  * @param File $file File to use
  * @return array [<property name> => ['value' => <value>]], or [] on error
  * @since 1.23
  */
 protected function getExtendedMetadataFromFile(File $file)
 {
     // If this is a remote file accessed via an API request, we already
     // have remote metadata so we just ignore any local one
     if ($file instanceof ForeignAPIFile) {
         // In case of error we pretend no metadata - this will get cached.
         // Might or might not be a good idea.
         return $file->getExtendedMetadata() ?: [];
     }
     $uploadDate = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
     $fileMetadata = ['DateTime' => ['value' => $uploadDate, 'source' => 'mediawiki-metadata']];
     $title = $file->getTitle();
     if ($title) {
         $text = $title->getText();
         $pos = strrpos($text, '.');
         if ($pos) {
             $name = substr($text, 0, $pos);
         } else {
             $name = $text;
         }
         $fileMetadata['ObjectName'] = ['value' => $name, 'source' => 'mediawiki-metadata'];
     }
     return $fileMetadata;
 }
 /**
  * @param File $file
  * @return string
  */
 protected function getThumbForLine($file)
 {
     $lang = $this->getLanguage();
     $user = $this->getUser();
     if ($file->allowInlineDisplay() && $file->userCan(File::DELETED_FILE, $user) && !$file->isDeleted(File::DELETED_FILE)) {
         $params = ['width' => '120', 'height' => '120'];
         $timestamp = wfTimestamp(TS_MW, $file->getTimestamp());
         $thumbnail = $file->transform($params);
         $options = ['alt' => $this->msg('filehist-thumbtext', $lang->userTimeAndDate($timestamp, $user), $lang->userDate($timestamp, $user), $lang->userTime($timestamp, $user))->text(), 'file-link' => true];
         if (!$thumbnail) {
             return $this->msg('filehist-nothumb')->escaped();
         }
         return $thumbnail->toHtml($options);
     } else {
         return $this->msg('filehist-nothumb')->escaped();
     }
 }
Example #7
0
 /**
  * Extract the timestamp of the old version
  *
  * @return string
  */
 private function getTimestamp()
 {
     return $this->oldfile->getTimestamp();
 }
 /**
  * @param File $file
  * @param bool $dumpContents
  * @return string
  */
 function writeUpload($file, $dumpContents = false)
 {
     if ($file->isOld()) {
         $archiveName = "      " . Xml::element('archivename', null, $file->getArchiveName()) . "\n";
     } else {
         $archiveName = '';
     }
     if ($dumpContents) {
         $be = $file->getRepo()->getBackend();
         # Dump file as base64
         # Uses only XML-safe characters, so does not need escaping
         # @todo Too bad this loads the contents into memory (script might swap)
         $contents = '      <contents encoding="base64">' . chunk_split(base64_encode($be->getFileContents(array('src' => $file->getPath())))) . "      </contents>\n";
     } else {
         $contents = '';
     }
     if ($file->isDeleted(File::DELETED_COMMENT)) {
         $comment = Xml::element('comment', array('deleted' => 'deleted'));
     } else {
         $comment = Xml::elementClean('comment', null, $file->getDescription());
     }
     return "    <upload>\n" . $this->writeTimestamp($file->getTimestamp()) . $this->writeContributor($file->getUser('id'), $file->getUser('text')) . "      " . $comment . "\n" . "      " . Xml::element('filename', null, $file->getName()) . "\n" . $archiveName . "      " . Xml::element('src', null, $file->getCanonicalURL()) . "\n" . "      " . Xml::element('size', null, $file->getSize()) . "\n" . "      " . Xml::element('sha1base36', null, $file->getSha1()) . "\n" . "      " . Xml::element('rel', null, $file->getRel()) . "\n" . $contents . "    </upload>\n";
 }
Example #9
0
 function doQuery()
 {
     if ($this->mQueryDone) {
         return;
     }
     $this->mImg = $this->mImagePage->getFile();
     // ensure loading
     if (!$this->mImg->exists()) {
         return;
     }
     $queryLimit = $this->mLimit + 1;
     // limit plus extra row
     if ($this->mIsBackwards) {
         // Fetch the file history
         $this->mHist = $this->mImg->getHistory($queryLimit, null, $this->mOffset, false);
         // The current rev may not meet the offset/limit
         $numRows = count($this->mHist);
         if ($numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset) {
             $this->mHist = array_merge(array($this->mImg), $this->mHist);
         }
     } else {
         // The current rev may not meet the offset
         if (!$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset) {
             $this->mHist[] = $this->mImg;
         }
         // Old image versions (fetch extra row for nav links)
         $oiLimit = count($this->mHist) ? $this->mLimit : $this->mLimit + 1;
         // Fetch the file history
         $this->mHist = array_merge($this->mHist, $this->mImg->getHistory($oiLimit, $this->mOffset, null, false));
     }
     $numRows = count($this->mHist);
     // Total number of query results
     if ($numRows) {
         # Index value of top item in the list
         $firstIndex = $this->mIsBackwards ? $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp();
         # Discard the extra result row if there is one
         if ($numRows > $this->mLimit && $numRows > 1) {
             if ($this->mIsBackwards) {
                 # Index value of item past the index
                 $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp();
                 # Index value of bottom item in the list
                 $lastIndex = $this->mHist[1]->getTimestamp();
                 # Display range
                 $this->mRange = array(1, $numRows - 1);
             } else {
                 # Index value of item past the index
                 $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp();
                 # Index value of bottom item in the list
                 $lastIndex = $this->mHist[$numRows - 2]->getTimestamp();
                 # Display range
                 $this->mRange = array(0, $numRows - 2);
             }
         } else {
             # Setting indexes to an empty string means that they will be
             # omitted if they would otherwise appear in URLs. It just so
             # happens that this  is the right thing to do in the standard
             # UI, in all the relevant cases.
             $this->mPastTheEndIndex = '';
             # Index value of bottom item in the list
             $lastIndex = $this->mIsBackwards ? $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp();
             # Display range
             $this->mRange = array(0, $numRows - 1);
         }
     } else {
         $firstIndex = '';
         $lastIndex = '';
         $this->mPastTheEndIndex = '';
     }
     if ($this->mIsBackwards) {
         $this->mIsFirst = $numRows < $queryLimit;
         $this->mIsLast = $this->mOffset == '';
         $this->mLastShown = $firstIndex;
         $this->mFirstShown = $lastIndex;
     } else {
         $this->mIsFirst = $this->mOffset == '';
         $this->mIsLast = $numRows < $queryLimit;
         $this->mLastShown = $lastIndex;
         $this->mFirstShown = $firstIndex;
     }
     $this->mQueryDone = true;
 }
 /**
  *
  * @param Skin $skin
  * @param File $result
  * @return string
  */
 function formatResult($skin, $result)
 {
     global $wgContLang;
     $nt = $result->getTitle();
     $text = $wgContLang->convert($nt->getText());
     $plink = Linker::link(Title::newFromText($nt->getPrefixedText()), $text);
     $userText = $result->getUser('text');
     $user = Linker::link(Title::makeTitle(NS_USER, $userText), $userText);
     $time = $this->getLanguage()->userTimeAndDate($result->getTimestamp(), $this->getUser());
     return "{$plink} . . {$user} . . {$time}";
 }
 /**
  * Get a thumbnail object from a file and parameters.
  * If $path is set to null, the output file is treated as a source copy.
  * If $path is set to false, no output file will be created.
  *
  * @param File $file File object
  * @param string $url URL path to the thumb
  * @param int $width File's width
  * @param int $height File's height
  * @param string|bool|null $path Filesystem path to the thumb
  * @param int|bool $page Page number, for multi-page files
  */
 function __construct($file, $url, $width, $height, $path = false, $page = false)
 {
     $this->file = $file;
     $this->url = $url;
     # start wikia change
     $timestamp = !empty($file) ? $file->getTimestamp() : false;
     $this->url = wfReplaceImageServer($this->url, $timestamp);
     # end wikia change
     # These should be integers when they get here.
     # If not, there's a bug somewhere.  But let's at
     # least produce valid HTML code regardless.
     $this->width = round($width);
     $this->height = round($height);
     $this->path = $path;
     $this->page = $page;
 }
 public static function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     global $wgRTEParserEnabled;
     if (!empty($wgRTEParserEnabled)) {
         return true;
     }
     if (is_null(self::$isWikiaMobile)) {
         self::init();
     }
     if (self::$isWikiaMobile) {
         wfProfileIn(__METHOD__);
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         //Not all 'files' have getProviderName defined
         if (is_callable([$file, 'getProviderName'])) {
             $provider = $file->getProviderName();
         } else {
             $provider = '';
         }
         $imageParams = array('type' => 'video', 'provider' => $provider, 'full' => $imageAttribs['src']);
         if (!empty($imageAttribs['data-video-key'])) {
             $imageParams['name'] = htmlspecialchars($imageAttribs['data-video-key']);
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = 1;
         }
         // TODO: this resizes every video thumbnail with a width over 64px regardless of where it appears.
         // We may want to add the ability to allow custom image widths (like on the file page history table for example)
         $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
         $thumb = $file->transform($size);
         $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
         $imageAttribs['width'] = $size['width'];
         $imageAttribs['height'] = $size['height'];
         $data = ['attributes' => $imageAttribs, 'parameters' => [$imageParams], 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg, 'isSmall' => WikiaMobileMediaService::isSmallImage($imageAttribs['width'], $imageAttribs['height'])];
         $title = $file->getTitle()->getDBKey();
         $titleText = $file->getTitle()->getText();
         $views = MediaQueryService::getTotalVideoViewsByTitle($title);
         $data['content'] = Xml::element('span', ['class' => 'videoInfo'], "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . wfMessage('wikiamobile-video-views-counter', $views)->inContentLanguage()->text() . ')');
         $html = F::app()->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
         wfProfileOut(__METHOD__);
     }
     return true;
 }
 /**
  *
  * @param Skin $skin
  * @param File $result
  * @return string
  */
 function formatResult($skin, $result)
 {
     global $wgContLang, $wgLang;
     $nt = $result->getTitle();
     $text = $wgContLang->convert($nt->getText());
     $plink = $skin->link(Title::newFromText($nt->getPrefixedText()), $text);
     $userText = $result->getUser('text');
     $user = $skin->link(Title::makeTitle(NS_USER, $userText), $userText);
     $time = $wgLang->timeanddate($result->getTimestamp());
     return "{$plink} . . {$user} . . {$time}";
 }
 public function onThumbnailVideoHTML($options, $linkAttribs, $imageAttribs, File $file, &$html)
 {
     $this->wf->profileIn(__METHOD__);
     if (self::$isWikiaMobile) {
         /**
          * WikiaMobile: lazy loading images in a SEO-friendly manner
          * @author Federico "Lox" Lucignano <federico@wikia-inc.com
          * @author Artur Klajnerok <*****@*****.**>
          */
         $origImg = Xml::element('img', $imageAttribs, '', true);
         if (empty($imageAttribs['alt'])) {
             unset($imageAttribs['alt']);
         }
         $imageParams = array('type' => 'video', 'full' => $imageAttribs['src']);
         if (!empty($linkAttribs['data-video-name'])) {
             $imageParams['name'] = $linkAttribs['data-video-name'];
         }
         if (!empty($options['caption'])) {
             $imageParams['capt'] = true;
         }
         if ($file instanceof File) {
             $size = WikiaMobileMediaService::calculateMediaSize($file->getWidth(), $file->getHeight());
             $thumb = $file->transform($size);
             $imageAttribs['src'] = wfReplaceImageServer($thumb->getUrl(), $file->getTimestamp());
             $imageAttribs['width'] = $size['width'];
             $imageAttribs['height'] = $size['height'];
         }
         $data = array('attributes' => $imageAttribs, 'parameters' => array($imageParams), 'anchorAttributes' => $linkAttribs, 'noscript' => $origImg);
         if ($file instanceof File) {
             $title = $file->getTitle()->getDBKey();
             $titleText = $file->getTitle()->getText();
             $data['content'] = Xml::element('span', array('class' => 'videoInfo'), "{$titleText} (" . $file->getHandler()->getFormattedDuration() . ", " . $this->wf->MsgForContent('wikiamobile-video-views-counter', MediaQueryService::getTotalVideoViewsByTitle($title)) . ')');
         }
         $html = $this->app->sendRequest('WikiaMobileMediaService', 'renderImageTag', $data, true)->toString();
     }
     $this->wf->profileOut(__METHOD__);
     return true;
 }
 /**
  *
  * @param Skin $skin
  * @param File $result
  * @return string HTML
  */
 function formatResult($skin, $result)
 {
     global $wgContLang;
     $nt = $result->getTitle();
     $text = $wgContLang->convert($nt->getText());
     $plink = Linker::link($nt, htmlspecialchars($text));
     $userText = $result->getUser('text');
     if ($result->isLocal()) {
         $userId = $result->getUser('id');
         $user = Linker::userLink($userId, $userText);
         $user .= '<span style="white-space: nowrap;">';
         $user .= Linker::userToolLinks($userId, $userText);
         $user .= '</span>';
     } else {
         $user = htmlspecialchars($userText);
     }
     $time = htmlspecialchars($this->getLanguage()->userTimeAndDate($result->getTimestamp(), $this->getUser()));
     return "{$plink} . . {$user} . . {$time}";
 }
Example #16
0
 /**
  * Update the images's oi_deleted field
  * @param File $file
  * @param int $bitfield new rev_deleted bitfield value
  */
 function updateOldFiles($file, $bitfield)
 {
     $this->dbw->update('oldimage', array('oi_deleted' => $bitfield), array('oi_name' => $file->getName(), 'oi_timestamp' => $this->dbw->timestamp($file->getTimestamp())), __METHOD__);
 }
Example #17
0
 /**
  * Get file-based metadata in standardized format.
  *
  * Note that for a remote file, this might return metadata supplied by extensions.
  *
  * @param File $file File to use
  * @return array [<property name> => ['value' => <value>]], or [] on error
  * @since 1.23
  */
 protected function getExtendedMetadataFromFile(File $file)
 {
     // If this is a remote file accessed via an API request, we already
     // have remote metadata so we just ignore any local one
     if ($file instanceof ForeignAPIFile) {
         // In case of error we pretend no metadata - this will get cached.
         // Might or might not be a good idea.
         return $file->getExtendedMetadata() ?: array();
     }
     wfProfileIn(__METHOD__);
     $uploadDate = wfTimestamp(TS_ISO_8601, $file->getTimestamp());
     $fileMetadata = array('DateTime' => array('value' => $uploadDate, 'source' => 'mediawiki-metadata'));
     $title = $file->getTitle();
     if ($title) {
         $text = $title->getText();
         $pos = strrpos($text, '.');
         if ($pos) {
             $name = substr($text, 0, $pos);
         } else {
             $name = $text;
         }
         $fileMetadata['ObjectName'] = array('value' => $name, 'source' => 'mediawiki-metadata');
     }
     $common = $file->getCommonMetaArray();
     if ($common !== false) {
         foreach ($common as $key => $value) {
             $fileMetadata[$key] = array('value' => $value, 'source' => 'file-metadata');
         }
     }
     wfProfileOut(__METHOD__);
     return $fileMetadata;
 }
 /**
  * @param File $img
  * @param null|string $start
  * @return string
  */
 protected function getContinueStr($img, $start = null)
 {
     if ($start === null) {
         $start = $img->getTimestamp();
     }
     return $img->getOriginalTitle()->getDBkey() . '|' . $start;
 }
Example #19
0
 /**
  * Get the link to the file.
  * Overridden by RevDel_ArchivedFileItem.
  */
 protected function getLink()
 {
     $date = $this->list->getLang()->timeanddate($this->file->getTimestamp(), true);
     if ($this->isDeleted()) {
         # Hidden files...
         if (!$this->canViewContent()) {
             $link = $date;
         } else {
             $revdelete = SpecialPage::getTitleFor('Revisiondelete');
             $link = Linker::link($revdelete, $date, array(), array('target' => $this->list->title->getPrefixedText(), 'file' => $this->file->getArchiveName(), 'token' => $this->list->getUser()->editToken($this->file->getArchiveName())));
         }
         return '<span class="history-deleted">' . $link . '</span>';
     } else {
         # Regular files...
         return Xml::element('a', array('href' => $this->file->getUrl()), $date);
     }
 }
Example #20
0
 /**
  * Set the displayed file version
  *
  * @param File|bool $file
  * @return mixed Previous value
  */
 public function setFileVersion($file)
 {
     $val = null;
     if ($file instanceof File && $file->exists()) {
         $val = array('time' => $file->getTimestamp(), 'sha1' => $file->getSha1());
     }
     return wfSetVar($this->mFileVersion, $val, true);
 }
 public static function addToFileHistLine($hist, File $file, &$s, &$rowClass)
 {
     if (!$file->isVisible()) {
         return true;
         // Don't bother showing notice for deleted revs
     }
     # Quality level for old versions selected all at once.
     # Commons queries cannot be done all at once...
     if (!$file->isOld() || !$file->isLocal()) {
         $dbr = wfGetDB(DB_SLAVE);
         $quality = $dbr->selectField('flaggedrevs', 'fr_quality', array('fr_img_sha1' => $file->getSha1(), 'fr_img_timestamp' => $dbr->timestamp($file->getTimestamp())), __METHOD__);
     } else {
         $quality = is_null($file->quality) ? false : $file->quality;
     }
     # If reviewed, class the line
     if ($quality !== false) {
         $rowClass = FlaggedRevsXML::getQualityColor($quality);
     }
     return true;
 }