* Made special page names case-insensitive and localisable. Care has been taken to...
[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, $wgStyleVersion;
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?wgStyleVersion\"></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, $wgLang;
167 global $wgUseImageResize, $wgGenerateThumbnailOnParse;
168
169 $full_url = $this->img->getURL();
170 $anchoropen = '';
171 $anchorclose = '';
172
173 if( $wgUser->getOption( 'imagesize' ) == '' ) {
174 $sizeSel = User::getDefaultOption( 'imagesize' );
175 } else {
176 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
177 }
178 if( !isset( $wgImageLimits[$sizeSel] ) ) {
179 $sizeSel = User::getDefaultOption( 'imagesize' );
180 }
181 $max = $wgImageLimits[$sizeSel];
182 $maxWidth = $max[0];
183 $maxHeight = $max[1];
184 $sk = $wgUser->getSkin();
185
186 if ( $this->img->exists() ) {
187 # image
188 $page = $wgRequest->getIntOrNull( 'page' );
189 if ( ! is_null( $page ) ) {
190 $this->img->selectPage( $page );
191 } else {
192 $page = 1;
193 }
194 $width = $this->img->getWidth();
195 $height = $this->img->getHeight();
196 $showLink = false;
197
198 if ( $this->img->allowInlineDisplay() and $width and $height) {
199 # image
200
201 # "Download high res version" link below the image
202 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
203
204 # We'll show a thumbnail of this image
205 if ( $width > $maxWidth || $height > $maxHeight ) {
206 # Calculate the thumbnail size.
207 # First case, the limiting factor is the width, not the height.
208 if ( $width / $height >= $maxWidth / $maxHeight ) {
209 $height = round( $height * $maxWidth / $width);
210 $width = $maxWidth;
211 # Note that $height <= $maxHeight now.
212 } else {
213 $newwidth = floor( $width * $maxHeight / $height);
214 $height = round( $height * $newwidth / $width );
215 $width = $newwidth;
216 # Note that $height <= $maxHeight now, but might not be identical
217 # because of rounding.
218 }
219
220 if( $wgUseImageResize ) {
221 $thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );
222 if ( $thumbnail == null ) {
223 $url = $this->img->getViewURL();
224 } else {
225 $url = $thumbnail->getURL();
226 }
227 } else {
228 # No resize ability? Show the full image, but scale
229 # it down in the browser so it fits on the page.
230 $url = $this->img->getViewURL();
231 }
232 $anchoropen = "<a href=\"{$full_url}\">";
233 $anchorclose = "</a><br />";
234 if( $this->img->mustRender() ) {
235 $showLink = true;
236 } else {
237 $anchorclose .= "\n$anchoropen{$msg}</a>";
238 }
239 } else {
240 $url = $this->img->getViewURL();
241 $showLink = true;
242 }
243
244 if ( $this->img->isMultipage() ) {
245 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
246 }
247
248 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
249 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
250 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
251
252 if ( $this->img->isMultipage() ) {
253 $count = $this->img->pageCount();
254
255 if ( $page > 1 ) {
256 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
257 $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
258 $this->img->selectPage( $page - 1 );
259 $thumb1 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
260 } else {
261 $thumb1 = '';
262 }
263
264 if ( $page < $count ) {
265 $label = wfMsg( 'imgmultipagenext' );
266 $this->img->selectPage( $page + 1 );
267 $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
268 $thumb2 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
269 } else {
270 $thumb2 = '';
271 }
272
273 $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl( '' ) . '" method="GET" onchange="document.pageselector.submit();">' ;
274 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
275 ' <select id="pageselector" name="page">';
276 for ( $i=1; $i <= $count; $i++ ) {
277 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
278 $i == $page );
279 }
280 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
281 '<input type="submit" value="' .
282 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
283
284 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
285 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
286 }
287 } else {
288 #if direct link is allowed but it's not a renderable image, show an icon.
289 if ($this->img->isSafeFile()) {
290 $icon= $this->img->iconThumb();
291
292 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
293 $icon->toHtml() .
294 '</a></div>' );
295 }
296
297 $showLink = true;
298 }
299
300
301 if ($showLink) {
302 $filename = wfEscapeWikiText( $this->img->getName() );
303 $info = wfMsg( 'fileinfo',
304 ceil($this->img->getSize()/1024.0),
305 $this->img->getMimeType() );
306
307 global $wgContLang;
308 $dirmark = $wgContLang->getDirMark();
309 if (!$this->img->isSafeFile()) {
310 $warning = wfMsg( 'mediawarning' );
311 $wgOut->addWikiText( <<<END
312 <div class="fullMedia">
313 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
314 <span class="fileInfo"> ($info)</span>
315 </div>
316
317 <div class="mediaWarning">$warning</div>
318 END
319 );
320 } else {
321 $wgOut->addWikiText( <<<END
322 <div class="fullMedia">
323 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
324 </div>
325 END
326 );
327 }
328 }
329
330 if($this->img->fromSharedDirectory) {
331 $this->printSharedImageText();
332 }
333 } else {
334 # Image does not exist
335
336 $title = SpecialPage::getTitleFor( 'Upload' );
337 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
338 'wpDestFile=' . urlencode( $this->img->getName() ) );
339 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
340 }
341 }
342
343 function printSharedImageText() {
344 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
345
346 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
347 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
348 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
349
350 $sk = $wgUser->getSkin();
351 $title = SpecialPage::getTitleFor( 'Upload' );
352 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
353 array( 'wpDestFile' => urlencode( $this->img->getName() )));
354 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
355 }
356 $sharedtext .= "</div>";
357 $wgOut->addHTML($sharedtext);
358
359 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
360 $text = Http::get($url . '?action=render');
361 if ($text)
362 $this->mExtraDescription = $text;
363 }
364 }
365
366 function getUploadUrl() {
367 global $wgServer;
368 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
369 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
370 }
371
372 /**
373 * Print out the various links at the bottom of the image page, e.g. reupload,
374 * external editing (and instructions link) etc.
375 */
376 function uploadLinksBox() {
377 global $wgUser, $wgOut;
378
379 if( $this->img->fromSharedDirectory )
380 return;
381
382 $sk = $wgUser->getSkin();
383
384 $wgOut->addHtml( '<br /><ul>' );
385
386 # "Upload a new version of this file" link
387 if( $wgUser->isAllowed( 'reupload' ) ) {
388 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
389 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
390 }
391
392 # External editing link
393 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
394 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
395
396 $wgOut->addHtml( '</ul>' );
397 }
398
399 function closeShowImage()
400 {
401 # For overloading
402
403 }
404
405 /**
406 * If the page we've just displayed is in the "Image" namespace,
407 * we follow it with an upload history of the image and its usage.
408 */
409 function imageHistory()
410 {
411 global $wgUser, $wgOut, $wgUseExternalEditor;
412
413 $sk = $wgUser->getSkin();
414
415 $line = $this->img->nextHistoryLine();
416
417 if ( $line ) {
418 $list = new ImageHistoryList( $sk );
419 $s = $list->beginImageHistoryList() .
420 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
421 $this->mTitle->getDBkey(), $line->img_user,
422 $line->img_user_text, $line->img_size, $line->img_description,
423 $line->img_width, $line->img_height
424 );
425
426 while ( $line = $this->img->nextHistoryLine() ) {
427 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
428 $line->oi_archive_name, $line->img_user,
429 $line->img_user_text, $line->img_size, $line->img_description,
430 $line->img_width, $line->img_height
431 );
432 }
433 $s .= $list->endImageHistoryList();
434 } else { $s=''; }
435 $wgOut->addHTML( $s );
436
437 # Exist check because we don't want to show this on pages where an image
438 # doesn't exist along with the noimage message, that would suck. -ævar
439 if( $wgUseExternalEditor && $this->img->exists() ) {
440 $this->uploadLinksBox();
441 }
442
443 }
444
445 function imageLinks()
446 {
447 global $wgUser, $wgOut;
448
449 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
450
451 $dbr =& wfGetDB( DB_SLAVE );
452 $page = $dbr->tableName( 'page' );
453 $imagelinks = $dbr->tableName( 'imagelinks' );
454
455 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
456 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
457 $sql = $dbr->limitResult($sql, 500, 0);
458 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
459
460 if ( 0 == $dbr->numRows( $res ) ) {
461 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
462 return;
463 }
464 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
465
466 $sk = $wgUser->getSkin();
467 while ( $s = $dbr->fetchObject( $res ) ) {
468 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
469 $link = $sk->makeKnownLinkObj( $name, "" );
470 $wgOut->addHTML( "<li>{$link}</li>\n" );
471 }
472 $wgOut->addHTML( "</ul>\n" );
473 }
474
475 function delete()
476 {
477 global $wgUser, $wgOut, $wgRequest;
478
479 $confirm = $wgRequest->wasPosted();
480 $reason = $wgRequest->getVal( 'wpReason' );
481 $image = $wgRequest->getVal( 'image' );
482 $oldimage = $wgRequest->getVal( 'oldimage' );
483
484 # Only sysops can delete images. Previously ordinary users could delete
485 # old revisions, but this is no longer the case.
486 if ( !$wgUser->isAllowed('delete') ) {
487 $wgOut->permissionRequired( 'delete' );
488 return;
489 }
490 if ( $wgUser->isBlocked() ) {
491 return $this->blockedIPpage();
492 }
493 if ( wfReadOnly() ) {
494 $wgOut->readOnlyPage();
495 return;
496 }
497
498 # Better double-check that it hasn't been deleted yet!
499 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
500 if ( ( !is_null( $image ) )
501 && ( '' == trim( $image ) ) ) {
502 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
503 return;
504 }
505
506 $this->img = new Image( $this->mTitle );
507
508 # Deleting old images doesn't require confirmation
509 if ( !is_null( $oldimage ) || $confirm ) {
510 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
511 $this->doDelete( $reason );
512 } else {
513 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
514 }
515 return;
516 }
517
518 if ( !is_null( $image ) ) {
519 $q = '&image=' . urlencode( $image );
520 } else if ( !is_null( $oldimage ) ) {
521 $q = '&oldimage=' . urlencode( $oldimage );
522 } else {
523 $q = '';
524 }
525 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
526 }
527
528 /*
529 * Delete an image.
530 * @param $reason User provided reason for deletion.
531 */
532 function doDelete( $reason ) {
533 global $wgOut, $wgRequest, $wgUseSquid;
534 global $wgPostCommitUpdateList;
535
536 $fname = 'ImagePage::doDelete';
537
538 $oldimage = $wgRequest->getVal( 'oldimage' );
539
540 $dbw =& wfGetDB( DB_MASTER );
541
542 if ( !is_null( $oldimage ) ) {
543 if ( strlen( $oldimage ) < 16 ) {
544 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
545 return;
546 }
547 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
548 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
549 return;
550 }
551 if ( !$this->doDeleteOldImage( $oldimage ) ) {
552 return;
553 }
554 $deleted = $oldimage;
555 } else {
556 $ok = $this->img->delete( $reason );
557 if( !$ok ) {
558 # If the deletion operation actually failed, bug out:
559 $wgOut->showFileDeleteError( $this->img->getName() );
560 return;
561 }
562
563 # Image itself is now gone, and database is cleaned.
564 # Now we remove the image description page.
565
566 $article = new Article( $this->mTitle );
567 $article->doDeleteArticle( $reason ); # ignore errors
568
569 $deleted = $this->img->getName();
570 }
571
572 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
573 $wgOut->setRobotpolicy( 'noindex,nofollow' );
574
575 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
576 $text = wfMsg( 'deletedtext', $deleted, $loglink );
577
578 $wgOut->addWikiText( $text );
579
580 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
581 }
582
583 /**
584 * @return success
585 */
586 function doDeleteOldImage( $oldimage )
587 {
588 global $wgOut;
589
590 $ok = $this->img->deleteOld( $oldimage, '' );
591 if( !$ok ) {
592 # If we actually have a file and can't delete it, throw an error.
593 # Something went awry...
594 $wgOut->showFileDeleteError( "$oldimage" );
595 } else {
596 # Log the deletion
597 $log = new LogPage( 'delete' );
598 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
599 }
600 return $ok;
601 }
602
603 function revert() {
604 global $wgOut, $wgRequest, $wgUser;
605
606 $oldimage = $wgRequest->getText( 'oldimage' );
607 if ( strlen( $oldimage ) < 16 ) {
608 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
609 return;
610 }
611 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
612 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
613 return;
614 }
615
616 if ( wfReadOnly() ) {
617 $wgOut->readOnlyPage();
618 return;
619 }
620 if( $wgUser->isAnon() ) {
621 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
622 return;
623 }
624 if ( ! $this->mTitle->userCanEdit() ) {
625 $wgOut->readOnlyPage( $this->getContent(), true );
626 return;
627 }
628 if ( $wgUser->isBlocked() ) {
629 return $this->blockedIPpage();
630 }
631 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
632 $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
633 return;
634 }
635 $name = substr( $oldimage, 15 );
636
637 $dest = wfImageDir( $name );
638 $archive = wfImageArchiveDir( $name );
639 $curfile = "{$dest}/{$name}";
640
641 if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
642 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
643
644 if ( ! is_file( $curfile ) ) {
645 $wgOut->showFileNotFoundError( 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->showFileRenameError( $curfile, "${archive}/{$oldver}" );
655 return;
656 }
657 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
658 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
659 return;
660 }
661
662 # Record upload and update metadata cache
663 $img = Image::newFromName( $name );
664 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
665
666 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
667 $wgOut->setRobotpolicy( 'noindex,nofollow' );
668 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
669
670 $descTitle = $img->getTitle();
671 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
672 }
673
674 function blockedIPpage() {
675 $edit = new EditPage( $this );
676 return $edit->blockedIPpage();
677 }
678
679 /**
680 * Override handling of action=purge
681 */
682 function doPurge() {
683 $this->img = new Image( $this->mTitle );
684 if( $this->img->exists() ) {
685 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
686 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
687 $update->doUpdate();
688 $this->img->purgeCache();
689 } else {
690 wfDebug( "ImagePage::doPurge no image\n" );
691 }
692 parent::doPurge();
693 }
694
695 }
696
697 /**
698 * @todo document
699 * @package MediaWiki
700 */
701 class ImageHistoryList {
702 function ImageHistoryList( &$skin ) {
703 $this->skin =& $skin;
704 }
705
706 function beginImageHistoryList() {
707 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
708 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
709 return $s;
710 }
711
712 function endImageHistoryList() {
713 $s = "</ul>\n";
714 return $s;
715 }
716
717 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
718 global $wgUser, $wgLang, $wgTitle, $wgContLang;
719
720 $datetime = $wgLang->timeanddate( $timestamp, true );
721 $del = wfMsg( 'deleteimg' );
722 $delall = wfMsg( 'deleteimgcompletely' );
723 $cur = wfMsg( 'cur' );
724
725 if ( $iscur ) {
726 $url = Image::imageUrl( $img );
727 $rlink = $cur;
728 if ( $wgUser->isAllowed('delete') ) {
729 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
730 '&action=delete' );
731 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
732
733 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
734 } else {
735 $dlink = $del;
736 }
737 } else {
738 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
739 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
740 $token = urlencode( $wgUser->editToken( $img ) );
741 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
742 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
743 urlencode( $img ) . "&wpEditToken=$token" );
744 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
745 $del, 'action=delete&oldimage=' . urlencode( $img ) .
746 "&wpEditToken=$token" );
747 } else {
748 # Having live active links for non-logged in users
749 # means that bots and spiders crawling our site can
750 # inadvertently change content. Baaaad idea.
751 $rlink = wfMsg( 'revertimg' );
752 $dlink = $del;
753 }
754 }
755
756 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
757 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
758 $wgLang->formatNum( $size ) );
759 $widthheight = wfMsg( 'widthheight', $width, $height );
760 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
761
762 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
763
764 $s .= $this->skin->commentBlock( $description, $wgTitle );
765 $s .= "</li>\n";
766 return $s;
767 }
768
769 }
770
771
772 ?>