Fix for DynamicPageList, which registers a mixed-case tag name.
[mediawiki.git] / includes / ImagePage.php
blob9b91c8785e91fdb570ed7ad89648852fbf642587
1 <?php
2 /**
3 * @package MediaWiki
4 */
6 /**
8 */
9 if( !defined( 'MEDIAWIKI' ) )
10 die( -1 );
12 require_once( 'Image.php' );
14 /**
15 * Special handling for image description pages
16 * @package MediaWiki
18 class ImagePage extends Article {
20 /* private */ var $img; // Image object this page is shown for
21 var $mExtraDescription = false;
23 /**
24 * Handler for action=render
25 * Include body text only; none of the image extras
27 function render() {
28 global $wgOut;
29 $wgOut->setArticleBodyOnly( true );
30 $wgOut->addSecondaryWikitext( $this->getContent() );
33 function view() {
34 global $wgOut, $wgShowEXIF;
36 $this->img = new Image( $this->mTitle );
38 if( $this->mTitle->getNamespace() == NS_IMAGE ) {
39 if ($wgShowEXIF && $this->img->exists()) {
40 $exif = $this->img->getExifData();
41 $showmeta = count($exif) ? true : false;
42 } else {
43 $exif = false;
44 $showmeta = false;
47 if ($this->img->exists())
48 $wgOut->addHTML($this->showTOC($showmeta));
50 $this->openShowImage();
52 # No need to display noarticletext, we use our own message, output in openShowImage()
53 if( $this->getID() ) {
54 Article::view();
55 } else {
56 # Just need to set the right headers
57 $wgOut->setArticleFlag( true );
58 $wgOut->setRobotpolicy( 'index,follow' );
59 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
60 $this->viewUpdates();
63 # Show shared description, if needed
64 if( $this->mExtraDescription ) {
65 $fol = wfMsg( 'shareddescriptionfollows' );
66 if( $fol != '-' ) {
67 $wgOut->addWikiText( $fol );
69 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
72 $this->closeShowImage();
73 $this->imageHistory();
74 $this->imageLinks();
75 if( $exif ) {
76 global $wgStylePath;
77 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
78 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
79 $wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
80 $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
81 $wgOut->addHTML(
82 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .
83 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
85 } else {
86 Article::view();
90 /**
91 * Create the TOC
93 * @access private
95 * @param bool $metadata Whether or not to show the metadata link
96 * @return string
98 function showTOC( $metadata ) {
99 global $wgLang;
100 $r = '<ul id="filetoc">
101 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
102 <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
103 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
104 ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
105 </ul>';
106 return $r;
110 * Make a table with metadata to be shown in the output page.
112 * @access private
114 * @param array $exif The array containing the EXIF data
115 * @return string
117 function makeMetadataTable( $exif ) {
118 $r = wfMsg( 'metadata-help' ) . "\n\n";
119 $r .= "{| id=mw_metadata class=mw_metadata\n";
120 $visibleFields = $this->visibleMetadataFields();
121 foreach( $exif as $k => $v ) {
122 $tag = strtolower( $k );
123 $msg = wfMsg( "exif-$tag" );
124 $class = "exif-$tag";
125 if( !in_array( $tag, $visibleFields ) ) {
126 $class .= ' collapsable';
128 $r .= "|- class=\"$class\"\n";
129 $r .= "!| $msg\n";
130 $r .= "|| $v\n";
132 $r .= '|}';
133 return $r;
137 * Get a list of EXIF metadata items which should be displayed when
138 * the metadata table is collapsed.
140 * @return array of strings
141 * @access private
143 function visibleMetadataFields() {
144 $fields = array();
145 $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
146 foreach( $lines as $line ) {
147 if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
148 $fields[] = $matches[1];
151 return $fields;
155 * Overloading Article's getContent method.
157 * Omit noarticletext if sharedupload; text will be fetched from the
158 * shared upload server if possible.
160 function getContent() {
161 if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
162 return '';
164 return Article::getContent();
167 function openShowImage() {
168 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
170 $full_url = $this->img->getURL();
171 $anchoropen = '';
172 $anchorclose = '';
174 if( $wgUser->getOption( 'imagesize' ) == '' ) {
175 $sizeSel = User::getDefaultOption( 'imagesize' );
176 } else {
177 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
179 if( !isset( $wgImageLimits[$sizeSel] ) ) {
180 $sizeSel = User::getDefaultOption( 'imagesize' );
182 $max = $wgImageLimits[$sizeSel];
183 $maxWidth = $max[0];
184 $maxHeight = $max[1];
185 $sk = $wgUser->getSkin();
187 if ( $this->img->exists() ) {
188 # image
189 $width = $this->img->getWidth();
190 $height = $this->img->getHeight();
191 $showLink = false;
193 if ( $this->img->allowInlineDisplay() and $width and $height) {
194 # image
196 # "Download high res version" link below the image
197 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
199 # We'll show a thumbnail of this image
200 if ( $width > $maxWidth || $height > $maxHeight ) {
201 # Calculate the thumbnail size.
202 # First case, the limiting factor is the width, not the height.
203 if ( $width / $height >= $maxWidth / $maxHeight ) {
204 $height = round( $height * $maxWidth / $width);
205 $width = $maxWidth;
206 # Note that $height <= $maxHeight now.
207 } else {
208 $newwidth = floor( $width * $maxHeight / $height);
209 $height = round( $height * $newwidth / $width );
210 $width = $newwidth;
211 # Note that $height <= $maxHeight now, but might not be identical
212 # because of rounding.
215 if( $wgUseImageResize ) {
216 $thumbnail = $this->img->getThumbnail( $width );
217 if ( $thumbnail == null ) {
218 $url = $this->img->getViewURL();
219 } else {
220 $url = $thumbnail->getURL();
222 } else {
223 # No resize ability? Show the full image, but scale
224 # it down in the browser so it fits on the page.
225 $url = $this->img->getViewURL();
227 $anchoropen = "<a href=\"{$full_url}\">";
228 $anchorclose = "</a><br />";
229 if( $this->img->mustRender() ) {
230 $showLink = true;
231 } else {
232 $anchorclose .= "\n$anchoropen{$msg}</a>";
234 } else {
235 $url = $this->img->getViewURL();
236 $showLink = true;
238 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
239 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
240 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
241 } else {
242 #if direct link is allowed but it's not a renderable image, show an icon.
243 if ($this->img->isSafeFile()) {
244 $icon= $this->img->iconThumb();
246 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
247 $icon->toHtml() .
248 '</a></div>' );
251 $showLink = true;
255 if ($showLink) {
256 $filename = wfEscapeWikiText( $this->img->getName() );
257 $info = wfMsg( 'fileinfo',
258 ceil($this->img->getSize()/1024.0),
259 $this->img->getMimeType() );
261 if (!$this->img->isSafeFile()) {
262 $warning = wfMsg( 'mediawarning' );
263 $wgOut->addWikiText( <<<END
264 <div class="fullMedia">
265 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
266 <span class="fileInfo"> ($info)</span>
267 </div>
269 <div class="mediaWarning">$warning</div>
272 } else {
273 $wgOut->addWikiText( <<<END
274 <div class="fullMedia">
275 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
276 </div>
282 if($this->img->fromSharedDirectory) {
283 $this->printSharedImageText();
285 } else {
286 # Image does not exist
288 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
289 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
290 'wpDestFile=' . urlencode( $this->img->getName() ) );
291 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
295 function printSharedImageText() {
296 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
298 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
299 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
300 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
302 $sk = $wgUser->getSkin();
303 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
304 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
305 array( 'wpDestFile' => urlencode( $this->img->getName() )));
306 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
308 $sharedtext .= "</div>";
309 $wgOut->addHTML($sharedtext);
311 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
312 require_once("HttpFunctions.php");
313 $ur = ini_set('allow_url_fopen', true);
314 $text = wfGetHTTP($url . '?action=render');
315 ini_set('allow_url_fopen', $ur);
316 if ($text)
317 $this->mExtraDescription = $text;
321 function getUploadUrl() {
322 global $wgServer;
323 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
324 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
328 * Print out the various links at the bottom of the image page, e.g. reupload,
329 * external editing (and instructions link) etc.
331 function uploadLinksBox() {
332 global $wgUser, $wgOut;
334 if( $this->img->fromSharedDirectory )
335 return;
337 $sk = $wgUser->getSkin();
339 $wgOut->addHtml( '<br /><ul>' );
341 # "Upload a new version of this file" link
342 if( $wgUser->isAllowed( 'reupload' ) ) {
343 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
344 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
347 # External editing link
348 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
349 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
351 $wgOut->addHtml( '</ul>' );
354 function closeShowImage()
356 # For overloading
361 * If the page we've just displayed is in the "Image" namespace,
362 * we follow it with an upload history of the image and its usage.
364 function imageHistory()
366 global $wgUser, $wgOut, $wgUseExternalEditor;
368 $sk = $wgUser->getSkin();
370 $line = $this->img->nextHistoryLine();
372 if ( $line ) {
373 $list =& new ImageHistoryList( $sk );
374 $s = $list->beginImageHistoryList() .
375 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
376 $this->mTitle->getDBkey(), $line->img_user,
377 $line->img_user_text, $line->img_size, $line->img_description,
378 $line->img_width, $line->img_height
381 while ( $line = $this->img->nextHistoryLine() ) {
382 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
383 $line->oi_archive_name, $line->img_user,
384 $line->img_user_text, $line->img_size, $line->img_description,
385 $line->img_width, $line->img_height
388 $s .= $list->endImageHistoryList();
389 } else { $s=''; }
390 $wgOut->addHTML( $s );
392 # Exist check because we don't want to show this on pages where an image
393 # doesn't exist along with the noimage message, that would suck. -ævar
394 if( $wgUseExternalEditor && $this->img->exists() ) {
395 $this->uploadLinksBox();
400 function imageLinks()
402 global $wgUser, $wgOut;
404 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
406 $dbr =& wfGetDB( DB_SLAVE );
407 $page = $dbr->tableName( 'page' );
408 $imagelinks = $dbr->tableName( 'imagelinks' );
410 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
411 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
412 $sql = $dbr->limitResult($sql, 500, 0);
413 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
415 if ( 0 == $dbr->numRows( $res ) ) {
416 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
417 return;
419 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
421 $sk = $wgUser->getSkin();
422 while ( $s = $dbr->fetchObject( $res ) ) {
423 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
424 $link = $sk->makeKnownLinkObj( $name, "" );
425 $wgOut->addHTML( "<li>{$link}</li>\n" );
427 $wgOut->addHTML( "</ul>\n" );
430 function delete()
432 global $wgUser, $wgOut, $wgRequest;
434 $confirm = $wgRequest->wasPosted();
435 $image = $wgRequest->getVal( 'image' );
436 $oldimage = $wgRequest->getVal( 'oldimage' );
438 # Only sysops can delete images. Previously ordinary users could delete
439 # old revisions, but this is no longer the case.
440 if ( !$wgUser->isAllowed('delete') ) {
441 $wgOut->sysopRequired();
442 return;
444 if ( $wgUser->isBlocked() ) {
445 return $this->blockedIPpage();
447 if ( wfReadOnly() ) {
448 $wgOut->readOnlyPage();
449 return;
452 # Better double-check that it hasn't been deleted yet!
453 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
454 if ( ( !is_null( $image ) )
455 && ( '' == trim( $image ) ) ) {
456 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
457 return;
460 $this->img = new Image( $this->mTitle );
462 # Deleting old images doesn't require confirmation
463 if ( !is_null( $oldimage ) || $confirm ) {
464 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
465 $this->doDelete();
466 } else {
467 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
469 return;
472 if ( !is_null( $image ) ) {
473 $q = '&image=' . urlencode( $image );
474 } else if ( !is_null( $oldimage ) ) {
475 $q = '&oldimage=' . urlencode( $oldimage );
476 } else {
477 $q = '';
479 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
482 function doDelete() {
483 global $wgOut, $wgRequest, $wgUseSquid;
484 global $wgPostCommitUpdateList;
486 $fname = 'ImagePage::doDelete';
488 $reason = $wgRequest->getVal( 'wpReason' );
489 $oldimage = $wgRequest->getVal( 'oldimage' );
491 $dbw =& wfGetDB( DB_MASTER );
493 if ( !is_null( $oldimage ) ) {
494 if ( strlen( $oldimage ) < 16 ) {
495 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
496 return;
498 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
499 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
500 return;
503 # Invalidate description page cache
504 $this->mTitle->invalidateCache();
506 # Squid purging
507 if ( $wgUseSquid ) {
508 $urlArr = array(
509 wfImageArchiveUrl( $oldimage ),
510 $this->mTitle->getInternalURL()
512 wfPurgeSquidServers($urlArr);
514 $this->doDeleteOldImage( $oldimage );
515 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
516 $deleted = $oldimage;
517 } else {
518 $image = $this->mTitle->getDBkey();
519 $dest = wfImageDir( $image );
520 $archive = wfImageDir( $image );
522 # Delete the image file if it exists; due to sync problems
523 # or manual trimming sometimes the file will be missing.
524 $targetFile = "{$dest}/{$image}";
525 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
526 # If the deletion operation actually failed, bug out:
527 $wgOut->fileDeleteError( $targetFile );
528 return;
530 $dbw->delete( 'image', array( 'img_name' => $image ) );
532 if ( $dbw->affectedRows() ) {
533 # Update site_stats
534 $site_stats = $dbw->tableName( 'site_stats' );
535 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", $fname );
539 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
541 # Purge archive URLs from the squid
542 $urlArr = Array();
543 while ( $s = $dbw->fetchObject( $res ) ) {
544 $this->doDeleteOldImage( $s->oi_archive_name );
545 $urlArr[] = wfImageArchiveUrl( $s->oi_archive_name );
548 # And also the HTML of all pages using this image
549 $linksTo = $this->img->getLinksTo();
550 if ( $wgUseSquid ) {
551 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
552 array_push( $wgPostCommitUpdateList, $u );
555 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
557 # Image itself is now gone, and database is cleaned.
558 # Now we remove the image description page.
560 $article = new Article( $this->mTitle );
561 $article->doDeleteArticle( $reason ); # ignore errors
563 # Invalidate parser cache and client cache for pages using this image
564 # This is left until relatively late to reduce lock time
565 Title::touchArray( $linksTo );
567 /* Delete thumbnails and refresh image metadata cache */
568 $this->img->purgeCache();
570 $deleted = $image;
573 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
574 $wgOut->setRobotpolicy( 'noindex,nofollow' );
576 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
577 $text = wfMsg( 'deletedtext', $deleted, $loglink );
579 $wgOut->addWikiText( $text );
581 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
584 function doDeleteOldImage( $oldimage )
586 global $wgOut;
588 $name = substr( $oldimage, 15 );
589 $archive = wfImageArchiveDir( $name );
591 # Delete the image if it exists. Sometimes the file will be missing
592 # due to manual intervention or weird sync problems; treat that
593 # condition gracefully and continue to delete the database entry.
594 # Also some records may end up with an empty oi_archive_name field
595 # if the original file was missing when a new upload was made;
596 # don't try to delete the directory then!
598 $targetFile = "{$archive}/{$oldimage}";
599 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
600 # If we actually have a file and can't delete it, throw an error.
601 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
602 } else {
603 # Log the deletion
604 $log = new LogPage( 'delete' );
605 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
609 function revert() {
610 global $wgOut, $wgRequest, $wgUser;
612 $oldimage = $wgRequest->getText( 'oldimage' );
613 if ( strlen( $oldimage ) < 16 ) {
614 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
615 return;
617 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
618 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
619 return;
622 if ( wfReadOnly() ) {
623 $wgOut->readOnlyPage();
624 return;
626 if( $wgUser->isAnon() ) {
627 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
628 return;
630 if ( ! $this->mTitle->userCanEdit() ) {
631 $wgOut->sysopRequired();
632 return;
634 if ( $wgUser->isBlocked() ) {
635 return $this->blockedIPpage();
637 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
638 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
639 return;
641 $name = substr( $oldimage, 15 );
643 $dest = wfImageDir( $name );
644 $archive = wfImageArchiveDir( $name );
645 $curfile = "{$dest}/{$name}";
647 if ( ! is_file( $curfile ) ) {
648 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
649 return;
651 $oldver = wfTimestampNow() . "!{$name}";
653 $dbr =& wfGetDB( DB_SLAVE );
654 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
656 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
657 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
658 return;
660 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
661 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
664 # Record upload and update metadata cache
665 $img = Image::newFromName( $name );
666 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
668 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
669 $wgOut->setRobotpolicy( 'noindex,nofollow' );
670 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
672 $descTitle = $img->getTitle();
673 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
676 function blockedIPpage() {
677 require_once( 'EditPage.php' );
678 $edit = new EditPage( $this );
679 return $edit->blockedIPpage();
683 * Override handling of action=purge
685 function doPurge() {
686 $this->img = new Image( $this->mTitle );
687 if( $this->img->exists() ) {
688 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
689 $linksTo = $this->img->getLinksTo();
690 Title::touchArray( $linksTo );
691 $this->img->purgeCache();
692 } else {
693 wfDebug( "ImagePage::doPurge no image\n" );
695 parent::doPurge();
701 * @todo document
702 * @package MediaWiki
704 class ImageHistoryList {
705 function ImageHistoryList( &$skin ) {
706 $this->skin =& $skin;
709 function beginImageHistoryList() {
710 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
711 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
712 return $s;
715 function endImageHistoryList() {
716 $s = "</ul>\n";
717 return $s;
720 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
721 global $wgUser, $wgLang, $wgTitle, $wgContLang;
723 $datetime = $wgLang->timeanddate( $timestamp, true );
724 $del = wfMsg( 'deleteimg' );
725 $delall = wfMsg( 'deleteimgcompletely' );
726 $cur = wfMsg( 'cur' );
728 if ( $iscur ) {
729 $url = Image::imageUrl( $img );
730 $rlink = $cur;
731 if ( $wgUser->isAllowed('delete') ) {
732 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
733 '&action=delete' );
734 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
736 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
737 } else {
738 $dlink = $del;
740 } else {
741 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
742 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
743 $token = urlencode( $wgUser->editToken( $img ) );
744 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
745 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
746 urlencode( $img ) . "&wpEditToken=$token" );
747 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
748 $del, 'action=delete&oldimage=' . urlencode( $img ) .
749 "&wpEditToken=$token" );
750 } else {
751 # Having live active links for non-logged in users
752 # means that bots and spiders crawling our site can
753 # inadvertently change content. Baaaad idea.
754 $rlink = wfMsg( 'revertimg' );
755 $dlink = $del;
758 if ( 0 == $user ) {
759 $userlink = $usertext;
760 } else {
761 $userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
762 $usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
763 $userdata = $userlink . ' (' . $usertalk . ')';
765 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
766 $wgLang->formatNum( $size ) );
767 $widthheight = wfMsg( 'widthheight', $width, $height );
768 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
770 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
772 $s .= $this->skin->commentBlock( $description, $wgTitle );
773 $s .= "</li>\n";
774 return $s;