FU r102073:
[lhc/web/wiklou.git] / includes / filerepo / File.php
1 <?php
2 /**
3 * Base code for files.
4 *
5 * @file
6 * @ingroup FileRepo
7 */
8
9 /**
10 * Implements some public methods and some protected utility functions which
11 * are required by multiple child classes. Contains stub functionality for
12 * unimplemented public methods.
13 *
14 * Stub functions which should be overridden are marked with STUB. Some more
15 * concrete functions are also typically overridden by child classes.
16 *
17 * Note that only the repo object knows what its file class is called. You should
18 * never name a file class explictly outside of the repo class. Instead use the
19 * repo's factory functions to generate file objects, for example:
20 *
21 * RepoGroup::singleton()->getLocalRepo()->newFile($title);
22 *
23 * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
24 * in most cases.
25 *
26 * @ingroup FileRepo
27 */
28 abstract class File {
29 const DELETED_FILE = 1;
30 const DELETED_COMMENT = 2;
31 const DELETED_USER = 4;
32 const DELETED_RESTRICTED = 8;
33
34 /** Force rendering in the current process */
35 const RENDER_NOW = 1;
36 /**
37 * Force rendering even if thumbnail already exist and using RENDER_NOW
38 * I.e. you have to pass both flags: File::RENDER_NOW | File::RENDER_FORCE
39 */
40 const RENDER_FORCE = 2;
41
42 const DELETE_SOURCE = 1;
43
44 /**
45 * Some member variables can be lazy-initialised using __get(). The
46 * initialisation function for these variables is always a function named
47 * like getVar(), where Var is the variable name with upper-case first
48 * letter.
49 *
50 * The following variables are initialised in this way in this base class:
51 * name, extension, handler, path, canRender, isSafeFile,
52 * transformScript, hashPath, pageCount, url
53 *
54 * Code within this class should generally use the accessor function
55 * directly, since __get() isn't re-entrant and therefore causes bugs that
56 * depend on initialisation order.
57 */
58
59 /**
60 * The following member variables are not lazy-initialised
61 */
62
63 /**
64 * @var FileRepo|false
65 */
66 var $repo;
67
68 /**
69 * @var Title|false
70 */
71 var $title;
72
73 var $lastError, $redirected, $redirectedTitle;
74
75 /**
76 * @var MediaHandler
77 */
78 protected $handler;
79
80 protected $url, $extension, $name, $path, $hashPath, $pageCount, $transformScript;
81
82 /**
83 * @var bool
84 */
85 protected $canRender, $isSafeFile;
86
87 /**
88 * @var string Required Repository class type
89 */
90 protected $repoClass = 'FileRepo';
91
92 /**
93 * Call this constructor from child classes.
94 *
95 * Both $title and $repo are optional, though some functions
96 * may return false or throw exceptions if they are not set.
97 * Most subclasses will want to call assertRepoDefined() here.
98 *
99 * @param $title Title|string|false
100 * @param $repo FileRepo|false
101 */
102 function __construct( $title, $repo ) {
103 if ( $title !== false ) { // subclasses may not use MW titles
104 $title = self::normalizeTitle( $title, 'exception' );
105 }
106 $this->title = $title;
107 $this->repo = $repo;
108 }
109
110 /**
111 * Given a string or Title object return either a
112 * valid Title object with namespace NS_FILE or null
113 * @param $title Title|string
114 * @param $exception string|false Use 'exception' to throw an error on bad titles
115 * @return Title|null
116 */
117 static function normalizeTitle( $title, $exception = false ) {
118 $ret = $title;
119 if ( $ret instanceof Title ) {
120 # Normalize NS_MEDIA -> NS_FILE
121 if ( $ret->getNamespace() == NS_MEDIA ) {
122 $ret = Title::makeTitleSafe( NS_FILE, $ret->getDBkey() );
123 # Sanity check the title namespace
124 } elseif ( $ret->getNamespace() !== NS_FILE ) {
125 $ret = null;
126 }
127 } else {
128 # Convert strings to Title objects
129 $ret = Title::makeTitleSafe( NS_FILE, (string)$ret );
130 }
131 if ( !$ret && $exception !== false ) {
132 throw new MWException( "`$title` is not a valid file title." );
133 }
134 return $ret;
135 }
136
137 function __get( $name ) {
138 $function = array( $this, 'get' . ucfirst( $name ) );
139 if ( !is_callable( $function ) ) {
140 return null;
141 } else {
142 $this->$name = call_user_func( $function );
143 return $this->$name;
144 }
145 }
146
147 /**
148 * Normalize a file extension to the common form, and ensure it's clean.
149 * Extensions with non-alphanumeric characters will be discarded.
150 *
151 * @param $ext string (without the .)
152 * @return string
153 */
154 static function normalizeExtension( $ext ) {
155 $lower = strtolower( $ext );
156 $squish = array(
157 'htm' => 'html',
158 'jpeg' => 'jpg',
159 'mpeg' => 'mpg',
160 'tiff' => 'tif',
161 'ogv' => 'ogg' );
162 if( isset( $squish[$lower] ) ) {
163 return $squish[$lower];
164 } elseif( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
165 return $lower;
166 } else {
167 return '';
168 }
169 }
170
171 /**
172 * Checks if file extensions are compatible
173 *
174 * @param $old File Old file
175 * @param $new string New name
176 *
177 * @return bool|null
178 */
179 static function checkExtensionCompatibility( File $old, $new ) {
180 $oldMime = $old->getMimeType();
181 $n = strrpos( $new, '.' );
182 $newExt = self::normalizeExtension(
183 $n ? substr( $new, $n + 1 ) : '' );
184 $mimeMagic = MimeMagic::singleton();
185 return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
186 }
187
188 /**
189 * Upgrade the database row if there is one
190 * Called by ImagePage
191 * STUB
192 */
193 function upgradeRow() {}
194
195 /**
196 * Split an internet media type into its two components; if not
197 * a two-part name, set the minor type to 'unknown'.
198 *
199 * @param string $mime "text/html" etc
200 * @return array ("text", "html") etc
201 */
202 public static function splitMime( $mime ) {
203 if( strpos( $mime, '/' ) !== false ) {
204 return explode( '/', $mime, 2 );
205 } else {
206 return array( $mime, 'unknown' );
207 }
208 }
209
210 /**
211 * Return the name of this file
212 *
213 * @return string
214 */
215 public function getName() {
216 if ( !isset( $this->name ) ) {
217 $this->assertRepoDefined();
218 $this->name = $this->repo->getNameFromTitle( $this->title );
219 }
220 return $this->name;
221 }
222
223 /**
224 * Get the file extension, e.g. "svg"
225 *
226 * @return string
227 */
228 function getExtension() {
229 if ( !isset( $this->extension ) ) {
230 $n = strrpos( $this->getName(), '.' );
231 $this->extension = self::normalizeExtension(
232 $n ? substr( $this->getName(), $n + 1 ) : '' );
233 }
234 return $this->extension;
235 }
236
237 /**
238 * Return the associated title object
239 * @return Title|false
240 */
241 public function getTitle() { return $this->title; }
242
243 /**
244 * Return the title used to find this file
245 *
246 * @return Title
247 */
248 public function getOriginalTitle() {
249 if ( $this->redirected ) {
250 return $this->getRedirectedTitle();
251 }
252 return $this->title;
253 }
254
255 /**
256 * Return the URL of the file
257 *
258 * @return string
259 */
260 public function getUrl() {
261 if ( !isset( $this->url ) ) {
262 $this->assertRepoDefined();
263 $this->url = $this->repo->getZoneUrl( 'public' ) . '/' . $this->getUrlRel();
264 }
265 return $this->url;
266 }
267
268 /**
269 * Return a fully-qualified URL to the file.
270 * Upload URL paths _may or may not_ be fully qualified, so
271 * we check. Local paths are assumed to belong on $wgServer.
272 *
273 * @return String
274 */
275 public function getFullUrl() {
276 return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE );
277 }
278
279 /**
280 * @return string
281 */
282 public function getCanonicalUrl() {
283 return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL );
284 }
285
286 /**
287 * @return string
288 */
289 function getViewURL() {
290 if( $this->mustRender()) {
291 if( $this->canRender() ) {
292 return $this->createThumb( $this->getWidth() );
293 } else {
294 wfDebug(__METHOD__.': supposed to render '.$this->getName().' ('.$this->getMimeType()."), but can't!\n");
295 return $this->getURL(); #hm... return NULL?
296 }
297 } else {
298 return $this->getURL();
299 }
300 }
301
302 /**
303 * Return the full filesystem path to the file. Note that this does
304 * not mean that a file actually exists under that location.
305 *
306 * This path depends on whether directory hashing is active or not,
307 * i.e. whether the files are all found in the same directory,
308 * or in hashed paths like /images/3/3c.
309 *
310 * Most callers don't check the return value, but ForeignAPIFile::getPath
311 * returns false.
312 *
313 * @return string|false
314 */
315 public function getPath() {
316 if ( !isset( $this->path ) ) {
317 $this->assertRepoDefined();
318 $this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel();
319 }
320 return $this->path;
321 }
322
323 /**
324 * Return the width of the image. Returns false if the width is unknown
325 * or undefined.
326 *
327 * STUB
328 * Overridden by LocalFile, UnregisteredLocalFile
329 *
330 * @param $page int
331 *
332 * @return number
333 */
334 public function getWidth( $page = 1 ) {
335 return false;
336 }
337
338 /**
339 * Return the height of the image. Returns false if the height is unknown
340 * or undefined
341 *
342 * STUB
343 * Overridden by LocalFile, UnregisteredLocalFile
344 *
345 * @param $page int
346 *
347 * @return false|number
348 */
349 public function getHeight( $page = 1 ) {
350 return false;
351 }
352
353 /**
354 * Returns ID or name of user who uploaded the file
355 * STUB
356 *
357 * @param $type string 'text' or 'id'
358 *
359 * @return string|int
360 */
361 public function getUser( $type = 'text' ) {
362 return null;
363 }
364
365 /**
366 * Get the duration of a media file in seconds
367 *
368 * @return number
369 */
370 public function getLength() {
371 $handler = $this->getHandler();
372 if ( $handler ) {
373 return $handler->getLength( $this );
374 } else {
375 return 0;
376 }
377 }
378
379 /**
380 * Return true if the file is vectorized
381 *
382 * @return bool
383 */
384 public function isVectorized() {
385 $handler = $this->getHandler();
386 if ( $handler ) {
387 return $handler->isVectorized( $this );
388 } else {
389 return false;
390 }
391 }
392
393 /**
394 * Get handler-specific metadata
395 * Overridden by LocalFile, UnregisteredLocalFile
396 * STUB
397 */
398 public function getMetadata() {
399 return false;
400 }
401
402 /**
403 * get versioned metadata
404 *
405 * @param $metadata Mixed Array or String of (serialized) metadata
406 * @param $version integer version number.
407 * @return Array containing metadata, or what was passed to it on fail (unserializing if not array)
408 */
409 public function convertMetadataVersion($metadata, $version) {
410 $handler = $this->getHandler();
411 if ( !is_array( $metadata ) ) {
412 //just to make the return type consistant
413 $metadata = unserialize( $metadata );
414 }
415 if ( $handler ) {
416 return $handler->convertMetadataVersion( $metadata, $version );
417 } else {
418 return $metadata;
419 }
420 }
421
422 /**
423 * Return the bit depth of the file
424 * Overridden by LocalFile
425 * STUB
426 */
427 public function getBitDepth() {
428 return 0;
429 }
430
431 /**
432 * Return the size of the image file, in bytes
433 * Overridden by LocalFile, UnregisteredLocalFile
434 * STUB
435 */
436 public function getSize() {
437 return false;
438 }
439
440 /**
441 * Returns the mime type of the file.
442 * Overridden by LocalFile, UnregisteredLocalFile
443 * STUB
444 *
445 * @return string
446 */
447 function getMimeType() {
448 return 'unknown/unknown';
449 }
450
451 /**
452 * Return the type of the media in the file.
453 * Use the value returned by this function with the MEDIATYPE_xxx constants.
454 * Overridden by LocalFile,
455 * STUB
456 */
457 function getMediaType() { return MEDIATYPE_UNKNOWN; }
458
459 /**
460 * Checks if the output of transform() for this file is likely
461 * to be valid. If this is false, various user elements will
462 * display a placeholder instead.
463 *
464 * Currently, this checks if the file is an image format
465 * that can be converted to a format
466 * supported by all browsers (namely GIF, PNG and JPEG),
467 * or if it is an SVG image and SVG conversion is enabled.
468 *
469 * @return bool
470 */
471 function canRender() {
472 if ( !isset( $this->canRender ) ) {
473 $this->canRender = $this->getHandler() && $this->handler->canRender( $this );
474 }
475 return $this->canRender;
476 }
477
478 /**
479 * Accessor for __get()
480 */
481 protected function getCanRender() {
482 return $this->canRender();
483 }
484
485 /**
486 * Return true if the file is of a type that can't be directly
487 * rendered by typical browsers and needs to be re-rasterized.
488 *
489 * This returns true for everything but the bitmap types
490 * supported by all browsers, i.e. JPEG; GIF and PNG. It will
491 * also return true for any non-image formats.
492 *
493 * @return bool
494 */
495 function mustRender() {
496 return $this->getHandler() && $this->handler->mustRender( $this );
497 }
498
499 /**
500 * Alias for canRender()
501 *
502 * @return bool
503 */
504 function allowInlineDisplay() {
505 return $this->canRender();
506 }
507
508 /**
509 * Determines if this media file is in a format that is unlikely to
510 * contain viruses or malicious content. It uses the global
511 * $wgTrustedMediaFormats list to determine if the file is safe.
512 *
513 * This is used to show a warning on the description page of non-safe files.
514 * It may also be used to disallow direct [[media:...]] links to such files.
515 *
516 * Note that this function will always return true if allowInlineDisplay()
517 * or isTrustedFile() is true for this file.
518 *
519 * @return bool
520 */
521 function isSafeFile() {
522 if ( !isset( $this->isSafeFile ) ) {
523 $this->isSafeFile = $this->_getIsSafeFile();
524 }
525 return $this->isSafeFile;
526 }
527
528 /**
529 * Accessor for __get()
530 *
531 * @return bool
532 */
533 protected function getIsSafeFile() {
534 return $this->isSafeFile();
535 }
536
537 /**
538 * Uncached accessor
539 *
540 * @return bool
541 */
542 protected function _getIsSafeFile() {
543 if ( $this->allowInlineDisplay() ) {
544 return true;
545 }
546 if ($this->isTrustedFile()) {
547 return true;
548 }
549
550 global $wgTrustedMediaFormats;
551
552 $type = $this->getMediaType();
553 $mime = $this->getMimeType();
554 #wfDebug("LocalFile::isSafeFile: type= $type, mime= $mime\n");
555
556 if ( !$type || $type === MEDIATYPE_UNKNOWN ) {
557 return false; #unknown type, not trusted
558 }
559 if ( in_array( $type, $wgTrustedMediaFormats ) ) {
560 return true;
561 }
562
563 if ( $mime === "unknown/unknown" ) {
564 return false; #unknown type, not trusted
565 }
566 if ( in_array( $mime, $wgTrustedMediaFormats) ) {
567 return true;
568 }
569
570 return false;
571 }
572
573 /**
574 * Returns true if the file is flagged as trusted. Files flagged that way
575 * can be linked to directly, even if that is not allowed for this type of
576 * file normally.
577 *
578 * This is a dummy function right now and always returns false. It could be
579 * implemented to extract a flag from the database. The trusted flag could be
580 * set on upload, if the user has sufficient privileges, to bypass script-
581 * and html-filters. It may even be coupled with cryptographics signatures
582 * or such.
583 *
584 * @return bool
585 */
586 function isTrustedFile() {
587 #this could be implemented to check a flag in the databas,
588 #look for signatures, etc
589 return false;
590 }
591
592 /**
593 * Returns true if file exists in the repository.
594 *
595 * Overridden by LocalFile to avoid unnecessary stat calls.
596 *
597 * @return boolean Whether file exists in the repository.
598 */
599 public function exists() {
600 return $this->getPath() && file_exists( $this->path );
601 }
602
603 /**
604 * Returns true if file exists in the repository and can be included in a page.
605 * It would be unsafe to include private images, making public thumbnails inadvertently
606 *
607 * @return boolean Whether file exists in the repository and is includable.
608 */
609 public function isVisible() {
610 return $this->exists();
611 }
612
613 /**
614 * @return string
615 */
616 function getTransformScript() {
617 if ( !isset( $this->transformScript ) ) {
618 $this->transformScript = false;
619 if ( $this->repo ) {
620 $script = $this->repo->getThumbScriptUrl();
621 if ( $script ) {
622 $this->transformScript = "$script?f=" . urlencode( $this->getName() );
623 }
624 }
625 }
626 return $this->transformScript;
627 }
628
629 /**
630 * Get a ThumbnailImage which is the same size as the source
631 *
632 * @param $handlerParams array
633 *
634 * @return string
635 */
636 function getUnscaledThumb( $handlerParams = array() ) {
637 $hp =& $handlerParams;
638 $page = isset( $hp['page'] ) ? $hp['page'] : false;
639 $width = $this->getWidth( $page );
640 if ( !$width ) {
641 return $this->iconThumb();
642 }
643 $hp['width'] = $width;
644 return $this->transform( $hp );
645 }
646
647 /**
648 * Return the file name of a thumbnail with the specified parameters
649 *
650 * @param $params Array: handler-specific parameters
651 * @private -ish
652 *
653 * @return string
654 */
655 function thumbName( $params ) {
656 return $this->generateThumbName( $this->getName(), $params );
657 }
658
659 /**
660 * Generate a thumbnail file name from a name and specified parameters
661 *
662 * @param string $name
663 * @param array $params Parameters which will be passed to MediaHandler::makeParamString
664 *
665 * @return string
666 */
667 function generateThumbName( $name, $params ) {
668 if ( !$this->getHandler() ) {
669 return null;
670 }
671 $extension = $this->getExtension();
672 list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params );
673 $thumbName = $this->handler->makeParamString( $params ) . '-' . $name;
674 if ( $thumbExt != $extension ) {
675 $thumbName .= ".$thumbExt";
676 }
677 return $thumbName;
678 }
679
680 /**
681 * Create a thumbnail of the image having the specified width/height.
682 * The thumbnail will not be created if the width is larger than the
683 * image's width. Let the browser do the scaling in this case.
684 * The thumbnail is stored on disk and is only computed if the thumbnail
685 * file does not exist OR if it is older than the image.
686 * Returns the URL.
687 *
688 * Keeps aspect ratio of original image. If both width and height are
689 * specified, the generated image will be no bigger than width x height,
690 * and will also have correct aspect ratio.
691 *
692 * @param $width Integer: maximum width of the generated thumbnail
693 * @param $height Integer: maximum height of the image (optional)
694 *
695 * @return string
696 */
697 public function createThumb( $width, $height = -1 ) {
698 $params = array( 'width' => $width );
699 if ( $height != -1 ) {
700 $params['height'] = $height;
701 }
702 $thumb = $this->transform( $params );
703 if( is_null( $thumb ) || $thumb->isError() ) return '';
704 return $thumb->getUrl();
705 }
706
707 /**
708 * Do the work of a transform (from an original into a thumb).
709 * Contains filesystem-specific functions.
710 *
711 * @param $thumbName string: the name of the thumbnail file.
712 * @param $thumbUrl string: the URL of the thumbnail file.
713 * @param $params Array: an associative array of handler-specific parameters.
714 * Typical keys are width, height and page.
715 * @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
716 *
717 * @return MediaTransformOutput | false
718 */
719 protected function maybeDoTransform( $thumbName, $thumbUrl, $params, $flags = 0 ) {
720 global $wgIgnoreImageErrors, $wgThumbnailEpoch;
721
722 $thumbPath = $this->getThumbPath( $thumbName );
723 if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) {
724 wfDebug( __METHOD__ . " transformation deferred." );
725 return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
726 }
727
728 wfDebug( __METHOD__.": Doing stat for $thumbPath\n" );
729 $this->migrateThumbFile( $thumbName );
730 if ( file_exists( $thumbPath ) && !($flags & self::RENDER_FORCE) ) {
731 $thumbTime = filemtime( $thumbPath );
732 if ( $thumbTime !== FALSE &&
733 gmdate( 'YmdHis', $thumbTime ) >= $wgThumbnailEpoch ) {
734
735 return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
736 }
737 } elseif( $flags & self::RENDER_FORCE ) {
738 wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
739 }
740 $thumb = $this->handler->doTransform( $this, $thumbPath, $thumbUrl, $params );
741
742 // Ignore errors if requested
743 if ( !$thumb ) {
744 $thumb = null;
745 } elseif ( $thumb->isError() ) {
746 $this->lastError = $thumb->toText();
747 if ( $wgIgnoreImageErrors && !($flags & self::RENDER_NOW) ) {
748 $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
749 }
750 }
751
752 return $thumb;
753 }
754
755
756 /**
757 * Transform a media file
758 *
759 * @param $params Array: an associative array of handler-specific parameters.
760 * Typical keys are width, height and page.
761 * @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering
762 * @return MediaTransformOutput | false
763 */
764 function transform( $params, $flags = 0 ) {
765 global $wgUseSquid;
766
767 wfProfileIn( __METHOD__ );
768 do {
769 if ( !$this->canRender() ) {
770 // not a bitmap or renderable image, don't try.
771 $thumb = $this->iconThumb();
772 break;
773 }
774
775 // Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
776 $descriptionUrl = $this->getDescriptionUrl();
777 if ( $descriptionUrl ) {
778 $params['descriptionUrl'] = wfExpandUrl( $descriptionUrl, PROTO_CANONICAL );
779 }
780
781 $script = $this->getTransformScript();
782 if ( $script && !($flags & self::RENDER_NOW) ) {
783 // Use a script to transform on client request, if possible
784 $thumb = $this->handler->getScriptedTransform( $this, $script, $params );
785 if( $thumb ) {
786 break;
787 }
788 }
789
790 $normalisedParams = $params;
791 $this->handler->normaliseParams( $this, $normalisedParams );
792 $thumbName = $this->thumbName( $normalisedParams );
793 $thumbUrl = $this->getThumbUrl( $thumbName );
794
795 $thumb = $this->maybeDoTransform( $thumbName, $thumbUrl, $params, $flags );
796
797 // Purge. Useful in the event of Core -> Squid connection failure or squid
798 // purge collisions from elsewhere during failure. Don't keep triggering for
799 // "thumbs" which have the main image URL though (bug 13776)
800 if ( $wgUseSquid && ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL()) ) {
801 SquidUpdate::purge( array( $thumbUrl ) );
802 }
803 } while (false);
804
805 wfProfileOut( __METHOD__ );
806 return is_object( $thumb ) ? $thumb : false;
807 }
808
809 /**
810 * Hook into transform() to allow migration of thumbnail files
811 * STUB
812 * Overridden by LocalFile
813 */
814 function migrateThumbFile( $thumbName ) {}
815
816 /**
817 * Get a MediaHandler instance for this file
818 * @return MediaHandler
819 */
820 function getHandler() {
821 if ( !isset( $this->handler ) ) {
822 $this->handler = MediaHandler::getHandler( $this->getMimeType() );
823 }
824 return $this->handler;
825 }
826
827 /**
828 * Get a ThumbnailImage representing a file type icon
829 * @return ThumbnailImage
830 */
831 function iconThumb() {
832 global $wgStylePath, $wgStyleDirectory;
833
834 $try = array( 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' );
835 foreach( $try as $icon ) {
836 $path = '/common/images/icons/' . $icon;
837 $filepath = $wgStyleDirectory . $path;
838 if( file_exists( $filepath ) ) {
839 return new ThumbnailImage( $this, $wgStylePath . $path, 120, 120 );
840 }
841 }
842 return null;
843 }
844
845 /**
846 * Get last thumbnailing error.
847 * Largely obsolete.
848 */
849 function getLastError() {
850 return $this->lastError;
851 }
852
853 /**
854 * Get all thumbnail names previously generated for this file
855 * STUB
856 * Overridden by LocalFile
857 */
858 function getThumbnails() {
859 return array();
860 }
861
862 /**
863 * Purge shared caches such as thumbnails and DB data caching
864 * STUB
865 * Overridden by LocalFile
866 */
867 function purgeCache() {}
868
869 /**
870 * Purge the file description page, but don't go after
871 * pages using the file. Use when modifying file history
872 * but not the current data.
873 */
874 function purgeDescription() {
875 $title = $this->getTitle();
876 if ( $title ) {
877 $title->invalidateCache();
878 $title->purgeSquid();
879 }
880 }
881
882 /**
883 * Purge metadata and all affected pages when the file is created,
884 * deleted, or majorly updated.
885 */
886 function purgeEverything() {
887 // Delete thumbnails and refresh file metadata cache
888 $this->purgeCache();
889 $this->purgeDescription();
890
891 // Purge cache of all pages using this file
892 $title = $this->getTitle();
893 if ( $title ) {
894 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
895 $update->doUpdate();
896 }
897 }
898
899 /**
900 * Return a fragment of the history of file.
901 *
902 * STUB
903 * @param $limit integer Limit of rows to return
904 * @param $start timestamp Only revisions older than $start will be returned
905 * @param $end timestamp Only revisions newer than $end will be returned
906 * @param $inc bool Include the endpoints of the time range
907 *
908 * @return array
909 */
910 function getHistory($limit = null, $start = null, $end = null, $inc=true) {
911 return array();
912 }
913
914 /**
915 * Return the history of this file, line by line. Starts with current version,
916 * then old versions. Should return an object similar to an image/oldimage
917 * database row.
918 *
919 * STUB
920 * Overridden in LocalFile
921 */
922 public function nextHistoryLine() {
923 return false;
924 }
925
926 /**
927 * Reset the history pointer to the first element of the history.
928 * Always call this function after using nextHistoryLine() to free db resources
929 * STUB
930 * Overridden in LocalFile.
931 */
932 public function resetHistory() {}
933
934 /**
935 * Get the filename hash component of the directory including trailing slash,
936 * e.g. f/fa/
937 * If the repository is not hashed, returns an empty string.
938 *
939 * @return string
940 */
941 function getHashPath() {
942 if ( !isset( $this->hashPath ) ) {
943 $this->assertRepoDefined();
944 $this->hashPath = $this->repo->getHashPath( $this->getName() );
945 }
946 return $this->hashPath;
947 }
948
949 /**
950 * Get the path of the file relative to the public zone root
951 *
952 * @return string
953 */
954 function getRel() {
955 return $this->getHashPath() . $this->getName();
956 }
957
958 /**
959 * Get urlencoded relative path of the file
960 *
961 * @return string
962 */
963 function getUrlRel() {
964 return $this->getHashPath() . rawurlencode( $this->getName() );
965 }
966
967 /**
968 * Get the relative path for an archived file
969 *
970 * @param $suffix bool|string if not false, the name of an archived thumbnail file
971 *
972 * @return string
973 */
974 function getArchiveRel( $suffix = false ) {
975 $path = 'archive/' . $this->getHashPath();
976 if ( $suffix === false ) {
977 $path = substr( $path, 0, -1 );
978 } else {
979 $path .= $suffix;
980 }
981 return $path;
982 }
983
984 /**
985 * Get the relative path for an archived file's thumbs directory
986 * or a specific thumb if the $suffix is given.
987 *
988 * @param $archiveName string the timestamped name of an archived image
989 * @param $suffix bool|string if not false, the name of a thumbnail file
990 *
991 * @return string
992 */
993 function getArchiveThumbRel( $archiveName, $suffix = false ) {
994 $path = 'archive/' . $this->getHashPath() . $archiveName . "/";
995 if ( $suffix === false ) {
996 $path = substr( $path, 0, -1 );
997 } else {
998 $path .= $suffix;
999 }
1000 return $path;
1001 }
1002
1003 /**
1004 * Get the path of the archived file.
1005 *
1006 * @param $suffix bool|string if not false, the name of an archived file.
1007 *
1008 * @return string
1009 */
1010 function getArchivePath( $suffix = false ) {
1011 $this->assertRepoDefined();
1012 return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
1013 }
1014
1015 /**
1016 * Get the path of the archived file's thumbs, or a particular thumb if $suffix is specified
1017 *
1018 * @param $archiveName string the timestamped name of an archived image
1019 * @param $suffix bool|string if not false, the name of a thumbnail file
1020 *
1021 * @return string
1022 */
1023 function getArchiveThumbPath( $archiveName, $suffix = false ) {
1024 $this->assertRepoDefined();
1025 return $this->repo->getZonePath( 'thumb' ) . '/' .
1026 $this->getArchiveThumbRel( $archiveName, $suffix );
1027 }
1028
1029 /**
1030 * Get the path of the thumbnail directory, or a particular file if $suffix is specified
1031 *
1032 * @param $suffix bool|string if not false, the name of a thumbnail file
1033 *
1034 * @return string
1035 */
1036 function getThumbPath( $suffix = false ) {
1037 $this->assertRepoDefined();
1038 $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getRel();
1039 if ( $suffix !== false ) {
1040 $path .= '/' . $suffix;
1041 }
1042 return $path;
1043 }
1044
1045 /**
1046 * Get the URL of the archive directory, or a particular file if $suffix is specified
1047 *
1048 * @param $suffix bool|string if not false, the name of an archived file
1049 *
1050 * @return string
1051 */
1052 function getArchiveUrl( $suffix = false ) {
1053 $this->assertRepoDefined();
1054 $path = $this->repo->getZoneUrl( 'public' ) . '/archive/' . $this->getHashPath();
1055 if ( $suffix === false ) {
1056 $path = substr( $path, 0, -1 );
1057 } else {
1058 $path .= rawurlencode( $suffix );
1059 }
1060 return $path;
1061 }
1062
1063 /**
1064 * Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified
1065 *
1066 * @param $archiveName string the timestamped name of an archived image
1067 * @param $suffix bool|string if not false, the name of a thumbnail file
1068 *
1069 * @return string
1070 */
1071 function getArchiveThumbUrl( $archiveName, $suffix = false ) {
1072 $this->assertRepoDefined();
1073 $path = $this->repo->getZoneUrl( 'thumb' ) . '/archive/' .
1074 $this->getHashPath() . rawurlencode( $archiveName ) . "/";
1075 if ( $suffix === false ) {
1076 $path = substr( $path, 0, -1 );
1077 } else {
1078 $path .= rawurlencode( $suffix );
1079 }
1080 return $path;
1081 }
1082
1083 /**
1084 * Get the URL of the thumbnail directory, or a particular file if $suffix is specified
1085 *
1086 * @param $suffix bool|string if not false, the name of a thumbnail file
1087 *
1088 * @return path
1089 */
1090 function getThumbUrl( $suffix = false ) {
1091 $this->assertRepoDefined();
1092 $path = $this->repo->getZoneUrl('thumb') . '/' . $this->getUrlRel();
1093 if ( $suffix !== false ) {
1094 $path .= '/' . rawurlencode( $suffix );
1095 }
1096 return $path;
1097 }
1098
1099 /**
1100 * Get the virtual URL for an archived file's thumbs, or a specific thumb.
1101 *
1102 * @param $suffix bool|string if not false, the name of a thumbnail file
1103 *
1104 * @return string
1105 */
1106 function getArchiveVirtualUrl( $suffix = false ) {
1107 $this->assertRepoDefined();
1108 $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
1109 if ( $suffix === false ) {
1110 $path = substr( $path, 0, -1 );
1111 } else {
1112 $path .= rawurlencode( $suffix );
1113 }
1114 return $path;
1115 }
1116
1117 /**
1118 * Get the virtual URL for a thumbnail file or directory
1119 *
1120 * @param $suffix bool|string if not false, the name of a thumbnail file
1121 *
1122 * @return string
1123 */
1124 function getThumbVirtualUrl( $suffix = false ) {
1125 $this->assertRepoDefined();
1126 $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
1127 if ( $suffix !== false ) {
1128 $path .= '/' . rawurlencode( $suffix );
1129 }
1130 return $path;
1131 }
1132
1133 /**
1134 * Get the virtual URL for the file itself
1135 *
1136 * @param $suffix bool|string if not false, the name of a thumbnail file
1137 *
1138 * @return string
1139 */
1140 function getVirtualUrl( $suffix = false ) {
1141 $this->assertRepoDefined();
1142 $path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
1143 if ( $suffix !== false ) {
1144 $path .= '/' . rawurlencode( $suffix );
1145 }
1146 return $path;
1147 }
1148
1149 /**
1150 * @return bool
1151 */
1152 function isHashed() {
1153 $this->assertRepoDefined();
1154 return $this->repo->isHashed();
1155 }
1156
1157 /**
1158 * @throws MWException
1159 */
1160 function readOnlyError() {
1161 throw new MWException( get_class($this) . ': write operations are not supported' );
1162 }
1163
1164 /**
1165 * Record a file upload in the upload log and the image table
1166 * STUB
1167 * Overridden by LocalFile
1168 * @param $oldver
1169 * @param $desc
1170 * @param $license string
1171 * @param $copyStatus string
1172 * @param $source string
1173 * @param $watch bool
1174 */
1175 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false ) {
1176 $this->readOnlyError();
1177 }
1178
1179 /**
1180 * Move or copy a file to its public location. If a file exists at the
1181 * destination, move it to an archive. Returns a FileRepoStatus object with
1182 * the archive name in the "value" member on success.
1183 *
1184 * The archive name should be passed through to recordUpload for database
1185 * registration.
1186 *
1187 * @param $srcPath String: local filesystem path to the source image
1188 * @param $flags Integer: a bitwise combination of:
1189 * File::DELETE_SOURCE Delete the source file, i.e. move
1190 * rather than copy
1191 * @return FileRepoStatus object. On success, the value member contains the
1192 * archive name, or an empty string if it was a new file.
1193 *
1194 * STUB
1195 * Overridden by LocalFile
1196 */
1197 function publish( $srcPath, $flags = 0 ) {
1198 $this->readOnlyError();
1199 }
1200
1201 /**
1202 * @return bool
1203 */
1204 function formatMetadata() {
1205 if ( !$this->getHandler() ) {
1206 return false;
1207 }
1208 return $this->getHandler()->formatMetadata( $this, $this->getMetadata() );
1209 }
1210
1211 /**
1212 * Returns true if the file comes from the local file repository.
1213 *
1214 * @return bool
1215 */
1216 function isLocal() {
1217 $repo = $this->getRepo();
1218 return $repo && $repo->isLocal();
1219 }
1220
1221 /**
1222 * Returns the name of the repository.
1223 *
1224 * @return string
1225 */
1226 function getRepoName() {
1227 return $this->repo ? $this->repo->getName() : 'unknown';
1228 }
1229
1230 /**
1231 * Returns the repository
1232 *
1233 * @return FileRepo|false
1234 */
1235 function getRepo() {
1236 return $this->repo;
1237 }
1238
1239 /**
1240 * Returns true if the image is an old version
1241 * STUB
1242 *
1243 * @return bool
1244 */
1245 function isOld() {
1246 return false;
1247 }
1248
1249 /**
1250 * Is this file a "deleted" file in a private archive?
1251 * STUB
1252 *
1253 * @param $field
1254 *
1255 * @return bool
1256 */
1257 function isDeleted( $field ) {
1258 return false;
1259 }
1260
1261 /**
1262 * Return the deletion bitfield
1263 * STUB
1264 */
1265 function getVisibility() {
1266 return 0;
1267 }
1268
1269 /**
1270 * Was this file ever deleted from the wiki?
1271 *
1272 * @return bool
1273 */
1274 function wasDeleted() {
1275 $title = $this->getTitle();
1276 return $title && $title->isDeletedQuick();
1277 }
1278
1279 /**
1280 * Move file to the new title
1281 *
1282 * Move current, old version and all thumbnails
1283 * to the new filename. Old file is deleted.
1284 *
1285 * Cache purging is done; checks for validity
1286 * and logging are caller's responsibility
1287 *
1288 * @param $target Title New file name
1289 * @return FileRepoStatus object.
1290 */
1291 function move( $target ) {
1292 $this->readOnlyError();
1293 }
1294
1295 /**
1296 * Delete all versions of the file.
1297 *
1298 * Moves the files into an archive directory (or deletes them)
1299 * and removes the database rows.
1300 *
1301 * Cache purging is done; logging is caller's responsibility.
1302 *
1303 * @param $reason String
1304 * @param $suppress Boolean: hide content from sysops?
1305 * @return true on success, false on some kind of failure
1306 * STUB
1307 * Overridden by LocalFile
1308 */
1309 function delete( $reason, $suppress = false ) {
1310 $this->readOnlyError();
1311 }
1312
1313 /**
1314 * Restore all or specified deleted revisions to the given file.
1315 * Permissions and logging are left to the caller.
1316 *
1317 * May throw database exceptions on error.
1318 *
1319 * @param $versions array set of record ids of deleted items to restore,
1320 * or empty to restore all revisions.
1321 * @param $unsuppress bool remove restrictions on content upon restoration?
1322 * @return int|false the number of file revisions restored if successful,
1323 * or false on failure
1324 * STUB
1325 * Overridden by LocalFile
1326 */
1327 function restore( $versions = array(), $unsuppress = false ) {
1328 $this->readOnlyError();
1329 }
1330
1331 /**
1332 * Returns 'true' if this file is a type which supports multiple pages,
1333 * e.g. DJVU or PDF. Note that this may be true even if the file in
1334 * question only has a single page.
1335 *
1336 * @return Bool
1337 */
1338 function isMultipage() {
1339 return $this->getHandler() && $this->handler->isMultiPage( $this );
1340 }
1341
1342 /**
1343 * Returns the number of pages of a multipage document, or false for
1344 * documents which aren't multipage documents
1345 *
1346 * @return false|int
1347 */
1348 function pageCount() {
1349 if ( !isset( $this->pageCount ) ) {
1350 if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
1351 $this->pageCount = $this->handler->pageCount( $this );
1352 } else {
1353 $this->pageCount = false;
1354 }
1355 }
1356 return $this->pageCount;
1357 }
1358
1359 /**
1360 * Calculate the height of a thumbnail using the source and destination width
1361 *
1362 * @param $srcWidth
1363 * @param $srcHeight
1364 * @param $dstWidth
1365 *
1366 * @return int
1367 */
1368 static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
1369 // Exact integer multiply followed by division
1370 if ( $srcWidth == 0 ) {
1371 return 0;
1372 } else {
1373 return round( $srcHeight * $dstWidth / $srcWidth );
1374 }
1375 }
1376
1377 /**
1378 * Get an image size array like that returned by getImageSize(), or false if it
1379 * can't be determined.
1380 *
1381 * @param $fileName String: The filename
1382 * @return Array
1383 */
1384 function getImageSize( $fileName ) {
1385 if ( !$this->getHandler() ) {
1386 return false;
1387 }
1388 return $this->handler->getImageSize( $this, $fileName );
1389 }
1390
1391 /**
1392 * Get the URL of the image description page. May return false if it is
1393 * unknown or not applicable.
1394 *
1395 * @return string
1396 */
1397 function getDescriptionUrl() {
1398 if ( $this->repo ) {
1399 return $this->repo->getDescriptionUrl( $this->getName() );
1400 } else {
1401 return false;
1402 }
1403 }
1404
1405 /**
1406 * Get the HTML text of the description page, if available
1407 *
1408 * @return string
1409 */
1410 function getDescriptionText() {
1411 global $wgMemc, $wgLang;
1412 if ( !$this->repo || !$this->repo->fetchDescription ) {
1413 return false;
1414 }
1415 $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgLang->getCode() );
1416 if ( $renderUrl ) {
1417 if ( $this->repo->descriptionCacheExpiry > 0 ) {
1418 wfDebug("Attempting to get the description from cache...");
1419 $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $wgLang->getCode(),
1420 $this->getName() );
1421 $obj = $wgMemc->get($key);
1422 if ($obj) {
1423 wfDebug("success!\n");
1424 return $obj;
1425 }
1426 wfDebug("miss\n");
1427 }
1428 wfDebug( "Fetching shared description from $renderUrl\n" );
1429 $res = Http::get( $renderUrl );
1430 if ( $res && $this->repo->descriptionCacheExpiry > 0 ) {
1431 $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry );
1432 }
1433 return $res;
1434 } else {
1435 return false;
1436 }
1437 }
1438
1439 /**
1440 * Get discription of file revision
1441 * STUB
1442 *
1443 * @return string
1444 */
1445 function getDescription() {
1446 return null;
1447 }
1448
1449 /**
1450 * Get the 14-character timestamp of the file upload, or false if
1451 * it doesn't exist
1452 *
1453 * @return string
1454 */
1455 function getTimestamp() {
1456 $path = $this->getPath();
1457 if ( !file_exists( $path ) ) {
1458 return false;
1459 }
1460 return wfTimestamp( TS_MW, filemtime( $path ) );
1461 }
1462
1463 /**
1464 * Get the SHA-1 base 36 hash of the file
1465 *
1466 * @return string
1467 */
1468 function getSha1() {
1469 return self::sha1Base36( $this->getPath() );
1470 }
1471
1472 /**
1473 * Get the deletion archive key, <sha1>.<ext>
1474 *
1475 * @return string
1476 */
1477 function getStorageKey() {
1478 $hash = $this->getSha1();
1479 if ( !$hash ) {
1480 return false;
1481 }
1482 $ext = $this->getExtension();
1483 $dotExt = $ext === '' ? '' : ".$ext";
1484 return $hash . $dotExt;
1485 }
1486
1487 /**
1488 * Determine if the current user is allowed to view a particular
1489 * field of this file, if it's marked as deleted.
1490 * STUB
1491 * @param $field Integer
1492 * @param $user User object to check, or null to use $wgUser
1493 * @return Boolean
1494 */
1495 function userCan( $field, User $user = null ) {
1496 return true;
1497 }
1498
1499 /**
1500 * Get an associative array containing information about a file in the local filesystem.
1501 *
1502 * @param $path String: absolute local filesystem path
1503 * @param $ext Mixed: the file extension, or true to extract it from the filename.
1504 * Set it to false to ignore the extension.
1505 *
1506 * @return array
1507 */
1508 static function getPropsFromPath( $path, $ext = true ) {
1509 wfProfileIn( __METHOD__ );
1510 wfDebug( __METHOD__.": Getting file info for $path\n" );
1511 $info = array(
1512 'fileExists' => file_exists( $path ) && !is_dir( $path )
1513 );
1514 $gis = false;
1515 if ( $info['fileExists'] ) {
1516 $magic = MimeMagic::singleton();
1517
1518 if ( $ext === true ) {
1519 $i = strrpos( $path, '.' );
1520 $ext = strtolower( $i ? substr( $path, $i + 1 ) : '' );
1521 }
1522
1523 # mime type according to file contents
1524 $info['file-mime'] = $magic->guessMimeType( $path, false );
1525 # logical mime type
1526 $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext );
1527
1528 list( $info['major_mime'], $info['minor_mime'] ) = self::splitMime( $info['mime'] );
1529 $info['media_type'] = $magic->getMediaType( $path, $info['mime'] );
1530
1531 # Get size in bytes
1532 $info['size'] = filesize( $path );
1533
1534 # Height, width and metadata
1535 $handler = MediaHandler::getHandler( $info['mime'] );
1536 if ( $handler ) {
1537 $tempImage = (object)array();
1538 $info['metadata'] = $handler->getMetadata( $tempImage, $path );
1539 $gis = $handler->getImageSize( $tempImage, $path, $info['metadata'] );
1540 } else {
1541 $gis = false;
1542 $info['metadata'] = '';
1543 }
1544 $info['sha1'] = self::sha1Base36( $path );
1545
1546 wfDebug(__METHOD__.": $path loaded, {$info['size']} bytes, {$info['mime']}.\n");
1547 } else {
1548 $info['mime'] = null;
1549 $info['media_type'] = MEDIATYPE_UNKNOWN;
1550 $info['metadata'] = '';
1551 $info['sha1'] = '';
1552 wfDebug(__METHOD__.": $path NOT FOUND!\n");
1553 }
1554 if( $gis ) {
1555 # NOTE: $gis[2] contains a code for the image type. This is no longer used.
1556 $info['width'] = $gis[0];
1557 $info['height'] = $gis[1];
1558 if ( isset( $gis['bits'] ) ) {
1559 $info['bits'] = $gis['bits'];
1560 } else {
1561 $info['bits'] = 0;
1562 }
1563 } else {
1564 $info['width'] = 0;
1565 $info['height'] = 0;
1566 $info['bits'] = 0;
1567 }
1568 wfProfileOut( __METHOD__ );
1569 return $info;
1570 }
1571
1572 /**
1573 * Get a SHA-1 hash of a file in the local filesystem, in base-36 lower case
1574 * encoding, zero padded to 31 digits.
1575 *
1576 * 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36
1577 * fairly neatly.
1578 *
1579 * @param $path string
1580 *
1581 * @return false|string False on failure
1582 */
1583 static function sha1Base36( $path ) {
1584 wfSuppressWarnings();
1585 $hash = sha1_file( $path );
1586 wfRestoreWarnings();
1587 if ( $hash === false ) {
1588 return false;
1589 } else {
1590 return wfBaseConvert( $hash, 16, 36, 31 );
1591 }
1592 }
1593
1594 /**
1595 * @return string
1596 */
1597 function getLongDesc() {
1598 $handler = $this->getHandler();
1599 if ( $handler ) {
1600 return $handler->getLongDesc( $this );
1601 } else {
1602 return MediaHandler::getGeneralLongDesc( $this );
1603 }
1604 }
1605
1606 /**
1607 * @return string
1608 */
1609 function getShortDesc() {
1610 $handler = $this->getHandler();
1611 if ( $handler ) {
1612 return $handler->getShortDesc( $this );
1613 } else {
1614 return MediaHandler::getGeneralShortDesc( $this );
1615 }
1616 }
1617
1618 /**
1619 * @return string
1620 */
1621 function getDimensionsString() {
1622 $handler = $this->getHandler();
1623 if ( $handler ) {
1624 return $handler->getDimensionsString( $this );
1625 } else {
1626 return '';
1627 }
1628 }
1629
1630 /**
1631 * @return
1632 */
1633 function getRedirected() {
1634 return $this->redirected;
1635 }
1636
1637 /**
1638 * @return Title
1639 */
1640 function getRedirectedTitle() {
1641 if ( $this->redirected ) {
1642 if ( !$this->redirectTitle ) {
1643 $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
1644 }
1645 return $this->redirectTitle;
1646 }
1647 }
1648
1649 /**
1650 * @param $from
1651 * @return void
1652 */
1653 function redirectedFrom( $from ) {
1654 $this->redirected = $from;
1655 }
1656
1657 /**
1658 * @return bool
1659 */
1660 function isMissing() {
1661 return false;
1662 }
1663
1664 /**
1665 * Assert that $this->repo is set to a valid FileRepo instance
1666 * @throws MWException
1667 */
1668 protected function assertRepoDefined() {
1669 if ( !( $this->repo instanceof $this->repoClass ) ) {
1670 throw new MWException( "A {$this->repoClass} object is not set for this File.\n" );
1671 }
1672 }
1673
1674 /**
1675 * Assert that $this->title is set to a Title
1676 * @throws MWException
1677 */
1678 protected function assertTitleDefined() {
1679 if ( !( $this->title instanceof Title ) ) {
1680 throw new MWException( "A Title object is not set for this File.\n" );
1681 }
1682 }
1683 }
1684 /**
1685 * Aliases for backwards compatibility with 1.6
1686 */
1687 define( 'MW_IMG_DELETED_FILE', File::DELETED_FILE );
1688 define( 'MW_IMG_DELETED_COMMENT', File::DELETED_COMMENT );
1689 define( 'MW_IMG_DELETED_USER', File::DELETED_USER );
1690 define( 'MW_IMG_DELETED_RESTRICTED', File::DELETED_RESTRICTED );