5936541f373ab3e4e7fed2c2bab90600ec8b11ba
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 */
4
5 /**
6 *
7 */
8 if( !defined( 'MEDIAWIKI' ) )
9 die( 1 );
10
11 /**
12 * Special handling for image description pages
13 */
14 class ImagePage extends Article {
15
16 /* private */ var $img; // Image object this page is shown for
17 var $mExtraDescription = false;
18
19 /**
20 * Handler for action=render
21 * Include body text only; none of the image extras
22 */
23 function render() {
24 global $wgOut;
25 $wgOut->setArticleBodyOnly( true );
26 $wgOut->addSecondaryWikitext( $this->getContent() );
27 }
28
29 function view() {
30 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
31
32 $this->img = new Image( $this->mTitle );
33
34 $diff = $wgRequest->getVal( 'diff' );
35 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
36
37 if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
38 return Article::view();
39
40 if ($wgShowEXIF && $this->img->exists()) {
41 $exif = $this->img->getExifData();
42 $showmeta = count($exif) ? true : false;
43 } else {
44 $exif = false;
45 $showmeta = false;
46 }
47
48 if ($this->img->exists())
49 $wgOut->addHTML($this->showTOC($showmeta));
50
51 $this->openShowImage();
52
53 # No need to display noarticletext, we use our own message, output in openShowImage()
54 if ( $this->getID() ) {
55 Article::view();
56 } else {
57 # Just need to set the right headers
58 $wgOut->setArticleFlag( true );
59 $wgOut->setRobotpolicy( 'index,follow' );
60 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
61 $this->viewUpdates();
62 }
63
64 # Show shared description, if needed
65 if ( $this->mExtraDescription ) {
66 $fol = wfMsg( 'shareddescriptionfollows' );
67 if( $fol != '-' ) {
68 $wgOut->addWikiText( $fol );
69 }
70 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
71 }
72
73 $this->closeShowImage();
74 $this->imageHistory();
75 $this->imageLinks();
76
77 if ( $exif ) {
78 global $wgStylePath, $wgStyleVersion;
79 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
80 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
81 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
82 $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
83 $wgOut->addHTML(
84 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
85 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
86 }
87 }
88
89 /**
90 * Create the TOC
91 *
92 * @access private
93 *
94 * @param bool $metadata Whether or not to show the metadata link
95 * @return string
96 */
97 function showTOC( $metadata ) {
98 global $wgLang;
99 $r = '<ul id="filetoc">
100 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
101 <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
102 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
103 ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
104 </ul>';
105 return $r;
106 }
107
108 /**
109 * Make a table with metadata to be shown in the output page.
110 *
111 * @access private
112 *
113 * @param array $exif The array containing the EXIF data
114 * @return string
115 */
116 function makeMetadataTable( $exif ) {
117 $r = wfMsg( 'metadata-help' ) . "\n\n";
118 $r .= "{| id=mw_metadata class=mw_metadata\n";
119 $visibleFields = $this->visibleMetadataFields();
120 foreach( $exif as $k => $v ) {
121 $tag = strtolower( $k );
122 $msg = wfMsg( "exif-$tag" );
123 $class = "exif-$tag";
124 if( !in_array( $tag, $visibleFields ) ) {
125 $class .= ' collapsable';
126 }
127 $r .= "|- class=\"$class\"\n";
128 $r .= "!| $msg\n";
129 $r .= "|| $v\n";
130 }
131 $r .= '|}';
132 return $r;
133 }
134
135 /**
136 * Get a list of EXIF metadata items which should be displayed when
137 * the metadata table is collapsed.
138 *
139 * @return array of strings
140 * @access private
141 */
142 function visibleMetadataFields() {
143 $fields = array();
144 $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
145 foreach( $lines as $line ) {
146 $matches = array();
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, $wgLang;
169 global $wgUseImageResize, $wgGenerateThumbnailOnParse;
170
171 $full_url = $this->img->getURL();
172 $anchoropen = '';
173 $anchorclose = '';
174 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
175
176 if( !isset( $wgImageLimits[$sizeSel] ) ) {
177 $sizeSel = User::getDefaultOption( 'imagesize' );
178 }
179 $max = $wgImageLimits[$sizeSel];
180 $maxWidth = $max[0];
181 $maxHeight = $max[1];
182 $sk = $wgUser->getSkin();
183
184 if ( $this->img->exists() ) {
185 # image
186 $page = $wgRequest->getIntOrNull( 'page' );
187 if ( ! is_null( $page ) ) {
188 $this->img->selectPage( $page );
189 } else {
190 $page = 1;
191 }
192 $width = $this->img->getWidth();
193 $height = $this->img->getHeight();
194 $showLink = false;
195
196 if ( $this->img->allowInlineDisplay() and $width and $height) {
197 # image
198
199 # "Download high res version" link below the image
200 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
201
202 # We'll show a thumbnail of this image
203 if ( $width > $maxWidth || $height > $maxHeight ) {
204 # Calculate the thumbnail size.
205 # First case, the limiting factor is the width, not the height.
206 if ( $width / $height >= $maxWidth / $maxHeight ) {
207 $height = round( $height * $maxWidth / $width);
208 $width = $maxWidth;
209 # Note that $height <= $maxHeight now.
210 } else {
211 $newwidth = floor( $width * $maxHeight / $height);
212 $height = round( $height * $newwidth / $width );
213 $width = $newwidth;
214 # Note that $height <= $maxHeight now, but might not be identical
215 # because of rounding.
216 }
217
218 if( $wgUseImageResize ) {
219 $thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );
220 if ( $thumbnail == null ) {
221 $url = $this->img->getViewURL();
222 } else {
223 $url = $thumbnail->getURL();
224 }
225 } else {
226 # No resize ability? Show the full image, but scale
227 # it down in the browser so it fits on the page.
228 $url = $this->img->getViewURL();
229 }
230 $anchoropen = "<a href=\"{$full_url}\">";
231 $anchorclose = "</a><br />";
232 if( $this->img->mustRender() ) {
233 $showLink = true;
234 } else {
235 $anchorclose .= "\n$anchoropen{$msg}</a>";
236 }
237 } else {
238 $url = $this->img->getViewURL();
239 $showLink = true;
240 }
241
242 if ( $this->img->isMultipage() ) {
243 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
244 }
245
246 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
247 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
248 htmlspecialchars( $this->img->getTitle()->getPrefixedText() ).'" />' . $anchorclose . '</div>' );
249
250 if ( $this->img->isMultipage() ) {
251 $count = $this->img->pageCount();
252
253 if ( $page > 1 ) {
254 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
255 $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
256 $this->img->selectPage( $page - 1 );
257 $thumb1 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
258 } else {
259 $thumb1 = '';
260 }
261
262 if ( $page < $count ) {
263 $label = wfMsg( 'imgmultipagenext' );
264 $this->img->selectPage( $page + 1 );
265 $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
266 $thumb2 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
267 } else {
268 $thumb2 = '';
269 }
270
271 $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl( '' ) . '" method="GET" onchange="document.pageselector.submit();">' ;
272 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
273 ' <select id="pageselector" name="page">';
274 for ( $i=1; $i <= $count; $i++ ) {
275 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
276 $i == $page );
277 }
278 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
279 '<input type="submit" value="' .
280 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
281
282 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
283 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
284 }
285 } else {
286 #if direct link is allowed but it's not a renderable image, show an icon.
287 if ($this->img->isSafeFile()) {
288 $icon= $this->img->iconThumb();
289
290 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
291 $icon->toHtml() .
292 '</a></div>' );
293 }
294
295 $showLink = true;
296 }
297
298
299 if ($showLink) {
300 $filename = wfEscapeWikiText( $this->img->getName() );
301 // Hacky workaround: for some reason we use the incorrect MIME type
302 // image/svg for SVG. This should be fixed internally, but at least
303 // make the displayed type right.
304 $mime = $this->img->getMimeType();
305 if ($mime == 'image/svg') $mime = 'image/svg+xml';
306
307 $info = wfMsg( 'fileinfo',
308 ceil($this->img->getSize()/1024.0),
309 $mime );
310
311 global $wgContLang;
312 $dirmark = $wgContLang->getDirMark();
313 if (!$this->img->isSafeFile()) {
314 $warning = wfMsg( 'mediawarning' );
315 $wgOut->addWikiText( <<<END
316 <div class="fullMedia">
317 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
318 <span class="fileInfo"> ($info)</span>
319 </div>
320
321 <div class="mediaWarning">$warning</div>
322 END
323 );
324 } else {
325 $wgOut->addWikiText( <<<END
326 <div class="fullMedia">
327 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
328 </div>
329 END
330 );
331 }
332 }
333
334 if($this->img->fromSharedDirectory) {
335 $this->printSharedImageText();
336 }
337 } else {
338 # Image does not exist
339
340 $title = SpecialPage::getTitleFor( 'Upload' );
341 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
342 'wpDestFile=' . urlencode( $this->img->getName() ) );
343 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
344 }
345 }
346
347 function printSharedImageText() {
348 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
349
350 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
351 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
352 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
353
354 $sk = $wgUser->getSkin();
355 $title = SpecialPage::getTitleFor( 'Upload' );
356 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
357 array( 'wpDestFile' => urlencode( $this->img->getName() )));
358 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
359 }
360 $sharedtext .= "</div>";
361 $wgOut->addHTML($sharedtext);
362
363 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
364 $text = Http::get($url . '?action=render');
365 if ($text)
366 $this->mExtraDescription = $text;
367 }
368 }
369
370 function getUploadUrl() {
371 global $wgServer;
372 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
373 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
374 }
375
376 /**
377 * Print out the various links at the bottom of the image page, e.g. reupload,
378 * external editing (and instructions link) etc.
379 */
380 function uploadLinksBox() {
381 global $wgUser, $wgOut;
382
383 if( $this->img->fromSharedDirectory )
384 return;
385
386 $sk = $wgUser->getSkin();
387
388 $wgOut->addHtml( '<br /><ul>' );
389
390 # "Upload a new version of this file" link
391 if( $wgUser->isAllowed( 'reupload' ) ) {
392 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
393 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
394 }
395
396 # External editing link
397 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
398 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
399
400 $wgOut->addHtml( '</ul>' );
401 }
402
403 function closeShowImage()
404 {
405 # For overloading
406
407 }
408
409 /**
410 * If the page we've just displayed is in the "Image" namespace,
411 * we follow it with an upload history of the image and its usage.
412 */
413 function imageHistory()
414 {
415 global $wgUser, $wgOut, $wgUseExternalEditor;
416
417 $sk = $wgUser->getSkin();
418
419 $line = $this->img->nextHistoryLine();
420
421 if ( $line ) {
422 $list = new ImageHistoryList( $sk );
423 $s = $list->beginImageHistoryList() .
424 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
425 $this->mTitle->getDBkey(), $line->img_user,
426 $line->img_user_text, $line->img_size, $line->img_description,
427 $line->img_width, $line->img_height
428 );
429
430 while ( $line = $this->img->nextHistoryLine() ) {
431 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
432 $line->oi_archive_name, $line->img_user,
433 $line->img_user_text, $line->img_size, $line->img_description,
434 $line->img_width, $line->img_height
435 );
436 }
437 $s .= $list->endImageHistoryList();
438 } else { $s=''; }
439 $wgOut->addHTML( $s );
440
441 # Exist check because we don't want to show this on pages where an image
442 # doesn't exist along with the noimage message, that would suck. -ævar
443 if( $wgUseExternalEditor && $this->img->exists() ) {
444 $this->uploadLinksBox();
445 }
446
447 }
448
449 function imageLinks()
450 {
451 global $wgUser, $wgOut;
452
453 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
454
455 $dbr =& wfGetDB( DB_SLAVE );
456 $page = $dbr->tableName( 'page' );
457 $imagelinks = $dbr->tableName( 'imagelinks' );
458
459 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
460 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
461 $sql = $dbr->limitResult($sql, 500, 0);
462 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
463
464 if ( 0 == $dbr->numRows( $res ) ) {
465 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
466 return;
467 }
468 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
469
470 $sk = $wgUser->getSkin();
471 while ( $s = $dbr->fetchObject( $res ) ) {
472 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
473 $link = $sk->makeKnownLinkObj( $name, "" );
474 $wgOut->addHTML( "<li>{$link}</li>\n" );
475 }
476 $wgOut->addHTML( "</ul>\n" );
477 }
478
479 function delete()
480 {
481 global $wgUser, $wgOut, $wgRequest;
482
483 $confirm = $wgRequest->wasPosted();
484 $reason = $wgRequest->getVal( 'wpReason' );
485 $image = $wgRequest->getVal( 'image' );
486 $oldimage = $wgRequest->getVal( 'oldimage' );
487
488 # Only sysops can delete images. Previously ordinary users could delete
489 # old revisions, but this is no longer the case.
490 if ( !$wgUser->isAllowed('delete') ) {
491 $wgOut->permissionRequired( 'delete' );
492 return;
493 }
494 if ( $wgUser->isBlocked() ) {
495 return $this->blockedIPpage();
496 }
497 if ( wfReadOnly() ) {
498 $wgOut->readOnlyPage();
499 return;
500 }
501
502 # Better double-check that it hasn't been deleted yet!
503 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
504 if ( ( !is_null( $image ) )
505 && ( '' == trim( $image ) ) ) {
506 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
507 return;
508 }
509
510 $this->img = new Image( $this->mTitle );
511
512 # Deleting old images doesn't require confirmation
513 if ( !is_null( $oldimage ) || $confirm ) {
514 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
515 $this->doDelete( $reason );
516 } else {
517 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
518 }
519 return;
520 }
521
522 if ( !is_null( $image ) ) {
523 $q = '&image=' . urlencode( $image );
524 } else if ( !is_null( $oldimage ) ) {
525 $q = '&oldimage=' . urlencode( $oldimage );
526 } else {
527 $q = '';
528 }
529 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
530 }
531
532 /*
533 * Delete an image.
534 * @param $reason User provided reason for deletion.
535 */
536 function doDelete( $reason ) {
537 global $wgOut, $wgRequest;
538
539 $oldimage = $wgRequest->getVal( 'oldimage' );
540
541 if ( !is_null( $oldimage ) ) {
542 if ( strlen( $oldimage ) < 16 ) {
543 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
544 return;
545 }
546 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
547 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
548 return;
549 }
550 if ( !$this->doDeleteOldImage( $oldimage ) ) {
551 return;
552 }
553 $deleted = $oldimage;
554 } else {
555 $ok = $this->img->delete( $reason );
556 if( !$ok ) {
557 # If the deletion operation actually failed, bug out:
558 $wgOut->showFileDeleteError( $this->img->getName() );
559 return;
560 }
561
562 # Image itself is now gone, and database is cleaned.
563 # Now we remove the image description page.
564
565 $article = new Article( $this->mTitle );
566 $article->doDeleteArticle( $reason ); # ignore errors
567
568 $deleted = $this->img->getName();
569 }
570
571 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
572 $wgOut->setRobotpolicy( 'noindex,nofollow' );
573
574 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
575 $text = wfMsg( 'deletedtext', $deleted, $loglink );
576
577 $wgOut->addWikiText( $text );
578
579 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
580 }
581
582 /**
583 * @return success
584 */
585 function doDeleteOldImage( $oldimage )
586 {
587 global $wgOut;
588
589 $ok = $this->img->deleteOld( $oldimage, '' );
590 if( !$ok ) {
591 # If we actually have a file and can't delete it, throw an error.
592 # Something went awry...
593 $wgOut->showFileDeleteError( "$oldimage" );
594 } else {
595 # Log the deletion
596 $log = new LogPage( 'delete' );
597 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
598 }
599 return $ok;
600 }
601
602 function revert() {
603 global $wgOut, $wgRequest, $wgUser;
604
605 $oldimage = $wgRequest->getText( 'oldimage' );
606 if ( strlen( $oldimage ) < 16 ) {
607 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
608 return;
609 }
610 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
611 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
612 return;
613 }
614
615 if ( wfReadOnly() ) {
616 $wgOut->readOnlyPage();
617 return;
618 }
619 if( $wgUser->isAnon() ) {
620 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
621 return;
622 }
623 if ( ! $this->mTitle->userCan( 'edit' ) ) {
624 $wgOut->readOnlyPage( $this->getContent(), true );
625 return;
626 }
627 if ( $wgUser->isBlocked() ) {
628 return $this->blockedIPpage();
629 }
630 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
631 $wgOut->showErrorPage( '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_dir( $dest ) ) wfMkdirParents( $dest );
641 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
642
643 if ( ! is_file( $curfile ) ) {
644 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
645 return;
646 }
647 $oldver = wfTimestampNow() . "!{$name}";
648
649 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
650 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
651 return;
652 }
653 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
654 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
655 return;
656 }
657
658 # Record upload and update metadata cache
659 $img = Image::newFromName( $name );
660 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
661
662 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
663 $wgOut->setRobotpolicy( 'noindex,nofollow' );
664 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
665
666 $descTitle = $img->getTitle();
667 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
668 }
669
670 function blockedIPpage() {
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 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
683 $update->doUpdate();
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 */
696 class ImageHistoryList {
697 function ImageHistoryList( &$skin ) {
698 $this->skin =& $skin;
699 }
700
701 function beginImageHistoryList() {
702 $s = "\n" .
703 Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'imghistory' ) ) .
704 "\n<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 = wfMsgHtml( 'deleteimg' );
718 $delall = wfMsgHtml( 'deleteimgcompletely' );
719 $cur = wfMsgHtml( '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->userCan( 'edit' ) ) {
736 $token = urlencode( $wgUser->editToken( $img ) );
737 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
738 wfMsgHtml( '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 = wfMsgHtml( 'revertimg' );
748 $dlink = $del;
749 }
750 }
751
752 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
753 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
754 $wgLang->formatNum( $size ) );
755 $widthheight = wfMsgHtml( 'widthheight', $width, $height );
756 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
757
758 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
759
760 $s .= $this->skin->commentBlock( $description, $wgTitle );
761 $s .= "</li>\n";
762 return $s;
763 }
764
765 }
766
767
768 ?>