/** * Get a list of warnings * * @param $filename String: local filename, e.g. 'file exists', 'non-descriptive filename' * @return Array: list of warning messages */ public static function ajaxGetExistsWarning($filename) { $file = wfFindFile($filename); if (!$file) { // Force local file so we have an object to do further checks against // if there isn't an exact match... $file = wfLocalFile($filename); } $s = ' '; if ($file) { $exists = UploadBase::getExistsWarning($file); $warning = self::getExistsWarning($exists); if ($warning !== '') { $s = "<div>{$warning}</div>"; } } return $s; }
/** * Get result information for an image revision * * @param File $file * @param array $prop Array of properties to get (in the keys) * @param ApiResult $result * @param array $thumbParams Containing 'width' and 'height' items, or null * @param array|bool|string $opts Options for data fetching. * This is an array consisting of the keys: * 'version': The metadata version for the metadata option * 'language': The language for extmetadata property * 'multilang': Return all translations in extmetadata property * 'revdelUser': User to use when checking whether to show revision-deleted fields. * @return array Result array */ static function getInfo($file, $prop, $result, $thumbParams = null, $opts = false) { global $wgContLang; $anyHidden = false; if (!$opts || is_string($opts)) { $opts = array('version' => $opts ?: 'latest', 'language' => $wgContLang, 'multilang' => false, 'extmetadatafilter' => array(), 'revdelUser' => null); } $version = $opts['version']; $vals = array(ApiResult::META_TYPE => 'assoc'); // Timestamp is shown even if the file is revdelete'd in interface // so do same here. if (isset($prop['timestamp'])) { $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); } // Handle external callers who don't pass revdelUser if (isset($opts['revdelUser']) && $opts['revdelUser']) { $revdelUser = $opts['revdelUser']; $canShowField = function ($field) use($file, $revdelUser) { return $file->userCan($field, $revdelUser); }; } else { $canShowField = function ($field) use($file) { return !$file->isDeleted($field); }; } $user = isset($prop['user']); $userid = isset($prop['userid']); if ($user || $userid) { if ($file->isDeleted(File::DELETED_USER)) { $vals['userhidden'] = true; $anyHidden = true; } if ($canShowField(File::DELETED_USER)) { if ($user) { $vals['user'] = $file->getUser(); } if ($userid) { $vals['userid'] = $file->getUser('id'); } if (!$file->getUser('id')) { $vals['anon'] = true; } } } // This is shown even if the file is revdelete'd in interface // so do same here. if (isset($prop['size']) || isset($prop['dimensions'])) { $vals['size'] = intval($file->getSize()); $vals['width'] = intval($file->getWidth()); $vals['height'] = intval($file->getHeight()); $pageCount = $file->pageCount(); if ($pageCount !== false) { $vals['pagecount'] = $pageCount; } // length as in how many seconds long a video is. $length = $file->getLength(); if ($length) { // Call it duration, because "length" can be ambiguous. $vals['duration'] = (double) $length; } } $pcomment = isset($prop['parsedcomment']); $comment = isset($prop['comment']); if ($pcomment || $comment) { if ($file->isDeleted(File::DELETED_COMMENT)) { $vals['commenthidden'] = true; $anyHidden = true; } if ($canShowField(File::DELETED_COMMENT)) { if ($pcomment) { $vals['parsedcomment'] = Linker::formatComment($file->getDescription(File::RAW), $file->getTitle()); } if ($comment) { $vals['comment'] = $file->getDescription(File::RAW); } } } $canonicaltitle = isset($prop['canonicaltitle']); $url = isset($prop['url']); $sha1 = isset($prop['sha1']); $meta = isset($prop['metadata']); $extmetadata = isset($prop['extmetadata']); $commonmeta = isset($prop['commonmetadata']); $mime = isset($prop['mime']); $mediatype = isset($prop['mediatype']); $archive = isset($prop['archivename']); $bitdepth = isset($prop['bitdepth']); $uploadwarning = isset($prop['uploadwarning']); if ($uploadwarning) { $vals['html'] = SpecialUpload::getExistsWarning(UploadBase::getExistsWarning($file)); } if ($file->isDeleted(File::DELETED_FILE)) { $vals['filehidden'] = true; $anyHidden = true; } if ($anyHidden && $file->isDeleted(File::DELETED_RESTRICTED)) { $vals['suppressed'] = true; } if (!$canShowField(File::DELETED_FILE)) { //Early return, tidier than indenting all following things one level return $vals; } if ($canonicaltitle) { $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText(); } if ($url) { if (!is_null($thumbParams)) { $mto = $file->transform($thumbParams); self::$transformCount++; if ($mto && !$mto->isError()) { $vals['thumburl'] = wfExpandUrl($mto->getUrl(), PROTO_CURRENT); // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted // thumbnail sizes for the thumbnail actual size if ($mto->getUrl() !== $file->getUrl()) { $vals['thumbwidth'] = intval($mto->getWidth()); $vals['thumbheight'] = intval($mto->getHeight()); } else { $vals['thumbwidth'] = intval($file->getWidth()); $vals['thumbheight'] = intval($file->getHeight()); } if (isset($prop['thumbmime']) && $file->getHandler()) { list(, $mime) = $file->getHandler()->getThumbType($mto->getExtension(), $file->getMimeType(), $thumbParams); $vals['thumbmime'] = $mime; } } elseif ($mto && $mto->isError()) { $vals['thumberror'] = $mto->toText(); } } $vals['url'] = wfExpandUrl($file->getFullURL(), PROTO_CURRENT); $vals['descriptionurl'] = wfExpandUrl($file->getDescriptionUrl(), PROTO_CURRENT); } if ($sha1) { $vals['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 40); } if ($meta) { wfSuppressWarnings(); $metadata = unserialize($file->getMetadata()); wfRestoreWarnings(); if ($metadata && $version !== 'latest') { $metadata = $file->convertMetadataVersion($metadata, $version); } $vals['metadata'] = $metadata ? self::processMetaData($metadata, $result) : null; } if ($commonmeta) { $metaArray = $file->getCommonMetaArray(); $vals['commonmetadata'] = $metaArray ? self::processMetaData($metaArray, $result) : array(); } if ($extmetadata) { // Note, this should return an array where all the keys // start with a letter, and all the values are strings. // Thus there should be no issue with format=xml. $format = new FormatMetadata(); $format->setSingleLanguage(!$opts['multilang']); $format->getContext()->setLanguage($opts['language']); $extmetaArray = $format->fetchExtendedMetadata($file); if ($opts['extmetadatafilter']) { $extmetaArray = array_intersect_key($extmetaArray, array_flip($opts['extmetadatafilter'])); } $vals['extmetadata'] = $extmetaArray; } if ($mime) { $vals['mime'] = $file->getMimeType(); } if ($mediatype) { $vals['mediatype'] = $file->getMediaType(); } if ($archive && $file->isOld()) { $vals['archivename'] = $file->getArchiveName(); } if ($bitdepth) { $vals['bitdepth'] = $file->getBitDepth(); } return $vals; }
/** * Get result information for an image revision * * @param $file File object * @param array $prop of properties to get (in the keys) * @param $result ApiResult object * @param array $thumbParams containing 'width' and 'height' items, or null * @param string $version Version of image metadata (for things like jpeg which have different versions). * @return Array: result array */ static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) { $vals = array(); // Timestamp is shown even if the file is revdelete'd in interface // so do same here. if ( isset( $prop['timestamp'] ) ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() ); } $user = isset( $prop['user'] ); $userid = isset( $prop['userid'] ); if ( $user || $userid ) { if ( $file->isDeleted( File::DELETED_USER ) ) { $vals['userhidden'] = ''; } else { if ( $user ) { $vals['user'] = $file->getUser(); } if ( $userid ) { $vals['userid'] = $file->getUser( 'id' ); } if ( !$file->getUser( 'id' ) ) { $vals['anon'] = ''; } } } // This is shown even if the file is revdelete'd in interface // so do same here. if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) { $vals['size'] = intval( $file->getSize() ); $vals['width'] = intval( $file->getWidth() ); $vals['height'] = intval( $file->getHeight() ); $pageCount = $file->pageCount(); if ( $pageCount !== false ) { $vals['pagecount'] = $pageCount; } } $pcomment = isset( $prop['parsedcomment'] ); $comment = isset( $prop['comment'] ); if ( $pcomment || $comment ) { if ( $file->isDeleted( File::DELETED_COMMENT ) ) { $vals['commenthidden'] = ''; } else { if ( $pcomment ) { $vals['parsedcomment'] = Linker::formatComment( $file->getDescription(), $file->getTitle() ); } if ( $comment ) { $vals['comment'] = $file->getDescription(); } } } $url = isset( $prop['url'] ); $sha1 = isset( $prop['sha1'] ); $meta = isset( $prop['metadata'] ); $mime = isset( $prop['mime'] ); $mediatype = isset( $prop['mediatype'] ); $archive = isset( $prop['archivename'] ); $bitdepth = isset( $prop['bitdepth'] ); $uploadwarning = isset( $prop['uploadwarning'] ); if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth ) && $file->isDeleted( File::DELETED_FILE ) ) { $vals['filehidden'] = ''; //Early return, tidier than indenting all following things one level return $vals; } if ( $url ) { if ( !is_null( $thumbParams ) ) { $mto = $file->transform( $thumbParams ); self::$transformCount++; if ( $mto && !$mto->isError() ) { $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT ); // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted // thumbnail sizes for the thumbnail actual size if ( $mto->getUrl() !== $file->getUrl() ) { $vals['thumbwidth'] = intval( $mto->getWidth() ); $vals['thumbheight'] = intval( $mto->getHeight() ); } else { $vals['thumbwidth'] = intval( $file->getWidth() ); $vals['thumbheight'] = intval( $file->getHeight() ); } if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) { list( , $mime ) = $file->getHandler()->getThumbType( $mto->getExtension(), $file->getMimeType(), $thumbParams ); $vals['thumbmime'] = $mime; } } elseif ( $mto && $mto->isError() ) { $vals['thumberror'] = $mto->toText(); } } $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT ); $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT ); } if ( $sha1 ) { $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 ); } if ( $meta ) { wfSuppressWarnings(); $metadata = unserialize( $file->getMetadata() ); wfRestoreWarnings(); if ( $metadata && $version !== 'latest' ) { $metadata = $file->convertMetadataVersion( $metadata, $version ); } $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null; } if ( $mime ) { $vals['mime'] = $file->getMimeType(); } if ( $mediatype ) { $vals['mediatype'] = $file->getMediaType(); } if ( $archive && $file->isOld() ) { $vals['archivename'] = $file->getArchiveName(); } if ( $bitdepth ) { $vals['bitdepth'] = $file->getBitDepth(); } if ( $uploadwarning ) { $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) ); } return $vals; }