MediaWiki  1.28.0
File.php
Go to the documentation of this file.
1 <?php
50 abstract class File implements IDBAccessObject {
51  // Bitfield values akin to the Revision deletion constants
52  const DELETED_FILE = 1;
53  const DELETED_COMMENT = 2;
54  const DELETED_USER = 4;
55  const DELETED_RESTRICTED = 8;
56 
58  const RENDER_NOW = 1;
63  const RENDER_FORCE = 2;
64 
65  const DELETE_SOURCE = 1;
66 
67  // Audience options for File::getDescription()
68  const FOR_PUBLIC = 1;
69  const FOR_THIS_USER = 2;
70  const RAW = 3;
71 
72  // Options for File::thumbName()
73  const THUMB_FULL_NAME = 1;
74 
95  public $repo;
96 
98  protected $title;
99 
101  protected $lastError;
102 
104  protected $redirected;
105 
107  protected $redirectedTitle;
108 
110  protected $fsFile;
111 
113  protected $handler;
114 
116  protected $url;
117 
119  protected $extension;
120 
122  protected $name;
123 
125  protected $path;
126 
128  protected $hashPath;
129 
133  protected $pageCount;
134 
136  protected $transformScript;
137 
139  protected $redirectTitle;
140 
142  protected $canRender;
143 
147  protected $isSafeFile;
148 
150  protected $repoClass = 'FileRepo';
151 
153  protected $tmpBucketedThumbCache = [];
154 
165  function __construct( $title, $repo ) {
166  // Some subclasses do not use $title, but set name/title some other way
167  if ( $title !== false ) {
168  $title = self::normalizeTitle( $title, 'exception' );
169  }
170  $this->title = $title;
171  $this->repo = $repo;
172  }
173 
183  static function normalizeTitle( $title, $exception = false ) {
184  $ret = $title;
185  if ( $ret instanceof Title ) {
186  # Normalize NS_MEDIA -> NS_FILE
187  if ( $ret->getNamespace() == NS_MEDIA ) {
188  $ret = Title::makeTitleSafe( NS_FILE, $ret->getDBkey() );
189  # Sanity check the title namespace
190  } elseif ( $ret->getNamespace() !== NS_FILE ) {
191  $ret = null;
192  }
193  } else {
194  # Convert strings to Title objects
195  $ret = Title::makeTitleSafe( NS_FILE, (string)$ret );
196  }
197  if ( !$ret && $exception !== false ) {
198  throw new MWException( "`$title` is not a valid file title." );
199  }
200 
201  return $ret;
202  }
203 
204  function __get( $name ) {
205  $function = [ $this, 'get' . ucfirst( $name ) ];
206  if ( !is_callable( $function ) ) {
207  return null;
208  } else {
209  $this->$name = call_user_func( $function );
210 
211  return $this->$name;
212  }
213  }
214 
223  static function normalizeExtension( $extension ) {
224  $lower = strtolower( $extension );
225  $squish = [
226  'htm' => 'html',
227  'jpeg' => 'jpg',
228  'mpeg' => 'mpg',
229  'tiff' => 'tif',
230  'ogv' => 'ogg' ];
231  if ( isset( $squish[$lower] ) ) {
232  return $squish[$lower];
233  } elseif ( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
234  return $lower;
235  } else {
236  return '';
237  }
238  }
239 
248  static function checkExtensionCompatibility( File $old, $new ) {
249  $oldMime = $old->getMimeType();
250  $n = strrpos( $new, '.' );
251  $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' );
253 
254  return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
255  }
256 
262  function upgradeRow() {
263  }
264 
272  public static function splitMime( $mime ) {
273  if ( strpos( $mime, '/' ) !== false ) {
274  return explode( '/', $mime, 2 );
275  } else {
276  return [ $mime, 'unknown' ];
277  }
278  }
279 
287  public static function compare( File $a, File $b ) {
288  return strcmp( $a->getName(), $b->getName() );
289  }
290 
296  public function getName() {
297  if ( !isset( $this->name ) ) {
298  $this->assertRepoDefined();
299  $this->name = $this->repo->getNameFromTitle( $this->title );
300  }
301 
302  return $this->name;
303  }
304 
310  function getExtension() {
311  if ( !isset( $this->extension ) ) {
312  $n = strrpos( $this->getName(), '.' );
313  $this->extension = self::normalizeExtension(
314  $n ? substr( $this->getName(), $n + 1 ) : '' );
315  }
316 
317  return $this->extension;
318  }
319 
325  public function getTitle() {
326  return $this->title;
327  }
328 
334  public function getOriginalTitle() {
335  if ( $this->redirected ) {
336  return $this->getRedirectedTitle();
337  }
338 
339  return $this->title;
340  }
341 
347  public function getUrl() {
348  if ( !isset( $this->url ) ) {
349  $this->assertRepoDefined();
350  $ext = $this->getExtension();
351  $this->url = $this->repo->getZoneUrl( 'public', $ext ) . '/' . $this->getUrlRel();
352  }
353 
354  return $this->url;
355  }
356 
357  /*
358  * Get short description URL for a files based on the page ID
359  *
360  * @return string|null
361  * @since 1.27
362  */
363  public function getDescriptionShortUrl() {
364  return null;
365  }
366 
374  public function getFullUrl() {
375  return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE );
376  }
377 
381  public function getCanonicalUrl() {
382  return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL );
383  }
384 
388  function getViewURL() {
389  if ( $this->mustRender() ) {
390  if ( $this->canRender() ) {
391  return $this->createThumb( $this->getWidth() );
392  } else {
393  wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() .
394  ' (' . $this->getMimeType() . "), but can't!\n" );
395 
396  return $this->getUrl(); # hm... return NULL?
397  }
398  } else {
399  return $this->getUrl();
400  }
401  }
402 
416  public function getPath() {
417  if ( !isset( $this->path ) ) {
418  $this->assertRepoDefined();
419  $this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel();
420  }
421 
422  return $this->path;
423  }
424 
432  public function getLocalRefPath() {
433  $this->assertRepoDefined();
434  if ( !isset( $this->fsFile ) ) {
435  $starttime = microtime( true );
436  $this->fsFile = $this->repo->getLocalReference( $this->getPath() );
437 
438  $statTiming = microtime( true ) - $starttime;
439  RequestContext::getMain()->getStats()->timing(
440  'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
441 
442  if ( !$this->fsFile ) {
443  $this->fsFile = false; // null => false; cache negative hits
444  }
445  }
446 
447  return ( $this->fsFile )
448  ? $this->fsFile->getPath()
449  : false;
450  }
451 
462  public function getWidth( $page = 1 ) {
463  return false;
464  }
465 
476  public function getHeight( $page = 1 ) {
477  return false;
478  }
479 
489  public function getThumbnailBucket( $desiredWidth, $page = 1 ) {
491 
492  $imageWidth = $this->getWidth( $page );
493 
494  if ( $imageWidth === false ) {
495  return false;
496  }
497 
498  if ( $desiredWidth > $imageWidth ) {
499  return false;
500  }
501 
502  if ( !$wgThumbnailBuckets ) {
503  return false;
504  }
505 
506  $sortedBuckets = $wgThumbnailBuckets;
507 
508  sort( $sortedBuckets );
509 
510  foreach ( $sortedBuckets as $bucket ) {
511  if ( $bucket >= $imageWidth ) {
512  return false;
513  }
514 
515  if ( $bucket - $wgThumbnailMinimumBucketDistance > $desiredWidth ) {
516  return $bucket;
517  }
518  }
519 
520  // Image is bigger than any available bucket
521  return false;
522  }
523 
531  public function getUser( $type = 'text' ) {
532  return null;
533  }
534 
540  public function getLength() {
541  $handler = $this->getHandler();
542  if ( $handler ) {
543  return $handler->getLength( $this );
544  } else {
545  return 0;
546  }
547  }
548 
554  public function isVectorized() {
555  $handler = $this->getHandler();
556  if ( $handler ) {
557  return $handler->isVectorized( $this );
558  } else {
559  return false;
560  }
561  }
562 
574  public function getAvailableLanguages() {
575  $handler = $this->getHandler();
576  if ( $handler ) {
577  return $handler->getAvailableLanguages( $this );
578  } else {
579  return [];
580  }
581  }
582 
590  public function getDefaultRenderLanguage() {
591  $handler = $this->getHandler();
592  if ( $handler ) {
593  return $handler->getDefaultRenderLanguage( $this );
594  } else {
595  return null;
596  }
597  }
598 
609  public function canAnimateThumbIfAppropriate() {
610  $handler = $this->getHandler();
611  if ( !$handler ) {
612  // We cannot handle image whatsoever, thus
613  // one would not expect it to be animated
614  // so true.
615  return true;
616  } else {
617  if ( $this->allowInlineDisplay()
618  && $handler->isAnimatedImage( $this )
619  && !$handler->canAnimateThumbnail( $this )
620  ) {
621  // Image is animated, but thumbnail isn't.
622  // This is unexpected to the user.
623  return false;
624  } else {
625  // Image is not animated, so one would
626  // not expect thumb to be
627  return true;
628  }
629  }
630  }
631 
638  public function getMetadata() {
639  return false;
640  }
641 
648  public function getCommonMetaArray() {
649  $handler = $this->getHandler();
650 
651  if ( !$handler ) {
652  return false;
653  }
654 
655  return $handler->getCommonMetaArray( $this );
656  }
657 
666  public function convertMetadataVersion( $metadata, $version ) {
667  $handler = $this->getHandler();
668  if ( !is_array( $metadata ) ) {
669  // Just to make the return type consistent
670  $metadata = unserialize( $metadata );
671  }
672  if ( $handler ) {
673  return $handler->convertMetadataVersion( $metadata, $version );
674  } else {
675  return $metadata;
676  }
677  }
678 
685  public function getBitDepth() {
686  return 0;
687  }
688 
695  public function getSize() {
696  return false;
697  }
698 
706  function getMimeType() {
707  return 'unknown/unknown';
708  }
709 
717  function getMediaType() {
718  return MEDIATYPE_UNKNOWN;
719  }
720 
733  function canRender() {
734  if ( !isset( $this->canRender ) ) {
735  $this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists();
736  }
737 
738  return $this->canRender;
739  }
740 
745  protected function getCanRender() {
746  return $this->canRender();
747  }
748 
759  function mustRender() {
760  return $this->getHandler() && $this->handler->mustRender( $this );
761  }
762 
768  function allowInlineDisplay() {
769  return $this->canRender();
770  }
771 
785  function isSafeFile() {
786  if ( !isset( $this->isSafeFile ) ) {
787  $this->isSafeFile = $this->getIsSafeFileUncached();
788  }
789 
790  return $this->isSafeFile;
791  }
792 
798  protected function getIsSafeFile() {
799  return $this->isSafeFile();
800  }
801 
807  protected function getIsSafeFileUncached() {
809 
810  if ( $this->allowInlineDisplay() ) {
811  return true;
812  }
813  if ( $this->isTrustedFile() ) {
814  return true;
815  }
816 
817  $type = $this->getMediaType();
818  $mime = $this->getMimeType();
819  # wfDebug( "LocalFile::isSafeFile: type= $type, mime= $mime\n" );
820 
821  if ( !$type || $type === MEDIATYPE_UNKNOWN ) {
822  return false; # unknown type, not trusted
823  }
824  if ( in_array( $type, $wgTrustedMediaFormats ) ) {
825  return true;
826  }
827 
828  if ( $mime === "unknown/unknown" ) {
829  return false; # unknown type, not trusted
830  }
831  if ( in_array( $mime, $wgTrustedMediaFormats ) ) {
832  return true;
833  }
834 
835  return false;
836  }
837 
851  function isTrustedFile() {
852  # this could be implemented to check a flag in the database,
853  # look for signatures, etc
854  return false;
855  }
856 
866  public function load( $flags = 0 ) {
867  }
868 
876  public function exists() {
877  return $this->getPath() && $this->repo->fileExists( $this->path );
878  }
879 
886  public function isVisible() {
887  return $this->exists();
888  }
889 
893  function getTransformScript() {
894  if ( !isset( $this->transformScript ) ) {
895  $this->transformScript = false;
896  if ( $this->repo ) {
897  $script = $this->repo->getThumbScriptUrl();
898  if ( $script ) {
899  $this->transformScript = wfAppendQuery( $script, [ 'f' => $this->getName() ] );
900  }
901  }
902  }
903 
904  return $this->transformScript;
905  }
906 
914  function getUnscaledThumb( $handlerParams = [] ) {
915  $hp =& $handlerParams;
916  $page = isset( $hp['page'] ) ? $hp['page'] : false;
917  $width = $this->getWidth( $page );
918  if ( !$width ) {
919  return $this->iconThumb();
920  }
921  $hp['width'] = $width;
922  // be sure to ignore any height specification as well (bug 62258)
923  unset( $hp['height'] );
924 
925  return $this->transform( $hp );
926  }
927 
937  public function thumbName( $params, $flags = 0 ) {
938  $name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) )
939  ? $this->repo->nameForThumb( $this->getName() )
940  : $this->getName();
941 
942  return $this->generateThumbName( $name, $params );
943  }
944 
952  public function generateThumbName( $name, $params ) {
953  if ( !$this->getHandler() ) {
954  return null;
955  }
956  $extension = $this->getExtension();
957  list( $thumbExt, ) = $this->getHandler()->getThumbType(
958  $extension, $this->getMimeType(), $params );
959  $thumbName = $this->getHandler()->makeParamString( $params );
960 
961  if ( $this->repo->supportsSha1URLs() ) {
962  $thumbName .= '-' . $this->getSha1() . '.' . $thumbExt;
963  } else {
964  $thumbName .= '-' . $name;
965 
966  if ( $thumbExt != $extension ) {
967  $thumbName .= ".$thumbExt";
968  }
969  }
970 
971  return $thumbName;
972  }
973 
991  public function createThumb( $width, $height = -1 ) {
992  $params = [ 'width' => $width ];
993  if ( $height != -1 ) {
994  $params['height'] = $height;
995  }
996  $thumb = $this->transform( $params );
997  if ( !$thumb || $thumb->isError() ) {
998  return '';
999  }
1000 
1001  return $thumb->getUrl();
1002  }
1003 
1013  protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) {
1015 
1016  $handler = $this->getHandler();
1017  if ( $handler && $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
1018  return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1019  } else {
1020  return new MediaTransformError( 'thumbnail_error',
1021  $params['width'], 0, wfMessage( 'thumbnail-dest-create' )->text() );
1022  }
1023  }
1024 
1033  function transform( $params, $flags = 0 ) {
1035 
1036  do {
1037  if ( !$this->canRender() ) {
1038  $thumb = $this->iconThumb();
1039  break; // not a bitmap or renderable image, don't try
1040  }
1041 
1042  // Get the descriptionUrl to embed it as comment into the thumbnail. Bug 19791.
1043  $descriptionUrl = $this->getDescriptionUrl();
1044  if ( $descriptionUrl ) {
1045  $params['descriptionUrl'] = wfExpandUrl( $descriptionUrl, PROTO_CANONICAL );
1046  }
1047 
1048  $handler = $this->getHandler();
1049  $script = $this->getTransformScript();
1050  if ( $script && !( $flags & self::RENDER_NOW ) ) {
1051  // Use a script to transform on client request, if possible
1052  $thumb = $handler->getScriptedTransform( $this, $script, $params );
1053  if ( $thumb ) {
1054  break;
1055  }
1056  }
1057 
1058  $normalisedParams = $params;
1059  $handler->normaliseParams( $this, $normalisedParams );
1060 
1061  $thumbName = $this->thumbName( $normalisedParams );
1062  $thumbUrl = $this->getThumbUrl( $thumbName );
1063  $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
1064 
1065  if ( $this->repo ) {
1066  // Defer rendering if a 404 handler is set up...
1067  if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
1068  // XXX: Pass in the storage path even though we are not rendering anything
1069  // and the path is supposed to be an FS path. This is due to getScalerType()
1070  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1071  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1072  break;
1073  }
1074  // Check if an up-to-date thumbnail already exists...
1075  wfDebug( __METHOD__ . ": Doing stat for $thumbPath\n" );
1076  if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) {
1077  $timestamp = $this->repo->getFileTimestamp( $thumbPath );
1078  if ( $timestamp !== false && $timestamp >= $wgThumbnailEpoch ) {
1079  // XXX: Pass in the storage path even though we are not rendering anything
1080  // and the path is supposed to be an FS path. This is due to getScalerType()
1081  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1082  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1083  $thumb->setStoragePath( $thumbPath );
1084  break;
1085  }
1086  } elseif ( $flags & self::RENDER_FORCE ) {
1087  wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
1088  }
1089 
1090  // If the backend is ready-only, don't keep generating thumbnails
1091  // only to return transformation errors, just return the error now.
1092  if ( $this->repo->getReadOnlyReason() !== false ) {
1093  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1094  break;
1095  }
1096  }
1097 
1098  $tmpFile = $this->makeTransformTmpFile( $thumbPath );
1099 
1100  if ( !$tmpFile ) {
1101  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1102  } else {
1103  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1104  }
1105  } while ( false );
1106 
1107  return is_object( $thumb ) ? $thumb : false;
1108  }
1109 
1117  public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
1119 
1120  $stats = RequestContext::getMain()->getStats();
1121 
1122  $handler = $this->getHandler();
1123 
1124  $normalisedParams = $transformParams;
1125  $handler->normaliseParams( $this, $normalisedParams );
1126 
1127  $thumbName = $this->thumbName( $normalisedParams );
1128  $thumbUrl = $this->getThumbUrl( $thumbName );
1129  $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
1130 
1131  $tmpThumbPath = $tmpFile->getPath();
1132 
1133  if ( $handler->supportsBucketing() ) {
1134  $this->generateBucketsIfNeeded( $normalisedParams, $flags );
1135  }
1136 
1137  $starttime = microtime( true );
1138 
1139  // Actually render the thumbnail...
1140  $thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1141  $tmpFile->bind( $thumb ); // keep alive with $thumb
1142 
1143  $statTiming = microtime( true ) - $starttime;
1144  $stats->timing( 'media.thumbnail.generate.transform', 1000 * $statTiming );
1145 
1146  if ( !$thumb ) { // bad params?
1147  $thumb = false;
1148  } elseif ( $thumb->isError() ) { // transform error
1150  $this->lastError = $thumb->toText();
1151  // Ignore errors if requested
1152  if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
1153  $thumb = $handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1154  }
1155  } elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
1156  // Copy the thumbnail from the file system into storage...
1157 
1158  $starttime = microtime( true );
1159 
1160  $disposition = $this->getThumbDisposition( $thumbName );
1161  $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
1162  if ( $status->isOK() ) {
1163  $thumb->setStoragePath( $thumbPath );
1164  } else {
1165  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags );
1166  }
1167 
1168  $statTiming = microtime( true ) - $starttime;
1169  $stats->timing( 'media.thumbnail.generate.store', 1000 * $statTiming );
1170 
1171  // Give extensions a chance to do something with this thumbnail...
1172  Hooks::run( 'FileTransformed', [ $this, $thumb, $tmpThumbPath, $thumbPath ] );
1173  }
1174 
1175  return $thumb;
1176  }
1177 
1184  protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
1185  if ( !$this->repo
1186  || !isset( $params['physicalWidth'] )
1187  || !isset( $params['physicalHeight'] )
1188  ) {
1189  return false;
1190  }
1191 
1192  $bucket = $this->getThumbnailBucket( $params['physicalWidth'] );
1193 
1194  if ( !$bucket || $bucket == $params['physicalWidth'] ) {
1195  return false;
1196  }
1197 
1198  $bucketPath = $this->getBucketThumbPath( $bucket );
1199 
1200  if ( $this->repo->fileExists( $bucketPath ) ) {
1201  return false;
1202  }
1203 
1204  $starttime = microtime( true );
1205 
1206  $params['physicalWidth'] = $bucket;
1207  $params['width'] = $bucket;
1208 
1209  $params = $this->getHandler()->sanitizeParamsForBucketing( $params );
1210 
1211  $tmpFile = $this->makeTransformTmpFile( $bucketPath );
1212 
1213  if ( !$tmpFile ) {
1214  return false;
1215  }
1216 
1217  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1218 
1219  $buckettime = microtime( true ) - $starttime;
1220 
1221  if ( !$thumb || $thumb->isError() ) {
1222  return false;
1223  }
1224 
1225  $this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath();
1226  // For the caching to work, we need to make the tmp file survive as long as
1227  // this object exists
1228  $tmpFile->bind( $this );
1229 
1230  RequestContext::getMain()->getStats()->timing(
1231  'media.thumbnail.generate.bucket', 1000 * $buckettime );
1232 
1233  return true;
1234  }
1235 
1241  public function getThumbnailSource( $params ) {
1242  if ( $this->repo
1243  && $this->getHandler()->supportsBucketing()
1244  && isset( $params['physicalWidth'] )
1245  && $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
1246  ) {
1247  if ( $this->getWidth() != 0 ) {
1248  $bucketHeight = round( $this->getHeight() * ( $bucket / $this->getWidth() ) );
1249  } else {
1250  $bucketHeight = 0;
1251  }
1252 
1253  // Try to avoid reading from storage if the file was generated by this script
1254  if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) {
1255  $tmpPath = $this->tmpBucketedThumbCache[$bucket];
1256 
1257  if ( file_exists( $tmpPath ) ) {
1258  return [
1259  'path' => $tmpPath,
1260  'width' => $bucket,
1261  'height' => $bucketHeight
1262  ];
1263  }
1264  }
1265 
1266  $bucketPath = $this->getBucketThumbPath( $bucket );
1267 
1268  if ( $this->repo->fileExists( $bucketPath ) ) {
1269  $fsFile = $this->repo->getLocalReference( $bucketPath );
1270 
1271  if ( $fsFile ) {
1272  return [
1273  'path' => $fsFile->getPath(),
1274  'width' => $bucket,
1275  'height' => $bucketHeight
1276  ];
1277  }
1278  }
1279  }
1280 
1281  // Thumbnailing a very large file could result in network saturation if
1282  // everyone does it at once.
1283  if ( $this->getSize() >= 1e7 ) { // 10MB
1284  $that = $this;
1285  $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
1286  [
1287  'doWork' => function () use ( $that ) {
1288  return $that->getLocalRefPath();
1289  }
1290  ]
1291  );
1292  $srcPath = $work->execute();
1293  } else {
1294  $srcPath = $this->getLocalRefPath();
1295  }
1296 
1297  // Original file
1298  return [
1299  'path' => $srcPath,
1300  'width' => $this->getWidth(),
1301  'height' => $this->getHeight()
1302  ];
1303  }
1304 
1310  protected function getBucketThumbPath( $bucket ) {
1311  $thumbName = $this->getBucketThumbName( $bucket );
1312  return $this->getThumbPath( $thumbName );
1313  }
1314 
1320  protected function getBucketThumbName( $bucket ) {
1321  return $this->thumbName( [ 'physicalWidth' => $bucket ] );
1322  }
1323 
1329  protected function makeTransformTmpFile( $thumbPath ) {
1330  $thumbExt = FileBackend::extensionFromPath( $thumbPath );
1331  return TempFSFile::factory( 'transform_', $thumbExt, wfTempDir() );
1332  }
1333 
1339  function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) {
1340  $fileName = $this->name; // file name to suggest
1341  $thumbExt = FileBackend::extensionFromPath( $thumbName );
1342  if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) {
1343  $fileName .= ".$thumbExt";
1344  }
1345 
1346  return FileBackend::makeContentDisposition( $dispositionType, $fileName );
1347  }
1348 
1355  function migrateThumbFile( $thumbName ) {
1356  }
1357 
1364  function getHandler() {
1365  if ( !isset( $this->handler ) ) {
1366  $this->handler = MediaHandler::getHandler( $this->getMimeType() );
1367  }
1368 
1369  return $this->handler;
1370  }
1371 
1377  function iconThumb() {
1379  $assetsPath = "$wgResourceBasePath/resources/assets/file-type-icons/";
1380  $assetsDirectory = "$IP/resources/assets/file-type-icons/";
1381 
1382  $try = [ 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' ];
1383  foreach ( $try as $icon ) {
1384  if ( file_exists( $assetsDirectory . $icon ) ) { // always FS
1385  $params = [ 'width' => 120, 'height' => 120 ];
1386 
1387  return new ThumbnailImage( $this, $assetsPath . $icon, false, $params );
1388  }
1389  }
1390 
1391  return null;
1392  }
1393 
1399  function getLastError() {
1400  return $this->lastError;
1401  }
1402 
1409  function getThumbnails() {
1410  return [];
1411  }
1412 
1420  function purgeCache( $options = [] ) {
1421  }
1422 
1428  function purgeDescription() {
1429  $title = $this->getTitle();
1430  if ( $title ) {
1432  $title->purgeSquid();
1433  }
1434  }
1435 
1440  function purgeEverything() {
1441  // Delete thumbnails and refresh file metadata cache
1442  $this->purgeCache();
1443  $this->purgeDescription();
1444 
1445  // Purge cache of all pages using this file
1446  $title = $this->getTitle();
1447  if ( $title ) {
1448  DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
1449  }
1450  }
1451 
1463  function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
1464  return [];
1465  }
1466 
1476  public function nextHistoryLine() {
1477  return false;
1478  }
1479 
1486  public function resetHistory() {
1487  }
1488 
1496  function getHashPath() {
1497  if ( !isset( $this->hashPath ) ) {
1498  $this->assertRepoDefined();
1499  $this->hashPath = $this->repo->getHashPath( $this->getName() );
1500  }
1501 
1502  return $this->hashPath;
1503  }
1504 
1511  function getRel() {
1512  return $this->getHashPath() . $this->getName();
1513  }
1514 
1522  function getArchiveRel( $suffix = false ) {
1523  $path = 'archive/' . $this->getHashPath();
1524  if ( $suffix === false ) {
1525  $path = substr( $path, 0, -1 );
1526  } else {
1527  $path .= $suffix;
1528  }
1529 
1530  return $path;
1531  }
1532 
1540  function getThumbRel( $suffix = false ) {
1541  $path = $this->getRel();
1542  if ( $suffix !== false ) {
1543  $path .= '/' . $suffix;
1544  }
1545 
1546  return $path;
1547  }
1548 
1555  function getUrlRel() {
1556  return $this->getHashPath() . rawurlencode( $this->getName() );
1557  }
1558 
1567  function getArchiveThumbRel( $archiveName, $suffix = false ) {
1568  $path = 'archive/' . $this->getHashPath() . $archiveName . "/";
1569  if ( $suffix === false ) {
1570  $path = substr( $path, 0, -1 );
1571  } else {
1572  $path .= $suffix;
1573  }
1574 
1575  return $path;
1576  }
1577 
1584  function getArchivePath( $suffix = false ) {
1585  $this->assertRepoDefined();
1586 
1587  return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
1588  }
1589 
1597  function getArchiveThumbPath( $archiveName, $suffix = false ) {
1598  $this->assertRepoDefined();
1599 
1600  return $this->repo->getZonePath( 'thumb' ) . '/' .
1601  $this->getArchiveThumbRel( $archiveName, $suffix );
1602  }
1603 
1610  function getThumbPath( $suffix = false ) {
1611  $this->assertRepoDefined();
1612 
1613  return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
1614  }
1615 
1622  function getTranscodedPath( $suffix = false ) {
1623  $this->assertRepoDefined();
1624 
1625  return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix );
1626  }
1627 
1634  function getArchiveUrl( $suffix = false ) {
1635  $this->assertRepoDefined();
1636  $ext = $this->getExtension();
1637  $path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath();
1638  if ( $suffix === false ) {
1639  $path = substr( $path, 0, -1 );
1640  } else {
1641  $path .= rawurlencode( $suffix );
1642  }
1643 
1644  return $path;
1645  }
1646 
1654  function getArchiveThumbUrl( $archiveName, $suffix = false ) {
1655  $this->assertRepoDefined();
1656  $ext = $this->getExtension();
1657  $path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' .
1658  $this->getHashPath() . rawurlencode( $archiveName ) . "/";
1659  if ( $suffix === false ) {
1660  $path = substr( $path, 0, -1 );
1661  } else {
1662  $path .= rawurlencode( $suffix );
1663  }
1664 
1665  return $path;
1666  }
1667 
1675  function getZoneUrl( $zone, $suffix = false ) {
1676  $this->assertRepoDefined();
1677  $ext = $this->getExtension();
1678  $path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel();
1679  if ( $suffix !== false ) {
1680  $path .= '/' . rawurlencode( $suffix );
1681  }
1682 
1683  return $path;
1684  }
1685 
1692  function getThumbUrl( $suffix = false ) {
1693  return $this->getZoneUrl( 'thumb', $suffix );
1694  }
1695 
1702  function getTranscodedUrl( $suffix = false ) {
1703  return $this->getZoneUrl( 'transcoded', $suffix );
1704  }
1705 
1712  function getVirtualUrl( $suffix = false ) {
1713  $this->assertRepoDefined();
1714  $path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
1715  if ( $suffix !== false ) {
1716  $path .= '/' . rawurlencode( $suffix );
1717  }
1718 
1719  return $path;
1720  }
1721 
1728  function getArchiveVirtualUrl( $suffix = false ) {
1729  $this->assertRepoDefined();
1730  $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
1731  if ( $suffix === false ) {
1732  $path = substr( $path, 0, -1 );
1733  } else {
1734  $path .= rawurlencode( $suffix );
1735  }
1736 
1737  return $path;
1738  }
1739 
1746  function getThumbVirtualUrl( $suffix = false ) {
1747  $this->assertRepoDefined();
1748  $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
1749  if ( $suffix !== false ) {
1750  $path .= '/' . rawurlencode( $suffix );
1751  }
1752 
1753  return $path;
1754  }
1755 
1759  function isHashed() {
1760  $this->assertRepoDefined();
1761 
1762  return (bool)$this->repo->getHashLevels();
1763  }
1764 
1768  function readOnlyError() {
1769  throw new MWException( get_class( $this ) . ': write operations are not supported' );
1770  }
1771 
1787  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
1788  $watch = false, $timestamp = false, User $user = null
1789  ) {
1790  $this->readOnlyError();
1791  }
1792 
1814  function publish( $src, $flags = 0, array $options = [] ) {
1815  $this->readOnlyError();
1816  }
1817 
1822  function formatMetadata( $context = false ) {
1823  if ( !$this->getHandler() ) {
1824  return false;
1825  }
1826 
1827  return $this->getHandler()->formatMetadata( $this, $context );
1828  }
1829 
1835  function isLocal() {
1836  return $this->repo && $this->repo->isLocal();
1837  }
1838 
1844  function getRepoName() {
1845  return $this->repo ? $this->repo->getName() : 'unknown';
1846  }
1847 
1853  function getRepo() {
1854  return $this->repo;
1855  }
1856 
1863  function isOld() {
1864  return false;
1865  }
1866 
1874  function isDeleted( $field ) {
1875  return false;
1876  }
1877 
1883  function getVisibility() {
1884  return 0;
1885  }
1886 
1892  function wasDeleted() {
1893  $title = $this->getTitle();
1894 
1895  return $title && $title->isDeletedQuick();
1896  }
1897 
1910  function move( $target ) {
1911  $this->readOnlyError();
1912  }
1913 
1929  function delete( $reason, $suppress = false, $user = null ) {
1930  $this->readOnlyError();
1931  }
1932 
1947  function restore( $versions = [], $unsuppress = false ) {
1948  $this->readOnlyError();
1949  }
1950 
1958  function isMultipage() {
1959  return $this->getHandler() && $this->handler->isMultiPage( $this );
1960  }
1961 
1968  function pageCount() {
1969  if ( !isset( $this->pageCount ) ) {
1970  if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
1971  $this->pageCount = $this->handler->pageCount( $this );
1972  } else {
1973  $this->pageCount = false;
1974  }
1975  }
1976 
1977  return $this->pageCount;
1978  }
1979 
1989  static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
1990  // Exact integer multiply followed by division
1991  if ( $srcWidth == 0 ) {
1992  return 0;
1993  } else {
1994  return round( $srcHeight * $dstWidth / $srcWidth );
1995  }
1996  }
1997 
2008  function getImageSize( $filePath ) {
2009  if ( !$this->getHandler() ) {
2010  return false;
2011  }
2012 
2013  return $this->getHandler()->getImageSize( $this, $filePath );
2014  }
2015 
2022  function getDescriptionUrl() {
2023  if ( $this->repo ) {
2024  return $this->repo->getDescriptionUrl( $this->getName() );
2025  } else {
2026  return false;
2027  }
2028  }
2029 
2036  function getDescriptionText( $lang = false ) {
2037  global $wgLang;
2038 
2039  if ( !$this->repo || !$this->repo->fetchDescription ) {
2040  return false;
2041  }
2042 
2043  $lang = $lang ?: $wgLang;
2044 
2045  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
2046  if ( $renderUrl ) {
2048  $key = $this->repo->getLocalCacheKey(
2049  'RemoteFileDescription',
2050  'url',
2051  $lang->getCode(),
2052  $this->getName()
2053  );
2054 
2055  return $cache->getWithSetCallback(
2056  $key,
2057  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
2058  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
2059  wfDebug( "Fetching shared description from $renderUrl\n" );
2060  $res = Http::get( $renderUrl, [], __METHOD__ );
2061  if ( !$res ) {
2063  }
2064 
2065  return $res;
2066  }
2067  );
2068  }
2069 
2070  return false;
2071  }
2072 
2085  function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
2086  return null;
2087  }
2088 
2094  function getTimestamp() {
2095  $this->assertRepoDefined();
2096 
2097  return $this->repo->getFileTimestamp( $this->getPath() );
2098  }
2099 
2107  public function getDescriptionTouched() {
2108  return false;
2109  }
2110 
2116  function getSha1() {
2117  $this->assertRepoDefined();
2118 
2119  return $this->repo->getFileSha1( $this->getPath() );
2120  }
2121 
2127  function getStorageKey() {
2128  $hash = $this->getSha1();
2129  if ( !$hash ) {
2130  return false;
2131  }
2132  $ext = $this->getExtension();
2133  $dotExt = $ext === '' ? '' : ".$ext";
2134 
2135  return $hash . $dotExt;
2136  }
2137 
2146  function userCan( $field, User $user = null ) {
2147  return true;
2148  }
2149 
2153  function getStreamHeaders() {
2154  $handler = $this->getHandler();
2155  if ( $handler ) {
2156  return $handler->getStreamHeaders( $this->getMetadata() );
2157  } else {
2158  return [];
2159  }
2160  }
2161 
2165  function getLongDesc() {
2166  $handler = $this->getHandler();
2167  if ( $handler ) {
2168  return $handler->getLongDesc( $this );
2169  } else {
2170  return MediaHandler::getGeneralLongDesc( $this );
2171  }
2172  }
2173 
2177  function getShortDesc() {
2178  $handler = $this->getHandler();
2179  if ( $handler ) {
2180  return $handler->getShortDesc( $this );
2181  } else {
2182  return MediaHandler::getGeneralShortDesc( $this );
2183  }
2184  }
2185 
2189  function getDimensionsString() {
2190  $handler = $this->getHandler();
2191  if ( $handler ) {
2192  return $handler->getDimensionsString( $this );
2193  } else {
2194  return '';
2195  }
2196  }
2197 
2201  function getRedirected() {
2202  return $this->redirected;
2203  }
2204 
2208  function getRedirectedTitle() {
2209  if ( $this->redirected ) {
2210  if ( !$this->redirectTitle ) {
2211  $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
2212  }
2213 
2214  return $this->redirectTitle;
2215  }
2216 
2217  return null;
2218  }
2219 
2224  function redirectedFrom( $from ) {
2225  $this->redirected = $from;
2226  }
2227 
2231  function isMissing() {
2232  return false;
2233  }
2234 
2239  public function isCacheable() {
2240  return true;
2241  }
2242 
2247  protected function assertRepoDefined() {
2248  if ( !( $this->repo instanceof $this->repoClass ) ) {
2249  throw new MWException( "A {$this->repoClass} object is not set for this File.\n" );
2250  }
2251  }
2252 
2257  protected function assertTitleDefined() {
2258  if ( !( $this->title instanceof Title ) ) {
2259  throw new MWException( "A Title object is not set for this File.\n" );
2260  }
2261  }
2262 
2267  public function isExpensiveToThumbnail() {
2268  $handler = $this->getHandler();
2269  return $handler ? $handler->isExpensiveToThumbnail( $this ) : false;
2270  }
2271 
2277  public function isTransformedLocally() {
2278  return true;
2279  }
2280 }
getArchivePath($suffix=false)
Get the path of the archived file.
Definition: File.php:1584
getArchiveThumbPath($archiveName, $suffix=false)
Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified.
Definition: File.php:1597
getLocalRefPath()
Get an FS copy or original of this file and return the path.
Definition: File.php:432
static getMainWANInstance()
Get the main WAN cache object.
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:183
Title $redirectedTitle
Definition: File.php:107
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
convertMetadataVersion($metadata, $version)
get versioned metadata
Definition: File.php:666
transformErrorOutput($thumbPath, $thumbUrl, $params, $flags)
Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors) ...
Definition: File.php:1013
const DELETED_COMMENT
Definition: File.php:53
the array() calling protocol came about after MediaWiki 1.4rc1.
const FOR_THIS_USER
Definition: File.php:69
getRepoName()
Returns the name of the repository.
Definition: File.php:1844
MediaHandler $handler
Definition: File.php:113
nextHistoryLine()
Return the history of this file, line by line.
Definition: File.php:1476
$context
Definition: load.php:50
static splitMime($mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
Definition: File.php:272
getPath()
Returns the file system path.
Definition: FSFile.php:50
assertTitleDefined()
Assert that $this->title is set to a Title.
Definition: File.php:2257
getUnscaledThumb($handlerParams=[])
Get a ThumbnailImage which is the same size as the source.
Definition: File.php:914
userCan($field, User $user=null)
Determine if the current user is allowed to view a particular field of this file, if it's marked as d...
Definition: File.php:2146
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$IP
Definition: WebStart.php:58
getThumbnailSource($params)
Returns the most appropriate source image for the thumbnail, given a target thumbnail size...
Definition: File.php:1241
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1936
getTranscodedPath($suffix=false)
Get the path of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1622
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static singleton()
Get an instance of this class.
Definition: MimeMagic.php:29
getTransformScript()
Definition: File.php:893
FSFile bool $fsFile
False if undefined.
Definition: File.php:110
execute($skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
getRedirectedTitle()
Definition: File.php:2208
getShortDesc()
Definition: File.php:2177
getAvailableLanguages()
Gives a (possibly empty) list of languages to render the file in.
Definition: File.php:574
getLongDesc($file)
Long description.
const DELETE_SOURCE
Definition: File.php:65
iconThumb()
Get a ThumbnailImage representing a file type icon.
Definition: File.php:1377
getArchiveVirtualUrl($suffix=false)
Get the public zone virtual URL for an archived version source file.
Definition: File.php:1728
if(!isset($args[0])) $lang
isSafeFile()
Determines if this media file is in a format that is unlikely to contain viruses or malicious content...
Definition: File.php:785
getThumbPath($suffix=false)
Get the path of the thumbnail directory, or a particular file if $suffix is specified.
Definition: File.php:1610
getTranscodedUrl($suffix=false)
Get the URL of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1702
const TTL_UNCACHEABLE
Idiom for getWithSetCallback() callbacks to avoid calling set()
string $extension
File extension.
Definition: File.php:119
isExpensiveToThumbnail($file)
True if creating thumbnails from the file is large or otherwise resource-intensive.
getStorageKey()
Get the deletion archive key, ".".
Definition: File.php:2127
isHashed()
Definition: File.php:1759
getCommonMetaArray()
Like getMetadata but returns a handler independent array of common values.
Definition: File.php:648
$source
publish($src, $flags=0, array $options=[])
Move or copy a file to its public location.
Definition: File.php:1814
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2022
$wgThumbnailEpoch
If rendered thumbnail files are older than this timestamp, they will be rerendered on demand as if th...
getArchiveThumbUrl($archiveName, $suffix=false)
Get the URL of the archived file's thumbs, or a particular thumb if $suffix is specified.
Definition: File.php:1654
if($ext== 'php'||$ext== 'php5') $mime
Definition: router.php:65
canRender()
Checks if the output of transform() for this file is likely to be valid.
Definition: File.php:733
getThumbnailBucket($desiredWidth, $page=1)
Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistan...
Definition: File.php:489
getArchiveThumbRel($archiveName, $suffix=false)
Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory or a speci...
Definition: File.php:1567
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition: File.php:2247
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2703
getName()
Return the name of this file.
Definition: File.php:296
string $name
The name of a file from its title object.
Definition: File.php:122
getRepo()
Returns the repository.
Definition: File.php:1853
__get($name)
Definition: File.php:204
isLocal()
Returns true if the file comes from the local file repository.
Definition: File.php:1835
restore($versions=[], $unsuppress=false)
Restore all or specified deleted revisions to the given file.
Definition: File.php:1947
formatMetadata($context=false)
Definition: File.php:1822
getThumbVirtualUrl($suffix=false)
Get the virtual URL for a thumbnail file or directory.
Definition: File.php:1746
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
isOld()
Returns true if the image is an old version STUB.
Definition: File.php:1863
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
generateBucketsIfNeeded($params, $flags=0)
Generates chained bucketed thumbnails if needed.
Definition: File.php:1184
title
getCanRender()
Accessor for __get()
Definition: File.php:745
when a variable name is used in a function
Definition: design.txt:93
const MEDIATYPE_UNKNOWN
Definition: defines.php:26
static extensionFromPath($path, $case= 'lowercase')
Get the final extension from a storage or FS path.
getTitle()
Return the associated title object.
Definition: File.php:325
Title string bool $title
Definition: File.php:98
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
Definition: File.php:1496
bool $isSafeFile
Whether this media file is in a format that is unlikely to contain viruses or malicious content...
Definition: File.php:147
static normalizeExtension($extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms...
Definition: File.php:223
purgeEverything()
Purge metadata and all affected pages when the file is created, deleted, or majorly updated...
Definition: File.php:1440
static factory($prefix, $extension= '', $tmpDirectory=null)
Make a new temporary file on the file system.
Definition: TempFSFile.php:55
getRedirected()
Definition: File.php:2201
migrateThumbFile($thumbName)
Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile.
Definition: File.php:1355
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
const DELETED_FILE
Definition: File.php:52
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
getThumbRel($suffix=false)
Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if...
Definition: File.php:1540
getThumbnails()
Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
Definition: File.php:1409
canAnimateThumbnail($file)
If the material is animated, we can animate the thumbnail.
getDefaultRenderLanguage(File $file)
On file types that support renderings in multiple languages, which language is used by default if uns...
getLongDesc()
Definition: File.php:2165
getLength()
Get the duration of a media file in seconds.
Definition: File.php:540
string $hashPath
Relative path including trailing slash.
Definition: File.php:128
const THUMB_FULL_NAME
Definition: File.php:73
getDescriptionText($lang=false)
Get the HTML text of the description page, if available.
Definition: File.php:2036
isVectorized($file)
The material is vectorized and thus scaling is lossless.
getScriptedTransform($image, $script, $params)
Get a MediaTransformOutput object representing an alternate of the transformed output which will call...
getPath()
Return the storage path to the file.
Definition: File.php:416
const RENDER_NOW
Force rendering in the current process.
Definition: File.php:58
move($target)
Move file to the new title.
Definition: File.php:1910
wasDeleted()
Was this file ever deleted from the wiki?
Definition: File.php:1892
Convenience class for dealing with PoolCounters using callbacks.
readOnlyError()
Definition: File.php:1768
isAnimatedImage($file)
The material is an image, and is animated.
wfTempDir()
Tries to get the system directory for temporary files.
static getMain()
Static methods.
mustRender()
Return true if the file is of a type that can't be directly rendered by typical browsers and needs to...
Definition: File.php:759
isTrustedFile()
Returns true if the file is flagged as trusted.
Definition: File.php:851
unserialize($serialized)
Definition: ApiMessage.php:102
getSize()
Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB...
Definition: File.php:695
wfAppendQuery($url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
isDeleted($field)
Is this file a "deleted" file in a private archive? STUB.
Definition: File.php:1874
isVectorized()
Return true if the file is vectorized.
Definition: File.php:554
Class to invalidate the HTML cache of all the pages linking to a given title.
getDescriptionShortUrl()
Definition: File.php:363
isMultipage()
Returns 'true' if this file is a type which supports multiple pages, e.g.
Definition: File.php:1958
getHandler()
Get a MediaHandler instance for this file.
Definition: File.php:1364
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 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 additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
if($limit) $timestamp
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1046
generateAndSaveThumb($tmpFile, $transformParams, $flags)
Generates a thumbnail according to the given parameters and saves it to storage.
Definition: File.php:1117
transform($params, $flags=0)
Transform a media file.
Definition: File.php:1033
$wgThumbnailBuckets
When defined, is an array of image widths used as buckets for thumbnail generation.
const NS_MEDIA
Definition: Defines.php:44
getRel()
Get the path of the file relative to the public zone root.
Definition: File.php:1511
$res
Definition: database.txt:21
getMetadata()
Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB.
Definition: File.php:638
purgeCache($options=[])
Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile.
Definition: File.php:1420
string $lastError
Text of last error.
Definition: File.php:101
getStreamHeaders()
Definition: File.php:2153
Media transform output for images.
resetHistory()
Reset the history pointer to the first element of the history.
Definition: File.php:1486
canAnimateThumbIfAppropriate()
Will the thumbnail be animated if one would expect it to be.
Definition: File.php:609
isMissing()
Definition: File.php:2231
getArchiveRel($suffix=false)
Get the path of an archived file relative to the public zone root.
Definition: File.php:1522
invalidateCache($purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4391
getLastError()
Get last thumbnailing error.
Definition: File.php:1399
$cache
Definition: mcc.php:33
$params
allowInlineDisplay()
Alias for canRender()
Definition: File.php:768
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
getAvailableLanguages(File $file)
Get list of languages file can be viewed in.
array $tmpBucketedThumbCache
Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.
Definition: File.php:153
getViewURL()
Definition: File.php:388
normaliseParams($image, &$params)
Changes the parameter array as necessary, ready for transformation.
getSha1()
Get the SHA-1 base 36 hash of the file.
Definition: File.php:2116
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:535
getDimensionsString()
Definition: File.php:2189
getFullUrl()
Return a fully-qualified URL to the file.
Definition: File.php:374
getVirtualUrl($suffix=false)
Get the public zone virtual URL for a current version source file.
Definition: File.php:1712
getExtension()
Get the file extension, e.g.
Definition: File.php:310
getStreamHeaders($metadata)
Get useful response headers for GET/HEAD requests for a file with the given metadata.
string $redirected
Main part of the title, with underscores (Title::getDBkey)
Definition: File.php:104
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
const PROTO_RELATIVE
Definition: Defines.php:225
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 text
Definition: design.txt:12
const NS_FILE
Definition: Defines.php:62
$wgThumbnailMinimumBucketDistance
When using thumbnail buckets as defined above, this sets the minimum distance to the bucket above the...
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
Definition: File.php:95
static compare(File $a, File $b)
Callback for usort() to do file sorts by name.
Definition: File.php:287
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array change it to the message you want to define you are encouraged to submit patches to MediaWiki s core to add new MIME types to mime types $mimeMagic
Definition: hooks.txt:2159
getMediaType()
Return the type of the media in the file.
Definition: File.php:717
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
isVisible()
Returns true if file exists in the repository and can be included in a page.
Definition: File.php:886
getUrlRel()
Get urlencoded path of the file relative to the public zone root.
Definition: File.php:1555
getBitDepth()
Return the bit depth of the file Overridden by LocalFile STUB.
Definition: File.php:685
convertMetadataVersion($metadata, $version=1)
Convert metadata version.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
getImageSize($filePath)
Get an image size array like that returned by getImageSize(), or false if it can't be determined...
Definition: File.php:2008
const DELETED_USER
Definition: File.php:54
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor'$rcid is used in generating this variable which contains information about the new such as the revision s whether the revision was marked as a minor edit or not
Definition: hooks.txt:1156
generateThumbName($name, $params)
Generate a thumbnail file name from a name and specified parameters.
Definition: File.php:952
const DELETED_RESTRICTED
Definition: File.php:55
getHeight($page=1)
Return the height of the image.
Definition: File.php:476
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:802
string $transformScript
URL of transformscript (for example thumb.php)
Definition: File.php:136
isExpensiveToThumbnail()
True if creating thumbnails from the file is large or otherwise resource-intensive.
Definition: File.php:2267
recordUpload($oldver, $desc, $license= '', $copyStatus= '', $source= '', $watch=false, $timestamp=false, User $user=null)
Record a file upload in the upload log and the image table STUB Overridden by LocalFile.
Definition: File.php:1787
getDimensionsString($file)
Shown in file history box on image description page.
getIsSafeFileUncached()
Uncached accessor.
Definition: File.php:807
static getGeneralLongDesc($file)
Used instead of getLongDesc if there is no handler registered for file.
string $pageCount
Number of pages of a multipage document, or false for documents which aren't multipage documents...
Definition: File.php:133
getDescriptionTouched()
Returns the timestamp (in TS_MW format) of the last change of the description page.
Definition: File.php:2107
$from
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static checkExtensionCompatibility(File $old, $new)
Checks if file extensions are compatible.
Definition: File.php:248
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
const PROTO_CANONICAL
Definition: Defines.php:227
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
getWidth($page=1)
Return the width of the image.
Definition: File.php:462
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition: File.php:2094
getDefaultRenderLanguage()
In files that support multiple language, what is the default language to use if none specified...
Definition: File.php:590
const RAW
Definition: File.php:70
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:116
doTransform($image, $dstPath, $dstUrl, $params, $flags=0)
Get a MediaTransformOutput object representing the transformed output.
getVisibility()
Return the deletion bitfield STUB.
Definition: File.php:1883
exists()
Returns true if file exists in the repository.
Definition: File.php:876
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 name
Definition: design.txt:12
static scaleHeight($srcWidth, $srcHeight, $dstWidth)
Calculate the height of a thumbnail using the source and destination width.
Definition: File.php:1989
__construct($title, $repo)
Call this constructor from child classes.
Definition: File.php:165
getUrl()
Return the URL of the file.
Definition: File.php:347
$license
getShortDesc($file)
Short description.
static getHandler($type)
Get a MediaHandler for a given MIME type from the instance cache.
getOriginalTitle()
Return the title used to find this file.
Definition: File.php:334
Title $redirectTitle
Definition: File.php:139
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1046
Interface for database access objects.
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3145
getThumbUrl($suffix=false)
Get the URL of the thumbnail directory, or a particular file if $suffix is specified.
Definition: File.php:1692
getBucketThumbName($bucket)
Returns the name of the thumb for a given bucket.
Definition: File.php:1320
getCanonicalUrl()
Definition: File.php:381
static makeContentDisposition($type, $filename= '')
Build a Content-Disposition header value per RFC 6266.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1046
bool $canRender
Whether the output of transform() for this file is likely to be valid.
Definition: File.php:142
getTransform($image, $dstPath, $dstUrl, $params)
Get a MediaTransformOutput object representing the transformed output.
redirectedFrom($from)
Definition: File.php:2224
see documentation in includes Linker php for Linker::makeImageLink & $handlerParams
Definition: hooks.txt:1747
isCacheable()
Check if this file object is small and can be cached.
Definition: File.php:2239
createThumb($width, $height=-1)
Create a thumbnail of the image having the specified width/height.
Definition: File.php:991
$wgTrustedMediaFormats
list of trusted media-types and MIME types.
getThumbDisposition($thumbName, $dispositionType= 'inline')
Definition: File.php:1339
getIsSafeFile()
Accessor for __get()
Definition: File.php:798
const FOR_PUBLIC
Definition: File.php:68
load($flags=0)
Load any lazy-loaded file object fields from source.
Definition: File.php:866
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition: File.php:63
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren't multipage do...
Definition: File.php:1968
upgradeRow()
Upgrade the database row if there is one Called by ImagePage STUB.
Definition: File.php:262
static getGeneralShortDesc($file)
Used instead of getShortDesc if there is no handler registered for file.
getCommonMetaArray(File $file)
Get an array of standard (FormatMetadata type) metadata values.
static get($url, $options=[], $caller=__METHOD__)
Simple wrapper for Http::request( 'GET' )
Definition: Http.php:94
string $path
The storage path corresponding to one of the zones.
Definition: File.php:125
supportsBucketing()
Returns whether or not this handler supports the chained generation of thumbnails according to bucket...
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
getArchiveUrl($suffix=false)
Get the URL of the archive directory, or a particular file if $suffix is specified.
Definition: File.php:1634
getUser($type= 'text')
Returns ID or name of user who uploaded the file STUB.
Definition: File.php:531
$wgIgnoreImageErrors
If set, inline scaled images will still produce "" tags ready for output instead of showing an e...
getDescription($audience=self::FOR_PUBLIC, User $user=null)
Get description of file revision STUB.
Definition: File.php:2085
string $repoClass
Required Repository class type.
Definition: File.php:150
thumbName($params, $flags=0)
Return the file name of a thumbnail with the specified parameters.
Definition: File.php:937
isTransformedLocally()
Whether the thumbnails created on the same server as this code is running.
Definition: File.php:2277
getMimeType()
Returns the MIME type of the file.
Definition: File.php:706
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
getZoneUrl($zone, $suffix=false)
Get the URL of the zone directory, or a particular file if $suffix is specified.
Definition: File.php:1675
purgeDescription()
Purge the file description page, but don't go after pages using the file.
Definition: File.php:1428
getHistory($limit=null, $start=null, $end=null, $inc=true)
Return a fragment of the history of file.
Definition: File.php:1463
Basic media transform error class.
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3593
getBucketThumbPath($bucket)
Returns the repo path of the thumb for a given bucket.
Definition: File.php:1310
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491
makeTransformTmpFile($thumbPath)
Creates a temp FS file with the same extension and the thumbnail.
Definition: File.php:1329
$starttime
Definition: api.php:40
getLength($file)
If its an audio file, return the length of the file.