* Use the real file link instead of the default-size rasterized version for
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 *
8 */
9 if( !defined( 'MEDIAWIKI' ) )
10 die();
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 function render() {
24 global $wgOut;
25 $wgOut->setArticleBodyOnly(true);
26 $wgOut->addWikitext($this->getContent(true));
27 }
28
29 function view() {
30 global $wgUseExternalEditor, $wgOut, $wgShowEXIF;
31
32 $this->img = new Image( $this->mTitle );
33
34 if( $this->mTitle->getNamespace() == NS_IMAGE ) {
35 if ($wgShowEXIF && $this->img->exists()) {
36 $exif = $this->img->getExifData();
37 $showmeta = count($exif) ? true : false;
38 } else {
39 $exif = false;
40 $showmeta = false;
41 }
42
43 if ($this->img->exists())
44 $wgOut->addHTML($this->showTOC($showmeta));
45
46 $this->openShowImage();
47 if ($exif)
48 $wgOut->addWikiText($this->makeMetadataTable($exif));
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 $wgOut->addMetaTags();
59 $this->viewUpdates();
60 }
61
62 if ($this->mExtraDescription) {
63 $fol = wfMsg('shareddescriptionfollows');
64 if ($fol != '-')
65 $wgOut->addWikiText(wfMsg('shareddescriptionfollows'));
66 $wgOut->addHTML($this->mExtraDescription);
67 }
68
69 $this->closeShowImage();
70 $this->imageHistory();
71 $this->imageLinks();
72 } else {
73 Article::view();
74 }
75 }
76
77 /**
78 * Create the TOC
79 *
80 * @access private
81 *
82 * @param bool $metadata Whether or not to show the metadata link
83 * @return string
84 */
85 function showTOC( $metadata ) {
86 global $wgLang;
87 $r = '<ul id="filetoc">
88 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>' .
89 ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
90 <li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
91 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>
92 </ul>';
93 return $r;
94 }
95
96 /**
97 * Make a table with metadata to be shown in the output page.
98 *
99 * @access private
100 *
101 * @param array $exif The array containing the EXIF data
102 * @return string
103 */
104 function makeMetadataTable( $exif ) {
105 $r = "{| class=metadata align=right width=250px\n";
106 $r .= '|+ id=metadata | '. htmlspecialchars( wfMsgHtml( 'metadata' ) ) . "\n";
107 foreach( $exif as $k => $v ) {
108 $tag = strtolower( $k );
109 $r .= "! class=$tag |" . wfMsg( "exif-$tag" ) . "\n";
110 $r .= "| class=$tag |" . htmlspecialchars( $v ) . "\n";
111 $r .= "|-\n";
112 }
113 return substr($r, 0, -3) . '|}';
114 }
115
116 /**
117 * Overloading Article's getContent method.
118 * Omit noarticletext if sharedupload
119 *
120 * @param $noredir If true, do not follow redirects
121 */
122 function getContent( $noredir )
123 {
124 if ( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
125 return '';
126 }
127 return Article::getContent( $noredir );
128 }
129
130 function openShowImage()
131 {
132 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
133 $wgUseImageResize, $wgRepositoryBaseUrl,
134 $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions;
135 $full_url = $this->img->getURL();
136 $anchoropen = '';
137 $anchorclose = '';
138
139 if( $wgUser->getOption( 'imagesize' ) == '' ) {
140 $sizeSel = User::getDefaultOption( 'imagesize' );
141 } else {
142 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
143 }
144 if( !isset( $wgImageLimits[$sizeSel] ) ) {
145 $sizeSel = User::getDefaultOption( 'imagesize' );
146 }
147 $max = $wgImageLimits[$sizeSel];
148 $maxWidth = $max[0];
149 $maxHeight = $max[1];
150 $sk = $wgUser->getSkin();
151
152 if ( $this->img->exists() ) {
153 # image
154 $width = $this->img->getWidth();
155 $height = $this->img->getHeight();
156 $showLink = false;
157
158 if ( $this->img->allowInlineDisplay() and $width and $height) {
159 # image
160
161 # "Download high res version" link below the image
162 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
163 if ( $width > $maxWidth ) {
164 $height = floor( $height * $maxWidth / $width );
165 $width = $maxWidth;
166 }
167 if ( $height > $maxHeight ) {
168 $width = floor( $width * $maxHeight / $height );
169 $height = $maxHeight;
170 }
171 if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) {
172 if( $wgUseImageResize ) {
173 $thumbnail = $this->img->getThumbnail( $width );
174 if ( $thumbnail == null ) {
175 $url = $img->getViewURL();
176 } else {
177 $url = $thumbnail->getURL();
178 }
179 } else {
180 # No resize ability? Show the full image, but scale
181 # it down in the browser so it fits on the page.
182 $url = $img->getViewURL();
183 }
184 $anchoropen = "<a href=\"{$full_url}\">";
185 $anchorclose = "</a><br />";
186 if( $this->img->mustRender() ) {
187 $showLink = true;
188 } else {
189 $anchorclose .= "\n$anchoropen{$msg}</a>";
190 }
191 } else {
192 $url = $this->img->getViewURL();
193 $showLink = true;
194 }
195 $wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .
196 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
197 htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );
198 } else {
199 #if direct link is allowed but it's not a renderable image, show an icon.
200 if ($this->img->isSafeFile()) {
201 $icon= $this->img->iconThumb();
202
203 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
204 $icon->toHtml() .
205 '</a></div>' );
206 }
207
208 $showLink = true;
209 }
210
211
212 if ($showLink) {
213 $filename = wfEscapeWikiText( $this->img->getName() );
214 $info = wfMsg( 'fileinfo',
215 ceil($this->img->getSize()/1024.0),
216 $this->img->getMimeType() );
217
218 if (!$this->img->isSafeFile()) {
219 $warning = wfMsg( 'mediawarning' );
220 $wgOut->addWikiText( <<<END
221 <div class="fullMedia">
222 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
223 <span class="fileInfo"> ($info)</span>
224 </div>
225
226 <div class="mediaWarning">$warning</div>
227 END
228 );
229 } else {
230 $wgOut->addWikiText( <<<END
231 <div class="fullMedia">
232 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
233 </div>
234 END
235 );
236 }
237 }
238
239 if($this->img->fromSharedDirectory) {
240 $this->printSharedImageText();
241 }
242 } else {
243 # Image does not exist
244
245 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
246 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
247 'wpDestFile=' . urlencode( $this->img->getName() ) );
248 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
249 }
250 }
251
252 function printSharedImageText() {
253 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
254
255 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
256 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
257 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
258
259 $sk = $wgUser->getSkin();
260 $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
261 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
262 array( 'wpDestFile' => urlencode( $this->img->getName() )));
263 $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
264 }
265 $sharedtext .= "</div>";
266 $wgOut->addHTML($sharedtext);
267
268 if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
269 require_once("HttpFunctions.php");
270 $ur = ini_set('allow_url_fopen', true);
271 $text = wfGetHTTP($url . '?action=render');
272 ini_set('allow_url_fopen', $ur);
273 if ($text)
274 $this->mExtraDescription = $text;
275 }
276 }
277
278 function getUploadUrl() {
279 global $wgServer;
280 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
281 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
282 }
283
284
285 function uploadLinksBox()
286 {
287 global $wgUser, $wgOut;
288
289 if ($this->img->fromSharedDirectory)
290 return;
291
292 $sk = $wgUser->getSkin();
293 $wgOut->addHTML( '<br /><ul>' );
294 if( $wgUser->isAllowed( 'reupload' ) ) {
295 $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
296 }
297 $wgOut->addHTML( '<li>' );
298 $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
299 wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
300 $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
301 $wgOut->addHTML( '</li></ul>' );
302 }
303
304 function closeShowImage()
305 {
306 # For overloading
307
308 }
309
310 /**
311 * If the page we've just displayed is in the "Image" namespace,
312 * we follow it with an upload history of the image and its usage.
313 */
314 function imageHistory()
315 {
316 global $wgUser, $wgOut, $wgUseExternalEditor;
317
318 $sk = $wgUser->getSkin();
319
320 $line = $this->img->nextHistoryLine();
321
322 if ( $line ) {
323 $list =& new ImageHistoryList( $sk );
324 $s = $list->beginImageHistoryList() .
325 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
326 $this->mTitle->getDBkey(), $line->img_user,
327 $line->img_user_text, $line->img_size, $line->img_description );
328
329 while ( $line = $this->img->nextHistoryLine() ) {
330 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
331 $line->oi_archive_name, $line->img_user,
332 $line->img_user_text, $line->img_size, $line->img_description );
333 }
334 $s .= $list->endImageHistoryList();
335 } else { $s=''; }
336 $wgOut->addHTML( $s );
337
338 # Exist check because we don't want to show this on pages where an image
339 # doesn't exist along with the noimage message, that would suck. -ævar
340 if( $wgUseExternalEditor && $this->img->exists() ) {
341 $this->uploadLinksBox();
342 }
343
344 }
345
346 function imageLinks()
347 {
348 global $wgUser, $wgOut;
349
350 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
351
352 $dbr =& wfGetDB( DB_SLAVE );
353 $page = $dbr->tableName( 'page' );
354 $imagelinks = $dbr->tableName( 'imagelinks' );
355
356 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
357 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
358 $sql = $dbr->limitResult($sql, 500, 0);
359 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
360
361 if ( 0 == $dbr->numRows( $res ) ) {
362 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
363 return;
364 }
365 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
366
367 $sk = $wgUser->getSkin();
368 while ( $s = $dbr->fetchObject( $res ) ) {
369 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
370 $link = $sk->makeKnownLinkObj( $name, "" );
371 $wgOut->addHTML( "<li>{$link}</li>\n" );
372 }
373 $wgOut->addHTML( "</ul>\n" );
374 }
375
376 function delete()
377 {
378 global $wgUser, $wgOut, $wgRequest;
379
380 $confirm = $wgRequest->getBool( 'wpConfirmB' );
381 $image = $wgRequest->getVal( 'image' );
382 $oldimage = $wgRequest->getVal( 'oldimage' );
383
384 # Only sysops can delete images. Previously ordinary users could delete
385 # old revisions, but this is no longer the case.
386 if ( !$wgUser->isAllowed('delete') ) {
387 $wgOut->sysopRequired();
388 return;
389 }
390 if ( $wgUser->isBlocked() ) {
391 return $this->blockedIPpage();
392 }
393 if ( wfReadOnly() ) {
394 $wgOut->readOnlyPage();
395 return;
396 }
397
398 # Better double-check that it hasn't been deleted yet!
399 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
400 if ( ( !is_null( $image ) )
401 && ( '' == trim( $image ) ) ) {
402 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
403 return;
404 }
405
406 $this->img = new Image( $this->mTitle );
407
408 # Deleting old images doesn't require confirmation
409 if ( !is_null( $oldimage ) || $confirm ) {
410 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
411 $this->doDelete();
412 } else {
413 $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
414 }
415 return;
416 }
417
418 if ( !is_null( $image ) ) {
419 $q = '&image=' . urlencode( $image );
420 } else if ( !is_null( $oldimage ) ) {
421 $q = '&oldimage=' . urlencode( $oldimage );
422 } else {
423 $q = '';
424 }
425 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
426 }
427
428 function doDelete()
429 {
430 global $wgOut, $wgUser, $wgContLang, $wgRequest;
431 global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList;
432 $fname = 'ImagePage::doDelete';
433
434 $reason = $wgRequest->getVal( 'wpReason' );
435 $oldimage = $wgRequest->getVal( 'oldimage' );
436
437 $dbw =& wfGetDB( DB_MASTER );
438
439 if ( !is_null( $oldimage ) ) {
440 if ( strlen( $oldimage ) < 16 ) {
441 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
442 return;
443 }
444 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
445 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
446 return;
447 }
448
449 # Invalidate description page cache
450 $this->mTitle->invalidateCache();
451
452 # Squid purging
453 if ( $wgUseSquid ) {
454 $urlArr = Array(
455 $wgInternalServer.wfImageArchiveUrl( $oldimage ),
456 $wgInternalServer.$this->mTitle->getFullURL()
457 );
458 wfPurgeSquidServers($urlArr);
459 }
460 $this->doDeleteOldImage( $oldimage );
461 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
462 $deleted = $oldimage;
463 } else {
464 $image = $this->mTitle->getDBkey();
465 $dest = wfImageDir( $image );
466 $archive = wfImageDir( $image );
467
468 # Delete the image file if it exists; due to sync problems
469 # or manual trimming sometimes the file will be missing.
470 $targetFile = "{$dest}/{$image}";
471 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
472 # If the deletion operation actually failed, bug out:
473 $wgOut->fileDeleteError( $targetFile );
474 return;
475 }
476 $dbw->delete( 'image', array( 'img_name' => $image ) );
477 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
478
479 # Purge archive URLs from the squid
480 $urlArr = Array();
481 while ( $s = $dbw->fetchObject( $res ) ) {
482 $this->doDeleteOldImage( $s->oi_archive_name );
483 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
484 }
485
486 # And also the HTML of all pages using this image
487 $linksTo = $this->img->getLinksTo();
488 if ( $wgUseSquid ) {
489 $u = SquidUpdate::newFromTitles( $linksTo, $urlArr );
490 array_push( $wgPostCommitUpdateList, $u );
491 }
492
493 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
494
495 # Image itself is now gone, and database is cleaned.
496 # Now we remove the image description page.
497
498 $article = new Article( $this->mTitle );
499 $article->doDeleteArticle( $reason ); # ignore errors
500
501 # Invalidate parser cache and client cache for pages using this image
502 # This is left until relatively late to reduce lock time
503 Title::touchArray( $linksTo );
504
505 /* Delete thumbnails and refresh image metadata cache */
506 $this->img->purgeCache();
507
508
509 $deleted = $image;
510 }
511
512 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
513 $wgOut->setRobotpolicy( 'noindex,nofollow' );
514
515 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
516 $text = wfMsg( 'deletedtext', $deleted, $loglink );
517
518 $wgOut->addWikiText( $text );
519
520 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
521 }
522
523 function doDeleteOldImage( $oldimage )
524 {
525 global $wgOut;
526
527 $name = substr( $oldimage, 15 );
528 $archive = wfImageArchiveDir( $name );
529
530 # Delete the image if it exists. Sometimes the file will be missing
531 # due to manual intervention or weird sync problems; treat that
532 # condition gracefully and continue to delete the database entry.
533 # Also some records may end up with an empty oi_archive_name field
534 # if the original file was missing when a new upload was made;
535 # don't try to delete the directory then!
536 #
537 $targetFile = "{$archive}/{$oldimage}";
538 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
539 # If we actually have a file and can't delete it, throw an error.
540 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
541 } else {
542 # Log the deletion
543 $log = new LogPage( 'delete' );
544 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
545 }
546 }
547
548 function revert()
549 {
550 global $wgOut, $wgRequest, $wgUser;
551 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
552
553 $oldimage = $wgRequest->getText( 'oldimage' );
554 if ( strlen( $oldimage ) < 16 ) {
555 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
556 return;
557 }
558 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
559 $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
560 return;
561 }
562
563 if ( wfReadOnly() ) {
564 $wgOut->readOnlyPage();
565 return;
566 }
567 if( $wgUser->isAnon() ) {
568 $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
569 return;
570 }
571 if ( ! $this->mTitle->userCanEdit() ) {
572 $wgOut->sysopRequired();
573 return;
574 }
575 if ( $wgUser->isBlocked() ) {
576 return $this->blockedIPpage();
577 }
578 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
579 $wgOut->errorpage( 'internalerror', 'sessionfailure' );
580 return;
581 }
582 $name = substr( $oldimage, 15 );
583
584 $dest = wfImageDir( $name );
585 $archive = wfImageArchiveDir( $name );
586 $curfile = "{$dest}/{$name}";
587
588 if ( ! is_file( $curfile ) ) {
589 $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
590 return;
591 }
592 $oldver = wfTimestampNow() . "!{$name}";
593
594 $dbr =& wfGetDB( DB_SLAVE );
595 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
596
597 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
598 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
599 return;
600 }
601 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
602 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
603 }
604
605 # Record upload and update metadata cache
606 $img = Image::newFromName( $name );
607 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
608
609 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
610 $wgOut->setRobotpolicy( 'noindex,nofollow' );
611 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
612
613 $descTitle = $img->getTitle();
614 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
615 }
616
617 function blockedIPpage() {
618 require_once( 'EditPage.php' );
619 $edit = new EditPage( $this );
620 return $edit->blockedIPpage();
621 }
622
623 }
624
625 /**
626 * @todo document
627 * @package MediaWiki
628 */
629 class ImageHistoryList {
630 function ImageHistoryList( &$skin ) {
631 $this->skin =& $skin;
632 }
633
634 function beginImageHistoryList() {
635 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
636 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
637 return $s;
638 }
639
640 function endImageHistoryList() {
641 $s = "</ul>\n";
642 return $s;
643 }
644
645 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
646 global $wgUser, $wgLang, $wgContLang, $wgTitle;
647
648 $datetime = $wgLang->timeanddate( $timestamp, true );
649 $del = wfMsg( 'deleteimg' );
650 $delall = wfMsg( 'deleteimgcompletely' );
651 $cur = wfMsg( 'cur' );
652
653 if ( $iscur ) {
654 $url = Image::imageUrl( $img );
655 $rlink = $cur;
656 if ( $wgUser->isAllowed('delete') ) {
657 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
658 '&action=delete' );
659 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
660
661 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
662 } else {
663 $dlink = $del;
664 }
665 } else {
666 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
667 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
668 $token = urlencode( $wgUser->editToken( $img ) );
669 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
670 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
671 urlencode( $img ) . "&wpEditToken=$token" );
672 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
673 $del, 'action=delete&oldimage=' . urlencode( $img ) .
674 "&wpEditToken=$token" );
675 } else {
676 # Having live active links for non-logged in users
677 # means that bots and spiders crawling our site can
678 # inadvertently change content. Baaaad idea.
679 $rlink = wfMsg( 'revertimg' );
680 $dlink = $del;
681 }
682 }
683 if ( 0 == $user ) {
684 $userlink = $usertext;
685 } else {
686 $userlink = $this->skin->makeLinkObj(
687 Title::makeTitle( NS_USER, $usertext ),
688 $usertext );
689 }
690 $nbytes = wfMsg( 'nbytes', $size );
691 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
692
693 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
694 . " . . {$userlink} ({$nbytes})";
695
696 $s .= $this->skin->commentBlock( $description, $wgTitle );
697 $s .= "</li>\n";
698 return $s;
699 }
700
701 }
702
703
704 ?>