From 8d4c6af284d60c9d24ce2576c739911d9c5ac74a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 23 Dec 2006 09:03:36 +0000 Subject: [PATCH] revert r18517; should have been on branch --- includes/AutoLoader.php | 1 - includes/Image.php | 139 ++++++------------------------------ includes/ImageFunctions.php | 9 +-- includes/SpecialUpload.php | 2 +- 4 files changed, 26 insertions(+), 125 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index d559ca08c4..8de5608f06 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -256,7 +256,6 @@ function __autoload($className) { 'Spyc' => 'includes/api/ApiFormatYaml_spyc.php', 'ApiFormatYaml' => 'includes/api/ApiFormatYaml.php', 'ApiHelp' => 'includes/api/ApiHelp.php', - 'ApiInstantCommons' => 'includes/api/ApiInstantCommons.php', 'ApiLogin' => 'includes/api/ApiLogin.php', 'ApiMain' => 'includes/api/ApiMain.php', 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php', diff --git a/includes/Image.php b/includes/Image.php index dc697d5ddd..1f3895c600 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -35,8 +35,6 @@ class Image $title, # Title object for this image (constructor) $fileExists, # does the image file exist on disk? (loadFromXxx) $fromSharedDirectory, # load this image from $wgSharedUploadDirectory (loadFromXxx) - $fromInstantCommons, # load this image from the InstantCommons repository - $description, #added in for instantCommons $historyLine, # Number of line to return by nextHistoryLine() (constructor) $historyRes, # result of the query for the image's history (nextHistoryLine) $width, # \ @@ -217,7 +215,6 @@ class Image 'imagePath' => $this->imagePath, 'fileExists' => $this->fileExists, 'fromShared' => $this->fromSharedDirectory, - 'fromInstantCommons' => $this->fromInstantCommons, 'width' => $this->width, 'height' => $this->height, 'bits' => $this->bits, @@ -252,14 +249,13 @@ class Image # In case we're on a wgCapitalLinks=false wiki, we # capitalize the first letter of the filename before # looking it up in the shared repository. - $sharedImage = Image::newFromName( $wgContLang->ucfirst($this->name) ); + $sharedImage = Image::newFromName( $wgContLang->ucfirst($this->name) ); $this->fileExists = $sharedImage && file_exists( $sharedImage->getFullPath(true) ); if ( $this->fileExists ) { $this->name = $sharedImage->name; $this->imagePath = $this->getFullPath(true); $this->fromSharedDirectory = true; } - } @@ -329,7 +325,7 @@ class Image * Load image metadata from the DB */ function loadFromDB() { - global $wgUseSharedUploads, $wgSharedUploadDBname, $wgSharedUploadDBprefix, $wgContLang, $wgUseInstantCommons, $wgInstantCommonsServerPath, $wgUploadDirectory; + global $wgUseSharedUploads, $wgSharedUploadDBname, $wgSharedUploadDBprefix, $wgContLang; wfProfileIn( __METHOD__ ); $dbr =& wfGetDB( DB_SLAVE ); @@ -337,7 +333,7 @@ class Image $row = $dbr->selectRow( 'image', array( 'img_size', 'img_width', 'img_height', 'img_bits', - 'img_media_type', 'img_major_mime', 'img_minor_mime', 'img_metadata','img_description' ), + 'img_media_type', 'img_major_mime', 'img_minor_mime', 'img_metadata' ), array( 'img_name' => $this->name ), __METHOD__ ); if ( $row ) { $this->fromSharedDirectory = false; @@ -348,7 +344,7 @@ class Image if ( is_null($this->type) ) { $this->upgradeRow(); } - } elseif ( ($wgUseSharedUploads && $wgSharedUploadDBname)) { + } elseif ( $wgUseSharedUploads && $wgSharedUploadDBname ) { # In case we're on a wgCapitalLinks=false wiki, we # capitalize the first letter of the filename before # looking it up in the shared repository. @@ -358,7 +354,7 @@ class Image $row = $dbc->selectRow( "`$wgSharedUploadDBname`.{$wgSharedUploadDBprefix}image", array( 'img_size', 'img_width', 'img_height', 'img_bits', - 'img_media_type', 'img_major_mime', 'img_minor_mime', 'img_metadata', 'img_description' ), + 'img_media_type', 'img_major_mime', 'img_minor_mime', 'img_metadata' ), array( 'img_name' => $name ), __METHOD__ ); if ( $row ) { $this->fromSharedDirectory = true; @@ -372,83 +368,7 @@ class Image $this->upgradeRow(); } } - } elseif ( $wgUseInstantCommons && $wgInstantCommonsServerPath ){ - //NB: We enter into this loop even when we're uploading to the wiki. - //Download the file from the InstantCommonsServer. - //store it in the image database and return an Image object It should - //return an object identical to a database row as above - - $ch = curl_init($wgInstantCommonsServerPath.'/api.php?action=instantcommons&format=xml&media='.$this->name); - $fp = fopen("icresponse.xml", "w"); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_exec($ch); - curl_close($ch); - //offer various methods of fetching the remote - //file data - /* - if(function_exists('json_decode')) - { - $row = utf8_decode(json_decode(fread($fp))); - } - else - { - wfDebug('Reading aborted'.__METHOD__.':'.__LINE__.' in '.__FILE__); - }*/ - $p =& new ApiInstantCommons('instantcommons', 'maint'); - - fclose($fp); - - //$fpr = fopen('icresponse.xml', 'r'); - //$xmlString = fread($fpr, 409600); - $xmlString = file_get_contents('icresponse.xml'); - wfDebug("xmlS=".$xmlString.__METHOD__.':'.__LINE__.' in '.__FILE__); - if(trim($xmlString)!=""){ - //$row = ($p->parse($xmlString)); - //$row = $row[0]['children'][0]['children'][0]['attrs']; - } - if ( $row ) { - //create the local file directory ($this->mSavedFile) - UploadForm::saveUploadedFile( $row['NAME'], - $row['NAME'] - ); //just creates the path - //now download the file to the final location - $ch = curl_init($wgInstantCommonsServerPath.$row['URL']); - $fp = fopen("{$this->mSavedFile}", "w"); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_exec($ch); - curl_close($ch); - - - //set further properties - $this->fromInstantCommons = true; //TODO:THIS IS NOT STORED! - $this->fileExists = true; - $this->imagePath = $this->getFullPath(false, true); - $this->width = $row['WIDTH']; - $this->height = $row['HEIGHT']; - $this->metadata = stripslashes($row['METADATA']); - $this->bits = $row['BITS']; - $this->type = $row['TYPE']; - $this->mime = $row['MIME']; - $this->size = $row['SIZE']; - $this->dataLoaded = $row['DATALOADED']; - $this->attr = $row['ATTR']; - $this->historyLine = $row['HISTORYLINE']; - $this->historyRes = $row['HISTORYRES']; - /** - * Update the upload log and create the description page - * if it's a new file. - */ - $success = $this->recordUpload('Downloaded with InstantCommons!', $row['DESCRIPTION']); - if ( $success ) { - wfRunHooks( 'UploadComplete', array( &$this ) ); - } - - } - - } - + } if ( !$row ) { $this->size = 0; @@ -476,7 +396,6 @@ class Image $this->height = $row->img_height; $this->bits = $row->img_bits; $this->type = $row->img_media_type; - $this->description = $row->img_description; $major= $row->img_major_mime; $minor= $row->img_minor_mime; @@ -497,12 +416,12 @@ class Image * Load image metadata from cache or DB, unless already loaded */ function load() { - global $wgSharedUploadDBname, $wgUseSharedUploads, $wgUseInstantCommons; - if ( !$this->dataLoaded ) { + global $wgSharedUploadDBname, $wgUseSharedUploads; + if ( !$this->dataLoaded ) { if ( !$this->loadFromCache() ) { $this->loadFromDB(); if ( !$wgSharedUploadDBname && $wgUseSharedUploads ) { - $this->loadFromFile(); + $this->loadFromFile(); } elseif ( $this->fileExists || !$wgUseSharedUploads ) { // We can do negative caching for local images, because the cache // will be purged on upload. But we can't do it when shared images @@ -600,7 +519,7 @@ class Image if ( !$this->url ) { $this->load(); if($this->fileExists) { - $this->url = Image::imageUrl( $this->name, $this->fromSharedDirectory, $this->fromInstantCommons ); + $this->url = Image::imageUrl( $this->name, $this->fromSharedDirectory ); } else { $this->url = ''; } @@ -855,20 +774,16 @@ class Image * @public * @static */ - function imageUrl( $name, $fromSharedDirectory = false, $fromInstantCommons = false ) { - global $wgUploadPath,$wgUploadBaseUrl,$wgSharedUploadPath, $wgInstantCommonsServerPath; - if($fromInstantCommons) { //check if this is set first before checking shared directory - $base = ''; - $path = $wgInstantCommonsServerPath; - } - else if($fromSharedDirectory) { + function imageUrl( $name, $fromSharedDirectory = false ) { + global $wgUploadPath,$wgUploadBaseUrl,$wgSharedUploadPath; + if($fromSharedDirectory) { $base = ''; $path = $wgSharedUploadPath; } else { $base = $wgUploadBaseUrl; $path = $wgUploadPath; } - $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory, $fromInstantCommons) . "{$name}"; + $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$name}"; return wfUrlencode( $url ); } @@ -887,7 +802,7 @@ class Image * @private */ function thumbUrl( $width, $subdir='thumb') { - global $wgUploadPath, $wgUploadBaseUrl, $wgSharedUploadPath, $wgInstantCommonsServerPath; + global $wgUploadPath, $wgUploadBaseUrl, $wgSharedUploadPath; global $wgSharedThumbnailScriptPath, $wgThumbnailScriptPath; // Generate thumb.php URL if possible @@ -919,7 +834,7 @@ class Image } if ( Image::isHashed( $this->fromSharedDirectory ) ) { $url = "{$base}{$path}/{$subdir}" . - wfGetHashPath($this->name, $this->fromSharedDirectory, $this->fromInstantCommons) + wfGetHashPath($this->name, $this->fromSharedDirectory) . $this->name.'/'.$name; $url = wfUrlencode( $url ); } else { @@ -1595,27 +1510,19 @@ class Image * options in DefaultSettings.php) instead of a local one. * */ - function getFullPath( $fromSharedRepository = false, $fromInstantCommons = false ) { - global $wgUploadDirectory, $wgSharedUploadDirectory, $wgInstantCommonsServerPath; - //use local repository paths only if InstantCommons path is not available - $dir = $fromInstantCommons ? $wgInstantCommonsServerPath : ($fromSharedRepository ? $wgSharedUploadDirectory : - $wgUploadDirectory); + function getFullPath( $fromSharedRepository = false ) { + global $wgUploadDirectory, $wgSharedUploadDirectory; + + $dir = $fromSharedRepository ? $wgSharedUploadDirectory : + $wgUploadDirectory; // $wgSharedUploadDirectory may be false, if thumb.php is used if ( $dir ) { - if($fromInstantCommons) - {//TODO: Not the best thing to do here as it adds another 10k to - //the default mediawiki install. Maybe point it to the default logo? - $fullpath = 'downloading.png'; - } - else - { - $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository, $fromInstantCommons) . $this->name; - } + $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository) . $this->name; } else { $fullpath = false; } - + return $fullpath; } diff --git a/includes/ImageFunctions.php b/includes/ImageFunctions.php index f7a78ecafd..931fdff177 100644 --- a/includes/ImageFunctions.php +++ b/includes/ImageFunctions.php @@ -78,14 +78,9 @@ function wfImageArchiveDir( $fname , $subdir='archive', $shared=false ) { * @param $dbkey The filesystem / database name of the file * @param $fromSharedDirectory Use the shared file repository? It may * use different hash settings from the local one. - * TODO:@param $fromInstantCommons Use the InstantCommons repository? - this is calculated by the IC Api */ -function wfGetHashPath ( $dbkey, $fromSharedDirectory = false, $fromInstantCommons = false ) { - if($fromInstantCommons) - {//we will display a local image that indicates that this file is being downloaded - return; - } - elseif( Image::isHashed( $fromSharedDirectory ) ) { +function wfGetHashPath ( $dbkey, $fromSharedDirectory = false ) { + if( Image::isHashed( $fromSharedDirectory ) ) { $hash = md5($dbkey); return '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . '/'; } else { diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index 8cb9db4c91..011cfa6533 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -1230,7 +1230,7 @@ class UploadForm { } $error = ''; - if( $img->exists('upload') ) { + if( $img->exists() ) { global $wgUser, $wgOut; if( $img->isLocal() ) { if( !$wgUser->isAllowed( 'reupload' ) ) { -- 2.20.1