r32810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32809‎ | r32810 | r32811 >
Date:12:26, 5 April 2008
Author:ialex
Status:old
Tags:
Comment:
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()
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)
  • /trunk/phase3/includes/filerepo/Image.php (added) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/OldLocalFile.php
@@ -11,7 +11,10 @@
1212 const CACHE_VERSION = 1;
1313 const MAX_CACHE_ROWS = 20;
1414
15 - static function newFromTitle( $title, $repo, $time ) {
 15+ static function newFromTitle( $title, $repo, $time = null ) {
 16+ # The null default value is only here to avoid an E_STRICT
 17+ if( $time === null )
 18+ throw new MWException( __METHOD__.' got null for $time parameter' );
1619 return new self( $title, $repo, $time, null );
1720 }
1821
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -56,8 +56,10 @@
5757 /**
5858 * Create a LocalFile from a title
5959 * Do not call this except from inside a repo class.
 60+ *
 61+ * Note: $unused param is only here to avoid an E_STRICT
6062 */
61 - static function newFromTitle( $title, $repo ) {
 63+ static function newFromTitle( $title, $repo, $unused = null ) {
6264 return new self( $title, $repo );
6365 }
6466
@@ -1091,75 +1093,6 @@
10921094 #------------------------------------------------------------------------------
10931095
10941096 /**
1095 - * Backwards compatibility class
1096 - */
1097 -class Image extends LocalFile {
1098 - function __construct( $title ) {
1099 - $repo = RepoGroup::singleton()->getLocalRepo();
1100 - parent::__construct( $title, $repo );
1101 - }
1102 -
1103 - /**
1104 - * Wrapper for wfFindFile(), for backwards-compatibility only
1105 - * Do not use in core code.
1106 - * @deprecated
1107 - */
1108 - static function newFromTitle( $title, $time = false ) {
1109 - $img = wfFindFile( $title, $time );
1110 - if ( !$img ) {
1111 - $img = wfLocalFile( $title );
1112 - }
1113 - return $img;
1114 - }
1115 -
1116 - /**
1117 - * Wrapper for wfFindFile(), for backwards-compatibility only.
1118 - * Do not use in core code.
1119 - *
1120 - * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
1121 - * @return image object or null if invalid title
1122 - * @deprecated
1123 - */
1124 - static function newFromName( $name ) {
1125 - $title = Title::makeTitleSafe( NS_IMAGE, $name );
1126 - if ( is_object( $title ) ) {
1127 - $img = wfFindFile( $title );
1128 - if ( !$img ) {
1129 - $img = wfLocalFile( $title );
1130 - }
1131 - return $img;
1132 - } else {
1133 - return NULL;
1134 - }
1135 - }
1136 -
1137 - /**
1138 - * Return the URL of an image, provided its name.
1139 - *
1140 - * Backwards-compatibility for extensions.
1141 - * Note that fromSharedDirectory will only use the shared path for files
1142 - * that actually exist there now, and will return local paths otherwise.
1143 - *
1144 - * @param string $name Name of the image, without the leading "Image:"
1145 - * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
1146 - * @return string URL of $name image
1147 - * @deprecated
1148 - */
1149 - static function imageUrl( $name, $fromSharedDirectory = false ) {
1150 - $image = null;
1151 - if( $fromSharedDirectory ) {
1152 - $image = wfFindFile( $name );
1153 - }
1154 - if( !$image ) {
1155 - $image = wfLocalFile( $name );
1156 - }
1157 - return $image->getUrl();
1158 - }
1159 -}
1160 -
1161 -#------------------------------------------------------------------------------
1162 -
1163 -/**
11641097 * Helper class for file deletion
11651098 */
11661099 class LocalFileDeleteBatch {
Index: trunk/phase3/includes/filerepo/File.php
@@ -723,7 +723,7 @@
724724
725725 /** Get the path of the archive directory, or a particular file if $suffix is specified */
726726 function getArchivePath( $suffix = false ) {
727 - return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel();
 727+ return $this->repo->getZonePath('public') . '/' . $this->getArchiveRel( $suffix );
728728 }
729729
730730 /** Get the path of the thumbnail directory, or a particular file if $suffix is specified */
Index: trunk/phase3/includes/filerepo/Image.php
@@ -0,0 +1,69 @@
 2+<?php
 3+
 4+/**
 5+ * Backwards compatibility class
 6+ * @deprecated
 7+ */
 8+class Image extends LocalFile {
 9+ function __construct( $title ) {
 10+ $repo = RepoGroup::singleton()->getLocalRepo();
 11+ parent::__construct( $title, $repo );
 12+ }
 13+
 14+ /**
 15+ * Wrapper for wfFindFile(), for backwards-compatibility only
 16+ * Do not use in core code.
 17+ * @deprecated
 18+ */
 19+ static function newFromTitle( $title, $time = false ) {
 20+ $img = wfFindFile( $title, $time );
 21+ if ( !$img ) {
 22+ $img = wfLocalFile( $title );
 23+ }
 24+ return $img;
 25+ }
 26+
 27+ /**
 28+ * Wrapper for wfFindFile(), for backwards-compatibility only.
 29+ * Do not use in core code.
 30+ *
 31+ * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
 32+ * @return image object or null if invalid title
 33+ * @deprecated
 34+ */
 35+ static function newFromName( $name ) {
 36+ $title = Title::makeTitleSafe( NS_IMAGE, $name );
 37+ if ( is_object( $title ) ) {
 38+ $img = wfFindFile( $title );
 39+ if ( !$img ) {
 40+ $img = wfLocalFile( $title );
 41+ }
 42+ return $img;
 43+ } else {
 44+ return NULL;
 45+ }
 46+ }
 47+
 48+ /**
 49+ * Return the URL of an image, provided its name.
 50+ *
 51+ * Backwards-compatibility for extensions.
 52+ * Note that fromSharedDirectory will only use the shared path for files
 53+ * that actually exist there now, and will return local paths otherwise.
 54+ *
 55+ * @param string $name Name of the image, without the leading "Image:"
 56+ * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
 57+ * @return string URL of $name image
 58+ * @deprecated
 59+ */
 60+ static function imageUrl( $name, $fromSharedDirectory = false ) {
 61+ $image = null;
 62+ if( $fromSharedDirectory ) {
 63+ $image = wfFindFile( $name );
 64+ }
 65+ if( !$image ) {
 66+ $image = wfLocalFile( $name );
 67+ }
 68+ return $image->getUrl();
 69+ }
 70+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/filerepo/Image.php
___________________________________________________________________
Name: svn:eol-style
171 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -297,7 +297,7 @@
298298 'ForeignDBRepo' => 'includes/filerepo/ForeignDBRepo.php',
299299 'ForeignDBViaLBRepo' => 'includes/filerepo/ForeignDBViaLBRepo.php',
300300 'FSRepo' => 'includes/filerepo/FSRepo.php',
301 - 'Image' => 'includes/filerepo/LocalFile.php',
 301+ 'Image' => 'includes/filerepo/Image.php',
302302 'LocalFileDeleteBatch' => 'includes/filerepo/LocalFile.php',
303303 'LocalFile' => 'includes/filerepo/LocalFile.php',
304304 'LocalFileRestoreBatch' => 'includes/filerepo/LocalFile.php',

Status & tagging log