MediaWiki  REL1_19
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 ()
 Return the bit depth of the file Overridden by LocalFile STUB.
 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 ()
 Get discription of file revision STUB.
 getDescriptionText ()
 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
 getMediaType ()
 Return the type of the media in the file.
 getMetadata ()
 Get handler-specific metadata.
 getMimeType ()
 Returns the mime type of the file.
 getSha1 ()
 Get the SHA-1 base 36 hash of the file.
 getSize ()
 Return the size of the image file, in bytes.
 getThumbnails ($archiveName=false)
 getHandler inherited
 getTimestamp ()
 Get the 14-character timestamp of the file upload.
 getUpgraded ()
 getUser ($type= 'text')
 Returns ID or name of user who uploaded the file.
 getWidth ($page=1)
 Return the width of the image.
 isMissing ()
 splitMime inherited
 load ()
 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)
 Move or copy a file to its public location.
 publishTo ($srcPath, $dstRel, $flags=0)
 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)
 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
 $fileExists
 #@+
 $historyLine
 $historyRes
 $locked
 $major_mime
 $media_type
 $metadata
 $mime
 $minor_mime
 $missing
 $sha1
 $size
 $timestamp
 $upgraded
 $user
 $user_text
 $width

Protected Member Functions

 purgeThumbList ($dir, $files)
 Delete a list of thumbnails visible at urls.

Protected Attributes

 $repoClass = 'LocalRepo'
 #@-

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 31 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 148 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.

Definition at line 290 of file LocalFile.php.

References wfTimestamp().

Here is the call graph for this function:

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 1244 of file LocalFile.php.

References $result, $wgUseSquid, and SquidUpdate\purge().

Here is the call graph for this function:

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 1297 of file LocalFile.php.

References $wgUseSquid, and SquidUpdate\purge().

Here is the call graph for this function:

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 576 of file LocalFile.php.

Referenced by OldLocalFile\isVisible().

Here is the caller graph for this function:

Return the bit depth of the file Overridden by LocalFile STUB.

Reimplemented from File.

Definition at line 536 of file LocalFile.php.

LocalFile::getCacheFields ( prefix = 'img_')

Reimplemented in OldLocalFile.

Definition at line 241 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.

Reimplemented in OldLocalFile.

Definition at line 164 of file LocalFile.php.

Get discription of file revision STUB.

Returns:
string

Reimplemented from File.

Definition at line 1382 of file LocalFile.php.

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.

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1372 of file LocalFile.php.

References $wgParser, and Revision\newFromTitle().

Here is the call graph for this function:

isMultipage inherited

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

Reimplemented from File.

Reimplemented in ForeignDBFile.

Definition at line 1363 of file LocalFile.php.

LocalFile::getHeight ( page = 1)

Return the height of the image.

Returns false on error

Reimplemented from File.

Definition at line 498 of file LocalFile.php.

References $page.

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

purgeDescription inherited

purgeEverything inherited

Reimplemented from File.

Definition at line 774 of file LocalFile.php.

References $dbr, $limit, $res, OldLocalFile\newFromRow(), OldLocalFile\selectFields(), and wfRunHooks().

Here is the call graph for this function:

Return the type of the media in the file.

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

Reimplemented from File.

Definition at line 561 of file LocalFile.php.

Get handler-specific metadata.

Reimplemented from File.

Definition at line 531 of file LocalFile.php.

Returns the mime type of the file.

Reimplemented from File.

Definition at line 552 of file LocalFile.php.

Get the SHA-1 base 36 hash of the file.

Returns:
string

Reimplemented from File.

Definition at line 1392 of file LocalFile.php.

References wfReadOnly().

Here is the call graph for this function:

Return the size of the image file, in bytes.

Reimplemented from File.

Definition at line 544 of file LocalFile.php.

LocalFile::getThumbnails ( archiveName = false)

getHandler inherited

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

Parameters:
$archiveNamestring|false Name of an archive file
Returns:
array first element is the base dir, then files in that base dir.

Definition at line 626 of file LocalFile.php.

References $dir, $file, and $files.

