MediaWiki
master
|
Class to represent a local file in the wiki's own database. More...
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 () | |
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 () | |
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 () | |
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 | |
LocalRepo | $repo |
#@- | |
$sha1 | |
$size | |
$timestamp | |
$upgraded | |
$user | |
$user_text | |
$width | |
const | CACHE_FIELD_MAX_LEN = 1000 |
Protected Member Functions | |
purgeThumbList ($dir, $files) | |
Delete a list of thumbnails visible at urls. | |
readOnlyFatalStatus () | |
Protected Attributes | |
$repoClass = 'LocalRepo' | |
Required Repository class type. |
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.
LocalFile::__construct | ( | $ | title, |
$ | repo | ||
) |
Constructor.
Do not call this except from inside a repo class.
Reimplemented from File.
Definition at line 170 of file LocalFile.php.
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.
$row | |
$prefix | string |
MWException |
Definition at line 322 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.
$reason | |
$suppress |
Reimplemented from File.
Reimplemented in ForeignDBFile.
Definition at line 1360 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.
$archiveName | String |
$reason | String |
$suppress | Boolean |
MWException | or FSException on database or file store failure |
Definition at line 1400 of file LocalFile.php.
canRender inherited
mustRender inherited allowInlineDisplay inherited isSafeFile inherited isTrustedFile inherited Returns true if the file exists on disk.
Reimplemented from File.
Definition at line 622 of file LocalFile.php.
Referenced by OldLocalFile\isVisible().
LocalFile::getCacheFields | ( | $ | prefix = 'img_' | ) |
$prefix | string |
Reimplemented in OldLocalFile.
Definition at line 269 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 187 of file LocalFile.php.
LocalFile::getDescription | ( | $ | audience = self::FOR_PUBLIC , |
User $ | user = 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.
Reimplemented from File.
Reimplemented in ForeignDBFile.
Definition at line 1476 of file LocalFile.php.
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 1466 of file LocalFile.php.
LocalFile::getHeight | ( | $ | page = 1 | ) |
Return the height of the image.
$page | int |
Reimplemented from File.
Definition at line 536 of file LocalFile.php.
LocalFile::getHistory | ( | $ | limit = null , |
$ | start = null , |
||
$ | end = null , |
||
$ | inc = true |
||
) |
purgeDescription inherited
purgeEverything inherited
$limit | null |
$start | null |
$end | null |
$inc | bool |
Reimplemented from File.
Definition at line 839 of file LocalFile.php.
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 607 of file LocalFile.php.
Get handler-specific metadata.
Reimplemented from File.
Definition at line 571 of file LocalFile.php.
Returns the mime type of the file.
Reimplemented from File.
Definition at line 597 of file LocalFile.php.
Return the size of the image file, in bytes.
Reimplemented from File.
Definition at line 588 of file LocalFile.php.
LocalFile::getThumbnails | ( | $ | archiveName = false | ) |
getHandler inherited
iconThumb inherited getLastError inherited Get all thumbnail names previously generated for this file
$archiveName | string|bool Name of an archive file, default false |
Definition at line 677 of file LocalFile.php.
Definition at line 410 of file LocalFile.php.
LocalFile::getUser | ( | $ | type = 'text' | ) |
Returns ID or name of user who uploaded the file.
$type | string 'text' or 'id' |
Reimplemented from File.
Definition at line 557 of file LocalFile.php.
LocalFile::getWidth | ( | $ | page = 1 | ) |
Return the width of the image.
$page | int |
Reimplemented from File.
Definition at line 515 of file LocalFile.php.
splitMime inherited
getName inherited getTitle inherited getURL inherited getViewURL inherited getPath inherited isVisible inhereted
Reimplemented from File.
Definition at line 501 of file LocalFile.php.
LocalFile::load | ( | ) |
Load file metadata from cache or DB, unless already loaded.
Definition at line 372 of file LocalFile.php.
Referenced by OldLocalFile\getArchiveName(), OldLocalFile\getVisibility(), OldLocalFile\isDeleted(), and OldLocalFile\userCan().
Try to load file metadata from memcached.
Returns true on success.
Definition at line 197 of file LocalFile.php.
Load file metadata from the DB.
Reimplemented in OldLocalFile.
Definition at line 292 of file LocalFile.php.
Load metadata from the file itself.
Definition at line 260 of file LocalFile.php.
Referenced by OldLocalFile\upgradeRow().
LocalFile::loadFromRow | ( | $ | row, |
$ | prefix = 'img_' |
||
) |
Load file metadata from a DB result row.
Definition at line 357 of file LocalFile.php.
Referenced by OldLocalFile\loadFromDB().
LocalFile::lock | ( | ) |
Start a transaction and lock the image for update Increments a reference counter if the lock is already held.
Definition at line 1548 of file LocalFile.php.
Referenced by OldLocalFile\uploadOld().
Upgrade a row if it needs it.
Definition at line 385 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
Enabling this code results in a serious RTT regression for wikis without 404 handling.
Reimplemented from File.
Definition at line 639 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
$target | Title New file name |
Reimplemented from File.
Reimplemented in ForeignDBFile.
Definition at line 1315 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.
$sha1 | string base-36 SHA-1 | |
$repo | LocalRepo | |
string | bool | $timestamp | MW_timestamp (optional) |
Reimplemented in OldLocalFile.
Definition at line 127 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.
$row | |
$repo |
Reimplemented in OldLocalFile, and ForeignDBFile.
Definition at line 109 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
$title | |
$repo | |
$unused |
Reimplemented in OldLocalFile, and ForeignDBFile.
Definition at line 96 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 894 of file LocalFile.php.
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.
$srcPath | String: local filesystem path to the source image |
$flags | Integer: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy |
Reimplemented from File.
Reimplemented in ForeignDBFile.
Definition at line 1257 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.
$srcPath | String: local filesystem path to the source image |
$dstRel | String: target relative path |
$flags | Integer: a bitwise combination of: File::DELETE_SOURCE Delete the source file, i.e. move rather than copy |
Definition at line 1275 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.
Reimplemented from File.
Definition at line 725 of file LocalFile.php.
Purge the shared history (OldLocalFile) cache.
Definition at line 706 of file LocalFile.php.
Refresh metadata in memcached, but don't touch thumbnails or squid.
Definition at line 697 of file LocalFile.php.
LocalFile::purgeOldThumbnails | ( | $ | archiveName | ) |
Delete cached transformed files for an archived version only.
$archiveName | string name of the archived file |
Definition at line 740 of file LocalFile.php.
Referenced by PurgeDeletedFiles\purgeFromArchiveTable().
LocalFile::purgeThumbList | ( | $ | dir, |
$ | files | ||
) | [protected] |
Delete a list of thumbnails visible at urls.
$dir | string base dir of the files. |
$files | array of strings: relative filenames (to $dir) |
Definition at line 805 of file LocalFile.php.
LocalFile::purgeThumbnails | ( | $ | options = array() | ) |
Delete cached transformed files for the current version only.
Definition at line 767 of file LocalFile.php.
LocalFile::readOnlyFatalStatus | ( | ) | [protected] |
Definition at line 1586 of file LocalFile.php.
LocalFile::recordUpload | ( | $ | oldver, |
$ | desc, | ||
$ | license = '' , |
||
$ | copyStatus = '' , |
||
$ | source = '' , |
||
$ | watch = false , |
||
$ | timestamp = false |
||
) |
Record a file upload in the upload log and the image table.
$oldver | |
$desc | string |
$license | string |
$copyStatus | string |
$source | string |
$watch | bool |
$timestamp | string|bool |
Reimplemented in ForeignDBFile.
Definition at line 1005 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.
$oldver | |
$comment | string |
$pageText | string |
$props | bool|array |
$timestamp | bool|string |
$user | null|User |
Definition at line 1031 of file LocalFile.php.
Reset the history pointer to the first element of the history.
Reimplemented from File.
Definition at line 931 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.
$versions | array set of record ids of deleted items to restore, or empty to restore all revisions. |
$unsuppress | Boolean |
Reimplemented from File.
Reimplemented in ForeignDBFile.
Definition at line 1432 of file LocalFile.php.
Save the file metadata to memcached.
Definition at line 234 of file LocalFile.php.
static LocalFile::selectFields | ( | ) | [static] |
Fields in the image table.
Reimplemented in OldLocalFile.
Definition at line 147 of file LocalFile.php.
Referenced by LocalRepo\findBySha1(), LocalRepo\findBySha1s(), 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.
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 470 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 1564 of file LocalFile.php.
Referenced by OldLocalFile\uploadOld().
Roll back the DB transaction and mark the image unlocked.
Definition at line 1577 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 417 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
$srcPath | String: source storage path or virtual URL |
$comment | String: upload description |
$pageText | String: text to use for the new description page, if a new description page is created |
$flags | Integer|bool: flags for publish() |
$props | Array|bool: 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 |
$timestamp | String|bool: timestamp for img_timestamp, or false to use the current time |
$user | User|null: User object or null to use $wgUser |
Definition at line 967 of file LocalFile.php.
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::$fileExists |
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::$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.
LocalRepo LocalFile::$repo |
#@-
Reimplemented from File.
Definition at line 80 of file LocalFile.php.
Referenced by OldLocalFile\__construct(), OldLocalFile\newFromArchiveName(), OldLocalFile\newFromKey(), ForeignDBFile\newFromRow(), OldLocalFile\newFromRow(), ForeignDBFile\newFromTitle(), and OldLocalFile\newFromTitle().
LocalFile::$repoClass = 'LocalRepo' [protected] |
Required Repository class type.
Reimplemented from File.
Definition at line 82 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 |
Definition at line 53 of file LocalFile.php.
Referenced by OldLocalFile\newFromKey(), OldLocalFile\recordOldUpload(), and OldLocalFile\uploadOld().
LocalFile::$upgraded |
Definition at line 53 of file LocalFile.php.
LocalFile::$user |
Definition at line 53 of file LocalFile.php.
Referenced by OldLocalFile\recordOldUpload(), OldLocalFile\uploadOld(), and OldLocalFile\userCan().
LocalFile::$user_text |
Definition at line 53 of file LocalFile.php.
LocalFile::$width |
Definition at line 53 of file LocalFile.php.
const LocalFile::CACHE_FIELD_MAX_LEN = 1000 |
Definition at line 47 of file LocalFile.php.