Index: includes/DefaultSettings.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/DefaultSettings.php,v retrieving revision 1.251 diff -u -r1.251 DefaultSettings.php --- includes/DefaultSettings.php 2 Mar 2005 01:53:55 -0000 1.251 +++ includes/DefaultSettings.php 11 Mar 2005 10:47:49 -0000 @@ -126,6 +126,8 @@ $wgSharedUploadPath = "http://commons.wikimedia.org/shared/images"; /** Path on the file system where shared uploads can be found */ $wgSharedUploadDirectory = "/var/www/wiki3/images"; +/** Path on the file system where shared uploads can be found */ +$wgSharedUploadDBname = "commons"; /** * Set the following to false especially if you have a set of files that need to Index: includes/Image.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/Image.php,v retrieving revision 1.54 diff -u -r1.54 Image.php --- includes/Image.php 21 Feb 2005 15:33:31 -0000 1.54 +++ includes/Image.php 11 Mar 2005 11:03:52 -0000 @@ -40,67 +40,121 @@ */ function Image( $name ) { - global $wgUseSharedUploads, $wgUseLatin1, $wgSharedLatin1, $wgLang; + global $wgUseSharedUploads, $wgUseLatin1, $wgSharedLatin1, $wgLang, $wgMemc, $wgDBname; $this->name = $name; $this->title = Title::makeTitleSafe( NS_IMAGE, $this->name ); $this->fromSharedDirectory = false; $this->imagePath = $this->getFullPath(); - $this->fileExists = file_exists( $this->imagePath); - - # If the file is not found, and a shared upload directory - # like the Wikimedia Commons is used, look for it there. - if (!$this->fileExists && $wgUseSharedUploads) { - - # 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. - $this->name= $wgLang->ucfirst($name); - - # Encode the filename if we're on a Latin1 wiki and the - # shared repository is UTF-8 - if($wgUseLatin1 && !$wgSharedLatin1) { - $this->name = utf8_encode($name); - } - - $this->imagePath = $this->getFullPath(true); - $this->fileExists = file_exists( $this->imagePath); - $this->fromSharedDirectory = true; - $name=$this->name; - - } - if($this->fileExists) { - $this->url = $this->wfImageUrl( $this->name, $this->fromSharedDirectory ); - } else { - $this->url=''; - } - + $n = strrpos( $name, '.' ); $this->extension = strtolower( $n ? substr( $name, $n + 1 ) : '' ); - + $gis = false; + $hashedName = md5($this->name); + $cachedValues = $wgMemc->get( $cacheKey = "$wgDBname:Image:".$hashedName ); + $foundCached = false; + + if (!empty($cachedValues) && is_array($cachedValues)) { + if ($wgUseSharedUploads && $cachedValues['fromShared']) { + # if this is shared file, we need to check if image + # in shared repository has not changed + $commonsCachedValues = $wgMemc->get( "$wgSharedUploadDBname:Image:".$hashedName ); + if (!empty($commonsCachedValues) && is_array($commonsCachedValues)) { + $this->name = $commonsCachedValues['name']; + $this->imagePath = $commonsCachedValues['imagePath']; + $this->fileExists = $commonsCachedValues['fileExists']; + $this->fromSharedDirectory = true; + $gis = $commonsCachedValues['gis']; + $foundCached = true; + } + } + else { + $this->name = $cachedValues['name']; + $this->imagePath = $cachedValues['imagePath']; + $this->fileExists = $cachedValues['fileExists']; + $this->fromSharedDirectory = false; + $gis = $cachedValues['gis']; + $foundCached = true; + } + } - if ( $this->fileExists ) { - if( $this->extension == 'svg' ) { - @$gis = getSVGsize( $this->imagePath ); - } else { - @$gis = getimagesize( $this->imagePath ); + if (!$foundCached) { + $this->fileExists = file_exists( $this->imagePath); + + # If the file is not found, and a shared upload directory + # like the Wikimedia Commons is used, look for it there. + if (!$this->fileExists && $wgUseSharedUploads) { + + # 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. + $this->name= $wgLang->ucfirst($name); + + # Encode the filename if we're on a Latin1 wiki and the + # shared repository is UTF-8 + if($wgUseLatin1 && !$wgSharedLatin1) { + $this->name = utf8_encode($name); + } + + $this->imagePath = $this->getFullPath(true); + $this->fileExists = file_exists( $this->imagePath); + $this->fromSharedDirectory = true; + $name=$this->name; } - if( $gis !== false ) { - $this->width = $gis[0]; - $this->height = $gis[1]; - $this->type = $gis[2]; - $this->attr = $gis[3]; - if ( isset( $gis['bits'] ) ) { - $this->bits = $gis['bits']; + + if ( $this->fileExists ) { + if( $this->extension == 'svg' ) { + @$gis = getSVGsize( $this->imagePath ); } else { - $this->bits = 0; + @$gis = getimagesize( $this->imagePath ); } } + + $cachedValues = array('name' => $this->name, + 'imagePath' => $this->imagePath, + 'fileExists' => $this->fileExists, + 'fromShared' => $this->fromSharedDirectory, + 'gis' => $gis); + + $wgMemc->set( $cacheKey, $cachedValues ); + + if ($wgUseSharedUploads && $this->fromSharedDirectory) { + $cachedValues['fromShared'] = false; + $wgMemc->set( "$wgSharedUploadDBname:Image:".$hashedName, $cachedValues ); + } + } + + if( $gis !== false ) { + $this->width = $gis[0]; + $this->height = $gis[1]; + $this->type = $gis[2]; + $this->attr = $gis[3]; + if ( isset( $gis['bits'] ) ) { + $this->bits = $gis['bits']; + } else { + $this->bits = 0; + } + } + + if($this->fileExists) { + $this->url = $this->wfImageUrl( $this->name, $this->fromSharedDirectory ); + } else { + $this->url=''; } $this->historyLine = 0; } /** + * Remove image metadata from cache if any + * + * @param string $name the title of an image + */ + function invalidateMetadataCache( $name ) { + global $wgMemc, $wgDBname; + $wgMemc->delete("$wgDBname:Image:".md5($name)); + } + + /** * Factory function * * Create a new image object from a title object. Index: includes/ImagePage.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/ImagePage.php,v retrieving revision 1.62 diff -u -r1.62 ImagePage.php --- includes/ImagePage.php 21 Feb 2005 12:46:35 -0000 1.62 +++ includes/ImagePage.php 11 Mar 2005 11:14:32 -0000 @@ -307,6 +307,9 @@ $article = new Article( $nt ); $article->doDeleteArticle( $reason ); # ignore errors + /* remove data from image metadata cache */ + Image::invalidateMetadataCache( $image ); + $deleted = $image; } @@ -404,6 +407,10 @@ $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); + + /* remove data from image metadata cache */ + Image::invalidateMetadataCache( $name ); + # Squid purging if ( $wgUseSquid ) { $urlArr = Array( Index: includes/SpecialUndelete.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/SpecialUndelete.php,v retrieving revision 1.47 diff -u -r1.47 SpecialUndelete.php --- includes/SpecialUndelete.php 22 Feb 2005 06:03:47 -0000 1.47 +++ includes/SpecialUndelete.php 11 Mar 2005 10:58:09 -0000 @@ -259,7 +259,7 @@ $reason = wfMsg( 'undeletedrevisions', $restoreRevisions ); } $log->addEntry( 'restore', $this->title, $reason ); - + return true; } } @@ -429,6 +429,12 @@ $archive = new PageArchive( $this->mTargetObj ); if( $archive->undelete( $this->mTargetTimestamp ) ) { $wgOut->addWikiText( wfMsg( "undeletedtext", $this->mTarget ) ); + + if (NS_IMAGE == $this->mTargetObj->getNamespace()) { + /* remove data from image metadata cache */ + Image::invalidateMetadataCache( $this->mTargetObj->getText() ); + } + return true; } } Index: includes/SpecialUpload.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/SpecialUpload.php,v retrieving revision 1.54 diff -u -r1.54 SpecialUpload.php --- includes/SpecialUpload.php 21 Feb 2005 12:23:49 -0000 1.54 +++ includes/SpecialUpload.php 11 Mar 2005 10:41:18 -0000 @@ -270,6 +270,10 @@ $this->mUploadDescription, $this->mUploadCopyStatus, $this->mUploadSource ); + + /* remove data from image metadata cache */ + Image::invalidateMetadataCache($this->mUploadSaveName); + $this->showSuccess(); } }