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;
23 function __construct( $title, $time = null ) {
24 parent
::__construct( $title );
27 $time = is_null($time) ?
$time : $wgRequest->getVal( 'filetimestamp' );
29 $this->img
= wfFindFile( $this->mTitle
, $time );
31 $this->img
= wfLocalFile( $this->mTitle
);
32 $this->current
= $this->img
;
34 $this->current
= $time ?
wfLocalFile( $this->mTitle
) : $this->img
;
36 $this->repo
= $this->img
->getRepo();
41 * Handler for action=render
42 * Include body text only; none of the image extras
46 $wgOut->setArticleBodyOnly( true );
51 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
53 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
54 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
55 // mTitle is the same as the redirect target so ask Article
56 // to perform the redirect for us.
57 return Article
::view();
59 // mTitle is not the same as the redirect target so it is
60 // probably the redirect page itself. Fake the redirect symbol
61 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
62 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
63 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
69 $diff = $wgRequest->getVal( 'diff' );
70 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
72 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
73 return Article
::view();
75 if ($wgShowEXIF && $this->img
->exists()) {
76 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
77 $formattedMetadata = $this->img
->formatMetadata();
78 $showmeta = $formattedMetadata !== false;
83 if ($this->img
->exists())
84 $wgOut->addHTML($this->showTOC($showmeta));
86 $this->openShowImage();
88 # No need to display noarticletext, we use our own message, output in openShowImage()
89 if ( $this->getID() ) {
92 # Just need to set the right headers
93 $wgOut->setArticleFlag( true );
94 $wgOut->setRobotpolicy( 'noindex,nofollow' );
95 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
99 # Show shared description, if needed
100 if ( $this->mExtraDescription
) {
101 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
102 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
103 $wgOut->addWikiText( $fol );
105 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
107 $this->checkSharedConflict();
110 $this->closeShowImage();
111 $this->imageHistory();
112 // TODO: Cleanup the following
114 $wgOut->addHTML( Xml
::element( 'h2',
115 array( 'id' => 'filelinks' ),
116 wfMsg( 'imagelinks' ) ) . "\n" );
118 // TODO: We may want to find local images redirecting to a foreign
119 // file: "The following local files redirect to this file"
120 if ( $this->img
->isLocal() ) $this->imageRedirects();
124 global $wgStylePath, $wgStyleVersion;
125 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
126 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
127 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
128 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
129 $wgOut->addScriptFile( 'metadata.js' );
131 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
135 public function getRedirectTarget() {
136 if ( $this->img
->isLocal() )
137 return parent
::getRedirectTarget();
139 // Foreign image page
140 $from = $this->img
->getRedirected();
141 $to = $this->img
->getName();
142 if ($from == $to) return null;
143 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
145 public function followRedirect() {
146 if ( $this->img
->isLocal() )
147 return parent
::followRedirect();
149 $from = $this->img
->getRedirected();
150 $to = $this->img
->getName();
151 if ($from == $to) return false;
152 return Title
::makeTitle( NS_IMAGE
, $to );
154 public function isRedirect( $text = false ) {
155 if ( $this->img
->isLocal() )
156 return parent
::isRedirect( $text );
158 return (bool)$this->img
->getRedirected();
161 public function isLocal() {
162 return $this->img
->isLocal();
165 public function getFile() {
169 public function getDuplicates() {
170 if ( !is_null($this->dupes
) ) return $this->dupes
;
172 if ( !( $hash = $this->img
->getSha1() ) )
173 return $this->dupes
= array();
174 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
176 // Remove duplicates with self and non matching file sizes
177 $self = $this->img
->getRepoName().':'.$this->img
->getName();
178 $size = $this->img
->getSize();
179 foreach ( $dupes as $index => $file ) {
180 $key = $file->getRepoName().':'.$file->getName();
182 unset( $dupes[$index] );
183 if ( $file->getSize() != $size )
184 unset( $dupes[$index] );
186 return $this->dupes
= $dupes;
196 * @param bool $metadata Whether or not to show the metadata link
199 function showTOC( $metadata ) {
201 $r = '<ul id="filetoc">
202 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
203 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
204 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
205 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
211 * Make a table with metadata to be shown in the output page.
213 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
217 * @param array $exif The array containing the EXIF data
220 function makeMetadataTable( $metadata ) {
221 $r = wfMsg( 'metadata-help' ) . "\n\n";
222 $r .= "{| id=mw_metadata class=mw_metadata\n";
223 foreach ( $metadata as $type => $stuff ) {
224 foreach ( $stuff as $v ) {
225 $class = Sanitizer
::escapeId( $v['id'] );
226 if( $type == 'collapsed' ) {
227 $class .= ' collapsable';
229 $r .= "|- class=\"$class\"\n";
230 $r .= "!| {$v['name']}\n";
231 $r .= "|| {$v['value']}\n";
239 * Overloading Article's getContent method.
241 * Omit noarticletext if sharedupload; text will be fetched from the
242 * shared upload server if possible.
244 function getContent() {
245 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
248 return Article
::getContent();
251 function openShowImage() {
252 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
254 $full_url = $this->img
->getURL();
255 $linkAttribs = false;
256 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
257 if( !isset( $wgImageLimits[$sizeSel] ) ) {
258 $sizeSel = User
::getDefaultOption( 'imagesize' );
260 // The user offset might still be incorrect, specially if
261 // $wgImageLimits got changed (see bug #8858).
262 if( !isset( $wgImageLimits[$sizeSel] ) ) {
263 // Default to the first offset in $wgImageLimits
267 $max = $wgImageLimits[$sizeSel];
269 $maxHeight = $max[1];
270 $sk = $wgUser->getSkin();
271 $dirmark = $wgContLang->getDirMark();
273 if ( $this->img
->exists() ) {
275 $page = $wgRequest->getIntOrNull( 'page' );
276 if ( is_null( $page ) ) {
280 $params = array( 'page' => $page );
282 $width_orig = $this->img
->getWidth();
283 $width = $width_orig;
284 $height_orig = $this->img
->getHeight();
285 $height = $height_orig;
286 $mime = $this->img
->getMimeType();
288 $linkAttribs = array( 'href' => $full_url );
289 $longDesc = $this->img
->getLongDesc();
291 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
293 if ( $this->img
->allowInlineDisplay() ) {
296 # "Download high res version" link below the image
297 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
298 # We'll show a thumbnail of this image
299 if ( $width > $maxWidth ||
$height > $maxHeight ) {
300 # Calculate the thumbnail size.
301 # First case, the limiting factor is the width, not the height.
302 if ( $width / $height >= $maxWidth / $maxHeight ) {
303 $height = round( $height * $maxWidth / $width);
305 # Note that $height <= $maxHeight now.
307 $newwidth = floor( $width * $maxHeight / $height);
308 $height = round( $height * $newwidth / $width );
310 # Note that $height <= $maxHeight now, but might not be identical
311 # because of rounding.
313 $msgbig = wfMsgHtml( 'show-big-image' );
314 $msgsmall = wfMsgExt( 'show-big-image-thumb',
315 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
317 # Image is small enough to show full size on image page
318 $msgbig = htmlspecialchars( $this->img
->getName() );
319 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
322 $params['width'] = $width;
323 $thumbnail = $this->img
->transform( $params );
325 $anchorclose = "<br />";
326 if( $this->img
->mustRender() ) {
331 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
334 if ( $this->img
->isMultipage() ) {
335 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
340 'alt' => $this->img
->getTitle()->getPrefixedText(),
343 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
344 $thumbnail->toHtml( $options ) .
345 $anchorclose . '</div>' );
348 if ( $this->img
->isMultipage() ) {
349 $count = $this->img
->pageCount();
352 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
353 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
354 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
355 array( 'page' => $page - 1 ) );
360 if ( $page < $count ) {
361 $label = wfMsg( 'imgmultipagenext' );
362 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
363 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->img
, $link, $label, 'none',
364 array( 'page' => $page +
1 ) );
372 'name' => 'pageselector',
373 'action' => $wgScript,
374 'onchange' => 'document.pageselector.submit();',
378 for ( $i=1; $i <= $count; $i++
) {
379 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
381 $select = Xml
::tags( 'select',
382 array( 'id' => 'pageselector', 'name' => 'page' ),
383 implode( "\n", $options ) );
386 '</td><td><div class="multipageimagenavbox">' .
387 Xml
::openElement( 'form', $formParams ) .
388 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
389 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
390 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
391 Xml
::closeElement( 'form' ) .
392 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
396 #if direct link is allowed but it's not a renderable image, show an icon.
397 if ($this->img
->isSafeFile()) {
398 $icon= $this->img
->iconThumb();
400 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
401 $icon->toHtml( array( 'desc-link' => true ) ) .
410 $filename = wfEscapeWikiText( $this->img
->getName() );
412 if (!$this->img
->isSafeFile()) {
413 $warning = wfMsgNoTrans( 'mediawarning' );
414 $wgOut->addWikiText( <<<EOT
415 <div class="fullMedia">
416 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
417 <span class="fileInfo"> $longDesc</span>
420 <div class="mediaWarning">$warning</div>
424 $wgOut->addWikiText( <<<EOT
425 <div class="fullMedia">
426 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
433 if(!$this->img
->isLocal()) {
434 $this->printSharedImageText();
437 # Image does not exist
439 $title = SpecialPage
::getTitleFor( 'Upload' );
440 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
441 'wpDestFile=' . urlencode( $this->img
->getName() ) );
442 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
447 * Show a notice that the file is from a shared repository
449 function printSharedImageText() {
450 global $wgOut, $wgUser;
452 $descUrl = $this->img
->getDescriptionUrl();
453 $descText = $this->img
->getDescriptionText();
454 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
456 $sk = $wgUser->getSkin();
457 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
458 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
459 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
461 # Show message only if not voided by local sysops
466 $wgOut->addHTML( $s );
469 $this->mExtraDescription
= $descText;
474 * Check for files with the same name on the foreign repos.
476 function checkSharedConflict() {
477 global $wgOut, $wgUser;
478 $repoGroup = RepoGroup
::singleton();
479 if( !$repoGroup->hasForeignRepos() ) {
482 if( !$this->img
->isLocal() ) {
486 $this->dupFile
= null;
487 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
489 if( !$this->dupFile
)
491 $dupfile = $this->dupFile
;
493 ($this->img
->getSha1() == $dupfile->getSha1()) &&
494 ($this->img
->getSize() == $dupfile->getSize())
497 $sk = $wgUser->getSkin();
498 $descUrl = $dupfile->getDescriptionUrl();
500 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
501 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
503 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
504 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
508 function checkSharedConflictCallback( $repo ) {
509 $dupfile = $repo->newFile( $this->img
->getTitle() );
510 if( $dupfile->exists() )
511 $this->dupFile
= $dupfile;
512 return $dupfile->exists();
515 function getUploadUrl() {
516 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
517 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
521 * Print out the various links at the bottom of the image page, e.g. reupload,
522 * external editing (and instructions link) etc.
524 function uploadLinksBox() {
525 global $wgUser, $wgOut;
527 if( !$this->img
->isLocal() )
530 $sk = $wgUser->getSkin();
532 $wgOut->addHtml( '<br /><ul>' );
534 # "Upload a new version of this file" link
535 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
536 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
537 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
540 # Link to Special:FileDuplicateSearch
541 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
542 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
544 # External editing link
545 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
546 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
548 $wgOut->addHtml( '</ul>' );
551 function closeShowImage()
558 * If the page we've just displayed is in the "Image" namespace,
559 * we follow it with an upload history of the image and its usage.
561 function imageHistory()
563 global $wgUser, $wgOut, $wgUseExternalEditor;
565 $sk = $wgUser->getSkin();
567 if ( $this->img
->exists() ) {
568 $list = new ImageHistoryList( $sk, $this->current
, $this->img
);
569 $file = $this->current
;
570 $dims = $file->getDimensionsString();
571 $s = $list->beginImageHistoryList();
572 $s .= $list->imageHistoryLine( true, $file );
573 // old image versions
574 $hist = $this->img
->getHistory();
575 foreach( $hist as $file ) {
576 $dims = $file->getDimensionsString();
577 $s .= $list->imageHistoryLine( false, $file );
579 $s .= $list->endImageHistoryList();
581 $wgOut->addHTML( $s );
583 $this->img
->resetHistory(); // free db resources
585 # Exist check because we don't want to show this on pages where an image
586 # doesn't exist along with the noimage message, that would suck. -ævar
587 if( $wgUseExternalEditor && $this->img
->exists() ) {
588 $this->uploadLinksBox();
593 function imageLinks()
595 global $wgUser, $wgOut;
599 $dbr = wfGetDB( DB_SLAVE
);
602 array( 'imagelinks', 'page' ),
603 array( 'page_namespace', 'page_title' ),
604 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
606 array( 'LIMIT' => $limit +
1)
609 if ( 0 == $dbr->numRows( $res ) ) {
610 $wgOut->addWikiMsg( 'nolinkstoimage' );
613 $wgOut->addWikiMsg( 'linkstoimage' );
614 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
616 $sk = $wgUser->getSkin();
618 while ( $s = $res->fetchObject() ) {
620 if ( $count <= $limit ) {
621 // We have not yet reached the extra one that tells us there is more to fetch
622 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
623 $link = $sk->makeKnownLinkObj( $name, "" );
624 $wgOut->addHTML( "<li>{$link}</li>\n" );
627 $wgOut->addHTML( "</ul>\n" );
630 // Add a links to [[Special:Whatlinkshere]]
631 if ( $count > $limit )
632 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
635 function imageRedirects()
637 global $wgUser, $wgOut;
639 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
640 if ( count( $redirects ) == 0 ) return;
643 $wgOut->addWikiMsg( 'redirectstofile' );
644 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
646 $sk = $wgUser->getSkin();
647 foreach ( $redirects as $title ) {
648 $link = $sk->makeKnownLinkObj( $title, "" );
649 $wgOut->addHTML( "<li>{$link}</li>\n" );
651 $wgOut->addHTML( "</ul>\n" );
655 function imageDupes() {
656 global $wgOut, $wgUser;
658 $dupes = $this->getDuplicates();
659 if ( count( $dupes ) == 0 ) return;
661 $wgOut->addWikiMsg( 'duplicatesoffile' );
662 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
664 $sk = $wgUser->getSkin();
665 foreach ( $dupes as $file ) {
666 if ( $file->isLocal() )
667 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
669 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
670 $file->getTitle()->getPrefixedText() );
671 $wgOut->addHTML( "<li>{$link}</li>\n" );
673 $wgOut->addHTML( "</ul>\n" );
677 * Delete the file, or an earlier version of it
679 public function delete() {
680 if( !$this->img
->exists() ||
!$this->img
->isLocal() ) {
681 // Standard article deletion
685 $deleter = new FileDeleteForm( $this->img
);
690 * Revert the file to an earlier version
692 public function revert() {
693 $reverter = new FileRevertForm( $this->img
);
694 $reverter->execute();
698 * Override handling of action=purge
701 if( $this->img
->exists() ) {
702 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
703 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
705 $this->img
->upgradeRow();
706 $this->img
->purgeCache();
708 wfDebug( "ImagePage::doPurge no image\n" );
714 * Display an error with a wikitext description
716 function showError( $description ) {
718 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
719 $wgOut->setRobotpolicy( "noindex,nofollow" );
720 $wgOut->setArticleRelated( false );
721 $wgOut->enableClientCache( false );
722 $wgOut->addWikiText( $description );
728 * Builds the image revision log shown on image pages
732 class ImageHistoryList
{
734 protected $img, $skin, $title, $repo;
736 public function __construct( $skin, $curimg, $img ) {
738 $this->current
= $curimg;
740 $this->title
= $img->getTitle();
743 public function beginImageHistoryList() {
744 global $wgOut, $wgUser;
745 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
746 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
747 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
749 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
750 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
751 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
752 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
753 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
757 public function endImageHistoryList() {
761 public function imageHistoryLine( $iscur, $file ) {
762 global $wgUser, $wgLang, $wgContLang, $wgTitle;
764 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
765 $img = $iscur ?
$file->getName() : $file->getArchiveName();
766 $user = $file->getUser('id');
767 $usertext = $file->getUser('text');
768 $size = $file->getSize();
769 $description = $file->getDescription();
770 $dims = $file->getDimensionsString();
771 $sha1 = $file->getSha1();
773 $local = $this->current
->isLocal();
774 $row = $css = $selected = '';
777 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
779 # Link to remove from history
780 if( $wgUser->isAllowed( 'delete' ) ) {
782 $q[] = 'action=delete';
784 $q[] = 'oldimage=' . urlencode( $img );
785 $row .= $this->skin
->makeKnownLinkObj(
787 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
791 # Link to hide content
792 if( $wgUser->isAllowed( 'deleterevision' ) ) {
793 if( $wgUser->isAllowed('delete') ) {
796 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
797 // If file is top revision or locked from this user, don't link
798 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
799 $del = wfMsgHtml( 'rev-delundel' );
801 // If the file was hidden, link to sha-1
802 list($ts,$name) = explode('!',$img,2);
803 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
804 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
805 '&oldimage=' . urlencode( $ts ) );
806 // Bolden oversighted content
807 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
808 $del = "<strong>$del</strong>";
810 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
815 // Reversion link/current indicator
818 $row .= wfMsgHtml( 'filehist-current' );
819 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
820 if( $file->isDeleted(File
::DELETED_FILE
) ) {
821 $row .= wfMsgHtml('filehist-revert');
824 $q[] = 'action=revert';
825 $q[] = 'oldimage=' . urlencode( $img );
826 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
827 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
828 wfMsgHtml( 'filehist-revert' ),
829 implode( '&', $q ) );
834 // Date/time and image link
835 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
836 $selected = "class='filehistory-selected'";
838 $row .= "<td $selected style='white-space: nowrap;'>";
839 if( !$file->userCan(File
::DELETED_FILE
) ) {
840 # Don't link to unviewable files
841 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
842 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
843 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
844 # Make a link to review the image
845 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
846 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
847 $row .= '<span class="history-deleted">'.$url.'</span>';
849 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
850 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
856 $row .= htmlspecialchars( $dims );
859 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
864 // Hide deleted usernames
865 if( $file->isDeleted(File
::DELETED_USER
) ) {
866 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
868 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
869 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
872 $row .= htmlspecialchars( $usertext );
876 // Don't show deleted descriptions
877 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
878 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
880 $row .= $this->skin
->commentBlock( $description, $this->title
);
884 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
885 $trCSS = $css ?
" class='$css'" : "";
887 return "<tr{$trCSS}>{$row}</tr>\n";