/**
* The following member variables are not lazy-initialised
*/
- var $repo, $title, $lastError, $redirected, $redirectedTitle;
+
+ /**
+ * @var LocalRepo
+ */
+ var $repo;
+
+ /**
+ * @var Title
+ */
+ var $title;
+
+ var $lastError, $redirected, $redirectedTitle;
+
+ /**
+ * @var MediaHandler
+ */
+ protected $handler;
/**
* Call this constructor from child classes
* Split an internet media type into its two components; if not
* a two-part name, set the minor type to 'unknown'.
*
- * @param $mime "text/html" etc
+ * @param string $mime "text/html" etc
* @return array ("text", "html") etc
*/
- static function splitMime( $mime ) {
+ public static function splitMime( $mime ) {
if( strpos( $mime, '/' ) !== false ) {
return explode( '/', $mime, 2 );
} else {
/**
* Return the associated title object
+ * @return Title
*/
public function getTitle() { return $this->title; }
-
+
/**
* Return the title used to find this file
*/
* i.e. whether the files are all found in the same directory,
* or in hashed paths like /images/3/3c.
*
- * May return false if the file is not locally accessible.
+ * Most callers don't check the return value, but ForeignAPIFile::getPath
+ * returns false.
*/
public function getPath() {
if ( !isset( $this->path ) ) {
/**
* Alias for getPath()
+ *
+ * @deprecated since 1.18 Use getPath().
*/
public function getFullPath() {
+ wfDeprecated( __METHOD__ );
return $this->getPath();
}
}
/**
- * Get the duration of a media file in seconds
- */
- public function isVectorized() {
- $handler = $this->getHandler();
- if ( $handler ) {
- return $handler->isVectorized( $this );
- } else {
- return false;
- }
- }
+ * Return true if the file is vectorized
+ */
+ public function isVectorized() {
+ $handler = $this->getHandler();
+ if ( $handler ) {
+ return $handler->isVectorized( $this );
+ } else {
+ return false;
+ }
+ }
/**
*/
public function getMetadata() { return false; }
+ /**
+ * get versioned metadata
+ *
+ * @param $metadata Mixed Array or String of (serialized) metadata
+ * @param $version integer version number.
+ * @return Array containing metadata, or what was passed to it on fail (unserializing if not array)
+ */
+ public function convertMetadataVersion($metadata, $version) {
+ $handler = $this->getHandler();
+ if ( !is_array( $metadata ) ) {
+ //just to make the return type consistant
+ $metadata = unserialize( $metadata );
+ }
+ if ( $handler ) {
+ return $handler->convertMetadataVersion( $metadata, $version );
+ } else {
+ return $metadata;
+ }
+ }
+
/**
* Return the bit depth of the file
* Overridden by LocalFile
* It would be unsafe to include private images, making public thumbnails inadvertently
*
* @return boolean Whether file exists in the repository and is includable.
- * @public
*/
- function isVisible() {
+ public function isVisible() {
return $this->exists();
}
* @private -ish
*/
function thumbName( $params ) {
+ return $this->generateThumbName( $this->getName(), $params );
+ }
+
+ /**
+ * Generate a thumbnail file name from a name and specified parameters
+ *
+ * @param string $name
+ * @param array $params Parameters which will be passed to MediaHandler::makeParamString
+ */
+ function generateThumbName( $name, $params ) {
if ( !$this->getHandler() ) {
return null;
}
$extension = $this->getExtension();
list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
- $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getName();
+ $thumbName = $this->handler->makeParamString( $params ) . '-' . $name;
if ( $thumbExt != $extension ) {
$thumbName .= ".$thumbExt";
}
return $thumb->getUrl();
}
- /**
- * As createThumb, but returns a ThumbnailImage object. This can
- * provide access to the actual file, the real size of the thumb,
- * and can produce a convenient \<img\> tag for you.
- *
- * For non-image formats, this may return a filetype-specific icon.
- *
- * @param $width Integer: maximum width of the generated thumbnail
- * @param $height Integer: maximum height of the image (optional)
- * @param $render Integer: Deprecated
- *
- * @return ThumbnailImage or null on failure
- *
- * @deprecated use transform()
- */
- public function getThumbnail( $width, $height=-1, $render = true ) {
- $params = array( 'width' => $width );
- if ( $height != -1 ) {
- $params['height'] = $height;
- }
- return $this->transform( $params, 0 );
- }
-
/**
* Transform a media file
*
* @param $params Array: an associative array of handler-specific parameters.
* Typical keys are width, height and page.
* @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
- * @return MediaTransformOutput
+ * @return MediaTransformOutput | false
*/
function transform( $params, $flags = 0 ) {
global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch, $wgServer;
$thumbPath = $this->getThumbPath( $thumbName );
$thumbUrl = $this->getThumbUrl( $thumbName );
- if ( $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
+ if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
break;
}
if ( file_exists( $thumbPath )) {
$thumbTime = filemtime( $thumbPath );
if ( $thumbTime !== FALSE &&
- gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) {
-
+ gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) {
+
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
break;
}
$thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
}
}
-
- // Purge. Useful in the event of Core -> Squid connection failure or squid
- // purge collisions from elsewhere during failure. Don't keep triggering for
+
+ // Purge. Useful in the event of Core -> Squid connection failure or squid
+ // purge collisions from elsewhere during failure. Don't keep triggering for
// "thumbs" which have the main image URL though (bug 13776)
if ( $wgUseSquid && ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
SquidUpdate::purge( array( $thumbUrl ) );
/**
* Get a MediaHandler instance for this file
+ * @return MediaHandler
*/
function getHandler() {
if ( !isset( $this->handler ) ) {
$this->readOnlyError();
}
- /**
- * Get an array of Title objects which are articles which use this file
- * Also adds their IDs to the link cache
- *
- * This is mostly copied from Title::getLinksTo()
- *
- * @deprecated Use HTMLCacheUpdate, this function uses too much memory
- */
- function getLinksTo( $options = array() ) {
- wfProfileIn( __METHOD__ );
-
- // Note: use local DB not repo DB, we want to know local links
- if ( count( $options ) > 0 ) {
- $db = wfGetDB( DB_MASTER );
- } else {
- $db = wfGetDB( DB_SLAVE );
- }
- $linkCache = LinkCache::singleton();
-
- $encName = $db->addQuotes( $this->getName() );
- $res = $db->select( array( 'page', 'imagelinks'),
- array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
- array( 'page_id' => 'il_from', 'il_to' => $encName ),
- __METHOD__,
- $options );
-
- $retVal = array();
- if ( $db->numRows( $res ) ) {
- foreach ( $res as $row ) {
- $titleObj = Title::newFromRow( $row )
- if ( $titleObj ) {
- $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
- $retVal[] = $titleObj;
- }
- }
- }
- wfProfileOut( __METHOD__ );
- return $retVal;
- }
-
function formatMetadata() {
if ( !$this->getHandler() ) {
return false;
function getRepoName() {
return $this->repo ? $this->repo->getName() : 'unknown';
}
+
/*
* Returns the repository
*/
function isDeleted( $field ) {
return false;
}
-
+
/**
* Return the deletion bitfield
* STUB
- */
+ */
function getVisibility() {
return 0;
}
}
/**
- * Returns 'true' if this file is a type which supports multiple pages,
- * e.g. DJVU or PDF. Note that this may be true even if the file in
+ * Returns 'true' if this file is a type which supports multiple pages,
+ * e.g. DJVU or PDF. Note that this may be true even if the file in
* question only has a single page.
*
* @return Bool
}
/**
- * Returns the number of pages of a multipage document, or NULL for
+ * Returns the number of pages of a multipage document, or false for
* documents which aren't multipage documents
*/
function pageCount() {
/**
* Get the HTML text of the description page, if available
- * For local files ImagePage does not use it, because it skips the parser cache.
*/
function getDescriptionText() {
- if( $this->isLocal() ) {
- global $wgParser;
- $revision = Revision::newFromTitle( $this->title );
- if ( !$revision ) return false;
- $text = $revision->getText();
- if ( !$text ) return false;
- $pout = $wgParser->parse( $text, $this->title, new ParserOptions() );
- return $pout->getText();
- }
-
global $wgMemc, $wgLang;
if ( !$this->repo->fetchDescription ) {
return false;
if ( $renderUrl ) {
if ( $this->repo->descriptionCacheExpiry > 0 ) {
wfDebug("Attempting to get the description from cache...");
- $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
+ $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
$this->getName() );
$obj = $wgMemc->get($key);
if ($obj) {
}
$ext = $this->getExtension();
$dotExt = $ext === '' ? '' : ".$ext";
- return $hash . $dotExt;
+ return $hash . $dotExt;
}
/**
function getRedirected() {
return $this->redirected;
}
-
+
function getRedirectedTitle() {
if ( $this->redirected ) {
- if ( !$this->redirectTitle )
+ if ( !$this->redirectTitle ) {
$this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
+ }
return $this->redirectTitle;
}
}