102ae49ea332f7d0ce3114c26f30c958e59417f2
[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 // Hacky workaround: for some reason we use the incorrect MIME type
304 // image/svg for SVG. This should be fixed internally, but at least
305 // make the displayed type right.
306 $mime = $this->img->getMimeType();
307 if ($mime == 'image/svg') $mime = 'image/svg+xml';
308
309 $info = wfMsg( 'fileinfo',
310 ceil($this->img->getSize()/1024.0),
311 $mime );
312
313 global $wgContLang;
314 $dirmark = $wgContLang->getDirMark();
315 if (!$this->img->isSafeFile()) {
316 $warning = wfMsg( 'mediawarning' );
317 $wgOut->addWikiText( <<<END
318 <div class="fullMedia">
319 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
320 <span class="fileInfo"> ($info)</span>
321 </div>
322
323 <div class="mediaWarning">$warning</div>
324 END
325 );
326 } else {
327 $wgOut->addWikiText( <<<END
328 <div class="fullMedia">
329 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
330 </div>
331 END
332 );
333 }
334 }
335
336 if($this->img->fromSharedDirectory) {
337 $this->printSharedImageText();
338 }
339 } else {
340 # Image does not exist
341
342 $title = SpecialPage::getTitleFor( 'Upload' );
343 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
344 'wpDestFile=' . urlencode( $this->img->getName() ) );
345 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
346 }
347 }
348
349 function printSharedImageText() {
350 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
351
352 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
353 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
354 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
355
356 $sk = $wgUser->getSkin();
357 $title = SpecialPage::getTitleFor( 'Upload' );
358 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
359 array( 'wpDestFile' => urlencode( $this->img->getName() )));
360 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
361 }
362 $sharedtext .= "</div>";
363 $wgOut->addHTML($sharedtext);
364
365 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
366 $text = Http::get($url . '?action=render');
367 if ($text)
368 $this->mExtraDescription = $text;
369 }
370 }
371
372 function getUploadUrl() {
373 global $wgServer;
374 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
375 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
376 }
377
378 /**
379 * Print out the various links at the bottom of the image page, e.g. reupload,
380 * external editing (and instructions link) etc.
381 */
382 function uploadLinksBox() {
383 global $wgUser, $wgOut;
384
385 if( $this->img->fromSharedDirectory )
386 return;
387
388 $sk = $wgUser->getSkin();
389
390 $wgOut->addHtml( '<br /><ul>' );
391
392 # "Upload a new version of this file" link
393 if( $wgUser->isAllowed( 'reupload' ) ) {
394 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
395 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
396 }
397
398 # External editing link
399 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
400 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
401
402 $wgOut->addHtml( '</ul>' );
403 }
404
405 function closeShowImage()
406 {
407 # For overloading
408
409 }
410
411 /**
412 * If the page we've just displayed is in the "Image" namespace,
413 * we follow it with an upload history of the image and its usage.
414 */
415 function imageHistory()
416 {
417 global $wgUser, $wgOut, $wgUseExternalEditor;
418
419 $sk = $wgUser->getSkin();
420
421 $line = $this->img->nextHistoryLine();
422
423 if ( $line ) {
424 $list = new ImageHistoryList( $sk );
425 $s = $list->beginImageHistoryList() .
426 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
427 $this->mTitle->getDBkey(), $line->img_user,
428 $line->img_user_text, $line->img_size, $line->img_description,
429 $line->img_width, $line->img_height
430 );
431
432 while ( $line = $this->img->nextHistoryLine() ) {
433 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
434 $line->oi_archive_name, $line->img_user,
435 $line->img_user_text, $line->img_size, $line->img_description,
436 $line->img_width, $line->img_height
437 );
438 }
439 $s .= $list->endImageHistoryList();
440 } else { $s=''; }
441 $wgOut->addHTML( $s );
442
443 # Exist check because we don't want to show this on pages where an image
444 # doesn't exist along with the noimage message, that would suck. -ævar
445 if( $wgUseExternalEditor && $this->img->exists() ) {
446 $this->uploadLinksBox();
447 }
448
449 }
450
451 function imageLinks()
452 {
453 global $wgUser, $wgOut;
454
455 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
456
457 $dbr =& wfGetDB( DB_SLAVE );
458 $page = $dbr->tableName( 'page' );
459 $imagelinks = $dbr->tableName( 'imagelinks' );
460
461 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
462 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
463 $sql = $dbr->limitResult($sql, 500, 0);
464 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
465
466 if ( 0 == $dbr->numRows( $res ) ) {
467 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
468 return;
469 }
470 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
471
472 $sk = $wgUser->getSkin();
473 while ( $s = $dbr->fetchObject( $res ) ) {
474 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
475 $link = $sk->makeKnownLinkObj( $name, "" );
476 $wgOut->addHTML( "<li>{$link}</li>\n" );
477 }
478 $wgOut->addHTML( "</ul>\n" );
479 }
480
481 function delete()
482 {
483 global $wgUser, $wgOut, $wgRequest;
484
485 $confirm = $wgRequest->wasPosted();
486 $reason = $wgRequest->getVal( 'wpReason' );
487 $image = $wgRequest->getVal( 'image' );
488 $oldimage = $wgRequest->getVal( 'oldimage' );
489
490 # Only sysops can delete images. Previously ordinary users could delete
491 # old revisions, but this is no longer the case.
492 if ( !$wgUser->isAllowed('delete') ) {
493 $wgOut->permissionRequired( 'delete' );
494 return;
495 }
496 if ( $wgUser->isBlocked() ) {
497 return $this->blockedIPpage();
498 }
499 if ( wfReadOnly() ) {
500 $wgOut->readOnlyPage();
501 return;
502 }
503
504 # Better double-check that it hasn't been deleted yet!
505 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
506 if ( ( !is_null( $image ) )
507 && ( '' == trim( $image ) ) ) {
508 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
509 return;
510 }
511
512 $this->img = new Image( $this->mTitle );
513
514 # Deleting old images doesn't require confirmation
515 if ( !is_null( $oldimage ) || $confirm ) {
516 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
517 $this->doDelete( $reason );
518 } else {
519 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
520 }
521 return;
522 }
523
524 if ( !is_null( $image ) ) {
525 $q = '&image=' . urlencode( $image );
526 } else if ( !is_null( $oldimage ) ) {
527 $q = '&oldimage=' . urlencode( $oldimage );
528 } else {
529 $q = '';
530 }
531 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
532 }
533
534 /*
535 * Delete an image.
536 * @param $reason User provided reason for deletion.
537 */
538 function doDelete( $reason ) {
539 global $wgOut, $wgRequest, $wgUseSquid;
540 global $wgPostCommitUpdateList;
541
542 $fname = 'ImagePage::doDelete';
543
544 $oldimage = $wgRequest->getVal( 'oldimage' );
545
546 $dbw =& wfGetDB( DB_MASTER );
547
548 if ( !is_null( $oldimage ) ) {
549 if ( strlen( $oldimage ) < 16 ) {
550 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
551 return;
552 }
553 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
554 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
555 return;
556 }
557 if ( !$this->doDeleteOldImage( $oldimage ) ) {
558 return;
559 }
560 $deleted = $oldimage;
561 } else {
562 $ok = $this->img->delete( $reason );
563 if( !$ok ) {
564 # If the deletion operation actually failed, bug out:
565 $wgOut->showFileDeleteError( $this->img->getName() );
566 return;
567 }
568
569 # Image itself is now gone, and database is cleaned.
570 # Now we remove the image description page.
571
572 $article = new Article( $this->mTitle );
573 $article->doDeleteArticle( $reason ); # ignore errors
574
575 $deleted = $this->img->getName();
576 }
577
578 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
579 $wgOut->setRobotpolicy( 'noindex,nofollow' );
580
581 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
582 $text = wfMsg( 'deletedtext', $deleted, $loglink );
583
584 $wgOut->addWikiText( $text );
585
586 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
587 }
588
589 /**
590 * @return success
591 */
592 function doDeleteOldImage( $oldimage )
593 {
594 global $wgOut;
595
596 $ok = $this->img->deleteOld( $oldimage, '' );
597 if( !$ok ) {
598 # If we actually have a file and can't delete it, throw an error.
599 # Something went awry...
600 $wgOut->showFileDeleteError( "$oldimage" );
601 } else {
602 # Log the deletion
603 $log = new LogPage( 'delete' );
604 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
605 }
606 return $ok;
607 }
608
609 function revert() {
610 global $wgOut, $wgRequest, $wgUser;
611
612 $oldimage = $wgRequest->getText( 'oldimage' );
613 if ( strlen( $oldimage ) < 16 ) {
614 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
615 return;
616 }
617 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
618 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
619 return;
620 }
621
622 if ( wfReadOnly() ) {
623 $wgOut->readOnlyPage();
624 return;
625 }
626 if( $wgUser->isAnon() ) {
627 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
628 return;
629 }
630 if ( ! $this->mTitle->userCanEdit() ) {
631 $wgOut->readOnlyPage( $this->getContent(), true );
632 return;
633 }
634 if ( $wgUser->isBlocked() ) {
635 return $this->blockedIPpage();
636 }
637 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
638 $wgOut->showErrorPage( '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_dir( $dest ) ) wfMkdirParents( $dest );
648 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
649
650 if ( ! is_file( $curfile ) ) {
651 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
652 return;
653 }
654 $oldver = wfTimestampNow() . "!{$name}";
655
656 $dbr =& wfGetDB( DB_SLAVE );
657 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
658
659 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
660 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
661 return;
662 }
663 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
664 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
665 return;
666 }
667
668 # Record upload and update metadata cache
669 $img = Image::newFromName( $name );
670 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
671
672 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
673 $wgOut->setRobotpolicy( 'noindex,nofollow' );
674 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
675
676 $descTitle = $img->getTitle();
677 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
678 }
679
680 function blockedIPpage() {
681 $edit = new EditPage( $this );
682 return $edit->blockedIPpage();
683 }
684
685 /**
686 * Override handling of action=purge
687 */
688 function doPurge() {
689 $this->img = new Image( $this->mTitle );
690 if( $this->img->exists() ) {
691 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
692 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
693 $update->doUpdate();
694 $this->img->purgeCache();
695 } else {
696 wfDebug( "ImagePage::doPurge no image\n" );
697 }
698 parent::doPurge();
699 }
700
701 }
702
703 /**
704 * @todo document
705 * @package MediaWiki
706 */
707 class ImageHistoryList {
708 function ImageHistoryList( &$skin ) {
709 $this->skin =& $skin;
710 }
711
712 function beginImageHistoryList() {
713 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
714 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
715 return $s;
716 }
717
718 function endImageHistoryList() {
719 $s = "</ul>\n";
720 return $s;
721 }
722
723 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
724 global $wgUser, $wgLang, $wgTitle, $wgContLang;
725
726 $datetime = $wgLang->timeanddate( $timestamp, true );
727 $del = wfMsg( 'deleteimg' );
728 $delall = wfMsg( 'deleteimgcompletely' );
729 $cur = wfMsg( 'cur' );
730
731 if ( $iscur ) {
732 $url = Image::imageUrl( $img );
733 $rlink = $cur;
734 if ( $wgUser->isAllowed('delete') ) {
735 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
736 '&action=delete' );
737 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
738
739 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
740 } else {
741 $dlink = $del;
742 }
743 } else {
744 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
745 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
746 $token = urlencode( $wgUser->editToken( $img ) );
747 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
748 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
749 urlencode( $img ) . "&wpEditToken=$token" );
750 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
751 $del, 'action=delete&oldimage=' . urlencode( $img ) .
752 "&wpEditToken=$token" );
753 } else {
754 # Having live active links for non-logged in users
755 # means that bots and spiders crawling our site can
756 # inadvertently change content. Baaaad idea.
757 $rlink = wfMsg( 'revertimg' );
758 $dlink = $del;
759 }
760 }
761
762 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
763 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
764 $wgLang->formatNum( $size ) );
765 $widthheight = wfMsg( 'widthheight', $width, $height );
766 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
767
768 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
769
770 $s .= $this->skin->commentBlock( $description, $wgTitle );
771 $s .= "</li>\n";
772 return $s;
773 }
774
775 }
776
777
778 ?>