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 $time = is_null($time) ?
$time : $wgRequest->getVal( 'filetimestamp' );
31 protected function loadFile() {
32 if( $this->fileLoaded
) {
35 $this->img
= wfFindFile( $this->mTitle
, $this->time
);
37 $this->img
= wfLocalFile( $this->mTitle
);
38 $this->current
= $this->img
;
40 $this->current
= $this->time ?
wfLocalFile( $this->mTitle
) : $this->img
;
42 $this->repo
= $this->img
->getRepo();
43 $this->fileLoaded
= true;
47 * Handler for action=render
48 * Include body text only; none of the image extras
52 $wgOut->setArticleBodyOnly( true );
57 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
60 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
61 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
62 // mTitle is the same as the redirect target so ask Article
63 // to perform the redirect for us.
64 return Article
::view();
66 // mTitle is not the same as the redirect target so it is
67 // probably the redirect page itself. Fake the redirect symbol
68 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
69 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
70 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
76 $diff = $wgRequest->getVal( 'diff' );
77 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
79 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
80 return Article
::view();
82 if ($wgShowEXIF && $this->img
->exists()) {
83 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
84 $formattedMetadata = $this->img
->formatMetadata();
85 $showmeta = $formattedMetadata !== false;
90 if ($this->img
->exists())
91 $wgOut->addHTML($this->showTOC($showmeta));
93 $this->openShowImage();
95 # No need to display noarticletext, we use our own message, output in openShowImage()
96 if ( $this->getID() ) {
99 # Just need to set the right headers
100 $wgOut->setArticleFlag( true );
101 $wgOut->setRobotpolicy( 'noindex,nofollow' );
102 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
103 $this->viewUpdates();
106 # Show shared description, if needed
107 if ( $this->mExtraDescription
) {
108 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
109 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
110 $wgOut->addWikiText( $fol );
112 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
114 $this->checkSharedConflict();
117 $this->closeShowImage();
118 $this->imageHistory();
119 // TODO: Cleanup the following
121 $wgOut->addHTML( Xml
::element( 'h2',
122 array( 'id' => 'filelinks' ),
123 wfMsg( 'imagelinks' ) ) . "\n" );
125 // TODO: We may want to find local images redirecting to a foreign
126 // file: "The following local files redirect to this file"
127 if ( $this->img
->isLocal() ) $this->imageRedirects();
131 global $wgStylePath, $wgStyleVersion;
132 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
133 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
134 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
135 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
136 $wgOut->addScriptFile( 'metadata.js' );
138 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
142 public function getRedirectTarget() {
144 if ( $this->img
->isLocal() ) {
145 return parent
::getRedirectTarget();
147 // Foreign image page
148 $from = $this->img
->getRedirected();
149 $to = $this->img
->getName();
150 if ( $from == $to ) {
153 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
155 public function followRedirect() {
157 if ( $this->img
->isLocal() ) {
158 return parent
::followRedirect();
160 $from = $this->img
->getRedirected();
161 $to = $this->img
->getName();
162 if ( $from == $to ) {
165 return Title
::makeTitle( NS_IMAGE
, $to );
167 public function isRedirect( $text = false ) {
169 if ( $this->img
->isLocal() )
170 return parent
::isRedirect( $text );
172 return (bool)$this->img
->getRedirected();
175 public function isLocal() {
177 return $this->img
->isLocal();
180 public function getFile() {
185 public function getDuplicates() {
187 if ( !is_null($this->dupes
) ) {
190 if ( !( $hash = $this->img
->getSha1() ) ) {
191 return $this->dupes
= array();
193 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
194 // Remove duplicates with self and non matching file sizes
195 $self = $this->img
->getRepoName().':'.$this->img
->getName();
196 $size = $this->img
->getSize();
197 foreach ( $dupes as $index => $file ) {
198 $key = $file->getRepoName().':'.$file->getName();
200 unset( $dupes[$index] );
201 if ( $file->getSize() != $size )
202 unset( $dupes[$index] );
204 return $this->dupes
= $dupes;
214 * @param bool $metadata Whether or not to show the metadata link
217 function showTOC( $metadata ) {
219 $r = '<ul id="filetoc">
220 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
221 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
222 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
223 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
229 * Make a table with metadata to be shown in the output page.
231 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
235 * @param array $exif The array containing the EXIF data
238 function makeMetadataTable( $metadata ) {
239 $r = wfMsg( 'metadata-help' ) . "\n\n";
240 $r .= "{| id=mw_metadata class=mw_metadata\n";
241 foreach ( $metadata as $type => $stuff ) {
242 foreach ( $stuff as $v ) {
243 $class = Sanitizer
::escapeId( $v['id'] );
244 if( $type == 'collapsed' ) {
245 $class .= ' collapsable';
247 $r .= "|- class=\"$class\"\n";
248 $r .= "!| {$v['name']}\n";
249 $r .= "|| {$v['value']}\n";
257 * Overloading Article's getContent method.
259 * Omit noarticletext if sharedupload; text will be fetched from the
260 * shared upload server if possible.
262 function getContent() {
264 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
267 return Article
::getContent();
270 function openShowImage() {
271 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
275 $full_url = $this->img
->getURL();
276 $linkAttribs = false;
277 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
278 if( !isset( $wgImageLimits[$sizeSel] ) ) {
279 $sizeSel = User
::getDefaultOption( 'imagesize' );
281 // The user offset might still be incorrect, specially if
282 // $wgImageLimits got changed (see bug #8858).
283 if( !isset( $wgImageLimits[$sizeSel] ) ) {
284 // Default to the first offset in $wgImageLimits
288 $max = $wgImageLimits[$sizeSel];
290 $maxHeight = $max[1];
291 $sk = $wgUser->getSkin();
292 $dirmark = $wgContLang->getDirMark();
294 if ( $this->img
->exists() ) {
296 $page = $wgRequest->getIntOrNull( 'page' );
297 if ( is_null( $page ) ) {
301 $params = array( 'page' => $page );
303 $width_orig = $this->img
->getWidth();
304 $width = $width_orig;
305 $height_orig = $this->img
->getHeight();
306 $height = $height_orig;
307 $mime = $this->img
->getMimeType();
309 $linkAttribs = array( 'href' => $full_url );
310 $longDesc = $this->img
->getLongDesc();
312 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
314 if ( $this->img
->allowInlineDisplay() ) {
317 # "Download high res version" link below the image
318 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
319 # We'll show a thumbnail of this image
320 if ( $width > $maxWidth ||
$height > $maxHeight ) {
321 # Calculate the thumbnail size.
322 # First case, the limiting factor is the width, not the height.
323 if ( $width / $height >= $maxWidth / $maxHeight ) {
324 $height = round( $height * $maxWidth / $width);
326 # Note that $height <= $maxHeight now.
328 $newwidth = floor( $width * $maxHeight / $height);
329 $height = round( $height * $newwidth / $width );
331 # Note that $height <= $maxHeight now, but might not be identical
332 # because of rounding.
334 $msgbig = wfMsgHtml( 'show-big-image' );
335 $msgsmall = wfMsgExt( 'show-big-image-thumb',
336 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
338 # Image is small enough to show full size on image page
339 $msgbig = htmlspecialchars( $this->img
->getName() );
340 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
343 $params['width'] = $width;
344 $thumbnail = $this->img
->transform( $params );
346 $anchorclose = "<br />";
347 if( $this->img
->mustRender() ) {
352 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
355 if ( $this->img
->isMultipage() ) {
356 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
361 'alt' => $this->img
->getTitle()->getPrefixedText(),
364 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
365 $thumbnail->toHtml( $options ) .
366 $anchorclose . '</div>' );
369 if ( $this->img
->isMultipage() ) {
370 $count = $this->img
->pageCount();
373 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
374 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
375 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
376 array( 'page' => $page - 1 ) );
381 if ( $page < $count ) {
382 $label = wfMsg( 'imgmultipagenext' );
383 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
384 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
385 array( 'page' => $page +
1 ) );
393 'name' => 'pageselector',
394 'action' => $wgScript,
395 'onchange' => 'document.pageselector.submit();',
399 for ( $i=1; $i <= $count; $i++
) {
400 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
402 $select = Xml
::tags( 'select',
403 array( 'id' => 'pageselector', 'name' => 'page' ),
404 implode( "\n", $options ) );
407 '</td><td><div class="multipageimagenavbox">' .
408 Xml
::openElement( 'form', $formParams ) .
409 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
410 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
411 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
412 Xml
::closeElement( 'form' ) .
413 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
417 #if direct link is allowed but it's not a renderable image, show an icon.
418 if ($this->img
->isSafeFile()) {
419 $icon= $this->img
->iconThumb();
421 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
422 $icon->toHtml( array( 'desc-link' => true ) ) .
431 $filename = wfEscapeWikiText( $this->img
->getName() );
433 if (!$this->img
->isSafeFile()) {
434 $warning = wfMsgNoTrans( 'mediawarning' );
435 $wgOut->addWikiText( <<<EOT
436 <div class="fullMedia">
437 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
438 <span class="fileInfo"> $longDesc</span>
441 <div class="mediaWarning">$warning</div>
445 $wgOut->addWikiText( <<<EOT
446 <div class="fullMedia">
447 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
454 if(!$this->img
->isLocal()) {
455 $this->printSharedImageText();
458 # Image does not exist
460 $title = SpecialPage
::getTitleFor( 'Upload' );
461 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
462 'wpDestFile=' . urlencode( $this->img
->getName() ) );
463 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
468 * Show a notice that the file is from a shared repository
470 function printSharedImageText() {
471 global $wgOut, $wgUser;
475 $descUrl = $this->img
->getDescriptionUrl();
476 $descText = $this->img
->getDescriptionText();
477 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
479 $sk = $wgUser->getSkin();
480 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
481 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
482 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
484 # Show message only if not voided by local sysops
489 $wgOut->addHTML( $s );
492 $this->mExtraDescription
= $descText;
497 * Check for files with the same name on the foreign repos.
499 function checkSharedConflict() {
500 global $wgOut, $wgUser;
502 $repoGroup = RepoGroup
::singleton();
503 if( !$repoGroup->hasForeignRepos() ) {
508 if( !$this->img
->isLocal() ) {
512 $this->dupFile
= null;
513 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
515 if( !$this->dupFile
)
517 $dupfile = $this->dupFile
;
519 ($this->img
->getSha1() == $dupfile->getSha1()) &&
520 ($this->img
->getSize() == $dupfile->getSize())
523 $sk = $wgUser->getSkin();
524 $descUrl = $dupfile->getDescriptionUrl();
526 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
527 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
529 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
530 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
534 function checkSharedConflictCallback( $repo ) {
536 $dupfile = $repo->newFile( $this->img
->getTitle() );
537 if( $dupfile->exists() ) {
538 $this->dupFile
= $dupfile;
540 return $dupfile->exists();
543 function getUploadUrl() {
545 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
546 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
550 * Print out the various links at the bottom of the image page, e.g. reupload,
551 * external editing (and instructions link) etc.
553 function uploadLinksBox() {
554 global $wgUser, $wgOut;
557 if( !$this->img
->isLocal() )
560 $sk = $wgUser->getSkin();
562 $wgOut->addHtml( '<br /><ul>' );
564 # "Upload a new version of this file" link
565 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
566 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
567 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
570 # Link to Special:FileDuplicateSearch
571 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
572 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
574 # External editing link
575 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
576 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
578 $wgOut->addHtml( '</ul>' );
581 function closeShowImage()
588 * If the page we've just displayed is in the "Image" namespace,
589 * we follow it with an upload history of the image and its usage.
591 function imageHistory()
593 global $wgUser, $wgOut, $wgUseExternalEditor;
595 $sk = $wgUser->getSkin();
598 if ( $this->img
->exists() ) {
599 $list = new ImageHistoryList( $sk, $this->current
, $this->img
);
600 $file = $this->current
;
601 $dims = $file->getDimensionsString();
602 $s = $list->beginImageHistoryList();
603 $s .= $list->imageHistoryLine( true, $file );
604 // old image versions
605 $hist = $this->img
->getHistory();
606 foreach( $hist as $file ) {
607 $dims = $file->getDimensionsString();
608 $s .= $list->imageHistoryLine( false, $file );
610 $s .= $list->endImageHistoryList();
612 $wgOut->addHTML( $s );
614 $this->img
->resetHistory(); // free db resources
616 # Exist check because we don't want to show this on pages where an image
617 # doesn't exist along with the noimage message, that would suck. -ævar
618 if( $wgUseExternalEditor && $this->img
->exists() ) {
619 $this->uploadLinksBox();
624 function imageLinks()
626 global $wgUser, $wgOut;
630 $dbr = wfGetDB( DB_SLAVE
);
633 array( 'imagelinks', 'page' ),
634 array( 'page_namespace', 'page_title' ),
635 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
637 array( 'LIMIT' => $limit +
1)
640 if ( 0 == $dbr->numRows( $res ) ) {
641 $wgOut->addWikiMsg( 'nolinkstoimage' );
644 $wgOut->addWikiMsg( 'linkstoimage' );
645 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
647 $sk = $wgUser->getSkin();
649 while ( $s = $res->fetchObject() ) {
651 if ( $count <= $limit ) {
652 // We have not yet reached the extra one that tells us there is more to fetch
653 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
654 $link = $sk->makeKnownLinkObj( $name, "" );
655 $wgOut->addHTML( "<li>{$link}</li>\n" );
658 $wgOut->addHTML( "</ul>\n" );
661 // Add a links to [[Special:Whatlinkshere]]
662 if ( $count > $limit )
663 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
666 function imageRedirects()
668 global $wgUser, $wgOut;
670 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
671 if ( count( $redirects ) == 0 ) return;
674 $wgOut->addWikiMsg( 'redirectstofile' );
675 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
677 $sk = $wgUser->getSkin();
678 foreach ( $redirects as $title ) {
679 $link = $sk->makeKnownLinkObj( $title, "" );
680 $wgOut->addHTML( "<li>{$link}</li>\n" );
682 $wgOut->addHTML( "</ul>\n" );
686 function imageDupes() {
687 global $wgOut, $wgUser;
691 $dupes = $this->getDuplicates();
692 if ( count( $dupes ) == 0 ) return;
694 $wgOut->addWikiMsg( 'duplicatesoffile' );
695 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
697 $sk = $wgUser->getSkin();
698 foreach ( $dupes as $file ) {
699 if ( $file->isLocal() )
700 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
702 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
703 $file->getTitle()->getPrefixedText() );
704 $wgOut->addHTML( "<li>{$link}</li>\n" );
706 $wgOut->addHTML( "</ul>\n" );
710 * Delete the file, or an earlier version of it
712 public function delete() {
714 if( !$this->img
->exists() ||
!$this->img
->isLocal() ) {
715 // Standard article deletion
719 $deleter = new FileDeleteForm( $this->img
);
724 * Revert the file to an earlier version
726 public function revert() {
728 $reverter = new FileRevertForm( $this->img
);
729 $reverter->execute();
733 * Override handling of action=purge
737 if( $this->img
->exists() ) {
738 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
739 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
741 $this->img
->upgradeRow();
742 $this->img
->purgeCache();
744 wfDebug( "ImagePage::doPurge no image\n" );
750 * Display an error with a wikitext description
752 function showError( $description ) {
754 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
755 $wgOut->setRobotpolicy( "noindex,nofollow" );
756 $wgOut->setArticleRelated( false );
757 $wgOut->enableClientCache( false );
758 $wgOut->addWikiText( $description );
764 * Builds the image revision log shown on image pages
768 class ImageHistoryList
{
770 protected $img, $skin, $title, $repo;
772 public function __construct( $skin, $curimg, $img ) {
774 $this->current
= $curimg;
776 $this->title
= $img->getTitle();
779 public function beginImageHistoryList() {
780 global $wgOut, $wgUser;
781 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
782 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
783 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
785 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
786 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
787 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
788 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
789 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
793 public function endImageHistoryList() {
797 public function imageHistoryLine( $iscur, $file ) {
798 global $wgUser, $wgLang, $wgContLang, $wgTitle;
800 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
801 $img = $iscur ?
$file->getName() : $file->getArchiveName();
802 $user = $file->getUser('id');
803 $usertext = $file->getUser('text');
804 $size = $file->getSize();
805 $description = $file->getDescription();
806 $dims = $file->getDimensionsString();
807 $sha1 = $file->getSha1();
809 $local = $this->current
->isLocal();
810 $row = $css = $selected = '';
813 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
815 # Link to remove from history
816 if( $wgUser->isAllowed( 'delete' ) ) {
818 $q[] = 'action=delete';
820 $q[] = 'oldimage=' . urlencode( $img );
821 $row .= $this->skin
->makeKnownLinkObj(
823 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
827 # Link to hide content
828 if( $wgUser->isAllowed( 'deleterevision' ) ) {
829 if( $wgUser->isAllowed('delete') ) {
832 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
833 // If file is top revision or locked from this user, don't link
834 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
835 $del = wfMsgHtml( 'rev-delundel' );
837 // If the file was hidden, link to sha-1
838 list($ts,$name) = explode('!',$img,2);
839 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
840 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
841 '&oldimage=' . urlencode( $ts ) );
842 // Bolden oversighted content
843 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
844 $del = "<strong>$del</strong>";
846 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
851 // Reversion link/current indicator
854 $row .= wfMsgHtml( 'filehist-current' );
855 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
856 if( $file->isDeleted(File
::DELETED_FILE
) ) {
857 $row .= wfMsgHtml('filehist-revert');
860 $q[] = 'action=revert';
861 $q[] = 'oldimage=' . urlencode( $img );
862 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
863 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
864 wfMsgHtml( 'filehist-revert' ),
865 implode( '&', $q ) );
870 // Date/time and image link
871 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
872 $selected = "class='filehistory-selected'";
874 $row .= "<td $selected style='white-space: nowrap;'>";
875 if( !$file->userCan(File
::DELETED_FILE
) ) {
876 # Don't link to unviewable files
877 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
878 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
879 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
880 # Make a link to review the image
881 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
882 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
883 $row .= '<span class="history-deleted">'.$url.'</span>';
885 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
886 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
892 $row .= htmlspecialchars( $dims );
895 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
900 // Hide deleted usernames
901 if( $file->isDeleted(File
::DELETED_USER
) ) {
902 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
904 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
905 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
908 $row .= htmlspecialchars( $usertext );
912 // Don't show deleted descriptions
913 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
914 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
916 $row .= $this->skin
->commentBlock( $description, $this->title
);
920 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
921 $trCSS = $css ?
" class='$css'" : "";
923 return "<tr{$trCSS}>{$row}</tr>\n";