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