MediaWiki  REL1_22
LocalFile Class Reference

Class to represent a local file in the wiki's own database. More...

Inheritance diagram for LocalFile:
Collaboration diagram for LocalFile:

List of all members.

Public Member Functions

 __construct ($title, $repo)
 Constructor.
 decodeRow ($row, $prefix= 'img_')
 Decode a row from the database (either object or array) to an array with timestamps and MIME types decoded, and the field prefix removed.
 delete ($reason, $suppress=false)
 Delete all versions of the file.
 deleteOld ($archiveName, $reason, $suppress=false)
 Delete an old version of the file.
 exists ()
 canRender inherited
 getBitDepth ()
 getCacheFields ($prefix= 'img_')
 getCacheKey ()
 Get the memcached key for the main data for this file, or false if there is no access to the shared cache.
 getDescription ($audience=self::FOR_PUBLIC, User $user=null)
 getDescriptionText ($lang=null)
 Get the HTML text of the description page This is not used by ImagePage for local files, since (among other things) it skips the parser cache.
 getDescriptionUrl ()
 isMultipage inherited
 getHeight ($page=1)
 Return the height of the image.
 getHistory ($limit=null, $start=null, $end=null, $inc=true)
 purgeDescription inherited
 getLazyCacheFields ($prefix= 'img_')
 getMediaType ()
 Return the type of the media in the file.
 getMetadata ()
 Get handler-specific metadata.
 getMimeType ()
 Returns the mime type of the file.
 getSha1 ()
 getSize ()
 Return the size of the image file, in bytes.
 getThumbnails ($archiveName=false)
 getHandler inherited
 getTimestamp ()
 getUpgraded ()
 getUser ($type= 'text')
 Returns ID or name of user who uploaded the file.
 getWidth ($page=1)
 Return the width of the image.
 isCacheable ()
 isMissing ()
 splitMime inherited
 load ($flags=0)
 Load file metadata from cache or DB, unless already loaded.
 loadFromCache ()
 Try to load file metadata from memcached.
 loadFromDB ()
 Load file metadata from the DB.
 loadFromFile ()
 Load metadata from the file itself.
 loadFromRow ($row, $prefix= 'img_')
 Load file metadata from a DB result row.
 lock ()
 Start a transaction and lock the image for update Increments a reference counter if the lock is already held.
 maybeUpgradeRow ()
 Upgrade a row if it needs it.
 migrateThumbFile ($thumbName)
 getTransformScript inherited
 move ($target)
 getLinksTo inherited
 nextHistoryLine ()
 Return the history of this file, line by line.
 publish ($srcPath, $flags=0, array $options=array())
 Move or copy a file to its public location.
 publishTo ($srcPath, $dstRel, $flags=0, array $options=array())
 Move or copy a file to a specified location.
 purgeCache ($options=array())
 Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid.
 purgeHistory ()
 Purge the shared history (OldLocalFile) cache.
 purgeMetadataCache ()
 Refresh metadata in memcached, but don't touch thumbnails or squid.
 purgeOldThumbnails ($archiveName)
 Delete cached transformed files for an archived version only.
 purgeThumbnails ($options=array())
 Delete cached transformed files for the current version only.
 recordUpload ($oldver, $desc, $license= '', $copyStatus= '', $source= '', $watch=false, $timestamp=false, User $user=null)
 Record a file upload in the upload log and the image table.
 recordUpload2 ($oldver, $comment, $pageText, $props=false, $timestamp=false, $user=null)
 Record a file upload in the upload log and the image table.
 resetHistory ()
 Reset the history pointer to the first element of the history.
 restore ($versions=array(), $unsuppress=false)
 Restore all or specified deleted revisions to the given file.
 saveToCache ()
 Save the file metadata to memcached.
 setProps ($info)
 Set properties in this object to be equal to those given in the associative array $info.
 unlock ()
 Decrement the lock reference count.
 unlockAndRollback ()
 Roll back the DB transaction and mark the image unlocked.
 upgradeRow ()
 Fix assorted version-related problems with the image row by reloading it from the file.
 upload ($srcPath, $comment, $pageText, $flags=0, $props=false, $timestamp=false, $user=null)
 getHashPath inherited

Static Public Member Functions

static newFromKey ($sha1, $repo, $timestamp=false)
 Create a LocalFile from a SHA-1 key Do not call this except from inside a repo class.
static newFromRow ($row, $repo)
 Create a LocalFile from a title Do not call this except from inside a repo class.
static newFromTitle ($title, $repo, $unused=null)
 Create a LocalFile from a title Do not call this except from inside a repo class.
static selectFields ()
 Fields in the image table.

