2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-12-03 10:57:19 +00:00
|
|
|
if( !defined( 'MEDIAWIKI' ) )
|
|
|
|
|
die();
|
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
require_once( 'Image.php' );
|
2004-08-13 15:55:59 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Special handling for image description pages
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-09-01 09:59:53 +00:00
|
|
|
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() {
|
2005-03-24 13:30:09 +00:00
|
|
|
global $wgUseExternalEditor;
|
2005-02-21 12:23:52 +00:00
|
|
|
if( $this->mTitle->getNamespace() == NS_IMAGE ) {
|
2004-01-12 00:55:01 +00:00
|
|
|
$this->openShowImage();
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
Article::view();
|
2005-03-24 13:30:09 +00:00
|
|
|
if($wgUseExternalEditor) {
|
|
|
|
|
$this->externalEditorLink();
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
2005-02-21 12:23:52 +00:00
|
|
|
if( $this->mTitle->getNamespace() == NS_IMAGE ) {
|
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-12-02 19:56:00 +00:00
|
|
|
global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
|
2005-03-24 13:30:09 +00:00
|
|
|
$wgUseImageResize, $wgRepositoryBaseUrl,
|
|
|
|
|
$wgUseExternalEditor;
|
2004-05-08 18:55:22 +00:00
|
|
|
$this->img = Image::newFromTitle( $this->mTitle );
|
2004-12-07 21:19:02 +00:00
|
|
|
$full_url = $this->img->getViewURL();
|
2004-08-22 17:24:50 +00:00
|
|
|
$anchoropen = '';
|
|
|
|
|
$anchorclose = '';
|
2004-12-21 03:21:41 +00:00
|
|
|
|
|
|
|
|
if( $wgUser->getOption( 'imagesize' ) == '' ) {
|
|
|
|
|
$sizeSel = User::getDefaultOption( 'imagesize' );
|
|
|
|
|
} else {
|
|
|
|
|
$sizeSel = IntVal( $wgUser->getOption( 'imagesize' ) );
|
|
|
|
|
}
|
|
|
|
|
if( !isset( $wgImageLimits[$sizeSel] ) ) {
|
|
|
|
|
$sizeSel = User::getDefaultOption( 'imagesize' );
|
2004-09-10 00:53:31 +00:00
|
|
|
}
|
2004-12-21 03:21:41 +00:00
|
|
|
$max = $wgImageLimits[$sizeSel];
|
|
|
|
|
$maxWidth = $max[0];
|
|
|
|
|
$maxHeight = $max[1];
|
2004-08-17 21:07:14 +00:00
|
|
|
|
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-08-22 17:24:50 +00:00
|
|
|
if ( $this->img->getType() != '' ) {
|
2004-01-16 18:11:47 +00:00
|
|
|
# image
|
2004-08-17 21:07:14 +00:00
|
|
|
$width = $this->img->getWidth();
|
|
|
|
|
$height = $this->img->getHeight();
|
2004-09-10 01:07:31 +00:00
|
|
|
$msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
|
2004-12-21 03:21:41 +00:00
|
|
|
if ( $width > $maxWidth ) {
|
2004-09-10 00:53:31 +00:00
|
|
|
$height = floor( $height * $maxWidth / $width );
|
|
|
|
|
$width = $maxWidth;
|
2004-09-10 01:07:31 +00:00
|
|
|
}
|
2004-12-21 03:21:41 +00:00
|
|
|
if ( $height > $maxHeight ) {
|
2004-09-10 00:53:31 +00:00
|
|
|
$width = floor( $width * $maxHeight / $height );
|
|
|
|
|
$height = $maxHeight;
|
2004-12-07 21:19:02 +00:00
|
|
|
}
|
|
|
|
|
if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
|
2004-12-21 03:21:41 +00:00
|
|
|
if( $wgUseImageResize ) {
|
2004-12-28 12:31:33 +00:00
|
|
|
$thumbnail = $this->img->getThumbnail( $width );
|
2004-12-28 22:35:12 +00:00
|
|
|
|
2004-12-28 12:31:33 +00:00
|
|
|
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();
|
|
|
|
|
}
|
2004-12-21 03:21:41 +00:00
|
|
|
} else {
|
|
|
|
|
# No resize ability? Show the full image, but scale
|
|
|
|
|
# it down in the browser so it fits on the page.
|
|
|
|
|
$url = $full_url;
|
|
|
|
|
}
|
2004-12-07 21:19:02 +00:00
|
|
|
$anchoropen = "<a href=\"{$full_url}\">";
|
2005-02-19 23:52:28 +00:00
|
|
|
$anchorclose = "</a><br />\n$anchoropen{$msg}</a>";
|
2004-12-07 21:19:02 +00:00
|
|
|
} else {
|
|
|
|
|
$url = $full_url;
|
2004-08-17 21:07:14 +00:00
|
|
|
}
|
2004-12-07 21:19:02 +00:00
|
|
|
$s = '<div class="fullImageLink">' . $anchoropen .
|
2004-08-17 21:07:14 +00:00
|
|
|
"<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
|
2004-12-07 21:19:02 +00:00
|
|
|
htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>';
|
2004-01-16 18:11:47 +00:00
|
|
|
} else {
|
2004-12-07 21:19:02 +00:00
|
|
|
$s = "<div class=\"fullMedia\">" . $sk->makeMediaLink( $this->img->getName(),'' ) . '</div>';
|
2004-01-16 18:11:47 +00:00
|
|
|
}
|
2004-10-27 14:22:15 +00:00
|
|
|
$wgOut->addHTML( $s );
|
2004-10-21 05:04:14 +00:00
|
|
|
if($this->img->fromSharedDirectory) {
|
2004-12-02 19:56:00 +00:00
|
|
|
$sharedtext="<div class=\"sharedUploadNotice\">" . wfMsg("sharedupload");
|
|
|
|
|
if($wgRepositoryBaseUrl) {
|
|
|
|
|
$sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()));
|
|
|
|
|
}
|
|
|
|
|
$sharedtext.="</div>";
|
|
|
|
|
$wgOut->addWikiText($sharedtext);
|
2004-10-21 05:04:14 +00:00
|
|
|
}
|
2005-03-24 13:30:09 +00:00
|
|
|
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2005-03-24 13:30:09 +00:00
|
|
|
function externalEditorLink()
|
|
|
|
|
{
|
|
|
|
|
global $wgUser,$wgOut;
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2005-04-01 16:40:20 +00:00
|
|
|
$wgOut->addHTML('<div class="editExternally">');
|
|
|
|
|
$wgOut->addHTML($sk->makeKnownLink($this->mTitle->getPrefixedDBkey(),wfMsg('edit-externally'),
|
2005-03-24 13:30:09 +00:00
|
|
|
"action=edit&externaledit=true&mode=file"));
|
2005-04-01 16:40:20 +00:00
|
|
|
$wgOut->addWikiText('<div class="editExternallyHelp">'.wfMsg('edit-externally-help'));
|
|
|
|
|
$wgOut->addHTML('</div><br clear="all"/>');
|
2005-03-24 13:30:09 +00:00
|
|
|
|
|
|
|
|
}
|
2004-01-12 00:55:01 +00:00
|
|
|
function closeShowImage()
|
|
|
|
|
{
|
2004-01-29 23:06:01 +00:00
|
|
|
# For overloading
|
2005-03-24 13:30:09 +00:00
|
|
|
|
2004-01-12 00:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +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.
|
|
|
|
|
*/
|
2003-09-01 09:59:53 +00:00
|
|
|
function imageHistory()
|
|
|
|
|
{
|
2004-05-08 18:55:22 +00:00
|
|
|
global $wgUser, $wgOut;
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
|
2004-05-08 18:55:22 +00:00
|
|
|
$line = $this->img->nextHistoryLine();
|
|
|
|
|
|
2004-08-22 07:38:16 +00:00
|
|
|
if ( $line ) {
|
2004-11-25 13:47:17 +00:00
|
|
|
$list =& new ImageHistoryList( $sk );
|
|
|
|
|
$s = $list->beginImageHistoryList() .
|
|
|
|
|
$list->imageHistoryLine( true, $line->img_timestamp,
|
2004-08-22 07:38:16 +00:00
|
|
|
$this->mTitle->getDBkey(), $line->img_user,
|
|
|
|
|
$line->img_user_text, $line->img_size, $line->img_description );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-08-22 07:38:16 +00:00
|
|
|
while ( $line = $this->img->nextHistoryLine() ) {
|
2004-11-25 13:47:17 +00:00
|
|
|
$s .= $list->imageHistoryLine( false, $line->img_timestamp,
|
2004-08-22 07:38:16 +00:00
|
|
|
$line->oi_archive_name, $line->img_user,
|
|
|
|
|
$line->img_user_text, $line->img_size, $line->img_description );
|
|
|
|
|
}
|
2004-11-25 13:47:17 +00:00
|
|
|
$s .= $list->endImageHistoryList();
|
2004-08-22 17:24:50 +00:00
|
|
|
} else { $s=''; }
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->addHTML( $s );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function imageLinks()
|
|
|
|
|
{
|
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
2004-12-19 08:00:50 +00:00
|
|
|
$page = $dbr->tableName( 'page' );
|
2004-07-10 03:09:26 +00:00
|
|
|
$imagelinks = $dbr->tableName( 'imagelinks' );
|
|
|
|
|
|
2004-12-19 08:00:50 +00:00
|
|
|
$sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
|
|
|
|
|
$dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id"
|
2004-12-02 03:04:56 +00:00
|
|
|
. " LIMIT 500"; # quickie emergency brake
|
2005-03-27 22:29:37 +00:00
|
|
|
$res = $dbr->query( $sql, "ImagePage::imageLinks" );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
if ( 0 == $dbr->numRows( $res ) ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
|
2003-09-01 09:59:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-08-22 17:24:50 +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-12-19 08:00:50 +00:00
|
|
|
$name = Title::MakeTitle( $s->page_namespace, $s->page_title );
|
2004-03-11 09:06:13 +00:00
|
|
|
$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
|
|
|
|
2005-03-13 15:00:59 +00:00
|
|
|
$confirm = $wgRequest->getBool( 'wpConfirmB' );
|
2004-03-29 14:48:07 +00:00
|
|
|
$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.
|
2004-10-24 19:14:48 +00:00
|
|
|
if ( !$wgUser->isAllowed('delete') ) {
|
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!
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
|
2004-12-19 08:00:50 +00:00
|
|
|
if ( ( !is_null( $image ) )
|
|
|
|
|
&& ( '' == trim( $image ) ) ) {
|
|
|
|
|
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
|
|
|
|
|
return;
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
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 ) {
|
2005-02-21 01:56:50 +00:00
|
|
|
if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
|
|
|
|
|
$this->doDelete();
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->fatalError( wfMsg( 'sessionfailure' ) );
|
|
|
|
|
}
|
2003-09-01 09:59:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
if ( !is_null( $image ) ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$q = '&image=' . urlencode( $image );
|
2004-03-29 14:48:07 +00:00
|
|
|
} else if ( !is_null( $oldimage ) ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$q = '&oldimage=' . urlencode( $oldimage );
|
2004-04-01 12:43:40 +00:00
|
|
|
} else {
|
2004-08-22 17:24:50 +00:00
|
|
|
$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-09-24 13:14:52 +00:00
|
|
|
global $wgOut, $wgUser, $wgContLang, $wgRequest;
|
2004-02-20 12:10:00 +00:00
|
|
|
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
|
2004-08-28 12:07:05 +00:00
|
|
|
$fname = 'ImagePage::doDelete';
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-03-29 14:48:07 +00:00
|
|
|
$reason = $wgRequest->getVal( 'wpReason' );
|
|
|
|
|
$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
|
|
|
|
2004-08-22 22:03:51 +00:00
|
|
|
if ( !is_null( $oldimage ) ) {
|
2005-02-21 01:56:50 +00:00
|
|
|
if ( strlen( $oldimage ) < 16 ) {
|
|
|
|
|
$wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
|
|
|
|
|
$wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-08-22 22:03:51 +00:00
|
|
|
# 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 {
|
2005-02-21 01:56:50 +00:00
|
|
|
$image = $this->mTitle->getDBkey();
|
2003-09-01 09:59:53 +00:00
|
|
|
$dest = wfImageDir( $image );
|
|
|
|
|
$archive = wfImageDir( $image );
|
2004-10-10 22:56:23 +00:00
|
|
|
|
|
|
|
|
# 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 );
|
2003-09-01 09:59:53 +00:00
|
|
|
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-08-22 22:03:51 +00:00
|
|
|
while ( $s = $dbw->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.
|
|
|
|
|
|
2005-02-21 12:23:52 +00:00
|
|
|
$nt = Title::makeTitleSafe( NS_IMAGE, $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
|
|
|
|
2005-03-13 15:00:59 +00:00
|
|
|
/* refresh image metadata cache */
|
|
|
|
|
new Image( $image, true );
|
|
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
$deleted = $image;
|
|
|
|
|
}
|
2004-08-22 22:03:51 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
|
|
|
|
$sk = $wgUser->getSkin();
|
2005-02-21 12:23:52 +00:00
|
|
|
$loglink = $sk->makeKnownLinkObj(
|
|
|
|
|
Title::makeTitle( NS_SPECIAL, 'Delete/log' ),
|
|
|
|
|
wfMsg( 'deletionlog' ) );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$text = wfMsg( 'deletedtext', $deleted, $loglink );
|
2003-09-01 09:59:53 +00:00
|
|
|
|
2004-08-22 17:24:50 +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 );
|
2004-10-10 22:56:23 +00:00
|
|
|
|
|
|
|
|
# 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.
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
|
2004-08-28 12:07:05 +00:00
|
|
|
} else {
|
|
|
|
|
# Log the deletion
|
|
|
|
|
$log = new LogPage( 'delete' );
|
|
|
|
|
$log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
|
2003-09-01 09:59:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function revert()
|
|
|
|
|
{
|
2005-02-21 01:56:50 +00:00
|
|
|
global $wgOut, $wgRequest, $wgUser;
|
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 ) {
|
2004-10-14 02:56:02 +00:00
|
|
|
$wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
|
|
|
|
|
$wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
|
2003-09-01 09:59:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-10-14 02:56:02 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
if ( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-02-21 12:46:37 +00:00
|
|
|
if( $wgUser->isAnon() ) {
|
2005-02-08 13:55:13 +00:00
|
|
|
$wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-08-05 04:30:29 +00:00
|
|
|
if ( ! $this->mTitle->userCanEdit() ) {
|
|
|
|
|
$wgOut->sysopRequired();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-02-21 01:56:50 +00:00
|
|
|
if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
|
|
|
|
|
$wgOut->errorpage( 'internalerror', 'sessionfailure' );
|
|
|
|
|
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 ) ) {
|
2004-10-14 02:56:02 +00:00
|
|
|
$wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
|
2003-09-01 09:59:53 +00:00
|
|
|
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-10-24 07:10:33 +00:00
|
|
|
$size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
|
2004-07-10 03:09:26 +00:00
|
|
|
$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" ) );
|
2005-03-13 15:00:59 +00:00
|
|
|
|
|
|
|
|
/* refresh image metadata cache */
|
|
|
|
|
new Image( $name, true );
|
|
|
|
|
|
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
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
|
|
|
|
|
$wgOut->setRobotpolicy( 'noindex,nofollow' );
|
|
|
|
|
$wgOut->addHTML( wfMsg( 'imagereverted' ) );
|
2003-09-01 09:59:53 +00:00
|
|
|
$wgOut->returnToMain( false );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document
|
|
|
|
|
* @package MediaWiki
|
|
|
|
|
*/
|
2004-11-25 13:47:17 +00:00
|
|
|
class ImageHistoryList {
|
|
|
|
|
function ImageHistoryList( &$skin ) {
|
|
|
|
|
$this->skin =& $skin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beginImageHistoryList() {
|
|
|
|
|
$s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
|
|
|
|
|
"<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function endImageHistoryList() {
|
|
|
|
|
$s = "</ul>\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 = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
|
|
|
|
|
} else {
|
|
|
|
|
$dlink = $del;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$url = htmlspecialchars( wfImageArchiveUrl( $img ) );
|
|
|
|
|
if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
|
2005-02-21 01:56:50 +00:00
|
|
|
$token = urlencode( $wgUser->editToken( $img ) );
|
2004-11-25 13:47:17 +00:00
|
|
|
$rlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
|
|
|
|
|
wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
|
2005-02-21 01:56:50 +00:00
|
|
|
urlencode( $img ) . "&wpEditToken=$token" );
|
2004-11-25 13:47:17 +00:00
|
|
|
$dlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
|
2005-02-21 01:56:50 +00:00
|
|
|
$del, 'action=delete&oldimage=' . urlencode( $img ) .
|
|
|
|
|
"&wpEditToken=$token" );
|
2004-11-25 13:47:17 +00:00
|
|
|
} 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 {
|
2005-02-21 12:23:52 +00:00
|
|
|
$userlink = $this->skin->makeLinkObj(
|
|
|
|
|
Title::makeTitle( NS_USER, $usertext ),
|
|
|
|
|
$usertext );
|
2004-11-25 13:47:17 +00:00
|
|
|
}
|
|
|
|
|
$nbytes = wfMsg( 'nbytes', $size );
|
|
|
|
|
$style = $this->skin->getInternalLinkAttributes( $url, $datetime );
|
|
|
|
|
|
|
|
|
|
$s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
|
|
|
|
|
. " . . {$userlink} ({$nbytes})";
|
|
|
|
|
|
2005-02-21 12:23:52 +00:00
|
|
|
$s .= $this->skin->commentBlock( $description, $wgTitle );
|
2004-11-25 13:47:17 +00:00
|
|
|
$s .= "</li>\n";
|
|
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 15:55:59 +00:00
|
|
|
|
2003-09-01 09:59:53 +00:00
|
|
|
?>
|