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;
65 $diff = $wgRequest->getVal( 'diff' );
66 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
68 if ( $this->mTitle
->getNamespace() != NS_FILE ||
( isset( $diff ) && $diffOnly ) ) {
69 return Article
::view();
74 if ( $this->mTitle
->getNamespace() == NS_FILE
&& $this->img
->getRedirected() ) {
75 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ||
isset( $diff ) ) {
76 // mTitle is the same as the redirect target so ask Article
77 // to perform the redirect for us.
78 $wgRequest->setVal( 'diffonly', 'true' );
79 return Article
::view();
81 // mTitle is not the same as the redirect target so it is
82 // probably the redirect page itself. Fake the redirect symbol
83 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
84 $wgOut->addHTML( $this->viewRedirect( Title
::makeTitle( NS_FILE
, $this->img
->getName() ),
85 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
91 $this->showRedirectedFromHeader();
93 if ( $wgShowEXIF && $this->displayImg
->exists() ) {
94 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
95 $formattedMetadata = $this->displayImg
->formatMetadata();
96 $showmeta = $formattedMetadata !== false;
101 if ( !$diff && $this->displayImg
->exists() )
102 $wgOut->addHTML( $this->showTOC( $showmeta ) );
105 $this->openShowImage();
107 # No need to display noarticletext, we use our own message, output in openShowImage()
108 if ( $this->getID() ) {
111 # Just need to set the right headers
112 $wgOut->setArticleFlag( true );
113 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
114 $this->viewUpdates();
117 # Show shared description, if needed
118 if ( $this->mExtraDescription
) {
119 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
120 if ( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
121 $wgOut->addWikiText( $fol );
123 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. "</div>\n" );
126 $this->closeShowImage();
127 $this->imageHistory();
128 // TODO: Cleanup the following
130 $wgOut->addHTML( Xml
::element( 'h2',
131 array( 'id' => 'filelinks' ),
132 wfMsg( 'imagelinks' ) ) . "\n" );
134 # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
135 # Yet we return metadata about the target. Definitely an issue in the FileRepo
136 $this->imageRedirects();
139 # Allow extensions to add something after the image links
141 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
143 $wgOut->addHTML( $html );
146 global $wgStylePath, $wgStyleVersion;
147 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
148 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
149 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
150 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
151 $wgOut->addScriptFile( 'metadata.js' );
153 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
157 public function getRedirectTarget() {
159 if ( $this->img
->isLocal() ) {
160 return parent
::getRedirectTarget();
162 // Foreign image page
163 $from = $this->img
->getRedirected();
164 $to = $this->img
->getName();
165 if ( $from == $to ) {
168 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
170 public function followRedirect() {
172 if ( $this->img
->isLocal() ) {
173 return parent
::followRedirect();
175 $from = $this->img
->getRedirected();
176 $to = $this->img
->getName();
177 if ( $from == $to ) {
180 return Title
::makeTitle( NS_FILE
, $to );
182 public function isRedirect( $text = false ) {
184 if ( $this->img
->isLocal() )
185 return parent
::isRedirect( $text );
187 return (bool)$this->img
->getRedirected();
190 public function isLocal() {
192 return $this->img
->isLocal();
195 public function getFile() {
200 public function getDisplayedFile() {
202 return $this->displayImg
;
205 public function getDuplicates() {
207 if ( !is_null( $this->dupes
) ) {
210 if ( !( $hash = $this->img
->getSha1() ) ) {
211 return $this->dupes
= array();
213 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
214 // Remove duplicates with self and non matching file sizes
215 $self = $this->img
->getRepoName() . ':' . $this->img
->getName();
216 $size = $this->img
->getSize();
217 foreach ( $dupes as $index => $file ) {
218 $key = $file->getRepoName() . ':' . $file->getName();
220 unset( $dupes[$index] );
221 if ( $file->getSize() != $size )
222 unset( $dupes[$index] );
224 return $this->dupes
= $dupes;
232 * @param bool $metadata Whether or not to show the metadata link
235 protected function showTOC( $metadata ) {
237 '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
238 '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
239 '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
242 $r[] = '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>';
245 wfRunHooks( 'ImagePageShowTOC', array( $this, &$r ) );
247 return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
251 * Make a table with metadata to be shown in the output page.
253 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
255 * @param array $exif The array containing the EXIF data
258 protected function makeMetadataTable( $metadata ) {
259 $r = "<div class=\"mw-imagepage-section-metadata\">";
260 $r .= wfMsgNoTrans( 'metadata-help' );
261 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
262 foreach ( $metadata as $type => $stuff ) {
263 foreach ( $stuff as $v ) {
264 # FIXME, why is this using escapeId for a class?!
265 $class = Sanitizer
::escapeId( $v['id'] );
266 if ( $type == 'collapsed' ) {
267 $class .= ' collapsable';
269 $r .= "<tr class=\"$class\">\n";
270 $r .= "<th>{$v['name']}</th>\n";
271 $r .= "<td>{$v['value']}</td>\n</tr>";
274 $r .= "</table>\n</div>\n";
279 * Overloading Article's getContent method.
281 * Omit noarticletext if sharedupload; text will be fetched from the
282 * shared upload server if possible.
284 public function getContent() {
286 if ( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
289 return Article
::getContent();
292 protected function openShowImage() {
293 global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
294 $wgLang, $wgContLang, $wgEnableUploads;
298 $full_url = $this->displayImg
->getURL();
299 $linkAttribs = false;
300 $sizeSel = intval( $wgUser->getOption( 'imagesize' ) );
301 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
302 $sizeSel = User
::getDefaultOption( 'imagesize' );
304 // The user offset might still be incorrect, specially if
305 // $wgImageLimits got changed (see bug #8858).
306 if ( !isset( $wgImageLimits[$sizeSel] ) ) {
307 // Default to the first offset in $wgImageLimits
311 $max = $wgImageLimits[$sizeSel];
313 $maxHeight = $max[1];
314 $sk = $wgUser->getSkin();
315 $dirmark = $wgContLang->getDirMark();
317 if ( $this->displayImg
->exists() ) {
319 $page = $wgRequest->getIntOrNull( 'page' );
320 if ( is_null( $page ) ) {
324 $params = array( 'page' => $page );
326 $width_orig = $this->displayImg
->getWidth();
327 $width = $width_orig;
328 $height_orig = $this->displayImg
->getHeight();
329 $height = $height_orig;
330 $mime = $this->displayImg
->getMimeType();
332 $linkAttribs = array( 'href' => $full_url );
333 $longDesc = $this->displayImg
->getLongDesc();
335 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this, &$wgOut ) );
337 if ( $this->displayImg
->allowInlineDisplay() ) {
340 # "Download high res version" link below the image
341 # $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
342 # We'll show a thumbnail of this image
343 if ( $width > $maxWidth ||
$height > $maxHeight ) {
344 # Calculate the thumbnail size.
345 # First case, the limiting factor is the width, not the height.
346 if ( $width / $height >= $maxWidth / $maxHeight ) {
347 $height = round( $height * $maxWidth / $width );
349 # Note that $height <= $maxHeight now.
351 $newwidth = floor( $width * $maxHeight / $height );
352 $height = round( $height * $newwidth / $width );
354 # Note that $height <= $maxHeight now, but might not be identical
355 # because of rounding.
357 $msgbig = wfMsgHtml( 'show-big-image' );
358 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
359 $wgLang->formatNum( $width ),
360 $wgLang->formatNum( $height )
363 # Image is small enough to show full size on image page
364 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
365 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
368 $params['width'] = $width;
369 $thumbnail = $this->displayImg
->transform( $params );
371 $anchorclose = "<br />";
372 if ( $this->displayImg
->mustRender() ) {
377 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
380 $isMulti = $this->displayImg
->isMultipage() && $this->displayImg
->pageCount() > 1;
382 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
387 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
390 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
391 $thumbnail->toHtml( $options ) .
392 $anchorclose . "</div>\n" );
396 $count = $this->displayImg
->pageCount();
399 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
404 array( 'page' => $page - 1 ),
405 array( 'known', 'noclasses' )
407 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
408 array( 'page' => $page - 1 ) );
413 if ( $page < $count ) {
414 $label = wfMsg( 'imgmultipagenext' );
419 array( 'page' => $page +
1 ),
420 array( 'known', 'noclasses' )
422 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
423 array( 'page' => $page +
1 ) );
431 'name' => 'pageselector',
432 'action' => $wgScript,
433 'onchange' => 'document.pageselector.submit();',
437 for ( $i = 1; $i <= $count; $i++
) {
438 $options[] = Xml
::option( $wgLang->formatNum( $i ), $i, $i == $page );
440 $select = Xml
::tags( 'select',
441 array( 'id' => 'pageselector', 'name' => 'page' ),
442 implode( "\n", $options ) );
445 '</td><td><div class="multipageimagenavbox">' .
446 Xml
::openElement( 'form', $formParams ) .
447 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
448 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
449 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
450 Xml
::closeElement( 'form' ) .
451 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
455 # if direct link is allowed but it's not a renderable image, show an icon.
456 if ( $this->displayImg
->isSafeFile() ) {
457 $icon = $this->displayImg
->iconThumb();
459 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
460 $icon->toHtml( array( 'file-link' => true ) ) .
469 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
470 $medialink = "[[Media:$filename|$filename]]";
472 if ( !$this->displayImg
->isSafeFile() ) {
473 $warning = wfMsgNoTrans( 'mediawarning' );
474 $wgOut->addWikiText( <<<EOT
475 <div class="fullMedia">
476 <span class="dangerousLink">{$medialink}</span>$dirmark
477 <span class="fileInfo">$longDesc</span>
479 <div class="mediaWarning">$warning</div>
483 $wgOut->addWikiText( <<<EOT
484 <div class="fullMedia">
485 {$medialink}{$dirmark}
486 <span class="fileInfo">$longDesc</span>
493 if ( !$this->displayImg
->isLocal() ) {
494 $this->printSharedImageText();
497 # Image does not exist
498 if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
499 // Only show an upload link if the user can upload
500 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
502 'filepage-nofile-link',
503 $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img
->getName() ) )
508 $nofile = 'filepage-nofile';
510 $wgOut->setRobotPolicy( 'noindex,nofollow' );
511 $wgOut->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
516 * Show a notice that the file is from a shared repository
518 protected function printSharedImageText() {
523 $descUrl = $this->img
->getDescriptionUrl();
524 $descText = $this->img
->getDescriptionText();
526 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
527 $repo = $this->img
->getRepo()->getDisplayName();
530 if ( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-' ) {
531 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
532 } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
533 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
535 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
539 $this->mExtraDescription
= $descText;
543 public function getUploadUrl() {
545 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
546 return $uploadTitle->getFullUrl( array(
547 'wpDestFile' => $this->img
->getName(),
553 * Print out the various links at the bottom of the image page, e.g. reupload,
554 * external editing (and instructions link) etc.
556 protected function uploadLinksBox() {
557 global $wgUser, $wgOut, $wgEnableUploads, $wgUseExternalEditor;
559 if ( !$wgEnableUploads ) { return; }
562 if ( !$this->img
->isLocal() )
565 $sk = $wgUser->getSkin();
567 $wgOut->addHTML( "<br /><ul>\n" );
569 # "Upload a new version of this file" link
570 if ( UploadBase
::userCanReUpload( $wgUser, $this->img
->name
) ) {
571 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
572 $wgOut->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
575 # External editing link
576 if ( $wgUseExternalEditor ) {
579 wfMsgHtml( 'edit-externally' ),
583 'externaledit' => 'true',
586 array( 'known', 'noclasses' )
588 $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
591 $wgOut->addHTML( "</ul>\n" );
594 protected function closeShowImage() { } # For overloading
597 * If the page we've just displayed is in the "Image" namespace,
598 * we follow it with an upload history of the image and its usage.
600 protected function imageHistory() {
604 $pager = new ImageHistoryPseudoPager( $this );
605 $wgOut->addHTML( $pager->getBody() );
607 $this->img
->resetHistory(); // free db resources
609 # Exist check because we don't want to show this on pages where an image
610 # doesn't exist along with the noimage message, that would suck. -ævar
611 if ( $this->img
->exists() ) {
612 $this->uploadLinksBox();
616 protected function imageLinks() {
617 global $wgUser, $wgOut, $wgLang;
621 $dbr = wfGetDB( DB_SLAVE
);
624 array( 'imagelinks', 'page' ),
625 array( 'page_namespace', 'page_title' ),
626 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
628 array( 'LIMIT' => $limit +
1 )
630 $count = $dbr->numRows( $res );
632 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
633 $wgOut->addWikiMsg( 'nolinkstoimage' );
634 $wgOut->addHTML( "</div>\n" );
638 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
639 if ( $count <= $limit - 1 ) {
640 $wgOut->addWikiMsg( 'linkstoimage', $count );
642 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
643 $wgOut->addWikiMsg( 'linkstoimage-more',
644 $wgLang->formatNum( $limit ),
645 $this->mTitle
->getPrefixedDBkey()
649 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
650 $sk = $wgUser->getSkin();
652 while ( $s = $res->fetchObject() ) {
654 if ( $count <= $limit ) {
655 // We have not yet reached the extra one that tells us there is more to fetch
657 Title
::makeTitle( $s->page_namespace
, $s->page_title
),
661 array( 'known', 'noclasses' )
663 $wgOut->addHTML( "<li>{$link}</li>\n" );
666 $wgOut->addHTML( "</ul>\n" );
669 // Add a links to [[Special:Whatlinkshere]]
670 if ( $count > $limit )
671 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
672 $wgOut->addHTML( "</div>\n" );
675 protected function imageRedirects() {
676 global $wgUser, $wgOut, $wgLang;
678 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
679 if ( count( $redirects ) == 0 ) return;
681 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
682 $wgOut->addWikiMsg( 'redirectstofile',
683 $wgLang->formatNum( count( $redirects ) )
685 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
687 $sk = $wgUser->getSkin();
688 foreach ( $redirects as $title ) {
693 array( 'redirect' => 'no' ),
694 array( 'known', 'noclasses' )
696 $wgOut->addHTML( "<li>{$link}</li>\n" );
698 $wgOut->addHTML( "</ul></div>\n" );
702 protected function imageDupes() {
703 global $wgOut, $wgUser, $wgLang;
707 $dupes = $this->getDuplicates();
708 if ( count( $dupes ) == 0 ) return;
710 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
711 $wgOut->addWikiMsg( 'duplicatesoffile',
712 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
714 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
716 $sk = $wgUser->getSkin();
717 foreach ( $dupes as $file ) {
719 if ( $file->isLocal() ) {
725 array( 'known', 'noclasses' )
728 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
729 $file->getTitle()->getPrefixedText() );
730 $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
732 $wgOut->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
734 $wgOut->addHTML( "</ul></div>\n" );
738 * Delete the file, or an earlier version of it
740 public function delete() {
741 global $wgUploadMaintenance;
742 if ( $wgUploadMaintenance && $this->mTitle
&& $this->mTitle
->getNamespace() == NS_FILE
) {
744 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
749 if ( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
750 // Standard article deletion
754 $deleter = new FileDeleteForm( $this->img
);
759 * Revert the file to an earlier version
761 public function revert() {
763 $reverter = new FileRevertForm( $this->img
);
764 $reverter->execute();
768 * Override handling of action=purge
770 public function doPurge() {
772 if ( $this->img
->exists() ) {
773 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
774 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
776 $this->img
->upgradeRow();
777 $this->img
->purgeCache();
779 wfDebug( "ImagePage::doPurge no image for " . $this->img
->getName() . "; limiting purge to cache only\n" );
780 // even if the file supposedly doesn't exist, force any cached information
781 // to be updated (in case the cached information is wrong)
782 $this->img
->purgeCache();
788 * Display an error with a wikitext description
790 function showError( $description ) {
792 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
793 $wgOut->setRobotPolicy( "noindex,nofollow" );
794 $wgOut->setArticleRelated( false );
795 $wgOut->enableClientCache( false );
796 $wgOut->addWikiText( $description );
802 * Builds the image revision log shown on image pages
806 class ImageHistoryList
{
808 protected $imagePage, $img, $skin, $title, $repo, $showThumb;
810 public function __construct( $imagePage ) {
811 global $wgUser, $wgShowArchiveThumbnails;
812 $this->skin
= $wgUser->getSkin();
813 $this->current
= $imagePage->getFile();
814 $this->img
= $imagePage->getDisplayedFile();
815 $this->title
= $imagePage->getTitle();
816 $this->imagePage
= $imagePage;
817 $this->showThumb
= $wgShowArchiveThumbnails && $this->img
->canRender();
820 public function getImagePage() {
821 return $this->imagePage
;
824 public function getSkin() {
828 public function getFile() {
832 public function beginImageHistoryList( $navLinks = '' ) {
833 global $wgOut, $wgUser;
834 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) . "\n"
835 . "<div id=\"mw-imagepage-section-filehistory\">\n"
836 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
838 . Xml
::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
840 . ( $this->current
->isLocal() && ( $wgUser->isAllowed( 'delete' ) ||
$wgUser->isAllowed( 'deletedhistory' ) ) ?
'<td></td>' : '' )
841 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
842 . ( $this->showThumb ?
'<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
843 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
844 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
845 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
849 public function endImageHistoryList( $navLinks = '' ) {
850 return "</table>\n$navLinks\n</div>\n";
853 public function imageHistoryLine( $iscur, $file ) {
854 global $wgUser, $wgLang, $wgContLang;
856 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
857 $img = $iscur ?
$file->getName() : $file->getArchiveName();
858 $user = $file->getUser( 'id' );
859 $usertext = $file->getUser( 'text' );
860 $description = $file->getDescription();
862 $local = $this->current
->isLocal();
863 $row = $css = $selected = '';
866 if ( $local && ( $wgUser->isAllowed( 'delete' ) ||
$wgUser->isAllowed( 'deletedhistory' ) ) ) {
868 # Link to remove from history
869 if ( $wgUser->isAllowed( 'delete' ) ) {
870 $q = array( 'action' => 'delete' );
872 $q['oldimage'] = $img;
873 $row .= $this->skin
->link(
875 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
876 array(), $q, array( 'known' )
879 # Link to hide content. Don't show useless link to people who cannot hide revisions.
880 $canHide = $wgUser->isAllowed( 'deleterevision' );
881 if ( $canHide ||
( $wgUser->isAllowed( 'deletedhistory' ) && $file->getVisibility() ) ) {
882 if ( $wgUser->isAllowed( 'delete' ) ) {
885 // If file is top revision or locked from this user, don't link
886 if ( $iscur ||
!$file->userCan( File
::DELETED_RESTRICTED
) ) {
887 $del = $this->skin
->revDeleteLinkDisabled( $canHide );
889 list( $ts, $name ) = explode( '!', $img, 2 );
891 'type' => 'oldimage',
892 'target' => $this->title
->getPrefixedText(),
895 $del = $this->skin
->revDeleteLink( $query,
896 $file->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
903 // Reversion link/current indicator
906 $row .= wfMsgHtml( 'filehist-current' );
907 } elseif ( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
908 if ( $file->isDeleted( File
::DELETED_FILE
) ) {
909 $row .= wfMsgHtml( 'filehist-revert' );
911 $row .= $this->skin
->link(
913 wfMsgHtml( 'filehist-revert' ),
916 'action' => 'revert',
918 'wpEditToken' => $wgUser->editToken( $img )
920 array( 'known', 'noclasses' )
926 // Date/time and image link
927 if ( $file->getTimestamp() === $this->img
->getTimestamp() ) {
928 $selected = "class='filehistory-selected'";
930 $row .= "<td $selected style='white-space: nowrap;'>";
931 if ( !$file->userCan( File
::DELETED_FILE
) ) {
932 # Don't link to unviewable files
933 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
934 } elseif ( $file->isDeleted( File
::DELETED_FILE
) ) {
935 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
936 # Make a link to review the image
937 $url = $this->skin
->link(
939 $wgLang->timeAndDate( $timestamp, true ),
942 'target' => $this->title
->getPrefixedText(),
944 'token' => $wgUser->editToken( $img )
946 array( 'known', 'noclasses' )
948 $row .= '<span class="history-deleted">' . $url . '</span>';
950 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
951 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
956 if ( $this->showThumb
) {
957 $row .= '<td>' . $this->getThumbForLine( $file ) . '</td>';
960 // Image dimensions + size
962 $row .= htmlspecialchars( $file->getDimensionsString() );
963 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $file->getSize() ) . ')</span>';
969 // Hide deleted usernames
970 if ( $file->isDeleted( File
::DELETED_USER
) ) {
971 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
973 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
974 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
977 $row .= htmlspecialchars( $usertext );
981 // Don't show deleted descriptions
982 if ( $file->isDeleted( File
::DELETED_COMMENT
) ) {
983 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
985 $row .= $this->skin
->commentBlock( $description, $this->title
);
989 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
990 $classAttr = $rowClass ?
" class='$rowClass'" : "";
992 return "<tr{$classAttr}>{$row}</tr>\n";
995 protected function getThumbForLine( $file ) {
998 if ( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
1003 $timestamp = wfTimestamp( TS_MW
, $file->getTimestamp() );
1005 $thumbnail = $file->transform( $params );
1007 'alt' => wfMsg( 'filehist-thumbtext',
1008 $wgLang->timeAndDate( $timestamp, true ),
1009 $wgLang->date( $timestamp, true ),
1010 $wgLang->time( $timestamp, true ) ),
1011 'file-link' => true,
1014 if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' );
1016 return $thumbnail->toHtml( $options );
1018 return wfMsgHtml( 'filehist-nothumb' );
1023 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
1024 function __construct( $imagePage ) {
1025 parent
::__construct();
1026 $this->mImagePage
= $imagePage;
1027 $this->mTitle
= clone ( $imagePage->getTitle() );
1028 $this->mTitle
->setFragment( '#filehistory' );
1030 $this->mHist
= array();
1031 $this->mRange
= array( 0, 0 ); // display range
1034 function getTitle() {
1035 return $this->mTitle
;
1038 function getQueryInfo() {
1042 function getIndexField() {
1046 function formatRow( $row ) {
1050 function getBody() {
1053 if ( count( $this->mHist
) ) {
1054 $list = new ImageHistoryList( $this->mImagePage
);
1055 # Generate prev/next links
1056 $navLink = $this->getNavigationBar();
1057 $s = $list->beginImageHistoryList( $navLink );
1058 // Skip rows there just for paging links
1059 for ( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1060 $file = $this->mHist
[$i];
1061 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1063 $s .= $list->endImageHistoryList( $navLink );
1068 function doQuery() {
1069 if ( $this->mQueryDone
) return;
1070 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1071 if ( !$this->mImg
->exists() ) {
1074 $queryLimit = $this->mLimit +
1; // limit plus extra row
1075 if ( $this->mIsBackwards
) {
1076 // Fetch the file history
1077 $this->mHist
= $this->mImg
->getHistory( $queryLimit, null, $this->mOffset
, false );
1078 // The current rev may not meet the offset/limit
1079 $numRows = count( $this->mHist
);
1080 if ( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1081 $this->mHist
= array_merge( array( $this->mImg
), $this->mHist
);
1084 // The current rev may not meet the offset
1085 if ( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1086 $this->mHist
[] = $this->mImg
;
1088 // Old image versions (fetch extra row for nav links)
1089 $oiLimit = count( $this->mHist
) ?
$this->mLimit
: $this->mLimit +
1;
1090 // Fetch the file history
1091 $this->mHist
= array_merge( $this->mHist
,
1092 $this->mImg
->getHistory( $oiLimit, $this->mOffset
, null, false ) );
1094 $numRows = count( $this->mHist
); // Total number of query results
1096 # Index value of top item in the list
1097 $firstIndex = $this->mIsBackwards ?
1098 $this->mHist
[$numRows - 1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1099 # Discard the extra result row if there is one
1100 if ( $numRows > $this->mLimit
&& $numRows > 1 ) {
1101 if ( $this->mIsBackwards
) {
1102 # Index value of item past the index
1103 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1104 # Index value of bottom item in the list
1105 $lastIndex = $this->mHist
[1]->getTimestamp();
1107 $this->mRange
= array( 1, $numRows - 1 );
1109 # Index value of item past the index
1110 $this->mPastTheEndIndex
= $this->mHist
[$numRows - 1]->getTimestamp();
1111 # Index value of bottom item in the list
1112 $lastIndex = $this->mHist
[$numRows - 2]->getTimestamp();
1114 $this->mRange
= array( 0, $numRows - 2 );
1117 # Setting indexes to an empty string means that they will be
1118 # omitted if they would otherwise appear in URLs. It just so
1119 # happens that this is the right thing to do in the standard
1120 # UI, in all the relevant cases.
1121 $this->mPastTheEndIndex
= '';
1122 # Index value of bottom item in the list
1123 $lastIndex = $this->mIsBackwards ?
1124 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows - 1]->getTimestamp();
1126 $this->mRange
= array( 0, $numRows - 1 );
1131 $this->mPastTheEndIndex
= '';
1133 if ( $this->mIsBackwards
) {
1134 $this->mIsFirst
= ( $numRows < $queryLimit );
1135 $this->mIsLast
= ( $this->mOffset
== '' );
1136 $this->mLastShown
= $firstIndex;
1137 $this->mFirstShown
= $lastIndex;
1139 $this->mIsFirst
= ( $this->mOffset
== '' );
1140 $this->mIsLast
= ( $numRows < $queryLimit );
1141 $this->mLastShown
= $lastIndex;
1142 $this->mFirstShown
= $firstIndex;
1144 $this->mQueryDone
= true;