Public Attributes

 $attr
 $bits
 $dataLoaded
 $deleted
 $description
 $extraDataLoaded
 $fileExists
 #@+
 $historyLine
 $historyRes
 $locked
 $lockedOwnTrx
 $major_mime
 $media_type
 $metadata
 $mime
 $minor_mime
 $missing
LocalRepo $repo
 #@-
 $sha1
 $size
 $timestamp
 $upgraded
 $user
 $user_text
 $width
const CACHE_FIELD_MAX_LEN = 1000
const LOAD_ALL = 1

Protected Member Functions

 loadExtraFromDB ()
 Load lazy file metadata from the DB.
 purgeThumbList ($dir, $files)
 Delete a list of thumbnails visible at urls.
 readOnlyFatalStatus ()
 unprefixRow ($row, $prefix= 'img_')

Protected Attributes

 $repoClass = 'LocalRepo'
 Required Repository class type.

Detailed Description

Class to represent a local file in the wiki's own database.

Provides methods to retrieve paths (physical, logical, URL), to generate image thumbnails or for uploading.

Note that only the repo object knows what its file class is called. You should never name a file class explictly outside of the repo class. Instead use the repo's factory functions to generate file objects, for example:

RepoGroup::singleton()->getLocalRepo()->newFile( $title );

The convenience functions wfLocalFile() and wfFindFile() should be sufficient in most cases.

Definition at line 46 of file LocalFile.php.


Constructor & Destructor Documentation

LocalFile::__construct ( title,
repo 
)

Constructor.

Do not call this except from inside a repo class.

Reimplemented from File.

Definition at line 174 of file LocalFile.php.


Member Function Documentation

LocalFile::decodeRow ( row,
prefix = 'img_' 
)

Decode a row from the database (either object or array) to an array with timestamps and MIME types decoded, and the field prefix removed.

Parameters:
$row
$prefixstring
Exceptions:
MWException
Returns:
array

Definition at line 420 of file LocalFile.php.

LocalFile::delete ( reason,
suppress = false 
)

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.

Parameters:
$reason
$suppress
Returns:
FileRepoStatus object.

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1549 of file LocalFile.php.

LocalFile::deleteOld ( archiveName,
reason,
suppress = false 
)

Delete an old version of the file.

Moves the file into an archive directory (or deletes it) and removes the database row.

Cache purging is done; logging is caller's responsibility.

Parameters:
$archiveNameString
$reasonString
$suppressBoolean
Exceptions:
MWExceptionor FSException on database or file store failure
Returns:
FileRepoStatus object.

Definition at line 1607 of file LocalFile.php.

canRender inherited

mustRender inherited allowInlineDisplay inherited isSafeFile inherited isTrustedFile inherited Returns true if the file exists on disk.

Returns:
boolean Whether file exist on disk.

Reimplemented from File.

Definition at line 729 of file LocalFile.php.

Referenced by OldLocalFile\isVisible().

Returns:
int

Reimplemented from File.

Definition at line 686 of file LocalFile.php.

LocalFile::getCacheFields ( prefix = 'img_')
Parameters:
$prefixstring
Returns:
array

Reimplemented in OldLocalFile.

Definition at line 289 of file LocalFile.php.

Get the memcached key for the main data for this file, or false if there is no access to the shared cache.

Returns:
bool

Reimplemented in OldLocalFile.

Definition at line 192 of file LocalFile.php.

LocalFile::getDescription ( audience = self::FOR_PUBLIC,
User user = null 
)
Returns:
string

Reimplemented from File.

Definition at line 1707 of file LocalFile.php.

LocalFile::getDescriptionText ( lang = null)

Get the HTML text of the description page This is not used by ImagePage for local files, since (among other things) it skips the parser cache.

Parameters:
$langLanguage What language to get description in (Optional)
Returns:
bool|mixed

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1691 of file LocalFile.php.

isMultipage inherited

pageCount inherited scaleHeight inherited getImageSize inherited Get the URL of the file description page.

Returns:
String

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1679 of file LocalFile.php.

LocalFile::getHeight ( page = 1)

Return the height of the image.

Parameters:
$pageint
Returns:
int

Reimplemented from File.

Definition at line 637 of file LocalFile.php.

LocalFile::getHistory ( limit = null,
start = null,
end = null,
inc = true 
)

purgeDescription inherited

purgeEverything inherited

Parameters:
$limitnull
$startnull
$endnull
$incbool
Returns:
array

Reimplemented from File.

Definition at line 954 of file LocalFile.php.

LocalFile::getLazyCacheFields ( prefix = 'img_')
Returns:
array

Definition at line 312 of file LocalFile.php.

