MediaWiki REL1_32
ArchivedFile.php
Go to the documentation of this file.
1<?php
25
33 private $id;
34
36 private $name;
37
39 private $group;
40
42 private $key;
43
45 private $size;
46
48 private $bits;
49
51 private $width;
52
54 private $height;
55
57 private $metadata;
58
60 private $mime;
61
63 private $media_type;
64
66 private $description;
67
69 private $user;
70
72 private $timestamp;
73
75 private $dataLoaded;
76
78 private $deleted;
79
81 private $sha1;
82
86 private $pageCount;
87
90
92 protected $handler;
93
95 protected $title; # image title
96
104 function __construct( $title, $id = 0, $key = '', $sha1 = '' ) {
105 $this->id = -1;
106 $this->title = false;
107 $this->name = false;
108 $this->group = 'deleted'; // needed for direct use of constructor
109 $this->key = '';
110 $this->size = 0;
111 $this->bits = 0;
112 $this->width = 0;
113 $this->height = 0;
114 $this->metadata = '';
115 $this->mime = "unknown/unknown";
116 $this->media_type = '';
117 $this->description = '';
118 $this->user = null;
119 $this->timestamp = null;
120 $this->deleted = 0;
121 $this->dataLoaded = false;
122 $this->exists = false;
123 $this->sha1 = '';
124
125 if ( $title instanceof Title ) {
126 $this->title = File::normalizeTitle( $title, 'exception' );
127 $this->name = $title->getDBkey();
128 }
129
130 if ( $id ) {
131 $this->id = $id;
132 }
133
134 if ( $key ) {
135 $this->key = $key;
136 }
137
138 if ( $sha1 ) {
139 $this->sha1 = $sha1;
140 }
141
142 if ( !$id && !$key && !( $title instanceof Title ) && !$sha1 ) {
143 throw new MWException( "No specifications provided to ArchivedFile constructor." );
144 }
145 }
146
152 public function load() {
153 if ( $this->dataLoaded ) {
154 return true;
155 }
156 $conds = [];
157
158 if ( $this->id > 0 ) {
159 $conds['fa_id'] = $this->id;
160 }
161 if ( $this->key ) {
162 $conds['fa_storage_group'] = $this->group;
163 $conds['fa_storage_key'] = $this->key;
164 }
165 if ( $this->title ) {
166 $conds['fa_name'] = $this->title->getDBkey();
167 }
168 if ( $this->sha1 ) {
169 $conds['fa_sha1'] = $this->sha1;
170 }
171
172 if ( !count( $conds ) ) {
173 throw new MWException( "No specific information for retrieving archived file" );
174 }
175
176 if ( !$this->title || $this->title->getNamespace() == NS_FILE ) {
177 $this->dataLoaded = true; // set it here, to have also true on miss
179 $fileQuery = self::getQueryInfo();
180 $row = $dbr->selectRow(
181 $fileQuery['tables'],
182 $fileQuery['fields'],
183 $conds,
184 __METHOD__,
185 [ 'ORDER BY' => 'fa_timestamp DESC' ],
186 $fileQuery['joins']
187 );
188 if ( !$row ) {
189 // this revision does not exist?
190 return null;
191 }
192
193 // initialize fields for filestore image object
194 $this->loadFromRow( $row );
195 } else {
196 throw new MWException( 'This title does not correspond to an image page.' );
197 }
198 $this->exists = true;
199
200 return true;
201 }
202
209 public static function newFromRow( $row ) {
210 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
211 $file->loadFromRow( $row );
212
213 return $file;
214 }
215
221 static function selectFields() {
223
225 // If code is using this instead of self::getQueryInfo(), there's a
226 // decent chance it's going to try to directly access
227 // $row->fa_user or $row->fa_user_text and we can't give it
228 // useful values here once those aren't being used anymore.
229 throw new BadMethodCallException(
230 'Cannot use ' . __METHOD__
231 . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
232 );
233 }
234
235 wfDeprecated( __METHOD__, '1.31' );
236 return [
237 'fa_id',
238 'fa_name',
239 'fa_archive_name',
240 'fa_storage_key',
241 'fa_storage_group',
242 'fa_size',
243 'fa_bits',
244 'fa_width',
245 'fa_height',
246 'fa_metadata',
247 'fa_media_type',
248 'fa_major_mime',
249 'fa_minor_mime',
250 'fa_user',
251 'fa_user_text',
252 'fa_actor' => 'NULL',
253 'fa_timestamp',
254 'fa_deleted',
255 'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
256 'fa_sha1',
257 ] + MediaWikiServices::getInstance()->getCommentStore()->getFields( 'fa_description' );
258 }
259
269 public static function getQueryInfo() {
270 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin( 'fa_description' );
271 $actorQuery = ActorMigration::newMigration()->getJoin( 'fa_user' );
272 return [
273 'tables' => [ 'filearchive' ] + $commentQuery['tables'] + $actorQuery['tables'],
274 'fields' => [
275 'fa_id',
276 'fa_name',
277 'fa_archive_name',
278 'fa_storage_key',
279 'fa_storage_group',
280 'fa_size',
281 'fa_bits',
282 'fa_width',
283 'fa_height',
284 'fa_metadata',
285 'fa_media_type',
286 'fa_major_mime',
287 'fa_minor_mime',
288 'fa_timestamp',
289 'fa_deleted',
290 'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
291 'fa_sha1',
292 ] + $commentQuery['fields'] + $actorQuery['fields'],
293 'joins' => $commentQuery['joins'] + $actorQuery['joins'],
294 ];
295 }
296
303 public function loadFromRow( $row ) {
304 $this->id = intval( $row->fa_id );
305 $this->name = $row->fa_name;
306 $this->archive_name = $row->fa_archive_name;
307 $this->group = $row->fa_storage_group;
308 $this->key = $row->fa_storage_key;
309 $this->size = $row->fa_size;
310 $this->bits = $row->fa_bits;
311 $this->width = $row->fa_width;
312 $this->height = $row->fa_height;
313 $this->metadata = $row->fa_metadata;
314 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
315 $this->media_type = $row->fa_media_type;
316 $this->description = MediaWikiServices::getInstance()->getCommentStore()
317 // Legacy because $row may have come from self::selectFields()
318 ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'fa_description', $row )->text;
319 $this->user = User::newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
320 $this->timestamp = $row->fa_timestamp;
321 $this->deleted = $row->fa_deleted;
322 if ( isset( $row->fa_sha1 ) ) {
323 $this->sha1 = $row->fa_sha1;
324 } else {
325 // old row, populate from key
326 $this->sha1 = LocalRepo::getHashFromKey( $this->key );
327 }
328 if ( !$this->title ) {
329 $this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name );
330 }
331 }
332
338 public function getTitle() {
339 if ( !$this->title ) {
340 $this->load();
341 }
342 return $this->title;
343 }
344
350 public function getName() {
351 if ( $this->name === false ) {
352 $this->load();
353 }
354
355 return $this->name;
356 }
357
361 public function getID() {
362 $this->load();
363
364 return $this->id;
365 }
366
370 public function exists() {
371 $this->load();
372
373 return $this->exists;
374 }
375
380 public function getKey() {
381 $this->load();
382
383 return $this->key;
384 }
385
390 public function getStorageKey() {
391 return $this->getKey();
392 }
393
398 public function getGroup() {
399 return $this->group;
400 }
401
406 public function getWidth() {
407 $this->load();
408
409 return $this->width;
410 }
411
416 public function getHeight() {
417 $this->load();
418
419 return $this->height;
420 }
421
426 public function getMetadata() {
427 $this->load();
428
429 return $this->metadata;
430 }
431
436 public function getSize() {
437 $this->load();
438
439 return $this->size;
440 }
441
446 public function getBits() {
447 $this->load();
448
449 return $this->bits;
450 }
451
456 public function getMimeType() {
457 $this->load();
458
459 return $this->mime;
460 }
461
466 function getHandler() {
467 if ( !isset( $this->handler ) ) {
468 $this->handler = MediaHandler::getHandler( $this->getMimeType() );
469 }
470
471 return $this->handler;
472 }
473
479 function pageCount() {
480 if ( !isset( $this->pageCount ) ) {
481 // @FIXME: callers expect File objects
482 if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
483 $this->pageCount = $this->handler->pageCount( $this );
484 } else {
485 $this->pageCount = false;
486 }
487 }
488
489 return $this->pageCount;
490 }
491
497 public function getMediaType() {
498 $this->load();
499
500 return $this->media_type;
501 }
502
508 public function getTimestamp() {
509 $this->load();
510
511 return wfTimestamp( TS_MW, $this->timestamp );
512 }
513
520 function getSha1() {
521 $this->load();
522
523 return $this->sha1;
524 }
525
537 public function getUser( $type = 'text' ) {
538 $this->load();
539
540 if ( $type === 'object' ) {
541 return $this->user;
542 } elseif ( $type === 'text' ) {
543 return $this->user ? $this->user->getName() : '';
544 } elseif ( $type === 'id' ) {
545 return $this->user ? $this->user->getId() : 0;
546 }
547
548 throw new MWException( "Unknown type '$type'." );
549 }
550
556 public function getDescription() {
557 $this->load();
558 if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
559 return 0;
560 } else {
561 return $this->description;
562 }
563 }
564
570 public function getRawUser() {
571 return $this->getUser( 'id' );
572 }
573
579 public function getRawUserText() {
580 return $this->getUser( 'text' );
581 }
582
588 public function getRawDescription() {
589 $this->load();
590
591 return $this->description;
592 }
593
598 public function getVisibility() {
599 $this->load();
600
601 return $this->deleted;
602 }
603
610 public function isDeleted( $field ) {
611 $this->load();
612
613 return ( $this->deleted & $field ) == $field;
614 }
615
623 public function userCan( $field, User $user = null ) {
624 $this->load();
625
626 $title = $this->getTitle();
627 return Revision::userCanBitfield( $this->deleted, $field, $user, $title ?: null );
628 }
629}
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
no text was provided for refs named< code > blankwithnoreference</code ></span ></li ></ol ></div > !end !test with< references/> in group !wikitext Wikipedia rocks< ref > Proceeds of vol XXI</ref > Wikipedia rocks< ref group=note > Proceeds of vol XXI</ref >< references/>< references group=note/> ! html< p > Wikipedia rocks< sup id="cite_ref-1" class="reference">< a href="#cite_note-1"> &Wikipedia rocks< sup id="cite_ref-2" class="reference">< a href="#cite_note-2"> &</p >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-1">< span class="mw-cite-backlink">< a href="#cite_ref-1"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-2">< span class="mw-cite-backlink">< a href="#cite_ref-2"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div > !end !test with< references/> in group
Class representing a row of the 'filearchive' table.
getTimestamp()
Return upload timestamp.
User null $user
Uploader.
getSize()
Return the size of the image file, in bytes.
MediaHandler $handler
bool $dataLoaded
Whether or not all this has been loaded from the database (loadFromXxx)
isDeleted( $field)
for file or revision rows
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this FileStore image file,...
getHeight()
Return the height of the image.
int $height
Height.
getBits()
Return the bits of the image file, in bytes.
int $size
File size in bytes.
string $sha1
SHA-1 hash of file content.
string $media_type
Media type.
string $key
FileStore SHA-1 key.
static selectFields()
Fields in the filearchive table.
string $group
FileStore storage group.
string $name
File name.
string $description
Upload description.
getSha1()
Get the SHA-1 base 36 hash of the file.
string $archive_name
Original base filename.
int false $pageCount
Number of pages of a multipage document, or false for documents which aren't multipage documents.
getHandler()
Get a MediaHandler instance for this file.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archivedfile object.
loadFromRow( $row)
Load ArchivedFile object fields from a DB row.
getRawUserText()
Return the user name of the uploader.
string $mime
MIME type.
getDescription()
Return upload description.
int $id
Filearchive row ID.
getRawUser()
Return the user ID of the uploader.
__construct( $title, $id=0, $key='', $sha1='')
load()
Loads a file object from the filearchive table.
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
getGroup()
Return the FileStore storage group.
static newFromRow( $row)
Loads a file object from the filearchive table.
getTitle()
Return the associated title object.
getWidth()
Return the width of the image.
int $deleted
Bitfield akin to rev_deleted.
getStorageKey()
Return the FileStore key (overriding base File class)
getMimeType()
Returns the MIME type of the file.
getUser( $type='text')
Returns ID or name of user who uploaded the file.
getKey()
Return the FileStore key.
string $metadata
Metadata string.
string $timestamp
Time of upload.
getName()
Return the file name.
int $bits
Size in bytes.
getMediaType()
Return the type of the media in the file.
getRawDescription()
Return upload description.
getVisibility()
Returns the deletion bitfield.
getMetadata()
Get handler-specific metadata.
int $width
Width.
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
Definition File.php:184
const DELETED_COMMENT
Definition File.php:54
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
MediaWiki exception.
Base media handler class.
static getHandler( $type)
Get a MediaHandler for a given MIME type from the instance cache.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2462
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition User.php:682
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
Definition hooks.txt:2214
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition hooks.txt:960
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED since 1.16! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Definition hooks.txt:1889
const SCHEMA_COMPAT_READ_NEW
Definition Defines.php:287
const NS_FILE
Definition Defines.php:70
const DB_REPLICA
Definition defines.php:25
width