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