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 public function setFile( $file ) {
27 $this->displayImg
= $file;
29 $this->fileLoaded
= true;
32 protected function loadFile() {
33 if( $this->fileLoaded
) {
36 $this->fileLoaded
= true;
38 $this->displayImg
= $this->img
= false;
39 wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img
, &$this->displayImg
) );
41 $this->img
= wfFindFile( $this->mTitle
);
43 $this->img
= wfLocalFile( $this->mTitle
);
46 if( !$this->displayImg
) {
47 $this->displayImg
= $this->img
;
49 $this->repo
= $this->img
->getRepo();
53 * Handler for action=render
54 * Include body text only; none of the image extras
56 public function render() {
58 $wgOut->setArticleBodyOnly( true );
62 public function view() {
63 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
66 if( $this->mTitle
->getNamespace() == NS_FILE
&& $this->img
->getRedirected() ) {
67 if( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
68 // mTitle is the same as the redirect target so ask Article
69 // to perform the redirect for us.
70 return Article
::view();
72 // mTitle is not the same as the redirect target so it is
73 // probably the redirect page itself. Fake the redirect symbol
74 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
75 $wgOut->addHTML( $this->viewRedirect( Title
::makeTitle( NS_FILE
, $this->img
->getName() ),
76 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
82 $diff = $wgRequest->getVal( 'diff' );
83 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
85 if( $this->mTitle
->getNamespace() != NS_FILE ||
( isset( $diff ) && $diffOnly ) )
86 return Article
::view();
88 $this->showRedirectedFromHeader();
90 if( $wgShowEXIF && $this->displayImg
->exists() ) {
91 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
92 $formattedMetadata = $this->displayImg
->formatMetadata();
93 $showmeta = $formattedMetadata !== false;
98 if( !$diff && $this->displayImg
->exists() )
99 $wgOut->addHTML( $this->showTOC($showmeta) );
102 $this->openShowImage();
104 # No need to display noarticletext, we use our own message, output in openShowImage()
105 if( $this->getID() ) {
108 # Just need to set the right headers
109 $wgOut->setArticleFlag( true );
110 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
111 $this->viewUpdates();
114 # Show shared description, if needed
115 if( $this->mExtraDescription
) {
116 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
117 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
118 $wgOut->addWikiText( $fol );
120 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. "</div>\n" );
123 $this->closeShowImage();
124 $this->imageHistory();
125 // TODO: Cleanup the following
127 $wgOut->addHTML( Xml
::element( 'h2',
128 array( 'id' => 'filelinks' ),
129 wfMsg( 'imagelinks' ) ) . "\n" );
131 # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
132 # Yet we return metadata about the target. Definitely an issue in the FileRepo
133 $this->imageRedirects();
136 # Allow extensions to add something after the image links
138 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
140 $wgOut->addHTML( $html );
143 global $wgStylePath, $wgStyleVersion;
144 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
145 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
146 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
147 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
148 $wgOut->addScriptFile( 'metadata.js' );
150 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
154 public function getRedirectTarget() {
156 if( $this->img
->isLocal() ) {
157 return parent
::getRedirectTarget();
159 // Foreign image page
160 $from = $this->img
->getRedirected();
161 $to = $this->img
->getName();
165 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
167 public function followRedirect() {
169 if( $this->img
->isLocal() ) {
170 return parent
::followRedirect();
172 $from = $this->img
->getRedirected();
173 $to = $this->img
->getName();
177 return Title
::makeTitle( NS_FILE
, $to );
179 public function isRedirect( $text = false ) {
181 if( $this->img
->isLocal() )
182 return parent
::isRedirect( $text );
184 return (bool)$this->img
->getRedirected();
187 public function isLocal() {
189 return $this->img
->isLocal();
192 public function getFile() {
197 public function getDisplayedFile() {
199 return $this->displayImg
;
202 public function getDuplicates() {
204 if( !is_null($this->dupes
) ) {
207 if( !( $hash = $this->img
->getSha1() ) ) {
208 return $this->dupes
= array();
210 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
211 // Remove duplicates with self and non matching file sizes
212 $self = $this->img
->getRepoName().':'.$this->img
->getName();
213 $size = $this->img
->getSize();
214 foreach ( $dupes as $index => $file ) {
215 $key = $file->getRepoName().':'.$file->getName();
217 unset( $dupes[$index] );
218 if( $file->getSize() != $size )
219 unset( $dupes[$index] );
221 return $this->dupes
= $dupes;
229 * @param bool $metadata Whether or not to show the metadata link
232 protected function showTOC( $metadata ) {
234 '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
235 '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
236 '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
239 $r[] = '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>';
242 wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) );
244 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
248 * Make a table with metadata to be shown in the output page.
250 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
252 * @param array $exif The array containing the EXIF data
255 protected function makeMetadataTable( $metadata ) {
256 $r = "<div class=\"mw-imagepage-section-metadata\">";
257 $r .= wfMsgNoTrans( 'metadata-help' );
258 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
259 foreach ( $metadata as $type => $stuff ) {
260 foreach ( $stuff as $v ) {
261 # FIXME, why is this using escapeId for a class?!
262 $class = Sanitizer
::escapeId( $v['id'] );
263 if( $type == 'collapsed' ) {
264 $class .= ' collapsable';
266 $r .= "<tr class=\"$class\">\n";
267 $r .= "<th>{$v['name']}</th>\n";
268 $r .= "<td>{$v['value']}</td>\n</tr>";
271 $r .= "</table>\n</div>\n";
276 * Overloading Article's getContent method.
278 * Omit noarticletext if sharedupload; text will be fetched from the
279 * shared upload server if possible.
281 public function getContent() {
283 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
286 return Article
::getContent();
289 protected function openShowImage() {
290 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
291 $wgLang, $wgContLang, $wgEnableUploads;
295 $full_url = $this->displayImg
->getURL();
296 $linkAttribs = false;
297 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
298 if( !isset( $wgImageLimits[$sizeSel] ) ) {
299 $sizeSel = User
::getDefaultOption( 'imagesize' );
301 // The user offset might still be incorrect, specially if
302 // $wgImageLimits got changed (see bug #8858).
303 if( !isset( $wgImageLimits[$sizeSel] ) ) {
304 // Default to the first offset in $wgImageLimits
308 $max = $wgImageLimits[$sizeSel];
310 $maxHeight = $max[1];
311 $sk = $wgUser->getSkin();
312 $dirmark = $wgContLang->getDirMark();
314 if( $this->displayImg
->exists() ) {
316 $page = $wgRequest->getIntOrNull( 'page' );
317 if( is_null( $page ) ) {
321 $params = array( 'page' => $page );
323 $width_orig = $this->displayImg
->getWidth();
324 $width = $width_orig;
325 $height_orig = $this->displayImg
->getHeight();
326 $height = $height_orig;
327 $mime = $this->displayImg
->getMimeType();
329 $linkAttribs = array( 'href' => $full_url );
330 $longDesc = $this->displayImg
->getLongDesc();
332 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$wgOut ) );
334 if( $this->displayImg
->allowInlineDisplay() ) {
337 # "Download high res version" link below the image
338 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
339 # We'll show a thumbnail of this image
340 if( $width > $maxWidth ||
$height > $maxHeight ) {
341 # Calculate the thumbnail size.
342 # First case, the limiting factor is the width, not the height.
343 if( $width / $height >= $maxWidth / $maxHeight ) {
344 $height = round( $height * $maxWidth / $width);
346 # Note that $height <= $maxHeight now.
348 $newwidth = floor( $width * $maxHeight / $height);
349 $height = round( $height * $newwidth / $width );
351 # Note that $height <= $maxHeight now, but might not be identical
352 # because of rounding.
354 $msgbig = wfMsgHtml( 'show-big-image' );
355 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
356 $wgLang->formatNum( $width ),
357 $wgLang->formatNum( $height )
360 # Image is small enough to show full size on image page
361 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
362 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
365 $params['width'] = $width;
366 $thumbnail = $this->displayImg
->transform( $params );
368 $anchorclose = "<br />";
369 if( $this->displayImg
->mustRender() ) {
374 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
377 $isMulti = $this->displayImg
->isMultipage() && $this->displayImg
->pageCount() > 1;
379 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
384 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
387 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
388 $thumbnail->toHtml( $options ) .
389 $anchorclose . "</div>\n" );
393 $count = $this->displayImg
->pageCount();
396 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
401 array( 'page' => $page - 1 ),
402 array( 'known', 'noclasses' )
404 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
405 array( 'page' => $page - 1 ) );
410 if( $page < $count ) {
411 $label = wfMsg( 'imgmultipagenext' );
416 array( 'page' => $page +
1 ),
417 array( 'known', 'noclasses' )
419 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
420 array( 'page' => $page +
1 ) );
428 'name' => 'pageselector',
429 'action' => $wgScript,
430 'onchange' => 'document.pageselector.submit();',
434 for ( $i=1; $i <= $count; $i++
) {
435 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
437 $select = Xml
::tags( 'select',
438 array( 'id' => 'pageselector', 'name' => 'page' ),
439 implode( "\n", $options ) );
442 '</td><td><div class="multipageimagenavbox">' .
443 Xml
::openElement( 'form', $formParams ) .
444 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
445 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
446 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
447 Xml
::closeElement( 'form' ) .
448 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
452 #if direct link is allowed but it's not a renderable image, show an icon.
453 if( $this->displayImg
->isSafeFile() ) {
454 $icon= $this->displayImg
->iconThumb();
456 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
457 $icon->toHtml( array( 'file-link' => true ) ) .
466 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
467 $medialink = "[[Media:$filename|$filename]]";
469 if( !$this->displayImg
->isSafeFile() ) {
470 $warning = wfMsgNoTrans( 'mediawarning' );
471 $wgOut->addWikiText( <<<EOT
472 <div class="fullMedia">
473 <span class="dangerousLink">{$medialink}</span>$dirmark
474 <span class="fileInfo">$longDesc</span>
476 <div class="mediaWarning">$warning</div>
480 $wgOut->addWikiText( <<<EOT
481 <div class="fullMedia">
482 {$medialink}{$dirmark}
483 <span class="fileInfo">$longDesc</span>
490 if( !$this->displayImg
->isLocal() ) {
491 $this->printSharedImageText();
494 # Image does not exist
495 if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
496 // Only show an upload link if the user can upload
497 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
499 'filepage-nofile-link',
500 $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img
->getName() ) )
505 $nofile = 'filepage-nofile';
507 $wgOut->setRobotPolicy( 'noindex,nofollow' );
508 $wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
513 * Show a notice that the file is from a shared repository
515 protected function printSharedImageText() {
520 $descUrl = $this->img
->getDescriptionUrl();
521 $descText = $this->img
->getDescriptionText();
523 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
524 $repo = $this->img
->getRepo()->getDisplayName();
527 if( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-' ) {
528 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
529 } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
530 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
532 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
536 $this->mExtraDescription
= $descText;
540 public function getUploadUrl() {
542 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
543 return $uploadTitle->getFullUrl( array(
544 'wpDestFile' => $this->img
->getName(),
550 * Print out the various links at the bottom of the image page, e.g. reupload,
551 * external editing (and instructions link) etc.
553 protected function uploadLinksBox() {
554 global $wgUser, $wgOut, $wgEnableUploads;
556 if( !$wgEnableUploads ) { return; }
559 if( !$this->img
->isLocal() )
562 $sk = $wgUser->getSkin();
564 $wgOut->addHTML( "<br /><ul>\n" );
566 # "Upload a new version of this file" link
567 if( UploadBase
::userCanReUpload($wgUser,$this->img
->name
) ) {
568 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
569 $wgOut->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
572 # External editing link
575 wfMsgHtml( 'edit-externally' ),
579 'externaledit' => 'true',
582 array( 'known', 'noclasses' )
584 $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
586 $wgOut->addHTML( "</ul>\n" );
589 protected function closeShowImage() {} # For overloading
592 * If the page we've just displayed is in the "Image" namespace,
593 * we follow it with an upload history of the image and its usage.
595 protected function imageHistory() {
596 global $wgOut, $wgUseExternalEditor;
599 $pager = new ImageHistoryPseudoPager( $this );
600 $wgOut->addHTML( $pager->getBody() );
602 $this->img
->resetHistory(); // free db resources
604 # Exist check because we don't want to show this on pages where an image
605 # doesn't exist along with the noimage message, that would suck. -ævar
606 if( $wgUseExternalEditor && $this->img
->exists() ) {
607 $this->uploadLinksBox();
611 protected function imageLinks() {
612 global $wgUser, $wgOut, $wgLang;
616 $dbr = wfGetDB( DB_SLAVE
);
619 array( 'imagelinks', 'page' ),
620 array( 'page_namespace', 'page_title' ),
621 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
623 array( 'LIMIT' => $limit +
1)
625 $count = $dbr->numRows( $res );
627 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
628 $wgOut->addWikiMsg( 'nolinkstoimage' );
629 $wgOut->addHTML( "</div>\n" );
633 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
634 if( $count <= $limit - 1 ) {
635 $wgOut->addWikiMsg( 'linkstoimage', $count );
637 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
638 $wgOut->addWikiMsg( 'linkstoimage-more',
639 $wgLang->formatNum( $limit ),
640 $this->mTitle
->getPrefixedDBkey()
644 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
645 $sk = $wgUser->getSkin();
647 while ( $s = $res->fetchObject() ) {
649 if( $count <= $limit ) {
650 // We have not yet reached the extra one that tells us there is more to fetch
652 Title
::makeTitle( $s->page_namespace
, $s->page_title
),
656 array( 'known', 'noclasses' )
658 $wgOut->addHTML( "<li>{$link}</li>\n" );
661 $wgOut->addHTML( "</ul>\n" );
664 // Add a links to [[Special:Whatlinkshere]]
665 if( $count > $limit )
666 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
667 $wgOut->addHTML( "</div>\n" );
670 protected function imageRedirects() {
671 global $wgUser, $wgOut, $wgLang;
673 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
674 if( count( $redirects ) == 0 ) return;
676 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
677 $wgOut->addWikiMsg( 'redirectstofile',
678 $wgLang->formatNum( count( $redirects ) )
680 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
682 $sk = $wgUser->getSkin();
683 foreach ( $redirects as $title ) {
688 array( 'redirect' => 'no' ),
689 array( 'known', 'noclasses' )
691 $wgOut->addHTML( "<li>{$link}</li>\n" );
693 $wgOut->addHTML( "</ul></div>\n" );
697 protected function imageDupes() {
698 global $wgOut, $wgUser, $wgLang;
702 $dupes = $this->getDuplicates();
703 if( count( $dupes ) == 0 ) return;
705 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
706 $wgOut->addWikiMsg( 'duplicatesoffile',
707 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
709 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
711 $sk = $wgUser->getSkin();
712 foreach ( $dupes as $file ) {
714 if( $file->isLocal() ) {
720 array( 'known', 'noclasses' )
723 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
724 $file->getTitle()->getPrefixedText() );
725 $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
727 $wgOut->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
729 $wgOut->addHTML( "</ul></div>\n" );
733 * Delete the file, or an earlier version of it
735 public function delete() {
736 global $wgUploadMaintenance;
737 if( $wgUploadMaintenance && $this->mTitle
&& $this->mTitle
->getNamespace() == NS_FILE
) {
739 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n", array( 'filedelete-maintenance' ) );
744 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
745 // Standard article deletion
749 $deleter = new FileDeleteForm( $this->img
);
754 * Revert the file to an earlier version
756 public function revert() {
758 $reverter = new FileRevertForm( $this->img
);
759 $reverter->execute();
763 * Override handling of action=purge
765 public function doPurge() {
767 if( $this->img
->exists() ) {
768 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
769 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
771 $this->img
->upgradeRow();
772 $this->img
->purgeCache();
774 wfDebug( "ImagePage::doPurge no image for " . $this->img
->getName() . "; limiting purge to cache only\n" );
775 // even if the file supposedly doesn't exist, force any cached information
776 // to be updated (in case the cached information is wrong)
777 $this->img
->purgeCache();
783 * Display an error with a wikitext description
785 function showError( $description ) {
787 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
788 $wgOut->setRobotPolicy( "noindex,nofollow" );
789 $wgOut->setArticleRelated( false );
790 $wgOut->enableClientCache( false );
791 $wgOut->addWikiText( $description );
797 * Builds the image revision log shown on image pages
801 class ImageHistoryList
{
803 protected $imagePage, $img, $skin, $title, $repo, $showThumb;
805 public function __construct( $imagePage ) {
806 global $wgUser, $wgShowArchiveThumbnails;
807 $this->skin
= $wgUser->getSkin();
808 $this->current
= $imagePage->getFile();
809 $this->img
= $imagePage->getDisplayedFile();
810 $this->title
= $imagePage->getTitle();
811 $this->imagePage
= $imagePage;
812 $this->showThumb
= $wgShowArchiveThumbnails && $this->img
->canRender();
815 public function getImagePage() {
816 return $this->imagePage
;
819 public function getSkin() {
823 public function getFile() {
827 public function beginImageHistoryList( $navLinks = '' ) {
828 global $wgOut, $wgUser;
829 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) . "\n"
830 . "<div id=\"mw-imagepage-section-filehistory\">\n"
831 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
833 . Xml
::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
835 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deletedhistory') ) ?
'<td></td>' : '' )
836 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
837 . ( $this->showThumb ?
'<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
838 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
839 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
840 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
844 public function endImageHistoryList( $navLinks = '' ) {
845 return "</table>\n$navLinks\n</div>\n";
848 public function imageHistoryLine( $iscur, $file ) {
849 global $wgUser, $wgLang, $wgContLang, $wgTitle;
851 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
852 $img = $iscur ?
$file->getName() : $file->getArchiveName();
853 $user = $file->getUser('id');
854 $usertext = $file->getUser('text');
855 $description = $file->getDescription();
857 $local = $this->current
->isLocal();
858 $row = $css = $selected = '';
861 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deletedhistory') ) ) {
863 # Link to remove from history
864 if( $wgUser->isAllowed( 'delete' ) ) {
865 $q = array( 'action' => 'delete' );
867 $q['oldimage'] = $img;
868 $row .= $this->skin
->link(
870 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
871 array(), $q, array( 'known' )
874 # Link to hide content. Don't show useless link to people who cannot hide revisions.
875 $canHide = $wgUser->isAllowed( 'deleterevision' );
876 if( $canHide ||
($wgUser->isAllowed('deletedhistory') && $file->getVisibility()) ) {
877 if( $wgUser->isAllowed('delete') ) {
880 // If file is top revision or locked from this user, don't link
881 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
882 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
884 list( $ts, $name ) = explode( '!', $img, 2 );
886 'type' => 'oldimage',
887 'target' => $wgTitle->getPrefixedText(),
890 $del = $this->skin
->revDeleteLink( $query,
891 $file->isDeleted(File
::DELETED_RESTRICTED
), $canHide );
898 // Reversion link/current indicator
901 $row .= wfMsgHtml( 'filehist-current' );
902 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
903 if( $file->isDeleted(File
::DELETED_FILE
) ) {
904 $row .= wfMsgHtml('filehist-revert');
906 $row .= $this->skin
->link(
908 wfMsgHtml( 'filehist-revert' ),
911 'action' => 'revert',
913 'wpEditToken' => $wgUser->editToken( $img )
915 array( 'known', 'noclasses' )
921 // Date/time and image link
922 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
923 $selected = "class='filehistory-selected'";
925 $row .= "<td $selected style='white-space: nowrap;'>";
926 if( !$file->userCan(File
::DELETED_FILE
) ) {
927 # Don't link to unviewable files
928 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
929 } elseif( $file->isDeleted(File
::DELETED_FILE
) ) {
930 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
931 # Make a link to review the image
932 $url = $this->skin
->link(
934 $wgLang->timeAndDate( $timestamp, true ),
937 'target' => $wgTitle->getPrefixedText(),
939 'token' => $wgUser->editToken( $img )
941 array( 'known', 'noclasses' )
943 $row .= '<span class="history-deleted">'.$url.'</span>';
945 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
946 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
951 if ( $this->showThumb
) {
952 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
955 // Image dimensions + size
957 $row .= htmlspecialchars( $file->getDimensionsString() );
958 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $file->getSize() ) . ')</span>';
964 // Hide deleted usernames
965 if( $file->isDeleted(File
::DELETED_USER
) ) {
966 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
968 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
969 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
972 $row .= htmlspecialchars( $usertext );
976 // Don't show deleted descriptions
977 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
978 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
980 $row .= $this->skin
->commentBlock( $description, $this->title
);
984 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
985 $classAttr = $rowClass ?
" class='$rowClass'" : "";
987 return "<tr{$classAttr}>{$row}</tr>\n";
990 protected function getThumbForLine( $file ) {
993 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
998 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
1000 $thumbnail = $file->transform( $params );
1002 'alt' => wfMsg( 'filehist-thumbtext',
1003 $wgLang->timeAndDate( $timestamp, true ),
1004 $wgLang->date( $timestamp, true ),
1005 $wgLang->time( $timestamp, true ) ),
1006 'file-link' => true,
1009 if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' );
1011 return $thumbnail->toHtml( $options );
1013 return wfMsgHtml( 'filehist-nothumb' );
1018 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
1019 function __construct( $imagePage ) {
1020 parent
::__construct();
1021 $this->mImagePage
= $imagePage;
1022 $this->mTitle
= clone( $imagePage->getTitle() );
1023 $this->mTitle
->setFragment( '#filehistory' );
1025 $this->mHist
= array();
1026 $this->mRange
= array( 0, 0 ); // display range
1029 function getTitle() {
1030 return $this->mTitle
;
1033 function getQueryInfo() {
1037 function getIndexField() {
1041 function formatRow( $row ) {
1045 function getBody() {
1048 if( count($this->mHist
) ) {
1049 $list = new ImageHistoryList( $this->mImagePage
);
1050 # Generate prev/next links
1051 $navLink = $this->getNavigationBar();
1052 $s = $list->beginImageHistoryList($navLink);
1053 // Skip rows there just for paging links
1054 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1055 $file = $this->mHist
[$i];
1056 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1058 $s .= $list->endImageHistoryList($navLink);
1063 function doQuery() {
1064 if( $this->mQueryDone
) return;
1065 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1066 if( !$this->mImg
->exists() ) {
1069 $queryLimit = $this->mLimit +
1; // limit plus extra row
1070 if( $this->mIsBackwards
) {
1071 // Fetch the file history
1072 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1073 // The current rev may not meet the offset/limit
1074 $numRows = count($this->mHist
);
1075 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1076 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1079 // The current rev may not meet the offset
1080 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1081 $this->mHist
[] = $this->mImg
;
1083 // Old image versions (fetch extra row for nav links)
1084 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1085 // Fetch the file history
1086 $this->mHist
= array_merge( $this->mHist
,
1087 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1089 $numRows = count($this->mHist
); // Total number of query results
1091 # Index value of top item in the list
1092 $firstIndex = $this->mIsBackwards ?
1093 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1094 # Discard the extra result row if there is one
1095 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1096 if( $this->mIsBackwards
) {
1097 # Index value of item past the index
1098 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1099 # Index value of bottom item in the list
1100 $lastIndex = $this->mHist
[1]->getTimestamp();
1102 $this->mRange
= array( 1, $numRows-1 );
1104 # Index value of item past the index
1105 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1106 # Index value of bottom item in the list
1107 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1109 $this->mRange
= array( 0, $numRows-2 );
1112 # Setting indexes to an empty string means that they will be
1113 # omitted if they would otherwise appear in URLs. It just so
1114 # happens that this is the right thing to do in the standard
1115 # UI, in all the relevant cases.
1116 $this->mPastTheEndIndex
= '';
1117 # Index value of bottom item in the list
1118 $lastIndex = $this->mIsBackwards ?
1119 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1121 $this->mRange
= array( 0, $numRows-1 );
1126 $this->mPastTheEndIndex
= '';
1128 if( $this->mIsBackwards
) {
1129 $this->mIsFirst
= ( $numRows < $queryLimit );
1130 $this->mIsLast
= ( $this->mOffset
== '' );
1131 $this->mLastShown
= $firstIndex;
1132 $this->mFirstShown
= $lastIndex;
1134 $this->mIsFirst
= ( $this->mOffset
== '' );
1135 $this->mIsLast
= ( $numRows < $queryLimit );
1136 $this->mLastShown
= $lastIndex;
1137 $this->mFirstShown
= $firstIndex;
1139 $this->mQueryDone
= true;