* Add an Image::newFromName for additional compat
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Jun 2007 18:44:49 +0000 (18:44 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 5 Jun 2007 18:44:49 +0000 (18:44 +0000)
* Add 'static' markers on the static factory methods

includes/filerepo/ForeignDBFile.php
includes/filerepo/LocalFile.php
includes/filerepo/OldLocalFile.php
includes/filerepo/UnregisteredLocalFile.php

index c5f65d5..e426a67 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 class ForeignDBFile extends LocalFile {
-       function newFromTitle( $title, $repo ) {
+       static function newFromTitle( $title, $repo ) {
                return new self( $title, $repo );
        }
 
index 418d56a..8b8486b 100644 (file)
@@ -52,7 +52,7 @@ class LocalFile extends File
         * Create a LocalFile from a title
         * Do not call this except from inside a repo class.
         */
-       function newFromTitle( $title, $repo ) {
+       static function newFromTitle( $title, $repo ) {
                return new self( $title, $repo );
        }
 
@@ -60,7 +60,7 @@ class LocalFile extends File
         * Create a LocalFile from a title
         * Do not call this except from inside a repo class.
         */
-       function newFromRow( $row, $repo ) {
+       static function newFromRow( $row, $repo ) {
                $title = Title::makeTitle( NS_IMAGE, $row->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.
         *
index 9db5e44..bc59662 100644 (file)
@@ -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_' );
index 72fdc80..ff9c5df 100644 (file)
 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 );
        }