title = File::normalizeTitle( $title, 'exception' ); $this->name = $repo->getNameFromTitle( $title ); } else { $this->name = basename( $path ); $this->title = File::normalizeTitle( $this->name, 'exception' ); } $this->repo = $repo; if ( $path ) { $this->path = $path; } else { $this->assertRepoDefined(); $this->path = $repo->getRootDirectory() . '/' . $repo->getHashPath( $this->name ) . $this->name; } if ( $mime ) { $this->mime = $mime; } $this->dims = []; } /** * @param int $page * @return bool */ private function cachePageDimensions( $page = 1 ) { $page = (int)$page; if ( $page < 1 ) { $page = 1; } if ( !isset( $this->dims[$page] ) ) { if ( !$this->getHandler() ) { return false; } $this->dims[$page] = $this->handler->getPageDimensions( $this, $page ); } return $this->dims[$page]; } /** * @param int $page * @return int */ function getWidth( $page = 1 ) { $dim = $this->cachePageDimensions( $page ); return $dim['width']; } /** * @param int $page * @return int */ function getHeight( $page = 1 ) { $dim = $this->cachePageDimensions( $page ); return $dim['height']; } /** * @return bool|string */ function getMimeType() { if ( !isset( $this->mime ) ) { $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer(); $this->mime = $magic->guessMimeType( $this->getLocalRefPath() ); } return $this->mime; } /** * @param string $filename * @return array|bool */ function getImageSize( $filename ) { if ( !$this->getHandler() ) { return false; } return $this->handler->getImageSize( $this, $this->getLocalRefPath() ); } /** * @return int */ function getBitDepth() { $gis = $this->getImageSize( $this->getLocalRefPath() ); if ( !$gis || !isset( $gis['bits'] ) ) { return 0; } return $gis['bits']; } /** * @return bool */ function getMetadata() { if ( !isset( $this->metadata ) ) { if ( !$this->getHandler() ) { $this->metadata = false; } else { $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() ); } } return $this->metadata; } /** * @return bool|string */ function getURL() { if ( $this->repo ) { return $this->repo->getZoneUrl( 'public' ) . '/' . $this->repo->getHashPath( $this->name ) . rawurlencode( $this->name ); } else { return false; } } /** * @return bool|int */ function getSize() { $this->assertRepoDefined(); return $this->repo->getFileSize( $this->path ); } /** * Optimize getLocalRefPath() by using an existing local reference. * The file at the path of $fsFile should not be deleted (or at least * not until the end of the request). This is mostly a performance hack. * * @param FSFile $fsFile * @return void */ public function setLocalReference( FSFile $fsFile ) { $this->fsFile = $fsFile; } }