Referenced by OldLocalFile\loadExtraFromDB().

Return the type of the media in the file.

Use the value returned by this function with the MEDIATYPE_xxx constants.

Returns:
string

Reimplemented from File.

Definition at line 714 of file LocalFile.php.

Get handler-specific metadata.

Returns:
string

Reimplemented from File.

Definition at line 678 of file LocalFile.php.

Returns the mime type of the file.

Returns:
string

Reimplemented from File.

Definition at line 704 of file LocalFile.php.

Returns:
string

Reimplemented from File.

Definition at line 1731 of file LocalFile.php.

Return the size of the image file, in bytes.

Returns:
int

Reimplemented from File.

Definition at line 695 of file LocalFile.php.

LocalFile::getThumbnails ( archiveName = false)

getHandler inherited

iconThumb inherited getLastError inherited Get all thumbnail names previously generated for this file

Parameters:
string | bool$archiveNameName of an archive file, default false
Returns:
array first element is the base dir, then files in that base dir.

Definition at line 783 of file LocalFile.php.

Returns:
bool|string

Reimplemented from File.

Definition at line 1723 of file LocalFile.php.

Definition at line 504 of file LocalFile.php.

LocalFile::getUser ( type = 'text')

Returns ID or name of user who uploaded the file.

Parameters:
string$type'text' or 'id'
Returns:
int|string

Reimplemented from File.

Definition at line 664 of file LocalFile.php.

LocalFile::getWidth ( page = 1)

Return the width of the image.

Parameters:
$pageint
Returns:
int

Reimplemented from File.

Definition at line 610 of file LocalFile.php.

Returns:
bool Whether to cache in RepoGroup (this avoids OOMs)

Reimplemented from File.

Definition at line 1756 of file LocalFile.php.

splitMime inherited

getName inherited getTitle inherited getURL inherited getViewURL inherited getPath inherited isVisible inhereted

Returns:
bool

Reimplemented from File.

Definition at line 596 of file LocalFile.php.

LocalFile::load ( flags = 0)

Load file metadata from cache or DB, unless already loaded.

Parameters:
integer$flags

Definition at line 463 of file LocalFile.php.

Referenced by OldLocalFile\getArchiveName(), OldLocalFile\getVisibility(), OldLocalFile\isDeleted(), and OldLocalFile\userCan().

LocalFile::loadExtraFromDB ( ) [protected]

Load lazy file metadata from the DB.

This covers fields that are sometimes not cached.

Reimplemented in OldLocalFile.

Definition at line 360 of file LocalFile.php.

Try to load file metadata from memcached.

Returns true on success.

Returns:
bool

Definition at line 202 of file LocalFile.php.

Load file metadata from the DB.

Reimplemented in OldLocalFile.

Definition at line 334 of file LocalFile.php.

Load metadata from the file itself.

Definition at line 280 of file LocalFile.php.

Referenced by OldLocalFile\upgradeRow().

LocalFile::loadFromRow ( row,
prefix = 'img_' 
)

Load file metadata from a DB result row.

Definition at line 445 of file LocalFile.php.

Referenced by OldLocalFile\loadFromDB().

Start a transaction and lock the image for update Increments a reference counter if the lock is already held.

Returns:
boolean True if the image exists, false otherwise

Definition at line 1768 of file LocalFile.php.

Referenced by OldLocalFile\uploadOld().

Upgrade a row if it needs it.

Definition at line 479 of file LocalFile.php.

LocalFile::migrateThumbFile ( thumbName)

getTransformScript inherited

getUnscaledThumb inherited thumbName inherited createThumb inherited transform inherited Fix thumbnail files from 1.4 or before, with extreme prejudice

Todo:
: do we still care about this? Perhaps a maintenance script can be made instead.

Enabling this code results in a serious RTT regression for wikis without 404 handling.

Reimplemented from File.

Definition at line 746 of file LocalFile.php.

LocalFile::move ( target)

getLinksTo inherited

getExifData inherited isLocal inherited wasDeleted inherited 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

Parameters:
$targetTitle New file name
Returns:
FileRepoStatus object.

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1495 of file LocalFile.php.

static LocalFile::newFromKey ( sha1,
repo,
timestamp = false 
) [static]

Create a LocalFile from a SHA-1 key Do not call this except from inside a repo class.

Parameters:
string$sha1base-36 SHA-1
$repoLocalRepo
string | bool$timestampMW_timestamp (optional)
Returns:
bool|LocalFile

Reimplemented in OldLocalFile.

Definition at line 131 of file LocalFile.php.

static LocalFile::newFromRow ( row,
repo 
) [static]

