MediaWiki REL1_31
ArchivedFile.php
Go to the documentation of this file.
1<?php
31 private $id;
32
34 private $name;
35
37 private $group;
38
40 private $key;
41
43 private $size;
44
46 private $bits;
47
49 private $width;
50
52 private $height;
53
55 private $metadata;
56
58 private $mime;
59
61 private $media_type;
62
64 private $description;
65
67 private $user;
68
70 private $timestamp;
71
73 private $dataLoaded;
74
76 private $deleted;
77
79 private $sha1;
80
84 private $pageCount;
85
88
90 protected $handler;
91
93 protected $title; # image title
94
102 function __construct( $title, $id = 0, $key = '', $sha1 = '' ) {
103 $this->id = -1;
104 $this->title = false;
105 $this->name = false;
106 $this->group = 'deleted'; // needed for direct use of constructor
107 $this->key = '';
108 $this->size = 0;
109 $this->bits = 0;
110 $this->width = 0;
111 $this->height = 0;
112 $this->metadata = '';
113 $this->mime = "unknown/unknown";
114 $this->media_type = '';
115 $this->description = '';
116 $this->user = null;
117 $this->timestamp = null;
118 $this->deleted = 0;
119 $this->dataLoaded = false;
120 $this->exists = false;
121 $this->sha1 = '';
122
123 if ( $title instanceof Title ) {
124 $this->title = File::normalizeTitle( $title, 'exception' );
125 $this->name = $title->getDBkey();
126 }
127
128 if ( $id ) {
129 $this->id = $id;
130 }
131
132 if ( $key ) {
133 $this->key = $key;
134 }
135
136 if ( $sha1 ) {
137 $this->sha1 = $sha1;
138 }
139
140 if ( !$id && !$key && !( $title instanceof Title ) && !$sha1 ) {
141 throw new MWException( "No specifications provided to ArchivedFile constructor." );
142 }
143 }
144
150 public function load() {
151 if ( $this->dataLoaded ) {
152 return true;
153 }
154 $conds = [];
155
156 if ( $this->id > 0 ) {
157 $conds['fa_id'] = $this->id;
158 }
159 if ( $this->key ) {
160 $conds['fa_storage_group'] = $this->group;
161 $conds['fa_storage_key'] = $this->key;
162 }
163 if ( $this->title ) {
164 $conds['fa_name'] = $this->title->getDBkey();
165 }
166 if ( $this->sha1 ) {
167 $conds['fa_sha1'] = $this->sha1;
168 }
169
170 if ( !count( $conds ) ) {
171 throw new MWException( "No specific information for retrieving archived file" );
172 }
173
174 if ( !$this->title || $this->title->getNamespace() == NS_FILE ) {
175 $this->dataLoaded = true; // set it here, to have also true on miss
177 $fileQuery = self::getQueryInfo();
178 $row = $dbr->selectRow(
179 $fileQuery['tables'],
180 $fileQuery['fields'],
181 $conds,
182 __METHOD__,
183 [ 'ORDER BY' => 'fa_timestamp DESC' ],
184 $fileQuery['joins']
185 );
186 if ( !$row ) {
187 // this revision does not exist?
188 return null;
189 }
190
191 // initialize fields for filestore image object
192 $this->loadFromRow( $row );
193 } else {
194 throw new MWException( 'This title does not correspond to an image page.' );
195 }
196 $this->exists = true;
197
198 return true;
199 }
200
207 public static function newFromRow( $row ) {
208 $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) );
209 $file->loadFromRow( $row );
210
211 return $file;
212 }
213
219 static function selectFields() {
221
223 // If code is using this instead of self::getQueryInfo(), there's a
224 // decent chance it's going to try to directly access
225 // $row->fa_user or $row->fa_user_text and we can't give it
226 // useful values here once those aren't being written anymore.
227 throw new BadMethodCallException(
228 'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
229 );
230 }
231
232 wfDeprecated( __METHOD__, '1.31' );
233 return [
234 'fa_id',
235 'fa_name',
236 'fa_archive_name',
237 'fa_storage_key',
238 'fa_storage_group',
239 'fa_size',
240 'fa_bits',
241 'fa_width',
242 'fa_height',
243 'fa_metadata',
244 'fa_media_type',
245 'fa_major_mime',
246 'fa_minor_mime',
247 'fa_user',
248 'fa_user_text',
249 'fa_actor' => $wgActorTableSchemaMigrationStage > MIGRATION_OLD ? 'fa_actor' : 'NULL',
250 'fa_timestamp',
251 'fa_deleted',
252 'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
253 'fa_sha1',
254 ] + CommentStore::getStore()->getFields( 'fa_description' );
255 }
256
266 public static function getQueryInfo() {
267 $commentQuery = CommentStore::getStore()->getJoin( 'fa_description' );
268 $actorQuery = ActorMigration::newMigration()->getJoin( 'fa_user' );
269 return [
270 'tables' => [ 'filearchive' ] + $commentQuery['tables'] + $actorQuery['tables'],
271 'fields' => [
272 'fa_id',
273 'fa_name',
274 'fa_archive_name',
275 'fa_storage_key',
276 'fa_storage_group',
277 'fa_size',
278 'fa_bits',
279 'fa_width',
280 'fa_height',
281 'fa_metadata',
282 'fa_media_type',
283 'fa_major_mime',
284 'fa_minor_mime',
285 'fa_timestamp',
286 'fa_deleted',
287 'fa_deleted_timestamp', /* Used by LocalFileRestoreBatch */
288 'fa_sha1',
289 ] + $commentQuery['fields'] + $actorQuery['fields'],
290 'joins' => $commentQuery['joins'] + $actorQuery['joins'],
291 ];
292 }
293
300 public function loadFromRow( $row ) {
301 $this->id = intval( $row->fa_id );
302 $this->name = $row->fa_name;
303 $this->archive_name = $row->fa_archive_name;
304 $this->group = $row->fa_storage_group;
305 $this->key = $row->fa_storage_key;
306 $this->size = $row->fa_size;
307 $this->bits = $row->fa_bits;
308 $this->width = $row->fa_width;
309 $this->height = $row->fa_height;
310 $this->metadata = $row->fa_metadata;
311 $this->mime = "$row->fa_major_mime/$row->fa_minor_mime";
312 $this->media_type = $row->fa_media_type;
313 $this->description = CommentStore::getStore()
314 // Legacy because $row may have come from self::selectFields()
315 ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'fa_description', $row )->text;
316 $this->user = User::newFromAnyId( $row->fa_user, $row->fa_user_text, $row->fa_actor );
317 $this->timestamp = $row->fa_timestamp;
318 $this->deleted = $row->fa_deleted;
319 if ( isset( $row->fa_sha1 ) ) {
320 $this->sha1 = $row->fa_sha1;
321 } else {
322 // old row, populate from key
323 $this->sha1 = LocalRepo::getHashFromKey( $this->key );
324 }
325 if ( !$this->title ) {
326 $this->title = Title::makeTitleSafe( NS_FILE, $row->fa_name );
327 }
328 }
329
335 public function getTitle() {
336 if ( !$this->title ) {
337 $this->load();
338 }
339 return $this->title;
340 }
341
347 public function getName() {
348 if ( $this->name === false ) {
349 $this->load();
350 }
351
352 return $this->name;
353 }
354
358 public function getID() {
359 $this->load();
360
361 return $this->id;
362 }
363
367 public function exists() {
368 $this->load();
369
370 return $this->exists;
371 }
372
377 public function getKey() {
378 $this->load();
379
380 return $this->key;
381 }
382
387 public function getStorageKey() {
388 return $this->getKey();
389 }
390
395 public function getGroup() {
396 return $this->group;
397 }
398
403 public function getWidth() {
404 $this->load();
405
406 return $this->width;
407 }
408
413 public function getHeight() {
414 $this->load();
415
416 return $this->height;
417 }
418
423 public function getMetadata() {
424 $this->load();
425
426 return $this->metadata;
427 }
428
433 public function getSize() {
434 $this->load();
435
436 return $this->size;
437 }
438
443 public function getBits() {
444 $this->load();
445
446 return $this->bits;
447 }
448
453 public function getMimeType() {
454 $this->load();
455
456 return $this->mime;
457 }
458
463 function getHandler() {
464 if ( !isset( $this->handler ) ) {
465 $this->handler = MediaHandler::getHandler( $this->getMimeType() );
466 }
467
468 return $this->handler;
469 }
470
476 function pageCount() {
477 if ( !isset( $this->pageCount ) ) {
478 // @FIXME: callers expect File objects
479 if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
480 $this->pageCount = $this->handler->pageCount( $this );
481 } else {
482 $this->pageCount = false;
483 }
484 }
485
486 return $this->pageCount;
487 }
488
494 public function getMediaType() {
495 $this->load();
496
497 return $this->media_type;
498 }
499
505 public function getTimestamp() {
506 $this->load();
507
508 return wfTimestamp( TS_MW, $this->timestamp );
509 }
510
517 function getSha1() {
518 $this->load();
519
520 return $this->sha1;
521 }
522
534 public function getUser( $type = 'text' ) {
535 $this->load();
536
537 if ( $type === 'object' ) {
538 return $this->user;
539 } elseif ( $type === 'text' ) {
540 return $this->user ? $this->user->getName() : '';
541 } elseif ( $type === 'id' ) {
542 return $this->user ? $this->user->getId() : 0;
543 }
544
545 throw new MWException( "Unknown type '$type'." );
546 }
547
553 public function getDescription() {
554 $this->load();
555 if ( $this->isDeleted( File::DELETED_COMMENT ) ) {
556 return 0;
557 } else {
558 return $this->description;
559 }
560 }
561
567 public function getRawUser() {
568 return $this->getUser( 'id' );
569 }
570
576 public function getRawUserText() {
577 return $this->getUser( 'text' );
578 }
579
585 public function getRawDescription() {
586 $this->load();
587
588 return $this->description;
589 }
590
595 public function getVisibility() {
596 $this->load();
597
598 return $this->deleted;
599 }
600
607 public function isDeleted( $field ) {
608 $this->load();
609
610 return ( $this->deleted & $field ) == $field;
611 }
612
620 public function userCan( $field, User $user = null ) {
621 $this->load();
622
623 $title = $this->getTitle();
624 return Revision::userCanBitfield( $this->deleted, $field, $user, $title ?: null );
625 }
626}
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.
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:53
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2482
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition User.php:657
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition design.txt:26
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:930
> 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! 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! 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:1840
const NS_FILE
Definition Defines.php:80
const MIGRATION_WRITE_BOTH
Definition Defines.php:303
const MIGRATION_OLD
Definition Defines.php:302
const DB_REPLICA
Definition defines.php:25
width