-<?
+<?php
/*
Special handling for image description pages
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();
+ }
+
Article::view();
# If the article we've just shown is in the "Image" namespace,
# it describes.
if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
+ $this->closeShowImage();
$this->imageHistory();
$this->imageLinks();
}
}
+
+ function openShowImage()
+ {
+ global $wgOut, $wgUser,$wgRequest;
+ $this->img = Image::newFromTitle( $this->mTitle );
+ $url = $this->img->getUrl();
+
+ if ( $this->img->exists() ) {
+
+ $sk = $wgUser->getSkin();
+
+ if ( $this->img->getType() != "" ) {
+ # image
+ $s = "<div class=\"fullImage\">" .
+ "<img src=\"{$url}\" width=\"" . $this->img->getWidth() . "\" height=\"" . $this->img->getHeight() .
+ "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
+ } else {
+ $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
+ }
+ $wgOut->addHTML( $s );
+ }
+ }
+ 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 );
+ $line = $this->img->nextHistoryLine();
+
$s .= $sk->imageHistoryLine( true, $line->img_timestamp,
- $this->mTitle->getText(), $line->img_user,
+ $this->mTitle->getDBkey(), $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 );
+ 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();
$wgOut->addHTML( $s );
$wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
- $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
- wfStrencode( $this->mTitle->getDBkey() ) . "'";
+ $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" );
if ( 0 == wfNumRows( $res ) ) {
- $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "\n" );
+ $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
return;
}
- $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "\n<ul>" );
+ $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
$sk = $wgUser->getSkin();
while ( $s = wfFetchObject( $res ) ) {
- $name = $s->il_from;
- $link = $sk->makeKnownLink( $name, "" );
+ $name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
+ $link = $sk->makeKnownLinkObj( $name, "" );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
$wgOut->addHTML( "</ul>\n" );
function delete()
{
- global $wgUser, $wgOut;
- global $wpConfirm, $wpReason, $image, $oldimage;
+ global $wgUser, $wgOut, $wgRequest;
- # Anybody can delete old revisions of images; only sysops
- # can delete articles and current images
-
- if ( ( ! $oldimage ) && ( ! $wgUser->isSysop() ) ) {
+ $confirm = $wgRequest->getBool( 'wpConfirm' );
+ $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->isSysop() ) {
$wgOut->sysopRequired();
return;
}
# Better double-check that it hasn't been deleted yet!
$wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
- if ( $image ) {
+ if ( !is_null( $image ) ) {
if ( "" == trim( $image ) ) {
$wgOut->fatalError( wfMsg( "cannotdelete" ) );
return;
}
}
- # Likewise, deleting old images doesn't require confirmation
- if ( $oldimage || 1 == $wpConfirm ) {
+ # Deleting old images doesn't require confirmation
+ if ( !is_null( $oldimage ) || $confirm ) {
$this->doDelete();
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;
+ global $wgOut, $wgUser, $wgLang, $wgRequest;
+ global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
$fname = "Article::doDelete";
- if ( $image ) {
+ $reason = $wgRequest->getVal( 'wpReason' );
+ $image = $wgRequest->getVal( 'image' );
+ $oldimage = $wgRequest->getVal( 'oldimage' );
+
+ if ( !is_null( $image ) ) {
$dest = wfImageDir( $image );
$archive = wfImageDir( $image );
- if ( ! unlink( "{$dest}/{$image}" ) ) {
+ if ( ! @unlink( "{$dest}/{$image}" ) ) {
$wgOut->fileDeleteError( "{$dest}/{$image}" );
return;
}
$sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
wfStrencode( $image ) . "'";
$res = wfQuery( $sql, DB_READ, $fname );
+
+ # Squid purging
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer . Image::wfImageUrl( $image )
+ );
+ wfPurgeSquidServers($urlArr);
+ }
+
+ $urlArr = Array();
while ( $s = wfFetchObject( $res ) ) {
$this->doDeleteOldImage( $s->oi_archive_name );
+ $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
}
+
+ # Squid purging, part II
+ if ( $wgUseSquid ) {
+ /* this needs to be done after LinksUpdate */
+ $u = new SquidUpdate( $urlArr );
+ array_push( $wgDeferredUpdateList, $u );
+ }
+
$sql = "DELETE FROM oldimage WHERE oi_name='" .
wfStrencode( $image ) . "'";
wfQuery( $sql, DB_WRITE, $fname );
# Now we remove the image description page.
$nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
- $this->doDeleteArticle( $nt );
+ $article = new Article( $nt );
+ $article->doDeleteArticle( $reason ); # ignore errors
$deleted = $image;
- } else if ( $oldimage ) {
+ } 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 ) . "'";
$deleted = $oldimage;
} else {
- $this->doDeleteArticle( $this->mTitle );
+ $this->doDeleteArticle( $reason ); # ignore errors
$deleted = $this->mTitle->getPrefixedText();
}
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
Namespace::getWikipedia() ) .
":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
- $text = str_replace( "$1" , $deleted, wfMsg( "deletedtext" ) );
- $text = str_replace( "$2", $loglink, $text );
+ $text = wfMsg( "deletedtext", $deleted, $loglink );
- $wgOut->addHTML( "<p>" . $text );
+ $wgOut->addHTML( "<p>" . $text . "</p>\n" );
$wgOut->returnToMain( false );
}
function revert()
{
- global $wgOut;
- global $oldimage;
+ global $wgOut, $wgRequest;
+ global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
+ $oldimage = $wgRequest->getText( 'oldimage' );
+
if ( strlen( $oldimage ) < 16 ) {
$wgOut->unexpectedValueError( "oldimage", $oldimage );
return;
$wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
}
wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
+ # Squid purging
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfImageArchiveUrl( $name ),
+ $wgInternalServer . Image::wfImageUrl( $name )
+ );
+ wfPurgeSquidServers($urlArr);
+ }
$wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
$wgOut->setRobotpolicy( "noindex,nofollow" );