From: Brion Vibber Date: Tue, 5 Jun 2007 18:44:49 +0000 (+0000) Subject: * Add an Image::newFromName for additional compat X-Git-Tag: 1.31.0-rc.0~52654 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=c0a1c63cc36e8e02935bf760d7a3c2033f79e1e9;p=lhc%2Fweb%2Fwiklou.git * Add an Image::newFromName for additional compat * Add 'static' markers on the static factory methods --- diff --git a/includes/filerepo/ForeignDBFile.php b/includes/filerepo/ForeignDBFile.php index c5f65d5ca5..e426a678ac 100644 --- a/includes/filerepo/ForeignDBFile.php +++ b/includes/filerepo/ForeignDBFile.php @@ -1,7 +1,7 @@ img_name ); $file = new self( $title, $repo ); $file->loadFromRow( $row ); @@ -1333,7 +1333,7 @@ class Image extends LocalFile { * Do not use in core code. * @deprecated */ - function newFromTitle( $title, $time = false ) { + static function newFromTitle( $title, $time = false ) { $img = wfFindFile( $title, $time ); if ( !$img ) { $img = wfLocalFile( $title ); @@ -1341,6 +1341,27 @@ class Image extends LocalFile { return $img; } + /** + * Wrapper for wfFindFile(), for backwards-compatibility only. + * Do not use in core code. + * + * @param string $name name of the image, used to create a title object using Title::makeTitleSafe + * @return image object or null if invalid title + * @deprecated + */ + static function newFromName( $name ) { + $title = Title::makeTitleSafe( NS_IMAGE, $name ); + if ( is_object( $title ) ) { + $img = wfFindFile( $title ); + if ( !$img ) { + $img = wfLocalFile( $title ); + } + return $img; + } else { + return NULL; + } + } + /** * Return the URL of an image, provided its name. * diff --git a/includes/filerepo/OldLocalFile.php b/includes/filerepo/OldLocalFile.php index 9db5e44b49..bc59662d10 100644 --- a/includes/filerepo/OldLocalFile.php +++ b/includes/filerepo/OldLocalFile.php @@ -11,15 +11,15 @@ class OldLocalFile extends LocalFile { const CACHE_VERSION = 1; const MAX_CACHE_ROWS = 20; - function newFromTitle( $title, $repo, $time ) { + static function newFromTitle( $title, $repo, $time ) { return new self( $title, $repo, $time, null ); } - function newFromArchiveName( $title, $repo, $archiveName ) { + static function newFromArchiveName( $title, $repo, $archiveName ) { return new self( $title, $repo, null, $archiveName ); } - function newFromRow( $row, $repo ) { + static function newFromRow( $row, $repo ) { $title = Title::makeTitle( NS_IMAGE, $row->oi_name ); $file = new self( $title, $repo, null, $row->oi_archive_name ); $file->loadFromRow( $row, 'oi_' ); diff --git a/includes/filerepo/UnregisteredLocalFile.php b/includes/filerepo/UnregisteredLocalFile.php index 72fdc80d29..ff9c5df08d 100644 --- a/includes/filerepo/UnregisteredLocalFile.php +++ b/includes/filerepo/UnregisteredLocalFile.php @@ -13,11 +13,11 @@ class UnregisteredLocalFile extends File { var $title, $path, $mime, $handler, $dims; - function newFromPath( $path, $mime ) { + static function newFromPath( $path, $mime ) { return new UnregisteredLocalFile( false, false, $path, $mime ); } - function newFromTitle( $title, $repo ) { + static function newFromTitle( $title, $repo ) { return new UnregisteredLocalFile( $title, $repo, false, false ); }