MediaWiki  1.27.1
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  wfDebug( __METHOD__ . " transformation deferred.\n" );
1069  // XXX: Pass in the storage path even though we are not rendering anything
1070  // and the path is supposed to be an FS path. This is due to getScalerType()
1071  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1072  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1073  break;
1074  }
1075  // Check if an up-to-date thumbnail already exists...
1076  wfDebug( __METHOD__ . ": Doing stat for $thumbPath\n" );
1077  if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) {
1078  $timestamp = $this->repo->getFileTimestamp( $thumbPath );
1079  if ( $timestamp !== false && $timestamp >= $wgThumbnailEpoch ) {
1080  // XXX: Pass in the storage path even though we are not rendering anything
1081  // and the path is supposed to be an FS path. This is due to getScalerType()
1082  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1083  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1084  $thumb->setStoragePath( $thumbPath );
1085  break;
1086  }
1087  } elseif ( $flags & self::RENDER_FORCE ) {
1088  wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
1089  }
1090 
1091  // If the backend is ready-only, don't keep generating thumbnails
1092  // only to return transformation errors, just return the error now.
1093  if ( $this->repo->getReadOnlyReason() !== false ) {
1094  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1095  break;
1096  }
1097  }
1098 
1099  $tmpFile = $this->makeTransformTmpFile( $thumbPath );
1100 
1101  if ( !$tmpFile ) {
1102  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1103  } else {
1104  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1105  }
1106  } while ( false );
1107 
1108  return is_object( $thumb ) ? $thumb : false;
1109  }
1110 
1118  public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
1120 
1121  $stats = RequestContext::getMain()->getStats();
1122 
1123  $handler = $this->getHandler();
1124 
1125  $normalisedParams = $transformParams;
1126  $handler->normaliseParams( $this, $normalisedParams );
1127 
1128  $thumbName = $this->thumbName( $normalisedParams );
1129  $thumbUrl = $this->getThumbUrl( $thumbName );
1130  $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
1131 
1132  $tmpThumbPath = $tmpFile->getPath();
1133 
1134  if ( $handler->supportsBucketing() ) {
1135  $this->generateBucketsIfNeeded( $normalisedParams, $flags );
1136  }
1137 
1138  $starttime = microtime( true );
1139 
1140  // Actually render the thumbnail...
1141  $thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1142  $tmpFile->bind( $thumb ); // keep alive with $thumb
1143 
1144  $statTiming = microtime( true ) - $starttime;
1145  $stats->timing( 'media.thumbnail.generate.transform', 1000 * $statTiming );
1146 
1147  if ( !$thumb ) { // bad params?
1148  $thumb = false;
1149  } elseif ( $thumb->isError() ) { // transform error
1151  $this->lastError = $thumb->toText();
1152  // Ignore errors if requested
1153  if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
1154  $thumb = $handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1155  }
1156  } elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
1157  // Copy the thumbnail from the file system into storage...
1158 
1159  $starttime = microtime( true );
1160 
1161  $disposition = $this->getThumbDisposition( $thumbName );
1162  $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
1163  if ( $status->isOK() ) {
1164  $thumb->setStoragePath( $thumbPath );
1165  } else {
1166  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags );
1167  }
1168 
1169  $statTiming = microtime( true ) - $starttime;
1170  $stats->timing( 'media.thumbnail.generate.store', 1000 * $statTiming );
1171 
1172  // Give extensions a chance to do something with this thumbnail...
1173  Hooks::run( 'FileTransformed', [ $this, $thumb, $tmpThumbPath, $thumbPath ] );
1174  }
1175 
1176  return $thumb;
1177  }
1178 
1185  protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
1186  if ( !$this->repo
1187  || !isset( $params['physicalWidth'] )
1188  || !isset( $params['physicalHeight'] )
1189  ) {
1190  return false;
1191  }
1192 
1193  $bucket = $this->getThumbnailBucket( $params['physicalWidth'] );
1194 
1195  if ( !$bucket || $bucket == $params['physicalWidth'] ) {
1196  return false;
1197  }
1198 
1199  $bucketPath = $this->getBucketThumbPath( $bucket );
1200 
1201  if ( $this->repo->fileExists( $bucketPath ) ) {
1202  return false;
1203  }
1204 
1205  $starttime = microtime( true );
1206 
1207  $params['physicalWidth'] = $bucket;
1208  $params['width'] = $bucket;
1209 
1210  $params = $this->getHandler()->sanitizeParamsForBucketing( $params );
1211 
1212  $tmpFile = $this->makeTransformTmpFile( $bucketPath );
1213 
1214  if ( !$tmpFile ) {
1215  return false;
1216  }
1217 
1218  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1219 
1220  $buckettime = microtime( true ) - $starttime;
1221 
1222  if ( !$thumb || $thumb->isError() ) {
1223  return false;
1224  }
1225 
1226  $this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath();
1227  // For the caching to work, we need to make the tmp file survive as long as
1228  // this object exists
1229  $tmpFile->bind( $this );
1230 
1231  RequestContext::getMain()->getStats()->timing(
1232  'media.thumbnail.generate.bucket', 1000 * $buckettime );
1233 
1234  return true;
1235  }
1236 
1242  public function getThumbnailSource( $params ) {
1243  if ( $this->repo
1244  && $this->getHandler()->supportsBucketing()
1245  && isset( $params['physicalWidth'] )
1246  && $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
1247  ) {
1248  if ( $this->getWidth() != 0 ) {
1249  $bucketHeight = round( $this->getHeight() * ( $bucket / $this->getWidth() ) );
1250  } else {
1251  $bucketHeight = 0;
1252  }
1253 
1254  // Try to avoid reading from storage if the file was generated by this script
1255  if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) {
1256  $tmpPath = $this->tmpBucketedThumbCache[$bucket];
1257 
1258  if ( file_exists( $tmpPath ) ) {
1259  return [
1260  'path' => $tmpPath,
1261  'width' => $bucket,
1262  'height' => $bucketHeight
1263  ];
1264  }
1265  }
1266 
1267  $bucketPath = $this->getBucketThumbPath( $bucket );
1268 
1269  if ( $this->repo->fileExists( $bucketPath ) ) {
1270  $fsFile = $this->repo->getLocalReference( $bucketPath );
1271 
1272  if ( $fsFile ) {
1273  return [
1274  'path' => $fsFile->getPath(),
1275  'width' => $bucket,
1276  'height' => $bucketHeight
1277  ];
1278  }
1279  }
1280  }
1281 
1282  // Thumbnailing a very large file could result in network saturation if
1283  // everyone does it at once.
1284  if ( $this->getSize() >= 1e7 ) { // 10MB
1285  $that = $this;
1286  $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
1287  [
1288  'doWork' => function () use ( $that ) {
1289  return $that->getLocalRefPath();
1290  }
1291  ]
1292  );
1293  $srcPath = $work->execute();
1294  } else {
1295  $srcPath = $this->getLocalRefPath();
1296  }
1297 
1298  // Original file
1299  return [
1300  'path' => $srcPath,
1301  'width' => $this->getWidth(),
1302  'height' => $this->getHeight()
1303  ];
1304  }
1305 
1311  protected function getBucketThumbPath( $bucket ) {
1312  $thumbName = $this->getBucketThumbName( $bucket );
1313  return $this->getThumbPath( $thumbName );
1314  }
1315 
1321  protected function getBucketThumbName( $bucket ) {
1322  return $this->thumbName( [ 'physicalWidth' => $bucket ] );
1323  }
1324 
1330  protected function makeTransformTmpFile( $thumbPath ) {
1331  $thumbExt = FileBackend::extensionFromPath( $thumbPath );
1332  return TempFSFile::factory( 'transform_', $thumbExt );
1333  }
1334 
1340  function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) {
1341  $fileName = $this->name; // file name to suggest
1342  $thumbExt = FileBackend::extensionFromPath( $thumbName );
1343  if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) {
1344  $fileName .= ".$thumbExt";
1345  }
1346 
1347  return FileBackend::makeContentDisposition( $dispositionType, $fileName );
1348  }
1349 
1356  function migrateThumbFile( $thumbName ) {
1357  }
1358 
1365  function getHandler() {
1366  if ( !isset( $this->handler ) ) {
1367  $this->handler = MediaHandler::getHandler( $this->getMimeType() );
1368  }
1369 
1370  return $this->handler;
1371  }
1372 
1378  function iconThumb() {
1380  $assetsPath = "$wgResourceBasePath/resources/assets/file-type-icons/";
1381  $assetsDirectory = "$IP/resources/assets/file-type-icons/";
1382 
1383  $try = [ 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' ];
1384  foreach ( $try as $icon ) {
1385  if ( file_exists( $assetsDirectory . $icon ) ) { // always FS
1386  $params = [ 'width' => 120, 'height' => 120 ];
1387 
1388  return new ThumbnailImage( $this, $assetsPath . $icon, false, $params );
1389  }
1390  }
1391 
1392  return null;
1393  }
1394 
1400  function getLastError() {
1401  return $this->lastError;
1402  }
1403 
1410  function getThumbnails() {
1411  return [];
1412  }
1413 
1421  function purgeCache( $options = [] ) {
1422  }
1423 
1429  function purgeDescription() {
1430  $title = $this->getTitle();
1431  if ( $title ) {
1433  $title->purgeSquid();
1434  }
1435  }
1436 
1441  function purgeEverything() {
1442  // Delete thumbnails and refresh file metadata cache
1443  $this->purgeCache();
1444  $this->purgeDescription();
1445 
1446  // Purge cache of all pages using this file
1447  $title = $this->getTitle();
1448  if ( $title ) {
1449  DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
1450  }
1451  }
1452 
1464  function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
1465  return [];
1466  }
1467 
1477  public function nextHistoryLine() {
1478  return false;
1479  }
1480 
1487  public function resetHistory() {
1488  }
1489 
1497  function getHashPath() {
1498  if ( !isset( $this->hashPath ) ) {
1499  $this->assertRepoDefined();
1500  $this->hashPath = $this->repo->getHashPath( $this->getName() );
1501  }
1502 
1503  return $this->hashPath;
1504  }
1505 
1512  function getRel() {
1513  return $this->getHashPath() . $this->getName();
1514  }
1515 
1523  function getArchiveRel( $suffix = false ) {
1524  $path = 'archive/' . $this->getHashPath();
1525  if ( $suffix === false ) {
1526  $path = substr( $path, 0, -1 );
1527  } else {
1528  $path .= $suffix;
1529  }
1530 
1531  return $path;
1532  }
1533 
1541  function getThumbRel( $suffix = false ) {
1542  $path = $this->getRel();
1543  if ( $suffix !== false ) {
1544  $path .= '/' . $suffix;
1545  }
1546 
1547  return $path;
1548  }
1549 
1556  function getUrlRel() {
1557  return $this->getHashPath() . rawurlencode( $this->getName() );
1558  }
1559 
1568  function getArchiveThumbRel( $archiveName, $suffix = false ) {
1569  $path = 'archive/' . $this->getHashPath() . $archiveName . "/";
1570  if ( $suffix === false ) {
1571  $path = substr( $path, 0, -1 );
1572  } else {
1573  $path .= $suffix;
1574  }
1575 
1576  return $path;
1577  }
1578 
1585  function getArchivePath( $suffix = false ) {
1586  $this->assertRepoDefined();
1587 
1588  return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
1589  }
1590 
1598  function getArchiveThumbPath( $archiveName, $suffix = false ) {
1599  $this->assertRepoDefined();
1600 
1601  return $this->repo->getZonePath( 'thumb' ) . '/' .
1602  $this->getArchiveThumbRel( $archiveName, $suffix );
1603  }
1604 
1611  function getThumbPath( $suffix = false ) {
1612  $this->assertRepoDefined();
1613 
1614  return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
1615  }
1616 
1623  function getTranscodedPath( $suffix = false ) {
1624  $this->assertRepoDefined();
1625 
1626  return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix );
1627  }
1628 
1635  function getArchiveUrl( $suffix = false ) {
1636  $this->assertRepoDefined();
1637  $ext = $this->getExtension();
1638  $path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath();
1639  if ( $suffix === false ) {
1640  $path = substr( $path, 0, -1 );
1641  } else {
1642  $path .= rawurlencode( $suffix );
1643  }
1644 
1645  return $path;
1646  }
1647 
1655  function getArchiveThumbUrl( $archiveName, $suffix = false ) {
1656  $this->assertRepoDefined();
1657  $ext = $this->getExtension();
1658  $path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' .
1659  $this->getHashPath() . rawurlencode( $archiveName ) . "/";
1660  if ( $suffix === false ) {
1661  $path = substr( $path, 0, -1 );
1662  } else {
1663  $path .= rawurlencode( $suffix );
1664  }
1665 
1666  return $path;
1667  }
1668 
1676  function getZoneUrl( $zone, $suffix = false ) {
1677  $this->assertRepoDefined();
1678  $ext = $this->getExtension();
1679  $path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel();
1680  if ( $suffix !== false ) {
1681  $path .= '/' . rawurlencode( $suffix );
1682  }
1683 
1684  return $path;
1685  }
1686 
1693  function getThumbUrl( $suffix = false ) {
1694  return $this->getZoneUrl( 'thumb', $suffix );
1695  }
1696 
1703  function getTranscodedUrl( $suffix = false ) {
1704  return $this->getZoneUrl( 'transcoded', $suffix );
1705  }
1706 
1713  function getVirtualUrl( $suffix = false ) {
1714  $this->assertRepoDefined();
1715  $path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
1716  if ( $suffix !== false ) {
1717  $path .= '/' . rawurlencode( $suffix );
1718  }
1719 
1720  return $path;
1721  }
1722 
1729  function getArchiveVirtualUrl( $suffix = false ) {
1730  $this->assertRepoDefined();
1731  $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
1732  if ( $suffix === false ) {
1733  $path = substr( $path, 0, -1 );
1734  } else {
1735  $path .= rawurlencode( $suffix );
1736  }
1737 
1738  return $path;
1739  }
1740 
1747  function getThumbVirtualUrl( $suffix = false ) {
1748  $this->assertRepoDefined();
1749  $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
1750  if ( $suffix !== false ) {
1751  $path .= '/' . rawurlencode( $suffix );
1752  }
1753 
1754  return $path;
1755  }
1756 
1760  function isHashed() {
1761  $this->assertRepoDefined();
1762 
1763  return (bool)$this->repo->getHashLevels();
1764  }
1765 
1769  function readOnlyError() {
1770  throw new MWException( get_class( $this ) . ': write operations are not supported' );
1771  }
1772 
1788  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
1789  $watch = false, $timestamp = false, User $user = null
1790  ) {
1791  $this->readOnlyError();
1792  }
1793 
1815  function publish( $src, $flags = 0, array $options = [] ) {
1816  $this->readOnlyError();
1817  }
1818 
1823  function formatMetadata( $context = false ) {
1824  if ( !$this->getHandler() ) {
1825  return false;
1826  }
1827 
1828  return $this->getHandler()->formatMetadata( $this, $context );
1829  }
1830 
1836  function isLocal() {
1837  return $this->repo && $this->repo->isLocal();
1838  }
1839 
1845  function getRepoName() {
1846  return $this->repo ? $this->repo->getName() : 'unknown';
1847  }
1848 
1854  function getRepo() {
1855  return $this->repo;
1856  }
1857 
1864  function isOld() {
1865  return false;
1866  }
1867 
1875  function isDeleted( $field ) {
1876  return false;
1877  }
1878 
1884  function getVisibility() {
1885  return 0;
1886  }
1887 
1893  function wasDeleted() {
1894  $title = $this->getTitle();
1895 
1896  return $title && $title->isDeletedQuick();
1897  }
1898 
1911  function move( $target ) {
1912  $this->readOnlyError();
1913  }
1914 
1930  function delete( $reason, $suppress = false, $user = null ) {
1931  $this->readOnlyError();
1932  }
1933 
1948  function restore( $versions = [], $unsuppress = false ) {
1949  $this->readOnlyError();
1950  }
1951 
1959  function isMultipage() {
1960  return $this->getHandler() && $this->handler->isMultiPage( $this );
1961  }
1962 
1969  function pageCount() {
1970  if ( !isset( $this->pageCount ) ) {
1971  if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
1972  $this->pageCount = $this->handler->pageCount( $this );
1973  } else {
1974  $this->pageCount = false;
1975  }
1976  }
1977 
1978  return $this->pageCount;
1979  }
1980 
1990  static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
1991  // Exact integer multiply followed by division
1992  if ( $srcWidth == 0 ) {
1993  return 0;
1994  } else {
1995  return round( $srcHeight * $dstWidth / $srcWidth );
1996  }
1997  }
1998 
2009  function getImageSize( $filePath ) {
2010  if ( !$this->getHandler() ) {
2011  return false;
2012  }
2013 
2014  return $this->getHandler()->getImageSize( $this, $filePath );
2015  }
2016 
2023  function getDescriptionUrl() {
2024  if ( $this->repo ) {
2025  return $this->repo->getDescriptionUrl( $this->getName() );
2026  } else {
2027  return false;
2028  }
2029  }
2030 
2037  function getDescriptionText( $lang = false ) {
2038  global $wgLang;
2039 
2040  if ( !$this->repo || !$this->repo->fetchDescription ) {
2041  return false;
2042  }
2043 
2044  $lang = $lang ?: $wgLang;
2045 
2046  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
2047  if ( $renderUrl ) {
2049  $key = $this->repo->getLocalCacheKey(
2050  'RemoteFileDescription',
2051  'url',
2052  $lang->getCode(),
2053  $this->getName()
2054  );
2055 
2056  return $cache->getWithSetCallback(
2057  $key,
2058  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
2059  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl ) {
2060  wfDebug( "Fetching shared description from $renderUrl\n" );
2061  $res = Http::get( $renderUrl, [], __METHOD__ );
2062  if ( !$res ) {
2064  }
2065 
2066  return $res;
2067  }
2068  );
2069  }
2070 
2071  return false;
2072  }
2073 
2086  function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
2087  return null;
2088  }
2089 
2095  function getTimestamp() {
2096  $this->assertRepoDefined();
2097 
2098  return $this->repo->getFileTimestamp( $this->getPath() );
2099  }
2100 
2108  public function getDescriptionTouched() {
2109  return false;
2110  }
2111 
2117  function getSha1() {
2118  $this->assertRepoDefined();
2119 
2120  return $this->repo->getFileSha1( $this->getPath() );
2121  }
2122 
2128  function getStorageKey() {
2129  $hash = $this->getSha1();
2130  if ( !$hash ) {
2131  return false;
2132  }
2133  $ext = $this->getExtension();
2134  $dotExt = $ext === '' ? '' : ".$ext";
2135 
2136  return $hash . $dotExt;
2137  }
2138 
2147  function userCan( $field, User $user = null ) {
2148  return true;
2149  }
2150 
2154  function getStreamHeaders() {
2155  $handler = $this->getHandler();
2156  if ( $handler ) {
2157  return $handler->getStreamHeaders( $this->getMetadata() );
2158  } else {
2159  return [];
2160  }
2161  }
2162 
2166  function getLongDesc() {
2167  $handler = $this->getHandler();
2168  if ( $handler ) {
2169  return $handler->getLongDesc( $this );
2170  } else {
2171  return MediaHandler::getGeneralLongDesc( $this );
2172  }
2173  }
2174 
2178  function getShortDesc() {
2179  $handler = $this->getHandler();
2180  if ( $handler ) {
2181  return $handler->getShortDesc( $this );
2182  } else {
2183  return MediaHandler::getGeneralShortDesc( $this );
2184  }
2185  }
2186 
2190  function getDimensionsString() {
2191  $handler = $this->getHandler();
2192  if ( $handler ) {
2193  return $handler->getDimensionsString( $this );
2194  } else {
2195  return '';
2196  }
2197  }
2198 
2202  function getRedirected() {
2203  return $this->redirected;
2204  }
2205 
2209  function getRedirectedTitle() {
2210  if ( $this->redirected ) {
2211  if ( !$this->redirectTitle ) {
2212  $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
2213  }
2214 
2215  return $this->redirectTitle;
2216  }
2217 
2218  return null;
2219  }
2220 
2225  function redirectedFrom( $from ) {
2226  $this->redirected = $from;
2227  }
2228 
2232  function isMissing() {
2233  return false;
2234  }
2235 
2240  public function isCacheable() {
2241  return true;
2242  }
2243 
2248  protected function assertRepoDefined() {
2249  if ( !( $this->repo instanceof $this->repoClass ) ) {
2250  throw new MWException( "A {$this->repoClass} object is not set for this File.\n" );
2251  }
2252  }
2253 
2258  protected function assertTitleDefined() {
2259  if ( !( $this->title instanceof Title ) ) {
2260  throw new MWException( "A Title object is not set for this File.\n" );
2261  }
2262  }
2263 
2268  public function isExpensiveToThumbnail() {
2269  $handler = $this->getHandler();
2270  return $handler ? $handler->isExpensiveToThumbnail( $this ) : false;
2271  }
2272 
2278  public function isTransformedLocally() {
2279  return true;
2280  }
2281 }
static factory($prefix, $extension= '')
Make a new temporary file on the file system.
Definition: TempFSFile.php:54
getArchivePath($suffix=false)
Get the path of the archived file.
Definition: File.php:1585
getArchiveThumbPath($archiveName, $suffix=false)
Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified.
Definition: File.php:1598
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:1845
MediaHandler $handler
Definition: File.php:113
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
nextHistoryLine()
Return the history of this file, line by line.
Definition: File.php:1477
$context
Definition: load.php:44
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:2258
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:2147
$IP
Definition: WebStart.php:58
getThumbnailSource($params)
Returns the most appropriate source image for the thumbnail, given a target thumbnail size...
Definition: File.php:1242
getTranscodedPath($suffix=false)
Get the path of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1623
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:366
getTransformScript()
Definition: File.php:893
FSFile bool $fsFile
False if undefined.
Definition: File.php:110
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:1798
execute($skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
getRedirectedTitle()
Definition: File.php:2209
getShortDesc()
Definition: File.php:2178
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:1378
getArchiveVirtualUrl($suffix=false)
Get the public zone virtual URL for an archived version source file.
Definition: File.php:1729
if(!isset($args[0])) $lang
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
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:1611
getTranscodedUrl($suffix=false)
Get the URL of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1703
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:2128
isHashed()
Definition: File.php:1760
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:1815
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2023
$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:1655
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:1568
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition: File.php:2248
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
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:1854
__get($name)
Definition: File.php:204
isLocal()
Returns true if the file comes from the local file repository.
Definition: File.php:1836
restore($versions=[], $unsuppress=false)
Restore all or specified deleted revisions to the given file.
Definition: File.php:1948
formatMetadata($context=false)
Definition: File.php:1823
getThumbVirtualUrl($suffix=false)
Get the virtual URL for a thumbnail file or directory.
Definition: File.php:1747
Represents a title within MediaWiki.
Definition: Title.php:34
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:1864
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:1185
getCanRender()
Accessor for __get()
Definition: File.php:745
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:1497
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:1441
getRedirected()
Definition: File.php:2202
migrateThumbFile($thumbName)
Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile.
Definition: File.php:1356
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:1541
getThumbnails()
Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
Definition: File.php:1410
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:2166
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:2037
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:1911
wasDeleted()
Was this file ever deleted from the wiki?
Definition: File.php:1893
Convenience class for dealing with PoolCounters using callbacks.
when a variable name is used in a function
Definition: design.txt:93
readOnlyError()
Definition: File.php:1769
isAnimatedImage($file)
The material is an image, and is animated.
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:1875
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:1959
getHandler()
Get a MediaHandler instance for this file.
Definition: File.php:1365
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:1004
generateAndSaveThumb($tmpFile, $transformParams, $flags)
Generates a thumbnail according to the given parameters and saves it to storage.
Definition: File.php:1118
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:57
getRel()
Get the path of the file relative to the public zone root.
Definition: File.php:1512
$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:1421
string $lastError
Text of last error.
Definition: File.php:101
getStreamHeaders()
Definition: File.php:2154
Media transform output for images.
resetHistory()
Reset the history pointer to the first element of the history.
Definition: File.php:1487
canAnimateThumbIfAppropriate()
Will the thumbnail be animated if one would expect it to be.
Definition: File.php:609
isMissing()
Definition: File.php:2232
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 just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing 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
getArchiveRel($suffix=false)
Get the path of an archived file relative to the public zone root.
Definition: File.php:1523
invalidateCache($purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4367
const MEDIATYPE_UNKNOWN
Definition: Defines.php:113
getLastError()
Get last thumbnailing error.
Definition: File.php:1400
$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:2117
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
title
getDimensionsString()
Definition: File.php:2190
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:1713
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.
static addUpdate(DeferrableUpdate $update, $type=self::POSTSEND)
Add an update to the deferred list.
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:263
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:75
$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
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:1556
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:2009
const DELETED_USER
Definition: File.php:54
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:762
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:2268
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:1788
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:2108
$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:265
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:2095
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:1884
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:1990
__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:1004
Interface for database access objects.
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:3123
getThumbUrl($suffix=false)
Get the URL of the thumbnail directory, or a particular file if $suffix is specified.
Definition: File.php:1693
getBucketThumbName($bucket)
Returns the name of the thumb for a given bucket.
Definition: File.php:1321
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:1004
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:2225
see documentation in includes Linker php for Linker::makeImageLink & $handlerParams
Definition: hooks.txt:1610
isCacheable()
Check if this file object is small and can be cached.
Definition: File.php:2240
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:1340
getIsSafeFile()
Accessor for __get()
Definition: File.php:798
$version
Definition: parserTests.php:85
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:1969
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' )
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
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 existing 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:1996
getArchiveUrl($suffix=false)
Get the URL of the archive directory, or a particular file if $suffix is specified.
Definition: File.php:1635
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:2086
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:2278
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:2338
getZoneUrl($zone, $suffix=false)
Get the URL of the zone directory, or a particular file if $suffix is specified.
Definition: File.php:1676
purgeDescription()
Purge the file description page, but don't go after pages using the file.
Definition: File.php:1429
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
getHistory($limit=null, $start=null, $end=null, $inc=true)
Return a fragment of the history of file.
Definition: File.php:1464
Basic media transform error class.
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3569
getBucketThumbPath($bucket)
Returns the repo path of the thumb for a given bucket.
Definition: File.php:1311
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:2338
makeTransformTmpFile($thumbPath)
Creates a temp FS file with the same extension and the thumbnail.
Definition: File.php:1330
$starttime
Definition: api.php:40
getLength($file)
If its an audio file, return the length of the file.