3 if( !defined( 'MEDIAWIKI' ) )
7 * Special handling for image description pages
11 class ImagePage
extends Article
{
13 /* private */ var $img; // Image object this page is shown for
14 /* private */ var $current;
15 /* private */ var $repo;
16 /* private */ var $time;
17 /* private */ var $fileLoaded;
18 var $mExtraDescription = false;
21 function __construct( $title, $time = null ) {
22 parent
::__construct( $title );
25 $this->time
= is_null($time) ?
$wgRequest->getVal( 'filetimestamp' ) : $time;
30 protected function loadFile() {
31 if( $this->fileLoaded
) {
34 $this->img
= wfFindFile( $this->mTitle
, $this->time
);
36 $this->img
= wfLocalFile( $this->mTitle
);
37 $this->current
= $this->img
;
39 $this->current
= $this->time ?
wfLocalFile( $this->mTitle
) : $this->img
;
41 $this->repo
= $this->img
->getRepo();
42 $this->fileLoaded
= true;
46 * Handler for action=render
47 * Include body text only; none of the image extras
51 $wgOut->setArticleBodyOnly( true );
56 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
59 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
60 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
61 // mTitle is the same as the redirect target so ask Article
62 // to perform the redirect for us.
63 return Article
::view();
65 // mTitle is not the same as the redirect target so it is
66 // probably the redirect page itself. Fake the redirect symbol
67 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
68 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
69 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
75 $diff = $wgRequest->getVal( 'diff' );
76 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
78 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
79 return Article
::view();
81 if ($wgShowEXIF && $this->img
->exists()) {
82 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
83 $formattedMetadata = $this->img
->formatMetadata();
84 $showmeta = $formattedMetadata !== false;
89 if ($this->img
->exists())
90 $wgOut->addHTML($this->showTOC($showmeta));
92 $this->openShowImage();
94 # No need to display noarticletext, we use our own message, output in openShowImage()
95 if ( $this->getID() ) {
98 # Just need to set the right headers
99 $wgOut->setArticleFlag( true );
100 $wgOut->setRobotpolicy( 'noindex,nofollow' );
101 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
102 $this->viewUpdates();
105 # Show shared description, if needed
106 if ( $this->mExtraDescription
) {
107 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
108 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
109 $wgOut->addWikiText( $fol );
111 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
113 $this->checkSharedConflict();
116 $this->closeShowImage();
117 $this->imageHistory();
118 // TODO: Cleanup the following
120 $wgOut->addHTML( Xml
::element( 'h2',
121 array( 'id' => 'filelinks' ),
122 wfMsg( 'imagelinks' ) ) . "\n" );
124 // TODO: We may want to find local images redirecting to a foreign
125 // file: "The following local files redirect to this file"
126 if ( $this->img
->isLocal() ) $this->imageRedirects();
130 global $wgStylePath, $wgStyleVersion;
131 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
132 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
133 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
134 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
135 $wgOut->addScriptFile( 'metadata.js' );
137 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
141 public function getRedirectTarget() {
143 if ( $this->img
->isLocal() ) {
144 return parent
::getRedirectTarget();
146 // Foreign image page
147 $from = $this->img
->getRedirected();
148 $to = $this->img
->getName();
149 if ( $from == $to ) {
152 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
154 public function followRedirect() {
156 if ( $this->img
->isLocal() ) {
157 return parent
::followRedirect();
159 $from = $this->img
->getRedirected();
160 $to = $this->img
->getName();
161 if ( $from == $to ) {
164 return Title
::makeTitle( NS_IMAGE
, $to );
166 public function isRedirect( $text = false ) {
168 if ( $this->img
->isLocal() )
169 return parent
::isRedirect( $text );
171 return (bool)$this->img
->getRedirected();
174 public function isLocal() {
176 return $this->img
->isLocal();
179 public function getFile() {
184 public function getDuplicates() {
186 if ( !is_null($this->dupes
) ) {
189 if ( !( $hash = $this->img
->getSha1() ) ) {
190 return $this->dupes
= array();
192 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
193 // Remove duplicates with self and non matching file sizes
194 $self = $this->img
->getRepoName().':'.$this->img
->getName();
195 $size = $this->img
->getSize();
196 foreach ( $dupes as $index => $file ) {
197 $key = $file->getRepoName().':'.$file->getName();
199 unset( $dupes[$index] );
200 if ( $file->getSize() != $size )
201 unset( $dupes[$index] );
203 return $this->dupes
= $dupes;
213 * @param bool $metadata Whether or not to show the metadata link
216 function showTOC( $metadata ) {
218 $r = '<ul id="filetoc">
219 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
220 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
221 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
222 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
228 * Make a table with metadata to be shown in the output page.
230 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
234 * @param array $exif The array containing the EXIF data
237 function makeMetadataTable( $metadata ) {
238 $r = wfMsg( 'metadata-help' ) . "\n\n";
239 $r .= "{| id=mw_metadata class=mw_metadata\n";
240 foreach ( $metadata as $type => $stuff ) {
241 foreach ( $stuff as $v ) {
242 $class = Sanitizer
::escapeId( $v['id'] );
243 if( $type == 'collapsed' ) {
244 $class .= ' collapsable';
246 $r .= "|- class=\"$class\"\n";
247 $r .= "!| {$v['name']}\n";
248 $r .= "|| {$v['value']}\n";
256 * Overloading Article's getContent method.
258 * Omit noarticletext if sharedupload; text will be fetched from the
259 * shared upload server if possible.
261 function getContent() {
263 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
266 return Article
::getContent();
269 function openShowImage() {
270 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
274 $full_url = $this->img
->getURL();
275 $linkAttribs = false;
276 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
277 if( !isset( $wgImageLimits[$sizeSel] ) ) {
278 $sizeSel = User
::getDefaultOption( 'imagesize' );
280 // The user offset might still be incorrect, specially if
281 // $wgImageLimits got changed (see bug #8858).
282 if( !isset( $wgImageLimits[$sizeSel] ) ) {
283 // Default to the first offset in $wgImageLimits
287 $max = $wgImageLimits[$sizeSel];
289 $maxHeight = $max[1];
290 $sk = $wgUser->getSkin();
291 $dirmark = $wgContLang->getDirMark();
293 if ( $this->img
->exists() ) {
295 $page = $wgRequest->getIntOrNull( 'page' );
296 if ( is_null( $page ) ) {
300 $params = array( 'page' => $page );
302 $width_orig = $this->img
->getWidth();
303 $width = $width_orig;
304 $height_orig = $this->img
->getHeight();
305 $height = $height_orig;
306 $mime = $this->img
->getMimeType();
308 $linkAttribs = array( 'href' => $full_url );
309 $longDesc = $this->img
->getLongDesc();
311 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
313 if ( $this->img
->allowInlineDisplay() ) {
316 # "Download high res version" link below the image
317 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
318 # We'll show a thumbnail of this image
319 if ( $width > $maxWidth ||
$height > $maxHeight ) {
320 # Calculate the thumbnail size.
321 # First case, the limiting factor is the width, not the height.
322 if ( $width / $height >= $maxWidth / $maxHeight ) {
323 $height = round( $height * $maxWidth / $width);
325 # Note that $height <= $maxHeight now.
327 $newwidth = floor( $width * $maxHeight / $height);
328 $height = round( $height * $newwidth / $width );
330 # Note that $height <= $maxHeight now, but might not be identical
331 # because of rounding.
333 $msgbig = wfMsgHtml( 'show-big-image' );
334 $msgsmall = wfMsgExt( 'show-big-image-thumb',
335 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
337 # Image is small enough to show full size on image page
338 $msgbig = htmlspecialchars( $this->img
->getName() );
339 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
342 $params['width'] = $width;
343 $thumbnail = $this->img
->transform( $params );
345 $anchorclose = "<br />";
346 if( $this->img
->mustRender() ) {
351 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
354 if ( $this->img
->isMultipage() ) {
355 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
360 'alt' => $this->img
->getTitle()->getPrefixedText(),
363 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
364 $thumbnail->toHtml( $options ) .
365 $anchorclose . '</div>' );
368 if ( $this->img
->isMultipage() ) {
369 $count = $this->img
->pageCount();
372 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
373 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
374 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
375 array( 'page' => $page - 1 ) );
380 if ( $page < $count ) {
381 $label = wfMsg( 'imgmultipagenext' );
382 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
383 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
384 array( 'page' => $page +
1 ) );
392 'name' => 'pageselector',
393 'action' => $wgScript,
394 'onchange' => 'document.pageselector.submit();',
398 for ( $i=1; $i <= $count; $i++
) {
399 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
401 $select = Xml
::tags( 'select',
402 array( 'id' => 'pageselector', 'name' => 'page' ),
403 implode( "\n", $options ) );
406 '</td><td><div class="multipageimagenavbox">' .
407 Xml
::openElement( 'form', $formParams ) .
408 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
409 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
410 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
411 Xml
::closeElement( 'form' ) .
412 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
416 #if direct link is allowed but it's not a renderable image, show an icon.
417 if ($this->img
->isSafeFile()) {
418 $icon= $this->img
->iconThumb();
420 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
421 $icon->toHtml( array( 'desc-link' => true ) ) .
430 $filename = wfEscapeWikiText( $this->img
->getName() );
432 if (!$this->img
->isSafeFile()) {
433 $warning = wfMsgNoTrans( 'mediawarning' );
434 $wgOut->addWikiText( <<<EOT
435 <div class="fullMedia">
436 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
437 <span class="fileInfo"> $longDesc</span>
440 <div class="mediaWarning">$warning</div>
444 $wgOut->addWikiText( <<<EOT
445 <div class="fullMedia">
446 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
453 if(!$this->img
->isLocal()) {
454 $this->printSharedImageText();
457 # Image does not exist
459 $title = SpecialPage
::getTitleFor( 'Upload' );
460 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
461 'wpDestFile=' . urlencode( $this->img
->getName() ) );
462 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
467 * Show a notice that the file is from a shared repository
469 function printSharedImageText() {
470 global $wgOut, $wgUser;
474 $descUrl = $this->img
->getDescriptionUrl();
475 $descText = $this->img
->getDescriptionText();
476 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
478 $sk = $wgUser->getSkin();
479 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
480 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
481 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
483 # Show message only if not voided by local sysops
488 $wgOut->addHTML( $s );
491 $this->mExtraDescription
= $descText;
496 * Check for files with the same name on the foreign repos.
498 function checkSharedConflict() {
499 global $wgOut, $wgUser;
501 $repoGroup = RepoGroup
::singleton();
502 if( !$repoGroup->hasForeignRepos() ) {
507 if( !$this->img
->isLocal() ) {
511 $this->dupFile
= null;
512 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
514 if( !$this->dupFile
)
516 $dupfile = $this->dupFile
;
518 ($this->img
->getSha1() == $dupfile->getSha1()) &&
519 ($this->img
->getSize() == $dupfile->getSize())
522 $sk = $wgUser->getSkin();
523 $descUrl = $dupfile->getDescriptionUrl();
525 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
526 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
528 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
529 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
533 function checkSharedConflictCallback( $repo ) {
535 $dupfile = $repo->newFile( $this->img
->getTitle() );
536 if( $dupfile->exists() ) {
537 $this->dupFile
= $dupfile;
539 return $dupfile->exists();
542 function getUploadUrl() {
544 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
545 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
549 * Print out the various links at the bottom of the image page, e.g. reupload,
550 * external editing (and instructions link) etc.
552 function uploadLinksBox() {
553 global $wgUser, $wgOut;
556 if( !$this->img
->isLocal() )
559 $sk = $wgUser->getSkin();
561 $wgOut->addHtml( '<br /><ul>' );
563 # "Upload a new version of this file" link
564 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
565 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
566 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
569 # Link to Special:FileDuplicateSearch
570 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
571 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
573 # External editing link
574 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
575 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
577 $wgOut->addHtml( '</ul>' );
580 function closeShowImage()
587 * If the page we've just displayed is in the "Image" namespace,
588 * we follow it with an upload history of the image and its usage.
590 function imageHistory()
592 global $wgUser, $wgOut, $wgUseExternalEditor;
594 $sk = $wgUser->getSkin();
597 if ( $this->img
->exists() ) {
598 $list = new ImageHistoryList( $sk, $this->current
, $this->img
);
599 $file = $this->current
;
600 $dims = $file->getDimensionsString();
601 $s = $list->beginImageHistoryList();
602 $s .= $list->imageHistoryLine( true, $file );
603 // old image versions
604 $hist = $this->img
->getHistory();
605 foreach( $hist as $file ) {
606 $dims = $file->getDimensionsString();
607 $s .= $list->imageHistoryLine( false, $file );
609 $s .= $list->endImageHistoryList();
611 $wgOut->addHTML( $s );
613 $this->img
->resetHistory(); // free db resources
615 # Exist check because we don't want to show this on pages where an image
616 # doesn't exist along with the noimage message, that would suck. -ævar
617 if( $wgUseExternalEditor && $this->img
->exists() ) {
618 $this->uploadLinksBox();
623 function imageLinks()
625 global $wgUser, $wgOut;
629 $dbr = wfGetDB( DB_SLAVE
);
632 array( 'imagelinks', 'page' ),
633 array( 'page_namespace', 'page_title' ),
634 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
636 array( 'LIMIT' => $limit +
1)
639 if ( 0 == $dbr->numRows( $res ) ) {
640 $wgOut->addWikiMsg( 'nolinkstoimage' );
643 $wgOut->addWikiMsg( 'linkstoimage' );
644 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
646 $sk = $wgUser->getSkin();
648 while ( $s = $res->fetchObject() ) {
650 if ( $count <= $limit ) {
651 // We have not yet reached the extra one that tells us there is more to fetch
652 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
653 $link = $sk->makeKnownLinkObj( $name, "" );
654 $wgOut->addHTML( "<li>{$link}</li>\n" );
657 $wgOut->addHTML( "</ul>\n" );
660 // Add a links to [[Special:Whatlinkshere]]
661 if ( $count > $limit )
662 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
665 function imageRedirects()
667 global $wgUser, $wgOut;
669 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
670 if ( count( $redirects ) == 0 ) return;
673 $wgOut->addWikiMsg( 'redirectstofile' );
674 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
676 $sk = $wgUser->getSkin();
677 foreach ( $redirects as $title ) {
678 $link = $sk->makeKnownLinkObj( $title, "" );
679 $wgOut->addHTML( "<li>{$link}</li>\n" );
681 $wgOut->addHTML( "</ul>\n" );
685 function imageDupes() {
686 global $wgOut, $wgUser;
690 $dupes = $this->getDuplicates();
691 if ( count( $dupes ) == 0 ) return;
693 $wgOut->addWikiMsg( 'duplicatesoffile' );
694 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
696 $sk = $wgUser->getSkin();
697 foreach ( $dupes as $file ) {
698 if ( $file->isLocal() )
699 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
701 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
702 $file->getTitle()->getPrefixedText() );
703 $wgOut->addHTML( "<li>{$link}</li>\n" );
705 $wgOut->addHTML( "</ul>\n" );
709 * Delete the file, or an earlier version of it
711 public function delete() {
713 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
714 // Standard article deletion
718 $deleter = new FileDeleteForm( $this->img
);
723 * Revert the file to an earlier version
725 public function revert() {
727 $reverter = new FileRevertForm( $this->img
);
728 $reverter->execute();
732 * Override handling of action=purge
736 if( $this->img
->exists() ) {
737 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
738 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
740 $this->img
->upgradeRow();
741 $this->img
->purgeCache();
743 wfDebug( "ImagePage::doPurge no image\n" );
749 * Display an error with a wikitext description
751 function showError( $description ) {
753 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
754 $wgOut->setRobotpolicy( "noindex,nofollow" );
755 $wgOut->setArticleRelated( false );
756 $wgOut->enableClientCache( false );
757 $wgOut->addWikiText( $description );
763 * Builds the image revision log shown on image pages
767 class ImageHistoryList
{
769 protected $img, $skin, $title, $repo;
771 public function __construct( $skin, $curimg, $img ) {
773 $this->current
= $curimg;
775 $this->title
= $img->getTitle();
778 public function beginImageHistoryList() {
779 global $wgOut, $wgUser;
780 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
781 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
782 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
784 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
785 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
786 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
787 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
788 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
792 public function endImageHistoryList() {
796 public function imageHistoryLine( $iscur, $file ) {
797 global $wgUser, $wgLang, $wgContLang, $wgTitle;
799 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
800 $img = $iscur ?
$file->getName() : $file->getArchiveName();
801 $user = $file->getUser('id');
802 $usertext = $file->getUser('text');
803 $size = $file->getSize();
804 $description = $file->getDescription();
805 $dims = $file->getDimensionsString();
806 $sha1 = $file->getSha1();
808 $local = $this->current
->isLocal();
809 $row = $css = $selected = '';
812 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
814 # Link to remove from history
815 if( $wgUser->isAllowed( 'delete' ) ) {
817 $q[] = 'action=delete';
819 $q[] = 'oldimage=' . urlencode( $img );
820 $row .= $this->skin
->makeKnownLinkObj(
822 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
826 # Link to hide content
827 if( $wgUser->isAllowed( 'deleterevision' ) ) {
828 if( $wgUser->isAllowed('delete') ) {
831 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
832 // If file is top revision or locked from this user, don't link
833 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
834 $del = wfMsgHtml( 'rev-delundel' );
836 // If the file was hidden, link to sha-1
837 list($ts,$name) = explode('!',$img,2);
838 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
839 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
840 '&oldimage=' . urlencode( $ts ) );
841 // Bolden oversighted content
842 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
843 $del = "<strong>$del</strong>";
845 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
850 // Reversion link/current indicator
853 $row .= wfMsgHtml( 'filehist-current' );
854 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
855 if( $file->isDeleted(File
::DELETED_FILE
) ) {
856 $row .= wfMsgHtml('filehist-revert');
859 $q[] = 'action=revert';
860 $q[] = 'oldimage=' . urlencode( $img );
861 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
862 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
863 wfMsgHtml( 'filehist-revert' ),
864 implode( '&', $q ) );
869 // Date/time and image link
870 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
871 $selected = "class='filehistory-selected'";
873 $row .= "<td $selected style='white-space: nowrap;'>";
874 if( !$file->userCan(File
::DELETED_FILE
) ) {
875 # Don't link to unviewable files
876 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
877 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
878 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
879 # Make a link to review the image
880 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
881 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
882 $row .= '<span class="history-deleted">'.$url.'</span>';
884 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
885 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
891 $row .= htmlspecialchars( $dims );
894 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
899 // Hide deleted usernames
900 if( $file->isDeleted(File
::DELETED_USER
) ) {
901 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
903 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
904 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
907 $row .= htmlspecialchars( $usertext );
911 // Don't show deleted descriptions
912 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
913 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
915 $row .= $this->skin
->commentBlock( $description, $this->title
);
919 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
920 $trCSS = $css ?
" class='$css'" : "";
922 return "<tr{$trCSS}>{$row}</tr>\n";