r19745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19744‎ | r19745 | r19746 >
Date:22:31, 3 February 2007
Author:hashar
Status:old
Tags:
Comment:
Kill all whitespaces
Modified paths:
  • /trunk/phase3/includes/Image.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Image.php
@@ -90,7 +90,7 @@
9191 $this->dataLoaded = false;
9292 }
9393
94 -
 94+
9595 /**
9696 * Normalize a file extension to the common form, and ensure it's clean.
9797 * Extensions with non-alphanumeric characters will be discarded.
@@ -113,7 +113,7 @@
114114 return '';
115115 }
116116 }
117 -
 117+
118118 /**
119119 * Get the memcached keys
120120 * Returns an array, first element is the local cache key, second is the shared cache key, if there is one
@@ -477,7 +477,7 @@
478478 }
479479 wfProfileOut( __METHOD__ );
480480 }
481 -
 481+
482482 /**
483483 * Split an internet media type into its two components; if not
484484 * a two-part name, set the minor type to 'unknown'.
@@ -964,7 +964,7 @@
965965 */
966966 function validateThumbParams( &$width, &$height ) {
967967 global $wgSVGMaxSize, $wgMaxImageArea;
968 -
 968+
969969 $this->load();
970970
971971 if ( ! $this->exists() )
@@ -972,9 +972,9 @@
973973 # If there is no image, there will be no thumbnail
974974 return false;
975975 }
976 -
 976+
977977 $width = intval( $width );
978 -
 978+
979979 # Sanity check $width
980980 if( $width <= 0 || $this->width <= 0) {
981981 # BZZZT
@@ -1003,7 +1003,7 @@
10041004 $height = round( $this->height * $width / $this->width );
10051005 return true;
10061006 }
1007 -
 1007+
