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