<?php
-
-/*
- Special handling for image description pages
-*/
-
+/**
+ * @package MediaWiki
+ */
+
+/**
+ *
+ */
+require_once( 'Image.php' );
+
+/**
+ * Special handling for image description pages
+ * @package MediaWiki
+ */
class ImagePage extends Article {
+ /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
+ // available in doDelete etc.
+
function view() {
if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
$this->openShowImage();
function openShowImage()
{
- global $wgOut, $wgUser,$wgRequest;
- $name = $this->mTitle->getText();
- $path = wfImagePath( $name );
- $url = wfImageUrl( $name );
+ global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
+ $this->img = Image::newFromTitle( $this->mTitle );
+ $url = $this->img->getUrl();
+ $anchoropen = '';
+ $anchorclose = '';
+ if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
+ $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
+ $maxWidth = $max[0];
+ $maxHeight = $max[1];
+ }
+
- if ( file_exists( $path ) ) {
- list($width, $height, $type, $attr) = getimagesize( $path );
+ if ( $this->img->exists() ) {
$sk = $wgUser->getSkin();
- if ( $type != "" ) {
+ if ( $this->img->getType() != '' ) {
# image
- $s = "<div class=\"fullImage\"><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"".
- "alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
+ $width = $this->img->getWidth();
+ $height = $this->img->getHeight();
+ $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
+ if ( $width > $maxWidth && $wgUseImageResize ) {
+ $anchoropen = "<a href=\"{$url}\">";
+ $anchorclose = "<br>{$msg}</a>";
+
+ $url = $this->img->createThumb( $maxWidth );
+ $height = floor( $height * $maxWidth / $width );
+ $width = $maxWidth;
+ }
+ if ( $height > $maxHeight && $wgUseImageResize ) {
+ $anchoropen = "<a href=\"{$url}\">";
+ $anchorclose = "<br>{$msg}</a>";
+
+ $width = floor( $width * $maxHeight / $height );
+ $height = $maxHeight;
+ $url = $this->img->createThumb( $width );
+ }
+ $s = "<div class=\"fullImageLink\">" . $anchoropen .
+ "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
+ $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
} else {
- $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($name,"")."</div>";
+ $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
}
$wgOut->addHTML( $s );
}
# 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.
-
+ /**
+ * 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";
+ global $wgUser, $wgOut;
- $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 );
+ $sk = $wgUser->getSkin();
- if ( 0 == wfNumRows( $res ) ) { return; }
+ $line = $this->img->nextHistoryLine();
- $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 );
-
- $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 );
-
- 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();
+ if ( $line ) {
+ $s = $sk->beginImageHistoryList() .
+ $sk->imageHistoryLine( true, $line->img_timestamp,
+ $this->mTitle->getDBkey(), $line->img_user,
+ $line->img_user_text, $line->img_size, $line->img_description );
+
+ while ( $line = $this->img->nextHistoryLine() ) {
+ $s .= $sk->imageHistoryLine( false, $line->img_timestamp,
+ $line->oi_archive_name, $line->img_user,
+ $line->img_user_text, $line->img_size, $line->img_description );
+ }
+ $s .= $sk->endImageHistoryList();
+ } else { $s=''; }
$wgOut->addHTML( $s );
}
{
global $wgUser, $wgOut;
- $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
+ $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
- $sql = "SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
- wfStrencode( $this->mTitle->getDBkey() ) . "' AND il_from=cur_id";
- $res = wfQuery( $sql, DB_READ, "Article::imageLinks" );
+ $dbr =& wfGetDB( DB_SLAVE );
+ $cur = $dbr->tableName( 'cur' );
+ $imagelinks = $dbr->tableName( 'imagelinks' );
+
+ $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
+ $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id";
+ $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
- if ( 0 == wfNumRows( $res ) ) {
- $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
+ if ( 0 == $dbr->numRows( $res ) ) {
+ $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
return;
}
- $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
+ $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
$sk = $wgUser->getSkin();
- while ( $s = wfFetchObject( $res ) ) {
+ while ( $s = $dbr->fetchObject( $res ) ) {
$name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
$link = $sk->makeKnownLinkObj( $name, "" );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
# Better double-check that it hasn't been deleted yet!
- $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
+ $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
if ( !is_null( $image ) ) {
- if ( "" == trim( $image ) ) {
- $wgOut->fatalError( wfMsg( "cannotdelete" ) );
+ if ( '' == trim( $image ) ) {
+ $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
return;
}
}
}
if ( !is_null( $image ) ) {
- $q = "&image={$image}";
+ $q = '&image=' . urlencode( $image );
} else if ( !is_null( $oldimage ) ) {
- $q = "&oldimage={$oldimage}";
+ $q = '&oldimage=' . urlencode( $oldimage );
} else {
- $q = "";
+ $q = '';
}
return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
}
{
global $wgOut, $wgUser, $wgLang, $wgRequest;
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
- $fname = "Article::doDelete";
+ $fname = 'ImagePage::doDelete';
$reason = $wgRequest->getVal( 'wpReason' );
$image = $wgRequest->getVal( 'image' );
$oldimage = $wgRequest->getVal( 'oldimage' );
+
+ $dbw =& wfGetDB( DB_MASTER );
- if ( !is_null( $image ) ) {
+ if ( !is_null( $oldimage ) ) {
+ # 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 {
+ if ( is_null ( $image ) ) {
+ $image = $this->mTitle->getDBkey();
+ }
$dest = wfImageDir( $image );
$archive = wfImageDir( $image );
if ( ! @unlink( "{$dest}/{$image}" ) ) {
$wgOut->fileDeleteError( "{$dest}/{$image}" );
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.wfImageUrl( $image )
+ $wgInternalServer . Image::wfImageUrl( $image )
);
wfPurgeSquidServers($urlArr);
}
$urlArr = Array();
- while ( $s = wfFetchObject( $res ) ) {
+ while ( $s = $dbw->fetchObject( $res ) ) {
$this->doDeleteOldImage( $s->oi_archive_name );
$urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
}
array_push( $wgDeferredUpdateList, $u );
}
- $sql = "DELETE FROM oldimage WHERE oi_name='" .
- wfStrencode( $image ) . "'";
- wfQuery( $sql, DB_WRITE, $fname );
+ $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
# Image itself is now gone, and database is cleaned.
# Now we remove the image description page.
$article->doDeleteArticle( $reason ); # ignore errors
$deleted = $image;
- } else if ( !is_null( $oldimage ) ) {
- # Squid purging
- if ( $wgUseSquid ) {
- $urlArr = Array(
- $wgInternalServer.wfImageArchiveUrl( $oldimage )
- );
- wfPurgeSquidServers($urlArr);
- }
- $this->doDeleteOldImage( $oldimage );
- $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
- wfStrencode( $oldimage ) . "'";
- wfQuery( $sql, DB_WRITE, $fname );
-
- $deleted = $oldimage;
- } else {
- $this->doDeleteArticle( $reason ); # ignore errors
- $deleted = $this->mTitle->getPrefixedText();
}
- $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" ) );
+ ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
- $text = wfMsg( "deletedtext", $deleted, $loglink );
+ $text = wfMsg( 'deletedtext', $deleted, $loglink );
- $wgOut->addHTML( "<p>" . $text . "</p>\n" );
+ $wgOut->addHTML( '<p>' . $text . "</p>\n" );
$wgOut->returnToMain( false );
}
$name = substr( $oldimage, 15 );
$archive = wfImageArchiveDir( $name );
- if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
+ if ( ! @unlink( "{$archive}/{$oldimage}" ) ) {
$wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
+ } else {
+ # Log the deletion
+ $log = new LogPage( 'delete' );
+ $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
}
}
$oldimage = $wgRequest->getText( 'oldimage' );
if ( strlen( $oldimage ) < 16 ) {
- $wgOut->unexpectedValueError( "oldimage", $oldimage );
+ $wgOut->unexpectedValueError( 'oldimage', $oldimage );
return;
}
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
+ if ( ! $this->mTitle->userCanEdit() ) {
+ $wgOut->sysopRequired();
+ return;
+ }
$name = substr( $oldimage, 15 );
$dest = wfImageDir( $name );
return;
}
$oldver = wfTimestampNow() . "!{$name}";
- $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
- wfStrencode( $oldimage ) . "'" );
+
+ $dbr =& wfGetDB( DB_SLAVE );
+ $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
+ $dbr->strencode( $oldimage ) . "'" );
if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
$wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
if ( $wgUseSquid ) {
$urlArr = Array(
$wgInternalServer.wfImageArchiveUrl( $name ),
- $wgInternalServer.wfImageUrl( $name )
+ $wgInternalServer . Image::wfImageUrl( $name )
);
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 );
}
}
+
?>