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