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 {
|
|
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
/* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
|
|
|
|
|
// available in doDelete etc.
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
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-05-08 18:55:22 +00:00
|
|
|
$this->img = Image::newFromTitle( $this->mTitle );
|
|
|
|
|
$url = $this->img->getUrl();
|
2004-01-12 00:55:01 +00:00
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
if ( $this->img->exists() ) {
|
2004-01-16 18:11:47 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2004-04-01 12:43:40 +00:00
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
if ( $this->img->getType() != "" ) {
|
2004-01-16 18:11:47 +00:00
|
|
|
# image
|
2004-04-24 23:45:11 +00:00
|
|
|
$s = "<div class=\"fullImage\">" .
|
2004-05-08 18:55:22 +00:00
|
|
|
"<img src=\"{$url}\" width=\"" . $this->img->getWidth() . "\" height=\"" . $this->img->getHeight() .
|
2004-04-24 23:45:11 +00:00
|
|
|
"\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
|
2004-01-16 18:11:47 +00:00
|
|
|
} else {
|
2004-05-08 18:55:22 +00:00
|
|
|
$s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</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()
|
|
|
|
|
{
|
2004-05-08 18:55:22 +00:00
|
|
|
global $wgUser, $wgOut;
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$s = $sk->beginImageHistoryList();
|
|
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
$line = $this->img->nextHistoryLine();
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
$s .= $sk->imageHistoryLine( true, $line->img_timestamp,
|
2004-05-31 23:46:04 +00:00
|
|
|
$this->mTitle->getDBkey(), $line->img_user,
|
2003-09-01 09:59:53 +00:00
|
|
|
$line->img_user_text, $line->img_size, $line->img_description );
|
|
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
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 );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
$s .= $sk->endImageHistoryList();
|
|
|
|
|
$wgOut->addHTML( $s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function imageLinks()
|
|
|
|
|
{
|
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
|
|
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-07-10 03:09:26 +00:00
|
|
|
$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";
|
2004-07-18 08:48:43 +00:00
|
|
|
$res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( 0 == $dbr->numRows( $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();
|
2004-07-10 03:09:26 +00:00
|
|
|
while ( $s = $dbr->fetchObject( $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 ) ) {
|
2004-05-28 07:45:38 +00:00
|
|
|
$q = "&image=" . urlencode( $image );
|
2004-03-29 14:48:07 +00:00
|
|
|
} else if ( !is_null( $oldimage ) ) {
|
2004-05-28 07:45:38 +00:00
|
|
|
$q = "&oldimage=" . urlencode( $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' );
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
2004-03-29 14:48:07 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->delete( 'image', array( 'img_name' => $image ) );
|
|
|
|
|
$res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
|
|
|
|
|
|
2004-02-20 12:10:00 +00:00
|
|
|
# Squid purging
|
|
|
|
|
if ( $wgUseSquid ) {
|
|
|
|
|
$urlArr = Array(
|
2004-05-04 20:35:37 +00:00
|
|
|
$wgInternalServer . Image::wfImageUrl( $image )
|
2004-02-20 12:10:00 +00:00
|
|
|
);
|
|
|
|
|
wfPurgeSquidServers($urlArr);
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-02-20 12:10:00 +00:00
|
|
|
$urlArr = Array();
|
2004-07-10 03:09:26 +00:00
|
|
|
while ( $s = $dbr->fetchObject( $res ) ) {
|
2003-09-01 09:59:53 +00:00
|
|
|
$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 );
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
|
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 );
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
|
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;
|
|
|
|
|
}
|
2004-08-05 04:30:29 +00:00
|
|
|
if ( ! $this->mTitle->userCanEdit() ) {
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
$name = substr( $oldimage, 15 );
|
|
|
|
|
|
|
|
|
|
$dest = wfImageDir( $name );
|
|
|
|
|
$archive = wfImageArchiveDir( $name );
|
|
|
|
|
$curfile = "{$dest}/{$name}";
|
|
|
|
|
|
|
|
|
|
if ( ! is_file( $curfile ) ) {
|
|
|
|
|
$wgOut->fileNotFoundError( $curfile );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$oldver = wfTimestampNow() . "!{$name}";
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-07-10 03:09:26 +00:00
|
|
|
$size = $dbr->getField( "oldimage", "oi_size", "oi_archive_name='" .
|
|
|
|
|
$dbr->strencode( $oldimage ) . "'" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
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 ),
|
2004-05-04 20:35:37 +00:00
|
|
|
$wgInternalServer . Image::wfImageUrl( $name )
|
2004-02-20 12:10:00 +00:00
|
|
|
);
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|