MediaWiki  master
File.php
Go to the documentation of this file.
1 <?php
10 
33 // @phan-file-suppress PhanTypeMissingReturn false positives
61 abstract class File implements IDBAccessObject {
62  // Bitfield values akin to the Revision deletion constants
63  const DELETED_FILE = 1;
64  const DELETED_COMMENT = 2;
65  const DELETED_USER = 4;
66  const DELETED_RESTRICTED = 8;
67 
69  const RENDER_NOW = 1;
74  const RENDER_FORCE = 2;
75 
76  const DELETE_SOURCE = 1;
77 
78  // Audience options for File::getDescription()
79  const FOR_PUBLIC = 1;
80  const FOR_THIS_USER = 2;
81  const RAW = 3;
82 
83  // Options for File::thumbName()
84  const THUMB_FULL_NAME = 1;
85 
106  public $repo;
107 
109  protected $title;
110 
112  protected $lastError;
113 
115  protected $redirected;
116 
118  protected $redirectedTitle;
119 
121  protected $fsFile;
122 
124  protected $handler;
125 
127  protected $url;
128 
130  protected $extension;
131 
133  protected $name;
134 
136  protected $path;
137 
139  protected $hashPath;
140 
144  protected $pageCount;
145 
147  protected $transformScript;
148 
150  protected $redirectTitle;
151 
153  protected $canRender;
154 
158  protected $isSafeFile;
159 
162 
164  protected $tmpBucketedThumbCache = [];
165 
176  function __construct( $title, $repo ) {
177  // Some subclasses do not use $title, but set name/title some other way
178  if ( $title !== false ) {
179  $title = self::normalizeTitle( $title, 'exception' );
180  }
181  $this->title = $title;
182  $this->repo = $repo;
183  }
184 
194  static function normalizeTitle( $title, $exception = false ) {
195  $ret = $title;
196  if ( $ret instanceof Title ) {
197  # Normalize NS_MEDIA -> NS_FILE
198  if ( $ret->getNamespace() == NS_MEDIA ) {
199  $ret = Title::makeTitleSafe( NS_FILE, $ret->getDBkey() );
200  # Sanity check the title namespace
201  } elseif ( $ret->getNamespace() !== NS_FILE ) {
202  $ret = null;
203  }
204  } else {
205  # Convert strings to Title objects
206  $ret = Title::makeTitleSafe( NS_FILE, (string)$ret );
207  }
208  if ( !$ret && $exception !== false ) {
209  throw new MWException( "`$title` is not a valid file title." );
210  }
211 
212  return $ret;
213  }
214 
215  function __get( $name ) {
216  $function = [ $this, 'get' . ucfirst( $name ) ];
217  if ( !is_callable( $function ) ) {
218  return null;
219  } else {
220  $this->$name = $function();
221 
222  return $this->$name;
223  }
224  }
225 
234  static function normalizeExtension( $extension ) {
235  $lower = strtolower( $extension );
236  $squish = [
237  'htm' => 'html',
238  'jpeg' => 'jpg',
239  'mpeg' => 'mpg',
240  'tiff' => 'tif',
241  'ogv' => 'ogg' ];
242  if ( isset( $squish[$lower] ) ) {
243  return $squish[$lower];
244  } elseif ( preg_match( '/^[0-9a-z]+$/', $lower ) ) {
245  return $lower;
246  } else {
247  return '';
248  }
249  }
250 
259  static function checkExtensionCompatibility( File $old, $new ) {
260  $oldMime = $old->getMimeType();
261  $n = strrpos( $new, '.' );
262  $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' );
264 
265  return $mimeMagic->isMatchingExtension( $newExt, $oldMime );
266  }
267 
273  function upgradeRow() {
274  }
275 
283  public static function splitMime( $mime ) {
284  if ( strpos( $mime, '/' ) !== false ) {
285  return explode( '/', $mime, 2 );
286  } else {
287  return [ $mime, 'unknown' ];
288  }
289  }
290 
298  public static function compare( File $a, File $b ) {
299  return strcmp( $a->getName(), $b->getName() );
300  }
301 
307  public function getName() {
308  if ( !isset( $this->name ) ) {
309  $this->assertRepoDefined();
310  $this->name = $this->repo->getNameFromTitle( $this->title );
311  }
312 
313  return $this->name;
314  }
315 
321  function getExtension() {
322  if ( !isset( $this->extension ) ) {
323  $n = strrpos( $this->getName(), '.' );
324  $this->extension = self::normalizeExtension(
325  $n ? substr( $this->getName(), $n + 1 ) : '' );
326  }
327 
328  return $this->extension;
329  }
330 
336  public function getTitle() {
337  return $this->title;
338  }
339 
345  public function getOriginalTitle() {
346  if ( $this->redirected ) {
347  return $this->getRedirectedTitle();
348  }
349 
350  return $this->title;
351  }
352 
358  public function getUrl() {
359  if ( !isset( $this->url ) ) {
360  $this->assertRepoDefined();
361  $ext = $this->getExtension();
362  $this->url = $this->repo->getZoneUrl( 'public', $ext ) . '/' . $this->getUrlRel();
363  }
364 
365  return $this->url;
366  }
367 
374  public function getDescriptionShortUrl() {
375  return null;
376  }
377 
385  public function getFullUrl() {
386  return wfExpandUrl( $this->getUrl(), PROTO_RELATIVE );
387  }
388 
392  public function getCanonicalUrl() {
393  return wfExpandUrl( $this->getUrl(), PROTO_CANONICAL );
394  }
395 
399  function getViewURL() {
400  if ( $this->mustRender() ) {
401  if ( $this->canRender() ) {
402  return $this->createThumb( $this->getWidth() );
403  } else {
404  wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() .
405  ' (' . $this->getMimeType() . "), but can't!\n" );
406 
407  return $this->getUrl(); # hm... return NULL?
408  }
409  } else {
410  return $this->getUrl();
411  }
412  }
413 
427  public function getPath() {
428  if ( !isset( $this->path ) ) {
429  $this->assertRepoDefined();
430  $this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel();
431  }
432 
433  return $this->path;
434  }
435 
443  public function getLocalRefPath() {
444  $this->assertRepoDefined();
445  if ( !isset( $this->fsFile ) ) {
446  $starttime = microtime( true );
447  $this->fsFile = $this->repo->getLocalReference( $this->getPath() );
448 
449  $statTiming = microtime( true ) - $starttime;
450  MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
451  'media.thumbnail.generate.fetchoriginal', 1000 * $statTiming );
452 
453  if ( !$this->fsFile ) {
454  $this->fsFile = false; // null => false; cache negative hits
455  }
456  }
457 
458  return ( $this->fsFile )
459  ? $this->fsFile->getPath()
460  : false;
461  }
462 
473  public function getWidth( $page = 1 ) {
474  return false;
475  }
476 
487  public function getHeight( $page = 1 ) {
488  return false;
489  }
490 
500  public function getThumbnailBucket( $desiredWidth, $page = 1 ) {
502 
503  $imageWidth = $this->getWidth( $page );
504 
505  if ( $imageWidth === false ) {
506  return false;
507  }
508 
509  if ( $desiredWidth > $imageWidth ) {
510  return false;
511  }
512 
513  if ( !$wgThumbnailBuckets ) {
514  return false;
515  }
516 
517  $sortedBuckets = $wgThumbnailBuckets;
518 
519  sort( $sortedBuckets );
520 
521  foreach ( $sortedBuckets as $bucket ) {
522  if ( $bucket >= $imageWidth ) {
523  return false;
524  }
525 
526  if ( $bucket - $wgThumbnailMinimumBucketDistance > $desiredWidth ) {
527  return $bucket;
528  }
529  }
530 
531  // Image is bigger than any available bucket
532  return false;
533  }
534 
542  public function getUser( $type = 'text' ) {
543  return null;
544  }
545 
551  public function getLength() {
552  $handler = $this->getHandler();
553  if ( $handler ) {
554  return $handler->getLength( $this );
555  } else {
556  return 0;
557  }
558  }
559 
565  public function isVectorized() {
566  $handler = $this->getHandler();
567  if ( $handler ) {
568  return $handler->isVectorized( $this );
569  } else {
570  return false;
571  }
572  }
573 
585  public function getAvailableLanguages() {
586  $handler = $this->getHandler();
587  if ( $handler ) {
588  return $handler->getAvailableLanguages( $this );
589  } else {
590  return [];
591  }
592  }
593 
601  public function getMatchedLanguage( $userPreferredLanguage ) {
602  $handler = $this->getHandler();
603  if ( $handler ) {
605  $userPreferredLanguage,
607  );
608  }
609 
610  return null;
611  }
612 
620  public function getDefaultRenderLanguage() {
621  $handler = $this->getHandler();
622  if ( $handler ) {
623  return $handler->getDefaultRenderLanguage( $this );
624  } else {
625  return null;
626  }
627  }
628 
639  public function canAnimateThumbIfAppropriate() {
640  $handler = $this->getHandler();
641  if ( !$handler ) {
642  // We cannot handle image whatsoever, thus
643  // one would not expect it to be animated
644  // so true.
645  return true;
646  }
647 
648  return !$this->allowInlineDisplay()
649  // Image is not animated, so one would
650  // not expect thumb to be
651  || !$handler->isAnimatedImage( $this )
652  // Image is animated, but thumbnail isn't.
653  // This is unexpected to the user.
654  || $handler->canAnimateThumbnail( $this );
655  }
656 
663  public function getMetadata() {
664  return false;
665  }
666 
673  public function getCommonMetaArray() {
674  $handler = $this->getHandler();
675 
676  if ( !$handler ) {
677  return false;
678  }
679 
680  return $handler->getCommonMetaArray( $this );
681  }
682 
691  public function convertMetadataVersion( $metadata, $version ) {
692  $handler = $this->getHandler();
693  if ( !is_array( $metadata ) ) {
694  // Just to make the return type consistent
695  $metadata = unserialize( $metadata );
696  }
697  if ( $handler ) {
698  return $handler->convertMetadataVersion( $metadata, $version );
699  } else {
700  return $metadata;
701  }
702  }
703 
710  public function getBitDepth() {
711  return 0;
712  }
713 
720  public function getSize() {
721  return false;
722  }
723 
731  function getMimeType() {
732  return 'unknown/unknown';
733  }
734 
742  function getMediaType() {
743  return MEDIATYPE_UNKNOWN;
744  }
745 
758  function canRender() {
759  if ( !isset( $this->canRender ) ) {
760  $this->canRender = $this->getHandler() && $this->handler->canRender( $this ) && $this->exists();
761  }
762 
763  return $this->canRender;
764  }
765 
770  protected function getCanRender() {
771  return $this->canRender();
772  }
773 
784  function mustRender() {
785  return $this->getHandler() && $this->handler->mustRender( $this );
786  }
787 
793  function allowInlineDisplay() {
794  return $this->canRender();
795  }
796 
810  function isSafeFile() {
811  if ( !isset( $this->isSafeFile ) ) {
812  $this->isSafeFile = $this->getIsSafeFileUncached();
813  }
814 
815  return $this->isSafeFile;
816  }
817 
823  protected function getIsSafeFile() {
824  return $this->isSafeFile();
825  }
826 
832  protected function getIsSafeFileUncached() {
833  global $wgTrustedMediaFormats;
834 
835  if ( $this->allowInlineDisplay() ) {
836  return true;
837  }
838  if ( $this->isTrustedFile() ) {
839  return true;
840  }
841 
842  $type = $this->getMediaType();
843  $mime = $this->getMimeType();
844  # wfDebug( "LocalFile::isSafeFile: type= $type, mime= $mime\n" );
845 
846  if ( !$type || $type === MEDIATYPE_UNKNOWN ) {
847  return false; # unknown type, not trusted
848  }
849  if ( in_array( $type, $wgTrustedMediaFormats ) ) {
850  return true;
851  }
852 
853  if ( $mime === "unknown/unknown" ) {
854  return false; # unknown type, not trusted
855  }
856  if ( in_array( $mime, $wgTrustedMediaFormats ) ) {
857  return true;
858  }
859 
860  return false;
861  }
862 
876  function isTrustedFile() {
877  # this could be implemented to check a flag in the database,
878  # look for signatures, etc
879  return false;
880  }
881 
891  public function load( $flags = 0 ) {
892  }
893 
901  public function exists() {
902  return $this->getPath() && $this->repo->fileExists( $this->path );
903  }
904 
911  public function isVisible() {
912  return $this->exists();
913  }
914 
918  function getTransformScript() {
919  if ( !isset( $this->transformScript ) ) {
920  $this->transformScript = false;
921  if ( $this->repo ) {
922  $script = $this->repo->getThumbScriptUrl();
923  if ( $script ) {
924  $this->transformScript = wfAppendQuery( $script, [ 'f' => $this->getName() ] );
925  }
926  }
927  }
928 
929  return $this->transformScript;
930  }
931 
939  function getUnscaledThumb( $handlerParams = [] ) {
940  $hp =& $handlerParams;
941  $page = $hp['page'] ?? false;
942  $width = $this->getWidth( $page );
943  if ( !$width ) {
944  return $this->iconThumb();
945  }
946  $hp['width'] = $width;
947  // be sure to ignore any height specification as well (T64258)
948  unset( $hp['height'] );
949 
950  return $this->transform( $hp );
951  }
952 
962  public function thumbName( $params, $flags = 0 ) {
963  $name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) )
964  ? $this->repo->nameForThumb( $this->getName() )
965  : $this->getName();
966 
967  return $this->generateThumbName( $name, $params );
968  }
969 
977  public function generateThumbName( $name, $params ) {
978  if ( !$this->getHandler() ) {
979  return null;
980  }
981  $extension = $this->getExtension();
982  list( $thumbExt, ) = $this->getHandler()->getThumbType(
983  $extension, $this->getMimeType(), $params );
984  $thumbName = $this->getHandler()->makeParamString( $params );
985 
986  if ( $this->repo->supportsSha1URLs() ) {
987  $thumbName .= '-' . $this->getSha1() . '.' . $thumbExt;
988  } else {
989  $thumbName .= '-' . $name;
990 
991  if ( $thumbExt != $extension ) {
992  $thumbName .= ".$thumbExt";
993  }
994  }
995 
996  return $thumbName;
997  }
998 
1016  public function createThumb( $width, $height = -1 ) {
1017  $params = [ 'width' => $width ];
1018  if ( $height != -1 ) {
1019  $params['height'] = $height;
1020  }
1021  $thumb = $this->transform( $params );
1022  if ( !$thumb || $thumb->isError() ) {
1023  return '';
1024  }
1025 
1026  return $thumb->getUrl();
1027  }
1028 
1038  protected function transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags ) {
1039  global $wgIgnoreImageErrors;
1040 
1041  $handler = $this->getHandler();
1042  if ( $handler && $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
1043  return $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1044  } else {
1045  return new MediaTransformError( 'thumbnail_error',
1046  $params['width'], 0, wfMessage( 'thumbnail-dest-create' ) );
1047  }
1048  }
1049 
1058  function transform( $params, $flags = 0 ) {
1059  global $wgThumbnailEpoch;
1060 
1061  do {
1062  if ( !$this->canRender() ) {
1063  $thumb = $this->iconThumb();
1064  break; // not a bitmap or renderable image, don't try
1065  }
1066 
1067  // Get the descriptionUrl to embed it as comment into the thumbnail. T21791.
1068  $descriptionUrl = $this->getDescriptionUrl();
1069  if ( $descriptionUrl ) {
1070  $params['descriptionUrl'] = wfExpandUrl( $descriptionUrl, PROTO_CANONICAL );
1071  }
1072 
1073  $handler = $this->getHandler();
1074  $script = $this->getTransformScript();
1075  if ( $script && !( $flags & self::RENDER_NOW ) ) {
1076  // Use a script to transform on client request, if possible
1077  $thumb = $handler->getScriptedTransform( $this, $script, $params );
1078  if ( $thumb ) {
1079  break;
1080  }
1081  }
1082 
1083  $normalisedParams = $params;
1084  $handler->normaliseParams( $this, $normalisedParams );
1085 
1086  $thumbName = $this->thumbName( $normalisedParams );
1087  $thumbUrl = $this->getThumbUrl( $thumbName );
1088  $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
1089 
1090  if ( $this->repo ) {
1091  // Defer rendering if a 404 handler is set up...
1092  if ( $this->repo->canTransformVia404() && !( $flags & self::RENDER_NOW ) ) {
1093  // XXX: Pass in the storage path even though we are not rendering anything
1094  // and the path is supposed to be an FS path. This is due to getScalerType()
1095  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1096  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1097  break;
1098  }
1099  // Check if an up-to-date thumbnail already exists...
1100  wfDebug( __METHOD__ . ": Doing stat for $thumbPath\n" );
1101  if ( !( $flags & self::RENDER_FORCE ) && $this->repo->fileExists( $thumbPath ) ) {
1102  $timestamp = $this->repo->getFileTimestamp( $thumbPath );
1103  if ( $timestamp !== false && $timestamp >= $wgThumbnailEpoch ) {
1104  // XXX: Pass in the storage path even though we are not rendering anything
1105  // and the path is supposed to be an FS path. This is due to getScalerType()
1106  // getting called on the path and clobbering $thumb->getUrl() if it's false.
1107  $thumb = $handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
1108  $thumb->setStoragePath( $thumbPath );
1109  break;
1110  }
1111  } elseif ( $flags & self::RENDER_FORCE ) {
1112  wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
1113  }
1114 
1115  // If the backend is ready-only, don't keep generating thumbnails
1116  // only to return transformation errors, just return the error now.
1117  if ( $this->repo->getReadOnlyReason() !== false ) {
1118  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1119  break;
1120  }
1121  }
1122 
1123  $tmpFile = $this->makeTransformTmpFile( $thumbPath );
1124 
1125  if ( !$tmpFile ) {
1126  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
1127  } else {
1128  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1129  }
1130  } while ( false );
1131 
1132  return is_object( $thumb ) ? $thumb : false;
1133  }
1134 
1142  public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
1143  global $wgIgnoreImageErrors;
1144 
1145  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
1146 
1147  $handler = $this->getHandler();
1148 
1149  $normalisedParams = $transformParams;
1150  $handler->normaliseParams( $this, $normalisedParams );
1151 
1152  $thumbName = $this->thumbName( $normalisedParams );
1153  $thumbUrl = $this->getThumbUrl( $thumbName );
1154  $thumbPath = $this->getThumbPath( $thumbName ); // final thumb path
1155 
1156  $tmpThumbPath = $tmpFile->getPath();
1157 
1158  if ( $handler->supportsBucketing() ) {
1159  $this->generateBucketsIfNeeded( $normalisedParams, $flags );
1160  }
1161 
1162  $starttime = microtime( true );
1163 
1164  // Actually render the thumbnail...
1165  $thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1166  $tmpFile->bind( $thumb ); // keep alive with $thumb
1167 
1168  $statTiming = microtime( true ) - $starttime;
1169  $stats->timing( 'media.thumbnail.generate.transform', 1000 * $statTiming );
1170 
1171  if ( !$thumb ) { // bad params?
1172  $thumb = false;
1173  } elseif ( $thumb->isError() ) { // transform error
1175  $this->lastError = $thumb->toText();
1176  // Ignore errors if requested
1177  if ( $wgIgnoreImageErrors && !( $flags & self::RENDER_NOW ) ) {
1178  $thumb = $handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
1179  }
1180  } elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
1181  // Copy the thumbnail from the file system into storage...
1182 
1183  $starttime = microtime( true );
1184 
1185  $disposition = $this->getThumbDisposition( $thumbName );
1186  $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
1187  if ( $status->isOK() ) {
1188  $thumb->setStoragePath( $thumbPath );
1189  } else {
1190  $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags );
1191  }
1192 
1193  $statTiming = microtime( true ) - $starttime;
1194  $stats->timing( 'media.thumbnail.generate.store', 1000 * $statTiming );
1195 
1196  // Give extensions a chance to do something with this thumbnail...
1197  Hooks::run( 'FileTransformed', [ $this, $thumb, $tmpThumbPath, $thumbPath ] );
1198  }
1199 
1200  return $thumb;
1201  }
1202 
1209  protected function generateBucketsIfNeeded( $params, $flags = 0 ) {
1210  if ( !$this->repo
1211  || !isset( $params['physicalWidth'] )
1212  || !isset( $params['physicalHeight'] )
1213  ) {
1214  return false;
1215  }
1216 
1217  $bucket = $this->getThumbnailBucket( $params['physicalWidth'] );
1218 
1219  if ( !$bucket || $bucket == $params['physicalWidth'] ) {
1220  return false;
1221  }
1222 
1223  $bucketPath = $this->getBucketThumbPath( $bucket );
1224 
1225  if ( $this->repo->fileExists( $bucketPath ) ) {
1226  return false;
1227  }
1228 
1229  $starttime = microtime( true );
1230 
1231  $params['physicalWidth'] = $bucket;
1232  $params['width'] = $bucket;
1233 
1234  $params = $this->getHandler()->sanitizeParamsForBucketing( $params );
1235 
1236  $tmpFile = $this->makeTransformTmpFile( $bucketPath );
1237 
1238  if ( !$tmpFile ) {
1239  return false;
1240  }
1241 
1242  $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags );
1243 
1244  $buckettime = microtime( true ) - $starttime;
1245 
1246  if ( !$thumb || $thumb->isError() ) {
1247  return false;
1248  }
1249 
1250  $this->tmpBucketedThumbCache[$bucket] = $tmpFile->getPath();
1251  // For the caching to work, we need to make the tmp file survive as long as
1252  // this object exists
1253  $tmpFile->bind( $this );
1254 
1255  MediaWikiServices::getInstance()->getStatsdDataFactory()->timing(
1256  'media.thumbnail.generate.bucket', 1000 * $buckettime );
1257 
1258  return true;
1259  }
1260 
1266  public function getThumbnailSource( $params ) {
1267  if ( $this->repo
1268  && $this->getHandler()->supportsBucketing()
1269  && isset( $params['physicalWidth'] )
1270  && $bucket = $this->getThumbnailBucket( $params['physicalWidth'] )
1271  ) {
1272  if ( $this->getWidth() != 0 ) {
1273  $bucketHeight = round( $this->getHeight() * ( $bucket / $this->getWidth() ) );
1274  } else {
1275  $bucketHeight = 0;
1276  }
1277 
1278  // Try to avoid reading from storage if the file was generated by this script
1279  if ( isset( $this->tmpBucketedThumbCache[$bucket] ) ) {
1280  $tmpPath = $this->tmpBucketedThumbCache[$bucket];
1281 
1282  if ( file_exists( $tmpPath ) ) {
1283  return [
1284  'path' => $tmpPath,
1285  'width' => $bucket,
1286  'height' => $bucketHeight
1287  ];
1288  }
1289  }
1290 
1291  $bucketPath = $this->getBucketThumbPath( $bucket );
1292 
1293  if ( $this->repo->fileExists( $bucketPath ) ) {
1294  $fsFile = $this->repo->getLocalReference( $bucketPath );
1295 
1296  if ( $fsFile ) {
1297  return [
1298  'path' => $fsFile->getPath(),
1299  'width' => $bucket,
1300  'height' => $bucketHeight
1301  ];
1302  }
1303  }
1304  }
1305 
1306  // Thumbnailing a very large file could result in network saturation if
1307  // everyone does it at once.
1308  if ( $this->getSize() >= 1e7 ) { // 10MB
1309  $work = new PoolCounterWorkViaCallback( 'GetLocalFileCopy', sha1( $this->getName() ),
1310  [
1311  'doWork' => function () {
1312  return $this->getLocalRefPath();
1313  }
1314  ]
1315  );
1316  $srcPath = $work->execute();
1317  } else {
1318  $srcPath = $this->getLocalRefPath();
1319  }
1320 
1321  // Original file
1322  return [
1323  'path' => $srcPath,
1324  'width' => $this->getWidth(),
1325  'height' => $this->getHeight()
1326  ];
1327  }
1328 
1334  protected function getBucketThumbPath( $bucket ) {
1335  $thumbName = $this->getBucketThumbName( $bucket );
1336  return $this->getThumbPath( $thumbName );
1337  }
1338 
1344  protected function getBucketThumbName( $bucket ) {
1345  return $this->thumbName( [ 'physicalWidth' => $bucket ] );
1346  }
1347 
1353  protected function makeTransformTmpFile( $thumbPath ) {
1354  $thumbExt = FileBackend::extensionFromPath( $thumbPath );
1355  return TempFSFile::factory( 'transform_', $thumbExt, wfTempDir() );
1356  }
1357 
1363  function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) {
1364  $fileName = $this->name; // file name to suggest
1365  $thumbExt = FileBackend::extensionFromPath( $thumbName );
1366  if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) {
1367  $fileName .= ".$thumbExt";
1368  }
1369 
1370  return FileBackend::makeContentDisposition( $dispositionType, $fileName );
1371  }
1372 
1379  function migrateThumbFile( $thumbName ) {
1380  }
1381 
1388  function getHandler() {
1389  if ( !isset( $this->handler ) ) {
1390  $this->handler = MediaHandler::getHandler( $this->getMimeType() );
1391  }
1392 
1393  return $this->handler;
1394  }
1395 
1401  function iconThumb() {
1402  global $wgResourceBasePath, $IP;
1403  $assetsPath = "$wgResourceBasePath/resources/assets/file-type-icons/";
1404  $assetsDirectory = "$IP/resources/assets/file-type-icons/";
1405 
1406  $try = [ 'fileicon-' . $this->getExtension() . '.png', 'fileicon.png' ];
1407  foreach ( $try as $icon ) {
1408  if ( file_exists( $assetsDirectory . $icon ) ) { // always FS
1409  $params = [ 'width' => 120, 'height' => 120 ];
1410 
1411  return new ThumbnailImage( $this, $assetsPath . $icon, false, $params );
1412  }
1413  }
1414 
1415  return null;
1416  }
1417 
1423  function getLastError() {
1424  return $this->lastError;
1425  }
1426 
1433  function getThumbnails() {
1434  return [];
1435  }
1436 
1444  function purgeCache( $options = [] ) {
1445  }
1446 
1452  function purgeDescription() {
1453  $title = $this->getTitle();
1454  if ( $title ) {
1456  $title->purgeSquid();
1457  }
1458  }
1459 
1464  function purgeEverything() {
1465  // Delete thumbnails and refresh file metadata cache
1466  $this->purgeCache();
1467  $this->purgeDescription();
1468 
1469  // Purge cache of all pages using this file
1470  $title = $this->getTitle();
1471  if ( $title ) {
1473  new HTMLCacheUpdate( $title, 'imagelinks', 'file-purge' )
1474  );
1475  }
1476  }
1477 
1489  function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
1490  return [];
1491  }
1492 
1502  public function nextHistoryLine() {
1503  return false;
1504  }
1505 
1512  public function resetHistory() {
1513  }
1514 
1522  function getHashPath() {
1523  if ( !isset( $this->hashPath ) ) {
1524  $this->assertRepoDefined();
1525  $this->hashPath = $this->repo->getHashPath( $this->getName() );
1526  }
1527 
1528  return $this->hashPath;
1529  }
1530 
1537  function getRel() {
1538  return $this->getHashPath() . $this->getName();
1539  }
1540 
1548  function getArchiveRel( $suffix = false ) {
1549  $path = 'archive/' . $this->getHashPath();
1550  if ( $suffix === false ) {
1551  $path = rtrim( $path, '/' );
1552  } else {
1553  $path .= $suffix;
1554  }
1555 
1556  return $path;
1557  }
1558 
1566  function getThumbRel( $suffix = false ) {
1567  $path = $this->getRel();
1568  if ( $suffix !== false ) {
1569  $path .= '/' . $suffix;
1570  }
1571 
1572  return $path;
1573  }
1574 
1581  function getUrlRel() {
1582  return $this->getHashPath() . rawurlencode( $this->getName() );
1583  }
1584 
1593  function getArchiveThumbRel( $archiveName, $suffix = false ) {
1594  $path = $this->getArchiveRel( $archiveName );
1595  if ( $suffix !== false ) {
1596  $path .= '/' . $suffix;
1597  }
1598 
1599  return $path;
1600  }
1601 
1608  function getArchivePath( $suffix = false ) {
1609  $this->assertRepoDefined();
1610 
1611  return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix );
1612  }
1613 
1621  function getArchiveThumbPath( $archiveName, $suffix = false ) {
1622  $this->assertRepoDefined();
1623 
1624  return $this->repo->getZonePath( 'thumb' ) . '/' .
1625  $this->getArchiveThumbRel( $archiveName, $suffix );
1626  }
1627 
1634  function getThumbPath( $suffix = false ) {
1635  $this->assertRepoDefined();
1636 
1637  return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix );
1638  }
1639 
1646  function getTranscodedPath( $suffix = false ) {
1647  $this->assertRepoDefined();
1648 
1649  return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix );
1650  }
1651 
1658  function getArchiveUrl( $suffix = false ) {
1659  $this->assertRepoDefined();
1660  $ext = $this->getExtension();
1661  $path = $this->repo->getZoneUrl( 'public', $ext ) . '/archive/' . $this->getHashPath();
1662  if ( $suffix === false ) {
1663  $path = rtrim( $path, '/' );
1664  } else {
1665  $path .= rawurlencode( $suffix );
1666  }
1667 
1668  return $path;
1669  }
1670 
1678  function getArchiveThumbUrl( $archiveName, $suffix = false ) {
1679  $this->assertRepoDefined();
1680  $ext = $this->getExtension();
1681  $path = $this->repo->getZoneUrl( 'thumb', $ext ) . '/archive/' .
1682  $this->getHashPath() . rawurlencode( $archiveName );
1683  if ( $suffix !== false ) {
1684  $path .= '/' . rawurlencode( $suffix );
1685  }
1686 
1687  return $path;
1688  }
1689 
1697  function getZoneUrl( $zone, $suffix = false ) {
1698  $this->assertRepoDefined();
1699  $ext = $this->getExtension();
1700  $path = $this->repo->getZoneUrl( $zone, $ext ) . '/' . $this->getUrlRel();
1701  if ( $suffix !== false ) {
1702  $path .= '/' . rawurlencode( $suffix );
1703  }
1704 
1705  return $path;
1706  }
1707 
1714  function getThumbUrl( $suffix = false ) {
1715  return $this->getZoneUrl( 'thumb', $suffix );
1716  }
1717 
1724  function getTranscodedUrl( $suffix = false ) {
1725  return $this->getZoneUrl( 'transcoded', $suffix );
1726  }
1727 
1734  function getVirtualUrl( $suffix = false ) {
1735  $this->assertRepoDefined();
1736  $path = $this->repo->getVirtualUrl() . '/public/' . $this->getUrlRel();
1737  if ( $suffix !== false ) {
1738  $path .= '/' . rawurlencode( $suffix );
1739  }
1740 
1741  return $path;
1742  }
1743 
1750  function getArchiveVirtualUrl( $suffix = false ) {
1751  $this->assertRepoDefined();
1752  $path = $this->repo->getVirtualUrl() . '/public/archive/' . $this->getHashPath();
1753  if ( $suffix === false ) {
1754  $path = rtrim( $path, '/' );
1755  } else {
1756  $path .= rawurlencode( $suffix );
1757  }
1758 
1759  return $path;
1760  }
1761 
1768  function getThumbVirtualUrl( $suffix = false ) {
1769  $this->assertRepoDefined();
1770  $path = $this->repo->getVirtualUrl() . '/thumb/' . $this->getUrlRel();
1771  if ( $suffix !== false ) {
1772  $path .= '/' . rawurlencode( $suffix );
1773  }
1774 
1775  return $path;
1776  }
1777 
1781  function isHashed() {
1782  $this->assertRepoDefined();
1783 
1784  return (bool)$this->repo->getHashLevels();
1785  }
1786 
1790  function readOnlyError() {
1791  throw new MWException( static::class . ': write operations are not supported' );
1792  }
1793 
1809  function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
1810  $watch = false, $timestamp = false, User $user = null
1811  ) {
1812  $this->readOnlyError();
1813  }
1814 
1836  function publish( $src, $flags = 0, array $options = [] ) {
1837  $this->readOnlyError();
1838  }
1839 
1844  function formatMetadata( $context = false ) {
1845  if ( !$this->getHandler() ) {
1846  return false;
1847  }
1848 
1849  return $this->getHandler()->formatMetadata( $this, $context );
1850  }
1851 
1857  function isLocal() {
1858  return $this->repo && $this->repo->isLocal();
1859  }
1860 
1866  function getRepoName() {
1867  return $this->repo ? $this->repo->getName() : 'unknown';
1868  }
1869 
1875  function getRepo() {
1876  return $this->repo;
1877  }
1878 
1885  function isOld() {
1886  return false;
1887  }
1888 
1896  function isDeleted( $field ) {
1897  return false;
1898  }
1899 
1905  function getVisibility() {
1906  return 0;
1907  }
1908 
1914  function wasDeleted() {
1915  $title = $this->getTitle();
1916 
1917  return $title && $title->isDeletedQuick();
1918  }
1919 
1932  function move( $target ) {
1933  $this->readOnlyError();
1934  }
1935 
1951  function delete( $reason, $suppress = false, $user = null ) {
1952  $this->readOnlyError();
1953  }
1954 
1968  function restore( $versions = [], $unsuppress = false ) {
1969  $this->readOnlyError();
1970  }
1971 
1979  function isMultipage() {
1980  return $this->getHandler() && $this->handler->isMultiPage( $this );
1981  }
1982 
1989  function pageCount() {
1990  if ( !isset( $this->pageCount ) ) {
1991  if ( $this->getHandler() && $this->handler->isMultiPage( $this ) ) {
1992  $this->pageCount = $this->handler->pageCount( $this );
1993  } else {
1994  $this->pageCount = false;
1995  }
1996  }
1997 
1998  return $this->pageCount;
1999  }
2000 
2010  static function scaleHeight( $srcWidth, $srcHeight, $dstWidth ) {
2011  // Exact integer multiply followed by division
2012  if ( $srcWidth == 0 ) {
2013  return 0;
2014  } else {
2015  return (int)round( $srcHeight * $dstWidth / $srcWidth );
2016  }
2017  }
2018 
2029  function getImageSize( $filePath ) {
2030  if ( !$this->getHandler() ) {
2031  return false;
2032  }
2033 
2034  return $this->getHandler()->getImageSize( $this, $filePath );
2035  }
2036 
2043  function getDescriptionUrl() {
2044  if ( $this->repo ) {
2045  return $this->repo->getDescriptionUrl( $this->getName() );
2046  } else {
2047  return false;
2048  }
2049  }
2050 
2058  global $wgLang;
2059 
2060  if ( !$this->repo || !$this->repo->fetchDescription ) {
2061  return false;
2062  }
2063 
2064  $lang = $lang ?? $wgLang;
2065 
2066  $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $lang->getCode() );
2067  if ( $renderUrl ) {
2068  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
2069  $key = $this->repo->getLocalCacheKey(
2070  'RemoteFileDescription',
2071  $lang->getCode(),
2072  md5( $this->getName() )
2073  );
2074  $fname = __METHOD__;
2075 
2076  return $cache->getWithSetCallback(
2077  $key,
2078  $this->repo->descriptionCacheExpiry ?: $cache::TTL_UNCACHEABLE,
2079  function ( $oldValue, &$ttl, array &$setOpts ) use ( $renderUrl, $fname ) {
2080  wfDebug( "Fetching shared description from $renderUrl\n" );
2081  $res = MediaWikiServices::getInstance()->getHttpRequestFactory()->
2082  get( $renderUrl, [], $fname );
2083  if ( !$res ) {
2085  }
2086 
2087  return $res;
2088  }
2089  );
2090  }
2091 
2092  return false;
2093  }
2094 
2107  function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
2108  return null;
2109  }
2110 
2116  function getTimestamp() {
2117  $this->assertRepoDefined();
2118 
2119  return $this->repo->getFileTimestamp( $this->getPath() );
2120  }
2121 
2129  public function getDescriptionTouched() {
2130  return false;
2131  }
2132 
2138  function getSha1() {
2139  $this->assertRepoDefined();
2140 
2141  return $this->repo->getFileSha1( $this->getPath() );
2142  }
2143 
2149  function getStorageKey() {
2150  $hash = $this->getSha1();
2151  if ( !$hash ) {
2152  return false;
2153  }
2154  $ext = $this->getExtension();
2155  $dotExt = $ext === '' ? '' : ".$ext";
2156 
2157  return $hash . $dotExt;
2158  }
2159 
2168  function userCan( $field, User $user = null ) {
2169  return true;
2170  }
2171 
2176  function getContentHeaders() {
2177  $handler = $this->getHandler();
2178  if ( $handler ) {
2179  $metadata = $this->getMetadata();
2180 
2181  if ( is_string( $metadata ) ) {
2182  $metadata = AtEase::quietCall( 'unserialize', $metadata );
2183  }
2184 
2185  if ( !is_array( $metadata ) ) {
2186  $metadata = [];
2187  }
2188 
2189  return $handler->getContentHeaders( $metadata );
2190  }
2191 
2192  return [];
2193  }
2194 
2198  function getLongDesc() {
2199  $handler = $this->getHandler();
2200  if ( $handler ) {
2201  return $handler->getLongDesc( $this );
2202  } else {
2203  return MediaHandler::getGeneralLongDesc( $this );
2204  }
2205  }
2206 
2210  function getShortDesc() {
2211  $handler = $this->getHandler();
2212  if ( $handler ) {
2213  return $handler->getShortDesc( $this );
2214  } else {
2215  return MediaHandler::getGeneralShortDesc( $this );
2216  }
2217  }
2218 
2222  function getDimensionsString() {
2223  $handler = $this->getHandler();
2224  if ( $handler ) {
2225  return $handler->getDimensionsString( $this );
2226  } else {
2227  return '';
2228  }
2229  }
2230 
2234  function getRedirected() {
2235  return $this->redirected;
2236  }
2237 
2241  function getRedirectedTitle() {
2242  if ( $this->redirected ) {
2243  if ( !$this->redirectTitle ) {
2244  $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected );
2245  }
2246 
2247  return $this->redirectTitle;
2248  }
2249 
2250  return null;
2251  }
2252 
2257  function redirectedFrom( $from ) {
2258  $this->redirected = $from;
2259  }
2260 
2264  function isMissing() {
2265  return false;
2266  }
2267 
2272  public function isCacheable() {
2273  return true;
2274  }
2275 
2280  protected function assertRepoDefined() {
2281  if ( !( $this->repo instanceof $this->repoClass ) ) {
2282  throw new MWException( "A {$this->repoClass} object is not set for this File.\n" );
2283  }
2284  }
2285 
2290  protected function assertTitleDefined() {
2291  if ( !( $this->title instanceof Title ) ) {
2292  throw new MWException( "A Title object is not set for this File.\n" );
2293  }
2294  }
2295 
2300  public function isExpensiveToThumbnail() {
2301  $handler = $this->getHandler();
2302  return $handler ? $handler->isExpensiveToThumbnail( $this ) : false;
2303  }
2304 
2310  public function isTransformedLocally() {
2311  return true;
2312  }
2313 }
convertMetadataVersion( $metadata, $version=1)
Convert metadata version.
getLocalRefPath()
Get an FS copy or original of this file and return the path.
Definition: File.php:443
Title $redirectedTitle
Definition: File.php:118
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
string false $pageCount
Number of pages of a multipage document, or false for documents which aren&#39;t multipage documents...
Definition: File.php:144
invalidateCache( $purgeTime=null)
Updates page_touched for this page; called from LinksUpdate.php.
Definition: Title.php:4181
const DELETED_COMMENT
Definition: File.php:64
transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags)
Return either a MediaTransformError or placeholder thumbnail (if $wgIgnoreImageErrors) ...
Definition: File.php:1038
const FOR_THIS_USER
Definition: File.php:80
getRepoName()
Returns the name of the repository.
Definition: File.php:1866
MediaHandler $handler
Definition: File.php:124
getMatchedLanguage( $userPreferredLanguage, array $availableLanguages)
When overridden in a descendant class, returns a language code most suiting.
nextHistoryLine()
Return the history of this file, line by line.
Definition: File.php:1502
getShortDesc( $file)
Short description.
getHistory( $limit=null, $start=null, $end=null, $inc=true)
Return a fragment of the history of file.
Definition: File.php:1489
getPath()
Returns the file system path.
Definition: FSFile.php:50
assertTitleDefined()
Assert that $this->title is set to a Title.
Definition: File.php:2290
formatMetadata( $context=false)
Definition: File.php:1844
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
$IP
Definition: WebStart.php:41
getThumbRel( $suffix=false)
Get the path, relative to the thumbnail zone root, of the thumbnail directory or a particular file if...
Definition: File.php:1566
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:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
move( $target)
Move file to the new title.
Definition: File.php:1932
getTransformScript()
Definition: File.php:918
FSFile bool $fsFile
False if undefined.
Definition: File.php:121
getArchiveThumbUrl( $archiveName, $suffix=false)
Get the URL of the archived file&#39;s thumbs, or a particular thumb if $suffix is specified.
Definition: File.php:1678
getThumbDisposition( $thumbName, $dispositionType='inline')
Definition: File.php:1363
getRedirectedTitle()
Definition: File.php:2241
getShortDesc()
Definition: File.php:2210
getAvailableLanguages()
Gives a (possibly empty) list of languages to render the file in.
Definition: File.php:585
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
getTransform( $image, $dstPath, $dstUrl, $params)
Get a MediaTransformOutput object representing the transformed output.
const DELETE_SOURCE
Definition: File.php:76
iconThumb()
Get a ThumbnailImage representing a file type icon.
Definition: File.php:1401
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:810
__construct( $title, $repo)
Call this constructor from child classes.
Definition: File.php:176
const TTL_UNCACHEABLE
Idiom for getWithSetCallback() callbacks to avoid calling set()
string $extension
File extension.
Definition: File.php:130
getStorageKey()
Get the deletion archive key, "<sha1>.<ext>".
Definition: File.php:2149
static scaleHeight( $srcWidth, $srcHeight, $dstWidth)
Calculate the height of a thumbnail using the source and destination width.
Definition: File.php:2010
isExpensiveToThumbnail( $file)
True if creating thumbnails from the file is large or otherwise resource-intensive.
transform( $params, $flags=0)
Transform a media file.
Definition: File.php:1058
isHashed()
Definition: File.php:1781
getCommonMetaArray()
Like getMetadata but returns a handler independent array of common values.
Definition: File.php:673
$source
createThumb( $width, $height=-1)
Create a thumbnail of the image having the specified width/height.
Definition: File.php:1016
getDescriptionUrl()
Get the URL of the image description page.
Definition: File.php:2043
$wgThumbnailEpoch
If rendered thumbnail files are older than this timestamp, they will be rerendered on demand as if th...
getMatchedLanguage( $userPreferredLanguage)
Get the language code from the available languages for this file that matches the language requested ...
Definition: File.php:601
canRender()
Checks if the output of transform() for this file is likely to be valid.
Definition: File.php:758
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 MediaWikiServices
Definition: injection.txt:23
assertRepoDefined()
Assert that $this->repo is set to a valid FileRepo instance.
Definition: File.php:2280
getName()
Return the name of this file.
Definition: File.php:307
string $name
The name of a file from its title object.
Definition: File.php:133
getRepo()
Returns the repository.
Definition: File.php:1875
__get( $name)
Definition: File.php:215
getArchiveUrl( $suffix=false)
Get the URL of the archive directory, or a particular file if $suffix is specified.
Definition: File.php:1658
isLocal()
Returns true if the file comes from the local file repository.
Definition: File.php:1857
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
getDescription( $audience=self::FOR_PUBLIC, User $user=null)
Get description of file revision STUB.
Definition: File.php:2107
isOld()
Returns true if the image is an old version STUB.
Definition: File.php:1885
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
getBucketThumbPath( $bucket)
Returns the repo path of the thumb for a given bucket.
Definition: File.php:1334
static getInstance()
Returns the global default instance of the top level service locator.
title
getCanRender()
Accessor for __get()
Definition: File.php:770
const MEDIATYPE_UNKNOWN
Definition: defines.php:26
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters.
Definition: File.php:977
getTitle()
Return the associated title object.
Definition: File.php:336
Title string bool $title
Definition: File.php:109
getHashPath()
Get the filename hash component of the directory including trailing slash, e.g.
Definition: File.php:1522
makeTransformTmpFile( $thumbPath)
Creates a temp FS file with the same extension and the thumbnail.
Definition: File.php:1353
bool $isSafeFile
Whether this media file is in a format that is unlikely to contain viruses or malicious content...
Definition: File.php:158
static getGeneralShortDesc( $file)
Used instead of getShortDesc if there is no handler registered for file.
getThumbnailBucket( $desiredWidth, $page=1)
Return the smallest bucket from $wgThumbnailBuckets which is at least $wgThumbnailMinimumBucketDistan...
Definition: File.php:500
purgeEverything()
Purge metadata and all affected pages when the file is created, deleted, or majorly updated...
Definition: File.php:1464
load( $flags=0)
Load any lazy-loaded file object fields from source.
Definition: File.php:891
getRedirected()
Definition: File.php:2234
const DELETED_FILE
Definition: File.php:63
isVectorized( $file)
The material is vectorized and thus scaling is lossless.
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
getThumbnails()
Get all thumbnail names previously generated for this file STUB Overridden by LocalFile.
Definition: File.php:1433
getVirtualUrl( $suffix=false)
Get the public zone virtual URL for a current version source file.
Definition: File.php:1734
getDefaultRenderLanguage(File $file)
On file types that support renderings in multiple languages, which language is used by default if uns...
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
getLongDesc()
Definition: File.php:2198
getLength()
Get the duration of a media file in seconds.
Definition: File.php:551
getDescriptionText(Language $lang=null)
Get the HTML text of the description page, if available.
Definition: File.php:2057
string $hashPath
Relative path including trailing slash.
Definition: File.php:139
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
const THUMB_FULL_NAME
Definition: File.php:84
publish( $src, $flags=0, array $options=[])
Move or copy a file to its public location.
Definition: File.php:1836
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, 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. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition: hooks.txt:1263
getContentHeaders()
Definition: File.php:2176
getPath()
Return the storage path to the file.
Definition: File.php:427
const RENDER_NOW
Force rendering in the current process.
Definition: File.php:69
wasDeleted()
Was this file ever deleted from the wiki?
Definition: File.php:1914
Convenience class for dealing with PoolCounters using callbacks.
readOnlyError()
Definition: File.php:1790
$wgLang
Definition: Setup.php:931
wfTempDir()
Tries to get the system directory for temporary files.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message 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 unset offset - wrap String Wrap the message in html(usually something like "&lt
mustRender()
Return true if the file is of a type that can&#39;t be directly rendered by typical browsers and needs to...
Definition: File.php:784
getUnscaledThumb( $handlerParams=[])
Get a ThumbnailImage which is the same size as the source.
Definition: File.php:939
static factory( $prefix, $extension='', $tmpDirectory=null)
Make a new temporary file on the file system.
Definition: TempFSFile.php:55
isTrustedFile()
Returns true if the file is flagged as trusted.
Definition: File.php:876
isAnimatedImage( $file)
The material is an image, and is animated.
getSize()
Return the size of the image file, in bytes Overridden by LocalFile, UnregisteredLocalFile STUB...
Definition: File.php:720
getThumbUrl( $suffix=false)
Get the URL of the thumbnail directory, or a particular file if $suffix is specified.
Definition: File.php:1714
isVectorized()
Return true if the file is vectorized.
Definition: File.php:565
Class to invalidate the HTML cache of all the pages linking to a given title.
getDescriptionShortUrl()
Get short description URL for a files based on the page ID.
Definition: File.php:374
isMultipage()
Returns &#39;true&#39; if this file is a type which supports multiple pages, e.g.
Definition: File.php:1979
getHandler()
Get a MediaHandler instance for this file.
Definition: File.php:1388
thumbName( $params, $flags=0)
Return the file name of a thumbnail with the specified parameters.
Definition: File.php:962
$wgThumbnailBuckets
When defined, is an array of image widths used as buckets for thumbnail generation.
const NS_MEDIA
Definition: Defines.php:48
generateBucketsIfNeeded( $params, $flags=0)
Generates chained bucketed thumbnails if needed.
Definition: File.php:1209
getRel()
Get the path of the file relative to the public zone root.
Definition: File.php:1537
$res
Definition: database.txt:21
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this file, if it&#39;s marked as d...
Definition: File.php:2168
getMetadata()
Get handler-specific metadata Overridden by LocalFile, UnregisteredLocalFile STUB.
Definition: File.php:663
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
string $lastError
Text of last error.
Definition: File.php:112
Media transform output for images.
getImageSize( $filePath)
Get an image size array like that returned by getImageSize(), or false if it can&#39;t be determined...
Definition: File.php:2029
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response 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:2217
resetHistory()
Reset the history pointer to the first element of the history.
Definition: File.php:1512
canAnimateThumbIfAppropriate()
Will the thumbnail be animated if one would expect it to be.
Definition: File.php:639
isMissing()
Definition: File.php:2264
getLastError()
Get last thumbnailing error.
Definition: File.php:1423
$cache
Definition: mcc.php:33
$params
allowInlineDisplay()
Alias for canRender()
Definition: File.php:793
$wgResourceBasePath
The default &#39;remoteBasePath&#39; value for instances of ResourceLoaderFileModule.
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 & $options
Definition: hooks.txt:1982
getAvailableLanguages(File $file)
Get list of languages file can be viewed in.
migrateThumbFile( $thumbName)
Hook into transform() to allow migration of thumbnail files STUB Overridden by LocalFile.
Definition: File.php:1379
array $tmpBucketedThumbCache
Cache of tmp filepaths pointing to generated bucket thumbnails, keyed by width.
Definition: File.php:164
unserialize( $serialized)
getViewURL()
Definition: File.php:399
getTranscodedPath( $suffix=false)
Get the path of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1646
getSha1()
Get the SHA-1 base 36 hash of the file.
Definition: File.php:2138
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 function
Definition: injection.txt:30
getDimensionsString()
Definition: File.php:2222
getFullUrl()
Return a fully-qualified URL to the file.
Definition: File.php:385
convertMetadataVersion( $metadata, $version)
get versioned metadata
Definition: File.php:691
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
getExtension()
Get the file extension, e.g.
Definition: File.php:321
string $redirected
Main part of the title, with underscores (Title::getDBkey)
Definition: File.php:115
const PROTO_RELATIVE
Definition: Defines.php:217
const NS_FILE
Definition: Defines.php:66
$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:106
static compare(File $a, File $b)
Callback for usort() to do file sorts by name.
Definition: File.php:298
getMediaType()
Return the type of the media in the file.
Definition: File.php:742
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
getArchivePath( $suffix=false)
Get the path of the archived file.
Definition: File.php:1608
isVisible()
Returns true if file exists in the repository and can be included in a page.
Definition: File.php:911
getScriptedTransform( $image, $script, $params)
Get a MediaTransformOutput object representing an alternate of the transformed output which will call...
getUrlRel()
Get urlencoded path of the file relative to the public zone root.
Definition: File.php:1581
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:123
getBitDepth()
Return the bit depth of the file Overridden by LocalFile STUB.
Definition: File.php:710
const DELETED_USER
Definition: File.php:65
getDimensionsString( $file)
Shown in file history box on image description page.
const DELETED_RESTRICTED
Definition: File.php:66
getZoneUrl( $zone, $suffix=false)
Get the URL of the zone directory, or a particular file if $suffix is specified.
Definition: File.php:1697
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
getArchiveRel( $suffix=false)
Get the path of an archived file relative to the public zone root.
Definition: File.php:1548
string $transformScript
URL of transformscript (for example thumb.php)
Definition: File.php:147
isExpensiveToThumbnail()
True if creating thumbnails from the file is large or otherwise resource-intensive.
Definition: File.php:2300
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
getIsSafeFileUncached()
Uncached accessor.
Definition: File.php:832
redirectedFrom( $from)
Definition: File.php:2257
getDescriptionTouched()
Returns the timestamp (in TS_MW format) of the last change of the description page.
Definition: File.php:2129
canAnimateThumbnail( $file)
If the material is animated, we can animate the thumbnail.
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:259
getArchiveThumbPath( $archiveName, $suffix=false)
Get the path of an archived file&#39;s thumbs, or a particular thumb if $suffix is specified.
Definition: File.php:1621
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:219
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
restore( $versions=[], $unsuppress=false)
Restore all or specified deleted revisions to the given file.
Definition: File.php:1968
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
getHeight( $page=1)
Return the height of the image.
Definition: File.php:487
getContentHeaders( $metadata)
Get useful response headers for GET/HEAD requests for a file with the given metadata.
getTimestamp()
Get the 14-character timestamp of the file upload.
Definition: File.php:2116
getLength( $file)
If its an audio file, return the length of the file.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
getDefaultRenderLanguage()
In files that support multiple language, what is the default language to use if none specified...
Definition: File.php:620
const RAW
Definition: File.php:81
string $url
The URL corresponding to one of the four basic zones.
Definition: File.php:127
getUser( $type='text')
Returns ID or name of user who uploaded the file STUB.
Definition: File.php:542
getVisibility()
Return the deletion bitfield STUB.
Definition: File.php:1905
exists()
Returns true if file exists in the repository.
Definition: File.php:901
getTranscodedUrl( $suffix=false)
Get the URL of the transcoded directory, or a particular file if $suffix is specified.
Definition: File.php:1724
getThumbVirtualUrl( $suffix=false)
Get the virtual URL for a thumbnail file or directory.
Definition: File.php:1768
getUrl()
Return the URL of the file.
Definition: File.php:358
normaliseParams( $image, &$params)
Changes the parameter array as necessary, ready for transformation.
getThumbnailSource( $params)
Returns the most appropriate source image for the thumbnail, given a target thumbnail size...
Definition: File.php:1266
static getGeneralLongDesc( $file)
Used instead of getLongDesc if there is no handler registered for file.
if(!is_readable( $file)) $ext
Definition: router.php:48
getOriginalTitle()
Return the title used to find this file.
Definition: File.php:345
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2633
Title $redirectTitle
Definition: File.php:150
isDeletedQuick()
Is there a version of this page in the deletion archive?
Definition: Title.php:2979
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to &#39;...
Definition: File.php:283
getCanonicalUrl()
Definition: File.php:392
bool $canRender
Whether the output of transform() for this file is likely to be valid.
Definition: File.php:153
see documentation in includes Linker php for Linker::makeImageLink & $handlerParams
Definition: hooks.txt:1797
isCacheable()
Check if this file object is small and can be cached.
Definition: File.php:2272
getBucketThumbName( $bucket)
Returns the name of the thumb for a given bucket.
Definition: File.php:1344
doTransform( $image, $dstPath, $dstUrl, $params, $flags=0)
Get a MediaTransformOutput object representing the transformed output.
$wgTrustedMediaFormats
list of trusted media-types and MIME types.
getIsSafeFile()
Accessor for __get()
Definition: File.php:823
const FOR_PUBLIC
Definition: File.php:79
getWidth( $page=1)
Return the width of the image.
Definition: File.php:473
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition: File.php:74
pageCount()
Returns the number of pages of a multipage document, or false for documents which aren&#39;t multipage do...
Definition: File.php:1989
upgradeRow()
Upgrade the database row if there is one Called by ImagePage STUB.
Definition: File.php:273
getCommonMetaArray(File $file)
Get an array of standard (FormatMetadata type) metadata values.
getLongDesc( $file)
Long description.
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:1809
generateAndSaveThumb( $tmpFile, $transformParams, $flags)
Generates a thumbnail according to the given parameters and saves it to storage.
Definition: File.php:1142
string $path
The storage path corresponding to one of the zones.
Definition: File.php:136
getArchiveVirtualUrl( $suffix=false)
Get the public zone virtual URL for an archived version source file.
Definition: File.php:1750
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms...
Definition: File.php:234
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:61
static getHandler( $type)
Get a MediaHandler for a given MIME type from the instance cache.
$wgIgnoreImageErrors
If set, inline scaled images will still produce "<img>" tags ready for output instead of showing an e...
purgeCache( $options=[])
Purge shared caches such as thumbnails and DB data caching STUB Overridden by LocalFile.
Definition: File.php:1444
string $repoClass
Required Repository class type.
Definition: File.php:161
isTransformedLocally()
Whether the thumbnails created on the same server as this code is running.
Definition: File.php:2310
getMimeType()
Returns the MIME type of the file.
Definition: File.php:731
isDeleted( $field)
Is this file a "deleted" file in a private archive? STUB.
Definition: File.php:1896
static makeContentDisposition( $type, $filename='')
Build a Content-Disposition header value per RFC 6266.
purgeDescription()
Purge the file description page, but don&#39;t go after pages using the file.
Definition: File.php:1452
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:194
getThumbPath( $suffix=false)
Get the path of the thumbnail directory, or a particular file if $suffix is specified.
Definition: File.php:1634
Basic media transform error class.
purgeSquid()
Purge all applicable CDN URLs.
Definition: Title.php:3414
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
getArchiveThumbRel( $archiveName, $suffix=false)
Get the path, relative to the thumbnail zone root, for an archived file&#39;s thumbs directory or a speci...
Definition: File.php:1593
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$starttime
Definition: api.php:37