Create a LocalFile from a title Do not call this except from inside a repo class.

Parameters:
$row
$repo
Returns:
LocalFile

Reimplemented in OldLocalFile, and ForeignDBFile.

Definition at line 113 of file LocalFile.php.

static LocalFile::newFromTitle ( title,
repo,
unused = null 
) [static]

Create a LocalFile from a title Do not call this except from inside a repo class.

Note: $unused param is only here to avoid an E_STRICT

Parameters:
$title
$repo
$unused
Returns:
LocalFile

Reimplemented in OldLocalFile, and ForeignDBFile.

Definition at line 100 of file LocalFile.php.

Return the history of this file, line by line.

starts with current version, then old versions. uses $this->historyLine to check which line to return: 0 return line for current version 1 query for old versions, return first one 2, ... return next old version from above query

Returns:
bool

Reimplemented from File.

Definition at line 1009 of file LocalFile.php.

LocalFile::publish ( srcPath,
flags = 0,
array options = array() 
)

Move or copy a file to its public location.

If a file exists at the destination, move it to an archive. Returns a FileRepoStatus object with the archive name in the "value" member on success.

The archive name should be passed through to recordUpload for database registration.

Parameters:
string$srcPathlocal filesystem path to the source image
$flagsInteger: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
array$optionsOptional additional parameters
Returns:
FileRepoStatus object. On success, the value member contains the archive name, or an empty string if it was a new file.

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1436 of file LocalFile.php.

LocalFile::publishTo ( srcPath,
dstRel,
flags = 0,
array options = array() 
)

Move or copy a file to a specified location.

Returns a FileRepoStatus object with the archive name in the "value" member on success.

The archive name should be passed through to recordUpload for database registration.

Parameters:
string$srcPathlocal filesystem path to the source image
string$dstReltarget relative path
$flagsInteger: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
array$optionsOptional additional parameters
Returns:
FileRepoStatus object. On success, the value member contains the archive name, or an empty string if it was a new file.

Definition at line 1455 of file LocalFile.php.

Referenced by OldLocalFile\uploadOld().

LocalFile::purgeCache ( options = array())

Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid.

Parameters:
Array$optionsAn array potentially with the key forThumbRefresh.
Note:
This used to purge old thumbnails by default as well, but doesn't anymore.

Reimplemented from File.

Definition at line 834 of file LocalFile.php.

Purge the shared history (OldLocalFile) cache.

Note:
This used to purge old thumbnails as well.

Definition at line 816 of file LocalFile.php.

Refresh metadata in memcached, but don't touch thumbnails or squid.

Definition at line 805 of file LocalFile.php.

LocalFile::purgeOldThumbnails ( archiveName)

Delete cached transformed files for an archived version only.

Parameters:
string$archiveNamename of the archived file

Definition at line 851 of file LocalFile.php.

LocalFile::purgeThumbList ( dir,
files 
) [protected]

Delete a list of thumbnails visible at urls.

Parameters:
string$dirbase dir of the files.
array$filesof strings: relative filenames (to $dir)

Definition at line 920 of file LocalFile.php.

LocalFile::purgeThumbnails ( options = array())

Delete cached transformed files for the current version only.

Definition at line 878 of file LocalFile.php.

Returns:
Status

Definition at line 1821 of file LocalFile.php.

LocalFile::recordUpload ( oldver,
desc,
license = '',
copyStatus = '',
source = '',
watch = false,
timestamp = false,
User user = null 
)

Record a file upload in the upload log and the image table.

Parameters:
$oldver
$descstring
$licensestring
$copyStatusstring
$sourcestring
$watchbool
$timestampstring|bool
$userUser object or null to use $wgUser
Returns:
bool

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1144 of file LocalFile.php.

LocalFile::recordUpload2 ( oldver,
comment,
pageText,
props = false,
timestamp = false,
user = null 
)

Record a file upload in the upload log and the image table.

Parameters:
$oldver
$commentstring
$pageTextstring
$propsbool|array
$timestampbool|string
$usernull|User
Returns:
bool

Definition at line 1174 of file LocalFile.php.

Reset the history pointer to the first element of the history.

Reimplemented from File.

Definition at line 1046 of file LocalFile.php.

LocalFile::restore ( versions = array(),
unsuppress = false 
)

Restore all or specified deleted revisions to the given file.

Permissions and logging are left to the caller.

May throw database exceptions on error.

Parameters:
array$versionsset of record ids of deleted items to restore, or empty to restore all revisions.
$unsuppressBoolean
Returns:
FileRepoStatus

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1645 of file LocalFile.php.

Save the file metadata to memcached.

Definition at line 244 of file LocalFile.php.