10081008 /**
10091009 * Create a thumbnail of the image having the specified width.
10101010 * The thumbnail will not be created if the width is larger than the
@@ -1035,7 +1035,7 @@
10361036 wfProfileOut( __METHOD__ );
10371037 return $thumb;
10381038 }
1039 -
 1039+
10401040 list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
10411041 if ( $isScriptUrl && $useScript ) {
10421042 // Use thumb.php to render the image
@@ -1074,7 +1074,7 @@
10751075 @unlink( $thumbDir );
10761076 }
10771077 wfMkdirParents( $thumbDir );
1078 -
 1078+
10791079 $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ).
10801080 '/'.$thumbName;
10811081 $done = false;
@@ -1148,7 +1148,7 @@
11491149 $err = false;
11501150 $cmd = "";
11511151 $retval = 0;
1152 -
 1152+
11531153 if( $this->mime === "image/svg" ) {
11541154 #Right now we have only SVG
11551155
@@ -1185,7 +1185,7 @@
11861186
11871187 } elseif ( $wgUseImageMagick ) {
11881188 # use ImageMagick
1189 -
 1189+
11901190 if ( $this->mime == 'image/jpeg' ) {
11911191 $quality = "-quality 80"; // 80%
11921192 } elseif ( $this->mime == 'image/png' ) {
@@ -1196,11 +1196,11 @@
11971197
11981198 # Specify white background color, will be used for transparent images
11991199 # in Internet Explorer/Windows instead of default black.
1200 -
 1200+
12011201 # Note, we specify "-size {$width}" and NOT "-size {$width}x{$height}".
12021202 # It seems that ImageMagick has a bug wherein it produces thumbnails of
12031203 # the wrong size in the second case.
1204 -
 1204+
12051205 $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) .
12061206 " {$quality} -background white -size {$width} ".
12071207 wfEscapeShellArg($this->imagePath) .
@@ -1233,7 +1233,7 @@
12341234 #
12351235 # First find out what kind of file this is, and select the correct
12361236 # input routine for this.
1237 -
 1237+
12381238 $typemap = array(
12391239 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
12401240 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( &$this, 'imageJpegWrapper' ) ),
@@ -1319,7 +1319,7 @@
13201320
13211321 if ( is_dir( $dir ) ) {
13221322 $handle = opendir( $dir );
1323 -
 1323+
13241324 if ( $handle ) {
13251325 while ( false !== ( $file = readdir($handle) ) ) {
13261326 if ( $file{0} != '.' ) {
@@ -1376,7 +1376,7 @@
13771377 wfPurgeSquidServers( $urls );
13781378 }
13791379 }
1380 -
 1380+
13811381 /**
13821382 * Purge the image description page, but don't go after
13831383 * pages using the image. Use when modifying file history
@@ -1387,7 +1387,7 @@
13881388 $page->invalidateCache();
13891389 $page->purgeSquid();
13901390 }
1391 -
 1391+
13921392 /**
13931393 * Purge metadata and all affected pages when the image is created,
13941394 * deleted, or majorly updated. A set of additional URLs may be
@@ -1398,7 +1398,7 @@
13991399 // Delete thumbnails and refresh image metadata cache
14001400 $this->purgeCache();
14011401 $this->purgeDescription();
1402 -
 1402+
14031403 // Purge cache of all pages using this image
14041404 $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
14051405 $update->doUpdate();
@@ -1720,7 +1720,7 @@
17211721 wfProfileOut( __METHOD__ );
17221722 return $retVal;
17231723 }
1724 -
 1724+
17251725 /**
17261726 * Retrive Exif data from the file and prune unrecognized tags
17271727 * and/or tags with invalid contents
@@ -1730,7 +1730,7 @@
17311731 */
17321732 private function retrieveExifData( $filename ) {
17331733 global $wgShowEXIF;
1734 -
 1734+
17351735 /*
17361736 if ( $this->getMimeType() !== "image/jpeg" )
17371737 return array();
@@ -1740,7 +1740,7 @@
17411741 $exif = new Exif( $filename );
17421742 return $exif->getFilteredData();
17431743 }
1744 -
 1744+
17451745 return array();
17461746 }
17471747
@@ -1800,7 +1800,7 @@
18011801 function isLocal() {
18021802 return !$this->fromSharedDirectory;
18031803 }
1804 -
 1804+
18051805 /**
18061806 * Was this image ever deleted from the wiki?
18071807 *
@@ -1810,7 +1810,7 @@
18111811 $title = Title::makeTitle( NS_IMAGE, $this->name );
18121812 return ( $title->isDeleted() > 0 );
18131813 }
1814 -
 1814+
18151815 /**
18161816 * Delete all versions of the image.
18171817 *
@@ -1825,34 +1825,34 @@
18261826 function delete( $reason ) {
18271827 $transaction = new FSTransaction();
18281828 $urlArr = array( $this->getURL() );
1829 -
 1829+
18301830 if( !FileStore::lock() ) {
18311831 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
18321832 return false;
18331833 }
1834 -
 1834+
18351835 try {
18361836 $dbw = wfGetDB( DB_MASTER );
18371837 $dbw->begin();
1838 -
 1838+
18391839 // Delete old versions
18401840 $result = $dbw->select( 'oldimage',
18411841 array( 'oi_archive_name' ),
18421842 array( 'oi_name' => $this->name ) );
1843 -
 1843+
18441844 while( $row = $dbw->fetchObject( $result ) ) {
18451845 $oldName = $row->oi_archive_name;
1846 -
 1846+
18471847 $transaction->add( $this->prepareDeleteOld( $oldName, $reason ) );
1848 -
 1848+
18491849 // We'll need to purge this URL from caches...
18501850 $urlArr[] = wfImageArchiveUrl( $oldName );
18511851 }
18521852 $dbw->freeResult( $result );
1853 -
 1853+
18541854 // And the current version...
18551855 $transaction->add( $this->prepareDeleteCurrent( $reason ) );
1856 -
 1856+
18571857 $dbw->immediateCommit();
18581858 } catch( MWException $e ) {
18591859 wfDebug( __METHOD__.": db error, rolling back file transactions\n" );
@@ -1860,22 +1860,22 @@
18611861 FileStore::unlock();
18621862 throw $e;
18631863 }
1864 -
 1864+
18651865 wfDebug( __METHOD__.": deleted db items, applying file transactions\n" );
18661866 $transaction->commit();
18671867 FileStore::unlock();
18681868
1869 -
 1869+
18701870 // Update site_stats
18711871 $site_stats = $dbw->tableName( 'site_stats' );
18721872 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", __METHOD__ );
1873 -
 1873+
18741874 $this->purgeEverything( $urlArr );
1875 -
 1875+
18761876 return true;
18771877 }
1878 -
1879 -
 1878+
 1879+
18801880 /**
18811881 * Delete an old version of the image.
18821882 *
@@ -1891,12 +1891,12 @@
18921892 function deleteOld( $archiveName, $reason ) {
18931893 $transaction = new FSTransaction();
18941894 $urlArr = array();
1895 -
 1895+
18961896 if( !FileStore::lock() ) {
18971897 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
18981898 return false;
18991899 }
1900 -
 1900+
19011901 $transaction = new FSTransaction();
19021902 try {
19031903 $dbw = wfGetDB( DB_MASTER );
@@ -1909,11 +1909,11 @@
19101910 FileStore::unlock();
19111911 throw $e;
19121912 }
1913 -
 1913+
19141914 wfDebug( __METHOD__.": deleted db items, applying file transaction\n" );
19151915 $transaction->commit();
19161916 FileStore::unlock();
1917 -
 1917+
19181918 $this->purgeDescription();
19191919
19201920 // Squid purging
@@ -1926,7 +1926,7 @@
19271927 }
19281928 return true;
19291929 }
1930 -
 1930+
19311931 /**
19321932 * Delete the current version of a file.
19331933 * May throw a database error.
@@ -2000,12 +2000,12 @@
20012001 */
20022002 private function prepareDeleteVersion( $path, $reason, $table, $fieldMap, $where, $fname ) {
20032003 global $wgUser, $wgSaveDeletedFiles;
2004 -
 2004+
20052005 // Dupe the file into the file store
20062006 if( file_exists( $path ) ) {
20072007 if( $wgSaveDeletedFiles ) {
20082008 $group = 'deleted';
2009 -
 2009+
20102010 $store = FileStore::get( $group );
20112011 $key = FileStore::calculateKey( $path, $this->extension );
20122012 $transaction = $store->insert( $key, $path,
@@ -2021,24 +2021,24 @@
20222022 $key = null;
20232023 $transaction = new FSTransaction(); // empty
20242024 }
2025 -
 2025+
20262026 if( $transaction === false ) {
20272027 // Fail to restore?
20282028 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
20292029 throw new MWException( "Could not archive and delete file $path" );
20302030 return false;
20312031 }
2032 -
 2032+
20332033 $dbw = wfGetDB( DB_MASTER );
20342034 $storageMap = array(
20352035 'fa_storage_group' => $dbw->addQuotes( $group ),
20362036 'fa_storage_key' => $dbw->addQuotes( $key ),
2037 -
 2037+
20382038 'fa_deleted_user' => $dbw->addQuotes( $wgUser->getId() ),
20392039 'fa_deleted_timestamp' => $dbw->timestamp(),
20402040 'fa_deleted_reason' => $dbw->addQuotes( $reason ) );
20412041 $allFields = array_merge( $storageMap, $fieldMap );
2042 -
 2042+
20432043 try {
20442044 if( $wgSaveDeletedFiles ) {
20452045 $dbw->insertSelect( 'filearchive', $table, $allFields, $where, $fname );
@@ -2051,10 +2051,10 @@
20522052 $transaction->rollback();
20532053 throw $e;
20542054 }
2055 -
 2055+
20562056 return $transaction;
20572057 }
2058 -
 2058+
20592059 /**
20602060 * Restore all or specified deleted revisions to the given file.
20612061 * Permissions and logging are left to the caller.
@@ -2071,31 +2071,31 @@
20722072 wfDebug( __METHOD__." could not acquire filestore lock\n" );
20732073 return false;
20742074 }
2075 -
 2075+
20762076 $transaction = new FSTransaction();
20772077 try {
20782078 $dbw = wfGetDB( DB_MASTER );
20792079 $dbw->begin();
2080 -
 2080+
20812081 // Re-confirm whether this image presently exists;
20822082 // if no we'll need to create an image record for the
20832083 // first item we restore.
20842084 $exists = $dbw->selectField( 'image', '1',
20852085 array( 'img_name' => $this->name ),
20862086 __METHOD__ );
2087 -
 2087+
20882088 // Fetch all or selected archived revisions for the file,
20892089 // sorted from the most recent to the oldest.
20902090 $conditions = array( 'fa_name' => $this->name );
20912091 if( $versions ) {
20922092 $conditions['fa_id'] = $versions;
20932093 }
2094 -
 2094+
20952095 $result = $dbw->select( 'filearchive', '*',
20962096 $conditions,
20972097 __METHOD__,
20982098 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
2099 -
 2099+
21002100 if( $dbw->numRows( $result ) < count( $versions ) ) {
21012101 // There's some kind of conflict or confusion;
21022102 // we can't restore everything we were asked to.
@@ -2112,7 +2112,7 @@
21132113 FileStore::unlock();
21142114 return true;
21152115 }
2116 -
 2116+
21172117 $revisions = 0;
21182118 while( $row = $dbw->fetchObject( $result ) ) {
21192119 $revisions++;
@@ -2121,20 +2121,20 @@
21222122 wfDebug( __METHOD__.": skipping row with no file.\n" );
21232123 continue;
21242124 }
2125 -
 2125+
21262126 if( $revisions == 1 && !$exists ) {
21272127 $destDir = wfImageDir( $row->fa_name );
21282128 if ( !is_dir( $destDir ) ) {
21292129 wfMkdirParents( $destDir );
21302130 }
21312131 $destPath = $destDir . DIRECTORY_SEPARATOR . $row->fa_name;
2132 -
 2132+
21332133 // We may have to fill in data if this was originally
21342134 // an archived file revision.
21352135 if( is_null( $row->fa_metadata ) ) {
21362136 $tempFile = $store->filePath( $row->fa_storage_key );
21372137 $metadata = serialize( $this->retrieveExifData( $tempFile ) );
2138 -
 2138+
21392139 $magic = MimeMagic::singleton();
21402140 $mime = $magic->guessMimeType( $tempFile, true );
21412141 $media_type = $magic->getMediaType( $tempFile, $mime );
@@ -2145,7 +2145,7 @@
21462146 $minor_mime = $row->fa_minor_mime;
21472147 $media_type = $row->fa_media_type;
21482148 }
2149 -
 2149+
21502150 $table = 'image';
21512151 $fields = array(
21522152 'img_name' => $row->fa_name,
@@ -2176,7 +2176,7 @@
21772177 wfMkdirParents( $destDir );
21782178 }
21792179 $destPath = $destDir . DIRECTORY_SEPARATOR . $archiveName;
2180 -
 2180+
21812181 $table = 'oldimage';
21822182 $fields = array(
21832183 'oi_name' => $row->fa_name,
@@ -2190,13 +2190,13 @@
21912191 'oi_user_text' => $row->fa_user_text,
21922192 'oi_timestamp' => $row->fa_timestamp );
21932193 }
2194 -
 2194+
21952195 $dbw->insert( $table, $fields, __METHOD__ );
21962196 /// @fixme this delete is not totally safe, potentially
21972197 $dbw->delete( 'filearchive',
21982198 array( 'fa_id' => $row->fa_id ),
21992199 __METHOD__ );
2200 -
 2200+
22012201 // Check if any other stored revisions use this file;
22022202 // if so, we shouldn't remove the file from the deletion
22032203 // archives so they will still work.
@@ -2212,36 +2212,36 @@
22132213 } else {
22142214 $flags = 0;
22152215 }
2216 -
 2216+
22172217 $transaction->add( $store->export( $row->fa_storage_key,
22182218 $destPath, $flags ) );
22192219 }
2220 -
 2220+
22212221 $dbw->immediateCommit();
22222222 } catch( MWException $e ) {
22232223 wfDebug( __METHOD__." caught error, aborting\n" );
22242224 $transaction->rollback();
22252225 throw $e;
22262226 }
2227 -
 2227+
22282228 $transaction->commit();
22292229 FileStore::unlock();
2230 -
 2230+
22312231 if( $revisions > 0 ) {
22322232 if( !$exists ) {
22332233 wfDebug( __METHOD__." restored $revisions items, creating a new current\n" );
2234 -
 2234+
22352235 // Update site_stats
22362236 $site_stats = $dbw->tableName( 'site_stats' );
22372237 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", __METHOD__ );
2238 -
 2238+
22392239 $this->purgeEverything();
22402240 } else {
22412241 wfDebug( __METHOD__." restored $revisions as archived versions\n" );
22422242 $this->purgeDescription();
22432243 }
22442244 }
2245 -
 2245+
22462246 return $revisions;
22472247 }
22482248
@@ -2274,7 +2274,7 @@
22752275 if ( isset( $this->multiPageXML ) ) {
22762276 return true;
22772277 }
2278 -
 2278+
22792279 #
22802280 # Check for files uploaded prior to DJVU support activation,
22812281 # or damaged.
@@ -2328,7 +2328,7 @@
23292329 return null;
23302330 }
23312331 }
2332 -
 2332+
23332333 } //class
23342334
23352335 /**