d29a431180773dfe1079f5da84f85dc605d9473d
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,
41 $wgUseImageResize, $wgRepositoryBaseUrl;
42 $this->img
= Image
::newFromTitle( $this->mTitle
);
43 $url = $this->img
->getViewURL();
46 if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) {
47 $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ];
53 if ( $this->img
->exists() ) {
55 $sk = $wgUser->getSkin();
57 if ( $this->img
->getType() != '' ) {
59 $width = $this->img
->getWidth();
60 $height = $this->img
->getHeight();
61 $msg = wfMsg('showbigimage', $width, $height, intval( $this->img
->getSize()/1024 ) );
62 if ( $width > $maxWidth && $wgUseImageResize ) {
63 $anchoropen = "<a href=\"{$url}\">";
64 $anchorclose = "<br>{$msg}</a>";
66 $url = $this->img
->createThumb( $maxWidth );
67 $height = floor( $height * $maxWidth / $width );
70 if ( $height > $maxHeight && $wgUseImageResize ) {
71 $anchoropen = "<a href=\"{$url}\">";
72 $anchorclose = "<br>{$msg}</a>";
74 $width = floor( $width * $maxHeight / $height );
76 $url = $this->img
->createThumb( $width );
78 $s = "<div class=\"fullImageLink\">" . $anchoropen .
79 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
80 htmlspecialchars( $wgRequest->getVal( 'image' ) )."\" />" . $anchorclose . "</div>";
82 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
84 $wgOut->addHTML( $s );
85 if($this->img
->fromSharedDirectory
) {
86 $sharedtext="<div class=\"sharedUploadNotice\">" . wfMsg("sharedupload");
87 if($wgRepositoryBaseUrl) {
88 $sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle
->getDBkey()));
90 $sharedtext.="</div>";
91 $wgOut->addWikiText($sharedtext);
96 function closeShowImage()
102 * If the page we've just displayed is in the "Image" namespace,
103 * we follow it with an upload history of the image and its usage.
105 function imageHistory()
107 global $wgUser, $wgOut;
109 $sk = $wgUser->getSkin();
111 $line = $this->img
->nextHistoryLine();
114 $list =& new ImageHistoryList( $sk );
115 $s = $list->beginImageHistoryList() .
116 $list->imageHistoryLine( true, $line->img_timestamp
,
117 $this->mTitle
->getDBkey(), $line->img_user
,
118 $line->img_user_text
, $line->img_size
, $line->img_description
);
120 while ( $line = $this->img
->nextHistoryLine() ) {
121 $s .= $list->imageHistoryLine( false, $line->img_timestamp
,
122 $line->oi_archive_name
, $line->img_user
,
123 $line->img_user_text
, $line->img_size
, $line->img_description
);
125 $s .= $list->endImageHistoryList();
127 $wgOut->addHTML( $s );
130 function imageLinks()
132 global $wgUser, $wgOut;
134 $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
136 $dbr =& wfGetDB( DB_SLAVE
);
137 $cur = $dbr->tableName( 'cur' );
138 $imagelinks = $dbr->tableName( 'imagelinks' );
140 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
141 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id"
142 . " LIMIT 500"; # quickie emergency brake
143 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
145 if ( 0 == $dbr->numRows( $res ) ) {
146 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
149 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
151 $sk = $wgUser->getSkin();
152 while ( $s = $dbr->fetchObject( $res ) ) {
153 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
154 $link = $sk->makeKnownLinkObj( $name, "" );
155 $wgOut->addHTML( "<li>{$link}</li>\n" );
157 $wgOut->addHTML( "</ul>\n" );
162 global $wgUser, $wgOut, $wgRequest;
164 $confirm = $wgRequest->getBool( 'wpConfirm' );
165 $image = $wgRequest->getVal( 'image' );
166 $oldimage = $wgRequest->getVal( 'oldimage' );
168 # Only sysops can delete images. Previously ordinary users could delete
169 # old revisions, but this is no longer the case.
170 if ( !$wgUser->isAllowed('delete') ) {
171 $wgOut->sysopRequired();
174 if ( wfReadOnly() ) {
175 $wgOut->readOnlyPage();
179 # Better double-check that it hasn't been deleted yet!
180 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
181 if ( !is_null( $image ) ) {
182 if ( '' == trim( $image ) ) {
183 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
188 # Deleting old images doesn't require confirmation
189 if ( !is_null( $oldimage ) ||
$confirm ) {
194 if ( !is_null( $image ) ) {
195 $q = '&image=' . urlencode( $image );
196 } else if ( !is_null( $oldimage ) ) {
197 $q = '&oldimage=' . urlencode( $oldimage );
201 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
206 global $wgOut, $wgUser, $wgContLang, $wgRequest;
207 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
208 $fname = 'ImagePage::doDelete';
210 $reason = $wgRequest->getVal( 'wpReason' );
211 $image = $wgRequest->getVal( 'image' );
212 $oldimage = $wgRequest->getVal( 'oldimage' );
214 $dbw =& wfGetDB( DB_MASTER
);
216 if ( !is_null( $oldimage ) ) {
220 $wgInternalServer.wfImageArchiveUrl( $oldimage )
222 wfPurgeSquidServers($urlArr);
224 $this->doDeleteOldImage( $oldimage );
225 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
226 $deleted = $oldimage;
228 if ( is_null ( $image ) ) {
229 $image = $this->mTitle
->getDBkey();
231 $dest = wfImageDir( $image );
232 $archive = wfImageDir( $image );
234 # Delete the image file if it exists; due to sync problems
235 # or manual trimming sometimes the file will be missing.
236 $targetFile = "{$dest}/{$image}";
237 if( file_exists( $targetFile ) && ! @unlink
( $targetFile ) ) {
238 # If the deletion operation actually failed, bug out:
239 $wgOut->fileDeleteError( $targetFile );
242 $dbw->delete( 'image', array( 'img_name' => $image ) );
243 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
248 $wgInternalServer . Image
::wfImageUrl( $image )
250 wfPurgeSquidServers($urlArr);
255 while ( $s = $dbw->fetchObject( $res ) ) {
256 $this->doDeleteOldImage( $s->oi_archive_name
);
257 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
260 # Squid purging, part II
262 /* this needs to be done after LinksUpdate */
263 $u = new SquidUpdate( $urlArr );
264 array_push( $wgDeferredUpdateList, $u );
267 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
269 # Image itself is now gone, and database is cleaned.
270 # Now we remove the image description page.
272 $nt = Title
::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image );
273 $article = new Article( $nt );
274 $article->doDeleteArticle( $reason ); # ignore errors
279 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
280 $wgOut->setRobotpolicy( 'noindex,nofollow' );
282 $sk = $wgUser->getSkin();
283 $loglink = $sk->makeKnownLink( $wgContLang->getNsText(
284 Namespace::getWikipedia() ) .
285 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
287 $text = wfMsg( 'deletedtext', $deleted, $loglink );
289 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
290 $wgOut->returnToMain( false );
293 function doDeleteOldImage( $oldimage )
297 $name = substr( $oldimage, 15 );
298 $archive = wfImageArchiveDir( $name );
300 # Delete the image if it exists. Sometimes the file will be missing
301 # due to manual intervention or weird sync problems; treat that
302 # condition gracefully and continue to delete the database entry.
303 # Also some records may end up with an empty oi_archive_name field
304 # if the original file was missing when a new upload was made;
305 # don't try to delete the directory then!
307 $targetFile = "{$archive}/{$oldimage}";
308 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink
( $targetFile ) ) {
309 # If we actually have a file and can't delete it, throw an error.
310 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
313 $log = new LogPage( 'delete' );
314 $log->addEntry( 'delete', $this->mTitle
, wfMsg('deletedrevision',$oldimage) );
320 global $wgOut, $wgRequest;
321 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
323 $oldimage = $wgRequest->getText( 'oldimage' );
324 if ( strlen( $oldimage ) < 16 ) {
325 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
328 if ( strstr( $oldimage, "/" ) ||
strstr( $oldimage, "\\" ) ) {
329 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
333 if ( wfReadOnly() ) {
334 $wgOut->readOnlyPage();
337 if ( ! $this->mTitle
->userCanEdit() ) {
338 $wgOut->sysopRequired();
341 $name = substr( $oldimage, 15 );
343 $dest = wfImageDir( $name );
344 $archive = wfImageArchiveDir( $name );
345 $curfile = "{$dest}/{$name}";
347 if ( ! is_file( $curfile ) ) {
348 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
351 $oldver = wfTimestampNow() . "!{$name}";
353 $dbr =& wfGetDB( DB_SLAVE
);
354 $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
355 $dbr->strencode( $oldimage ) . "'" );
357 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
358 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
361 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
362 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
364 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
368 $wgInternalServer.wfImageArchiveUrl( $name ),
369 $wgInternalServer . Image
::wfImageUrl( $name )
371 wfPurgeSquidServers($urlArr);
374 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
375 $wgOut->setRobotpolicy( 'noindex,nofollow' );
376 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
377 $wgOut->returnToMain( false );
381 class ImageHistoryList
{
382 function ImageHistoryList( &$skin ) {
383 $this->skin
=& $skin;
386 function beginImageHistoryList() {
387 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
388 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
392 function endImageHistoryList() {
397 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
398 global $wgUser, $wgLang, $wgContLang, $wgTitle;
400 $datetime = $wgLang->timeanddate( $timestamp, true );
401 $del = wfMsg( 'deleteimg' );
402 $delall = wfMsg( 'deleteimgcompletely' );
403 $cur = wfMsg( 'cur' );
406 $url = Image
::wfImageUrl( $img );
408 if ( $wgUser->isAllowed('delete') ) {
409 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
411 $style = $this->skin
->getInternalLinkAttributes( $link, $delall );
413 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
418 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
419 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
420 $rlink = $this->skin
->makeKnownLink( $wgTitle->getPrefixedText(),
421 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
423 $dlink = $this->skin
->makeKnownLink( $wgTitle->getPrefixedText(),
424 $del, 'action=delete&oldimage=' . urlencode( $img ) );
426 # Having live active links for non-logged in users
427 # means that bots and spiders crawling our site can
428 # inadvertently change content. Baaaad idea.
429 $rlink = wfMsg( 'revertimg' );
434 $userlink = $usertext;
436 $userlink = $this->skin
->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
437 ':'.$usertext, $usertext );
439 $nbytes = wfMsg( 'nbytes', $size );
440 $style = $this->skin
->getInternalLinkAttributes( $url, $datetime );
442 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
443 . " . . {$userlink} ({$nbytes})";
445 if ( '' != $description && '*' != $description ) {
446 $sk=$wgUser->getSkin();
447 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');