Get the 14-character timestamp of the file upload.

Returns:
string|false TS_MW timestamp or false on failure

Reimplemented from File.

Definition at line 1387 of file LocalFile.php.

Definition at line 378 of file LocalFile.php.

LocalFile::getUser ( type = 'text')

Returns ID or name of user who uploaded the file.

Parameters:
$typestring 'text' or 'id'

Reimplemented from File.

Definition at line 518 of file LocalFile.php.

LocalFile::getWidth ( page = 1)

Return the width of the image.

Returns false on error

Reimplemented from File.

Definition at line 478 of file LocalFile.php.

References $page.

splitMime inherited

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

Reimplemented from File.

Definition at line 465 of file LocalFile.php.

References FileRepo\FILES_ONLY.

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

Definition at line 340 of file LocalFile.php.

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

Here is the caller graph for this function:

Try to load file metadata from memcached.

Returns true on success.

Definition at line 173 of file LocalFile.php.

Load file metadata from the DB.

Reimplemented in OldLocalFile.

Definition at line 264 of file LocalFile.php.

References loadFromRow().

Here is the call graph for this function:

Load metadata from the file itself.

Definition at line 236 of file LocalFile.php.

Referenced by OldLocalFile\upgradeRow().

Here is the caller graph for this function:

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

Load file metadata from a DB result row.

Definition at line 325 of file LocalFile.php.

Referenced by OldLocalFile\loadFromDB(), and loadFromDB().

Here is the caller graph for this function:

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 1419 of file LocalFile.php.

Referenced by OldLocalFile\uploadOld().

Here is the caller graph for this function:

Upgrade a row if it needs it.

Definition at line 353 of file LocalFile.php.

References $wgUpdateCompatibleMetadata, MediaHandler\METADATA_BAD, MediaHandler\METADATA_COMPATIBLE, and wfReadOnly().

Here is the call graph for this function:

LocalFile::migrateThumbFile ( thumbName)

getTransformScript inherited

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

Reimplemented from File.

Definition at line 590 of file LocalFile.php.

References FileRepo\FILES_ONLY.

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 1205 of file LocalFile.php.

References wfDebugLog().

Here is the call graph for this function:

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:
$sha1string base-36 SHA-1
$repoLocalRepo
string | bool$timestampMW_timestamp (optional)
Returns:
bool|LocalFile

Reimplemented in OldLocalFile.

Definition at line 106 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 ForeignDBFile, and OldLocalFile.

Definition at line 88 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 ForeignDBFile, and OldLocalFile.

Definition at line 75 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

Reimplemented from File.

Definition at line 828 of file LocalFile.php.

References $dbr, and $fname.

LocalFile::publish ( srcPath,
flags = 0 
)

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:
$srcPathString: local filesystem path to the source image
$flagsInteger: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
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 1151 of file LocalFile.php.

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

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:
$srcPathString: local filesystem path to the source image
$dstRelString: target relative path
$flagsInteger: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
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 1169 of file LocalFile.php.

References FileRepo\DELETE_SOURCE, File\DELETE_SOURCE, and wfTimestamp().

Referenced by OldLocalFile\uploadOld().

Here is the call graph for this function:

Here is the caller graph for this function:

LocalFile::purgeCache ( options = array())

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

Reimplemented from File.

Definition at line 676 of file LocalFile.php.

References $options, and SquidUpdate\purge().

Here is the call graph for this function:

Purge the shared history (OldLocalFile) cache.

Definition at line 657 of file LocalFile.php.

References $wgMemc.

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

Definition at line 648 of file LocalFile.php.

LocalFile::purgeOldThumbnails ( archiveName)

Delete cached transformed files for an archived version only.

Parameters:
$archiveNamestring name of the archived file

Definition at line 691 of file LocalFile.php.

References $dir, $file, $files, $urls, $wgUseSquid, SquidUpdate\purge(), and wfRunHooks().

Referenced by PurgeDeletedFiles\purgeFromArchiveTable().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Delete a list of thumbnails visible at urls.

Parameters:
$dirstring base dir of the files.
$filesarray of strings: relative filenames (to $dir)

