8 if( !defined( 'MEDIAWIKI' ) )
12 * Special handling for image description pages
16 class ImagePage
extends Article
{
18 /* private */ var $img; // Image object this page is shown for
19 /* private */ var $repo;
20 var $mExtraDescription = false;
22 function __construct( $title, $time = false ) {
23 parent
::__construct( $title );
24 $this->img
= wfFindFile( $this->mTitle
, $time );
26 $this->img
= wfLocalFile( $this->mTitle
);
27 $this->current
= $this->img
;
29 $this->current
= $time ?
wfLocalFile( $this->mTitle
) : $this->img
;
31 $this->repo
= $this->img
->repo
;
35 * Handler for action=render
36 * Include body text only; none of the image extras
40 $wgOut->setArticleBodyOnly( true );
45 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
47 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
48 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
49 // mTitle is the same as the redirect target so ask Article
50 // to perform the redirect for us.
51 return Article
::view();
53 // mTitle is not the same as the redirect target so it is
54 // probably the redirect page itself. Fake the redirect symbol
55 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
56 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
57 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
63 $diff = $wgRequest->getVal( 'diff' );
64 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
66 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
67 return Article
::view();
69 if ($wgShowEXIF && $this->img
->exists()) {
70 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
71 $formattedMetadata = $this->img
->formatMetadata();
72 $showmeta = $formattedMetadata !== false;
77 if ($this->img
->exists())
78 $wgOut->addHTML($this->showTOC($showmeta));
80 $this->openShowImage();
82 # No need to display noarticletext, we use our own message, output in openShowImage()
83 if ( $this->getID() ) {
86 # Just need to set the right headers
87 $wgOut->setArticleFlag( true );
88 $wgOut->setRobotpolicy( 'noindex,nofollow' );
89 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
93 # Show shared description, if needed
94 if ( $this->mExtraDescription
) {
95 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
96 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
97 $wgOut->addWikiText( $fol );
99 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
101 $this->checkSharedConflict();
104 $this->closeShowImage();
105 $this->imageHistory();
106 // TODO: Cleanup the following
109 // TODO: We may want to find local images redirecting to a foreign
110 // file: "The following local files redirect to this file"
111 if ( $this->img
->isLocal() ) $this->imageRedirects();
114 global $wgStylePath, $wgStyleVersion;
115 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
116 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
117 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
118 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
119 $wgOut->addScriptFile( 'metadata.js' );
121 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
125 public function getRedirectTarget() {
126 if ( $this->img
->isLocal() )
127 return parent
::getRedirectTarget();
129 // Foreign image page
130 $from = $this->img
->getRedirected();
131 $to = $this->img
->getName();
132 if ($from == $to) return null;
133 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
135 public function followRedirect() {
136 if ( $this->img
->isLocal() )
137 return parent
::followRedirect();
139 $from = $this->img
->getRedirected();
140 $to = $this->img
->getName();
141 if ($from == $to) return false;
142 return Title
::makeTitle( NS_IMAGE
, $to );
144 public function isRedirect( $text = false ) {
145 if ( $this->img
->isLocal() )
146 return parent
::isRedirect( $text );
148 return (bool)$this->img
->getRedirected();
151 public function isLocal() {
152 return $this->img
->isLocal();
155 public function getFile() {
164 * @param bool $metadata Whether or not to show the metadata link
167 function showTOC( $metadata ) {
169 $r = '<ul id="filetoc">
170 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
171 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
172 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
173 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
179 * Make a table with metadata to be shown in the output page.
181 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
185 * @param array $exif The array containing the EXIF data
188 function makeMetadataTable( $metadata ) {
189 $r = wfMsg( 'metadata-help' ) . "\n\n";
190 $r .= "{| id=mw_metadata class=mw_metadata\n";
191 foreach ( $metadata as $type => $stuff ) {
192 foreach ( $stuff as $v ) {
193 $class = Sanitizer
::escapeId( $v['id'] );
194 if( $type == 'collapsed' ) {
195 $class .= ' collapsable';
197 $r .= "|- class=\"$class\"\n";
198 $r .= "!| {$v['name']}\n";
199 $r .= "|| {$v['value']}\n";
207 * Overloading Article's getContent method.
209 * Omit noarticletext if sharedupload; text will be fetched from the
210 * shared upload server if possible.
212 function getContent() {
213 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
216 return Article
::getContent();
219 function openShowImage() {
220 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
222 $full_url = $this->img
->getURL();
223 $linkAttribs = false;
224 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
225 if( !isset( $wgImageLimits[$sizeSel] ) ) {
226 $sizeSel = User
::getDefaultOption( 'imagesize' );
228 // The user offset might still be incorrect, specially if
229 // $wgImageLimits got changed (see bug #8858).
230 if( !isset( $wgImageLimits[$sizeSel] ) ) {
231 // Default to the first offset in $wgImageLimits
235 $max = $wgImageLimits[$sizeSel];
237 $maxHeight = $max[1];
238 $sk = $wgUser->getSkin();
239 $dirmark = $wgContLang->getDirMark();
241 if ( $this->img
->exists() ) {
243 $page = $wgRequest->getIntOrNull( 'page' );
244 if ( is_null( $page ) ) {
248 $params = array( 'page' => $page );
250 $width_orig = $this->img
->getWidth();
251 $width = $width_orig;
252 $height_orig = $this->img
->getHeight();
253 $height = $height_orig;
254 $mime = $this->img
->getMimeType();
256 $linkAttribs = array( 'href' => $full_url );
257 $longDesc = $this->img
->getLongDesc();
259 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
261 if ( $this->img
->allowInlineDisplay() ) {
264 # "Download high res version" link below the image
265 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
266 # We'll show a thumbnail of this image
267 if ( $width > $maxWidth ||
$height > $maxHeight ) {
268 # Calculate the thumbnail size.
269 # First case, the limiting factor is the width, not the height.
270 if ( $width / $height >= $maxWidth / $maxHeight ) {
271 $height = round( $height * $maxWidth / $width);
273 # Note that $height <= $maxHeight now.
275 $newwidth = floor( $width * $maxHeight / $height);
276 $height = round( $height * $newwidth / $width );
278 # Note that $height <= $maxHeight now, but might not be identical
279 # because of rounding.
281 $msgbig = wfMsgHtml( 'show-big-image' );
282 $msgsmall = wfMsgExt( 'show-big-image-thumb',
283 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
285 # Image is small enough to show full size on image page
286 $msgbig = htmlspecialchars( $this->img
->getName() );
287 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
290 $params['width'] = $width;
291 $thumbnail = $this->img
->transform( $params );
293 $anchorclose = "<br />";
294 if( $this->img
->mustRender() ) {
299 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
302 if ( $this->img
->isMultipage() ) {
303 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
308 'alt' => $this->img
->getTitle()->getPrefixedText(),
311 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
312 $thumbnail->toHtml( $options ) .
313 $anchorclose . '</div>' );
316 if ( $this->img
->isMultipage() ) {
317 $count = $this->img
->pageCount();
320 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
321 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
322 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
323 array( 'page' => $page - 1 ) );
328 if ( $page < $count ) {
329 $label = wfMsg( 'imgmultipagenext' );
330 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
331 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
332 array( 'page' => $page +
1 ) );
340 'name' => 'pageselector',
341 'action' => $wgScript,
342 'onchange' => 'document.pageselector.submit();',
346 for ( $i=1; $i <= $count; $i++
) {
347 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
349 $select = Xml
::tags( 'select',
350 array( 'id' => 'pageselector', 'name' => 'page' ),
351 implode( "\n", $options ) );
354 '</td><td><div class="multipageimagenavbox">' .
355 Xml
::openElement( 'form', $formParams ) .
356 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
357 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
358 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
359 Xml
::closeElement( 'form' ) .
360 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
364 #if direct link is allowed but it's not a renderable image, show an icon.
365 if ($this->img
->isSafeFile()) {
366 $icon= $this->img
->iconThumb();
368 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
369 $icon->toHtml( array( 'desc-link' => true ) ) .
378 $filename = wfEscapeWikiText( $this->img
->getName() );
380 if (!$this->img
->isSafeFile()) {
381 $warning = wfMsgNoTrans( 'mediawarning' );
382 $wgOut->addWikiText( <<<EOT
383 <div class="fullMedia">
384 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
385 <span class="fileInfo"> $longDesc</span>
388 <div class="mediaWarning">$warning</div>
392 $wgOut->addWikiText( <<<EOT
393 <div class="fullMedia">
394 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
401 if(!$this->img
->isLocal()) {
402 $this->printSharedImageText();
405 # Image does not exist
407 $title = SpecialPage
::getTitleFor( 'Upload' );
408 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
409 'wpDestFile=' . urlencode( $this->img
->getName() ) );
410 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
415 * Show a notice that the file is from a shared repository
417 function printSharedImageText() {
418 global $wgOut, $wgUser;
420 $descUrl = $this->img
->getDescriptionUrl();
421 $descText = $this->img
->getDescriptionText();
422 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
424 $sk = $wgUser->getSkin();
425 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
426 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
427 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
429 # Show message only if not voided by local sysops
434 $wgOut->addHTML( $s );
437 $this->mExtraDescription
= $descText;
441 function checkSharedConflict() {
442 global $wgOut, $wgUser;
443 $repoGroup = RepoGroup
::singleton();
444 if( !$repoGroup->hasForeignRepos() ) {
447 if( !$this->img
->isLocal() ) {
451 $this->dupFile
= null;
452 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
454 if( !$this->dupFile
)
456 $dupfile = $this->dupFile
;
458 ($this->img
->getSha1() == $dupfile->getSha1()) &&
459 ($this->img
->getSize() == $dupfile->getSize())
462 $sk = $wgUser->getSkin();
463 $descUrl = $dupfile->getDescriptionUrl();
465 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
466 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
468 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
469 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
473 function checkSharedConflictCallback( $repo ) {
474 $dupfile = $repo->newFile( $this->img
->getTitle() );
475 if( $dupfile->exists() )
476 $this->dupFile
= $dupfile;
477 return $dupfile->exists();
480 function getUploadUrl() {
481 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
482 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
486 * Print out the various links at the bottom of the image page, e.g. reupload,
487 * external editing (and instructions link) etc.
489 function uploadLinksBox() {
490 global $wgUser, $wgOut;
492 if( !$this->img
->isLocal() )
495 $sk = $wgUser->getSkin();
497 $wgOut->addHtml( '<br /><ul>' );
499 # "Upload a new version of this file" link
500 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
501 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
502 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
505 # Link to Special:FileDuplicateSearch
506 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
507 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
509 # External editing link
510 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
511 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
513 $wgOut->addHtml( '</ul>' );
516 function closeShowImage()
523 * If the page we've just displayed is in the "Image" namespace,
524 * we follow it with an upload history of the image and its usage.
526 function imageHistory()
528 global $wgUser, $wgOut, $wgUseExternalEditor;
530 $sk = $wgUser->getSkin();
532 if ( $this->img
->exists() ) {
533 $list = new ImageHistoryList( $sk, $this->current
);
534 $file = $this->current
;
535 $dims = $file->getDimensionsString();
536 $s = $list->beginImageHistoryList() .
537 $list->imageHistoryLine( true, $file );
538 // old image versions
539 $hist = $this->img
->getHistory();
540 foreach( $hist as $file ) {
541 $dims = $file->getDimensionsString();
542 $s .= $list->imageHistoryLine( false, $file );
544 $s .= $list->endImageHistoryList();
546 $wgOut->addHTML( $s );
548 $this->img
->resetHistory(); // free db resources
550 # Exist check because we don't want to show this on pages where an image
551 # doesn't exist along with the noimage message, that would suck. -ævar
552 if( $wgUseExternalEditor && $this->img
->exists() ) {
553 $this->uploadLinksBox();
558 function imageLinks()
560 global $wgUser, $wgOut;
564 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
566 $dbr = wfGetDB( DB_SLAVE
);
569 array( 'imagelinks', 'page' ),
570 array( 'page_namespace', 'page_title' ),
571 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
573 array( 'LIMIT' => $limit +
1)
576 if ( 0 == $dbr->numRows( $res ) ) {
577 $wgOut->addWikiMsg( 'nolinkstoimage' );
580 $wgOut->addWikiMsg( 'linkstoimage' );
581 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
583 $sk = $wgUser->getSkin();
585 while ( $s = $res->fetchObject() ) {
587 if ( $count <= $limit ) {
588 // We have not yet reached the extra one that tells us there is more to fetch
589 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
590 $link = $sk->makeKnownLinkObj( $name, "" );
591 $wgOut->addHTML( "<li>{$link}</li>\n" );
594 $wgOut->addHTML( "</ul>\n" );
597 // Add a links to [[Special:Whatlinkshere]]
598 if ( $count > $limit )
599 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
602 function imageRedirects()
604 global $wgUser, $wgOut;
606 $dbr = wfGetDB( DB_SLAVE
);
608 array( 'redirect', 'page' ),
609 array( 'page_title' ),
611 'rd_namespace' => NS_IMAGE
,
612 'rd_title' => $this->mTitle
->getDBkey(),
613 'page_namespace' => NS_IMAGE
,
620 if ( 0 == $dbr->numRows( $res ) )
623 $wgOut->addWikiMsg( 'redirectstofile' );
624 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
626 $sk = $wgUser->getSkin();
627 while ( $row = $dbr->fetchObject( $res ) ) {
628 $name = Title
::makeTitle( NS_IMAGE
, $row->page_title
);
629 $link = $sk->makeKnownLinkObj( $name, "" );
630 wfDebug("Image redirect: {$row->page_title}\n");
631 $wgOut->addHTML( "<li>{$link}</li>\n" );
633 $wgOut->addHTML( "</ul>\n" );
638 function imageDupes() {
639 global $wgOut, $wgUser;
641 if ( !( $hash = $this->img
->getSha1() ) ) return;
642 // Probably deprecates checkSharedConflict?
643 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
644 //$dupes = RepoGroup::singleton()->getLocalRepo()->findBySha1( $hash );
646 // Don't dupe with self
647 $self = $this->img
->getRepoName().':'.$this->img
->getName();
648 foreach ( $dupes as $index => $file ) {
649 $key = $file->getRepoName().':'.$file->getName();
651 unset( $dupes[$index] );
653 if ( count( $dupes ) == 0 ) return;
655 $wgOut->addWikiMsg( 'duplicatesoffile' );
656 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
658 $sk = $wgUser->getSkin();
659 foreach ( $dupes as $file ) {
660 if ( $file->isLocal() )
661 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
663 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
664 $file->getTitle()->getPrefixedText() );
665 $wgOut->addHTML( "<li>{$link}</li>\n" );
667 $wgOut->addHTML( "</ul>\n" );
671 * Delete the file, or an earlier version of it
673 public function delete() {
674 if( !$this->img
->exists() ||
!$this->img
->isLocal() ) {
675 // Standard article deletion
679 $deleter = new FileDeleteForm( $this->img
);
684 * Revert the file to an earlier version
686 public function revert() {
687 $reverter = new FileRevertForm( $this->img
);
688 $reverter->execute();
692 * Override handling of action=purge
695 if( $this->img
->exists() ) {
696 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
697 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
699 $this->img
->upgradeRow();
700 $this->img
->purgeCache();
702 wfDebug( "ImagePage::doPurge no image\n" );
708 * Display an error with a wikitext description
710 function showError( $description ) {
712 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
713 $wgOut->setRobotpolicy( "noindex,nofollow" );
714 $wgOut->setArticleRelated( false );
715 $wgOut->enableClientCache( false );
716 $wgOut->addWikiText( $description );
722 * Builds the image revision log shown on image pages
726 class ImageHistoryList
{
728 protected $img, $skin, $title, $repo;
730 public function __construct( $skin, $img ) {
733 $this->title
= $img->getTitle();
736 public function beginImageHistoryList() {
737 global $wgOut, $wgUser;
738 $deleteColumn = $wgUser->isAllowed( 'delete' ) ||
$wgUser->isAllowed( 'deleterevision' );
739 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
740 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
741 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
743 . ( $this->img
->isLocal() && $deleteColumn ?
'<td></td>' : '' )
744 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
745 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
746 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
747 . '<th class="mw-imagepage-filesize">' . wfMsgHtml( 'filehist-filesize' ) . '</th>'
748 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
752 public function endImageHistoryList() {
756 public function imageHistoryLine( $iscur, $file ) {
757 global $wgUser, $wgLang, $wgContLang, $wgTitle;
759 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
760 $img = $iscur ?
$file->getName() : $file->getArchiveName();
761 $user = $file->getUser('id');
762 $usertext = $file->getUser('text');
763 $size = $file->getSize();
764 $description = $file->getDescription();
765 $dims = $file->getDimensionsString();
766 $sha1 = $file->getSha1();
768 $local = $this->img
->isLocal();
772 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
774 # Link to remove from history
775 if( $wgUser->isAllowed( 'delete' ) ) {
777 $q[] = 'action=delete';
779 $q[] = 'oldimage=' . urlencode( $img );
780 $row .= $this->skin
->makeKnownLinkObj(
782 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
787 # Link to hide content
788 if( $wgUser->isAllowed( 'deleterevision' ) ) {
789 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
790 // If file is top revision or locked from this user, don't link
791 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
792 $del = wfMsgHtml( 'rev-delundel' );
794 // If the file was hidden, link to sha-1
795 list($ts,$name) = explode('!',$img,2);
796 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
797 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
798 '&oldimage=' . urlencode( $ts ) );
799 // Bolden oversighted content
800 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
801 $del = "<strong>$del</strong>";
803 $row .= "<tt><small>$del</small></tt>";
808 // Reversion link/current indicator
811 $row .= wfMsgHtml( 'filehist-current' );
812 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
813 if( $file->isDeleted(File
::DELETED_FILE
) ) {
814 $row .= wfMsgHtml('filehist-revert');
817 $q[] = 'action=revert';
818 $q[] = 'oldimage=' . urlencode( $img );
819 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
820 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
821 wfMsgHtml( 'filehist-revert' ),
822 implode( '&', $q ) );
827 // Date/time and image link
829 if( !$file->userCan(File
::DELETED_FILE
) ) {
830 # Don't link to unviewable files
831 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
832 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
833 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
834 # Make a link to review the image
835 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
836 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->img
->getExtension() );
837 $row .= '<span class="history-deleted">'.$url.'</span>';
839 $url = $iscur ?
$this->img
->getUrl() : $this->img
->getArchiveUrl( $img );
840 $row .= Xml
::element( 'a',
841 array( 'href' => $url ),
842 $wgLang->timeAndDate( $timestamp, true ) );
850 // Hide deleted usernames
851 if( $file->isDeleted(File
::DELETED_USER
) )
852 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
854 $row .= $this->skin
->userLink( $user, $usertext ) .
855 $this->skin
->userToolLinks( $user, $usertext );
857 $row .= htmlspecialchars( $usertext );
862 $row .= '<td>' . htmlspecialchars( $dims ) . '</td>';
865 $row .= '<td class="mw-imagepage-filesize">' . $this->skin
->formatSize( $size ) . '</td>';
867 // Don't show deleted descriptions
868 if ( $file->isDeleted(File
::DELETED_COMMENT
) )
869 $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
871 $row .= '<td>' . $this->skin
->commentBlock( $description, $this->title
) . '</td>';
873 return "<tr>{$row}</tr>\n";