X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=d0285e8960aea5a8c3ff1e47eb70d412f0e4310b;hb=cd724523d697bdbaa2c86d222f81ff660d05d51e;hp=9f0eab9758a5a2a3a209dc2937d619773f4e2fbb;hpb=5f4b3ec0642d1b16524bd614b18a34ca1e6b086a;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/ImagePage.php b/includes/ImagePage.php
index 9f0eab9758..d0285e8960 100644
--- a/includes/ImagePage.php
+++ b/includes/ImagePage.php
@@ -1,18 +1,27 @@
mTitle->getNamespace() ) {
+ if( $this->mTitle->getNamespace() == NS_IMAGE ) {
$this->openShowImage();
}
@@ -22,7 +31,7 @@ class ImagePage extends Article {
# follow it with the history list and link list for the image
# it describes.
- if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
+ if( $this->mTitle->getNamespace() == NS_IMAGE ) {
$this->closeShowImage();
$this->imageHistory();
$this->imageLinks();
@@ -31,35 +40,82 @@ class ImagePage extends Article {
function openShowImage()
{
- global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
+ global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
+ $wgUseImageResize, $wgRepositoryBaseUrl;
$this->img = Image::newFromTitle( $this->mTitle );
- $url = $this->img->getUrl();
- $anchoropen = "";
- $anchorclose = "";
+ $full_url = $this->img->getViewURL();
+ $anchoropen = '';
+ $anchorclose = '';
+
+ if( $wgUser->getOption( 'imagesize' ) == '' ) {
+ $sizeSel = User::getDefaultOption( 'imagesize' );
+ } else {
+ $sizeSel = IntVal( $wgUser->getOption( 'imagesize' ) );
+ }
+ if( !isset( $wgImageLimits[$sizeSel] ) ) {
+ $sizeSel = User::getDefaultOption( 'imagesize' );
+ }
+ $max = $wgImageLimits[$sizeSel];
+ $maxWidth = $max[0];
+ $maxHeight = $max[1];
if ( $this->img->exists() ) {
$sk = $wgUser->getSkin();
- if ( $this->img->getType() != "" ) {
+ if ( $this->img->getType() != '' ) {
# image
$width = $this->img->getWidth();
$height = $this->img->getHeight();
- if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
- $anchoropen = "";
- $anchorclose = '';
- $url=$this->img->createThumb( $wgMaxImageWidth );
- $height = floor( $height * $wgMaxImageWidth / $width );
- $width = $wgMaxImageWidth;
+ $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
+ if ( $width > $maxWidth ) {
+ $height = floor( $height * $maxWidth / $width );
+ $width = $maxWidth;
+ }
+ if ( $height > $maxHeight ) {
+ $width = floor( $width * $maxHeight / $height );
+ $height = $maxHeight;
+ }
+ if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
+ if( $wgUseImageResize ) {
+ $thumbnail = $this->img->getThumbnail( $width );
+
+ if ( ( ! $this->img->mustRender() )
+ && ( $thumbnail->getSize() > $this->img->getSize() ) ) {
+ # the thumbnail is bigger thatn the original image.
+ # show the original image instead of the thumb.
+ $url = $full_url;
+ $width = $this->img->getWidth();
+ $height = $this->img->getHeight();
+ } else {
+ $url = $thumbnail->getUrl();
+ }
+ } else {
+ # No resize ability? Show the full image, but scale
+ # it down in the browser so it fits on the page.
+ $url = $full_url;
+ }
+ $anchoropen = "";
+ $anchorclose = "
\n$anchoropen{$msg}";
+ } else {
+ $url = $full_url;
}
- $s = "
" . wfMsg( "nolinkstoimage" ) . "
\n" ); + $wgOut->addHtml( '' . wfMsg( "nolinkstoimage" ) . "
\n" ); return; } - $wgOut->addHTML( "" . wfMsg( "linkstoimage" ) . "
\n' . wfMsg( 'linkstoimage' ) . "
\n" . $text . "
\n" ); + $wgOut->addHTML( '' . $text . "
\n" ); $wgOut->returnToMain( false ); } @@ -255,30 +333,56 @@ class ImagePage extends Article { $name = substr( $oldimage, 15 ); $archive = wfImageArchiveDir( $name ); - if ( ! unlink( "{$archive}/{$oldimage}" ) ) { + + # Delete the image if it exists. Sometimes the file will be missing + # due to manual intervention or weird sync problems; treat that + # condition gracefully and continue to delete the database entry. + # Also some records may end up with an empty oi_archive_name field + # if the original file was missing when a new upload was made; + # don't try to delete the directory then! + # + $targetFile = "{$archive}/{$oldimage}"; + if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) { + # If we actually have a file and can't delete it, throw an error. $wgOut->fileDeleteError( "{$archive}/{$oldimage}" ); + } else { + # Log the deletion + $log = new LogPage( 'delete' ); + $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) ); } } function revert() { - global $wgOut, $wgRequest; + global $wgOut, $wgRequest, $wgUser; global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList; $oldimage = $wgRequest->getText( 'oldimage' ); - if ( strlen( $oldimage ) < 16 ) { - $wgOut->unexpectedValueError( "oldimage", $oldimage ); + $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + return; + } + if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) { + $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } + if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } + if( $wgUser->isAnon() ) { + $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); + return; + } if ( ! $this->mTitle->userCanEdit() ) { $wgOut->sysopRequired(); return; } + if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { + $wgOut->errorpage( 'internalerror', 'sessionfailure' ); + return; + } $name = substr( $oldimage, 15 ); $dest = wfImageDir( $name ); @@ -286,13 +390,13 @@ class ImagePage extends Article { $curfile = "{$dest}/{$name}"; if ( ! is_file( $curfile ) ) { - $wgOut->fileNotFoundError( $curfile ); + $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) ); return; } $oldver = wfTimestampNow() . "!{$name}"; $dbr =& wfGetDB( DB_SLAVE ); - $size = $dbr->getField( "oldimage", "oi_size", "oi_archive_name='" . + $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' . $dbr->strencode( $oldimage ) . "'" ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { @@ -303,6 +407,10 @@ class ImagePage extends Article { $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); + + /* refresh image metadata cache */ + new Image( $name, true ); + # Squid purging if ( $wgUseSquid ) { $urlArr = Array( @@ -312,12 +420,90 @@ class ImagePage extends Article { wfPurgeSquidServers($urlArr); } - $wgOut->setPagetitle( wfMsg( "actioncomplete" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->addHTML( wfMsg( "imagereverted" ) ); + $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->addHTML( wfMsg( 'imagereverted' ) ); $wgOut->returnToMain( false ); } } +/** + * @todo document + * @package MediaWiki + */ +class ImageHistoryList { + function ImageHistoryList( &$skin ) { + $this->skin =& $skin; + } + + function beginImageHistoryList() { + $s = "\n" . wfMsg( 'imghistlegend' ) . "
\n".'