X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=d0285e8960aea5a8c3ff1e47eb70d412f0e4310b;hb=8da29ee8fccfd8d36ec11f597670a7dcd743449c;hp=bc993a820773b638633f5a46712d975d158f3f81;hpb=def0193f313521c499378e1e7ae294161e31f6f0;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/ImagePage.php b/includes/ImagePage.php
index bc993a8207..d0285e8960 100644
--- a/includes/ImagePage.php
+++ b/includes/ImagePage.php
@@ -1,59 +1,155 @@
-
-
-/*
- Special handling for image description pages
-*/
-
+mTitle->getNamespace() == NS_IMAGE ) {
+ $this->openShowImage();
+ }
+
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.
- if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
+ if( $this->mTitle->getNamespace() == NS_IMAGE ) {
+ $this->closeShowImage();
$this->imageHistory();
$this->imageLinks();
}
}
+
+ function openShowImage()
+ {
+ global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
+ $wgUseImageResize, $wgRepositoryBaseUrl;
+ $this->img = Image::newFromTitle( $this->mTitle );
+ $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() != '' ) {
+ # image
+ $width = $this->img->getWidth();
+ $height = $this->img->getHeight();
+ $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 = '
' . $anchoropen .
+ "
getVal( 'image' ) ).'" />' . $anchorclose . '
';
+ } else {
+ $s = "" . $sk->makeMediaLink( $this->img->getName(),'' ) . '
';
+ }
+ $wgOut->addHTML( $s );
+ if($this->img->fromSharedDirectory) {
+ $sharedtext="" . wfMsg("sharedupload");
+ if($wgRepositoryBaseUrl) {
+ $sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()));
+ }
+ $sharedtext.="
";
+ $wgOut->addWikiText($sharedtext);
+ }
+ }
+ }
- # If the page we've just displayed is in the "Image" namespace,
- # we follow it with an upload history of the image and its usage.
+ function closeShowImage()
+ {
+ # For overloading
+ }
+ /**
+ * If the page we've just displayed is in the "Image" namespace,
+ * we follow it with an upload history of the image and its usage.
+ */
function imageHistory()
{
- global $wgUser, $wgOut, $wgLang;
- $fname = "Article::imageHistory";
-
- $sql = "SELECT img_size,img_description,img_user," .
- "img_user_text,img_timestamp FROM image WHERE " .
- "img_name='" . wfStrencode( $this->mTitle->getDBkey() ) . "'";
- $res = wfQuery( $sql, DB_READ, $fname );
-
- if ( 0 == wfNumRows( $res ) ) { return; }
+ global $wgUser, $wgOut;
$sk = $wgUser->getSkin();
- $s = $sk->beginImageHistoryList();
- $line = wfFetchObject( $res );
- $s .= $sk->imageHistoryLine( true, $line->img_timestamp,
- $this->mTitle->getText(), $line->img_user,
- $line->img_user_text, $line->img_size, $line->img_description );
+ $line = $this->img->nextHistoryLine();
- $sql = "SELECT oi_size,oi_description,oi_user," .
- "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " .
- "oi_name='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " .
- "ORDER BY oi_timestamp DESC";
- $res = wfQuery( $sql, DB_READ, $fname );
+ if ( $line ) {
+ $list =& new ImageHistoryList( $sk );
+ $s = $list->beginImageHistoryList() .
+ $list->imageHistoryLine( true, $line->img_timestamp,
+ $this->mTitle->getDBkey(), $line->img_user,
+ $line->img_user_text, $line->img_size, $line->img_description );
- while ( $line = wfFetchObject( $res ) ) {
- $s .= $sk->imageHistoryLine( false, $line->oi_timestamp,
- $line->oi_archive_name, $line->oi_user,
- $line->oi_user_text, $line->oi_size, $line->oi_description );
- }
- $s .= $sk->endImageHistoryList();
+ while ( $line = $this->img->nextHistoryLine() ) {
+ $s .= $list->imageHistoryLine( false, $line->img_timestamp,
+ $line->oi_archive_name, $line->img_user,
+ $line->img_user_text, $line->img_size, $line->img_description );
+ }
+ $s .= $list->endImageHistoryList();
+ } else { $s=''; }
$wgOut->addHTML( $s );
}
@@ -61,22 +157,27 @@ class ImagePage extends Article {
{
global $wgUser, $wgOut;
- $wgOut->addHTML( "" . wfMsg( "imagelinks" ) . "
\n" );
+ $wgOut->addHTML( '' . wfMsg( 'imagelinks' ) . "
\n" );
- $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
- wfStrencode( $this->mTitle->getDBkey() ) . "'";
- $res = wfQuery( $sql, DB_READ, "Article::imageLinks" );
+ $dbr =& wfGetDB( DB_SLAVE );
+ $page = $dbr->tableName( 'page' );
+ $imagelinks = $dbr->tableName( 'imagelinks' );
+
+ $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
+ $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id"
+ . " LIMIT 500"; # quickie emergency brake
+ $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
- if ( 0 == wfNumRows( $res ) ) {
- $wgOut->addHtml( "" . wfMsg( "nolinkstoimage" ) . "\n" );
+ if ( 0 == $dbr->numRows( $res ) ) {
+ $wgOut->addHtml( '
' . wfMsg( "nolinkstoimage" ) . "
\n" );
return;
}
- $wgOut->addHTML( "" . wfMsg( "linkstoimage" ) . "\n
" );
+ $wgOut->addHTML( '' . wfMsg( 'linkstoimage' ) . "
\n" );
$sk = $wgUser->getSkin();
- while ( $s = wfFetchObject( $res ) ) {
- $name = $s->il_from;
- $link = $sk->makeKnownLink( $name, "" );
+ while ( $s = $dbr->fetchObject( $res ) ) {
+ $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
+ $link = $sk->makeKnownLinkObj( $name, "" );
$wgOut->addHTML( "- {$link}
\n" );
}
$wgOut->addHTML( "
\n" );
@@ -84,13 +185,15 @@ class ImagePage extends Article {
function delete()
{
- global $wgUser, $wgOut;
- global $wpConfirm, $wpReason, $image, $oldimage;
-
- # Anybody can delete old revisions of images; only sysops
- # can delete articles and current images
+ global $wgUser, $wgOut, $wgRequest;
- if ( ( ! $oldimage ) && ( ! $wgUser->isSysop() ) ) {
+ $confirm = $wgRequest->getBool( 'wpConfirmB' );
+ $image = $wgRequest->getVal( 'image' );
+ $oldimage = $wgRequest->getVal( 'oldimage' );
+
+ # Only sysops can delete images. Previously ordinary users could delete
+ # old revisions, but this is no longer the case.
+ if ( !$wgUser->isAllowed('delete') ) {
$wgOut->sysopRequired();
return;
}
@@ -100,85 +203,127 @@ class ImagePage extends Article {
}
# Better double-check that it hasn't been deleted yet!
- $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
- if ( $image ) {
- if ( "" == trim( $image ) ) {
- $wgOut->fatalError( wfMsg( "cannotdelete" ) );
- return;
- }
+ $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
+ if ( ( !is_null( $image ) )
+ && ( '' == trim( $image ) ) ) {
+ $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+ return;
}
- # Likewise, deleting old images doesn't require confirmation
- if ( $oldimage || 1 == $wpConfirm ) {
- $this->doDelete();
+ # Deleting old images doesn't require confirmation
+ if ( !is_null( $oldimage ) || $confirm ) {
+ if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
+ $this->doDelete();
+ } else {
+ $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
+ }
return;
}
- if ( $image ) {
- $q = "&image={$image}";
- } else if ( $oldimage ) {
- $q = "&oldimage={$oldimage}";
+ if ( !is_null( $image ) ) {
+ $q = '&image=' . urlencode( $image );
+ } else if ( !is_null( $oldimage ) ) {
+ $q = '&oldimage=' . urlencode( $oldimage );
+ } else {
+ $q = '';
}
- return $this->confirmDelete( $q );
+ return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
}
function doDelete()
{
- global $wgOut, $wgUser, $wgLang;
- global $image, $oldimage, $wpReason;
- $fname = "Article::doDelete";
+ global $wgOut, $wgUser, $wgContLang, $wgRequest;
+ global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
+ $fname = 'ImagePage::doDelete';
+
+ $reason = $wgRequest->getVal( 'wpReason' );
+ $oldimage = $wgRequest->getVal( 'oldimage' );
+
+ $dbw =& wfGetDB( DB_MASTER );
- if ( $image ) {
+ if ( !is_null( $oldimage ) ) {
+ if ( strlen( $oldimage ) < 16 ) {
+ $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+ return;
+ }
+ if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
+ $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+ return;
+ }
+ # Squid purging
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfImageArchiveUrl( $oldimage )
+ );
+ wfPurgeSquidServers($urlArr);
+ }
+ $this->doDeleteOldImage( $oldimage );
+ $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
+ $deleted = $oldimage;
+ } else {
+ $image = $this->mTitle->getDBkey();
$dest = wfImageDir( $image );
$archive = wfImageDir( $image );
- if ( ! unlink( "{$dest}/{$image}" ) ) {
- $wgOut->fileDeleteError( "{$dest}/{$image}" );
+
+ # Delete the image file if it exists; due to sync problems
+ # or manual trimming sometimes the file will be missing.
+ $targetFile = "{$dest}/{$image}";
+ if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
+ # If the deletion operation actually failed, bug out:
+ $wgOut->fileDeleteError( $targetFile );
return;
}
- $sql = "DELETE FROM image WHERE img_name='" .
- wfStrencode( $image ) . "'";
- wfQuery( $sql, DB_WRITE, $fname );
-
- $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
- wfStrencode( $image ) . "'";
- $res = wfQuery( $sql, DB_READ, $fname );
+ $dbw->delete( 'image', array( 'img_name' => $image ) );
+ $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
+
+ # Squid purging
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer . Image::wfImageUrl( $image )
+ );
+ wfPurgeSquidServers($urlArr);
+ }
+
- while ( $s = wfFetchObject( $res ) ) {
+ $urlArr = Array();
+ while ( $s = $dbw->fetchObject( $res ) ) {
$this->doDeleteOldImage( $s->oi_archive_name );
+ $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
}
- $sql = "DELETE FROM oldimage WHERE oi_name='" .
- wfStrencode( $image ) . "'";
- wfQuery( $sql, DB_WRITE, $fname );
+
+ # Squid purging, part II
+ if ( $wgUseSquid ) {
+ /* this needs to be done after LinksUpdate */
+ $u = new SquidUpdate( $urlArr );
+ array_push( $wgDeferredUpdateList, $u );
+ }
+
+ $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
# Image itself is now gone, and database is cleaned.
# Now we remove the image description page.
- $nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
- $this->doDeleteArticle( $nt );
+ $nt = Title::makeTitleSafe( NS_IMAGE, $image );
+ $article = new Article( $nt );
+ $article->doDeleteArticle( $reason ); # ignore errors
- $deleted = $image;
- } else if ( $oldimage ) {
- $this->doDeleteOldImage( $oldimage );
- $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
- wfStrencode( $oldimage ) . "'";
- wfQuery( $sql, DB_WRITE, $fname );
+ /* refresh image metadata cache */
+ new Image( $image, true );
- $deleted = $oldimage;
- } else {
- $this->doDeleteArticle( $this->mTitle );
- $deleted = $this->mTitle->getPrefixedText();
+ $deleted = $image;
}
- $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
- $wgOut->setRobotpolicy( "noindex,nofollow" );
+
+ $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
$sk = $wgUser->getSkin();
- $loglink = $sk->makeKnownLink( $wgLang->getNsText(
- Namespace::getWikipedia() ) .
- ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
+ $loglink = $sk->makeKnownLinkObj(
+ Title::makeTitle( NS_SPECIAL, 'Delete/log' ),
+ wfMsg( 'deletionlog' ) );
- $text = wfMsg( "deletedtext", $deleted, $loglink );
+ $text = wfMsg( 'deletedtext', $deleted, $loglink );
- $wgOut->addHTML( "" . $text );
+ $wgOut->addHTML( '
' . $text . "
\n" );
$wgOut->returnToMain( false );
}
@@ -188,24 +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;
- global $oldimage;
+ 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 );
@@ -213,12 +390,14 @@ 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', 'oi_archive_name=\'' .
+ $dbr->strencode( $oldimage ) . "'" );
if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
$wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
@@ -229,11 +408,102 @@ class ImagePage extends Article {
}
wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
- $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
- $wgOut->setRobotpolicy( "noindex,nofollow" );
- $wgOut->addHTML( wfMsg( "imagereverted" ) );
+ /* refresh image metadata cache */
+ new Image( $name, true );
+
+ # Squid purging
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfImageArchiveUrl( $name ),
+ $wgInternalServer . Image::wfImageUrl( $name )
+ );
+ wfPurgeSquidServers($urlArr);
+ }
+
+ $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( 'imghistory' ) . "
\n" .
+ "" . wfMsg( 'imghistlegend' ) . "
\n".'';
+ return $s;
+ }
+
+ function endImageHistoryList() {
+ $s = "
\n";
+ return $s;
+ }
+
+ function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
+ global $wgUser, $wgLang, $wgContLang, $wgTitle;
+
+ $datetime = $wgLang->timeanddate( $timestamp, true );
+ $del = wfMsg( 'deleteimg' );
+ $delall = wfMsg( 'deleteimgcompletely' );
+ $cur = wfMsg( 'cur' );
+
+ if ( $iscur ) {
+ $url = Image::wfImageUrl( $img );
+ $rlink = $cur;
+ if ( $wgUser->isAllowed('delete') ) {
+ $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
+ '&action=delete' );
+ $style = $this->skin->getInternalLinkAttributes( $link, $delall );
+
+ $dlink = ''.$delall.'';
+ } else {
+ $dlink = $del;
+ }
+ } else {
+ $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
+ if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
+ $token = urlencode( $wgUser->editToken( $img ) );
+ $rlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+ wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
+ urlencode( $img ) . "&wpEditToken=$token" );
+ $dlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+ $del, 'action=delete&oldimage=' . urlencode( $img ) .
+ "&wpEditToken=$token" );
+ } else {
+ # Having live active links for non-logged in users
+ # means that bots and spiders crawling our site can
+ # inadvertently change content. Baaaad idea.
+ $rlink = wfMsg( 'revertimg' );
+ $dlink = $del;
+ }
+ }
+ if ( 0 == $user ) {
+ $userlink = $usertext;
+ } else {
+ $userlink = $this->skin->makeLinkObj(
+ Title::makeTitle( NS_USER, $usertext ),
+ $usertext );
+ }
+ $nbytes = wfMsg( 'nbytes', $size );
+ $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
+
+ $s = "- ({$dlink}) ({$rlink}) {$datetime}"
+ . " . . {$userlink} ({$nbytes})";
+
+ $s .= $this->skin->commentBlock( $description, $wgTitle );
+ $s .= "
\n";
+ return $s;
+ }
+
+}
+
+
?>