2007-05-30 21:02:32 +00:00
|
|
|
<?php
|
2012-02-08 15:51:16 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup FileAbstraction File abstraction
|
|
|
|
|
* @ingroup FileRepo
|
|
|
|
|
*
|
|
|
|
|
* Represents files in a repository.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-04 18:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* Base code for files.
|
|
|
|
|
*
|
2012-05-07 07:11:33 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-09-04 18:13:18 +00:00
|
|
|
* @file
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
2010-09-04 18:13:18 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Implements some public methods and some protected utility functions which
|
|
|
|
|
* are required by multiple child classes. Contains stub functionality for
|
2007-05-30 21:02:32 +00:00
|
|
|
* unimplemented public methods.
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Stub functions which should be overridden are marked with STUB. Some more
|
2007-05-30 21:02:32 +00:00
|
|
|
* concrete functions are also typically overridden by child classes.
|
|
|
|
|
*
|
2007-05-31 01:43:41 +00:00
|
|
|
* Note that only the repo object knows what its file class is called. You should
|
2008-04-14 07:45:50 +00:00
|
|
|
* never name a file class explictly outside of the repo class. Instead use the
|
2007-05-31 01:43:41 +00:00
|
|
|
* repo's factory functions to generate file objects, for example:
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2013-02-03 19:42:08 +00:00
|
|
|
* RepoGroup::singleton()->getLocalRepo()->newFile( $title );
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2007-05-31 01:43:41 +00:00
|
|
|
* The convenience functions wfLocalFile() and wfFindFile() should be sufficient
|
|
|
|
|
* in most cases.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2012-02-08 15:51:16 +00:00
|
|
|
* @ingroup FileAbstraction
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
abstract class File {
|
2013-07-07 20:54:26 +00:00
|
|
|
// Bitfield values akin to the Revision deletion constants
|
2007-05-30 21:02:32 +00:00
|
|
|
const DELETED_FILE = 1;
|
|
|
|
|
const DELETED_COMMENT = 2;
|
|
|
|
|
const DELETED_USER = 4;
|
|
|
|
|
const DELETED_RESTRICTED = 8;
|
2011-11-03 17:06:44 +00:00
|
|
|
|
|
|
|
|
/** Force rendering in the current process */
|
2013-02-03 19:42:08 +00:00
|
|
|
const RENDER_NOW = 1;
|
2011-11-03 17:06:44 +00:00
|
|
|
/**
|
|
|
|
|
* Force rendering even if thumbnail already exist and using RENDER_NOW
|
2011-12-27 00:28:23 +00:00
|
|
|
* I.e. you have to pass both flags: File::RENDER_NOW | File::RENDER_FORCE
|
2011-11-03 17:06:44 +00:00
|
|
|
*/
|
|
|
|
|
const RENDER_FORCE = 2;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
const DELETE_SOURCE = 1;
|
|
|
|
|
|
2012-06-05 22:58:54 +00:00
|
|
|
// Audience options for File::getDescription()
|
|
|
|
|
const FOR_PUBLIC = 1;
|
|
|
|
|
const FOR_THIS_USER = 2;
|
|
|
|
|
const RAW = 3;
|
|
|
|
|
|
2012-09-04 16:57:44 +00:00
|
|
|
// Options for File::thumbName()
|
|
|
|
|
const THUMB_FULL_NAME = 1;
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
|
|
|
|
* Some member variables can be lazy-initialised using __get(). The
|
2007-05-30 21:02:32 +00:00
|
|
|
* initialisation function for these variables is always a function named
|
2008-04-14 07:45:50 +00:00
|
|
|
* like getVar(), where Var is the variable name with upper-case first
|
2007-05-30 21:02:32 +00:00
|
|
|
* letter.
|
|
|
|
|
*
|
|
|
|
|
* The following variables are initialised in this way in this base class:
|
2008-04-14 07:45:50 +00:00
|
|
|
* name, extension, handler, path, canRender, isSafeFile,
|
2007-05-30 21:02:32 +00:00
|
|
|
* transformScript, hashPath, pageCount, url
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Code within this class should generally use the accessor function
|
2007-05-30 21:02:32 +00:00
|
|
|
* directly, since __get() isn't re-entrant and therefore causes bugs that
|
|
|
|
|
* depend on initialisation order.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The following member variables are not lazy-initialised
|
|
|
|
|
*/
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2013-12-05 09:13:28 +00:00
|
|
|
/** @var FileRepo|LocalRepo|ForeignAPIRepo|bool */
|
2013-11-24 08:12:23 +00:00
|
|
|
public $repo;
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var Title|string|bool */
|
|
|
|
|
protected $title;
|
2011-02-18 23:56:08 +00:00
|
|
|
|
2014-02-05 11:02:29 +00:00
|
|
|
/** @var string Text of last error */
|
2013-11-24 08:12:23 +00:00
|
|
|
protected $lastError;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2014-02-05 11:02:29 +00:00
|
|
|
/** @var string Main part of the title, with underscores (Title::getDBkey) */
|
2013-11-24 08:12:23 +00:00
|
|
|
protected $redirected;
|
|
|
|
|
|
|
|
|
|
/** @var Title */
|
|
|
|
|
protected $redirectedTitle;
|
|
|
|
|
|
|
|
|
|
/** @var FSFile|bool False if undefined */
|
2011-12-20 03:52:06 +00:00
|
|
|
protected $fsFile;
|
|
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var MediaHandler */
|
2011-03-13 22:58:41 +00:00
|
|
|
protected $handler;
|
|
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var string The URL corresponding to one of the four basic zones */
|
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
|
|
/** @var string File extension */
|
|
|
|
|
protected $extension;
|
|
|
|
|
|
|
|
|
|
/** @var string The name of a file from its title object */
|
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
|
|
/** @var string The storage path corresponding to one of the zones */
|
|
|
|
|
protected $path;
|
|
|
|
|
|
|
|
|
|
/** @var string Relative path including trailing slash */
|
|
|
|
|
protected $hashPath;
|
|
|
|
|
|
2014-07-24 17:43:03 +00:00
|
|
|
/** @var string Number of pages of a multipage document, or false for
|
2013-11-24 08:12:23 +00:00
|
|
|
* documents which aren't multipage documents
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
2013-11-24 08:12:23 +00:00
|
|
|
protected $pageCount;
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var string URL of transformscript (for example thumb.php) */
|
|
|
|
|
protected $transformScript;
|
|
|
|
|
|
|
|
|
|
/** @var Title */
|
2012-05-18 02:58:15 +00:00
|
|
|
protected $redirectTitle;
|
|
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var bool Wether the output of transform() for this file is likely to be valid. */
|
|
|
|
|
protected $canRender;
|
2011-09-07 12:00:58 +00:00
|
|
|
|
2013-11-24 08:12:23 +00:00
|
|
|
/** @var bool Wether this media file is in a format that is unlikely to
|
|
|
|
|
* contain viruses or malicious content
|
2011-11-07 21:54:19 +00:00
|
|
|
*/
|
2013-11-24 08:12:23 +00:00
|
|
|
protected $isSafeFile;
|
|
|
|
|
|
|
|
|
|
/** @var string Required Repository class type */
|
2011-11-07 21:54:19 +00:00
|
|
|
protected $repoClass = 'FileRepo';
|
|
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
/** @var array Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width */
|
|
|
|
|
protected $tmpBucketedThumbCache = array();
|
|
|
|
|
|
2011-11-07 21:54:19 +00:00
|
|
|
/**
|
|
|
|
|
* Call this constructor from child classes.
|
2011-12-27 00:28:23 +00:00
|
|
|
*
|
2011-11-07 21:54:19 +00:00
|
|
|
* Both $title and $repo are optional, though some functions
|
|
|
|
|
* may return false or throw exceptions if they are not set.
|
|
|
|
|
* Most subclasses will want to call assertRepoDefined() here.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param Title|string|bool $title
|
|
|
|
|
* @param FileRepo|bool $repo
|
2007-05-31 01:43:41 +00:00
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function __construct( $title, $repo ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
if ( $title !== false ) { // subclasses may not use MW titles
|
2011-11-04 23:49:03 +00:00
|
|
|
$title = self::normalizeTitle( $title, 'exception' );
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->title = $title;
|
|
|
|
|
$this->repo = $repo;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-04 23:49:03 +00:00
|
|
|
/**
|
|
|
|
|
* Given a string or Title object return either a
|
|
|
|
|
* valid Title object with namespace NS_FILE or null
|
2011-12-20 03:52:06 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param Title|string $title
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string|bool $exception Use 'exception' to throw an error on bad titles
|
2012-05-18 02:58:15 +00:00
|
|
|
* @throws MWException
|
2011-11-04 23:49:03 +00:00
|
|
|
* @return Title|null
|
|
|
|
|
*/
|
|
|
|
|
static function normalizeTitle( $title, $exception = false ) {
|
|
|
|
|
$ret = $title;
|
|
|
|
|
if ( $ret instanceof Title ) {
|
|
|
|
|
# Normalize NS_MEDIA -> NS_FILE
|
|
|
|
|
if ( $ret->getNamespace() == NS_MEDIA ) {
|
|
|
|
|
$ret = Title::makeTitleSafe( NS_FILE, $ret->getDBkey() );
|
|
|
|
|
# Sanity check the title namespace
|
|
|
|
|
} elseif ( $ret->getNamespace() !== NS_FILE ) {
|
|
|
|
|
$ret = null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# Convert strings to Title objects
|
|
|
|
|
$ret = Title::makeTitleSafe( NS_FILE, (string)$ret );
|
|
|
|
|
}
|
|
|
|
|
if ( !$ret && $exception !== false ) {
|
|
|
|
|
throw new MWException( "`$title` is not a valid file title." );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-11-04 23:49:03 +00:00
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
function __get( $name ) {
|
|
|
|
|
$function = array( $this, 'get' . ucfirst( $name ) );
|
|
|
|
|
if ( !is_callable( $function ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
$this->$name = call_user_func( $function );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->$name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize a file extension to the common form, and ensure it's clean.
|
|
|
|
|
* Extensions with non-alphanumeric characters will be discarded.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $ext (without the .)
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
static function normalizeExtension( $ext ) {
|
|
|
|
|
$lower = strtolower( $ext );
|
|
|
|
|
$squish = array(
|
|
|
|
|
'htm' => 'html',
|
|
|
|
|
'jpeg' => 'jpg',
|
|
|
|
|
'mpeg' => 'mpg',
|
2008-06-06 19:58:06 +00:00
|
|
|
'tiff' => 'tif',
|
|
|
|
|
'ogv' => 'ogg' );
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( isset( $squish[$lower] ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return $squish[$lower];
|
2013-04-20 17:18:13 +00:00
|
|
|
} elseif ( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return $lower;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
/**
|
|
|
|
|
* Checks if file extensions are compatible
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param File $old Old file
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $new New name
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return bool|null
|
2008-05-03 13:09:34 +00:00
|
|
|
*/
|
2008-05-03 13:39:10 +00:00
|
|
|
static function checkExtensionCompatibility( File $old, $new ) {
|
2008-05-03 13:09:34 +00:00
|
|
|
$oldMime = $old->getMimeType();
|
|
|
|
|
$n = strrpos( $new, '.' );
|
2011-12-20 03:52:06 +00:00
|
|
|
$newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' );
|
2008-05-03 13:09:34 +00:00
|
|
|
$mimeMagic = MimeMagic::singleton();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Upgrade the database row if there is one
|
|
|
|
|
* Called by ImagePage
|
|
|
|
|
* STUB
|
|
|
|
|
*/
|
2013-11-23 20:00:11 +00:00
|
|
|
function upgradeRow() {
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Split an internet media type into its two components; if not
|
|
|
|
|
* a two-part name, set the minor type to 'unknown'.
|
|
|
|
|
*
|
2011-03-13 22:02:40 +00:00
|
|
|
* @param string $mime "text/html" etc
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return array ("text", "html") etc
|
|
|
|
|
*/
|
2011-03-13 22:02:40 +00:00
|
|
|
public static function splitMime( $mime ) {
|
2013-04-20 17:18:13 +00:00
|
|
|
if ( strpos( $mime, '/' ) !== false ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return explode( '/', $mime, 2 );
|
|
|
|
|
} else {
|
|
|
|
|
return array( $mime, 'unknown' );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2012-07-08 08:45:21 +00:00
|
|
|
/**
|
2012-08-01 17:40:10 +00:00
|
|
|
* Callback for usort() to do file sorts by name
|
2012-07-08 08:45:21 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param File $a
|
|
|
|
|
* @param File $b
|
|
|
|
|
* @return int Result of name comparison
|
2012-07-08 08:45:21 +00:00
|
|
|
*/
|
|
|
|
|
public static function compare( File $a, File $b ) {
|
2012-08-01 17:40:10 +00:00
|
|
|
return strcmp( $a->getName(), $b->getName() );
|
2012-07-08 08:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Return the name of this file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function getName() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->name ) ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2007-06-03 10:44:27 +00:00
|
|
|
$this->name = $this->repo->getNameFromTitle( $this->title );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->name;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the file extension, e.g. "svg"
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getExtension() {
|
|
|
|
|
if ( !isset( $this->extension ) ) {
|
|
|
|
|
$n = strrpos( $this->getName(), '.' );
|
2008-04-14 07:45:50 +00:00
|
|
|
$this->extension = self::normalizeExtension(
|
2007-05-30 21:02:32 +00:00
|
|
|
$n ? substr( $this->getName(), $n + 1 ) : '' );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->extension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the associated title object
|
2011-12-20 03:52:06 +00:00
|
|
|
*
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return Title
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
public function getTitle() {
|
|
|
|
|
return $this->title;
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2008-05-20 17:05:57 +00:00
|
|
|
/**
|
|
|
|
|
* Return the title used to find this file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return Title
|
2008-05-20 17:05:57 +00:00
|
|
|
*/
|
|
|
|
|
public function getOriginalTitle() {
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $this->redirected ) {
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->getRedirectedTitle();
|
2011-05-29 13:33:29 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->title;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the URL of the file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
public function getUrl() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->url ) ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2012-10-13 00:24:31 +00:00
|
|
|
$ext = $this->getExtension();
|
|
|
|
|
$this->url = $this->repo->getZoneUrl( 'public', $ext ) . '/' . $this->getUrlRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
return $this->url;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-09-14 15:29:52 +00:00
|
|
|
/**
|
|
|
|
|
* Return a fully-qualified URL to the file.
|
|
|
|
|
* Upload URL paths _may or may not_ be fully qualified, so
|
|
|
|
|
* we check. Local paths are assumed to belong on $wgServer.
|
2010-03-25 20:12:56 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return string
|
2007-09-14 15:29:52 +00:00
|
|
|
*/
|
|
|
|
|
public function getFullUrl() {
|
2011-08-19 15:27:49 +00:00
|
|
|
return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE );
|
|
|
|
|
}
|
2011-09-07 12:00:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-08-19 15:27:49 +00:00
|
|
|
public function getCanonicalUrl() {
|
|
|
|
|
return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL );
|
2007-09-14 15:29:52 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getViewURL() {
|
2011-12-27 22:49:37 +00:00
|
|
|
if ( $this->mustRender() ) {
|
|
|
|
|
if ( $this->canRender() ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->createThumb( $this->getWidth() );
|
2011-05-29 13:33:29 +00:00
|
|
|
} else {
|
2013-02-03 19:42:08 +00:00
|
|
|
wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() .
|
2011-12-27 22:49:37 +00:00
|
|
|
' (' . $this->getMimeType() . "), but can't!\n" );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->getURL(); #hm... return NULL?
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return $this->getURL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-10 15:37:33 +00:00
|
|
|
* Return the storage path to the file. Note that this does
|
|
|
|
|
* not mean that a file actually exists under that location.
|
|
|
|
|
*
|
|
|
|
|
* This path depends on whether directory hashing is active or not,
|
|
|
|
|
* i.e. whether the files are all found in the same directory,
|
|
|
|
|
* or in hashed paths like /images/3/3c.
|
|
|
|
|
*
|
|
|
|
|
* Most callers don't check the return value, but ForeignAPIFile::getPath
|
|
|
|
|
* returns false.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return string|bool ForeignAPIFile::getPath can return false
|
2013-03-07 16:27:38 +00:00
|
|
|
*/
|
2008-01-15 15:02:36 +00:00
|
|
|
public function getPath() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->path ) ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
|
|
|
|
$this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get an FS copy or original of this file and return the path.
|
|
|
|
|
* Returns false on failure. Callers must not alter the file.
|
|
|
|
|
* Temporary files are cleared automatically.
|
2011-12-27 00:28:23 +00:00
|
|
|
*
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return string|bool False on failure
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
|
|
|
|
public function getLocalRefPath() {
|
|
|
|
|
$this->assertRepoDefined();
|
|
|
|
|
if ( !isset( $this->fsFile ) ) {
|
|
|
|
|
$this->fsFile = $this->repo->getLocalReference( $this->getPath() );
|
|
|
|
|
if ( !$this->fsFile ) {
|
|
|
|
|
$this->fsFile = false; // null => false; cache negative hits
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return ( $this->fsFile )
|
|
|
|
|
? $this->fsFile->getPath()
|
|
|
|
|
: false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the width of the image. Returns false if the width is unknown
|
2007-05-30 21:02:32 +00:00
|
|
|
* or undefined.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $page
|
|
|
|
|
* @return int|bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
public function getWidth( $page = 1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the height of the image. Returns false if the height is unknown
|
2007-05-30 21:02:32 +00:00
|
|
|
* or undefined
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
2011-05-29 14:01:47 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $page
|
|
|
|
|
* @return bool|int False on failure
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
public function getHeight( $page = 1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
/**
|
|
|
|
|
* Return the smallest bucket from $wgThumbnailBuckets which is at least
|
|
|
|
|
* $wgThumbnailMinimumBucketDistance larger than $desiredWidth. The returned bucket, if any,
|
|
|
|
|
* will always be bigger than $desiredWidth.
|
|
|
|
|
*
|
|
|
|
|
* @param int $desiredWidth
|
|
|
|
|
* @param int $page
|
|
|
|
|
* @return bool|int
|
|
|
|
|
*/
|
|
|
|
|
public function getThumbnailBucket( $desiredWidth, $page = 1 ) {
|
|
|
|
|
global $wgThumbnailBuckets, $wgThumbnailMinimumBucketDistance;
|
|
|
|
|
|
2014-11-10 17:21:54 +00:00
|
|
|
wfDebugLog( 'thumbnail', 'thumbnail buckets ' . json_encode( $wgThumbnailBuckets ) );
|
|
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
$imageWidth = $this->getWidth( $page );
|
|
|
|
|
|
|
|
|
|
if ( $imageWidth === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $desiredWidth > $imageWidth ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$wgThumbnailBuckets ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sortedBuckets = $wgThumbnailBuckets;
|
|
|
|
|
|
|
|
|
|
sort( $sortedBuckets );
|
|
|
|
|
|
|
|
|
|
foreach ( $sortedBuckets as $bucket ) {
|
|
|
|
|
if ( $bucket > $imageWidth ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $bucket - $wgThumbnailMinimumBucketDistance > $desiredWidth ) {
|
|
|
|
|
return $bucket;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Image is bigger than any available bucket
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Returns ID or name of user who uploaded the file
|
|
|
|
|
* STUB
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $type 'text' or 'id'
|
2011-05-29 14:01:47 +00:00
|
|
|
* @return string|int
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getUser( $type = 'text' ) {
|
2011-05-29 13:33:29 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2008-01-20 06:48:57 +00:00
|
|
|
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get the duration of a media file in seconds
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return int
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
*/
|
|
|
|
|
public function getLength() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLength( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-31 21:49:25 +00:00
|
|
|
/**
|
2011-05-29 14:01:47 +00:00
|
|
|
* Return true if the file is vectorized
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2011-05-29 14:01:47 +00:00
|
|
|
* @return bool
|
2011-05-25 15:39:47 +00:00
|
|
|
*/
|
2011-02-02 10:42:17 +00:00
|
|
|
public function isVectorized() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->isVectorized( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-31 21:49:25 +00:00
|
|
|
|
2013-11-16 01:47:51 +00:00
|
|
|
/**
|
|
|
|
|
* Gives a (possibly empty) list of languages to render
|
|
|
|
|
* the file in.
|
|
|
|
|
*
|
|
|
|
|
* If the file doesn't have translations, or if the file
|
|
|
|
|
* format does not support that sort of thing, returns
|
|
|
|
|
* an empty array.
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return array
|
2013-11-16 01:47:51 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getAvailableLanguages() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getAvailableLanguages( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* In files that support multiple language, what is the default language
|
|
|
|
|
* to use if none specified.
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return string Lang code, or null if filetype doesn't support multiple languages.
|
2013-11-16 01:47:51 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getDefaultRenderLanguage() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getDefaultRenderLanguage( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-19 01:19:53 +00:00
|
|
|
/**
|
|
|
|
|
* Will the thumbnail be animated if one would expect it to be.
|
|
|
|
|
*
|
|
|
|
|
* Currently used to add a warning to the image description page
|
|
|
|
|
*
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return bool False if the main image is both animated
|
2012-08-19 01:19:53 +00:00
|
|
|
* and the thumbnail is not. In all other cases must return
|
|
|
|
|
* true. If image is not renderable whatsoever, should
|
|
|
|
|
* return true.
|
|
|
|
|
*/
|
|
|
|
|
public function canAnimateThumbIfAppropriate() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( !$handler ) {
|
|
|
|
|
// We cannot handle image whatsoever, thus
|
|
|
|
|
// one would not expect it to be animated
|
|
|
|
|
// so true.
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if ( $this->allowInlineDisplay()
|
|
|
|
|
&& $handler->isAnimatedImage( $this )
|
|
|
|
|
&& !$handler->canAnimateThumbnail( $this )
|
|
|
|
|
) {
|
|
|
|
|
// Image is animated, but thumbnail isn't.
|
|
|
|
|
// This is unexpected to the user.
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// Image is not animated, so one would
|
|
|
|
|
// not expect thumb to be
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get handler-specific metadata
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
2013-12-05 19:09:38 +00:00
|
|
|
* @return bool|array
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getMetadata() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-07-31 20:10:36 +00:00
|
|
|
|
2013-08-28 23:09:07 +00:00
|
|
|
/**
|
|
|
|
|
* Like getMetadata but returns a handler independent array of common values.
|
|
|
|
|
* @see MediaHandler::getCommonMetaArray()
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return array|bool Array or false if not supported
|
2013-08-28 23:09:07 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public function getCommonMetaArray() {
|
|
|
|
|
$handler = $this->getHandler();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-01-07 20:04:14 +00:00
|
|
|
if ( !$handler ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-05 11:02:29 +00:00
|
|
|
|
2013-08-28 23:09:07 +00:00
|
|
|
return $handler->getCommonMetaArray( $this );
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-16 01:23:15 +00:00
|
|
|
/**
|
2013-03-07 16:27:38 +00:00
|
|
|
* get versioned metadata
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array|string $metadata Array or string of (serialized) metadata
|
|
|
|
|
* @param int $version Version number.
|
|
|
|
|
* @return array Array containing metadata, or what was passed to it on fail
|
|
|
|
|
* (unserializing if not array)
|
2013-03-07 16:27:38 +00:00
|
|
|
*/
|
2013-03-24 10:01:51 +00:00
|
|
|
public function convertMetadataVersion( $metadata, $version ) {
|
2011-04-16 01:23:15 +00:00
|
|
|
$handler = $this->getHandler();
|
2011-04-18 13:08:20 +00:00
|
|
|
if ( !is_array( $metadata ) ) {
|
2011-12-20 03:52:06 +00:00
|
|
|
// Just to make the return type consistent
|
2011-05-25 15:39:47 +00:00
|
|
|
$metadata = unserialize( $metadata );
|
2011-04-16 01:23:15 +00:00
|
|
|
}
|
|
|
|
|
if ( $handler ) {
|
2011-04-18 13:08:20 +00:00
|
|
|
return $handler->convertMetadataVersion( $metadata, $version );
|
2011-04-16 01:23:15 +00:00
|
|
|
} else {
|
|
|
|
|
return $metadata;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-31 20:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* Return the bit depth of the file
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
* STUB
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return int
|
2008-07-31 20:10:36 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getBitDepth() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the size of the image file, in bytes
|
|
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
public function getSize() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-07-24 14:04:48 +00:00
|
|
|
* Returns the MIME type of the file.
|
2007-05-30 21:02:32 +00:00
|
|
|
* Overridden by LocalFile, UnregisteredLocalFile
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 14:01:47 +00:00
|
|
|
function getMimeType() {
|
|
|
|
|
return 'unknown/unknown';
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the type of the media in the file.
|
|
|
|
|
* Use the value returned by this function with the MEDIATYPE_xxx constants.
|
|
|
|
|
* Overridden by LocalFile,
|
|
|
|
|
* STUB
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
function getMediaType() {
|
|
|
|
|
return MEDIATYPE_UNKNOWN;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Checks if the output of transform() for this file is likely
|
|
|
|
|
* to be valid. If this is false, various user elements will
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
* display a placeholder instead.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* Currently, this checks if the file is an image format
|
|
|
|
|
* that can be converted to a format
|
|
|
|
|
* supported by all browsers (namely GIF, PNG and JPEG),
|
|
|
|
|
* or if it is an SVG image and SVG conversion is enabled.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function canRender() {
|
|
|
|
|
if ( !isset( $this->canRender ) ) {
|
2014-08-03 04:10:01 +00:00
|
|
|
$this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->canRender;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accessor for __get()
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
protected function getCanRender() {
|
|
|
|
|
return $this->canRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if the file is of a type that can't be directly
|
|
|
|
|
* rendered by typical browsers and needs to be re-rasterized.
|
|
|
|
|
*
|
|
|
|
|
* This returns true for everything but the bitmap types
|
|
|
|
|
* supported by all browsers, i.e. JPEG; GIF and PNG. It will
|
|
|
|
|
* also return true for any non-image formats.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function mustRender() {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
return $this->getHandler() && $this->handler->mustRender( $this );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
* Alias for canRender()
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function allowInlineDisplay() {
|
|
|
|
|
return $this->canRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines if this media file is in a format that is unlikely to
|
|
|
|
|
* contain viruses or malicious content. It uses the global
|
|
|
|
|
* $wgTrustedMediaFormats list to determine if the file is safe.
|
|
|
|
|
*
|
|
|
|
|
* This is used to show a warning on the description page of non-safe files.
|
|
|
|
|
* It may also be used to disallow direct [[media:...]] links to such files.
|
|
|
|
|
*
|
|
|
|
|
* Note that this function will always return true if allowInlineDisplay()
|
|
|
|
|
* or isTrustedFile() is true for this file.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isSafeFile() {
|
|
|
|
|
if ( !isset( $this->isSafeFile ) ) {
|
2013-11-23 21:00:16 +00:00
|
|
|
$this->isSafeFile = $this->getIsSafeFileUncached();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->isSafeFile;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* Accessor for __get()
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2011-05-29 14:01:47 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
protected function getIsSafeFile() {
|
|
|
|
|
return $this->isSafeFile();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* Uncached accessor
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2013-11-23 21:00:16 +00:00
|
|
|
protected function getIsSafeFileUncached() {
|
2011-12-20 03:52:06 +00:00
|
|
|
global $wgTrustedMediaFormats;
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $this->allowInlineDisplay() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-02-03 19:42:08 +00:00
|
|
|
if ( $this->isTrustedFile() ) {
|
2011-05-29 13:33:29 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
$type = $this->getMediaType();
|
|
|
|
|
$mime = $this->getMimeType();
|
2013-02-03 19:42:08 +00:00
|
|
|
#wfDebug( "LocalFile::isSafeFile: type= $type, mime= $mime\n" );
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( !$type || $type === MEDIATYPE_UNKNOWN ) {
|
|
|
|
|
return false; #unknown type, not trusted
|
|
|
|
|
}
|
|
|
|
|
if ( in_array( $type, $wgTrustedMediaFormats ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
if ( $mime === "unknown/unknown" ) {
|
|
|
|
|
return false; #unknown type, not trusted
|
|
|
|
|
}
|
2013-03-24 10:01:51 +00:00
|
|
|
if ( in_array( $mime, $wgTrustedMediaFormats ) ) {
|
2011-05-29 13:33:29 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if the file is flagged as trusted. Files flagged that way
|
|
|
|
|
* can be linked to directly, even if that is not allowed for this type of
|
|
|
|
|
* file normally.
|
|
|
|
|
*
|
|
|
|
|
* This is a dummy function right now and always returns false. It could be
|
|
|
|
|
* implemented to extract a flag from the database. The trusted flag could be
|
|
|
|
|
* set on upload, if the user has sufficient privileges, to bypass script-
|
|
|
|
|
* and html-filters. It may even be coupled with cryptographics signatures
|
|
|
|
|
* or such.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function isTrustedFile() {
|
2011-12-20 03:52:06 +00:00
|
|
|
#this could be implemented to check a flag in the database,
|
2007-05-30 21:02:32 +00:00
|
|
|
#look for signatures, etc
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if file exists in the repository.
|
|
|
|
|
*
|
|
|
|
|
* Overridden by LocalFile to avoid unnecessary stat calls.
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool Whether file exists in the repository.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function exists() {
|
2011-12-20 03:52:06 +00:00
|
|
|
return $this->getPath() && $this->repo->fileExists( $this->path );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-09 03:10:28 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if file exists in the repository and can be included in a page.
|
|
|
|
|
* It would be unsafe to include private images, making public thumbnails inadvertently
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool Whether file exists in the repository and is includable.
|
2008-03-09 03:10:28 +00:00
|
|
|
*/
|
2011-04-02 14:48:22 +00:00
|
|
|
public function isVisible() {
|
2008-03-09 03:10:28 +00:00
|
|
|
return $this->exists();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function getTransformScript() {
|
|
|
|
|
if ( !isset( $this->transformScript ) ) {
|
|
|
|
|
$this->transformScript = false;
|
|
|
|
|
if ( $this->repo ) {
|
|
|
|
|
$script = $this->repo->getThumbScriptUrl();
|
|
|
|
|
if ( $script ) {
|
2013-04-11 18:22:11 +00:00
|
|
|
$this->transformScript = wfAppendQuery( $script, array( 'f' => $this->getName() ) );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->transformScript;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a ThumbnailImage which is the same size as the source
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array $handlerParams
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2010-05-19 00:40:48 +00:00
|
|
|
function getUnscaledThumb( $handlerParams = array() ) {
|
|
|
|
|
$hp =& $handlerParams;
|
|
|
|
|
$page = isset( $hp['page'] ) ? $hp['page'] : false;
|
2007-05-30 21:02:32 +00:00
|
|
|
$width = $this->getWidth( $page );
|
|
|
|
|
if ( !$width ) {
|
|
|
|
|
return $this->iconThumb();
|
|
|
|
|
}
|
2010-05-19 00:40:48 +00:00
|
|
|
$hp['width'] = $width;
|
2014-03-05 17:26:28 +00:00
|
|
|
// be sure to ignore any height specification as well (bug 62258)
|
|
|
|
|
unset( $hp['height'] );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2010-05-19 00:40:48 +00:00
|
|
|
return $this->transform( $hp );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-09-04 16:57:44 +00:00
|
|
|
* Return the file name of a thumbnail with the specified parameters.
|
|
|
|
|
* Use File::THUMB_FULL_NAME to always get a name like "<params>-<source>".
|
|
|
|
|
* Otherwise, the format may be "<params>-<source>" or "<params>-thumbnail.<ext>".
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param array $params Handler-specific parameters
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $flags Bitfield that supports THUMB_* constants
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2012-09-04 16:57:44 +00:00
|
|
|
public function thumbName( $params, $flags = 0 ) {
|
|
|
|
|
$name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) )
|
|
|
|
|
? $this->repo->nameForThumb( $this->getName() )
|
|
|
|
|
: $this->getName();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-08-31 21:21:39 +00:00
|
|
|
return $this->generateThumbName( $name, $params );
|
2011-02-11 19:10:31 +00:00
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2011-02-11 19:10:31 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
2011-02-11 19:10:31 +00:00
|
|
|
*/
|
2012-09-04 16:57:44 +00:00
|
|
|
public function generateThumbName( $name, $params ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
$extension = $this->getExtension();
|
2014-06-03 16:09:30 +00:00
|
|
|
list( $thumbExt, ) = $this->getHandler()->getThumbType(
|
2011-12-20 03:52:06 +00:00
|
|
|
$extension, $this->getMimeType(), $params );
|
2014-06-03 16:09:30 +00:00
|
|
|
$thumbName = $this->getHandler()->makeParamString( $params ) . '-' . $name;
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $thumbExt != $extension ) {
|
|
|
|
|
$thumbName .= ".$thumbExt";
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $thumbName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a thumbnail of the image having the specified width/height.
|
|
|
|
|
* The thumbnail will not be created if the width is larger than the
|
|
|
|
|
* image's width. Let the browser do the scaling in this case.
|
|
|
|
|
* The thumbnail is stored on disk and is only computed if the thumbnail
|
|
|
|
|
* file does not exist OR if it is older than the image.
|
|
|
|
|
* Returns the URL.
|
|
|
|
|
*
|
|
|
|
|
* Keeps aspect ratio of original image. If both width and height are
|
|
|
|
|
* specified, the generated image will be no bigger than width x height,
|
|
|
|
|
* and will also have correct aspect ratio.
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $width Maximum width of the generated thumbnail
|
|
|
|
|
* @param int $height Maximum height of the image (optional)
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function createThumb( $width, $height = -1 ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$params = array( 'width' => $width );
|
|
|
|
|
if ( $height != -1 ) {
|
|
|
|
|
$params['height'] = $height;
|
|
|
|
|
}
|
|
|
|
|
$thumb = $this->transform( $params );
|
2013-12-13 08:54:20 +00:00
|
|
|
if ( !$thumb || $thumb->isError() ) {
|
2011-12-20 03:52:06 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $thumb->getUrl();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-05 01:58:05 +00:00
|
|
|
/**
|
|
|
|
|
* Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors)
|
2012-04-06 17:38:38 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $thumbPath Thumbnail storage path
|
|
|
|
|
* @param string $thumbUrl Thumbnail URL
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param array $params
|
|
|
|
|
* @param int $flags
|
2012-01-05 01:58:05 +00:00
|
|
|
* @return MediaTransformOutput
|
|
|
|
|
*/
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) {
|
2012-01-05 01:58:05 +00:00
|
|
|
global $wgIgnoreImageErrors;
|
|
|
|
|
|
2013-09-05 20:46:38 +00:00
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler && $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
|
|
|
|
|
return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
2012-01-05 01:58:05 +00:00
|
|
|
} else {
|
|
|
|
|
return new MediaTransformError( 'thumbnail_error',
|
2012-07-24 01:04:15 +00:00
|
|
|
$params['width'], 0, wfMessage( 'thumbnail-dest-create' )->text() );
|
2012-01-05 01:58:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Transform a media file
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param array $params An associative array of handler-specific parameters.
|
2013-12-04 16:18:05 +00:00
|
|
|
* Typical keys are width, height and page.
|
|
|
|
|
* @param int $flags A bitfield, may contain self::RENDER_NOW to force rendering
|
2012-02-10 15:37:33 +00:00
|
|
|
* @return MediaTransformOutput|bool False on failure
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function transform( $params, $flags = 0 ) {
|
2014-06-03 16:09:30 +00:00
|
|
|
global $wgThumbnailEpoch;
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
do {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( !$this->canRender() ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumb = $this->iconThumb();
|
2012-02-03 06:16:37 +00:00
|
|
|
break; // not a bitmap or renderable image, don't try
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-17 20:25:55 +00:00
|
|
|
// Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
|
2012-02-03 06:16:37 +00:00
|
|
|
$descriptionUrl = $this->getDescriptionUrl();
|
2009-12-17 20:25:55 +00:00
|
|
|
if ( $descriptionUrl ) {
|
2011-10-05 10:16:49 +00:00
|
|
|
$params['descriptionUrl'] = wfExpandUrl( $descriptionUrl, PROTO_CANONICAL );
|
2009-12-17 20:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-25 19:47:06 +00:00
|
|
|
$handler = $this->getHandler();
|
2007-05-30 21:02:32 +00:00
|
|
|
$script = $this->getTransformScript();
|
2012-02-03 06:16:37 +00:00
|
|
|
if ( $script && !( $flags & self::RENDER_NOW ) ) {
|
2008-01-22 03:31:10 +00:00
|
|
|
// Use a script to transform on client request, if possible
|
2013-01-25 19:47:06 +00:00
|
|
|
$thumb = $handler->getScriptedTransform( $this, $script, $params );
|
2012-02-03 06:16:37 +00:00
|
|
|
if ( $thumb ) {
|
2008-01-22 03:31:10 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$normalisedParams = $params;
|
2013-01-25 19:47:06 +00:00
|
|
|
$handler->normaliseParams( $this, $normalisedParams );
|
2012-02-03 06:16:37 +00:00
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
$thumbName = $this->thumbName( $normalisedParams );
|
2007-05-30 21:02:32 +00:00
|
|
|
$thumbUrl = $this->getThumbUrl( $thumbName );
|
2012-02-03 06:16:37 +00:00
|
|
|
$thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
|
|
|
|
|
|
|
|
|
|
if ( $this->repo ) {
|
|
|
|
|
// Defer rendering if a 404 handler is set up...
|
|
|
|
|
if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
|
2014-03-29 10:52:07 +00:00
|
|
|
wfDebug( __METHOD__ . " transformation deferred.\n" );
|
2012-02-03 06:16:37 +00:00
|
|
|
// XXX: Pass in the storage path even though we are not rendering anything
|
|
|
|
|
// and the path is supposed to be an FS path. This is due to getScalerType()
|
|
|
|
|
// getting called on the path and clobbering $thumb->getUrl() if it's false.
|
2013-01-25 19:47:06 +00:00
|
|
|
$thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
2012-02-03 06:16:37 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Check if an up-to-date thumbnail already exists...
|
2013-02-03 19:42:08 +00:00
|
|
|
wfDebug( __METHOD__ . ": Doing stat for $thumbPath\n" );
|
2013-01-21 21:36:01 +00:00
|
|
|
if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) {
|
2012-02-03 06:16:37 +00:00
|
|
|
$timestamp = $this->repo->getFileTimestamp( $thumbPath );
|
|
|
|
|
if ( $timestamp !== false && $timestamp >= $wgThumbnailEpoch ) {
|
|
|
|
|
// XXX: Pass in the storage path even though we are not rendering anything
|
|
|
|
|
// and the path is supposed to be an FS path. This is due to getScalerType()
|
|
|
|
|
// getting called on the path and clobbering $thumb->getUrl() if it's false.
|
2013-03-27 19:48:08 +00:00
|
|
|
$thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
|
2012-02-03 06:16:37 +00:00
|
|
|
$thumb->setStoragePath( $thumbPath );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $flags & self::RENDER_FORCE ) {
|
|
|
|
|
wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
// If the backend is ready-only, don't keep generating thumbnails
|
|
|
|
|
// only to return transformation errors, just return the error now.
|
|
|
|
|
if ( $this->repo->getReadOnlyReason() !== false ) {
|
|
|
|
|
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-04-21 18:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
$tmpFile = $this->makeTransformTmpFile( $thumbPath );
|
|
|
|
|
|
2012-02-03 06:16:37 +00:00
|
|
|
if ( !$tmpFile ) {
|
|
|
|
|
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
|
2014-06-03 16:09:30 +00:00
|
|
|
} else {
|
|
|
|
|
$thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
|
2012-02-03 06:16:37 +00:00
|
|
|
}
|
2014-06-03 16:09:30 +00:00
|
|
|
} while ( false );
|
|
|
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
return is_object( $thumb ) ? $thumb : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a thumbnail according to the given parameters and saves it to storage
|
|
|
|
|
* @param TempFSFile $tmpFile Temporary file where the rendered thumbnail will be saved
|
|
|
|
|
* @param array $transformParams
|
|
|
|
|
* @param int $flags
|
|
|
|
|
* @return bool|MediaTransformOutput
|
|
|
|
|
*/
|
|
|
|
|
public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
|
|
|
|
|
global $wgUseSquid, $wgIgnoreImageErrors;
|
|
|
|
|
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
|
|
|
|
|
$normalisedParams = $transformParams;
|
|
|
|
|
$handler->normaliseParams( $this, $normalisedParams );
|
|
|
|
|
|
|
|
|
|
$thumbName = $this->thumbName( $normalisedParams );
|
|
|
|
|
$thumbUrl = $this->getThumbUrl( $thumbName );
|
|
|
|
|
$thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
|
|
|
|
|
|
|
|
|
|
$tmpThumbPath = $tmpFile->getPath();
|
|
|
|
|
|
|
|
|
|
if ( $handler->supportsBucketing() ) {
|
|
|
|
|
$this->generateBucketsIfNeeded( $normalisedParams, $flags );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Actually render the thumbnail...
|
|
|
|
|
wfProfileIn( __METHOD__ . '-doTransform' );
|
|
|
|
|
$thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
|
|
|
|
|
wfProfileOut( __METHOD__ . '-doTransform' );
|
|
|
|
|
$tmpFile->bind( $thumb ); // keep alive with $thumb
|
|
|
|
|
|
|
|
|
|
if ( !$thumb ) { // bad params?
|
|
|
|
|
$thumb = false;
|
|
|
|
|
} elseif ( $thumb->isError() ) { // transform error
|
|
|
|
|
$this->lastError = $thumb->toText();
|
|
|
|
|
// Ignore errors if requested
|
|
|
|
|
if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
|
|
|
|
|
$thumb = $handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
|
|
|
|
|
// Copy the thumbnail from the file system into storage...
|
|
|
|
|
$disposition = $this->getThumbDisposition( $thumbName );
|
|
|
|
|
$status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
|
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
|
$thumb->setStoragePath( $thumbPath );
|
|
|
|
|
} else {
|
|
|
|
|
$thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags );
|
|
|
|
|
}
|
|
|
|
|
// Give extensions a chance to do something with this thumbnail...
|
|
|
|
|
wfRunHooks( 'FileTransformed', array( $this, $thumb, $tmpThumbPath, $thumbPath ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 ) {
|
|
|
|
|
if ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL() ) {
|
|
|
|
|
SquidUpdate::purge( array( $thumbUrl ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $thumb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates chained bucketed thumbnails if needed
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @param int $flags
|
|
|
|
|
* @return bool Whether at least one bucket was generated
|
|
|
|
|
*/
|
|
|
|
|
protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
|
|
|
|
|
if ( !$this->repo
|
|
|
|
|
|| !isset( $params['physicalWidth'] )
|
|
|
|
|
|| !isset( $params['physicalHeight'] )
|
|
|
|
|
|| !( $bucket = $this->getThumbnailBucket( $params['physicalWidth'] ) )
|
|
|
|
|
|| $bucket == $params['physicalWidth'] ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bucketPath = $this->getBucketThumbPath( $bucket );
|
|
|
|
|
|
|
|
|
|
if ( $this->repo->fileExists( $bucketPath ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params['physicalWidth'] = $bucket;
|
|
|
|
|
$params['width'] = $bucket;
|
|
|
|
|
|
|
|
|
|
$params = $this->getHandler()->sanitizeParamsForBucketing( $params );
|
|
|
|
|
|
|
|
|
|
$bucketName = $this->getBucketThumbName( $bucket );
|
|
|
|
|
|
|
|
|
|
$tmpFile = $this->makeTransformTmpFile( $bucketPath );
|
|
|
|
|
|
|
|
|
|
if ( !$tmpFile ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
|
|
|
|
|
|
|
|
|
|
if ( !$thumb || $thumb->isError() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:47:42 +00:00
|
|
|
$this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath();
|
2014-06-03 16:09:30 +00:00
|
|
|
// For the caching to work, we need to make the tmp file survive as long as
|
|
|
|
|
// this object exists
|
|
|
|
|
$tmpFile->bind( $this );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the most appropriate source image for the thumbnail, given a target thumbnail size
|
|
|
|
|
* @param array $params
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return array Source path and width/height of the source
|
2014-06-03 16:09:30 +00:00
|
|
|
*/
|
|
|
|
|
public function getThumbnailSource( $params ) {
|
|
|
|
|
if ( $this->repo
|
|
|
|
|
&& $this->getHandler()->supportsBucketing()
|
|
|
|
|
&& isset( $params['physicalWidth'] )
|
|
|
|
|
&& $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
|
|
|
|
|
) {
|
|
|
|
|
if ( $this->getWidth() != 0 ) {
|
|
|
|
|
$bucketHeight = round( $this->getHeight() * ( $bucket / $this->getWidth() ) );
|
|
|
|
|
} else {
|
|
|
|
|
$bucketHeight = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to avoid reading from storage if the file was generated by this script
|
2014-07-21 12:47:42 +00:00
|
|
|
if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) {
|
|
|
|
|
$tmpPath = $this->tmpBucketedThumbCache[$bucket];
|
2014-06-03 16:09:30 +00:00
|
|
|
|
|
|
|
|
if ( file_exists( $tmpPath ) ) {
|
|
|
|
|
return array(
|
|
|
|
|
'path' => $tmpPath,
|
|
|
|
|
'width' => $bucket,
|
|
|
|
|
'height' => $bucketHeight
|
|
|
|
|
);
|
2012-02-03 06:16:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
$bucketPath = $this->getBucketThumbPath( $bucket );
|
|
|
|
|
|
|
|
|
|
if ( $this->repo->fileExists( $bucketPath ) ) {
|
|
|
|
|
$fsFile = $this->repo->getLocalReference( $bucketPath );
|
|
|
|
|
|
|
|
|
|
if ( $fsFile ) {
|
|
|
|
|
return array(
|
|
|
|
|
'path' => $fsFile->getPath(),
|
|
|
|
|
'width' => $bucket,
|
|
|
|
|
'height' => $bucketHeight
|
|
|
|
|
);
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2014-06-03 16:09:30 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
2014-07-27 23:23:55 +00:00
|
|
|
// Thumbnailing a very large file could result in network saturation if
|
|
|
|
|
// everyone does it at once.
|
|
|
|
|
if ( $this->getSize() >= 1e7 ) { // 10MB
|
|
|
|
|
$that = $this;
|
|
|
|
|
$work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
|
|
|
|
|
array(
|
2014-09-29 18:46:19 +00:00
|
|
|
'doWork' => function () use ( $that ) {
|
2014-07-27 23:23:55 +00:00
|
|
|
return $that->getLocalRefPath();
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$srcPath = $work->execute();
|
|
|
|
|
} else {
|
|
|
|
|
$srcPath = $this->getLocalRefPath();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
// Original file
|
|
|
|
|
return array(
|
2014-07-27 23:23:55 +00:00
|
|
|
'path' => $srcPath,
|
2014-06-03 16:09:30 +00:00
|
|
|
'width' => $this->getWidth(),
|
|
|
|
|
'height' => $this->getHeight()
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the repo path of the thumb for a given bucket
|
|
|
|
|
* @param int $bucket
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getBucketThumbPath( $bucket ) {
|
|
|
|
|
$thumbName = $this->getBucketThumbName( $bucket );
|
|
|
|
|
return $this->getThumbPath( $thumbName );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the thumb for a given bucket
|
|
|
|
|
* @param int $bucket
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected function getBucketThumbName( $bucket ) {
|
|
|
|
|
return $this->thumbName( array( 'physicalWidth' => $bucket ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a temp FS file with the same extension and the thumbnail
|
|
|
|
|
* @param string $thumbPath Thumbnail path
|
2014-08-17 19:25:21 +00:00
|
|
|
* @return TempFSFile
|
2014-06-03 16:09:30 +00:00
|
|
|
*/
|
|
|
|
|
protected function makeTransformTmpFile( $thumbPath ) {
|
|
|
|
|
$thumbExt = FileBackend::extensionFromPath( $thumbPath );
|
|
|
|
|
return TempFSFile::factory( 'transform_', $thumbExt );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-01 04:20:56 +00:00
|
|
|
/**
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $thumbName Thumbnail name
|
2014-03-24 23:31:21 +00:00
|
|
|
* @param string $dispositionType Type of disposition (either "attachment" or "inline")
|
2012-09-01 04:20:56 +00:00
|
|
|
* @return string Content-Disposition header value
|
|
|
|
|
*/
|
2014-03-24 23:31:21 +00:00
|
|
|
function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) {
|
2012-09-01 04:20:56 +00:00
|
|
|
$fileName = $this->name; // file name to suggest
|
|
|
|
|
$thumbExt = FileBackend::extensionFromPath( $thumbName );
|
|
|
|
|
if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) {
|
|
|
|
|
$fileName .= ".$thumbExt";
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-03-24 23:31:21 +00:00
|
|
|
return FileBackend::makeContentDisposition( $dispositionType, $fileName );
|
2012-09-01 04:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-14 07:45:50 +00:00
|
|
|
/**
|
2007-05-30 21:02:32 +00:00
|
|
|
* Hook into transform() to allow migration of thumbnail files
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param string $thumbName
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2013-11-23 20:00:11 +00:00
|
|
|
function migrateThumbFile( $thumbName ) {
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a MediaHandler instance for this file
|
2011-12-20 03:52:06 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return MediaHandler|bool Registered MediaHandler for file's MIME type
|
|
|
|
|
* or false if none found
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function getHandler() {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !isset( $this->handler ) ) {
|
|
|
|
|
$this->handler = MediaHandler::getHandler( $this->getMimeType() );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a ThumbnailImage representing a file type icon
|
2011-12-20 03:52:06 +00:00
|
|
|
*
|
2007-05-30 21:02:32 +00:00
|
|
|
* @return ThumbnailImage
|
|
|
|
|
*/
|
|
|
|
|
function iconThumb() {
|
2014-09-17 23:12:53 +00:00
|
|
|
global $wgResourceBasePath, $IP;
|
|
|
|
|
$assetsPath = "$wgResourceBasePath/resources/assets/file-type-icons/";
|
2014-09-17 19:39:03 +00:00
|
|
|
$assetsDirectory = "$IP/resources/assets/file-type-icons/";
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
$try = array( 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' );
|
2011-12-20 03:52:06 +00:00
|
|
|
foreach ( $try as $icon ) {
|
2014-09-05 17:13:52 +00:00
|
|
|
if ( file_exists( $assetsDirectory . $icon ) ) { // always FS
|
2012-09-01 16:12:48 +00:00
|
|
|
$params = array( 'width' => 120, 'height' => 120 );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-09-05 17:13:52 +00:00
|
|
|
return new ThumbnailImage( $this, $assetsPath . $icon, false, $params );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get last thumbnailing error.
|
|
|
|
|
* Largely obsolete.
|
2014-08-23 20:34:25 +00:00
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getLastError() {
|
|
|
|
|
return $this->lastError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all thumbnail names previously generated for this file
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return array
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
function getThumbnails() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge shared caches such as thumbnails and DB data caching
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options Options, which include:
|
2013-12-04 16:18:05 +00:00
|
|
|
* 'forThumbRefresh' : The purging is only to refresh thumbnails
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2013-11-23 20:00:11 +00:00
|
|
|
function purgeCache( $options = array() ) {
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Purge the file description page, but don't go after
|
|
|
|
|
* pages using the file. Use when modifying file history
|
|
|
|
|
* but not the current data.
|
|
|
|
|
*/
|
|
|
|
|
function purgeDescription() {
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
if ( $title ) {
|
|
|
|
|
$title->invalidateCache();
|
|
|
|
|
$title->purgeSquid();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Purge metadata and all affected pages when the file is created,
|
2007-07-22 14:45:12 +00:00
|
|
|
* deleted, or majorly updated.
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function purgeEverything() {
|
2007-05-30 21:02:32 +00:00
|
|
|
// Delete thumbnails and refresh file metadata cache
|
|
|
|
|
$this->purgeCache();
|
|
|
|
|
$this->purgeDescription();
|
|
|
|
|
|
|
|
|
|
// Purge cache of all pages using this file
|
|
|
|
|
$title = $this->getTitle();
|
|
|
|
|
if ( $title ) {
|
|
|
|
|
$update = new HTMLCacheUpdate( $title, 'imagelinks' );
|
|
|
|
|
$update->doUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
|
|
|
|
* Return a fragment of the history of file.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $limit Limit of rows to return
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $start Only revisions older than $start will be returned
|
|
|
|
|
* @param string $end Only revisions newer than $end will be returned
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $inc Include the endpoints of the time range
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return array
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
2013-04-13 11:36:24 +00:00
|
|
|
function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
|
2008-05-11 14:54:45 +00:00
|
|
|
return array();
|
2008-01-20 06:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Return the history of this file, line by line. Starts with current version,
|
|
|
|
|
* then old versions. Should return an object similar to an image/oldimage
|
2007-05-30 21:02:32 +00:00
|
|
|
* database row.
|
|
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden in LocalFile
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-06-24 06:32:07 +00:00
|
|
|
public function nextHistoryLine() {
|
2007-05-30 21:02:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-07-07 03:04:20 +00:00
|
|
|
* Reset the history pointer to the first element of the history.
|
|
|
|
|
* Always call this function after using nextHistoryLine() to free db resources
|
2007-05-30 21:02:32 +00:00
|
|
|
* STUB
|
|
|
|
|
* Overridden in LocalFile.
|
|
|
|
|
*/
|
2013-11-23 20:00:11 +00:00
|
|
|
public function resetHistory() {
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the filename hash component of the directory including trailing slash,
|
|
|
|
|
* e.g. f/fa/
|
|
|
|
|
* If the repository is not hashed, returns an empty string.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getHashPath() {
|
|
|
|
|
if ( !isset( $this->hashPath ) ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->hashPath = $this->repo->getHashPath( $this->getName() );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->hashPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-21 20:39:50 +00:00
|
|
|
* Get the path of the file relative to the public zone root.
|
|
|
|
|
* This function is overriden in OldLocalFile to be like getArchiveRel().
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getRel() {
|
|
|
|
|
return $this->getHashPath() . $this->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-21 20:39:50 +00:00
|
|
|
* Get the path of an archived file relative to the public zone root
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of an archived thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2011-05-29 13:33:29 +00:00
|
|
|
*/
|
2011-09-07 02:31:55 +00:00
|
|
|
function getArchiveRel( $suffix = false ) {
|
|
|
|
|
$path = 'archive/' . $this->getHashPath();
|
|
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
|
|
|
|
$path .= $suffix;
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-09-07 02:31:55 +00:00
|
|
|
return $path;
|
2011-09-06 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-21 20:39:50 +00:00
|
|
|
* Get the path, relative to the thumbnail zone root, of the
|
|
|
|
|
* thumbnail directory or a particular file if $suffix is specified
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-12-21 20:39:50 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getThumbRel( $suffix = false ) {
|
|
|
|
|
$path = $this->getRel();
|
|
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . $suffix;
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-12-21 20:39:50 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get urlencoded path of the file relative to the public zone root.
|
|
|
|
|
* This function is overriden in OldLocalFile to be like getArchiveUrl().
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getUrlRel() {
|
|
|
|
|
return $this->getHashPath() . rawurlencode( $this->getName() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory
|
2011-09-06 21:01:42 +00:00
|
|
|
* or a specific thumb if the $suffix is given.
|
2011-09-07 12:00:58 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $archiveName The timestamped name of an archived image
|
|
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-09-07 12:00:58 +00:00
|
|
|
* @return string
|
2011-09-06 21:01:42 +00:00
|
|
|
*/
|
|
|
|
|
function getArchiveThumbRel( $archiveName, $suffix = false ) {
|
|
|
|
|
$path = 'archive/' . $this->getHashPath() . $archiveName . "/";
|
2007-06-11 14:46:18 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
|
|
|
|
$path .= $suffix;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2011-09-06 21:01:42 +00:00
|
|
|
* Get the path of the archived file.
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of an archived file.
|
2011-09-06 21:01:42 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-07 02:31:55 +00:00
|
|
|
function getArchivePath( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-09-07 02:31:55 +00:00
|
|
|
return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
|
2011-09-06 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-12-21 20:39:50 +00:00
|
|
|
* Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $archiveName The timestamped name of an archived image
|
|
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-06 21:01:42 +00:00
|
|
|
function getArchiveThumbPath( $archiveName, $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-11-07 21:54:19 +00:00
|
|
|
return $this->repo->getZonePath( 'thumb' ) . '/' .
|
2014-02-05 11:02:29 +00:00
|
|
|
$this->getArchiveThumbRel( $archiveName, $suffix );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path of the thumbnail directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getThumbPath( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-12-21 20:39:50 +00:00
|
|
|
return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:30:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get the path of the transcoded directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a media file
|
2013-01-15 23:30:41 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function getTranscodedPath( $suffix = false ) {
|
|
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2013-01-15 23:30:41 +00:00
|
|
|
return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix );
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2011-09-07 02:31:55 +00:00
|
|
|
* Get the URL of the archive directory, or a particular file if $suffix is specified
|
2011-09-06 21:01:42 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of an archived file
|
2011-09-06 21:01:42 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-07 02:31:55 +00:00
|
|
|
function getArchiveUrl( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2012-10-13 00:24:31 +00:00
|
|
|
$ext = $this->getExtension();
|
|
|
|
|
$path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath();
|
2011-09-07 02:31:55 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
|
|
|
|
$path .= rawurlencode( $suffix );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-09-07 02:31:55 +00:00
|
|
|
return $path;
|
2011-09-06 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $archiveName The timestamped name of an archived image
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-06 21:01:42 +00:00
|
|
|
function getArchiveThumbUrl( $archiveName, $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2012-10-13 00:24:31 +00:00
|
|
|
$ext = $this->getExtension();
|
|
|
|
|
$path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' .
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->getHashPath() . rawurlencode( $archiveName ) . "/";
|
2007-06-11 14:46:18 +00:00
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2013-01-15 23:30:41 +00:00
|
|
|
* Get the URL of the zone directory, or a particular file if $suffix is specified
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $zone Name of requested zone
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a file in zone
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return string Path
|
2011-05-29 13:33:29 +00:00
|
|
|
*/
|
2013-01-15 23:30:41 +00:00
|
|
|
function getZoneUrl( $zone, $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2012-10-13 00:24:31 +00:00
|
|
|
$ext = $this->getExtension();
|
2013-01-15 23:30:41 +00:00
|
|
|
$path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel();
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $suffix !== false ) {
|
2007-06-16 02:55:25 +00:00
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:30:41 +00:00
|
|
|
/**
|
|
|
|
|
* Get the URL of the thumbnail directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return string Path
|
2013-01-15 23:30:41 +00:00
|
|
|
*/
|
|
|
|
|
function getThumbUrl( $suffix = false ) {
|
|
|
|
|
return $this->getZoneUrl( 'thumb', $suffix );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of the transcoded directory, or a particular file if $suffix is specified
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a media file
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return string Path
|
2013-01-15 23:30:41 +00:00
|
|
|
*/
|
|
|
|
|
function getTranscodedUrl( $suffix = false ) {
|
|
|
|
|
return $this->getZoneUrl( 'transcoded', $suffix );
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2011-12-20 03:52:06 +00:00
|
|
|
* Get the public zone virtual URL for a current version source file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
function getVirtualUrl( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2011-12-20 03:52:06 +00:00
|
|
|
$path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
|
|
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2011-12-20 03:52:06 +00:00
|
|
|
* Get the public zone virtual URL for an archived version source file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
function getArchiveVirtualUrl( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2011-12-20 03:52:06 +00:00
|
|
|
$path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
|
|
|
|
|
if ( $suffix === false ) {
|
|
|
|
|
$path = substr( $path, 0, -1 );
|
|
|
|
|
} else {
|
|
|
|
|
$path .= rawurlencode( $suffix );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2011-12-20 03:52:06 +00:00
|
|
|
* Get the virtual URL for a thumbnail file or directory
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|string $suffix If not false, the name of a thumbnail file
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
function getThumbVirtualUrl( $suffix = false ) {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2011-12-20 03:52:06 +00:00
|
|
|
$path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
|
2007-06-16 02:55:25 +00:00
|
|
|
if ( $suffix !== false ) {
|
|
|
|
|
$path .= '/' . rawurlencode( $suffix );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-06-16 02:55:25 +00:00
|
|
|
return $path;
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function isHashed() {
|
2011-11-07 21:54:19 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-04-05 04:10:50 +00:00
|
|
|
return (bool)$this->repo->getHashLevels();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-29 14:01:47 +00:00
|
|
|
/**
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
2007-05-30 21:02:32 +00:00
|
|
|
function readOnlyError() {
|
2013-02-03 19:42:08 +00:00
|
|
|
throw new MWException( get_class( $this ) . ': write operations are not supported' );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Record a file upload in the upload log and the image table
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $oldver
|
|
|
|
|
* @param string $desc
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $license
|
|
|
|
|
* @param string $copyStatus
|
|
|
|
|
* @param string $source
|
|
|
|
|
* @param bool $watch
|
|
|
|
|
* @param string|bool $timestamp
|
|
|
|
|
* @param null|User $user User object or null to use $wgUser
|
2013-02-18 18:55:08 +00:00
|
|
|
* @return bool
|
|
|
|
|
* @throws MWException
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2013-11-23 20:54:48 +00:00
|
|
|
function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
|
|
|
|
|
$watch = false, $timestamp = false, User $user = null
|
|
|
|
|
) {
|
2008-04-14 07:45:50 +00:00
|
|
|
$this->readOnlyError();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* Move or copy a file to its public location. If a file exists at the
|
2010-04-16 15:20:12 +00:00
|
|
|
* destination, move it to an archive. Returns a FileRepoStatus object with
|
|
|
|
|
* the archive name in the "value" member on success.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* The archive name should be passed through to recordUpload for database
|
|
|
|
|
* registration.
|
|
|
|
|
*
|
2012-11-20 01:38:17 +00:00
|
|
|
* Options to $options include:
|
|
|
|
|
* - headers : name/value map of HTTP headers to use in response to GET/HEAD requests
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param string $srcPath Local filesystem path to the source image
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $flags A bitwise combination of:
|
|
|
|
|
* File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $options Optional additional parameters
|
2014-07-24 17:43:03 +00:00
|
|
|
* @return FileRepoStatus On success, the value member contains the
|
2013-12-04 16:18:05 +00:00
|
|
|
* archive name, or an empty string if it was a new file.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
|
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2012-11-20 01:38:17 +00:00
|
|
|
function publish( $srcPath, $flags = 0, array $options = array() ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-07-28 01:15:35 +00:00
|
|
|
function formatMetadata() {
|
|
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return false;
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-07-28 01:15:35 +00:00
|
|
|
return $this->getHandler()->formatMetadata( $this, $this->getMetadata() );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the file comes from the local file repository.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function isLocal() {
|
2011-12-21 21:29:16 +00:00
|
|
|
return $this->repo && $this->repo->isLocal();
|
2007-07-07 03:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the repository.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-04-14 07:45:50 +00:00
|
|
|
function getRepoName() {
|
|
|
|
|
return $this->repo ? $this->repo->getName() : 'unknown';
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2011-05-21 19:35:16 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2008-05-15 19:17:21 +00:00
|
|
|
* Returns the repository
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-05 09:13:28 +00:00
|
|
|
* @return FileRepo|LocalRepo|bool
|
2008-05-15 19:17:21 +00:00
|
|
|
*/
|
|
|
|
|
function getRepo() {
|
|
|
|
|
return $this->repo;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the image is an old version
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isOld() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this file a "deleted" file in a private archive?
|
|
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param int $field One of DELETED_* bitfield constants
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isDeleted( $field ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2009-09-12 22:02:51 +00:00
|
|
|
/**
|
|
|
|
|
* Return the deletion bitfield
|
|
|
|
|
* STUB
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return int
|
2011-05-25 15:39:47 +00:00
|
|
|
*/
|
2009-09-12 22:02:51 +00:00
|
|
|
function getVisibility() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Was this file ever deleted from the wiki?
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function wasDeleted() {
|
|
|
|
|
$title = $this->getTitle();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2009-02-24 16:17:23 +00:00
|
|
|
return $title && $title->isDeletedQuick();
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-03 13:09:34 +00:00
|
|
|
/**
|
|
|
|
|
* Move file to the new title
|
|
|
|
|
*
|
|
|
|
|
* Move current, old version and all thumbnails
|
|
|
|
|
* to the new filename. Old file is deleted.
|
|
|
|
|
*
|
|
|
|
|
* Cache purging is done; checks for validity
|
|
|
|
|
* and logging are caller's responsibility
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param Title $target New file name
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return FileRepoStatus
|
2008-05-03 13:09:34 +00:00
|
|
|
*/
|
2013-02-03 19:42:08 +00:00
|
|
|
function move( $target ) {
|
2008-05-03 13:09:34 +00:00
|
|
|
$this->readOnlyError();
|
2013-02-03 19:42:08 +00:00
|
|
|
}
|
2008-05-03 13:09:34 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Delete all versions of the file.
|
|
|
|
|
*
|
|
|
|
|
* Moves the files into an archive directory (or deletes them)
|
|
|
|
|
* and removes the database rows.
|
|
|
|
|
*
|
|
|
|
|
* Cache purging is done; logging is caller's responsibility.
|
|
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $reason
|
|
|
|
|
* @param bool $suppress Hide content from sysops?
|
2014-05-07 17:42:35 +00:00
|
|
|
* @param User|null $user
|
2014-04-19 15:19:17 +00:00
|
|
|
* @return bool Boolean on success, false on some kind of failure
|
2007-05-30 21:02:32 +00:00
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2014-05-07 17:42:35 +00:00
|
|
|
function delete( $reason, $suppress = false, $user = null ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Restore all or specified deleted revisions to the given file.
|
|
|
|
|
* Permissions and logging are left to the caller.
|
|
|
|
|
*
|
|
|
|
|
* May throw database exceptions on error.
|
|
|
|
|
*
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param array $versions Set of record ids of deleted items to restore,
|
2013-12-04 16:18:05 +00:00
|
|
|
* or empty to restore all revisions.
|
2014-04-19 15:19:17 +00:00
|
|
|
* @param bool $unsuppress Remove restrictions on content upon restoration?
|
|
|
|
|
* @return int|bool The number of file revisions restored if successful,
|
2013-12-04 16:18:05 +00:00
|
|
|
* or false on failure
|
2007-05-30 21:02:32 +00:00
|
|
|
* STUB
|
|
|
|
|
* Overridden by LocalFile
|
|
|
|
|
*/
|
2011-05-29 13:33:29 +00:00
|
|
|
function restore( $versions = array(), $unsuppress = false ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->readOnlyError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-25 15:39:47 +00:00
|
|
|
* 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
|
2009-12-08 00:07:37 +00:00
|
|
|
* question only has a single page.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function isMultipage() {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
return $this->getHandler() && $this->handler->isMultiPage( $this );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-11-27 18:51:17 +00:00
|
|
|
* Returns the number of pages of a multipage document, or false for
|
2007-05-30 21:02:32 +00:00
|
|
|
* documents which aren't multipage documents
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2012-02-09 17:42:35 +00:00
|
|
|
* @return bool|int
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function pageCount() {
|
|
|
|
|
if ( !isset( $this->pageCount ) ) {
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
$this->pageCount = $this->handler->pageCount( $this );
|
|
|
|
|
} else {
|
|
|
|
|
$this->pageCount = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
return $this->pageCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate the height of a thumbnail using the source and destination width
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $srcWidth
|
|
|
|
|
* @param int $srcHeight
|
|
|
|
|
* @param int $dstWidth
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return int
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
|
|
|
|
|
// Exact integer multiply followed by division
|
|
|
|
|
if ( $srcWidth == 0 ) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return round( $srcHeight * $dstWidth / $srcWidth );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2010-06-08 12:15:48 +00:00
|
|
|
* Get an image size array like that returned by getImageSize(), or false if it
|
2014-05-24 17:27:36 +00:00
|
|
|
* can't be determined. Loads the image size directly from the file ignoring caches.
|
2007-05-30 21:02:32 +00:00
|
|
|
*
|
2014-05-24 17:27:36 +00:00
|
|
|
* @note Use getWidth()/getHeight() instead of this method unless you have a
|
|
|
|
|
* a good reason. This method skips all caches.
|
|
|
|
|
*
|
2014-08-13 19:41:39 +00:00
|
|
|
* @param string $filePath The path to the file (e.g. From getLocalPathRef() )
|
2014-05-24 17:27:36 +00:00
|
|
|
* @return array The width, followed by height, with optionally more things after
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2014-05-24 17:27:36 +00:00
|
|
|
function getImageSize( $filePath ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( !$this->getHandler() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2014-06-03 16:09:30 +00:00
|
|
|
return $this->getHandler()->getImageSize( $this, $filePath );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of the image description page. May return false if it is
|
|
|
|
|
* unknown or not applicable.
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
|
|
|
|
function getDescriptionUrl() {
|
* (bug 6672, 31024) Fixes for handling of images with an EXIF orientation
- sets an image's reported width/height to the logical form (portait image reports itself as portait)
- everything works in logical coordinates when sizing -- we don't touch the physical pre-rotation dimensions again until it's actual low-level resize time. This fixes several problems with incorrect thumb sizing (eg getting a 600x800 image when we asked for something that fits in 800x600 box)
- fixes unit test cases in ExifRotationTest that were reporting that the width/height were coming back with the physical form which we don't want
- removes some test cases on ExifRotationTest that tested dimension swapping in a place where we don't want it
- ensures that only logical width/height need be exposed to API etc, making exif-rotated images work via ForeignAPIRepo
Note that this may actually cause file metadata to get loaded twice during File::getPropsFromPath, as the $image parameter it passes in to the handler's getImageSize function is bogus and can't be used to fetch an already-loaded metadata blob. This should not generally be too expensive though; it's not a fast path.
Rotated files that were uploaded under previous versions may still have their width/height reversed; an action=purge on the file page will refresh it and cause thumbs to be regenerated.
Follows up on r79845, r90016, r92246, r92279, r96687, r97651, r97656, r97659.
Needs merge to 1.18.
2011-09-20 22:13:34 +00:00
|
|
|
if ( $this->repo ) {
|
|
|
|
|
return $this->repo->getDescriptionUrl( $this->getName() );
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTML text of the description page, if available
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param bool|Language $lang Optional language to fetch description in
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2013-08-31 05:45:43 +00:00
|
|
|
function getDescriptionText( $lang = false ) {
|
2009-08-02 15:22:06 +00:00
|
|
|
global $wgMemc, $wgLang;
|
2011-11-07 21:54:19 +00:00
|
|
|
if ( !$this->repo || !$this->repo->fetchDescription ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-08-31 05:45:43 +00:00
|
|
|
if ( !$lang ) {
|
|
|
|
|
$lang = $wgLang;
|
|
|
|
|
}
|
|
|
|
|
$renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
|
2007-05-30 21:02:32 +00:00
|
|
|
if ( $renderUrl ) {
|
2008-07-03 21:33:09 +00:00
|
|
|
if ( $this->repo->descriptionCacheExpiry > 0 ) {
|
2013-02-03 19:42:08 +00:00
|
|
|
wfDebug( "Attempting to get the description from cache..." );
|
2013-11-23 20:00:11 +00:00
|
|
|
$key = $this->repo->getLocalCacheKey(
|
|
|
|
|
'RemoteFileDescription',
|
|
|
|
|
'url',
|
|
|
|
|
$lang->getCode(),
|
|
|
|
|
$this->getName()
|
|
|
|
|
);
|
2013-02-03 19:42:08 +00:00
|
|
|
$obj = $wgMemc->get( $key );
|
|
|
|
|
if ( $obj ) {
|
|
|
|
|
wfDebug( "success!\n" );
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-07-03 18:24:08 +00:00
|
|
|
return $obj;
|
2008-07-03 07:49:35 +00:00
|
|
|
}
|
2013-02-03 19:42:08 +00:00
|
|
|
wfDebug( "miss\n" );
|
2008-07-03 07:49:35 +00:00
|
|
|
}
|
2007-05-30 21:02:32 +00:00
|
|
|
wfDebug( "Fetching shared description from $renderUrl\n" );
|
2008-07-03 07:49:35 +00:00
|
|
|
$res = Http::get( $renderUrl );
|
2009-01-27 19:34:21 +00:00
|
|
|
if ( $res && $this->repo->descriptionCacheExpiry > 0 ) {
|
|
|
|
|
$wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-07-03 07:49:35 +00:00
|
|
|
return $res;
|
2007-05-30 21:02:32 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-20 06:48:57 +00:00
|
|
|
/**
|
2012-06-05 22:58:54 +00:00
|
|
|
* Get description of file revision
|
2008-01-20 06:48:57 +00:00
|
|
|
* STUB
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $audience One of:
|
|
|
|
|
* File::FOR_PUBLIC to be displayed to all users
|
|
|
|
|
* File::FOR_THIS_USER to be displayed to the given user
|
|
|
|
|
* File::RAW get the description regardless of permissions
|
|
|
|
|
* @param User $user User object to check for, only if FOR_THIS_USER is
|
|
|
|
|
* passed to the $audience parameter
|
2011-05-29 13:33:29 +00:00
|
|
|
* @return string
|
2008-01-20 06:48:57 +00:00
|
|
|
*/
|
2012-06-05 22:58:54 +00:00
|
|
|
function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
|
2008-01-20 06:48:57 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
2011-12-20 03:52:06 +00:00
|
|
|
* Get the 14-character timestamp of the file upload
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
2012-02-09 18:01:54 +00:00
|
|
|
* @return string|bool TS_MW timestamp or false on failure
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2007-07-22 14:45:12 +00:00
|
|
|
function getTimestamp() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $this->repo->getFileTimestamp( $this->getPath() );
|
2007-05-30 21:02:32 +00:00
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the SHA-1 base 36 hash of the file
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-07-22 14:45:12 +00:00
|
|
|
*/
|
|
|
|
|
function getSha1() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertRepoDefined();
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $this->repo->getFileSha1( $this->getPath() );
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
/**
|
2012-07-10 12:48:06 +00:00
|
|
|
* Get the deletion archive key, "<sha1>.<ext>"
|
2011-05-29 13:33:29 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
*/
|
|
|
|
|
function getStorageKey() {
|
|
|
|
|
$hash = $this->getSha1();
|
|
|
|
|
if ( !$hash ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$ext = $this->getExtension();
|
|
|
|
|
$dotExt = $ext === '' ? '' : ".$ext";
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2011-05-25 15:39:47 +00:00
|
|
|
return $hash . $dotExt;
|
In Special:RevisionDelete:
* Refactored to remove massive duplication
* Removed page parameter and associated contextPage member variable, doesn't seem to do anything.
* Put ID lists into a single ids parameter and member variable instead of having one for each type.
* Fixed inappropriate call of Title::newFromUrl(), always wrong
* Don't pretend to use the return value from functions that don't return anything, this reduces readability.
* Use the table names for deleteKey/typeName values, they look more like English
* Use protected not private
* Remove requirement for log type to be specified in the target
* Use POST for RevisionDelete entry forms, to avoid URL size limits and issues with non-PATH_INFO URLs
* Don't purge all pages that use the given file
* LocalFile::purgeCache() already calls purgeHistory,() no need to do it again. But do call purgeDescription().
* Removed token from unhide=1 links, unnecessary
* Tokens are necessary on file streaming links, added them
* Fixed private data leakage due to incorrect use of LocalRepo::newFromArchiveName(). Non-existent placeholder file was returned which meant that $oimage->userCan(File::DELETED_FILE) was always true. Pass the archive name to tryShowFile() instead of the storage key.
* Using ls_field='oi_timestamp' is not correct, oi_timestamp refers to the timestamp of the revision in question, whereas the key that is stored is the timestamp of the previous revision (i.e. the timestamp in oi_archive_name). oi_archive_name would be more correct, although only half the field is used.
Elsewhere:
* Added missing message filehist-missing
* Fixed double asterisk in Status::getWikiText()
* Fixed escaping of the target parameter to Special:RevisionDelete from ImagePage
* Deleted FileStore.php. Deprecated in filerepo refactor except for get()/export() but somehow resurrected by RevisionDelete. Hopefully this will be the end of it. New interfaces will be added for wfStreamFile() in a later commit.
* Added convenience function File::getStorageKey(), factored out of Special:Undelete
* Added convenience function Revision::newFromArchiveRow(), factored out of Special:Undelete and Special:RevisionDelete
* Fixed notice in Special:Upload, uninitialised $pageText
FIXME: current revision can be suppressed on undeletion causing an unauthenticated unsuppress. Comments indicate this is a known issue. I fixed the parser cache pollution in this case but not the rest.
2009-06-01 11:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-30 21:02:32 +00:00
|
|
|
/**
|
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
|
* field of this file, if it's marked as deleted.
|
|
|
|
|
* STUB
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param int $field
|
|
|
|
|
* @param User $user User object to check, or null to use $wgUser
|
|
|
|
|
* @return bool
|
2007-05-30 21:02:32 +00:00
|
|
|
*/
|
2011-10-12 15:09:04 +00:00
|
|
|
function userCan( $field, User $user = null ) {
|
2007-05-30 21:02:32 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-06-16 02:55:25 +00:00
|
|
|
|
2012-11-21 18:37:41 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return array HTTP header name/value map to use for HEAD/GET request responses
|
2012-11-21 18:37:41 +00:00
|
|
|
*/
|
|
|
|
|
function getStreamHeaders() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getStreamHeaders( $this->getMetadata() );
|
|
|
|
|
} else {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
function getLongDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getLongDesc( $this );
|
|
|
|
|
} else {
|
2008-12-15 22:22:21 +00:00
|
|
|
return MediaHandler::getGeneralLongDesc( $this );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
function getShortDesc() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getShortDesc( $this );
|
|
|
|
|
} else {
|
2008-12-15 22:22:21 +00:00
|
|
|
return MediaHandler::getGeneralShortDesc( $this );
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.
Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
|
|
|
function getDimensionsString() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
if ( $handler ) {
|
|
|
|
|
return $handler->getDimensionsString( $this );
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return string
|
2011-05-29 13:33:29 +00:00
|
|
|
*/
|
2008-01-16 18:31:00 +00:00
|
|
|
function getRedirected() {
|
|
|
|
|
return $this->redirected;
|
|
|
|
|
}
|
2011-05-25 15:39:47 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2012-12-09 02:59:04 +00:00
|
|
|
* @return Title|null
|
2011-05-29 13:33:29 +00:00
|
|
|
*/
|
2008-05-20 17:05:57 +00:00
|
|
|
function getRedirectedTitle() {
|
|
|
|
|
if ( $this->redirected ) {
|
2011-04-12 00:16:04 +00:00
|
|
|
if ( !$this->redirectTitle ) {
|
2008-12-01 17:14:30 +00:00
|
|
|
$this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
|
2011-04-12 00:16:04 +00:00
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2008-05-20 17:05:57 +00:00
|
|
|
return $this->redirectTitle;
|
|
|
|
|
}
|
2013-11-23 20:00:11 +00:00
|
|
|
|
2012-12-09 02:59:04 +00:00
|
|
|
return null;
|
2008-05-20 17:05:57 +00:00
|
|
|
}
|
2008-01-16 18:31:00 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
2013-12-04 16:18:05 +00:00
|
|
|
* @param string $from
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-05-29 13:33:29 +00:00
|
|
|
*/
|
2008-01-16 18:31:00 +00:00
|
|
|
function redirectedFrom( $from ) {
|
|
|
|
|
$this->redirected = $from;
|
|
|
|
|
}
|
2009-04-26 11:12:39 +00:00
|
|
|
|
2011-05-29 13:33:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2009-04-26 11:12:39 +00:00
|
|
|
function isMissing() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-07 21:54:19 +00:00
|
|
|
|
2012-04-06 17:38:38 +00:00
|
|
|
/**
|
|
|
|
|
* Check if this file object is small and can be cached
|
2013-12-04 16:18:05 +00:00
|
|
|
* @return bool
|
2012-04-06 17:38:38 +00:00
|
|
|
*/
|
|
|
|
|
public function isCacheable() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 21:54:19 +00:00
|
|
|
/**
|
|
|
|
|
* Assert that $this->repo is set to a valid FileRepo instance
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
|
|
|
|
protected function assertRepoDefined() {
|
|
|
|
|
if ( !( $this->repo instanceof $this->repoClass ) ) {
|
|
|
|
|
throw new MWException( "A {$this->repoClass} object is not set for this File.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assert that $this->title is set to a Title
|
|
|
|
|
* @throws MWException
|
|
|
|
|
*/
|
|
|
|
|
protected function assertTitleDefined() {
|
|
|
|
|
if ( !( $this->title instanceof Title ) ) {
|
|
|
|
|
throw new MWException( "A Title object is not set for this File.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-27 20:09:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if creating thumbnails from the file is large or otherwise resource-intensive.
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isExpensiveToThumbnail() {
|
|
|
|
|
$handler = $this->getHandler();
|
|
|
|
|
return $handler ? $handler->isExpensiveToThumbnail( $this ) : false;
|
|
|
|
|
}
|
2007-07-22 14:45:12 +00:00
|
|
|
}
|