66084bc732e3f92c469308a1f6a6dbb675954cb7
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 $current;
20 /* private */ var $repo;
21 /* private */ var $time;
22 /* private */ var $fileLoaded;
23 var $mExtraDescription = false;
26 function __construct( $title, $time = null ) {
27 parent
::__construct( $title );
30 $time = is_null($time) ?
$time : $wgRequest->getVal( 'filetimestamp' );
36 protected function loadFile() {
37 if( $this->fileLoaded
) {
40 $this->img
= wfFindFile( $this->mTitle
, $this->time
);
42 $this->img
= wfLocalFile( $this->mTitle
);
43 $this->current
= $this->img
;
45 $this->current
= $this->time ?
wfLocalFile( $this->mTitle
) : $this->img
;
47 $this->repo
= $this->img
->getRepo();
48 $this->fileLoaded
= true;
52 * Handler for action=render
53 * Include body text only; none of the image extras
57 $wgOut->setArticleBodyOnly( true );
62 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
65 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
66 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
67 // mTitle is the same as the redirect target so ask Article
68 // to perform the redirect for us.
69 return Article
::view();
71 // mTitle is not the same as the redirect target so it is
72 // probably the redirect page itself. Fake the redirect symbol
73 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
74 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
75 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
81 $diff = $wgRequest->getVal( 'diff' );
82 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
84 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
85 return Article
::view();
87 if ($wgShowEXIF && $this->img
->exists()) {
88 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
89 $formattedMetadata = $this->img
->formatMetadata();
90 $showmeta = $formattedMetadata !== false;
95 if ($this->img
->exists())
96 $wgOut->addHTML($this->showTOC($showmeta));
98 $this->openShowImage();
100 # No need to display noarticletext, we use our own message, output in openShowImage()
101 if ( $this->getID() ) {
104 # Just need to set the right headers
105 $wgOut->setArticleFlag( true );
106 $wgOut->setRobotpolicy( 'noindex,nofollow' );
107 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
108 $this->viewUpdates();
111 # Show shared description, if needed
112 if ( $this->mExtraDescription
) {
113 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
114 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
115 $wgOut->addWikiText( $fol );
117 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
119 $this->checkSharedConflict();
122 $this->closeShowImage();
123 $this->imageHistory();
124 // TODO: Cleanup the following
126 $wgOut->addHTML( Xml
::element( 'h2',
127 array( 'id' => 'filelinks' ),
128 wfMsg( 'imagelinks' ) ) . "\n" );
130 // TODO: We may want to find local images redirecting to a foreign
131 // file: "The following local files redirect to this file"
132 if ( $this->img
->isLocal() ) $this->imageRedirects();
136 global $wgStylePath, $wgStyleVersion;
137 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
138 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
139 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
140 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
141 $wgOut->addScriptFile( 'metadata.js' );
143 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
147 public function getRedirectTarget() {
149 if ( $this->img
->isLocal() ) {
150 return parent
::getRedirectTarget();
152 // Foreign image page
153 $from = $this->img
->getRedirected();
154 $to = $this->img
->getName();
155 if ( $from == $to ) {
158 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
160 public function followRedirect() {
162 if ( $this->img
->isLocal() ) {
163 return parent
::followRedirect();
165 $from = $this->img
->getRedirected();
166 $to = $this->img
->getName();
167 if ( $from == $to ) {
170 return Title
::makeTitle( NS_IMAGE
, $to );
172 public function isRedirect( $text = false ) {
174 if ( $this->img
->isLocal() )
175 return parent
::isRedirect( $text );
177 return (bool)$this->img
->getRedirected();
180 public function isLocal() {
182 return $this->img
->isLocal();
185 public function getFile() {
190 public function getDuplicates() {
192 if ( !is_null($this->dupes
) ) {
195 if ( !( $hash = $this->img
->getSha1() ) ) {
196 return $this->dupes
= array();
198 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
199 // Remove duplicates with self and non matching file sizes
200 $self = $this->img
->getRepoName().':'.$this->img
->getName();
201 $size = $this->img
->getSize();
202 foreach ( $dupes as $index => $file ) {
203 $key = $file->getRepoName().':'.$file->getName();
205 unset( $dupes[$index] );
206 if ( $file->getSize() != $size )
207 unset( $dupes[$index] );
209 return $this->dupes
= $dupes;
219 * @param bool $metadata Whether or not to show the metadata link
222 function showTOC( $metadata ) {
224 $r = '<ul id="filetoc">
225 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
226 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
227 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
228 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
234 * Make a table with metadata to be shown in the output page.
236 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
240 * @param array $exif The array containing the EXIF data
243 function makeMetadataTable( $metadata ) {
244 $r = wfMsg( 'metadata-help' ) . "\n\n";
245 $r .= "{| id=mw_metadata class=mw_metadata\n";
246 foreach ( $metadata as $type => $stuff ) {
247 foreach ( $stuff as $v ) {
248 $class = Sanitizer
::escapeId( $v['id'] );
249 if( $type == 'collapsed' ) {
250 $class .= ' collapsable';
252 $r .= "|- class=\"$class\"\n";
253 $r .= "!| {$v['name']}\n";
254 $r .= "|| {$v['value']}\n";
262 * Overloading Article's getContent method.
264 * Omit noarticletext if sharedupload; text will be fetched from the
265 * shared upload server if possible.
267 function getContent() {
269 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
272 return Article
::getContent();
275 function openShowImage() {
276 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
280 $full_url = $this->img
->getURL();
281 $linkAttribs = false;
282 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
283 if( !isset( $wgImageLimits[$sizeSel] ) ) {
284 $sizeSel = User
::getDefaultOption( 'imagesize' );
286 // The user offset might still be incorrect, specially if
287 // $wgImageLimits got changed (see bug #8858).
288 if( !isset( $wgImageLimits[$sizeSel] ) ) {
289 // Default to the first offset in $wgImageLimits
293 $max = $wgImageLimits[$sizeSel];
295 $maxHeight = $max[1];
296 $sk = $wgUser->getSkin();
297 $dirmark = $wgContLang->getDirMark();
299 if ( $this->img
->exists() ) {
301 $page = $wgRequest->getIntOrNull( 'page' );
302 if ( is_null( $page ) ) {
306 $params = array( 'page' => $page );
308 $width_orig = $this->img
->getWidth();
309 $width = $width_orig;
310 $height_orig = $this->img
->getHeight();
311 $height = $height_orig;
312 $mime = $this->img
->getMimeType();
314 $linkAttribs = array( 'href' => $full_url );
315 $longDesc = $this->img
->getLongDesc();
317 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
319 if ( $this->img
->allowInlineDisplay() ) {
322 # "Download high res version" link below the image
323 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
324 # We'll show a thumbnail of this image
325 if ( $width > $maxWidth ||
$height > $maxHeight ) {
326 # Calculate the thumbnail size.
327 # First case, the limiting factor is the width, not the height.
328 if ( $width / $height >= $maxWidth / $maxHeight ) {
329 $height = round( $height * $maxWidth / $width);
331 # Note that $height <= $maxHeight now.
333 $newwidth = floor( $width * $maxHeight / $height);
334 $height = round( $height * $newwidth / $width );
336 # Note that $height <= $maxHeight now, but might not be identical
337 # because of rounding.
339 $msgbig = wfMsgHtml( 'show-big-image' );
340 $msgsmall = wfMsgExt( 'show-big-image-thumb',
341 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
343 # Image is small enough to show full size on image page
344 $msgbig = htmlspecialchars( $this->img
->getName() );
345 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
348 $params['width'] = $width;
349 $thumbnail = $this->img
->transform( $params );
351 $anchorclose = "<br />";
352 if( $this->img
->mustRender() ) {
357 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
360 if ( $this->img
->isMultipage() ) {
361 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
366 'alt' => $this->img
->getTitle()->getPrefixedText(),
369 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
370 $thumbnail->toHtml( $options ) .
371 $anchorclose . '</div>' );
374 if ( $this->img
->isMultipage() ) {
375 $count = $this->img
->pageCount();
378 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
379 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
380 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
381 array( 'page' => $page - 1 ) );
386 if ( $page < $count ) {
387 $label = wfMsg( 'imgmultipagenext' );
388 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
389 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
390 array( 'page' => $page +
1 ) );
398 'name' => 'pageselector',
399 'action' => $wgScript,
400 'onchange' => 'document.pageselector.submit();',
404 for ( $i=1; $i <= $count; $i++
) {
405 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
407 $select = Xml
::tags( 'select',
408 array( 'id' => 'pageselector', 'name' => 'page' ),
409 implode( "\n", $options ) );
412 '</td><td><div class="multipageimagenavbox">' .
413 Xml
::openElement( 'form', $formParams ) .
414 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
415 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
416 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
417 Xml
::closeElement( 'form' ) .
418 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
422 #if direct link is allowed but it's not a renderable image, show an icon.
423 if ($this->img
->isSafeFile()) {
424 $icon= $this->img
->iconThumb();
426 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
427 $icon->toHtml( array( 'desc-link' => true ) ) .
436 $filename = wfEscapeWikiText( $this->img
->getName() );
438 if (!$this->img
->isSafeFile()) {
439 $warning = wfMsgNoTrans( 'mediawarning' );
440 $wgOut->addWikiText( <<<EOT
441 <div class="fullMedia">
442 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
443 <span class="fileInfo"> $longDesc</span>
446 <div class="mediaWarning">$warning</div>
450 $wgOut->addWikiText( <<<EOT
451 <div class="fullMedia">
452 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
459 if(!$this->img
->isLocal()) {
460 $this->printSharedImageText();
463 # Image does not exist
465 $title = SpecialPage
::getTitleFor( 'Upload' );
466 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
467 'wpDestFile=' . urlencode( $this->img
->getName() ) );
468 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
473 * Show a notice that the file is from a shared repository
475 function printSharedImageText() {
476 global $wgOut, $wgUser;
480 $descUrl = $this->img
->getDescriptionUrl();
481 $descText = $this->img
->getDescriptionText();
482 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
484 $sk = $wgUser->getSkin();
485 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
486 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
487 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
489 # Show message only if not voided by local sysops
494 $wgOut->addHTML( $s );
497 $this->mExtraDescription
= $descText;
502 * Check for files with the same name on the foreign repos.
504 function checkSharedConflict() {
505 global $wgOut, $wgUser;
507 $repoGroup = RepoGroup
::singleton();
508 if( !$repoGroup->hasForeignRepos() ) {
513 if( !$this->img
->isLocal() ) {
517 $this->dupFile
= null;
518 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
520 if( !$this->dupFile
)
522 $dupfile = $this->dupFile
;
524 ($this->img
->getSha1() == $dupfile->getSha1()) &&
525 ($this->img
->getSize() == $dupfile->getSize())
528 $sk = $wgUser->getSkin();
529 $descUrl = $dupfile->getDescriptionUrl();
531 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
532 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
534 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
535 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
539 function checkSharedConflictCallback( $repo ) {
541 $dupfile = $repo->newFile( $this->img
->getTitle() );
542 if( $dupfile->exists() ) {
543 $this->dupFile
= $dupfile;
545 return $dupfile->exists();
548 function getUploadUrl() {
550 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
551 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
555 * Print out the various links at the bottom of the image page, e.g. reupload,
556 * external editing (and instructions link) etc.
558 function uploadLinksBox() {
559 global $wgUser, $wgOut;
562 if( !$this->img
->isLocal() )
565 $sk = $wgUser->getSkin();
567 $wgOut->addHtml( '<br /><ul>' );
569 # "Upload a new version of this file" link
570 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
571 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
572 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
575 # Link to Special:FileDuplicateSearch
576 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
577 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
579 # External editing link
580 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
581 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
583 $wgOut->addHtml( '</ul>' );
586 function closeShowImage()
593 * If the page we've just displayed is in the "Image" namespace,
594 * we follow it with an upload history of the image and its usage.
596 function imageHistory()
598 global $wgUser, $wgOut, $wgUseExternalEditor;
600 $sk = $wgUser->getSkin();
603 if ( $this->img
->exists() ) {
604 $list = new ImageHistoryList( $sk, $this->current
, $this->img
);
605 $file = $this->current
;
606 $dims = $file->getDimensionsString();
607 $s = $list->beginImageHistoryList();
608 $s .= $list->imageHistoryLine( true, $file );
609 // old image versions
610 $hist = $this->img
->getHistory();
611 foreach( $hist as $file ) {
612 $dims = $file->getDimensionsString();
613 $s .= $list->imageHistoryLine( false, $file );
615 $s .= $list->endImageHistoryList();
617 $wgOut->addHTML( $s );
619 $this->img
->resetHistory(); // free db resources
621 # Exist check because we don't want to show this on pages where an image
622 # doesn't exist along with the noimage message, that would suck. -ævar
623 if( $wgUseExternalEditor && $this->img
->exists() ) {
624 $this->uploadLinksBox();
629 function imageLinks()
631 global $wgUser, $wgOut;
635 $dbr = wfGetDB( DB_SLAVE
);
638 array( 'imagelinks', 'page' ),
639 array( 'page_namespace', 'page_title' ),
640 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
642 array( 'LIMIT' => $limit +
1)
645 if ( 0 == $dbr->numRows( $res ) ) {
646 $wgOut->addWikiMsg( 'nolinkstoimage' );
649 $wgOut->addWikiMsg( 'linkstoimage' );
650 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
652 $sk = $wgUser->getSkin();
654 while ( $s = $res->fetchObject() ) {
656 if ( $count <= $limit ) {
657 // We have not yet reached the extra one that tells us there is more to fetch
658 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
659 $link = $sk->makeKnownLinkObj( $name, "" );
660 $wgOut->addHTML( "<li>{$link}</li>\n" );
663 $wgOut->addHTML( "</ul>\n" );
666 // Add a links to [[Special:Whatlinkshere]]
667 if ( $count > $limit )
668 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
671 function imageRedirects()
673 global $wgUser, $wgOut;
675 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
676 if ( count( $redirects ) == 0 ) return;
679 $wgOut->addWikiMsg( 'redirectstofile' );
680 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
682 $sk = $wgUser->getSkin();
683 foreach ( $redirects as $title ) {
684 $link = $sk->makeKnownLinkObj( $title, "" );
685 $wgOut->addHTML( "<li>{$link}</li>\n" );
687 $wgOut->addHTML( "</ul>\n" );
691 function imageDupes() {
692 global $wgOut, $wgUser;
696 $dupes = $this->getDuplicates();
697 if ( count( $dupes ) == 0 ) return;
699 $wgOut->addWikiMsg( 'duplicatesoffile' );
700 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
702 $sk = $wgUser->getSkin();
703 foreach ( $dupes as $file ) {
704 if ( $file->isLocal() )
705 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
707 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
708 $file->getTitle()->getPrefixedText() );
709 $wgOut->addHTML( "<li>{$link}</li>\n" );
711 $wgOut->addHTML( "</ul>\n" );
715 * Delete the file, or an earlier version of it
717 public function delete() {
719 if( !$this->img
->exists() ||
!$this->img
->isLocal() ) {
720 // Standard article deletion
724 $deleter = new FileDeleteForm( $this->img
);
729 * Revert the file to an earlier version
731 public function revert() {
733 $reverter = new FileRevertForm( $this->img
);
734 $reverter->execute();
738 * Override handling of action=purge
742 if( $this->img
->exists() ) {
743 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
744 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
746 $this->img
->upgradeRow();
747 $this->img
->purgeCache();
749 wfDebug( "ImagePage::doPurge no image\n" );
755 * Display an error with a wikitext description
757 function showError( $description ) {
759 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
760 $wgOut->setRobotpolicy( "noindex,nofollow" );
761 $wgOut->setArticleRelated( false );
762 $wgOut->enableClientCache( false );
763 $wgOut->addWikiText( $description );
769 * Builds the image revision log shown on image pages
773 class ImageHistoryList
{
775 protected $img, $skin, $title, $repo;
777 public function __construct( $skin, $curimg, $img ) {
779 $this->current
= $curimg;
781 $this->title
= $img->getTitle();
784 public function beginImageHistoryList() {
785 global $wgOut, $wgUser;
786 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
787 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
788 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
790 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
791 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
792 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
793 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
794 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
798 public function endImageHistoryList() {
802 public function imageHistoryLine( $iscur, $file ) {
803 global $wgUser, $wgLang, $wgContLang, $wgTitle;
805 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
806 $img = $iscur ?
$file->getName() : $file->getArchiveName();
807 $user = $file->getUser('id');
808 $usertext = $file->getUser('text');
809 $size = $file->getSize();
810 $description = $file->getDescription();
811 $dims = $file->getDimensionsString();
812 $sha1 = $file->getSha1();
814 $local = $this->current
->isLocal();
815 $row = $css = $selected = '';
818 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
820 # Link to remove from history
821 if( $wgUser->isAllowed( 'delete' ) ) {
823 $q[] = 'action=delete';
825 $q[] = 'oldimage=' . urlencode( $img );
826 $row .= $this->skin
->makeKnownLinkObj(
828 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
832 # Link to hide content
833 if( $wgUser->isAllowed( 'deleterevision' ) ) {
834 if( $wgUser->isAllowed('delete') ) {
837 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
838 // If file is top revision or locked from this user, don't link
839 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
840 $del = wfMsgHtml( 'rev-delundel' );
842 // If the file was hidden, link to sha-1
843 list($ts,$name) = explode('!',$img,2);
844 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
845 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
846 '&oldimage=' . urlencode( $ts ) );
847 // Bolden oversighted content
848 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
849 $del = "<strong>$del</strong>";
851 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
856 // Reversion link/current indicator
859 $row .= wfMsgHtml( 'filehist-current' );
860 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
861 if( $file->isDeleted(File
::DELETED_FILE
) ) {
862 $row .= wfMsgHtml('filehist-revert');
865 $q[] = 'action=revert';
866 $q[] = 'oldimage=' . urlencode( $img );
867 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
868 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
869 wfMsgHtml( 'filehist-revert' ),
870 implode( '&', $q ) );
875 // Date/time and image link
876 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
877 $selected = "class='filehistory-selected'";
879 $row .= "<td $selected style='white-space: nowrap;'>";
880 if( !$file->userCan(File
::DELETED_FILE
) ) {
881 # Don't link to unviewable files
882 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
883 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
884 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
885 # Make a link to review the image
886 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
887 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
888 $row .= '<span class="history-deleted">'.$url.'</span>';
890 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
891 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
897 $row .= htmlspecialchars( $dims );
900 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
905 // Hide deleted usernames
906 if( $file->isDeleted(File
::DELETED_USER
) ) {
907 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
909 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
910 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
913 $row .= htmlspecialchars( $usertext );
917 // Don't show deleted descriptions
918 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
919 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
921 $row .= $this->skin
->commentBlock( $description, $this->title
);
925 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
926 $trCSS = $css ?
" class='$css'" : "";
928 return "<tr{$trCSS}>{$row}</tr>\n";