* (bug 5805) message nbytes can now use {{plural:}}
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 *
8 */
9 if( !defined( 'MEDIAWIKI' ) )
10 die( -1 );
11
12 require_once( 'Image.php' );
13
14 /**
15 * Special handling for image description pages
16 * @package MediaWiki
17 */
18 class ImagePage extends Article {
19
20 /* private */ var $img; // Image object this page is shown for
21 var $mExtraDescription = false;
22
23 /**
24 * Handler for action=render
25 * Include body text only; none of the image extras
26 */
27 function render() {
28 global $wgOut;
29 $wgOut->setArticleBodyOnly( true );
30 $wgOut->addSecondaryWikitext( $this->getContent() );
31 }
32
33 function view() {
34 global $wgOut, $wgShowEXIF;
35
36 $this->img = new Image( $this->mTitle );
37
38 if( $this->mTitle->getNamespace() == NS_IMAGE ) {
39 if ($wgShowEXIF && $this->img->exists()) {
40 $exif = $this->img->getExifData();
41 $showmeta = count($exif) ? true : false;
42 } else {
43 $exif = false;
44 $showmeta = false;
45 }
46
47 if ($this->img->exists())
48 $wgOut->addHTML($this->showTOC($showmeta));
49
50 $this->openShowImage();
51
52 # No need to display noarticletext, we use our own message, output in openShowImage()
53 if( $this->getID() ) {
54 Article::view();
55 } else {
56 # Just need to set the right headers
57 $wgOut->setArticleFlag( true );
58 $wgOut->setRobotpolicy( 'index,follow' );
59 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
60 $this->viewUpdates();
61 }
62
63 # Show shared description, if needed
64 if( $this->mExtraDescription ) {
65 $fol = wfMsg( 'shareddescriptionfollows' );
66 if( $fol != '-' ) {
67 $wgOut->addWikiText( $fol );
68 }
69 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
70 }
71
72 $this->closeShowImage();
73 $this->imageHistory();
74 $this->imageLinks();
75 if( $exif ) {
76 global $wgStylePath;
77 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
78 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
79 $wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
80 $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
81 $wgOut->addHTML(
82 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .
83 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
84 }
85 } else {
86 Article::view();
87 }
88 }
89
90 /**
91 * Create the TOC
92 *
93 * @access private
94 *
95 * @param bool $metadata Whether or not to show the metadata link
96 * @return string
97 */
98 function showTOC( $metadata ) {
99 global $wgLang;
100 $r = '<ul id="filetoc">
101 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
102 <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
103 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
104 ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
105 </ul>';
106 return $r;
107 }
108
109 /**
110 * Make a table with metadata to be shown in the output page.
111 *
112 * @access private
113 *
114 * @param array $exif The array containing the EXIF data
115 * @return string
116 */
117 function makeMetadataTable( $exif ) {
118 $r = wfMsg( 'metadata-help' ) . "\n\n";
119 $r .= "{| id=mw_metadata class=mw_metadata\n";
120 $visibleFields = $this->visibleMetadataFields();
121 foreach( $exif as $k => $v ) {
122 $tag = strtolower( $k );
123 $msg = wfMsg( "exif-$tag" );
124 $class = "exif-$tag";
125 if( !in_array( $tag, $visibleFields ) ) {
126 $class .= ' collapsable';
127 }
128 $r .= "|- class=\"$class\"\n";
129 $r .= "!| $msg\n";
130 $r .= "|| $v\n";
131 }
132 $r .= '|}';
133 return $r;
134 }
135
136 /**
137 * Get a list of EXIF metadata items which should be displayed when
138 * the metadata table is collapsed.
139 *
140 * @return array of strings
141 * @access private
142 */
143 function visibleMetadataFields() {
144 $fields = array();
145 $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
146 foreach( $lines as $line ) {
147 if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
148 $fields[] = $matches[1];
149 }
150 }
151 return $fields;
152 }
153
154 /**
155 * Overloading Article's getContent method.
156 *
157 * Omit noarticletext if sharedupload; text will be fetched from the
158 * shared upload server if possible.
159 */
160 function getContent() {
161 if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
162 return '';
163 }
164 return Article::getContent();
165 }
166
167 function openShowImage() {
168 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
169
170 $full_url = $this->img->getURL();
171 $anchoropen = '';
172 $anchorclose = '';
173
174 if( $wgUser->getOption( 'imagesize' ) == '' ) {
175 $sizeSel = User::getDefaultOption( 'imagesize' );
176 } else {
177 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
178 }
179 if( !isset( $wgImageLimits[$sizeSel] ) ) {
180 $sizeSel = User::getDefaultOption( 'imagesize' );
181 }
182 $max = $wgImageLimits[$sizeSel];
183 $maxWidth = $max[0];
184 $maxHeight = $max[1];
185 $sk = $wgUser->getSkin();
186
187 if ( $this->img->exists() ) {
188 # image
189 $width = $this->img->getWidth();
190 $height = $this->img->getHeight();
191 $showLink = false;
192
193 if ( $this->img->allowInlineDisplay() and $width and $height) {
194 # image
195
196 # "Download high res version" link below the image
197 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
198
199 # We'll show a thumbnail of this image
200 if ( $width > $maxWidth || $height > $maxHeight ) {
201 # Calculate the thumbnail size.
202 # First case, the limiting factor is the width, not the height.
203 if ( $width / $height >= $maxWidth / $maxHeight ) {
204 $height = round( $height * $maxWidth / $width);
205 $width = $maxWidth;
206 # Note that $height <= $maxHeight now.
207 } else {
208 $newwidth = floor( $width * $maxHeight / $height);
209 $height = round( $height * $newwidth / $width );
210 $width = $newwidth;
211 # Note that $height <= $maxHeight now, but might not be identical
212 # because of rounding.
213 }
214
215 if( $wgUseImageResize ) {
216 $thumbnail = $this->img->getThumbnail( $width );
217 if ( $thumbnail == null ) {
218 $url = $this->img->getViewURL();
219 } else {
220 $url = $thumbnail->getURL();
221 }
222 } else {
223 # No resize ability? Show the full image, but scale
224 # it down in the browser so it fits on the page.
225 $url = $this->img->getViewURL();
226 }
227 $anchoropen = "<a href=\"{$full_url}\">";
228 $anchorclose = "</a><br />";
229 if( $this->img->mustRender() ) {
230 $showLink = true;
231 } else {
232 $anchorclose .= "\n$anchoropen{$msg}</a>";
233 }
234 } else {
235 $url = $this->img->getViewURL();
236 $showLink = true;
237 }
238 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
239 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
240 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
241 } else {
242 #if direct link is allowed but it's not a renderable image, show an icon.
243 if ($this->img->isSafeFile()) {
244 $icon= $this->img->iconThumb();
245
246 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
247 $icon->toHtml() .
248 '</a></div>' );
249 }
250
251 $showLink = true;
252 }
253
254
255 if ($showLink) {
256 $filename = wfEscapeWikiText( $this->img->getName() );
257 $info = wfMsg( 'fileinfo',
258 ceil($this->img->getSize()/1024.0),
259 $this->img->getMimeType() );
260
261 if (!$this->img->isSafeFile()) {
262 $warning = wfMsg( 'mediawarning' );
263 $wgOut->addWikiText( <<<END
264 <div class="fullMedia">
265 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
266 <span class="fileInfo"> ($info)</span>
267 </div>
268
269 <div class="mediaWarning">$warning</div>
270 END
271 );
272 } else {
273 $wgOut->addWikiText( <<<END
274 <div class="fullMedia">
275 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
276 </div>
277 END
278 );
279 }
280 }
281
282 if($this->img->fromSharedDirectory) {
283 $this->printSharedImageText();
284 }
285 } else {
286 # Image does not exist
287
288 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
289 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
290 'wpDestFile=' . urlencode( $this->img->getName() ) );
291 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
292 }
293 }
294
295 function printSharedImageText() {
296 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
297
298 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
299 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
300 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
301
302 $sk = $wgUser->getSkin();
303 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
304 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
305 array( 'wpDestFile' => urlencode( $this->img->getName() )));
306 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
307 }
308 $sharedtext .= "</div>";
309 $wgOut->addHTML($sharedtext);
310
311 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
312 require_once("HttpFunctions.php");
313 $ur = ini_set('allow_url_fopen', true);
314 $text = wfGetHTTP($url . '?action=render');
315 ini_set('allow_url_fopen', $ur);
316 if ($text)
317 $this->mExtraDescription = $text;
318 }
319 }
320
321 function getUploadUrl() {
322 global $wgServer;
323 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
324 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
325 }
326
327
328 function uploadLinksBox()
329 {
330 global $wgUser, $wgOut;
331
332 if ($this->img->fromSharedDirectory)
333 return;
334
335 $sk = $wgUser->getSkin();
336 $wgOut->addHTML( '<br /><ul>' );
337 if( $wgUser->isAllowed( 'reupload' ) ) {
338 $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
339 }
340 $wgOut->addHTML( '<li>' );
341 $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
342 wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
343 $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
344 $wgOut->addHTML( '</li></ul>' );
345 }
346
347 function closeShowImage()
348 {
349 # For overloading
350
351 }
352
353 /**
354 * If the page we've just displayed is in the "Image" namespace,
355 * we follow it with an upload history of the image and its usage.
356 */
357 function imageHistory()
358 {
359 global $wgUser, $wgOut, $wgUseExternalEditor;
360
361 $sk = $wgUser->getSkin();
362
363 $line = $this->img->nextHistoryLine();
364
365 if ( $line ) {
366 $list =& new ImageHistoryList( $sk );
367 $s = $list->beginImageHistoryList() .
368 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
369 $this->mTitle->getDBkey(), $line->img_user,
370 $line->img_user_text, $line->img_size, $line->img_description,
371 $line->img_width, $line->img_height
372 );
373
374 while ( $line = $this->img->nextHistoryLine() ) {
375 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
376 $line->oi_archive_name, $line->img_user,
377 $line->img_user_text, $line->img_size, $line->img_description,
378 $line->img_width, $line->img_height
379 );
380 }
381 $s .= $list->endImageHistoryList();
382 } else { $s=''; }
383 $wgOut->addHTML( $s );
384
385 # Exist check because we don't want to show this on pages where an image
386 # doesn't exist along with the noimage message, that would suck. -ævar
387 if( $wgUseExternalEditor && $this->img->exists() ) {
388 $this->uploadLinksBox();
389 }
390
391 }
392
393 function imageLinks()
394 {
395 global $wgUser, $wgOut;
396
397 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
398
399 $dbr =& wfGetDB( DB_SLAVE );
400 $page = $dbr->tableName( 'page' );
401 $imagelinks = $dbr->tableName( 'imagelinks' );
402
403 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
404 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
405 $sql = $dbr->limitResult($sql, 500, 0);
406 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
407
408 if ( 0 == $dbr->numRows( $res ) ) {
409 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
410 return;
411 }
412 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
413
414 $sk = $wgUser->getSkin();
415 while ( $s = $dbr->fetchObject( $res ) ) {
416 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
417 $link = $sk->makeKnownLinkObj( $name, "" );
418 $wgOut->addHTML( "<li>{$link}</li>\n" );
419 }
420 $wgOut->addHTML( "</ul>\n" );
421 }
422
423 function delete()
424 {
425 global $wgUser, $wgOut, $wgRequest;
426
427 $confirm = $wgRequest->wasPosted();
428 $image = $wgRequest->getVal( 'image' );
429 $oldimage = $wgRequest->getVal( 'oldimage' );
430
431 # Only sysops can delete images. Previously ordinary users could delete
432 # old revisions, but this is no longer the case.
433 if ( !$wgUser->isAllowed('delete') ) {
434 $wgOut->sysopRequired();
435 return;
436 }
437 if ( $wgUser->isBlocked() ) {
438 return $this->blockedIPpage();
439 }
440 if ( wfReadOnly() ) {
441 $wgOut->readOnlyPage();
442 return;
443 }
444
445 # Better double-check that it hasn't been deleted yet!
446 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
447 if ( ( !is_null( $image ) )
448 && ( '' == trim( $image ) ) ) {
449 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
450 return;
451 }
452
453 $this->img = new Image( $this->mTitle );
454
455 # Deleting old images doesn't require confirmation
456 if ( !is_null( $oldimage ) || $confirm ) {
457 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
458 $this->doDelete();
459 } else {
460 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
461 }
462 return;
463 }
464
465 if ( !is_null( $image ) ) {
466 $q = '&image=' . urlencode( $image );
467 } else if ( !is_null( $oldimage ) ) {
468 $q = '&oldimage=' . urlencode( $oldimage );
469 } else {
470 $q = '';
471 }
472 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
473 }
474
475 function doDelete() {
476 global $wgOut, $wgRequest, $wgUseSquid, $wgInternalServer;
477 global $wgPostCommitUpdateList;
478
479 $fname = 'ImagePage::doDelete';
480
481 $reason = $wgRequest->getVal( 'wpReason' );
482 $oldimage = $wgRequest->getVal( 'oldimage' );
483
484 $dbw =& wfGetDB( DB_MASTER );
485
486 if ( !is_null( $oldimage ) ) {
487 if ( strlen( $oldimage ) < 16 ) {
488 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
489 return;
490 }
491 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
492 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
493 return;
494 }
495
496 # Invalidate description page cache
497 $this->mTitle->invalidateCache();
498
499 # Squid purging
500 if ( $wgUseSquid ) {
501 $urlArr = array(
502 $wgInternalServer.wfImageArchiveUrl( $oldimage ),
503 $this->mTitle->getInternalURL()
504 );
505 wfPurgeSquidServers($urlArr);
506 }
507 $this->doDeleteOldImage( $oldimage );
508 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
509 $deleted = $oldimage;
510 } else {
511 $image = $this->mTitle->getDBkey();
512 $dest = wfImageDir( $image );
513 $archive = wfImageDir( $image );
514
515 # Delete the image file if it exists; due to sync problems
516 # or manual trimming sometimes the file will be missing.
517 $targetFile = "{$dest}/{$image}";
518 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
519 # If the deletion operation actually failed, bug out:
520 $wgOut->fileDeleteError( $targetFile );
521 return;
522 }
523 $dbw->delete( 'image', array( 'img_name' => $image ) );
524
525 if ( $dbw->affectedRows() ) {
526 # Update site_stats
527 $site_stats = $dbw->tableName( 'site_stats' );
528 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", $fname );
529 }
530
531
532 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
533
534 # Purge archive URLs from the squid
535 $urlArr = Array();
536 while ( $s = $dbw->fetchObject( $res ) ) {
537 $this->doDeleteOldImage( $s->oi_archive_name );
538 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
539 }
540
541 # And also the HTML of all pages using this image
542 $linksTo = $this->img->getLinksTo();
543 if ( $wgUseSquid ) {
544 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
545 array_push( $wgPostCommitUpdateList, $u );
546 }
547
548 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
549
550 # Image itself is now gone, and database is cleaned.
551 # Now we remove the image description page.
552
553 $article = new Article( $this->mTitle );
554 $article->doDeleteArticle( $reason ); # ignore errors
555
556 # Invalidate parser cache and client cache for pages using this image
557 # This is left until relatively late to reduce lock time
558 Title::touchArray( $linksTo );
559
560 /* Delete thumbnails and refresh image metadata cache */
561 $this->img->purgeCache();
562
563 $deleted = $image;
564 }
565
566 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
567 $wgOut->setRobotpolicy( 'noindex,nofollow' );
568
569 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
570 $text = wfMsg( 'deletedtext', $deleted, $loglink );
571
572 $wgOut->addWikiText( $text );
573
574 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
575 }
576
577 function doDeleteOldImage( $oldimage )
578 {
579 global $wgOut;
580
581 $name = substr( $oldimage, 15 );
582 $archive = wfImageArchiveDir( $name );
583
584 # Delete the image if it exists. Sometimes the file will be missing
585 # due to manual intervention or weird sync problems; treat that
586 # condition gracefully and continue to delete the database entry.
587 # Also some records may end up with an empty oi_archive_name field
588 # if the original file was missing when a new upload was made;
589 # don't try to delete the directory then!
590 #
591 $targetFile = "{$archive}/{$oldimage}";
592 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
593 # If we actually have a file and can't delete it, throw an error.
594 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
595 } else {
596 # Log the deletion
597 $log = new LogPage( 'delete' );
598 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
599 }
600 }
601
602 function revert() {
603 global $wgOut, $wgRequest, $wgUser;
604
605 $oldimage = $wgRequest->getText( 'oldimage' );
606 if ( strlen( $oldimage ) < 16 ) {
607 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
608 return;
609 }
610 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
611 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
612 return;
613 }
614
615 if ( wfReadOnly() ) {
616 $wgOut->readOnlyPage();
617 return;
618 }
619 if( $wgUser->isAnon() ) {
620 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
621 return;
622 }
623 if ( ! $this->mTitle->userCanEdit() ) {
624 $wgOut->sysopRequired();
625 return;
626 }
627 if ( $wgUser->isBlocked() ) {
628 return $this->blockedIPpage();
629 }
630 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
631 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
632 return;
633 }
634 $name = substr( $oldimage, 15 );
635
636 $dest = wfImageDir( $name );
637 $archive = wfImageArchiveDir( $name );
638 $curfile = "{$dest}/{$name}";
639
640 if ( ! is_file( $curfile ) ) {
641 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
642 return;
643 }
644 $oldver = wfTimestampNow() . "!{$name}";
645
646 $dbr =& wfGetDB( DB_SLAVE );
647 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
648
649 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
650 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
651 return;
652 }
653 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
654 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
655 }
656
657 # Record upload and update metadata cache
658 $img = Image::newFromName( $name );
659 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
660
661 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
662 $wgOut->setRobotpolicy( 'noindex,nofollow' );
663 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
664
665 $descTitle = $img->getTitle();
666 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
667 }
668
669 function blockedIPpage() {
670 require_once( 'EditPage.php' );
671 $edit = new EditPage( $this );
672 return $edit->blockedIPpage();
673 }
674
675 /**
676 * Override handling of action=purge
677 */
678 function doPurge() {
679 $this->img = new Image( $this->mTitle );
680 if( $this->img->exists() ) {
681 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
682 $linksTo = $this->img->getLinksTo();
683 Title::touchArray( $linksTo );
684 $this->img->purgeCache();
685 } else {
686 wfDebug( "ImagePage::doPurge no image\n" );
687 }
688 parent::doPurge();
689 }
690
691 }
692
693 /**
694 * @todo document
695 * @package MediaWiki
696 */
697 class ImageHistoryList {
698 function ImageHistoryList( &$skin ) {
699 $this->skin =& $skin;
700 }
701
702 function beginImageHistoryList() {
703 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
704 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
705 return $s;
706 }
707
708 function endImageHistoryList() {
709 $s = "</ul>\n";
710 return $s;
711 }
712
713 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
714 global $wgUser, $wgLang, $wgTitle, $wgContLang;
715
716 $datetime = $wgLang->timeanddate( $timestamp, true );
717 $del = wfMsg( 'deleteimg' );
718 $delall = wfMsg( 'deleteimgcompletely' );
719 $cur = wfMsg( 'cur' );
720
721 if ( $iscur ) {
722 $url = Image::imageUrl( $img );
723 $rlink = $cur;
724 if ( $wgUser->isAllowed('delete') ) {
725 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
726 '&action=delete' );
727 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
728
729 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
730 } else {
731 $dlink = $del;
732 }
733 } else {
734 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
735 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
736 $token = urlencode( $wgUser->editToken( $img ) );
737 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
738 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
739 urlencode( $img ) . "&wpEditToken=$token" );
740 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
741 $del, 'action=delete&oldimage=' . urlencode( $img ) .
742 "&wpEditToken=$token" );
743 } else {
744 # Having live active links for non-logged in users
745 # means that bots and spiders crawling our site can
746 # inadvertently change content. Baaaad idea.
747 $rlink = wfMsg( 'revertimg' );
748 $dlink = $del;
749 }
750 }
751 if ( 0 == $user ) {
752 $userlink = $usertext;
753 } else {
754 $userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
755 $usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
756 $userdata = $userlink . ' (' . $usertalk . ')';
757 }
758 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
759 $wgLang->formatNum( $size ) );
760 $widthheight = wfMsg( 'widthheight', $width, $height );
761 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
762
763 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
764
765 $s .= $this->skin->commentBlock( $description, $wgTitle );
766 $s .= "</li>\n";
767 return $s;
768 }
769
770 }
771
772
773 ?>