X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=6abf063e859e0e4e08d9b9ca2dfa5f82959beb6d;hb=0ee9a04366b22971725e45af9abd6b28827880dc;hp=6e8d72b6c20ef299909dee0131cbab2518183e70;hpb=ae2557057f963099ed911057364a9aa6f1c7ecf3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 6e8d72b6c2..6abf063e85 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -1,81 +1,208 @@ mTitle->getNamespace() ) { - $this->openShowImage(); - } + global $wgUseExternalEditor, $wgOut ; - Article::view(); - - # If the article we've just shown is in the "Image" namespace, - # follow it with the history list and link list for the image - # it describes. + $this->img = new Image( $this->mTitle ); - if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { + if( $this->mTitle->getNamespace() == NS_IMAGE ) { + $this->openShowImage(); + if ( $this->img->exists() ) $this->showEXIFdata(); + + # No need to display noarticletext, we use our own message, output in openShowImage() + if ( $this->getID() ) { + Article::view(); + } else { + # Just need to set the right headers + $wgOut->setArticleFlag( true ); + $wgOut->setRobotpolicy( 'index,follow' ); + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $wgOut->addMetaTags(); + $this->viewUpdates(); + } + + if ( $this->img->exists() ) { + $this->uploadNewVersionLink(); + if ( $wgUseExternalEditor && $this->img->exists() ) { + $this->externalEditorLink(); + } + } $this->closeShowImage(); $this->imageHistory(); $this->imageLinks(); + } else { + Article::view(); } } + + function showEXIFdata() { + global $wgOut, $wgShowEXIF; + if ( ! $wgShowEXIF ) return; + + # Get the EXIF data + $exif = $this->img->getExifData(); + if ( count ( $exif ) == 0 ) return; # No EXIF data available + + # Create the table + $r = "{| class=exif\n" ; + $r .= '|+ ' . wfMsg( 'exifdata' ) . "\n|-\n" ; + foreach ( $exif as $k => $v ) { + $r .= "! $k\n"; + $r .= '| ' . htmlspecialchars($v) . "\n|-\n"; + } + $wgOut->addWikiText( substr($r, 0, -3) . '|}' ); + } function openShowImage() { - global $wgOut, $wgUser,$wgRequest; - $this->img = Image::newFromTitle( $this->mTitle ); - $url = $this->img->getUrl(); + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, + $wgUseImageResize, $wgRepositoryBaseUrl, + $wgUseExternalEditor, $wgServer; + $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]; + $sk = $wgUser->getSkin(); if ( $this->img->exists() ) { - - $sk = $wgUser->getSkin(); - - if ( $this->img->getType() != "" ) { + if ( $this->img->getType() != '' ) { # image - $s = "
" . wfMsg( "nolinkstoimage" ) . "
\n" ); + if ( 0 == $dbr->numRows( $res ) ) { + $wgOut->addHtml( '' . wfMsg( "nolinkstoimage" ) . "
\n" ); return; } - $wgOut->addHTML( "" . wfMsg( "linkstoimage" ) . "
\n' . wfMsg( 'linkstoimage' ) . "
\n" . $text . "
\n" ); - $wgOut->returnToMain( false ); + $wgOut->addHTML( '' . $text . "
\n" ); + $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() ); } function doDeleteOldImage( $oldimage ) @@ -245,26 +389,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 ); @@ -272,12 +446,13 @@ class ImagePage extends Article { $curfile = "{$dest}/{$name}"; if ( ! is_file( $curfile ) ) { - $wgOut->fileNotFoundError( $curfile ); + $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) ); return; } $oldver = wfTimestampNow() . "!{$name}"; - $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" . - wfStrencode( $oldimage ) . "'" ); + + $dbr =& wfGetDB( DB_SLAVE ); + $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" ); @@ -286,21 +461,97 @@ class ImagePage extends Article { if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) { $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } - wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); - # Squid purging - if ( $wgUseSquid ) { - $urlArr = Array( - $wgInternalServer.wfImageArchiveUrl( $name ), - $wgInternalServer . Image::wfImageUrl( $name ) - ); - wfPurgeSquidServers($urlArr); + + # Record upload and update metadata cache + $img = Image::newFromName( $name ); + $img->recordUpload( $oldver, wfMsg( "reverted" ) ); + + $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->addHTML( wfMsg( 'imagereverted' ) ); + + $descTitle = $img->getTitle(); + $wgOut->returnToMain( false, $descTitle->getPrefixedText() ); + } +} + +/** + * @todo document + * @package MediaWiki + */ +class ImageHistoryList { + function ImageHistoryList( &$skin ) { + $this->skin =& $skin; + } + + function beginImageHistoryList() { + $s = "\n" . wfMsg( 'imghistlegend' ) . "
\n".'