* (bug 10739) Users can now enter comments when reverting files
[lhc/web/wiklou.git] / includes / ImagePage.php
1 <?php
2 /**
3 */
4
5 /**
6 *
7 */
8 if( !defined( 'MEDIAWIKI' ) )
9 die( 1 );
10
11 /**
12 * Special handling for image description pages
13 *
14 * @addtogroup Media
15 */
16 class ImagePage extends Article {
17
18 /* private */ var $img; // Image object this page is shown for
19 var $mExtraDescription = false;
20
21 function __construct( $title ) {
22 parent::__construct( $title );
23 $this->img = wfFindFile( $this->mTitle );
24 if ( !$this->img ) {
25 $this->img = wfLocalFile( $this->mTitle );
26 }
27 }
28
29 /**
30 * Handler for action=render
31 * Include body text only; none of the image extras
32 */
33 function render() {
34 global $wgOut;
35 $wgOut->setArticleBodyOnly( true );
36 $wgOut->addSecondaryWikitext( $this->getContent() );
37 }
38
39 function view() {
40 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
41
42 $diff = $wgRequest->getVal( 'diff' );
43 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
44
45 if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
46 return Article::view();
47
48 if ($wgShowEXIF && $this->img->exists()) {
49 $formattedMetadata = $this->img->formatMetadata();
50 $showmeta = $formattedMetadata !== false;
51 } else {
52 $showmeta = false;
53 }
54
55 if ($this->img->exists())
56 $wgOut->addHTML($this->showTOC($showmeta));
57
58 $this->openShowImage();
59
60 # No need to display noarticletext, we use our own message, output in openShowImage()
61 if ( $this->getID() ) {
62 Article::view();
63 } else {
64 # Just need to set the right headers
65 $wgOut->setArticleFlag( true );
66 $wgOut->setRobotpolicy( 'index,follow' );
67 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
68 $this->viewUpdates();
69 }
70
71 # Show shared description, if needed
72 if ( $this->mExtraDescription ) {
73 $fol = wfMsg( 'shareddescriptionfollows' );
74 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
75 $wgOut->addWikiText( $fol );
76 }
77 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
78 }
79
80 $this->closeShowImage();
81 $this->imageHistory();
82 $this->imageLinks();
83
84 if ( $showmeta ) {
85 global $wgStylePath, $wgStyleVersion;
86 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
87 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
88 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
89 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
90 $wgOut->addHTML(
91 "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
92 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
93 }
94 }
95
96 /**
97 * Create the TOC
98 *
99 * @access private
100 *
101 * @param bool $metadata Whether or not to show the metadata link
102 * @return string
103 */
104 function showTOC( $metadata ) {
105 global $wgLang;
106 $r = '<ul id="filetoc">
107 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
108 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
109 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
110 ($metadata ? ' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
111 </ul>';
112 return $r;
113 }
114
115 /**
116 * Make a table with metadata to be shown in the output page.
117 *
118 * @access private
119 *
120 * @param array $exif The array containing the EXIF data
121 * @return string
122 */
123 function makeMetadataTable( $metadata ) {
124 $r = wfMsg( 'metadata-help' ) . "\n\n";
125 $r .= "{| id=mw_metadata class=mw_metadata\n";
126 foreach ( $metadata as $type => $stuff ) {
127 foreach ( $stuff as $k => $v ) {
128 $class = Sanitizer::escapeId( $v['id'] );
129 if( $type == 'collapsed' ) {
130 $class .= ' collapsable';
131 }
132 $r .= "|- class=\"$class\"\n";
133 $r .= "!| {$v['name']}\n";
134 $r .= "|| {$v['value']}\n";
135 }
136 }
137 $r .= '|}';
138 return $r;
139 }
140
141 /**
142 * Overloading Article's getContent method.
143 *
144 * Omit noarticletext if sharedupload; text will be fetched from the
145 * shared upload server if possible.
146 */
147 function getContent() {
148 if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
149 return '';
150 }
151 return Article::getContent();
152 }
153
154 function openShowImage() {
155 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang;
156
157 $full_url = $this->img->getURL();
158 $linkAttribs = false;
159 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
160 if( !isset( $wgImageLimits[$sizeSel] ) ) {
161 $sizeSel = User::getDefaultOption( 'imagesize' );
162
163 // The user offset might still be incorrect, specially if
164 // $wgImageLimits got changed (see bug #8858).
165 if( !isset( $wgImageLimits[$sizeSel] ) ) {
166 // Default to the first offset in $wgImageLimits
167 $sizeSel = 0;
168 }
169 }
170 $max = $wgImageLimits[$sizeSel];
171 $maxWidth = $max[0];
172 $maxHeight = $max[1];
173 $sk = $wgUser->getSkin();
174
175 if ( $this->img->exists() ) {
176 # image
177 $page = $wgRequest->getIntOrNull( 'page' );
178 if ( is_null( $page ) ) {
179 $params = array();
180 $page = 1;
181 } else {
182 $params = array( 'page' => $page );
183 }
184 $width_orig = $this->img->getWidth();
185 $width = $width_orig;
186 $height_orig = $this->img->getHeight();
187 $height = $height_orig;
188 $mime = $this->img->getMimeType();
189 $showLink = false;
190 $linkAttribs = array( 'href' => $full_url );
191
192 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
193
194 if ( $this->img->allowInlineDisplay() and $width and $height) {
195 # image
196
197 # "Download high res version" link below the image
198 $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
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 $msgbig = wfMsgHtml( 'show-big-image' );
215 $msgsmall = wfMsgExt( 'show-big-image-thumb',
216 array( 'parseinline' ), $width, $height );
217 } else {
218 # Image is small enough to show full size on image page
219 $msgbig = htmlspecialchars( $this->img->getName() );
220 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
221 }
222
223 $params['width'] = $width;
224 $thumbnail = $this->img->transform( $params );
225
226 $anchorclose = "<br />";
227 if( $this->img->mustRender() ) {
228 $showLink = true;
229 } else {
230 $anchorclose .=
231 $msgsmall .
232 '<br />' . Xml::tags( 'a', $linkAttribs, $msgbig ) . ' ' . $msgsize;
233 }
234
235 if ( $this->img->isMultipage() ) {
236 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
237 }
238
239 $imgAttribs = array(
240 'border' => 0,
241 'alt' => $this->img->getTitle()->getPrefixedText()
242 );
243
244 if ( $thumbnail ) {
245 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
246 $thumbnail->toHtml( $imgAttribs, $linkAttribs ) .
247 $anchorclose . '</div>' );
248 }
249
250 if ( $this->img->isMultipage() ) {
251 $count = $this->img->pageCount();
252
253 if ( $page > 1 ) {
254 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
255 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) );
256 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
257 array( 'page' => $page - 1 ) );
258 } else {
259 $thumb1 = '';
260 }
261
262 if ( $page < $count ) {
263 $label = wfMsg( 'imgmultipagenext' );
264 $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
265 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none',
266 array( 'page' => $page + 1 ) );
267 } else {
268 $thumb2 = '';
269 }
270
271 global $wgScript;
272 $select = '<form name="pageselector" action="' .
273 htmlspecialchars( $wgScript ) .
274 '" method="get" onchange="document.pageselector.submit();">' .
275 Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() );
276 $select .= $wgOut->parse( wfMsg( 'imgmultigotopre' ), false ) .
277 ' <select id="pageselector" name="page">';
278 for ( $i=1; $i <= $count; $i++ ) {
279 $select .= Xml::option( $wgLang->formatNum( $i ), $i,
280 $i == $page );
281 }
282 $select .= '</select>' . $wgOut->parse( wfMsg( 'imgmultigotopost' ), false ) .
283 '<input type="submit" value="' .
284 htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
285
286 $wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
287 "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
288 }
289 } else {
290 #if direct link is allowed but it's not a renderable image, show an icon.
291 if ($this->img->isSafeFile()) {
292 $icon= $this->img->iconThumb();
293
294 $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .
295 $icon->toHtml() .
296 '</a></div>' );
297 }
298
299 $showLink = true;
300 }
301
302
303 if ($showLink) {
304 // Workaround for incorrect MIME type on SVGs uploaded in previous versions
305 if ($mime == 'image/svg') $mime = 'image/svg+xml';
306
307 $filename = wfEscapeWikiText( $this->img->getName() );
308 $info = wfMsg( 'file-info', $sk->formatSize( $this->img->getSize() ), $mime );
309 $infores = '';
310
311 // Check for MIME type. Other types may have more information in the future.
312 if (substr($mime,0,9) == 'image/svg' ) {
313 $infores = wfMsg('file-svg', $width_orig, $height_orig ) . '<br />';
314 }
315
316 global $wgContLang;
317 $dirmark = $wgContLang->getDirMark();
318 if (!$this->img->isSafeFile()) {
319 $warning = wfMsg( 'mediawarning' );
320 $wgOut->addWikiText( <<<EOT
321 <div class="fullMedia">$infores
322 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
323 <span class="fileInfo"> $info</span>
324 </div>
325
326 <div class="mediaWarning">$warning</div>
327 EOT
328 );
329 } else {
330 $wgOut->addWikiText( <<<EOT
331 <div class="fullMedia">$infores
332 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $info</span>
333 </div>
334 EOT
335 );
336 }
337 }
338
339 if(!$this->img->isLocal()) {
340 $this->printSharedImageText();
341 }
342 } else {
343 # Image does not exist
344
345 $title = SpecialPage::getTitleFor( 'Upload' );
346 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
347 'wpDestFile=' . urlencode( $this->img->getName() ) );
348 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
349 }
350 }
351
352 function printSharedImageText() {
353 global $wgOut, $wgUser;
354
355 $descUrl = $this->img->getDescriptionUrl();
356 $descText = $this->img->getDescriptionText();
357 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
358 if ( $descUrl && !$descText) {
359 $sk = $wgUser->getSkin();
360 $link = $sk->makeExternalLink( $descUrl, wfMsg('shareduploadwiki-linktext') );
361 $s .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
362 }
363 $s .= "</div>";
364 $wgOut->addHTML($s);
365
366 if ( $descText ) {
367 $this->mExtraDescription = $descText;
368 }
369 }
370
371 function getUploadUrl() {
372 global $wgServer;
373 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
374 return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
375 }
376
377 /**
378 * Print out the various links at the bottom of the image page, e.g. reupload,
379 * external editing (and instructions link) etc.
380 */
381 function uploadLinksBox() {
382 global $wgUser, $wgOut;
383
384 if( !$this->img->isLocal() )
385 return;
386
387 $sk = $wgUser->getSkin();
388
389 $wgOut->addHtml( '<br /><ul>' );
390
391 # "Upload a new version of this file" link
392 if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
393 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
394 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
395 }
396
397 # External editing link
398 $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
399 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
400
401 $wgOut->addHtml( '</ul>' );
402 }
403
404 function closeShowImage()
405 {
406 # For overloading
407
408 }
409
410 /**
411 * If the page we've just displayed is in the "Image" namespace,
412 * we follow it with an upload history of the image and its usage.
413 */
414 function imageHistory()
415 {
416 global $wgUser, $wgOut, $wgUseExternalEditor;
417
418 $sk = $wgUser->getSkin();
419
420 $line = $this->img->nextHistoryLine();
421
422 if ( $line ) {
423 $list = new ImageHistoryList( $sk, $this->img );
424 $s = $list->beginImageHistoryList() .
425 $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
426 $this->mTitle->getDBkey(), $line->img_user,
427 $line->img_user_text, $line->img_size, $line->img_description,
428 $line->img_width, $line->img_height
429 );
430
431 while ( $line = $this->img->nextHistoryLine() ) {
432 $s .= $list->imageHistoryLine( false, $line->img_timestamp,
433 $line->oi_archive_name, $line->img_user,
434 $line->img_user_text, $line->img_size, $line->img_description,
435 $line->img_width, $line->img_height
436 );
437 }
438 $s .= $list->endImageHistoryList();
439 } else { $s=''; }
440 $wgOut->addHTML( $s );
441
442 $this->img->resetHistory(); // free db resources
443
444 # Exist check because we don't want to show this on pages where an image
445 # doesn't exist along with the noimage message, that would suck. -ævar
446 if( $wgUseExternalEditor && $this->img->exists() ) {
447 $this->uploadLinksBox();
448 }
449
450 }
451
452 function imageLinks()
453 {
454 global $wgUser, $wgOut;
455
456 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
457
458 $dbr = wfGetDB( DB_SLAVE );
459 $page = $dbr->tableName( 'page' );
460 $imagelinks = $dbr->tableName( 'imagelinks' );
461
462 $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .
463 $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";
464 $sql = $dbr->limitResult($sql, 500, 0);
465 $res = $dbr->query( $sql, "ImagePage::imageLinks" );
466
467 if ( 0 == $dbr->numRows( $res ) ) {
468 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
469 return;
470 }
471 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
472
473 $sk = $wgUser->getSkin();
474 while ( $s = $dbr->fetchObject( $res ) ) {
475 $name = Title::MakeTitle( $s->page_namespace, $s->page_title );
476 $link = $sk->makeKnownLinkObj( $name, "" );
477 $wgOut->addHTML( "<li>{$link}</li>\n" );
478 }
479 $wgOut->addHTML( "</ul>\n" );
480 }
481
482 function delete()
483 {
484 global $wgUser, $wgOut, $wgRequest;
485
486 if ( !$this->img->exists() || !$this->img->isLocal() ) {
487 # Use standard article deletion
488 Article::delete();
489 return;
490 }
491
492 $confirm = $wgRequest->wasPosted();
493 $reason = $wgRequest->getVal( 'wpReason' );
494 $image = $wgRequest->getVal( 'image' );
495 $oldimage = $wgRequest->getVal( 'oldimage' );
496
497 # Only sysops can delete images. Previously ordinary users could delete
498 # old revisions, but this is no longer the case.
499 if ( !$wgUser->isAllowed('delete') ) {
500 $wgOut->permissionRequired( 'delete' );
501 return;
502 }
503 if ( $wgUser->isBlocked() ) {
504 $wgOut->blockedPage();
505 return;
506 }
507 if ( wfReadOnly() ) {
508 $wgOut->readOnlyPage();
509 return;
510 }
511
512 # Better double-check that it hasn't been deleted yet!
513 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
514 if ( ( !is_null( $image ) )
515 && ( '' == trim( $image ) ) ) {
516 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
517 return;
518 }
519
520 # Deleting old images doesn't require confirmation
521 if ( !is_null( $oldimage ) || $confirm ) {
522 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
523 $this->doDeleteImage( $reason );
524 } else {
525 $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
526 }
527 return;
528 }
529
530 if ( !is_null( $image ) ) {
531 $q = '&image=' . urlencode( $image );
532 } else if ( !is_null( $oldimage ) ) {
533 $q = '&oldimage=' . urlencode( $oldimage );
534 } else {
535 $q = '';
536 }
537 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
538 }
539
540 /*
541 * Delete an image.
542 * Called doDeleteImage() not doDelete() so that Article::delete() doesn't
543 * call back to here.
544 *
545 * @param $reason User provided reason for deletion.
546 */
547 function doDeleteImage( $reason ) {
548 global $wgOut, $wgRequest;
549
550 $oldimage = $wgRequest->getVal( 'oldimage' );
551
552 if ( !is_null( $oldimage ) ) {
553 if ( strlen( $oldimage ) < 16 ) {
554 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
555 return;
556 }
557 if( strpos( $oldimage, '/' ) !== false || strpos( $oldimage, '\\' ) !== false ) {
558 $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
559 return;
560 }
561 $status = $this->doDeleteOldImage( $oldimage );
562 $deleted = $oldimage;
563 } else {
564 $status = $this->img->delete( $reason );
565 if ( !$status->isGood() ) {
566 // Warning or error
567 $wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) );
568 }
569 if ( $status->ok ) {
570 # Image itself is now gone, and database is cleaned.
571 # Now we remove the image description page.
572 $article = new Article( $this->mTitle );
573 $article->doDeleteArticle( $reason ); # ignore errors
574 $deleted = $this->img->getName();
575 }
576 }
577
578 $wgOut->setRobotpolicy( 'noindex,nofollow' );
579
580 if ( !$status->ok ) {
581 // Fatal error flagged
582 $wgOut->setPagetitle( wfMsg( 'errorpagetitle' ) );
583 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
584 } else {
585 // Operation completed
586 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
587 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
588 $text = wfMsg( 'deletedtext', $deleted, $loglink );
589 $wgOut->addWikiText( $text );
590 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
591 }
592 }
593
594 /**
595 * Delete an old revision of an image,
596 * @return FileRepoStatus
597 */
598 function doDeleteOldImage( $oldimage ) {
599 global $wgOut;
600
601 $status = $this->img->deleteOld( $oldimage, '' );
602 if( !$status->isGood() ) {
603 $wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) );
604 }
605 if ( $status->ok ) {
606 # Log the deletion
607 $log = new LogPage( 'delete' );
608 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
609 }
610 return $status;
611 }
612
613 /**
614 * Revert the file to an earlier version
615 */
616 function revert() {
617 $reverter = new FileRevertForm( $this->img );
618 $reverter->execute();
619 }
620
621 /**
622 * Override handling of action=purge
623 */
624 function doPurge() {
625 if( $this->img->exists() ) {
626 wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
627 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
628 $update->doUpdate();
629 $this->img->upgradeRow();
630 $this->img->purgeCache();
631 } else {
632 wfDebug( "ImagePage::doPurge no image\n" );
633 }
634 parent::doPurge();
635 }
636
637 /**
638 * Display an error with a wikitext description
639 */
640 function showError( $description ) {
641 global $wgOut;
642 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
643 $wgOut->setRobotpolicy( "noindex,nofollow" );
644 $wgOut->setArticleRelated( false );
645 $wgOut->enableClientCache( false );
646 $wgOut->addWikiText( $description );
647 }
648
649 }
650
651 /**
652 * Builds the image revision log shown on image pages
653 *
654 * @addtogroup Media
655 */
656 class ImageHistoryList {
657
658 protected $img, $skin, $title;
659
660 public function __construct( $skin, $img ) {
661 $this->skin = $skin;
662 $this->img = $img;
663 $this->title = $img->getTitle();
664 }
665
666 public function beginImageHistoryList() {
667 global $wgOut, $wgUser;
668 return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
669 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
670 . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
671 . '<tr><th></th>'
672 . ( $this->img->isLocal() && $wgUser->isAllowed( 'delete' ) ? '<th></th>' : '' )
673 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
674 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
675 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
676 . '<th>' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
677 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
678 . "</tr>\n";
679 }
680
681 public function endImageHistoryList() {
682 return "</table>\n";
683 }
684
685 public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {
686 global $wgUser, $wgLang, $wgTitle, $wgContLang;
687 $local = $this->img->isLocal();
688 $row = '';
689
690 // Deletion link
691 if( $local && $wgUser->isAllowed( 'delete' ) ) {
692 $row .= '<td>';
693 $q = array();
694 $q[] = 'action=delete';
695 $q[] = ( $iscur ? 'image=' . $this->title->getPartialUrl() : 'oldimage=' . urlencode( $img ) );
696 if( !$iscur )
697 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
698 $row .= '(' . $this->skin->makeKnownLinkObj(
699 $this->title,
700 wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
701 implode( '&', $q )
702 ) . ')';
703 $row .= '</td>';
704 }
705
706 // Reversion link/current indicator
707 $row .= '<td>';
708 if( $iscur ) {
709 $row .= '(' . wfMsgHtml( 'filehist-current' ) . ')';
710 } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
711 $q = array();
712 $q[] = 'action=revert';
713 $q[] = 'oldimage=' . urlencode( $img );
714 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
715 $row .= '(' . $this->skin->makeKnownLinkObj(
716 $this->title,
717 wfMsgHtml( 'filehist-revert' ),
718 implode( '&', $q )
719 ) . ')';
720 }
721 $row .= '</td>';
722
723 // Date/time and image link
724 $row .= '<td>';
725 $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
726 $row .= Xml::element(
727 'a',
728 array( 'href' => $url ),
729 $wgLang->timeAndDate( $timestamp, true )
730 );
731 $row .= '</td>';
732
733 // Uploading user
734 $row .= '<td>';
735 if( $local ) {
736 $row .= $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
737 } else {
738 $row .= htmlspecialchars( $usertext );
739 }
740 $row .= '</td>';
741
742 // Image dimensions
743 // FIXME: It would be nice to show the duration (sound files) or
744 // width/height/duration (video files) here, but this needs some
745 // additional media handler work
746 $row .= '<td>' . wfMsgHtml( 'widthheight', $width, $height ) . '</td>';
747
748 // File size
749 $row .= '<td>' . $this->skin->formatSize( $size ) . '</td>';
750
751 // Comment
752 $row .= '<td>' . $this->skin->formatComment( $description, $this->title ) . '</td>';
753
754 return "<tr>{$row}</tr>\n";
755 }
756
757 }