From dd3136f423599e2a98bb1b3b3c072c226d3f2efb Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 5 Apr 2008 12:26:10 +0000 Subject: [PATCH] Ugly hack to fix two strict standarts errors: * Declaration of Image::newFromTitle() should be compatible with that of LocalFile::newFromTitle() : Moved Image class to Image.php, will only be loaded when an old extension need it. * Declaration of OldLocalFile::newFromTitle() should be compatible with that of LocalFile::newFromTitle() : Added an unsed param to LocalFile::newFromTitle() with a null default value, also added the null default value to OldLocalFile::newFromTitle() but that function will throw an Exception if that value isn't modified (even if these functions should not be called by extensions). Pass $suffix parameter to File::getArchiveRel() in File::getArchivePath() --- includes/AutoLoader.php | 2 +- includes/filerepo/File.php | 2 +- includes/filerepo/Image.php | 69 ++++++++++++++++++++++++++++ includes/filerepo/LocalFile.php | 73 ++---------------------------- includes/filerepo/OldLocalFile.php | 5 +- 5 files changed, 78 insertions(+), 73 deletions(-) create mode 100644 includes/filerepo/Image.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index ffc1351885..ebf166c21e 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -297,7 +297,7 @@ function __autoload($className) { 'ForeignDBRepo' => 'includes/filerepo/ForeignDBRepo.php', 'ForeignDBViaLBRepo' => 'includes/filerepo/ForeignDBViaLBRepo.php', 'FSRepo' => 'includes/filerepo/FSRepo.php', - 'Image' => 'includes/filerepo/LocalFile.php', + 'Image' => 'includes/filerepo/Image.php', 'LocalFileDeleteBatch' => 'includes/filerepo/LocalFile.php', 'LocalFile' => 'includes/filerepo/LocalFile.php', 'LocalFileRestoreBatch' => 'includes/filerepo/LocalFile.php', diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 72eacc4d5f..4b517a256c 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -723,7 +723,7 @@ abstract class File { /** Get the path of the archive directory, or a particular file if $suffix is specified */ function getArchivePath( $suffix = false ) { - return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel(); + return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel( $suffix ); } /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */ diff --git a/includes/filerepo/Image.php b/includes/filerepo/Image.php new file mode 100644 index 0000000000..9ab750c1b4 --- /dev/null +++ b/includes/filerepo/Image.php @@ -0,0 +1,69 @@ +getLocalRepo(); + parent::__construct( $title, $repo ); + } + + /** + * Wrapper for wfFindFile(), for backwards-compatibility only + * Do not use in core code. + * @deprecated + */ + static function newFromTitle( $title, $time = false ) { + $img = wfFindFile( $title, $time ); + if ( !$img ) { + $img = wfLocalFile( $title ); + } + 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. + * + * Backwards-compatibility for extensions. + * Note that fromSharedDirectory will only use the shared path for files + * that actually exist there now, and will return local paths otherwise. + * + * @param string $name Name of the image, without the leading "Image:" + * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath? + * @return string URL of $name image + * @deprecated + */ + static function imageUrl( $name, $fromSharedDirectory = false ) { + $image = null; + if( $fromSharedDirectory ) { + $image = wfFindFile( $name ); + } + if( !$image ) { + $image = wfLocalFile( $name ); + } + return $image->getUrl(); + } +} \ No newline at end of file diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 871756a598..f3afc74205 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -56,8 +56,10 @@ class LocalFile extends File /** * Create a LocalFile from a title * Do not call this except from inside a repo class. + * + * Note: $unused param is only here to avoid an E_STRICT */ - static function newFromTitle( $title, $repo ) { + static function newFromTitle( $title, $repo, $unused = null ) { return new self( $title, $repo ); } @@ -1090,75 +1092,6 @@ class LocalFile extends File #------------------------------------------------------------------------------ -/** - * Backwards compatibility class - */ -class Image extends LocalFile { - function __construct( $title ) { - $repo = RepoGroup::singleton()->getLocalRepo(); - parent::__construct( $title, $repo ); - } - - /** - * Wrapper for wfFindFile(), for backwards-compatibility only - * Do not use in core code. - * @deprecated - */ - static function newFromTitle( $title, $time = false ) { - $img = wfFindFile( $title, $time ); - if ( !$img ) { - $img = wfLocalFile( $title ); - } - 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. - * - * Backwards-compatibility for extensions. - * Note that fromSharedDirectory will only use the shared path for files - * that actually exist there now, and will return local paths otherwise. - * - * @param string $name Name of the image, without the leading "Image:" - * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath? - * @return string URL of $name image - * @deprecated - */ - static function imageUrl( $name, $fromSharedDirectory = false ) { - $image = null; - if( $fromSharedDirectory ) { - $image = wfFindFile( $name ); - } - if( !$image ) { - $image = wfLocalFile( $name ); - } - return $image->getUrl(); - } -} - -#------------------------------------------------------------------------------ - /** * Helper class for file deletion */ diff --git a/includes/filerepo/OldLocalFile.php b/includes/filerepo/OldLocalFile.php index 581bce4680..4906e795fe 100644 --- a/includes/filerepo/OldLocalFile.php +++ b/includes/filerepo/OldLocalFile.php @@ -11,7 +11,10 @@ class OldLocalFile extends LocalFile { const CACHE_VERSION = 1; const MAX_CACHE_ROWS = 20; - static function newFromTitle( $title, $repo, $time ) { + static function newFromTitle( $title, $repo, $time = null ) { + # The null default value is only here to avoid an E_STRICT + if( $time === null ) + throw new MWException( __METHOD__.' got null for $time parameter' ); return new self( $title, $repo, $time, null ); } -- 2.20.1