2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Special handling for image description pages
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class ImagePage extends Article {
|
|
|
|
|
|
|
|
|
|
function view() {
|
2004-01-12 00:55:01 +00:00
|
|
|
if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
|
|
|
|
|
$this->openShowImage();
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
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() ) {
|
2004-01-12 00:55:01 +00:00
|
|
|
$this->closeShowImage();
|
2003-09-01 09:59:53 +00:00
|
|
|
$this->imageHistory();
|
|
|
|
|
$this->imageLinks();
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-12 00:55:01 +00:00
|
|
|
|
|
|
|
|
function openShowImage()
|
|
|
|
|
{
|
2004-04-09 14:57:05 +00:00
|
|
|
global $wgOut, $wgUser,$wgRequest;
|
2004-01-12 00:55:01 +00:00
|
|
|
$name = $this->mTitle->getText();
|
|
|
|
|
$path = wfImagePath( $name );
|
|
|
|
|
$url = wfImageUrl( $name );
|
|
|
|
|
|
2004-01-16 18:11:47 +00:00
|
|
|
if ( file_exists( $path ) ) {
|
|
|
|
|
list($width, $height, $type, $attr) = getimagesize( $path );
|
|
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2004-04-01 12:43:40 +00:00
|
|
|
|
2004-01-16 18:11:47 +00:00
|
|
|
if ( $type != "" ) {
|
|
|
|
|
# image
|
2004-04-16 10:53:55 +00:00
|
|
|
$s = "<div class=\"fullImage\"><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"".
|
|
|
|
|
"alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
|
2004-01-16 18:11:47 +00:00
|
|
|
} else {
|
2004-04-16 10:53:55 +00:00
|
|
|
$s = "<div class=\"fullMedia\">".$sk->makeMediaLink($name,"")."</div>";
|
2004-01-16 18:11:47 +00:00
|
|
|
}
|
2004-01-29 23:06:01 +00:00
|
|
|
$wgOut->addHTML( $s );
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-01-12 00:55:01 +00:00
|
|
|
function closeShowImage()
|
|
|
|
|
{
|
2004-01-29 23:06:01 +00:00
|
|
|
# For overloading
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
# 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() ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
$res = wfQuery( $sql, DB_READ, $fname );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
if ( 0 == wfNumRows( $res ) ) { return; }
|
|
|
|
|
|
|
|
|
|
$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";
|
2003-09-20 01:34:06 +00:00
|
|
|
$res = wfQuery( $sql, DB_READ, $fname );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
$wgOut->addHTML( $s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function imageLinks()
|
|
|
|
|
{
|
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
|
|
|
|
|
|
2004-03-11 09:06:13 +00:00
|
|
|
$sql = "SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
|
|
|
|
|
wfStrencode( $this->mTitle->getDBkey() ) . "' AND il_from=cur_id";
|
2003-09-20 01:34:06 +00:00
|
|
|
$res = wfQuery( $sql, DB_READ, "Article::imageLinks" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
if ( 0 == wfNumRows( $res ) ) {
|
2004-04-09 01:37:41 +00:00
|
|
|
$wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
|
2003-09-01 09:59:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-04-09 01:37:41 +00:00
|
|
|
$wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
while ( $s = wfFetchObject( $res ) ) {
|
2004-03-11 09:06:13 +00:00
|
|
|
$name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
|
|
|
|
|
$link = $sk->makeKnownLinkObj( $name, "" );
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->addHTML( "<li>{$link}</li>\n" );
|
|
|
|
|
}
|
|
|
|
|
$wgOut->addHTML( "</ul>\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete()
|
|
|
|
|
{
|
2004-03-29 14:48:07 +00:00
|
|
|
global $wgUser, $wgOut, $wgRequest;
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
$confirm = $wgRequest->getBool( 'wpConfirm' );
|
|
|
|
|
$image = $wgRequest->getVal( 'image' );
|
|
|
|
|
$oldimage = $wgRequest->getVal( 'oldimage' );
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
# Only sysops can delete images. Previously ordinary users could delete
|
|
|
|
|
# old revisions, but this is no longer the case.
|
2003-11-24 10:48:39 +00:00
|
|
|
if ( !$wgUser->isSysop() ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Better double-check that it hasn't been deleted yet!
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
|
2004-03-29 14:48:07 +00:00
|
|
|
if ( !is_null( $image ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
if ( "" == trim( $image ) ) {
|
|
|
|
|
$wgOut->fatalError( wfMsg( "cannotdelete" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-20 15:03:26 +00:00
|
|
|
# Deleting old images doesn't require confirmation
|
2004-03-29 14:48:07 +00:00
|
|
|
if ( !is_null( $oldimage ) || $confirm ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$this->doDelete();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
if ( !is_null( $image ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$q = "&image={$image}";
|
2004-03-29 14:48:07 +00:00
|
|
|
} else if ( !is_null( $oldimage ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$q = "&oldimage={$oldimage}";
|
2004-04-01 12:43:40 +00:00
|
|
|
} else {
|
|
|
|
|
$q = "";
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2004-04-01 12:43:40 +00:00
|
|
|
return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doDelete()
|
|
|
|
|
{
|
2004-03-29 14:48:07 +00:00
|
|
|
global $wgOut, $wgUser, $wgLang, $wgRequest;
|
2004-02-20 12:10:00 +00:00
|
|
|
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
|
2003-09-01 09:59:53 +00:00
|
|
|
$fname = "Article::doDelete";
|
|
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
$reason = $wgRequest->getVal( 'wpReason' );
|
|
|
|
|
$image = $wgRequest->getVal( 'image' );
|
|
|
|
|
$oldimage = $wgRequest->getVal( 'oldimage' );
|
|
|
|
|
|
|
|
|
|
if ( !is_null( $image ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$dest = wfImageDir( $image );
|
|
|
|
|
$archive = wfImageDir( $image );
|
2004-04-01 12:43:40 +00:00
|
|
|
if ( ! @unlink( "{$dest}/{$image}" ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->fileDeleteError( "{$dest}/{$image}" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$sql = "DELETE FROM image WHERE img_name='" .
|
|
|
|
|
wfStrencode( $image ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, $fname );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
|
|
|
|
|
wfStrencode( $image ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
$res = wfQuery( $sql, DB_READ, $fname );
|
2004-02-20 12:10:00 +00:00
|
|
|
|
|
|
|
|
# Squid purging
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urlArr = Array(
|
|
|
|
|
$wgInternalServer.wfImageUrl( $image )
|
|
|
|
|
);
|
|
|
|
|
wfPurgeSquidServers($urlArr);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-02-20 12:10:00 +00:00
|
|
|
$urlArr = Array();
|
2003-09-01 09:59:53 +00:00
|
|
|
while ( $s = wfFetchObject( $res ) ) {
|
|
|
|
|
$this->doDeleteOldImage( $s->oi_archive_name );
|
2004-02-20 12:10:00 +00:00
|
|
|
$urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
2004-02-20 12:10:00 +00:00
|
|
|
|
|
|
|
|
# Squid purging, part II
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
/* this needs to be done after LinksUpdate */
|
2004-03-20 15:03:26 +00:00
|
|
|
$u = new SquidUpdate( $urlArr );
|
2004-02-20 12:10:00 +00:00
|
|
|
array_push( $wgDeferredUpdateList, $u );
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
$sql = "DELETE FROM oldimage WHERE oi_name='" .
|
|
|
|
|
wfStrencode( $image ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, $fname );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
# Image itself is now gone, and database is cleaned.
|
|
|
|
|
# Now we remove the image description page.
|
|
|
|
|
|
|
|
|
|
$nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
|
2004-03-20 15:03:26 +00:00
|
|
|
$article = new Article( $nt );
|
2004-03-29 14:48:07 +00:00
|
|
|
$article->doDeleteArticle( $reason ); # ignore errors
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$deleted = $image;
|
2004-03-29 14:48:07 +00:00
|
|
|
} else if ( !is_null( $oldimage ) ) {
|
2004-02-20 12:10:00 +00:00
|
|
|
# Squid purging
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urlArr = Array(
|
|
|
|
|
$wgInternalServer.wfImageArchiveUrl( $oldimage )
|
|
|
|
|
);
|
|
|
|
|
wfPurgeSquidServers($urlArr);
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
$this->doDeleteOldImage( $oldimage );
|
|
|
|
|
$sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
|
|
|
|
|
wfStrencode( $oldimage ) . "'";
|
2003-09-20 01:34:06 +00:00
|
|
|
wfQuery( $sql, DB_WRITE, $fname );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$deleted = $oldimage;
|
|
|
|
|
} else {
|
2004-03-29 14:48:07 +00:00
|
|
|
$this->doDeleteArticle( $reason ); # ignore errors
|
2003-09-01 09:59:53 +00:00
|
|
|
$deleted = $this->mTitle->getPrefixedText();
|
|
|
|
|
}
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
|
|
|
|
|
$wgOut->setRobotpolicy( "noindex,nofollow" );
|
|
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$loglink = $sk->makeKnownLink( $wgLang->getNsText(
|
|
|
|
|
Namespace::getWikipedia() ) .
|
|
|
|
|
":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
|
|
|
|
|
|
2003-11-15 14:11:30 +00:00
|
|
|
$text = wfMsg( "deletedtext", $deleted, $loglink );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-04-09 01:37:41 +00:00
|
|
|
$wgOut->addHTML( "<p>" . $text . "</p>\n" );
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doDeleteOldImage( $oldimage )
|
|
|
|
|
{
|
|
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
|
|
$name = substr( $oldimage, 15 );
|
|
|
|
|
$archive = wfImageArchiveDir( $name );
|
|
|
|
|
if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
|
|
|
|
|
$wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function revert()
|
|
|
|
|
{
|
2004-03-29 14:48:07 +00:00
|
|
|
global $wgOut, $wgRequest;
|
2004-02-20 12:10:00 +00:00
|
|
|
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
$oldimage = $wgRequest->getText( 'oldimage' );
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
if ( strlen( $oldimage ) < 16 ) {
|
|
|
|
|
$wgOut->unexpectedValueError( "oldimage", $oldimage );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$name = substr( $oldimage, 15 );
|
|
|
|
|
|
|
|
|
|
$dest = wfImageDir( $name );
|
|
|
|
|
$archive = wfImageArchiveDir( $name );
|
|
|
|
|
$curfile = "{$dest}/{$name}";
|
|
|
|
|
|
|
|
|
|
if ( ! is_file( $curfile ) ) {
|
|
|
|
|
$wgOut->fileNotFoundError( $curfile );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$oldver = wfTimestampNow() . "!{$name}";
|
|
|
|
|
$size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
|
|
|
|
|
wfStrencode( $oldimage ) . "'" );
|
|
|
|
|
|
|
|
|
|
if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
|
|
|
|
|
$wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
|
|
|
|
|
$wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
|
|
|
|
|
}
|
|
|
|
|
wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
|
2004-02-20 12:10:00 +00:00
|
|
|
# Squid purging
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urlArr = Array(
|
|
|
|
|
$wgInternalServer.wfImageArchiveUrl( $name ),
|
|
|
|
|
$wgInternalServer.wfImageUrl( $name )
|
|
|
|
|
);
|
|
|
|
|
wfPurgeSquidServers($urlArr);
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
|
|
|
|
|
$wgOut->setRobotpolicy( "noindex,nofollow" );
|
|
|
|
|
$wgOut->addHTML( wfMsg( "imagereverted" ) );
|
|
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|