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 if( $wgShowEXIF && $this->displayImg
->exists() ) {
89 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
90 $formattedMetadata = $this->displayImg
->formatMetadata();
91 $showmeta = $formattedMetadata !== false;
96 if( !$diff && $this->displayImg
->exists() )
97 $wgOut->addHTML( $this->showTOC($showmeta) );
100 $this->openShowImage();
102 # No need to display noarticletext, we use our own message, output in openShowImage()
103 if( $this->getID() ) {
106 # Just need to set the right headers
107 $wgOut->setArticleFlag( true );
108 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
109 $this->viewUpdates();
112 # Show shared description, if needed
113 if( $this->mExtraDescription
) {
114 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
115 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
116 $wgOut->addWikiText( $fol );
118 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. "</div>\n" );
121 $this->closeShowImage();
122 $this->imageHistory();
123 // TODO: Cleanup the following
125 $wgOut->addHTML( Xml
::element( 'h2',
126 array( 'id' => 'filelinks' ),
127 wfMsg( 'imagelinks' ) ) . "\n" );
129 # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
130 # Yet we return metadata about the target. Definitely an issue in the FileRepo
131 $this->imageRedirects();
135 global $wgStylePath, $wgStyleVersion;
136 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
137 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
138 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
139 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
140 $wgOut->addScriptFile( 'metadata.js' );
142 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
146 public function getRedirectTarget() {
148 if( $this->img
->isLocal() ) {
149 return parent
::getRedirectTarget();
151 // Foreign image page
152 $from = $this->img
->getRedirected();
153 $to = $this->img
->getName();
157 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
159 public function followRedirect() {
161 if( $this->img
->isLocal() ) {
162 return parent
::followRedirect();
164 $from = $this->img
->getRedirected();
165 $to = $this->img
->getName();
169 return Title
::makeTitle( NS_FILE
, $to );
171 public function isRedirect( $text = false ) {
173 if( $this->img
->isLocal() )
174 return parent
::isRedirect( $text );
176 return (bool)$this->img
->getRedirected();
179 public function isLocal() {
181 return $this->img
->isLocal();
184 public function getFile() {
189 public function getDisplayedFile() {
191 return $this->displayImg
;
194 public function getDuplicates() {
196 if( !is_null($this->dupes
) ) {
199 if( !( $hash = $this->img
->getSha1() ) ) {
200 return $this->dupes
= array();
202 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
203 // Remove duplicates with self and non matching file sizes
204 $self = $this->img
->getRepoName().':'.$this->img
->getName();
205 $size = $this->img
->getSize();
206 foreach ( $dupes as $index => $file ) {
207 $key = $file->getRepoName().':'.$file->getName();
209 unset( $dupes[$index] );
210 if( $file->getSize() != $size )
211 unset( $dupes[$index] );
213 return $this->dupes
= $dupes;
221 * @param bool $metadata Whether or not to show the metadata link
224 protected function showTOC( $metadata ) {
226 $r = '<ul id="filetoc">
227 <li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>
228 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
229 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . "</a></li>\n" .
230 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . "
236 * Make a table with metadata to be shown in the output page.
238 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
240 * @param array $exif The array containing the EXIF data
243 protected function makeMetadataTable( $metadata ) {
244 $r = "<div class=\"mw-imagepage-section-metadata\">";
245 $r .= wfMsgNoTrans( 'metadata-help' );
246 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
247 foreach ( $metadata as $type => $stuff ) {
248 foreach ( $stuff as $v ) {
249 # FIXME, why is this using escapeId for a class?!
250 $class = Sanitizer
::escapeId( $v['id'] );
251 if( $type == 'collapsed' ) {
252 $class .= ' collapsable';
254 $r .= "<tr class=\"$class\">\n";
255 $r .= "<th>{$v['name']}</th>\n";
256 $r .= "<td>{$v['value']}</td>\n</tr>";
259 $r .= "</table>\n</div>\n";
264 * Overloading Article's getContent method.
266 * Omit noarticletext if sharedupload; text will be fetched from the
267 * shared upload server if possible.
269 public function getContent() {
271 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
274 return Article
::getContent();
277 protected function openShowImage() {
278 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
279 $wgLang, $wgContLang, $wgEnableUploads;
283 $full_url = $this->displayImg
->getURL();
284 $linkAttribs = false;
285 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
286 if( !isset( $wgImageLimits[$sizeSel] ) ) {
287 $sizeSel = User
::getDefaultOption( 'imagesize' );
289 // The user offset might still be incorrect, specially if
290 // $wgImageLimits got changed (see bug #8858).
291 if( !isset( $wgImageLimits[$sizeSel] ) ) {
292 // Default to the first offset in $wgImageLimits
296 $max = $wgImageLimits[$sizeSel];
298 $maxHeight = $max[1];
299 $sk = $wgUser->getSkin();
300 $dirmark = $wgContLang->getDirMark();
302 if( $this->displayImg
->exists() ) {
304 $page = $wgRequest->getIntOrNull( 'page' );
305 if( is_null( $page ) ) {
309 $params = array( 'page' => $page );
311 $width_orig = $this->displayImg
->getWidth();
312 $width = $width_orig;
313 $height_orig = $this->displayImg
->getHeight();
314 $height = $height_orig;
315 $mime = $this->displayImg
->getMimeType();
317 $linkAttribs = array( 'href' => $full_url );
318 $longDesc = $this->displayImg
->getLongDesc();
320 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
322 if( $this->displayImg
->allowInlineDisplay() ) {
325 # "Download high res version" link below the image
326 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
327 # We'll show a thumbnail of this image
328 if( $width > $maxWidth ||
$height > $maxHeight ) {
329 # Calculate the thumbnail size.
330 # First case, the limiting factor is the width, not the height.
331 if( $width / $height >= $maxWidth / $maxHeight ) {
332 $height = round( $height * $maxWidth / $width);
334 # Note that $height <= $maxHeight now.
336 $newwidth = floor( $width * $maxHeight / $height);
337 $height = round( $height * $newwidth / $width );
339 # Note that $height <= $maxHeight now, but might not be identical
340 # because of rounding.
342 $msgbig = wfMsgHtml( 'show-big-image' );
343 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
344 $wgLang->formatNum( $width ),
345 $wgLang->formatNum( $height )
348 # Image is small enough to show full size on image page
349 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
350 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
353 $params['width'] = $width;
354 $thumbnail = $this->displayImg
->transform( $params );
356 $anchorclose = "<br />";
357 if( $this->displayImg
->mustRender() ) {
362 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
365 if( $this->displayImg
->isMultipage() ) {
366 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
371 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
374 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
375 $thumbnail->toHtml( $options ) .
376 $anchorclose . "</div>\n" );
379 if( $this->displayImg
->isMultipage() ) {
380 $count = $this->displayImg
->pageCount();
383 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
388 array( 'page' => $page - 1 ),
389 array( 'known', 'noclasses' )
391 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
392 array( 'page' => $page - 1 ) );
397 if( $page < $count ) {
398 $label = wfMsg( 'imgmultipagenext' );
403 array( 'page' => $page +
1 ),
404 array( 'known', 'noclasses' )
406 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
407 array( 'page' => $page +
1 ) );
415 'name' => 'pageselector',
416 'action' => $wgScript,
417 'onchange' => 'document.pageselector.submit();',
421 for ( $i=1; $i <= $count; $i++
) {
422 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
424 $select = Xml
::tags( 'select',
425 array( 'id' => 'pageselector', 'name' => 'page' ),
426 implode( "\n", $options ) );
429 '</td><td><div class="multipageimagenavbox">' .
430 Xml
::openElement( 'form', $formParams ) .
431 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
432 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
433 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
434 Xml
::closeElement( 'form' ) .
435 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
439 #if direct link is allowed but it's not a renderable image, show an icon.
440 if( $this->displayImg
->isSafeFile() ) {
441 $icon= $this->displayImg
->iconThumb();
443 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
444 $icon->toHtml( array( 'desc-link' => true ) ) .
453 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
454 $medialink = $this->displayImg
->isMissing() ?
456 "[[Media:$filename|$filename]]";
458 if( !$this->displayImg
->isSafeFile() ) {
459 $warning = wfMsgNoTrans( 'mediawarning' );
460 $wgOut->addWikiText( <<<EOT
461 <div class="fullMedia">
462 <span class="dangerousLink">{$medialink}</span>$dirmark
463 <span class="fileInfo">$longDesc</span>
465 <div class="mediaWarning">$warning</div>
469 $wgOut->addWikiText( <<<EOT
470 <div class="fullMedia">
471 {$medialink}{$dirmark}
472 <span class="fileInfo">$longDesc</span>
479 if( !$this->displayImg
->isLocal() ) {
480 $this->printSharedImageText();
483 # Image does not exist
484 if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
485 // Only show an upload link if the user can upload
486 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
488 'filepage-nofile-link',
489 $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img
->getName() ) )
494 $nofile = wfMsgHtml( 'filepage-nofile' );
496 $wgOut->setRobotPolicy( 'noindex,nofollow' );
497 $wgOut->addHTML( '<div id="mw-imagepage-nofile" class="plainlinks">' . $nofile . '</div>' );
502 * Show a notice that the file is from a shared repository
504 protected function printSharedImageText() {
509 $descUrl = $this->img
->getDescriptionUrl();
510 $descText = $this->img
->getDescriptionText();
512 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
513 $repo = $this->img
->getRepo()->getDisplayName();
516 if( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-' ) {
517 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
518 } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
519 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
521 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
525 $this->mExtraDescription
= $descText;
529 public function getUploadUrl() {
531 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
532 return $uploadTitle->getFullUrl( array(
533 'wpDestFile' => $this->img
->getName(),
539 * Print out the various links at the bottom of the image page, e.g. reupload,
540 * external editing (and instructions link) etc.
542 protected function uploadLinksBox() {
543 global $wgUser, $wgOut, $wgEnableUploads;
545 if( !$wgEnableUploads ) { return; }
548 if( !$this->img
->isLocal() )
551 $sk = $wgUser->getSkin();
553 $wgOut->addHTML( "<br /><ul>\n" );
555 # "Upload a new version of this file" link
556 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
557 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
558 $wgOut->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
561 # External editing link
564 wfMsgHtml( 'edit-externally' ),
568 'externaledit' => 'true',
571 array( 'known', 'noclasses' )
573 $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
575 $wgOut->addHTML( "</ul>\n" );
578 protected function closeShowImage() {} # For overloading
581 * If the page we've just displayed is in the "Image" namespace,
582 * we follow it with an upload history of the image and its usage.
584 protected function imageHistory() {
585 global $wgOut, $wgUseExternalEditor;
588 $pager = new ImageHistoryPseudoPager( $this );
589 $wgOut->addHTML( $pager->getBody() );
591 $this->img
->resetHistory(); // free db resources
593 # Exist check because we don't want to show this on pages where an image
594 # doesn't exist along with the noimage message, that would suck. -ævar
595 if( $wgUseExternalEditor && $this->img
->exists() ) {
596 $this->uploadLinksBox();
600 protected function imageLinks() {
601 global $wgUser, $wgOut, $wgLang;
605 $dbr = wfGetDB( DB_SLAVE
);
608 array( 'imagelinks', 'page' ),
609 array( 'page_namespace', 'page_title' ),
610 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
612 array( 'LIMIT' => $limit +
1)
614 $count = $dbr->numRows( $res );
616 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
617 $wgOut->addWikiMsg( 'nolinkstoimage' );
618 $wgOut->addHTML( "</div>\n" );
622 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
623 if( $count <= $limit - 1 ) {
624 $wgOut->addWikiMsg( 'linkstoimage', $count );
626 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
627 $wgOut->addWikiMsg( 'linkstoimage-more',
628 $wgLang->formatNum( $limit ),
629 $this->mTitle
->getPrefixedDBkey()
633 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
634 $sk = $wgUser->getSkin();
636 while ( $s = $res->fetchObject() ) {
638 if( $count <= $limit ) {
639 // We have not yet reached the extra one that tells us there is more to fetch
641 Title
::makeTitle( $s->page_namespace
, $s->page_title
),
645 array( 'known', 'noclasses' )
647 $wgOut->addHTML( "<li>{$link}</li>\n" );
650 $wgOut->addHTML( "</ul>\n" );
653 // Add a links to [[Special:Whatlinkshere]]
654 if( $count > $limit )
655 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
656 $wgOut->addHTML( "</div>\n" );
659 protected function imageRedirects() {
660 global $wgUser, $wgOut, $wgLang;
662 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
663 if( count( $redirects ) == 0 ) return;
665 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
666 $wgOut->addWikiMsg( 'redirectstofile',
667 $wgLang->formatNum( count( $redirects ) )
669 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
671 $sk = $wgUser->getSkin();
672 foreach ( $redirects as $title ) {
677 array( 'redirect' => 'no' ),
678 array( 'known', 'noclasses' )
680 $wgOut->addHTML( "<li>{$link}</li>\n" );
682 $wgOut->addHTML( "</ul></div>\n" );
686 protected function imageDupes() {
687 global $wgOut, $wgUser, $wgLang;
691 $dupes = $this->getDuplicates();
692 if( count( $dupes ) == 0 ) return;
694 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
695 $wgOut->addWikiMsg( 'duplicatesoffile',
696 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
698 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
700 $sk = $wgUser->getSkin();
701 foreach ( $dupes as $file ) {
703 if( $file->isLocal() ) {
709 array( 'known', 'noclasses' )
712 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
713 $file->getTitle()->getPrefixedText() );
714 $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
716 $wgOut->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
718 $wgOut->addHTML( "</ul></div>\n" );
722 * Delete the file, or an earlier version of it
724 public function delete() {
726 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
727 // Standard article deletion
731 $deleter = new FileDeleteForm( $this->img
);
736 * Revert the file to an earlier version
738 public function revert() {
740 $reverter = new FileRevertForm( $this->img
);
741 $reverter->execute();
745 * Override handling of action=purge
747 public function doPurge() {
749 if( $this->img
->exists() ) {
750 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
751 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
753 $this->img
->upgradeRow();
754 $this->img
->purgeCache();
756 wfDebug( "ImagePage::doPurge no image for " . $this->img
->getName() . "; limiting purge to cache only\n" );
757 // even if the file supposedly doesn't exist, force any cached information
758 // to be updated (in case the cached information is wrong)
759 $this->img
->purgeCache();
765 * Display an error with a wikitext description
767 function showError( $description ) {
769 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
770 $wgOut->setRobotPolicy( "noindex,nofollow" );
771 $wgOut->setArticleRelated( false );
772 $wgOut->enableClientCache( false );
773 $wgOut->addWikiText( $description );
779 * Builds the image revision log shown on image pages
783 class ImageHistoryList
{
785 protected $imagePage, $img, $skin, $title, $repo;
787 public function __construct( $imagePage ) {
789 $this->skin
= $wgUser->getSkin();
790 $this->current
= $imagePage->getFile();
791 $this->img
= $imagePage->getDisplayedFile();
792 $this->title
= $imagePage->getTitle();
793 $this->imagePage
= $imagePage;
796 public function getImagePage() {
797 return $this->imagePage
;
800 public function getSkin() {
804 public function getFile() {
808 public function beginImageHistoryList( $navLinks = '' ) {
809 global $wgOut, $wgUser;
810 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) . "\n"
811 . "<div id=\"mw-imagepage-section-filehistory\">\n"
812 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
814 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
816 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
817 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
818 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
819 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
820 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
821 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
825 public function endImageHistoryList( $navLinks = '' ) {
826 return "</table>\n$navLinks\n</div>\n";
829 public function imageHistoryLine( $iscur, $file ) {
830 global $wgUser, $wgLang, $wgContLang, $wgTitle;
832 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
833 $img = $iscur ?
$file->getName() : $file->getArchiveName();
834 $user = $file->getUser('id');
835 $usertext = $file->getUser('text');
836 $description = $file->getDescription();
838 $local = $this->current
->isLocal();
839 $row = $css = $selected = '';
842 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
844 # Link to remove from history
845 if( $wgUser->isAllowed( 'delete' ) ) {
846 $q = array( 'action' => 'delete' );
848 $q['oldimage'] = $img;
849 $row .= $this->skin
->link(
851 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
852 array(), $q, array( 'known' )
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
->link( $revdel, wfMsgHtml( 'rev-delundel' ),
870 'type' => 'oldimage',
871 'target' => $wgTitle->getPrefixedText(),
876 // Bolden oversighted content
877 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
878 $del = "<strong>$del</strong>";
880 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
885 // Reversion link/current indicator
888 $row .= wfMsgHtml( 'filehist-current' );
889 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
890 if( $file->isDeleted(File
::DELETED_FILE
) ) {
891 $row .= wfMsgHtml('filehist-revert');
893 $row .= $this->skin
->link(
895 wfMsgHtml( 'filehist-revert' ),
898 'action' => 'revert',
900 'wpEditToken' => $wgUser->editToken( $img )
902 array( 'known', 'noclasses' )
908 // Date/time and image link
909 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
910 $selected = "class='filehistory-selected'";
912 $row .= "<td $selected style='white-space: nowrap;'>";
913 if( !$file->userCan(File
::DELETED_FILE
) ) {
914 # Don't link to unviewable files
915 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
916 } elseif( $file->isDeleted(File
::DELETED_FILE
) ) {
917 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
918 # Make a link to review the image
919 $url = $this->skin
->link(
921 $wgLang->timeAndDate( $timestamp, true ),
924 'target' => $wgTitle->getPrefixedUrl(),
926 'token' => $wgUser->editToken( $img )
928 array( 'known', 'noclasses' )
930 $row .= '<span class="history-deleted">'.$url.'</span>';
931 } elseif( $file->isMissing() ) {
932 # Don't link to missing files
933 $row .= $wgLang->timeAndDate( $timestamp, true );
935 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
936 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
941 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
943 // Image dimensions + size
945 $row .= htmlspecialchars( $file->getDimensionsString() );
946 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $file->getSize() ) . ')</span>';
952 // Hide deleted usernames
953 if( $file->isDeleted(File
::DELETED_USER
) ) {
954 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
956 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
957 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
960 $row .= htmlspecialchars( $usertext );
964 // Don't show deleted descriptions
965 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
966 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
968 $row .= $this->skin
->commentBlock( $description, $this->title
);
972 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
973 $classAttr = $rowClass ?
" class='$rowClass'" : "";
975 return "<tr{$classAttr}>{$row}</tr>\n";
978 protected function getThumbForLine( $file ) {
981 if( $file->isMissing() ) {
982 return '<strong class="error">' . wfMsgHtml( 'filehist-missing' ) . '</strong>';
983 } elseif( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
988 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
990 $thumbnail = $file->transform( $params );
992 'alt' => wfMsg( 'filehist-thumbtext',
993 $wgLang->timeAndDate( $timestamp, true ),
994 $wgLang->date( $timestamp, true ),
995 $wgLang->time( $timestamp, true ) ),
999 if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' );
1001 return $thumbnail->toHtml( $options );
1003 return wfMsgHtml( 'filehist-nothumb' );
1008 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
1009 function __construct( $imagePage ) {
1010 parent
::__construct();
1011 $this->mImagePage
= $imagePage;
1012 $this->mTitle
= clone( $imagePage->getTitle() );
1013 $this->mTitle
->setFragment( '#filehistory' );
1015 $this->mHist
= array();
1016 $this->mRange
= array( 0, 0 ); // display range
1019 function getTitle() {
1020 return $this->mTitle
;
1023 function getQueryInfo() {
1027 function getIndexField() {
1031 function formatRow( $row ) {
1035 function getBody() {
1038 if( count($this->mHist
) ) {
1039 $list = new ImageHistoryList( $this->mImagePage
);
1040 # Generate prev/next links
1041 $navLink = $this->getNavigationBar();
1042 $s = $list->beginImageHistoryList($navLink);
1043 // Skip rows there just for paging links
1044 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1045 $file = $this->mHist
[$i];
1046 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1048 $s .= $list->endImageHistoryList($navLink);
1053 function doQuery() {
1054 if( $this->mQueryDone
) return;
1055 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1056 if( !$this->mImg
->exists() ) {
1059 $queryLimit = $this->mLimit +
1; // limit plus extra row
1060 if( $this->mIsBackwards
) {
1061 // Fetch the file history
1062 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1063 // The current rev may not meet the offset/limit
1064 $numRows = count($this->mHist
);
1065 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1066 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1069 // The current rev may not meet the offset
1070 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1071 $this->mHist
[] = $this->mImg
;
1073 // Old image versions (fetch extra row for nav links)
1074 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1075 // Fetch the file history
1076 $this->mHist
= array_merge( $this->mHist
,
1077 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1079 $numRows = count($this->mHist
); // Total number of query results
1081 # Index value of top item in the list
1082 $firstIndex = $this->mIsBackwards ?
1083 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1084 # Discard the extra result row if there is one
1085 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1086 if( $this->mIsBackwards
) {
1087 # Index value of item past the index
1088 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1089 # Index value of bottom item in the list
1090 $lastIndex = $this->mHist
[1]->getTimestamp();
1092 $this->mRange
= array( 1, $numRows-1 );
1094 # Index value of item past the index
1095 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1096 # Index value of bottom item in the list
1097 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1099 $this->mRange
= array( 0, $numRows-2 );
1102 # Setting indexes to an empty string means that they will be
1103 # omitted if they would otherwise appear in URLs. It just so
1104 # happens that this is the right thing to do in the standard
1105 # UI, in all the relevant cases.
1106 $this->mPastTheEndIndex
= '';
1107 # Index value of bottom item in the list
1108 $lastIndex = $this->mIsBackwards ?
1109 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1111 $this->mRange
= array( 0, $numRows-1 );
1116 $this->mPastTheEndIndex
= '';
1118 if( $this->mIsBackwards
) {
1119 $this->mIsFirst
= ( $numRows < $queryLimit );
1120 $this->mIsLast
= ( $this->mOffset
== '' );
1121 $this->mLastShown
= $firstIndex;
1122 $this->mFirstShown
= $lastIndex;
1124 $this->mIsFirst
= ( $this->mOffset
== '' );
1125 $this->mIsLast
= ( $numRows < $queryLimit );
1126 $this->mLastShown
= $lastIndex;
1127 $this->mFirstShown
= $firstIndex;
1129 $this->mQueryDone
= true;