e99e046aa3321c7df0db3bd5dfc0ad7a5c8b529b
9 if( !defined( 'MEDIAWIKI' ) )
12 require_once( 'Image.php' );
15 * Special handling for image description pages
18 class ImagePage
extends Article
{
20 /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
21 // available in doDelete etc.
24 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
25 $this->openShowImage();
30 # If the article we've just shown is in the "Image" namespace,
31 # follow it with the history list and link list for the image
34 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
35 $this->closeShowImage();
36 $this->imageHistory();
41 function openShowImage()
43 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
44 $wgUseImageResize, $wgRepositoryBaseUrl;
45 $this->img
= Image
::newFromTitle( $this->mTitle
);
46 $full_url = $this->img
->getViewURL();
49 if ( $wgUseImageResize ) {
50 if( $wgUser->getOption( 'imagesize' ) == '' ) {
51 $sizeSel = User
::getDefaultOption( 'imagesize' );
53 $sizeSel = IntVal( $wgUser->getOption( 'imagesize' ) );
55 if( !isset( $wgImageLimits[$sizeSel] ) ) {
56 $sizeSel = User
::getDefaultOption( 'imagesize' );
58 $max = $wgImageLimits[$sizeSel];
64 if ( $this->img
->exists() ) {
66 $sk = $wgUser->getSkin();
68 if ( $this->img
->getType() != '' ) {
70 $width = $this->img
->getWidth();
71 $height = $this->img
->getHeight();
72 $msg = wfMsg('showbigimage', $width, $height, intval( $this->img
->getSize()/1024 ) );
73 if ( $width > $maxWidth && $wgUseImageResize ) {
74 $height = floor( $height * $maxWidth / $width );
77 if ( $height > $maxHeight && $wgUseImageResize ) {
78 $width = floor( $width * $maxHeight / $height );
81 if ( $width != $this->img
->getWidth() ||
$height != $this->img
->getHeight() ) {
82 $url = $this->img
->createThumb( $width );
83 $anchoropen = "<a href=\"{$full_url}\">";
84 $anchorclose = "<br>{$msg}</a>";
88 $s = '<div class="fullImageLink">' . $anchoropen .
89 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
90 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>';
92 $s = "<div class=\"fullMedia\">" . $sk->makeMediaLink( $this->img
->getName(),'' ) . '</div>';
94 $wgOut->addHTML( $s );
95 if($this->img
->fromSharedDirectory
) {
96 $sharedtext="<div class=\"sharedUploadNotice\">" . wfMsg("sharedupload");
97 if($wgRepositoryBaseUrl) {
98 $sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle
->getDBkey()));
100 $sharedtext.="</div>";
101 $wgOut->addWikiText($sharedtext);
106 function closeShowImage()
112 * If the page we've just displayed is in the "Image" namespace,
113 * we follow it with an upload history of the image and its usage.
115 function imageHistory()
117 global $wgUser, $wgOut;
119 $sk = $wgUser->getSkin();
121 $line = $this->img
->nextHistoryLine();
124 $list =& new ImageHistoryList( $sk );
125 $s = $list->beginImageHistoryList() .
126 $list->imageHistoryLine( true, $line->img_timestamp
,
127 $this->mTitle
->getDBkey(), $line->img_user
,
128 $line->img_user_text
, $line->img_size
, $line->img_description
);
130 while ( $line = $this->img
->nextHistoryLine() ) {
131 $s .= $list->imageHistoryLine( false, $line->img_timestamp
,
132 $line->oi_archive_name
, $line->img_user
,
133 $line->img_user_text
, $line->img_size
, $line->img_description
);
135 $s .= $list->endImageHistoryList();
137 $wgOut->addHTML( $s );
140 function imageLinks()
142 global $wgUser, $wgOut;
144 $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
146 $dbr =& wfGetDB( DB_SLAVE
);
147 $page = $dbr->tableName( 'page' );
148 $imagelinks = $dbr->tableName( 'imagelinks' );
150 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
151 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=page_id"
152 . " LIMIT 500"; # quickie emergency brake
153 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
155 if ( 0 == $dbr->numRows( $res ) ) {
156 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
159 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
161 $sk = $wgUser->getSkin();
162 while ( $s = $dbr->fetchObject( $res ) ) {
163 $name = Title
::MakeTitle( $s->page_namespace
, $s->page_title
);
164 $link = $sk->makeKnownLinkObj( $name, "" );
165 $wgOut->addHTML( "<li>{$link}</li>\n" );
167 $wgOut->addHTML( "</ul>\n" );
172 global $wgUser, $wgOut, $wgRequest;
174 $confirm = $wgRequest->getBool( 'wpConfirm' );
175 $image = $wgRequest->getVal( 'image' );
176 $oldimage = $wgRequest->getVal( 'oldimage' );
178 # Only sysops can delete images. Previously ordinary users could delete
179 # old revisions, but this is no longer the case.
180 if ( !$wgUser->isAllowed('delete') ) {
181 $wgOut->sysopRequired();
184 if ( wfReadOnly() ) {
185 $wgOut->readOnlyPage();
189 # Better double-check that it hasn't been deleted yet!
190 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
191 if ( ( !is_null( $image ) )
192 && ( '' == trim( $image ) ) ) {
193 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
197 # Deleting old images doesn't require confirmation
198 if ( !is_null( $oldimage ) ||
$confirm ) {
203 if ( !is_null( $image ) ) {
204 $q = '&image=' . urlencode( $image );
205 } else if ( !is_null( $oldimage ) ) {
206 $q = '&oldimage=' . urlencode( $oldimage );
210 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
215 global $wgOut, $wgUser, $wgContLang, $wgRequest;
216 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
217 $fname = 'ImagePage::doDelete';
219 $reason = $wgRequest->getVal( 'wpReason' );
220 $image = $wgRequest->getVal( 'image' );
221 $oldimage = $wgRequest->getVal( 'oldimage' );
223 $dbw =& wfGetDB( DB_MASTER
);
225 if ( !is_null( $oldimage ) ) {
229 $wgInternalServer.wfImageArchiveUrl( $oldimage )
231 wfPurgeSquidServers($urlArr);
233 $this->doDeleteOldImage( $oldimage );
234 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
235 $deleted = $oldimage;
237 if ( is_null ( $image ) ) {
238 $image = $this->mTitle
->getDBkey();
240 $dest = wfImageDir( $image );
241 $archive = wfImageDir( $image );
243 # Delete the image file if it exists; due to sync problems
244 # or manual trimming sometimes the file will be missing.
245 $targetFile = "{$dest}/{$image}";
246 if( file_exists( $targetFile ) && ! @unlink
( $targetFile ) ) {
247 # If the deletion operation actually failed, bug out:
248 $wgOut->fileDeleteError( $targetFile );
251 $dbw->delete( 'image', array( 'img_name' => $image ) );
252 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
257 $wgInternalServer . Image
::wfImageUrl( $image )
259 wfPurgeSquidServers($urlArr);
264 while ( $s = $dbw->fetchObject( $res ) ) {
265 $this->doDeleteOldImage( $s->oi_archive_name
);
266 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
269 # Squid purging, part II
271 /* this needs to be done after LinksUpdate */
272 $u = new SquidUpdate( $urlArr );
273 array_push( $wgDeferredUpdateList, $u );
276 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
278 # Image itself is now gone, and database is cleaned.
279 # Now we remove the image description page.
281 $nt = Title
::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image );
282 $article = new Article( $nt );
283 $article->doDeleteArticle( $reason ); # ignore errors
288 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
289 $wgOut->setRobotpolicy( 'noindex,nofollow' );
291 $sk = $wgUser->getSkin();
292 $loglink = $sk->makeKnownLink( $wgContLang->getNsText(
293 Namespace::getWikipedia() ) .
294 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
296 $text = wfMsg( 'deletedtext', $deleted, $loglink );
298 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
299 $wgOut->returnToMain( false );
302 function doDeleteOldImage( $oldimage )
306 $name = substr( $oldimage, 15 );
307 $archive = wfImageArchiveDir( $name );
309 # Delete the image if it exists. Sometimes the file will be missing
310 # due to manual intervention or weird sync problems; treat that
311 # condition gracefully and continue to delete the database entry.
312 # Also some records may end up with an empty oi_archive_name field
313 # if the original file was missing when a new upload was made;
314 # don't try to delete the directory then!
316 $targetFile = "{$archive}/{$oldimage}";
317 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink
( $targetFile ) ) {
318 # If we actually have a file and can't delete it, throw an error.
319 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
322 $log = new LogPage( 'delete' );
323 $log->addEntry( 'delete', $this->mTitle
, wfMsg('deletedrevision',$oldimage) );
329 global $wgOut, $wgRequest;
330 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
332 $oldimage = $wgRequest->getText( 'oldimage' );
333 if ( strlen( $oldimage ) < 16 ) {
334 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
337 if ( strstr( $oldimage, "/" ) ||
strstr( $oldimage, "\\" ) ) {
338 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
342 if ( wfReadOnly() ) {
343 $wgOut->readOnlyPage();
346 if ( ! $this->mTitle
->userCanEdit() ) {
347 $wgOut->sysopRequired();
350 $name = substr( $oldimage, 15 );
352 $dest = wfImageDir( $name );
353 $archive = wfImageArchiveDir( $name );
354 $curfile = "{$dest}/{$name}";
356 if ( ! is_file( $curfile ) ) {
357 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
360 $oldver = wfTimestampNow() . "!{$name}";
362 $dbr =& wfGetDB( DB_SLAVE
);
363 $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
364 $dbr->strencode( $oldimage ) . "'" );
366 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
367 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
370 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
371 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
373 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
377 $wgInternalServer.wfImageArchiveUrl( $name ),
378 $wgInternalServer . Image
::wfImageUrl( $name )
380 wfPurgeSquidServers($urlArr);
383 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
384 $wgOut->setRobotpolicy( 'noindex,nofollow' );
385 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
386 $wgOut->returnToMain( false );
390 class ImageHistoryList
{
391 function ImageHistoryList( &$skin ) {
392 $this->skin
=& $skin;
395 function beginImageHistoryList() {
396 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
397 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
401 function endImageHistoryList() {
406 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
407 global $wgUser, $wgLang, $wgContLang, $wgTitle;
409 $datetime = $wgLang->timeanddate( $timestamp, true );
410 $del = wfMsg( 'deleteimg' );
411 $delall = wfMsg( 'deleteimgcompletely' );
412 $cur = wfMsg( 'cur' );
415 $url = Image
::wfImageUrl( $img );
417 if ( $wgUser->isAllowed('delete') ) {
418 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
420 $style = $this->skin
->getInternalLinkAttributes( $link, $delall );
422 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
427 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
428 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
429 $rlink = $this->skin
->makeKnownLink( $wgTitle->getPrefixedText(),
430 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
432 $dlink = $this->skin
->makeKnownLink( $wgTitle->getPrefixedText(),
433 $del, 'action=delete&oldimage=' . urlencode( $img ) );
435 # Having live active links for non-logged in users
436 # means that bots and spiders crawling our site can
437 # inadvertently change content. Baaaad idea.
438 $rlink = wfMsg( 'revertimg' );
443 $userlink = $usertext;
445 $userlink = $this->skin
->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
446 ':'.$usertext, $usertext );
448 $nbytes = wfMsg( 'nbytes', $size );
449 $style = $this->skin
->getInternalLinkAttributes( $url, $datetime );
451 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
452 . " . . {$userlink} ({$nbytes})";
454 if ( '' != $description && '*' != $description ) {
455 $sk=$wgUser->getSkin();
456 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');