Direction mark between the image file name and its size in the image page, to prevent...
[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 require_once( 'Image.php' );
13
14 /**
15 * Special handling for image description pages
16 * @package MediaWiki
17 */
18 class ImagePage extends Article {
19
20 /* private */ var $img; // Image object this page is shown for
21 var $mExtraDescription = false;
22
23 /**
24 * Handler for action=render
25 * Include body text only; none of the image extras
26 */
27 function render() {
28 global $wgOut;
29 $wgOut->setArticleBodyOnly( true );
30 $wgOut->addSecondaryWikitext( $this->getContent() );
31 }
32
33 function view() {
34 global $wgOut, $wgShowEXIF;
35
36 $this->img = new Image( $this->mTitle );
37
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;
45 }
46
47 if ($this->img->exists())
48 $wgOut->addHTML($this->showTOC($showmeta));
49
50 $this->openShowImage();
51
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();
61 }
62
63 # Show shared description, if needed
64 if( $this->mExtraDescription ) {
65 $fol = wfMsg( 'shareddescriptionfollows' );
66 if( $fol != '-' ) {
67 $wgOut->addWikiText( $fol );
68 }
69 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
70 }
71
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" );
84 }
85 } else {
86 Article::view();
87 }
88 }
89
90 /**
91 * Create the TOC
92 *
93 * @access private
94 *
95 * @param bool $metadata Whether or not to show the metadata link
96 * @return string
97 */
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;
107 }
108
109 /**
110 * Make a table with metadata to be shown in the output page.
111 *
112 * @access private
113 *
114 * @param array $exif The array containing the EXIF data
115 * @return string
116 */
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';
127 }
128 $r .= "|- class=\"$class\"\n";
129 $r .= "!| $msg\n";
130 $r .= "|| $v\n";
131 }
132 $r .= '|}';
133 return $r;
134 }
135
136 /**
137 * Get a list of EXIF metadata items which should be displayed when
138 * the metadata table is collapsed.
139 *
140 * @return array of strings
141 * @access private
142 */
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];
149 }
150 }
151 return $fields;
152 }
153
154 /**
155 * Overloading Article's getContent method.
156 *
157 * Omit noarticletext if sharedupload; text will be fetched from the
158 * shared upload server if possible.
159 */
160 function getContent() {
161 if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
162 return '';
163 }
164 return Article::getContent();
165 }
166
167 function openShowImage() {
168 global $wgOut, $wgUser, $wgImageLimits, $wgRequest;
169 global $wgUseImageResize, $wgGenerateThumbnailOnParse;
170
171 $full_url = $this->img->getURL();
172 $anchoropen = '';
173 $anchorclose = '';
174
175 if( $wgUser->getOption( 'imagesize' ) == '' ) {
176 $sizeSel = User::getDefaultOption( 'imagesize' );
177 } else {
178 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
179 }
180 if( !isset( $wgImageLimits[$sizeSel] ) ) {
181 $sizeSel = User::getDefaultOption( 'imagesize' );
182 }
183 $max = $wgImageLimits[$sizeSel];
184 $maxWidth = $max[0];
185 $maxHeight = $max[1];
186 $sk = $wgUser->getSkin();
187
188 if ( $this->img->exists() ) {
189 # image
190 $width = $this->img->getWidth();
191 $height = $this->img->getHeight();
192 $showLink = false;
193
194 if ( $this->img->allowInlineDisplay() and $width and $height) {
195 # image
196
197 # "Download high res version" link below the image
198 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
199
200 # We'll show a thumbnail of this image
201 if ( $width > $maxWidth || $height > $maxHeight ) {
202 # Calculate the thumbnail size.
203 # First case, the limiting factor is the width, not the height.
204 if ( $width / $height >= $maxWidth / $maxHeight ) {
205 $height = round( $height * $maxWidth / $width);
206 $width = $maxWidth;
207 # Note that $height <= $maxHeight now.
208 } else {
209 $newwidth = floor( $width * $maxHeight / $height);
210 $height = round( $height * $newwidth / $width );
211 $width = $newwidth;
212 # Note that $height <= $maxHeight now, but might not be identical
213 # because of rounding.
214 }
215
216 if( $wgUseImageResize ) {
217 $thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );
218 if ( $thumbnail == null ) {
219 $url = $this->img->getViewURL();
220 } else {
221 $url = $thumbnail->getURL();
222 }
223 } else {
224 # No resize ability? Show the full image, but scale
225 # it down in the browser so it fits on the page.
226 $url = $this->img->getViewURL();
227 }
228 $anchoropen = "<a href=\"{$full_url}\">";
229 $anchorclose = "</a><br />";
230 if( $this->img->mustRender() ) {
231 $showLink = true;
232 } else {
233 $anchorclose .= "\n$anchoropen{$msg}</a>";
234 }
235 } else {
236 $url = $this->img->getViewURL();
237 $showLink = true;
238 }
239 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
240 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
241 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
242 } else {
243 #if direct link is allowed but it's not a renderable image, show an icon.
244 if ($this->img->isSafeFile()) {
245 $icon= $this->img->iconThumb();
246
247 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
248 $icon->toHtml() .
249 '</a></div>' );
250 }
251
252 $showLink = true;
253 }
254
255
256 if ($showLink) {
257 $filename = wfEscapeWikiText( $this->img->getName() );
258 $info = wfMsg( 'fileinfo',
259 ceil($this->img->getSize()/1024.0),
260 $this->img->getMimeType() );
261
262 global $wgContLang;
263 $dirmark = $wgContLang->getDirMark();
264 if (!$this->img->isSafeFile()) {
265 $warning = wfMsg( 'mediawarning' );
266 $wgOut->addWikiText( <<<END
267 <div class="fullMedia">
268 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
269 <span class="fileInfo"> ($info)</span>
270 </div>
271
272 <div class="mediaWarning">$warning</div>
273 END
274 );
275 } else {
276 $wgOut->addWikiText( <<<END
277 <div class="fullMedia">
278 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
279 </div>
280 END
281 );
282 }
283 }
284
285 if($this->img->fromSharedDirectory) {
286 $this->printSharedImageText();
287 }
288 } else {
289 # Image does not exist
290
291 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
292 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
293 'wpDestFile=' . urlencode( $this->img->getName() ) );
294 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
295 }
296 }
297
298 function printSharedImageText() {
299 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
300
301 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
302 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
303 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
304
305 $sk = $wgUser->getSkin();
306 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
307 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
308 array( 'wpDestFile' => urlencode( $this->img->getName() )));
309 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
310 }
311 $sharedtext .= "</div>";
312 $wgOut->addHTML($sharedtext);
313
314 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
315 require_once("HttpFunctions.php");
316 $ur = ini_set('allow_url_fopen', true);
317 $text = wfGetHTTP($url . '?action=render');
318 ini_set('allow_url_fopen', $ur);
319 if ($text)
320 $this->mExtraDescription = $text;
321 }
322 }
323
324 function getUploadUrl() {
325 global $wgServer;
326 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
327 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
328 }
329
330 /**
331 * Print out the various links at the bottom of the image page, e.g. reupload,
332 * external editing (and instructions link) etc.
333 */
334 function uploadLinksBox() {
335 global $wgUser, $wgOut;
336
337 if( $this->img->fromSharedDirectory )
338 return;
339
340 $sk = $wgUser->getSkin();
341
342 $wgOut->addHtml( '<br /><ul>' );
343
344 # "Upload a new version of this file" link
345 if( $wgUser->isAllowed( 'reupload' ) ) {
346 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
347 $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
348 }
349
350 # External editing link
351 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
352 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
353
354 $wgOut->addHtml( '</ul>' );
355 }
356
357 function closeShowImage()
358 {
359 # For overloading
360
361 }
362
363 /**
364 * If the page we've just displayed is in the "Image" namespace,
365 * we follow it with an upload history of the image and its usage.
366 */
367 function imageHistory()
368 {
369 global $wgUser, $wgOut, $wgUseExternalEditor;
370
371 $sk = $wgUser->getSkin();
372
373 $line = $this->img->nextHistoryLine();
374
375 if ( $line ) {
376 $list =& new ImageHistoryList( $sk );
377 $s = $list->beginImageHistoryList() .
378 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
379 $this->mTitle->getDBkey(), $line->img_user,
380 $line->img_user_text, $line->img_size, $line->img_description,
381 $line->img_width, $line->img_height
382 );
383
384 while ( $line = $this->img->nextHistoryLine() ) {
385 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
386 $line->oi_archive_name, $line->img_user,
387 $line->img_user_text, $line->img_size, $line->img_description,
388 $line->img_width, $line->img_height
389 );
390 }
391 $s .= $list->endImageHistoryList();
392 } else { $s=''; }
393 $wgOut->addHTML( $s );
394
395 # Exist check because we don't want to show this on pages where an image
396 # doesn't exist along with the noimage message, that would suck. -ævar
397 if( $wgUseExternalEditor && $this->img->exists() ) {
398 $this->uploadLinksBox();
399 }
400
401 }
402
403 function imageLinks()
404 {
405 global $wgUser, $wgOut;
406
407 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
408
409 $dbr =& wfGetDB( DB_SLAVE );
410 $page = $dbr->tableName( 'page' );
411 $imagelinks = $dbr->tableName( 'imagelinks' );
412
413 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
414 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
415 $sql = $dbr->limitResult($sql, 500, 0);
416 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
417
418 if ( 0 == $dbr->numRows( $res ) ) {
419 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
420 return;
421 }
422 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
423
424 $sk = $wgUser->getSkin();
425 while ( $s = $dbr->fetchObject( $res ) ) {
426 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
427 $link = $sk->makeKnownLinkObj( $name, "" );
428 $wgOut->addHTML( "<li>{$link}</li>\n" );
429 }
430 $wgOut->addHTML( "</ul>\n" );
431 }
432
433 function delete()
434 {
435 global $wgUser, $wgOut, $wgRequest;
436
437 $confirm = $wgRequest->wasPosted();
438 $image = $wgRequest->getVal( 'image' );
439 $oldimage = $wgRequest->getVal( 'oldimage' );
440
441 # Only sysops can delete images. Previously ordinary users could delete
442 # old revisions, but this is no longer the case.
443 if ( !$wgUser->isAllowed('delete') ) {
444 $wgOut->sysopRequired();
445 return;
446 }
447 if ( $wgUser->isBlocked() ) {
448 return $this->blockedIPpage();
449 }
450 if ( wfReadOnly() ) {
451 $wgOut->readOnlyPage();
452 return;
453 }
454
455 # Better double-check that it hasn't been deleted yet!
456 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
457 if ( ( !is_null( $image ) )
458 && ( '' == trim( $image ) ) ) {
459 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
460 return;
461 }
462
463 $this->img = new Image( $this->mTitle );
464
465 # Deleting old images doesn't require confirmation
466 if ( !is_null( $oldimage ) || $confirm ) {
467 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
468 $this->doDelete();
469 } else {
470 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
471 }
472 return;
473 }
474
475 if ( !is_null( $image ) ) {
476 $q = '&image=' . urlencode( $image );
477 } else if ( !is_null( $oldimage ) ) {
478 $q = '&oldimage=' . urlencode( $oldimage );
479 } else {
480 $q = '';
481 }
482 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
483 }
484
485 function doDelete() {
486 global $wgOut, $wgRequest, $wgUseSquid;
487 global $wgPostCommitUpdateList;
488
489 $fname = 'ImagePage::doDelete';
490
491 $reason = $wgRequest->getVal( 'wpReason' );
492 $oldimage = $wgRequest->getVal( 'oldimage' );
493
494 $dbw =& wfGetDB( DB_MASTER );
495
496 if ( !is_null( $oldimage ) ) {
497 if ( strlen( $oldimage ) < 16 ) {
498 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
499 return;
500 }
501 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
502 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
503 return;
504 }
505 if ( !$this->doDeleteOldImage( $oldimage ) ) {
506 return;
507 }
508 $deleted = $oldimage;
509 } else {
510 $ok = $this->img->delete( $reason );
511 if( !$ok ) {
512 # If the deletion operation actually failed, bug out:
513 $wgOut->showFileDeleteError( $this->img->getName() );
514 return;
515 }
516
517 # Image itself is now gone, and database is cleaned.
518 # Now we remove the image description page.
519
520 $article = new Article( $this->mTitle );
521 $article->doDeleteArticle( $reason ); # ignore errors
522
523 $deleted = $this->img->getName();
524 }
525
526 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
527 $wgOut->setRobotpolicy( 'noindex,nofollow' );
528
529 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
530 $text = wfMsg( 'deletedtext', $deleted, $loglink );
531
532 $wgOut->addWikiText( $text );
533
534 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
535 }
536
537 /**
538 * @return success
539 */
540 function doDeleteOldImage( $oldimage )
541 {
542 global $wgOut;
543
544 $ok = $this->img->deleteOld( $oldimage, '' );
545 if( !$ok ) {
546 # If we actually have a file and can't delete it, throw an error.
547 # Something went awry...
548 $wgOut->showFileDeleteError( "$oldimage" );
549 } else {
550 # Log the deletion
551 $log = new LogPage( 'delete' );
552 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
553 }
554 return $ok;
555 }
556
557 function revert() {
558 global $wgOut, $wgRequest, $wgUser;
559
560 $oldimage = $wgRequest->getText( 'oldimage' );
561 if ( strlen( $oldimage ) < 16 ) {
562 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
563 return;
564 }
565 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
566 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
567 return;
568 }
569
570 if ( wfReadOnly() ) {
571 $wgOut->readOnlyPage();
572 return;
573 }
574 if( $wgUser->isAnon() ) {
575 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
576 return;
577 }
578 if ( ! $this->mTitle->userCanEdit() ) {
579 $wgOut->sysopRequired();
580 return;
581 }
582 if ( $wgUser->isBlocked() ) {
583 return $this->blockedIPpage();
584 }
585 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
586 $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
587 return;
588 }
589 $name = substr( $oldimage, 15 );
590
591 $dest = wfImageDir( $name );
592 $archive = wfImageArchiveDir( $name );
593 $curfile = "{$dest}/{$name}";
594
595 if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
596 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
597
598 if ( ! is_file( $curfile ) ) {
599 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
600 return;
601 }
602 $oldver = wfTimestampNow() . "!{$name}";
603
604 $dbr =& wfGetDB( DB_SLAVE );
605 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
606
607 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
608 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
609 return;
610 }
611 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
612 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
613 return;
614 }
615
616 # Record upload and update metadata cache
617 $img = Image::newFromName( $name );
618 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
619
620 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
621 $wgOut->setRobotpolicy( 'noindex,nofollow' );
622 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
623
624 $descTitle = $img->getTitle();
625 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
626 }
627
628 function blockedIPpage() {
629 $edit = new EditPage( $this );
630 return $edit->blockedIPpage();
631 }
632
633 /**
634 * Override handling of action=purge
635 */
636 function doPurge() {
637 $this->img = new Image( $this->mTitle );
638 if( $this->img->exists() ) {
639 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
640 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
641 $update->doUpdate();
642 $this->img->purgeCache();
643 } else {
644 wfDebug( "ImagePage::doPurge no image\n" );
645 }
646 parent::doPurge();
647 }
648
649 }
650
651 /**
652 * @todo document
653 * @package MediaWiki
654 */
655 class ImageHistoryList {
656 function ImageHistoryList( &$skin ) {
657 $this->skin =& $skin;
658 }
659
660 function beginImageHistoryList() {
661 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
662 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
663 return $s;
664 }
665
666 function endImageHistoryList() {
667 $s = "</ul>\n";
668 return $s;
669 }
670
671 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
672 global $wgUser, $wgLang, $wgTitle, $wgContLang;
673
674 $datetime = $wgLang->timeanddate( $timestamp, true );
675 $del = wfMsg( 'deleteimg' );
676 $delall = wfMsg( 'deleteimgcompletely' );
677 $cur = wfMsg( 'cur' );
678
679 if ( $iscur ) {
680 $url = Image::imageUrl( $img );
681 $rlink = $cur;
682 if ( $wgUser->isAllowed('delete') ) {
683 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
684 '&action=delete' );
685 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
686
687 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
688 } else {
689 $dlink = $del;
690 }
691 } else {
692 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
693 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
694 $token = urlencode( $wgUser->editToken( $img ) );
695 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
696 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
697 urlencode( $img ) . "&wpEditToken=$token" );
698 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
699 $del, 'action=delete&oldimage=' . urlencode( $img ) .
700 "&wpEditToken=$token" );
701 } else {
702 # Having live active links for non-logged in users
703 # means that bots and spiders crawling our site can
704 # inadvertently change content. Baaaad idea.
705 $rlink = wfMsg( 'revertimg' );
706 $dlink = $del;
707 }
708 }
709
710 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
711 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
712 $wgLang->formatNum( $size ) );
713 $widthheight = wfMsg( 'widthheight', $width, $height );
714 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
715
716 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
717
718 $s .= $this->skin->commentBlock( $description, $wgTitle );
719 $s .= "</li>\n";
720 return $s;
721 }
722
723 }
724
725
726 ?>