Introduce 'FetchChangesList' hook; see docs/hooks.txt for more information
[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, $wgUseImageResize;
169
170 $full_url = $this->img->getURL();
171 $anchoropen = '';
172 $anchorclose = '';
173
174 if( $wgUser->getOption( 'imagesize' ) == '' ) {
175 $sizeSel = User::getDefaultOption( 'imagesize' );
176 } else {
177 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
178 }
179 if( !isset( $wgImageLimits[$sizeSel] ) ) {
180 $sizeSel = User::getDefaultOption( 'imagesize' );
181 }
182 $max = $wgImageLimits[$sizeSel];
183 $maxWidth = $max[0];
184 $maxHeight = $max[1];
185 $sk = $wgUser->getSkin();
186
187 if ( $this->img->exists() ) {
188 # image
189 $width = $this->img->getWidth();
190 $height = $this->img->getHeight();
191 $showLink = false;
192
193 if ( $this->img->allowInlineDisplay() and $width and $height) {
194 # image
195
196 # "Download high res version" link below the image
197 $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );
198
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.
213 }
214
215 if( $wgUseImageResize ) {
216 $thumbnail = $this->img->getThumbnail( $width );
217 if ( $thumbnail == null ) {
218 $url = $this->img->getViewURL();
219 } else {
220 $url = $thumbnail->getURL();
221 }
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();
226 }
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>";
233 }
234 } else {
235 $url = $this->img->getViewURL();
236 $showLink = true;
237 }
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();
245
246 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
247 $icon->toHtml() .
248 '</a></div>' );
249 }
250
251 $showLink = true;
252 }
253
254
255 if ($showLink) {
256 $filename = wfEscapeWikiText( $this->img->getName() );
257 $info = wfMsg( 'fileinfo',
258 ceil($this->img->getSize()/1024.0),
259 $this->img->getMimeType() );
260
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>
268
269 <div class="mediaWarning">$warning</div>
270 END
271 );
272 } else {
273 $wgOut->addWikiText( <<<END
274 <div class="fullMedia">
275 [[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
276 </div>
277 END
278 );
279 }
280 }
281
282 if($this->img->fromSharedDirectory) {
283 $this->printSharedImageText();
284 }
285 } else {
286 # Image does not exist
287
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 ) );
292 }
293 }
294
295 function printSharedImageText() {
296 global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
297
298 $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
299 $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
300 if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
301
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);
307 }
308 $sharedtext .= "</div>";
309 $wgOut->addHTML($sharedtext);
310
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;
318 }
319 }
320
321 function getUploadUrl() {
322 global $wgServer;
323 $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
324 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
325 }
326
327 /**
328 * Print out the various links at the bottom of the image page, e.g. reupload,
329 * external editing (and instructions link) etc.
330 */
331 function uploadLinksBox() {
332 global $wgUser, $wgOut;
333
334 if( $this->img->fromSharedDirectory )
335 return;
336
337 $sk = $wgUser->getSkin();
338
339 $wgOut->addHtml( '<br /><ul>' );
340
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>" );
345 }
346
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>' );
350
351 $wgOut->addHtml( '</ul>' );
352 }
353
354 function closeShowImage()
355 {
356 # For overloading
357
358 }
359
360 /**
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.
363 */
364 function imageHistory()
365 {
366 global $wgUser, $wgOut, $wgUseExternalEditor;
367
368 $sk = $wgUser->getSkin();
369
370 $line = $this->img->nextHistoryLine();
371
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
379 );
380
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
386 );
387 }
388 $s .= $list->endImageHistoryList();
389 } else { $s=''; }
390 $wgOut->addHTML( $s );
391
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();
396 }
397
398 }
399
400 function imageLinks()
401 {
402 global $wgUser, $wgOut;
403
404 $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
405
406 $dbr =& wfGetDB( DB_SLAVE );
407 $page = $dbr->tableName( 'page' );
408 $imagelinks = $dbr->tableName( 'imagelinks' );
409
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" );
414
415 if ( 0 == $dbr->numRows( $res ) ) {
416 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
417 return;
418 }
419 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
420
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" );
426 }
427 $wgOut->addHTML( "</ul>\n" );
428 }
429
430 function delete()
431 {
432 global $wgUser, $wgOut, $wgRequest;
433
434 $confirm = $wgRequest->wasPosted();
435 $image = $wgRequest->getVal( 'image' );
436 $oldimage = $wgRequest->getVal( 'oldimage' );
437
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;
443 }
444 if ( $wgUser->isBlocked() ) {
445 return $this->blockedIPpage();
446 }
447 if ( wfReadOnly() ) {
448 $wgOut->readOnlyPage();
449 return;
450 }
451
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->showFatalError( wfMsg( 'cannotdelete' ) );
457 return;
458 }
459
460 $this->img = new Image( $this->mTitle );
461
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->showFatalError( wfMsg( 'sessionfailure' ) );
468 }
469 return;
470 }
471
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 = '';
478 }
479 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
480 }
481
482 function doDelete() {
483 global $wgOut, $wgRequest, $wgUseSquid;
484 global $wgPostCommitUpdateList;
485
486 $fname = 'ImagePage::doDelete';
487
488 $reason = $wgRequest->getVal( 'wpReason' );
489 $oldimage = $wgRequest->getVal( 'oldimage' );
490
491 $dbw =& wfGetDB( DB_MASTER );
492
493 if ( !is_null( $oldimage ) ) {
494 if ( strlen( $oldimage ) < 16 ) {
495 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
496 return;
497 }
498 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
499 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
500 return;
501 }
502 if ( !$this->doDeleteOldImage( $oldimage ) ) {
503 return;
504 }
505 $deleted = $oldimage;
506 } else {
507 $ok = $this->img->delete( $reason );
508 if( !$ok ) {
509 # If the deletion operation actually failed, bug out:
510 $wgOut->showFileDeleteError( $this->img->getName() );
511 return;
512 }
513
514 # Image itself is now gone, and database is cleaned.
515 # Now we remove the image description page.
516
517 $article = new Article( $this->mTitle );
518 $article->doDeleteArticle( $reason ); # ignore errors
519
520 $deleted = $this->img->getName();
521 }
522
523 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
524 $wgOut->setRobotpolicy( 'noindex,nofollow' );
525
526 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
527 $text = wfMsg( 'deletedtext', $deleted, $loglink );
528
529 $wgOut->addWikiText( $text );
530
531 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
532 }
533
534 /**
535 * @return success
536 */
537 function doDeleteOldImage( $oldimage )
538 {
539 global $wgOut;
540
541 $ok = $this->img->deleteOld( $oldimage, '' );
542 if( !$ok ) {
543 # If we actually have a file and can't delete it, throw an error.
544 # Something went awry...
545 $wgOut->showFileDeleteError( "$oldimage" );
546 } else {
547 # Log the deletion
548 $log = new LogPage( 'delete' );
549 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
550 }
551 return $ok;
552 }
553
554 function revert() {
555 global $wgOut, $wgRequest, $wgUser;
556
557 $oldimage = $wgRequest->getText( 'oldimage' );
558 if ( strlen( $oldimage ) < 16 ) {
559 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
560 return;
561 }
562 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
563 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
564 return;
565 }
566
567 if ( wfReadOnly() ) {
568 $wgOut->readOnlyPage();
569 return;
570 }
571 if( $wgUser->isAnon() ) {
572 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
573 return;
574 }
575 if ( ! $this->mTitle->userCanEdit() ) {
576 $wgOut->sysopRequired();
577 return;
578 }
579 if ( $wgUser->isBlocked() ) {
580 return $this->blockedIPpage();
581 }
582 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
583 $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
584 return;
585 }
586 $name = substr( $oldimage, 15 );
587
588 $dest = wfImageDir( $name );
589 $archive = wfImageArchiveDir( $name );
590 $curfile = "{$dest}/{$name}";
591
592 if ( ! is_file( $curfile ) ) {
593 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
594 return;
595 }
596 $oldver = wfTimestampNow() . "!{$name}";
597
598 $dbr =& wfGetDB( DB_SLAVE );
599 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
600
601 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
602 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
603 return;
604 }
605 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
606 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
607 return;
608 }
609
610 # Record upload and update metadata cache
611 $img = Image::newFromName( $name );
612 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
613
614 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
615 $wgOut->setRobotpolicy( 'noindex,nofollow' );
616 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
617
618 $descTitle = $img->getTitle();
619 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
620 }
621
622 function blockedIPpage() {
623 $edit = new EditPage( $this );
624 return $edit->blockedIPpage();
625 }
626
627 /**
628 * Override handling of action=purge
629 */
630 function doPurge() {
631 $this->img = new Image( $this->mTitle );
632 if( $this->img->exists() ) {
633 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
634 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
635 $update->doUpdate();
636 $this->img->purgeCache();
637 } else {
638 wfDebug( "ImagePage::doPurge no image\n" );
639 }
640 parent::doPurge();
641 }
642
643 }
644
645 /**
646 * @todo document
647 * @package MediaWiki
648 */
649 class ImageHistoryList {
650 function ImageHistoryList( &$skin ) {
651 $this->skin =& $skin;
652 }
653
654 function beginImageHistoryList() {
655 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
656 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
657 return $s;
658 }
659
660 function endImageHistoryList() {
661 $s = "</ul>\n";
662 return $s;
663 }
664
665 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
666 global $wgUser, $wgLang, $wgTitle, $wgContLang;
667
668 $datetime = $wgLang->timeanddate( $timestamp, true );
669 $del = wfMsg( 'deleteimg' );
670 $delall = wfMsg( 'deleteimgcompletely' );
671 $cur = wfMsg( 'cur' );
672
673 if ( $iscur ) {
674 $url = Image::imageUrl( $img );
675 $rlink = $cur;
676 if ( $wgUser->isAllowed('delete') ) {
677 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
678 '&action=delete' );
679 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
680
681 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
682 } else {
683 $dlink = $del;
684 }
685 } else {
686 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
687 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
688 $token = urlencode( $wgUser->editToken( $img ) );
689 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
690 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
691 urlencode( $img ) . "&wpEditToken=$token" );
692 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
693 $del, 'action=delete&oldimage=' . urlencode( $img ) .
694 "&wpEditToken=$token" );
695 } else {
696 # Having live active links for non-logged in users
697 # means that bots and spiders crawling our site can
698 # inadvertently change content. Baaaad idea.
699 $rlink = wfMsg( 'revertimg' );
700 $dlink = $del;
701 }
702 }
703
704 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
705 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
706 $wgLang->formatNum( $size ) );
707 $widthheight = wfMsg( 'widthheight', $width, $height );
708 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
709
710 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
711
712 $s .= $this->skin->commentBlock( $description, $wgTitle );
713 $s .= "</li>\n";
714 return $s;
715 }
716
717 }
718
719
720 ?>