3 if( !defined( 'MEDIAWIKI' ) )
7 * Special handling for image description pages
11 class ImagePage
extends Article
{
13 /* private */ var $img; // Image object
14 /* private */ var $displayImg;
15 /* private */ var $repo;
16 /* private */ var $fileLoaded;
17 var $mExtraDescription = false;
20 function __construct( $title ) {
21 parent
::__construct( $title );
26 protected function loadFile() {
27 if( $this->fileLoaded
) {
30 $this->fileLoaded
= true;
32 $this->displayImg
= $this->img
= false;
33 wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img
, &$this->displayImg
) );
35 $this->img
= wfFindFile( $this->mTitle
);
37 $this->img
= wfLocalFile( $this->mTitle
);
40 if( !$this->displayImg
) {
41 $this->displayImg
= $this->img
;
43 $this->repo
= $this->img
->getRepo();
47 * Handler for action=render
48 * Include body text only; none of the image extras
50 public function render() {
52 $wgOut->setArticleBodyOnly( true );
56 public function view() {
57 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
60 if( $this->mTitle
->getNamespace() == NS_FILE
&& $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 $wgOut->addHTML( $this->viewRedirect( Title
::makeTitle( NS_FILE
, $this->img
->getName() ),
70 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
76 $diff = $wgRequest->getVal( 'diff' );
77 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
79 if( $this->mTitle
->getNamespace() != NS_FILE ||
( isset( $diff ) && $diffOnly ) )
80 return Article
::view();
82 if( $wgShowEXIF && $this->displayImg
->exists() ) {
83 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
84 $formattedMetadata = $this->displayImg
->formatMetadata();
85 $showmeta = $formattedMetadata !== false;
90 if( $this->displayImg
->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() ) {
128 $this->imageRedirects();
133 global $wgStylePath, $wgStyleVersion;
134 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
135 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
136 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
137 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
138 $wgOut->addScriptFile( 'metadata.js' );
140 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
144 public function getRedirectTarget() {
146 if( $this->img
->isLocal() ) {
147 return parent
::getRedirectTarget();
149 // Foreign image page
150 $from = $this->img
->getRedirected();
151 $to = $this->img
->getName();
155 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
157 public function followRedirect() {
159 if( $this->img
->isLocal() ) {
160 return parent
::followRedirect();
162 $from = $this->img
->getRedirected();
163 $to = $this->img
->getName();
167 return Title
::makeTitle( NS_FILE
, $to );
169 public function isRedirect( $text = false ) {
171 if( $this->img
->isLocal() )
172 return parent
::isRedirect( $text );
174 return (bool)$this->img
->getRedirected();
177 public function isLocal() {
179 return $this->img
->isLocal();
182 public function getFile() {
187 public function getDisplayedFile() {
189 return $this->displayImg
;
192 public function getDuplicates() {
194 if( !is_null($this->dupes
) ) {
197 if( !( $hash = $this->img
->getSha1() ) ) {
198 return $this->dupes
= array();
200 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
201 // Remove duplicates with self and non matching file sizes
202 $self = $this->img
->getRepoName().':'.$this->img
->getName();
203 $size = $this->img
->getSize();
204 foreach ( $dupes as $index => $file ) {
205 $key = $file->getRepoName().':'.$file->getName();
207 unset( $dupes[$index] );
208 if( $file->getSize() != $size )
209 unset( $dupes[$index] );
211 return $this->dupes
= $dupes;
219 * @param bool $metadata Whether or not to show the metadata link
222 protected function showTOC( $metadata ) {
224 $r = '<ul id="filetoc">
225 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</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().
238 * @param array $exif The array containing the EXIF data
241 protected function makeMetadataTable( $metadata ) {
242 $r = wfMsg( 'metadata-help' ) . "\n\n";
243 $r .= "{| id=mw_metadata class=mw_metadata\n";
244 foreach ( $metadata as $type => $stuff ) {
245 foreach ( $stuff as $v ) {
246 $class = Sanitizer
::escapeId( $v['id'] );
247 if( $type == 'collapsed' ) {
248 $class .= ' collapsable';
250 $r .= "|- class=\"$class\"\n";
251 $r .= "!| {$v['name']}\n";
252 $r .= "|| {$v['value']}\n";
260 * Overloading Article's getContent method.
262 * Omit noarticletext if sharedupload; text will be fetched from the
263 * shared upload server if possible.
265 public function getContent() {
267 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
270 return Article
::getContent();
273 protected function openShowImage() {
274 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
278 $full_url = $this->displayImg
->getURL();
279 $linkAttribs = false;
280 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
281 if( !isset( $wgImageLimits[$sizeSel] ) ) {
282 $sizeSel = User
::getDefaultOption( 'imagesize' );
284 // The user offset might still be incorrect, specially if
285 // $wgImageLimits got changed (see bug #8858).
286 if( !isset( $wgImageLimits[$sizeSel] ) ) {
287 // Default to the first offset in $wgImageLimits
291 $max = $wgImageLimits[$sizeSel];
293 $maxHeight = $max[1];
294 $sk = $wgUser->getSkin();
295 $dirmark = $wgContLang->getDirMark();
297 if( $this->displayImg
->exists() ) {
299 $page = $wgRequest->getIntOrNull( 'page' );
300 if( is_null( $page ) ) {
304 $params = array( 'page' => $page );
306 $width_orig = $this->displayImg
->getWidth();
307 $width = $width_orig;
308 $height_orig = $this->displayImg
->getHeight();
309 $height = $height_orig;
310 $mime = $this->displayImg
->getMimeType();
312 $linkAttribs = array( 'href' => $full_url );
313 $longDesc = $this->displayImg
->getLongDesc();
315 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
317 if( $this->displayImg
->allowInlineDisplay() ) {
320 # "Download high res version" link below the image
321 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
322 # We'll show a thumbnail of this image
323 if( $width > $maxWidth ||
$height > $maxHeight ) {
324 # Calculate the thumbnail size.
325 # First case, the limiting factor is the width, not the height.
326 if( $width / $height >= $maxWidth / $maxHeight ) {
327 $height = round( $height * $maxWidth / $width);
329 # Note that $height <= $maxHeight now.
331 $newwidth = floor( $width * $maxHeight / $height);
332 $height = round( $height * $newwidth / $width );
334 # Note that $height <= $maxHeight now, but might not be identical
335 # because of rounding.
337 $msgbig = wfMsgHtml( 'show-big-image' );
338 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
339 $wgLang->formatNum( $width ),
340 $wgLang->formatNum( $height )
343 # Image is small enough to show full size on image page
344 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
345 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
348 $params['width'] = $width;
349 $thumbnail = $this->displayImg
->transform( $params );
351 $anchorclose = "<br />";
352 if( $this->displayImg
->mustRender() ) {
357 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
360 if( $this->displayImg
->isMultipage() ) {
361 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
366 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
369 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
370 $thumbnail->toHtml( $options ) .
371 $anchorclose . '</div>' );
374 if( $this->displayImg
->isMultipage() ) {
375 $count = $this->displayImg
->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->displayImg
, $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->displayImg
, $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->displayImg
->isSafeFile() ) {
424 $icon= $this->displayImg
->iconThumb();
426 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
427 $icon->toHtml( array( 'desc-link' => true ) ) .
436 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
438 if( !$this->displayImg
->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->displayImg
->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->displayImg
->getName() ) );
468 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
473 * Show a notice that the file is from a shared repository
475 protected 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 protected 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 public function checkSharedConflictCallback( $repo ) {
541 $dupfile = $repo->newFile( $this->img
->getTitle() );
542 if( $dupfile && $dupfile->exists() ) {
543 $this->dupFile
= $dupfile;
544 return $dupfile->exists();
549 public function getUploadUrl() {
551 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
552 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
556 * Print out the various links at the bottom of the image page, e.g. reupload,
557 * external editing (and instructions link) etc.
559 protected function uploadLinksBox() {
560 global $wgUser, $wgOut;
563 if( !$this->img
->isLocal() )
566 $sk = $wgUser->getSkin();
568 $wgOut->addHTML( '<br /><ul>' );
570 # "Upload a new version of this file" link
571 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
572 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
573 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
576 # Link to Special:FileDuplicateSearch
577 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
578 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
580 # External editing link
581 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
582 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
584 $wgOut->addHTML( '</ul>' );
587 protected function closeShowImage() {} # For overloading
590 * If the page we've just displayed is in the "Image" namespace,
591 * we follow it with an upload history of the image and its usage.
593 protected function imageHistory() {
594 global $wgOut, $wgUseExternalEditor;
598 if( $this->img
->exists() ) {
599 $list = new ImageHistoryList( $this );
601 $s = $list->beginImageHistoryList();
602 $s .= $list->imageHistoryLine( true, $file );
603 // old image versions
604 $hist = $this->img
->getHistory();
605 foreach( $hist as $file ) {
606 $s .= $list->imageHistoryLine( false, $file );
608 $s .= $list->endImageHistoryList();
610 $wgOut->addHTML( $s );
612 $this->img
->resetHistory(); // free db resources
614 # Exist check because we don't want to show this on pages where an image
615 # doesn't exist along with the noimage message, that would suck. -ævar
616 if( $wgUseExternalEditor && $this->img
->exists() ) {
617 $this->uploadLinksBox();
621 protected function imageLinks() {
622 global $wgUser, $wgOut, $wgLang;
626 $dbr = wfGetDB( DB_SLAVE
);
629 array( 'imagelinks', 'page' ),
630 array( 'page_namespace', 'page_title' ),
631 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
633 array( 'LIMIT' => $limit +
1)
635 $count = $dbr->numRows( $res );
637 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
638 $wgOut->addWikiMsg( 'nolinkstoimage' );
639 $wgOut->addHTML( "</div>\n" );
643 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
644 if( $count <= $limit - 1 ) {
645 $wgOut->addWikiMsg( 'linkstoimage', $count );
647 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
648 $wgOut->addWikiMsg( 'linkstoimage-more',
649 $wgLang->formatNum( $limit ),
650 $this->mTitle
->getPrefixedDBkey()
654 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
655 $sk = $wgUser->getSkin();
657 while ( $s = $res->fetchObject() ) {
659 if( $count <= $limit ) {
660 // We have not yet reached the extra one that tells us there is more to fetch
661 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
662 $link = $sk->makeKnownLinkObj( $name, "" );
663 $wgOut->addHTML( "<li>{$link}</li>\n" );
666 $wgOut->addHTML( "</ul></div>\n" );
669 // Add a links to [[Special:Whatlinkshere]]
670 if( $count > $limit )
671 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
674 protected function imageRedirects() {
675 global $wgUser, $wgOut, $wgLang;
677 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
678 if( count( $redirects ) == 0 ) return;
680 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
681 $wgOut->addWikiMsg( 'redirectstofile',
682 $wgLang->formatNum( count( $redirects ) )
684 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
686 $sk = $wgUser->getSkin();
687 foreach ( $redirects as $title ) {
688 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
689 $wgOut->addHTML( "<li>{$link}</li>\n" );
691 $wgOut->addHTML( "</ul></div>\n" );
695 protected function imageDupes() {
696 global $wgOut, $wgUser, $wgLang;
700 $dupes = $this->getDuplicates();
701 if( count( $dupes ) == 0 ) return;
703 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
704 $wgOut->addWikiMsg( 'duplicatesoffile',
705 $wgLang->formatNum( count( $dupes ) )
707 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
709 $sk = $wgUser->getSkin();
710 foreach ( $dupes as $file ) {
711 if( $file->isLocal() )
712 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
714 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
715 $file->getTitle()->getPrefixedText() );
717 $wgOut->addHTML( "<li>{$link}</li>\n" );
719 $wgOut->addHTML( "</ul></div>\n" );
723 * Delete the file, or an earlier version of it
725 public function delete() {
727 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
728 // Standard article deletion
732 $deleter = new FileDeleteForm( $this->img
);
737 * Revert the file to an earlier version
739 public function revert() {
741 $reverter = new FileRevertForm( $this->img
);
742 $reverter->execute();
746 * Override handling of action=purge
748 public function doPurge() {
750 if( $this->img
->exists() ) {
751 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
752 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
754 $this->img
->upgradeRow();
755 $this->img
->purgeCache();
757 wfDebug( "ImagePage::doPurge no image\n" );
763 * Display an error with a wikitext description
765 function showError( $description ) {
767 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
768 $wgOut->setRobotPolicy( "noindex,nofollow" );
769 $wgOut->setArticleRelated( false );
770 $wgOut->enableClientCache( false );
771 $wgOut->addWikiText( $description );
777 * Builds the image revision log shown on image pages
781 class ImageHistoryList
{
783 protected $imagePage, $img, $skin, $title, $repo;
785 public function __construct( $imagePage ) {
787 $this->skin
= $wgUser->getSkin();
788 $this->current
= $imagePage->getFile();
789 $this->img
= $imagePage->getDisplayedFile();
790 $this->title
= $imagePage->getTitle();
791 $this->imagePage
= $imagePage;
794 public function getImagePage() {
795 return $this->imagePage
;
798 public function getSkin() {
802 public function getFile() {
806 public function beginImageHistoryList() {
807 global $wgOut, $wgUser;
808 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
809 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
810 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
812 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
813 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
814 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
815 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
816 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
817 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
821 public function endImageHistoryList() {
825 public function imageHistoryLine( $iscur, $file ) {
826 global $wgUser, $wgLang, $wgContLang, $wgTitle;
828 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
829 $img = $iscur ?
$file->getName() : $file->getArchiveName();
830 $user = $file->getUser('id');
831 $usertext = $file->getUser('text');
832 $size = $file->getSize();
833 $description = $file->getDescription();
834 $dims = $file->getDimensionsString();
835 $sha1 = $file->getSha1();
837 $local = $this->current
->isLocal();
838 $row = $css = $selected = '';
841 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
843 # Link to remove from history
844 if( $wgUser->isAllowed( 'delete' ) ) {
846 $q[] = 'action=delete';
848 $q[] = 'oldimage=' . urlencode( $img );
849 $row .= $this->skin
->makeKnownLinkObj(
851 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
855 # Link to hide content
856 if( $wgUser->isAllowed( 'deleterevision' ) ) {
857 if( $wgUser->isAllowed('delete') ) {
860 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
861 // If file is top revision or locked from this user, don't link
862 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
863 $del = wfMsgHtml( 'rev-delundel' );
865 // If the file was hidden, link to sha-1
866 list($ts,$name) = explode('!',$img,2);
867 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
868 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
869 '&oldimage=' . urlencode( $ts ) );
870 // Bolden oversighted content
871 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
872 $del = "<strong>$del</strong>";
874 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
879 // Reversion link/current indicator
882 $row .= wfMsgHtml( 'filehist-current' );
883 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
884 if( $file->isDeleted(File
::DELETED_FILE
) ) {
885 $row .= wfMsgHtml('filehist-revert');
888 $q[] = 'action=revert';
889 $q[] = 'oldimage=' . urlencode( $img );
890 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
891 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
892 wfMsgHtml( 'filehist-revert' ),
893 implode( '&', $q ) );
898 // Date/time and image link
899 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
900 $selected = "class='filehistory-selected'";
902 $row .= "<td $selected style='white-space: nowrap;'>";
903 if( !$file->userCan(File
::DELETED_FILE
) ) {
904 # Don't link to unviewable files
905 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
906 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
907 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
908 # Make a link to review the image
909 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
910 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
911 $row .= '<span class="history-deleted">'.$url.'</span>';
913 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
914 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
918 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
923 $thumbnail = $file->transform( $params );
925 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
928 $row .= '</td><td>' . $thumbnail->toHtml( $options );
930 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
935 $row .= htmlspecialchars( $dims );
938 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
943 // Hide deleted usernames
944 if( $file->isDeleted(File
::DELETED_USER
) ) {
945 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
947 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
948 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
951 $row .= htmlspecialchars( $usertext );
955 // Don't show deleted descriptions
956 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
957 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
959 $row .= $this->skin
->commentBlock( $description, $this->title
);
963 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
964 $classAttr = $rowClass ?
" class='$rowClass'" : "";
966 return "<tr{$classAttr}>{$row}</tr>\n";