Removing the last references to OutputPage::sysopRequired() and OutputPage::developer...
[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 $reason = $wgRequest->getVal( 'wpReason' );
439 $image = $wgRequest->getVal( 'image' );
440 $oldimage = $wgRequest->getVal( 'oldimage' );
441
442 # Only sysops can delete images. Previously ordinary users could delete
443 # old revisions, but this is no longer the case.
444 if ( !$wgUser->isAllowed('delete') ) {
445 $wgOut->permissionRequired( 'delete' );
446 return;
447 }
448 if ( $wgUser->isBlocked() ) {
449 return $this->blockedIPpage();
450 }
451 if ( wfReadOnly() ) {
452 $wgOut->readOnlyPage();
453 return;
454 }
455
456 # Better double-check that it hasn't been deleted yet!
457 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
458 if ( ( !is_null( $image ) )
459 && ( '' == trim( $image ) ) ) {
460 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
461 return;
462 }
463
464 $this->img = new Image( $this->mTitle );
465
466 # Deleting old images doesn't require confirmation
467 if ( !is_null( $oldimage ) || $confirm ) {
468 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
469 $this->doDelete( $reason );
470 } else {
471 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
472 }
473 return;
474 }
475
476 if ( !is_null( $image ) ) {
477 $q = '&image=' . urlencode( $image );
478 } else if ( !is_null( $oldimage ) ) {
479 $q = '&oldimage=' . urlencode( $oldimage );
480 } else {
481 $q = '';
482 }
483 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
484 }
485
486 /*
487 * Delete an image.
488 * @param $reason User provided reason for deletion.
489 */
490 function doDelete( $reason ) {
491 global $wgOut, $wgRequest, $wgUseSquid;
492 global $wgPostCommitUpdateList;
493
494 $fname = 'ImagePage::doDelete';
495
496 $oldimage = $wgRequest->getVal( 'oldimage' );
497
498 $dbw =& wfGetDB( DB_MASTER );
499
500 if ( !is_null( $oldimage ) ) {
501 if ( strlen( $oldimage ) < 16 ) {
502 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
503 return;
504 }
505 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
506 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
507 return;
508 }
509 if ( !$this->doDeleteOldImage( $oldimage ) ) {
510 return;
511 }
512 $deleted = $oldimage;
513 } else {
514 $ok = $this->img->delete( $reason );
515 if( !$ok ) {
516 # If the deletion operation actually failed, bug out:
517 $wgOut->showFileDeleteError( $this->img->getName() );
518 return;
519 }
520
521 # Image itself is now gone, and database is cleaned.
522 # Now we remove the image description page.
523
524 $article = new Article( $this->mTitle );
525 $article->doDeleteArticle( $reason ); # ignore errors
526
527 $deleted = $this->img->getName();
528 }
529
530 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
531 $wgOut->setRobotpolicy( 'noindex,nofollow' );
532
533 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
534 $text = wfMsg( 'deletedtext', $deleted, $loglink );
535
536 $wgOut->addWikiText( $text );
537
538 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
539 }
540
541 /**
542 * @return success
543 */
544 function doDeleteOldImage( $oldimage )
545 {
546 global $wgOut;
547
548 $ok = $this->img->deleteOld( $oldimage, '' );
549 if( !$ok ) {
550 # If we actually have a file and can't delete it, throw an error.
551 # Something went awry...
552 $wgOut->showFileDeleteError( "$oldimage" );
553 } else {
554 # Log the deletion
555 $log = new LogPage( 'delete' );
556 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
557 }
558 return $ok;
559 }
560
561 function revert() {
562 global $wgOut, $wgRequest, $wgUser;
563
564 $oldimage = $wgRequest->getText( 'oldimage' );
565 if ( strlen( $oldimage ) < 16 ) {
566 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
567 return;
568 }
569 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
570 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
571 return;
572 }
573
574 if ( wfReadOnly() ) {
575 $wgOut->readOnlyPage();
576 return;
577 }
578 if( $wgUser->isAnon() ) {
579 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
580 return;
581 }
582 if ( ! $this->mTitle->userCanEdit() ) {
583 $wgOut->readOnlyPage( $this->getContent(), true );
584 return;
585 }
586 if ( $wgUser->isBlocked() ) {
587 return $this->blockedIPpage();
588 }
589 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
590 $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
591 return;
592 }
593 $name = substr( $oldimage, 15 );
594
595 $dest = wfImageDir( $name );
596 $archive = wfImageArchiveDir( $name );
597 $curfile = "{$dest}/{$name}";
598
599 if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
600 if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
601
602 if ( ! is_file( $curfile ) ) {
603 $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
604 return;
605 }
606 $oldver = wfTimestampNow() . "!{$name}";
607
608 $dbr =& wfGetDB( DB_SLAVE );
609 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
610
611 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
612 $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
613 return;
614 }
615 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
616 $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
617 return;
618 }
619
620 # Record upload and update metadata cache
621 $img = Image::newFromName( $name );
622 $img->recordUpload( $oldver, wfMsg( "reverted" ) );
623
624 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
625 $wgOut->setRobotpolicy( 'noindex,nofollow' );
626 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
627
628 $descTitle = $img->getTitle();
629 $wgOut->returnToMain( false, $descTitle->getPrefixedText() );
630 }
631
632 function blockedIPpage() {
633 $edit = new EditPage( $this );
634 return $edit->blockedIPpage();
635 }
636
637 /**
638 * Override handling of action=purge
639 */
640 function doPurge() {
641 $this->img = new Image( $this->mTitle );
642 if( $this->img->exists() ) {
643 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
644 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
645 $update->doUpdate();
646 $this->img->purgeCache();
647 } else {
648 wfDebug( "ImagePage::doPurge no image\n" );
649 }
650 parent::doPurge();
651 }
652
653 }
654
655 /**
656 * @todo document
657 * @package MediaWiki
658 */
659 class ImageHistoryList {
660 function ImageHistoryList( &$skin ) {
661 $this->skin =& $skin;
662 }
663
664 function beginImageHistoryList() {
665 $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
666 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
667 return $s;
668 }
669
670 function endImageHistoryList() {
671 $s = "</ul>\n";
672 return $s;
673 }
674
675 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
676 global $wgUser, $wgLang, $wgTitle, $wgContLang;
677
678 $datetime = $wgLang->timeanddate( $timestamp, true );
679 $del = wfMsg( 'deleteimg' );
680 $delall = wfMsg( 'deleteimgcompletely' );
681 $cur = wfMsg( 'cur' );
682
683 if ( $iscur ) {
684 $url = Image::imageUrl( $img );
685 $rlink = $cur;
686 if ( $wgUser->isAllowed('delete') ) {
687 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
688 '&action=delete' );
689 $style = $this->skin->getInternalLinkAttributes( $link, $delall );
690
691 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
692 } else {
693 $dlink = $del;
694 }
695 } else {
696 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
697 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
698 $token = urlencode( $wgUser->editToken( $img ) );
699 $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
700 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
701 urlencode( $img ) . "&wpEditToken=$token" );
702 $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
703 $del, 'action=delete&oldimage=' . urlencode( $img ) .
704 "&wpEditToken=$token" );
705 } else {
706 # Having live active links for non-logged in users
707 # means that bots and spiders crawling our site can
708 # inadvertently change content. Baaaad idea.
709 $rlink = wfMsg( 'revertimg' );
710 $dlink = $del;
711 }
712 }
713
714 $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
715 $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
716 $wgLang->formatNum( $size ) );
717 $widthheight = wfMsg( 'widthheight', $width, $height );
718 $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
719
720 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
721
722 $s .= $this->skin->commentBlock( $description, $wgTitle );
723 $s .= "</li>\n";
724 return $s;
725 }
726
727 }
728
729
730 ?>