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( $this->displayImg
->exists() )
97 $wgOut->addHTML( $this->showTOC($showmeta) );
99 $this->openShowImage();
101 # No need to display noarticletext, we use our own message, output in openShowImage()
102 if( $this->getID() ) {
105 # Just need to set the right headers
106 $wgOut->setArticleFlag( true );
107 $wgOut->setRobotPolicy( 'noindex,nofollow' );
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>' );
120 $this->checkSharedConflict();
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: We may want to find local images redirecting to a foreign
132 // file: "The following local files redirect to this file"
133 if( $this->img
->isLocal() ) {
134 $this->imageRedirects();
139 global $wgStylePath, $wgStyleVersion;
140 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
141 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
142 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
143 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
144 $wgOut->addScriptFile( 'metadata.js' );
146 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
150 public function getRedirectTarget() {
152 if( $this->img
->isLocal() ) {
153 return parent
::getRedirectTarget();
155 // Foreign image page
156 $from = $this->img
->getRedirected();
157 $to = $this->img
->getName();
161 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
163 public function followRedirect() {
165 if( $this->img
->isLocal() ) {
166 return parent
::followRedirect();
168 $from = $this->img
->getRedirected();
169 $to = $this->img
->getName();
173 return Title
::makeTitle( NS_FILE
, $to );
175 public function isRedirect( $text = false ) {
177 if( $this->img
->isLocal() )
178 return parent
::isRedirect( $text );
180 return (bool)$this->img
->getRedirected();
183 public function isLocal() {
185 return $this->img
->isLocal();
188 public function getFile() {
193 public function getDisplayedFile() {
195 return $this->displayImg
;
198 public function getDuplicates() {
200 if( !is_null($this->dupes
) ) {
203 if( !( $hash = $this->img
->getSha1() ) ) {
204 return $this->dupes
= array();
206 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
207 // Remove duplicates with self and non matching file sizes
208 $self = $this->img
->getRepoName().':'.$this->img
->getName();
209 $size = $this->img
->getSize();
210 foreach ( $dupes as $index => $file ) {
211 $key = $file->getRepoName().':'.$file->getName();
213 unset( $dupes[$index] );
214 if( $file->getSize() != $size )
215 unset( $dupes[$index] );
217 return $this->dupes
= $dupes;
225 * @param bool $metadata Whether or not to show the metadata link
228 protected function showTOC( $metadata ) {
230 $r = '<ul id="filetoc">
231 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
232 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
233 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
234 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
240 * Make a table with metadata to be shown in the output page.
242 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
244 * @param array $exif The array containing the EXIF data
247 protected function makeMetadataTable( $metadata ) {
248 $r = wfMsg( 'metadata-help' ) . "\n\n";
249 $r .= "{| id=mw_metadata class=mw_metadata\n";
250 foreach ( $metadata as $type => $stuff ) {
251 foreach ( $stuff as $v ) {
252 $class = Sanitizer
::escapeId( $v['id'] );
253 if( $type == 'collapsed' ) {
254 $class .= ' collapsable';
256 $r .= "|- class=\"$class\"\n";
257 $r .= "!| {$v['name']}\n";
258 $r .= "|| {$v['value']}\n";
266 * Overloading Article's getContent method.
268 * Omit noarticletext if sharedupload; text will be fetched from the
269 * shared upload server if possible.
271 public function getContent() {
273 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
276 return Article
::getContent();
279 protected function openShowImage() {
280 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
284 $full_url = $this->displayImg
->getURL();
285 $linkAttribs = false;
286 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
287 if( !isset( $wgImageLimits[$sizeSel] ) ) {
288 $sizeSel = User
::getDefaultOption( 'imagesize' );
290 // The user offset might still be incorrect, specially if
291 // $wgImageLimits got changed (see bug #8858).
292 if( !isset( $wgImageLimits[$sizeSel] ) ) {
293 // Default to the first offset in $wgImageLimits
297 $max = $wgImageLimits[$sizeSel];
299 $maxHeight = $max[1];
300 $sk = $wgUser->getSkin();
301 $dirmark = $wgContLang->getDirMark();
303 if( $this->displayImg
->exists() ) {
305 $page = $wgRequest->getIntOrNull( 'page' );
306 if( is_null( $page ) ) {
310 $params = array( 'page' => $page );
312 $width_orig = $this->displayImg
->getWidth();
313 $width = $width_orig;
314 $height_orig = $this->displayImg
->getHeight();
315 $height = $height_orig;
316 $mime = $this->displayImg
->getMimeType();
318 $linkAttribs = array( 'href' => $full_url );
319 $longDesc = $this->displayImg
->getLongDesc();
321 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
323 if( $this->displayImg
->allowInlineDisplay() ) {
326 # "Download high res version" link below the image
327 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
328 # We'll show a thumbnail of this image
329 if( $width > $maxWidth ||
$height > $maxHeight ) {
330 # Calculate the thumbnail size.
331 # First case, the limiting factor is the width, not the height.
332 if( $width / $height >= $maxWidth / $maxHeight ) {
333 $height = round( $height * $maxWidth / $width);
335 # Note that $height <= $maxHeight now.
337 $newwidth = floor( $width * $maxHeight / $height);
338 $height = round( $height * $newwidth / $width );
340 # Note that $height <= $maxHeight now, but might not be identical
341 # because of rounding.
343 $msgbig = wfMsgHtml( 'show-big-image' );
344 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
345 $wgLang->formatNum( $width ),
346 $wgLang->formatNum( $height )
349 # Image is small enough to show full size on image page
350 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
351 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
354 $params['width'] = $width;
355 $thumbnail = $this->displayImg
->transform( $params );
357 $anchorclose = "<br />";
358 if( $this->displayImg
->mustRender() ) {
363 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
366 if( $this->displayImg
->isMultipage() ) {
367 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
372 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
375 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
376 $thumbnail->toHtml( $options ) .
377 $anchorclose . '</div>' );
380 if( $this->displayImg
->isMultipage() ) {
381 $count = $this->displayImg
->pageCount();
384 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
385 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
386 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
387 array( 'page' => $page - 1 ) );
392 if( $page < $count ) {
393 $label = wfMsg( 'imgmultipagenext' );
394 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
395 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
396 array( 'page' => $page +
1 ) );
404 'name' => 'pageselector',
405 'action' => $wgScript,
406 'onchange' => 'document.pageselector.submit();',
410 for ( $i=1; $i <= $count; $i++
) {
411 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
413 $select = Xml
::tags( 'select',
414 array( 'id' => 'pageselector', 'name' => 'page' ),
415 implode( "\n", $options ) );
418 '</td><td><div class="multipageimagenavbox">' .
419 Xml
::openElement( 'form', $formParams ) .
420 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
421 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
422 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
423 Xml
::closeElement( 'form' ) .
424 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
428 #if direct link is allowed but it's not a renderable image, show an icon.
429 if( $this->displayImg
->isSafeFile() ) {
430 $icon= $this->displayImg
->iconThumb();
432 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
433 $icon->toHtml( array( 'desc-link' => true ) ) .
442 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
444 if( !$this->displayImg
->isSafeFile() ) {
445 $warning = wfMsgNoTrans( 'mediawarning' );
446 $wgOut->addWikiText( <<<EOT
447 <div class="fullMedia">
448 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
449 <span class="fileInfo"> $longDesc</span>
452 <div class="mediaWarning">$warning</div>
456 $wgOut->addWikiText( <<<EOT
457 <div class="fullMedia">
458 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
465 if( !$this->displayImg
->isLocal() ) {
466 $this->printSharedImageText();
469 # Image does not exist
471 $title = SpecialPage
::getTitleFor( 'Upload' );
472 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
473 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
474 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
479 * Show a notice that the file is from a shared repository
481 protected function printSharedImageText() {
482 global $wgOut, $wgUser;
486 $descUrl = $this->img
->getDescriptionUrl();
487 $descText = $this->img
->getDescriptionText();
488 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
490 $sk = $wgUser->getSkin();
491 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
492 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
493 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
495 # Show message only if not voided by local sysops
500 $wgOut->addHTML( $s );
503 $this->mExtraDescription
= $descText;
508 * Check for files with the same name on the foreign repos.
510 protected function checkSharedConflict() {
511 global $wgOut, $wgUser;
513 $repoGroup = RepoGroup
::singleton();
514 if( !$repoGroup->hasForeignRepos() ) {
519 if( !$this->img
->isLocal() ) {
523 $this->dupFile
= null;
524 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
526 if( !$this->dupFile
)
528 $dupfile = $this->dupFile
;
530 ($this->img
->getSha1() == $dupfile->getSha1()) &&
531 ($this->img
->getSize() == $dupfile->getSize())
534 $sk = $wgUser->getSkin();
535 $descUrl = $dupfile->getDescriptionUrl();
537 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
538 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
540 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
541 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
545 public function checkSharedConflictCallback( $repo ) {
547 $dupfile = $repo->newFile( $this->img
->getTitle() );
548 if( $dupfile && $dupfile->exists() ) {
549 $this->dupFile
= $dupfile;
550 return $dupfile->exists();
555 public function getUploadUrl() {
557 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
558 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
562 * Print out the various links at the bottom of the image page, e.g. reupload,
563 * external editing (and instructions link) etc.
565 protected function uploadLinksBox() {
566 global $wgUser, $wgOut;
569 if( !$this->img
->isLocal() )
572 $sk = $wgUser->getSkin();
574 $wgOut->addHTML( '<br /><ul>' );
576 # "Upload a new version of this file" link
577 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
578 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
579 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
582 # Link to Special:FileDuplicateSearch
583 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
584 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
586 # External editing link
587 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
588 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
590 $wgOut->addHTML( '</ul>' );
593 protected function closeShowImage() {} # For overloading
596 * If the page we've just displayed is in the "Image" namespace,
597 * we follow it with an upload history of the image and its usage.
599 protected function imageHistory() {
600 global $wgOut, $wgUseExternalEditor;
603 $pager = new ImageHistoryPseudoPager( $this );
604 $wgOut->addHTML( $pager->getBody() );
606 $this->img
->resetHistory(); // free db resources
608 # Exist check because we don't want to show this on pages where an image
609 # doesn't exist along with the noimage message, that would suck. -ævar
610 if( $wgUseExternalEditor && $this->img
->exists() ) {
611 $this->uploadLinksBox();
615 protected function imageLinks() {
616 global $wgUser, $wgOut, $wgLang;
620 $dbr = wfGetDB( DB_SLAVE
);
623 array( 'imagelinks', 'page' ),
624 array( 'page_namespace', 'page_title' ),
625 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
627 array( 'LIMIT' => $limit +
1)
629 $count = $dbr->numRows( $res );
631 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
632 $wgOut->addWikiMsg( 'nolinkstoimage' );
633 $wgOut->addHTML( "</div>\n" );
637 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
638 if( $count <= $limit - 1 ) {
639 $wgOut->addWikiMsg( 'linkstoimage', $count );
641 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
642 $wgOut->addWikiMsg( 'linkstoimage-more',
643 $wgLang->formatNum( $limit ),
644 $this->mTitle
->getPrefixedDBkey()
648 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
649 $sk = $wgUser->getSkin();
651 while ( $s = $res->fetchObject() ) {
653 if( $count <= $limit ) {
654 // We have not yet reached the extra one that tells us there is more to fetch
655 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
656 $link = $sk->makeKnownLinkObj( $name, "" );
657 $wgOut->addHTML( "<li>{$link}</li>\n" );
660 $wgOut->addHTML( "</ul></div>\n" );
663 // Add a links to [[Special:Whatlinkshere]]
664 if( $count > $limit )
665 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
668 protected function imageRedirects() {
669 global $wgUser, $wgOut, $wgLang;
671 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
672 if( count( $redirects ) == 0 ) return;
674 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
675 $wgOut->addWikiMsg( 'redirectstofile',
676 $wgLang->formatNum( count( $redirects ) )
678 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
680 $sk = $wgUser->getSkin();
681 foreach ( $redirects as $title ) {
682 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
683 $wgOut->addHTML( "<li>{$link}</li>\n" );
685 $wgOut->addHTML( "</ul></div>\n" );
689 protected function imageDupes() {
690 global $wgOut, $wgUser, $wgLang;
694 $dupes = $this->getDuplicates();
695 if( count( $dupes ) == 0 ) return;
697 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
698 $wgOut->addWikiMsg( 'duplicatesoffile',
699 $wgLang->formatNum( count( $dupes ) )
701 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
703 $sk = $wgUser->getSkin();
704 foreach ( $dupes as $file ) {
705 if( $file->isLocal() )
706 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
708 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
709 $file->getTitle()->getPrefixedText() );
711 $wgOut->addHTML( "<li>{$link}</li>\n" );
713 $wgOut->addHTML( "</ul></div>\n" );
717 * Delete the file, or an earlier version of it
719 public function delete() {
721 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
722 // Standard article deletion
726 $deleter = new FileDeleteForm( $this->img
);
731 * Revert the file to an earlier version
733 public function revert() {
735 $reverter = new FileRevertForm( $this->img
);
736 $reverter->execute();
740 * Override handling of action=purge
742 public function doPurge() {
744 if( $this->img
->exists() ) {
745 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
746 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
748 $this->img
->upgradeRow();
749 $this->img
->purgeCache();
751 wfDebug( "ImagePage::doPurge no image\n" );
757 * Display an error with a wikitext description
759 function showError( $description ) {
761 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
762 $wgOut->setRobotPolicy( "noindex,nofollow" );
763 $wgOut->setArticleRelated( false );
764 $wgOut->enableClientCache( false );
765 $wgOut->addWikiText( $description );
771 * Builds the image revision log shown on image pages
775 class ImageHistoryList
{
777 protected $imagePage, $img, $skin, $title, $repo;
779 public function __construct( $imagePage ) {
781 $this->skin
= $wgUser->getSkin();
782 $this->current
= $imagePage->getFile();
783 $this->img
= $imagePage->getDisplayedFile();
784 $this->title
= $imagePage->getTitle();
785 $this->imagePage
= $imagePage;
788 public function getImagePage() {
789 return $this->imagePage
;
792 public function getSkin() {
796 public function getFile() {
800 public function beginImageHistoryList( $navLinks = '' ) {
801 global $wgOut, $wgUser;
802 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
803 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
805 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
807 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
808 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
809 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
810 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
811 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
812 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
816 public function endImageHistoryList( $navLinks = '' ) {
817 return "</table>\n$navLinks\n";
820 public function imageHistoryLine( $iscur, $file ) {
821 global $wgUser, $wgLang, $wgContLang, $wgTitle;
823 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
824 $img = $iscur ?
$file->getName() : $file->getArchiveName();
825 $user = $file->getUser('id');
826 $usertext = $file->getUser('text');
827 $size = $file->getSize();
828 $description = $file->getDescription();
829 $dims = $file->getDimensionsString();
830 $sha1 = $file->getSha1();
832 $local = $this->current
->isLocal();
833 $row = $css = $selected = '';
836 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
838 # Link to remove from history
839 if( $wgUser->isAllowed( 'delete' ) ) {
841 $q[] = 'action=delete';
843 $q[] = 'oldimage=' . urlencode( $img );
844 $row .= $this->skin
->makeKnownLinkObj(
846 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
850 # Link to hide content
851 if( $wgUser->isAllowed( 'deleterevision' ) ) {
852 if( $wgUser->isAllowed('delete') ) {
855 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
856 // If file is top revision or locked from this user, don't link
857 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
858 $del = wfMsgHtml( 'rev-delundel' );
860 // If the file was hidden, link to sha-1
861 list($ts,$name) = explode('!',$img,2);
862 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
863 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
864 '&oldimage=' . urlencode( $ts ) );
865 // Bolden oversighted content
866 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
867 $del = "<strong>$del</strong>";
869 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
874 // Reversion link/current indicator
877 $row .= wfMsgHtml( 'filehist-current' );
878 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
879 if( $file->isDeleted(File
::DELETED_FILE
) ) {
880 $row .= wfMsgHtml('filehist-revert');
883 $q[] = 'action=revert';
884 $q[] = 'oldimage=' . urlencode( $img );
885 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
886 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
887 wfMsgHtml( 'filehist-revert' ),
888 implode( '&', $q ) );
893 // Date/time and image link
894 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
895 $selected = "class='filehistory-selected'";
897 $row .= "<td $selected style='white-space: nowrap;'>";
898 if( !$file->userCan(File
::DELETED_FILE
) ) {
899 # Don't link to unviewable files
900 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
901 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
902 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
903 # Make a link to review the image
904 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
905 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
906 $row .= '<span class="history-deleted">'.$url.'</span>';
908 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
909 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
913 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
918 $thumbnail = $file->transform( $params );
920 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
923 $row .= '</td><td>' . $thumbnail->toHtml( $options );
925 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
930 $row .= htmlspecialchars( $dims );
933 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
938 // Hide deleted usernames
939 if( $file->isDeleted(File
::DELETED_USER
) ) {
940 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
942 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
943 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
946 $row .= htmlspecialchars( $usertext );
950 // Don't show deleted descriptions
951 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
952 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
954 $row .= $this->skin
->commentBlock( $description, $this->title
);
958 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
959 $classAttr = $rowClass ?
" class='$rowClass'" : "";
961 return "<tr{$classAttr}>{$row}</tr>\n";
965 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
966 function __construct( $imagePage ) {
967 parent
::__construct();
968 $this->mImagePage
=& $imagePage;
969 $this->mTitle
= $imagePage->getTitle();
971 $this->mHist
= array();
972 $this->mRange
= array( 0, 0 ); // display range
975 function getQueryInfo() {
979 function getIndexField() {
983 function formatRow( $row ) {
990 if( count($this->mHist
) ) {
991 $list = new ImageHistoryList( $this->mImagePage
);
992 # Generate prev/next links
993 $navLink = $this->getNavigationBar();
994 $s = $list->beginImageHistoryList($navLink);
995 // Skip rows there just for paging links
996 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
997 $file = $this->mHist
[$i];
998 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1000 $s .= $list->endImageHistoryList($navLink);
1005 function doQuery() {
1006 if( $this->mQueryDone
) return;
1007 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1008 if( !$this->mImg
->exists() ) {
1011 $queryLimit = $this->mLimit +
1; // limit plus extra row
1012 if( $this->mIsBackwards
) {
1013 // Fetch the file history
1014 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1015 // The current rev may not meet the offset/limit
1016 $numRows = count($this->mHist
);
1017 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1018 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1021 // The current rev may not meet the offset
1022 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1023 $this->mHist
[] = $this->mImg
;
1025 // Old image versions (fetch extra row for nav links)
1026 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1027 // Fetch the file history
1028 $this->mHist
= array_merge( $this->mHist
,
1029 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1031 $numRows = count($this->mHist
); // Total number of query results
1033 # Index value of top item in the list
1034 $firstIndex = $this->mIsBackwards ?
1035 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1036 # Discard the extra result row if there is one
1037 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1038 if( $this->mIsBackwards
) {
1039 # Index value of item past the index
1040 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1041 # Index value of bottom item in the list
1042 $lastIndex = $this->mHist
[1]->getTimestamp();
1044 $this->mRange
= array( 1, $numRows-1 );
1046 # Index value of item past the index
1047 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1048 # Index value of bottom item in the list
1049 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1051 $this->mRange
= array( 0, $numRows-2 );
1054 # Setting indexes to an empty string means that they will be
1055 # omitted if they would otherwise appear in URLs. It just so
1056 # happens that this is the right thing to do in the standard
1057 # UI, in all the relevant cases.
1058 $this->mPastTheEndIndex
= '';
1059 # Index value of bottom item in the list
1060 $lastIndex = $this->mIsBackwards ?
1061 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1063 $this->mRange
= array( 0, $numRows-1 );
1068 $this->mPastTheEndIndex
= '';
1070 if( $this->mIsBackwards
) {
1071 $this->mIsFirst
= ( $numRows < $queryLimit );
1072 $this->mIsLast
= ( $this->mOffset
== '' );
1073 $this->mLastShown
= $firstIndex;
1074 $this->mFirstShown
= $lastIndex;
1076 $this->mIsFirst
= ( $this->mOffset
== '' );
1077 $this->mIsLast
= ( $numRows < $queryLimit );
1078 $this->mLastShown
= $lastIndex;
1079 $this->mFirstShown
= $firstIndex;
1081 $this->mQueryDone
= true;