Revert to r14512; domas introduced massive breakage with incomplete experimental...
[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 * Print out the various links at the bottom of the image page, e.g. reupload,
329 * external editing (and instructions link) etc.
330 */
331 function uploadLinksBox() {
332 global $wgUser, $wgOut;
333
334 if( $this->img->fromSharedDirectory )
335 return;
336
337 $sk = $wgUser->getSkin();
338
339 $wgOut->addHtml( '<br /><ul>' );
340
341 # "Upload a new version of this file" link
342 if( $wgUser->isAllowed( 'reupload' ) ) {
343 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
344 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
345 }
346
347 # External editing link
348 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
349 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
350
351 $wgOut->addHtml( '</ul>' );
352 }
353
354 function closeShowImage()
355 {
356 # For overloading
357
358 }
359
360 /**
361 * If the page we've just displayed is in the "Image" namespace,
362 * we follow it with an upload history of the image and its usage.
363 */
364 function imageHistory()
365 {
366 global $wgUser, $wgOut, $wgUseExternalEditor;
367
368 $sk = $wgUser->getSkin();
369
370 $line = $this->img->nextHistoryLine();
371
372 if ( $line ) {
373 $list =& new ImageHistoryList( $sk );
374 $s = $list->beginImageHistoryList() .
375 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
376 $this->mTitle->getDBkey(), $line->img_user,
377 $line->img_user_text, $line->img_size, $line->img_description,
378 $line->img_width, $line->img_height
379 );
380
381 while ( $line = $this->img->nextHistoryLine() ) {
382 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
383 $line->oi_archive_name, $line->img_user,
384 $line->img_user_text, $line->img_size, $line->img_description,
385 $line->img_width, $line->img_height
386 );
387 }
388 $s .= $list->endImageHistoryList();
389 } else { $s=''; }
390 $wgOut->addHTML( $s );
391
392 # Exist check because we don't want to show this on pages where an image
393 # doesn't exist along with the noimage message, that would suck. -ævar
394 if( $wgUseExternalEditor && $this->img->exists() ) {
395 $this->uploadLinksBox();
396 }
397
398 }
399
400 function imageLinks()
401 {
402 global $wgUser, $wgOut;
403
404 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
405
406 $dbr =& wfGetDB( DB_SLAVE );
407 $page = $dbr->tableName( 'page' );
408 $imagelinks = $dbr->tableName( 'imagelinks' );
409
410 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
411 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
412 $sql = $dbr->limitResult($sql, 500, 0);
413 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
414
415 if ( 0 == $dbr->numRows( $res ) ) {
416 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
417 return;
418 }
419 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
420
421 $sk = $wgUser->getSkin();
422 while ( $s = $dbr->fetchObject( $res ) ) {
423 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
424 $link = $sk->makeKnownLinkObj( $name, "" );
425 $wgOut->addHTML( "<li>{$link}</li>\n" );
426 }
427 $wgOut->addHTML( "</ul>\n" );
428 }
429
430 function delete()
431 {
432 global $wgUser, $wgOut, $wgRequest;
433
434 $confirm = $wgRequest->wasPosted();
435 $image = $wgRequest->getVal( 'image' );
436 $oldimage = $wgRequest->getVal( 'oldimage' );
437
438 # Only sysops can delete images. Previously ordinary users could delete
439 # old revisions, but this is no longer the case.
440 if ( !$wgUser->isAllowed('delete') ) {
441 $wgOut->sysopRequired();
442 return;
443 }
444 if ( $wgUser->isBlocked() ) {
445 return $this->blockedIPpage();
446 }
447 if ( wfReadOnly() ) {
448 $wgOut->readOnlyPage();
449 return;
450 }
451
452 # Better double-check that it hasn't been deleted yet!
453 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
454 if ( ( !is_null( $image ) )
455 && ( '' == trim( $image ) ) ) {
456 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
457 return;
458 }
459
460 $this->img = new Image( $this->mTitle );
461
462 # Deleting old images doesn't require confirmation
463 if ( !is_null( $oldimage ) || $confirm ) {
464 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
465 $this->doDelete();
466 } else {
467 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
468 }
469 return;
470 }
471
472 if ( !is_null( $image ) ) {
473 $q = '&image=' . urlencode( $image );
474 } else if ( !is_null( $oldimage ) ) {
475 $q = '&oldimage=' . urlencode( $oldimage );
476 } else {
477 $q = '';
478 }
479 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
480 }
481
482 function doDelete() {
483 global $wgOut, $wgRequest, $wgUseSquid;
484 global $wgPostCommitUpdateList;
485
486 $fname = 'ImagePage::doDelete';
487
488 $reason = $wgRequest->getVal( 'wpReason' );
489 $oldimage = $wgRequest->getVal( 'oldimage' );
490
491 $dbw =& wfGetDB( DB_MASTER );
492
493 if ( !is_null( $oldimage ) ) {
494 if ( strlen( $oldimage ) < 16 ) {
495 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
496 return;
497 }
498 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
499 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
500 return;
501 }
502
503 # Invalidate description page cache
504 $this->mTitle->invalidateCache();
505
506 # Squid purging
507 if ( $wgUseSquid ) {
508 $urlArr = array(
509 wfImageArchiveUrl( $oldimage ),
510 $this->mTitle->getInternalURL()
511 );
512 wfPurgeSquidServers($urlArr);
513 }
514 $this->doDeleteOldImage( $oldimage );
515 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
516 $deleted = $oldimage;
517 } else {
518 $image = $this->mTitle->getDBkey();
519 $dest = wfImageDir( $image );
520 $archive = wfImageDir( $image );
521
522 # Delete the image file if it exists; due to sync problems
523 # or manual trimming sometimes the file will be missing.
524 $targetFile = "{$dest}/{$image}";
525 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
526 # If the deletion operation actually failed, bug out:
527 $wgOut->fileDeleteError( $targetFile );
528 return;
529 }
530 $dbw->delete( 'image', array( 'img_name' => $image ) );
531
532 if ( $dbw->affectedRows() ) {
533 # Update site_stats
534 $site_stats = $dbw->tableName( 'site_stats' );
535 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", $fname );
536 }
537
538
539 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
540
541 # Purge archive URLs from the squid
542 $urlArr = Array();
543 while ( $s = $dbw->fetchObject( $res ) ) {
544 $this->doDeleteOldImage( $s->oi_archive_name );
545 $urlArr[] = wfImageArchiveUrl( $s->oi_archive_name );
546 }
547
548 # And also the HTML of all pages using this image
549 $linksTo = $this->img->getLinksTo();
550 if ( $wgUseSquid ) {
551 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
552 array_push( $wgPostCommitUpdateList, $u );
553 }
554
555 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
556
557 # Image itself is now gone, and database is cleaned.
558 # Now we remove the image description page.
559
560 $article = new Article( $this->mTitle );
561 $article->doDeleteArticle( $reason ); # ignore errors
562
563 # Invalidate parser cache and client cache for pages using this image
564 # This is left until relatively late to reduce lock time
565 Title::touchArray( $linksTo );
566
567 /* Delete thumbnails and refresh image metadata cache */
568 $this->img->purgeCache();
569
570 $deleted = $image;
571 }
572
573 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
574 $wgOut->setRobotpolicy( 'noindex,nofollow' );
575
576 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
577 $text = wfMsg( 'deletedtext', $deleted, $loglink );
578
579 $wgOut->addWikiText( $text );
580
581 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
582 }
583
584 function doDeleteOldImage( $oldimage )
585 {
586 global $wgOut;
587
588 $name = substr( $oldimage, 15 );
589 $archive = wfImageArchiveDir( $name );
590
591 # Delete the image if it exists. Sometimes the file will be missing
592 # due to manual intervention or weird sync problems; treat that
593 # condition gracefully and continue to delete the database entry.
594 # Also some records may end up with an empty oi_archive_name field
595 # if the original file was missing when a new upload was made;
596 # don't try to delete the directory then!
597 #
598 $targetFile = "{$archive}/{$oldimage}";
599 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
600 # If we actually have a file and can't delete it, throw an error.
601 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
602 } else {
603 # Log the deletion
604 $log = new LogPage( 'delete' );
605 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
606 }
607 }
608
609 function revert() {
610 global $wgOut, $wgRequest, $wgUser;
611
612 $oldimage = $wgRequest->getText( 'oldimage' );
613 if ( strlen( $oldimage ) < 16 ) {
614 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
615 return;
616 }
617 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
618 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
619 return;
620 }
621
622 if ( wfReadOnly() ) {
623 $wgOut->readOnlyPage();
624 return;
625 }
626 if( $wgUser->isAnon() ) {
627 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
628 return;
629 }
630 if ( ! $this->mTitle->userCanEdit() ) {
631 $wgOut->sysopRequired();
632 return;
633 }
634 if ( $wgUser->isBlocked() ) {
635 return $this->blockedIPpage();
636 }
637 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
638 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
639 return;
640 }
641 $name = substr( $oldimage, 15 );
642
643 $dest = wfImageDir( $name );
644 $archive = wfImageArchiveDir( $name );
645 $curfile = "{$dest}/{$name}";
646
647 if ( ! is_file( $curfile ) ) {
648 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
649 return;
650 }
651 $oldver = wfTimestampNow() . "!{$name}";
652
653 $dbr =& wfGetDB( DB_SLAVE );
654 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
655
656 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
657 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
658 return;
659 }
660 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
661 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
662 }
663
664 # Record upload and update metadata cache
665 $img = Image::newFromName( $name );
666 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
667
668 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
669 $wgOut->setRobotpolicy( 'noindex,nofollow' );
670 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
671
672 $descTitle = $img->getTitle();
673 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
674 }
675
676 function blockedIPpage() {
677 require_once( 'EditPage.php' );
678 $edit = new EditPage( $this );
679 return $edit->blockedIPpage();
680 }
681
682 /**
683 * Override handling of action=purge
684 */
685 function doPurge() {
686 $this->img = new Image( $this->mTitle );
687 if( $this->img->exists() ) {
688 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
689 $linksTo = $this->img->getLinksTo();
690 Title::touchArray( $linksTo );
691 $this->img->purgeCache();
692 } else {
693 wfDebug( "ImagePage::doPurge no image\n" );
694 }
695 parent::doPurge();
696 }
697
698 }
699
700 /**
701 * @todo document
702 * @package MediaWiki
703 */
704 class ImageHistoryList {
705 function ImageHistoryList( &$skin ) {
706 $this->skin =& $skin;
707 }
708
709 function beginImageHistoryList() {
710 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
711 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
712 return $s;
713 }
714
715 function endImageHistoryList() {
716 $s = "</ul>\n";
717 return $s;
718 }
719
720 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
721 global $wgUser, $wgLang, $wgTitle, $wgContLang;
722
723 $datetime = $wgLang->timeanddate( $timestamp, true );
724 $del = wfMsg( 'deleteimg' );
725 $delall = wfMsg( 'deleteimgcompletely' );
726 $cur = wfMsg( 'cur' );
727
728 if ( $iscur ) {
729 $url = Image::imageUrl( $img );
730 $rlink = $cur;
731 if ( $wgUser->isAllowed('delete') ) {
732 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
733 '&action=delete' );
734 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
735
736 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
737 } else {
738 $dlink = $del;
739 }
740 } else {
741 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
742 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
743 $token = urlencode( $wgUser->editToken( $img ) );
744 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
745 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
746 urlencode( $img ) . "&wpEditToken=$token" );
747 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
748 $del, 'action=delete&oldimage=' . urlencode( $img ) .
749 "&wpEditToken=$token" );
750 } else {
751 # Having live active links for non-logged in users
752 # means that bots and spiders crawling our site can
753 # inadvertently change content. Baaaad idea.
754 $rlink = wfMsg( 'revertimg' );
755 $dlink = $del;
756 }
757 }
758 if ( 0 == $user ) {
759 $userlink = $usertext;
760 } else {
761 $userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
762 $usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
763 $userdata = $userlink . ' (' . $usertalk . ')';
764 }
765 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
766 $wgLang->formatNum( $size ) );
767 $widthheight = wfMsg( 'widthheight', $width, $height );
768 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
769
770 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
771
772 $s .= $this->skin->commentBlock( $description, $wgTitle );
773 $s .= "</li>\n";
774 return $s;
775 }
776
777 }
778
779
780 ?>