Definition at line 749 of file LocalFile.php.

References $dir, $file, $files, FileRepo\SKIP_LOCKING, and wfDebug().

Here is the call graph for this function:

LocalFile::purgeThumbnails ( options = array())

Delete cached transformed files for the current version only.

Definition at line 714 of file LocalFile.php.

References $dir, $file, $files, $options, $urls, $wgUseSquid, SquidUpdate\purge(), and wfRunHooks().

Here is the call graph for this function:

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

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

Reimplemented in ForeignDBFile.

Definition at line 927 of file LocalFile.php.

References $license, $wgUser, and SpecialUpload\getInitialPageText().

Here is the call graph for this function:

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

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

Definition at line 946 of file LocalFile.php.

References $comment, $user, $wgUser, false, Revision\newNullRevision(), SquidUpdate\purge(), wfDebug(), wfRunHooks(), and wfTimestamp().

Here is the call graph for this function:

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

Reimplemented from File.

Definition at line 865 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:
$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 1332 of file LocalFile.php.

Save the file metadata to memcached.

Definition at line 210 of file LocalFile.php.

static LocalFile::selectFields ( ) [static]

Fields in the image table.

Reimplemented in OldLocalFile.

Definition at line 125 of file LocalFile.php.

Referenced by LocalRepo\findBySha1(), and ApiQueryAllimages\run().

Here is the caller graph for this function:

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.

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 437 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 1434 of file LocalFile.php.

Referenced by OldLocalFile\uploadOld().

Here is the caller graph for this function:

Roll back the DB transaction and mark the image unlocked.

Definition at line 1447 of file LocalFile.php.

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

Reimplemented from File.

Reimplemented in OldLocalFile.

Definition at line 385 of file LocalFile.php.

References wfDebug(), wfProfileIn(), wfProfileOut(), and wfReadOnly().

Here is the call graph for this function:

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:
$srcPathString: source storage path or virtual URL
$commentString: upload description
$pageTextString: text to use for the new description page, if a new description page is created
$flagsInteger: flags for publish()
$propsArray: File properties, if known. This can be used to reduce the upload time when uploading virtual URLs for which the file info is already known
$timestampString: timestamp for img_timestamp, or false to use the current time
$userMixed: 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 901 of file LocalFile.php.

References $comment, $user, and $wgContLang.


Member Data Documentation

LocalFile::$attr

Definition at line 36 of file LocalFile.php.

LocalFile::$bits

Definition at line 36 of file LocalFile.php.

LocalFile::$dataLoaded

Definition at line 36 of file LocalFile.php.

LocalFile::$deleted

Definition at line 36 of file LocalFile.php.

LocalFile::$description

Definition at line 36 of file LocalFile.php.

LocalFile::$fileExists

#@+

Access:
private

Definition at line 36 of file LocalFile.php.

LocalFile::$historyLine

Definition at line 36 of file LocalFile.php.

LocalFile::$historyRes

Definition at line 36 of file LocalFile.php.

LocalFile::$locked

Definition at line 36 of file LocalFile.php.

LocalFile::$major_mime

Definition at line 36 of file LocalFile.php.

LocalFile::$media_type

Definition at line 36 of file LocalFile.php.

LocalFile::$metadata

Definition at line 36 of file LocalFile.php.

LocalFile::$mime

Definition at line 36 of file LocalFile.php.

LocalFile::$minor_mime

Definition at line 36 of file LocalFile.php.

LocalFile::$missing

Definition at line 36 of file LocalFile.php.

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

#@-

Reimplemented from File.

Definition at line 61 of file LocalFile.php.

LocalFile::$sha1

Definition at line 36 of file LocalFile.php.

Referenced by OldLocalFile\newFromKey().

LocalFile::$size

Definition at line 36 of file LocalFile.php.

LocalFile::$timestamp
LocalFile::$upgraded

Definition at line 36 of file LocalFile.php.

LocalFile::$user
LocalFile::$user_text

Definition at line 36 of file LocalFile.php.

LocalFile::$width

Definition at line 36 of file LocalFile.php.


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