9 require_once( 'Image.php' );
12 * Special handling for image description pages
15 class ImagePage
extends Article
{
17 /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
18 // available in doDelete etc.
21 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
22 $this->openShowImage();
27 # If the article we've just shown is in the "Image" namespace,
28 # follow it with the history list and link list for the image
31 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
32 $this->closeShowImage();
33 $this->imageHistory();
38 function openShowImage()
40 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
41 $this->img
= Image
::newFromTitle( $this->mTitle
);
42 $url = $this->img
->getUrl();
45 if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
46 $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
52 if ( $this->img
->exists() ) {
54 $sk = $wgUser->getSkin();
56 if ( $this->img
->getType() != '' ) {
58 $width = $this->img
->getWidth();
59 $height = $this->img
->getHeight();
60 $msg = wfMsg('showbigimage', $width, $height, intval( $this->img
->getSize()/1024 ) );
61 if ( $width > $maxWidth && $wgUseImageResize ) {
62 $anchoropen = "<a href=\"{$url}\">";
63 $anchorclose = "<br>{$msg}</a>";
65 $url = $this->img
->createThumb( $maxWidth );
66 $height = floor( $height * $maxWidth / $width );
69 if ( $height > $maxHeight && $wgUseImageResize ) {
70 $anchoropen = "<a href=\"{$url}\">";
71 $anchorclose = "<br>{$msg}</a>";
73 $width = floor( $width * $maxHeight / $height );
75 $url = $this->img
->createThumb( $width );
77 $s = "<div class=\"fullImageLink\">" . $anchoropen .
78 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
79 $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
81 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
83 $wgOut->addHTML( $s );
87 function closeShowImage()
93 * If the page we've just displayed is in the "Image" namespace,
94 * we follow it with an upload history of the image and its usage.
96 function imageHistory()
98 global $wgUser, $wgOut;
100 $sk = $wgUser->getSkin();
102 $line = $this->img
->nextHistoryLine();
105 $s = $sk->beginImageHistoryList() .
106 $sk->imageHistoryLine( true, $line->img_timestamp
,
107 $this->mTitle
->getDBkey(), $line->img_user
,
108 $line->img_user_text
, $line->img_size
, $line->img_description
);
110 while ( $line = $this->img
->nextHistoryLine() ) {
111 $s .= $sk->imageHistoryLine( false, $line->img_timestamp
,
112 $line->oi_archive_name
, $line->img_user
,
113 $line->img_user_text
, $line->img_size
, $line->img_description
);
115 $s .= $sk->endImageHistoryList();
117 $wgOut->addHTML( $s );
120 function imageLinks()
122 global $wgUser, $wgOut;
124 $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
126 $dbr =& wfGetDB( DB_SLAVE
);
127 $cur = $dbr->tableName( 'cur' );
128 $imagelinks = $dbr->tableName( 'imagelinks' );
130 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
131 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id";
132 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
134 if ( 0 == $dbr->numRows( $res ) ) {
135 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
138 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
140 $sk = $wgUser->getSkin();
141 while ( $s = $dbr->fetchObject( $res ) ) {
142 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
143 $link = $sk->makeKnownLinkObj( $name, "" );
144 $wgOut->addHTML( "<li>{$link}</li>\n" );
146 $wgOut->addHTML( "</ul>\n" );
151 global $wgUser, $wgOut, $wgRequest;
153 $confirm = $wgRequest->getBool( 'wpConfirm' );
154 $image = $wgRequest->getVal( 'image' );
155 $oldimage = $wgRequest->getVal( 'oldimage' );
157 # Only sysops can delete images. Previously ordinary users could delete
158 # old revisions, but this is no longer the case.
159 if ( !$wgUser->isSysop() ) {
160 $wgOut->sysopRequired();
163 if ( wfReadOnly() ) {
164 $wgOut->readOnlyPage();
168 # Better double-check that it hasn't been deleted yet!
169 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
170 if ( !is_null( $image ) ) {
171 if ( '' == trim( $image ) ) {
172 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
177 # Deleting old images doesn't require confirmation
178 if ( !is_null( $oldimage ) ||
$confirm ) {
183 if ( !is_null( $image ) ) {
184 $q = '&image=' . urlencode( $image );
185 } else if ( !is_null( $oldimage ) ) {
186 $q = '&oldimage=' . urlencode( $oldimage );
190 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
195 global $wgOut, $wgUser, $wgContLang, $wgRequest;
196 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
197 $fname = 'ImagePage::doDelete';
199 $reason = $wgRequest->getVal( 'wpReason' );
200 $image = $wgRequest->getVal( 'image' );
201 $oldimage = $wgRequest->getVal( 'oldimage' );
203 $dbw =& wfGetDB( DB_MASTER
);
205 if ( !is_null( $oldimage ) ) {
209 $wgInternalServer.wfImageArchiveUrl( $oldimage )
211 wfPurgeSquidServers($urlArr);
213 $this->doDeleteOldImage( $oldimage );
214 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
215 $deleted = $oldimage;
217 if ( is_null ( $image ) ) {
218 $image = $this->mTitle
->getDBkey();
220 $dest = wfImageDir( $image );
221 $archive = wfImageDir( $image );
222 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
223 $wgOut->fileDeleteError( "{$dest}/{$image}" );
226 $dbw->delete( 'image', array( 'img_name' => $image ) );
227 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
232 $wgInternalServer . Image
::wfImageUrl( $image )
234 wfPurgeSquidServers($urlArr);
239 while ( $s = $dbw->fetchObject( $res ) ) {
240 $this->doDeleteOldImage( $s->oi_archive_name
);
241 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
244 # Squid purging, part II
246 /* this needs to be done after LinksUpdate */
247 $u = new SquidUpdate( $urlArr );
248 array_push( $wgDeferredUpdateList, $u );
251 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
253 # Image itself is now gone, and database is cleaned.
254 # Now we remove the image description page.
256 $nt = Title
::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image );
257 $article = new Article( $nt );
258 $article->doDeleteArticle( $reason ); # ignore errors
263 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
264 $wgOut->setRobotpolicy( 'noindex,nofollow' );
266 $sk = $wgUser->getSkin();
267 $loglink = $sk->makeKnownLink( $wgContLang->getNsText(
268 Namespace::getWikipedia() ) .
269 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
271 $text = wfMsg( 'deletedtext', $deleted, $loglink );
273 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
274 $wgOut->returnToMain( false );
277 function doDeleteOldImage( $oldimage )
281 $name = substr( $oldimage, 15 );
282 $archive = wfImageArchiveDir( $name );
283 if ( ! @unlink
( "{$archive}/{$oldimage}" ) ) {
284 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
287 $log = new LogPage( 'delete' );
288 $log->addEntry( 'delete', $this->mTitle
, wfMsg('deletedrevision',$oldimage) );
294 global $wgOut, $wgRequest;
295 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
297 $oldimage = $wgRequest->getText( 'oldimage' );
299 if ( strlen( $oldimage ) < 16 ) {
300 $wgOut->unexpectedValueError( 'oldimage', $oldimage );
303 if ( wfReadOnly() ) {
304 $wgOut->readOnlyPage();
307 if ( ! $this->mTitle
->userCanEdit() ) {
308 $wgOut->sysopRequired();
311 $name = substr( $oldimage, 15 );
313 $dest = wfImageDir( $name );
314 $archive = wfImageArchiveDir( $name );
315 $curfile = "{$dest}/{$name}";
317 if ( ! is_file( $curfile ) ) {
318 $wgOut->fileNotFoundError( $curfile );
321 $oldver = wfTimestampNow() . "!{$name}";
323 $dbr =& wfGetDB( DB_SLAVE
);
324 $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
325 $dbr->strencode( $oldimage ) . "'" );
327 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
328 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
331 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
332 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
334 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
338 $wgInternalServer.wfImageArchiveUrl( $name ),
339 $wgInternalServer . Image
::wfImageUrl( $name )
341 wfPurgeSquidServers($urlArr);
344 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
345 $wgOut->setRobotpolicy( 'noindex,nofollow' );
346 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
347 $wgOut->returnToMain( false );