static LocalFile::selectFields ( ) [static]

Fields in the image table.

Returns:
array

Reimplemented in OldLocalFile.

Definition at line 151 of file LocalFile.php.

Referenced by LocalRepo\findBySha1(), LocalRepo\findBySha1s(), LocalRepo\findFilesByPrefix(), and ApiQueryAllImages\run().

LocalFile::setProps ( info)

Set properties in this object to be equal to those given in the associative array $info.

Only cacheable fields can be set. All fields *must* be set in $info except for getLazyCacheFields().

If 'mime' is given, it will be split into major_mime/minor_mime. If major_mime/minor_mime are given, $this->mime will also be set.

Definition at line 565 of file LocalFile.php.

Decrement the lock reference count.

If the reference count is reduced to zero, commits the transaction and thereby releases the image lock.

Definition at line 1797 of file LocalFile.php.

Referenced by OldLocalFile\uploadOld().

Roll back the DB transaction and mark the image unlocked.

Definition at line 1811 of file LocalFile.php.

LocalFile::unprefixRow ( row,
prefix = 'img_' 
) [protected]
Parameters:
Row$row
$prefixstring
Returns:
Array

Definition at line 396 of file LocalFile.php.

Referenced by OldLocalFile\loadExtraFromDB().

Fix assorted version-related problems with the image row by reloading it from the file.

Reimplemented from File.

Reimplemented in OldLocalFile.

Definition at line 511 of file LocalFile.php.

LocalFile::upload ( srcPath,
comment,
pageText,
flags = 0,
props = false,
timestamp = false,
user = null 
)

getHashPath inherited

getRel inherited getUrlRel inherited getArchiveRel inherited getArchivePath inherited getThumbPath inherited getArchiveUrl inherited getThumbUrl inherited getArchiveVirtualUrl inherited getThumbVirtualUrl inherited isHashed inherited Upload a file and record it in the DB

Parameters:
string$srcPathsource storage path, virtual URL, or filesystem path
string$commentupload description
string$pageTexttext to use for the new description page, if a new description page is created
$flagsInteger|bool: flags for publish()
array | bool$propsFile properties, if known. This can be used to reduce the upload time when uploading virtual URLs for which the file info is already known
string | bool$timestamptimestamp for img_timestamp, or false to use the current time
$userUser|null: User object or null to use $wgUser
Returns:
FileRepoStatus object. On success, the value member contains the archive name, or an empty string if it was a new file.

Definition at line 1082 of file LocalFile.php.


Member Data Documentation

LocalFile::$attr

Definition at line 53 of file LocalFile.php.

LocalFile::$bits

Definition at line 53 of file LocalFile.php.

LocalFile::$dataLoaded

Definition at line 53 of file LocalFile.php.

LocalFile::$deleted

Definition at line 53 of file LocalFile.php.

LocalFile::$description

Definition at line 53 of file LocalFile.php.

LocalFile::$extraDataLoaded

Definition at line 53 of file LocalFile.php.

LocalFile::$fileExists

#@+

Access:
private

Definition at line 53 of file LocalFile.php.

LocalFile::$historyLine

Definition at line 53 of file LocalFile.php.

LocalFile::$historyRes

Definition at line 53 of file LocalFile.php.

LocalFile::$locked

Definition at line 53 of file LocalFile.php.

LocalFile::$lockedOwnTrx

Definition at line 53 of file LocalFile.php.

LocalFile::$major_mime

Definition at line 53 of file LocalFile.php.

LocalFile::$media_type

Definition at line 53 of file LocalFile.php.

LocalFile::$metadata

Definition at line 53 of file LocalFile.php.

LocalFile::$mime

Definition at line 53 of file LocalFile.php.

LocalFile::$minor_mime

Definition at line 53 of file LocalFile.php.

LocalFile::$missing

Definition at line 53 of file LocalFile.php.

LocalFile::$repoClass = 'LocalRepo' [protected]

Required Repository class type.

Reimplemented from File.

Definition at line 84 of file LocalFile.php.

LocalFile::$sha1

Definition at line 53 of file LocalFile.php.

Referenced by OldLocalFile\newFromKey().

LocalFile::$size

Definition at line 53 of file LocalFile.php.

LocalFile::$timestamp
LocalFile::$upgraded

Definition at line 53 of file LocalFile.php.

LocalFile::$user
LocalFile::$user_text

Definition at line 53 of file LocalFile.php.

LocalFile::$width

Definition at line 53 of file LocalFile.php.

Definition at line 47 of file LocalFile.php.

Definition at line 86 of file LocalFile.php.


The documentation for this class was generated from the following file: