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 # FIXME, why is this using escapeId for a class?!
253 $class = Sanitizer
::escapeId( $v['id'] );
254 if( $type == 'collapsed' ) {
255 $class .= ' collapsable';
257 $r .= "|- class=\"$class\"\n";
258 $r .= "!| {$v['name']}\n";
259 $r .= "|| {$v['value']}\n";
267 * Overloading Article's getContent method.
269 * Omit noarticletext if sharedupload; text will be fetched from the
270 * shared upload server if possible.
272 public function getContent() {
274 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
277 return Article
::getContent();
280 protected function openShowImage() {
281 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
285 $full_url = $this->displayImg
->getURL();
286 $linkAttribs = false;
287 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
288 if( !isset( $wgImageLimits[$sizeSel] ) ) {
289 $sizeSel = User
::getDefaultOption( 'imagesize' );
291 // The user offset might still be incorrect, specially if
292 // $wgImageLimits got changed (see bug #8858).
293 if( !isset( $wgImageLimits[$sizeSel] ) ) {
294 // Default to the first offset in $wgImageLimits
298 $max = $wgImageLimits[$sizeSel];
300 $maxHeight = $max[1];
301 $sk = $wgUser->getSkin();
302 $dirmark = $wgContLang->getDirMark();
304 if( $this->displayImg
->exists() ) {
306 $page = $wgRequest->getIntOrNull( 'page' );
307 if( is_null( $page ) ) {
311 $params = array( 'page' => $page );
313 $width_orig = $this->displayImg
->getWidth();
314 $width = $width_orig;
315 $height_orig = $this->displayImg
->getHeight();
316 $height = $height_orig;
317 $mime = $this->displayImg
->getMimeType();
319 $linkAttribs = array( 'href' => $full_url );
320 $longDesc = $this->displayImg
->getLongDesc();
322 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
324 if( $this->displayImg
->allowInlineDisplay() ) {
327 # "Download high res version" link below the image
328 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
329 # We'll show a thumbnail of this image
330 if( $width > $maxWidth ||
$height > $maxHeight ) {
331 # Calculate the thumbnail size.
332 # First case, the limiting factor is the width, not the height.
333 if( $width / $height >= $maxWidth / $maxHeight ) {
334 $height = round( $height * $maxWidth / $width);
336 # Note that $height <= $maxHeight now.
338 $newwidth = floor( $width * $maxHeight / $height);
339 $height = round( $height * $newwidth / $width );
341 # Note that $height <= $maxHeight now, but might not be identical
342 # because of rounding.
344 $msgbig = wfMsgHtml( 'show-big-image' );
345 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
346 $wgLang->formatNum( $width ),
347 $wgLang->formatNum( $height )
350 # Image is small enough to show full size on image page
351 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
352 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
355 $params['width'] = $width;
356 $thumbnail = $this->displayImg
->transform( $params );
358 $anchorclose = "<br />";
359 if( $this->displayImg
->mustRender() ) {
364 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
367 if( $this->displayImg
->isMultipage() ) {
368 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
373 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
376 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
377 $thumbnail->toHtml( $options ) .
378 $anchorclose . '</div>' );
381 if( $this->displayImg
->isMultipage() ) {
382 $count = $this->displayImg
->pageCount();
385 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
386 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
387 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
388 array( 'page' => $page - 1 ) );
393 if( $page < $count ) {
394 $label = wfMsg( 'imgmultipagenext' );
395 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
396 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
397 array( 'page' => $page +
1 ) );
405 'name' => 'pageselector',
406 'action' => $wgScript,
407 'onchange' => 'document.pageselector.submit();',
411 for ( $i=1; $i <= $count; $i++
) {
412 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
414 $select = Xml
::tags( 'select',
415 array( 'id' => 'pageselector', 'name' => 'page' ),
416 implode( "\n", $options ) );
419 '</td><td><div class="multipageimagenavbox">' .
420 Xml
::openElement( 'form', $formParams ) .
421 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
422 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
423 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
424 Xml
::closeElement( 'form' ) .
425 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
429 #if direct link is allowed but it's not a renderable image, show an icon.
430 if( $this->displayImg
->isSafeFile() ) {
431 $icon= $this->displayImg
->iconThumb();
433 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
434 $icon->toHtml( array( 'desc-link' => true ) ) .
443 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
445 if( !$this->displayImg
->isSafeFile() ) {
446 $warning = wfMsgNoTrans( 'mediawarning' );
447 $wgOut->addWikiText( <<<EOT
448 <div class="fullMedia">
449 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
450 <span class="fileInfo"> $longDesc</span>
453 <div class="mediaWarning">$warning</div>
457 $wgOut->addWikiText( <<<EOT
458 <div class="fullMedia">
459 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
466 if( !$this->displayImg
->isLocal() ) {
467 $this->printSharedImageText();
470 # Image does not exist
472 $title = SpecialPage
::getTitleFor( 'Upload' );
473 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
474 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
475 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
480 * Show a notice that the file is from a shared repository
482 protected function printSharedImageText() {
483 global $wgOut, $wgUser;
487 $descUrl = $this->img
->getDescriptionUrl();
488 $descText = $this->img
->getDescriptionText();
489 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
491 $sk = $wgUser->getSkin();
492 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
493 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
494 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
496 # Show message only if not voided by local sysops
501 $wgOut->addHTML( $s );
504 $this->mExtraDescription
= $descText;
509 * Check for files with the same name on the foreign repos.
511 protected function checkSharedConflict() {
512 global $wgOut, $wgUser;
514 $repoGroup = RepoGroup
::singleton();
515 if( !$repoGroup->hasForeignRepos() ) {
520 if( !$this->img
->isLocal() ) {
524 $this->dupFile
= null;
525 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
527 if( !$this->dupFile
)
529 $dupfile = $this->dupFile
;
531 ($this->img
->getSha1() == $dupfile->getSha1()) &&
532 ($this->img
->getSize() == $dupfile->getSize())
535 $sk = $wgUser->getSkin();
536 $descUrl = $dupfile->getDescriptionUrl();
538 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
539 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
541 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
542 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
546 public function checkSharedConflictCallback( $repo ) {
548 $dupfile = $repo->newFile( $this->img
->getTitle() );
549 if( $dupfile && $dupfile->exists() ) {
550 $this->dupFile
= $dupfile;
551 return $dupfile->exists();
556 public function getUploadUrl() {
558 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
559 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
563 * Print out the various links at the bottom of the image page, e.g. reupload,
564 * external editing (and instructions link) etc.
566 protected function uploadLinksBox() {
567 global $wgUser, $wgOut;
570 if( !$this->img
->isLocal() )
573 $sk = $wgUser->getSkin();
575 $wgOut->addHTML( '<br /><ul>' );
577 # "Upload a new version of this file" link
578 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
579 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
580 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
583 # Link to Special:FileDuplicateSearch
584 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
585 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
587 # External editing link
588 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
589 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
591 $wgOut->addHTML( '</ul>' );
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() {
601 global $wgOut, $wgUseExternalEditor;
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( $wgUseExternalEditor && $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
656 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
657 $link = $sk->makeKnownLinkObj( $name, "" );
658 $wgOut->addHTML( "<li>{$link}</li>\n" );
661 $wgOut->addHTML( "</ul></div>\n" );
664 // Add a links to [[Special:Whatlinkshere]]
665 if( $count > $limit )
666 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
669 protected function imageRedirects() {
670 global $wgUser, $wgOut, $wgLang;
672 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
673 if( count( $redirects ) == 0 ) return;
675 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
676 $wgOut->addWikiMsg( 'redirectstofile',
677 $wgLang->formatNum( count( $redirects ) )
679 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
681 $sk = $wgUser->getSkin();
682 foreach ( $redirects as $title ) {
683 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
684 $wgOut->addHTML( "<li>{$link}</li>\n" );
686 $wgOut->addHTML( "</ul></div>\n" );
690 protected function imageDupes() {
691 global $wgOut, $wgUser, $wgLang;
695 $dupes = $this->getDuplicates();
696 if( count( $dupes ) == 0 ) return;
698 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
699 $wgOut->addWikiMsg( 'duplicatesoffile',
700 $wgLang->formatNum( count( $dupes ) )
702 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
704 $sk = $wgUser->getSkin();
705 foreach ( $dupes as $file ) {
706 if( $file->isLocal() )
707 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
709 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
710 $file->getTitle()->getPrefixedText() );
712 $wgOut->addHTML( "<li>{$link}</li>\n" );
714 $wgOut->addHTML( "</ul></div>\n" );
718 * Delete the file, or an earlier version of it
720 public function delete() {
722 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
723 // Standard article deletion
727 $deleter = new FileDeleteForm( $this->img
);
732 * Revert the file to an earlier version
734 public function revert() {
736 $reverter = new FileRevertForm( $this->img
);
737 $reverter->execute();
741 * Override handling of action=purge
743 public function doPurge() {
745 if( $this->img
->exists() ) {
746 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
747 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
749 $this->img
->upgradeRow();
750 $this->img
->purgeCache();
752 wfDebug( "ImagePage::doPurge no image\n" );
758 * Display an error with a wikitext description
760 function showError( $description ) {
762 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
763 $wgOut->setRobotPolicy( "noindex,nofollow" );
764 $wgOut->setArticleRelated( false );
765 $wgOut->enableClientCache( false );
766 $wgOut->addWikiText( $description );
772 * Builds the image revision log shown on image pages
776 class ImageHistoryList
{
778 protected $imagePage, $img, $skin, $title, $repo;
780 public function __construct( $imagePage ) {
782 $this->skin
= $wgUser->getSkin();
783 $this->current
= $imagePage->getFile();
784 $this->img
= $imagePage->getDisplayedFile();
785 $this->title
= $imagePage->getTitle();
786 $this->imagePage
= $imagePage;
789 public function getImagePage() {
790 return $this->imagePage
;
793 public function getSkin() {
797 public function getFile() {
801 public function beginImageHistoryList( $navLinks = '' ) {
802 global $wgOut, $wgUser;
803 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
804 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
806 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
808 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
809 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
810 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
811 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
812 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
813 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
817 public function endImageHistoryList( $navLinks = '' ) {
818 return "</table>\n$navLinks\n";
821 public function imageHistoryLine( $iscur, $file ) {
822 global $wgUser, $wgLang, $wgContLang, $wgTitle;
824 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
825 $img = $iscur ?
$file->getName() : $file->getArchiveName();
826 $user = $file->getUser('id');
827 $usertext = $file->getUser('text');
828 $size = $file->getSize();
829 $description = $file->getDescription();
830 $dims = $file->getDimensionsString();
831 $sha1 = $file->getSha1();
833 $local = $this->current
->isLocal();
834 $row = $css = $selected = '';
837 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
839 # Link to remove from history
840 if( $wgUser->isAllowed( 'delete' ) ) {
842 $q[] = 'action=delete';
844 $q[] = 'oldimage=' . urlencode( $img );
845 $row .= $this->skin
->makeKnownLinkObj(
847 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
851 # Link to hide content
852 if( $wgUser->isAllowed( 'deleterevision' ) ) {
853 if( $wgUser->isAllowed('delete') ) {
856 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
857 // If file is top revision or locked from this user, don't link
858 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
859 $del = wfMsgHtml( 'rev-delundel' );
861 // If the file was hidden, link to sha-1
862 list($ts,$name) = explode('!',$img,2);
863 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
864 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
865 '&oldimage=' . urlencode( $ts ) );
866 // Bolden oversighted content
867 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
868 $del = "<strong>$del</strong>";
870 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
875 // Reversion link/current indicator
878 $row .= wfMsgHtml( 'filehist-current' );
879 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
880 if( $file->isDeleted(File
::DELETED_FILE
) ) {
881 $row .= wfMsgHtml('filehist-revert');
884 $q[] = 'action=revert';
885 $q[] = 'oldimage=' . urlencode( $img );
886 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
887 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
888 wfMsgHtml( 'filehist-revert' ),
889 implode( '&', $q ) );
894 // Date/time and image link
895 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
896 $selected = "class='filehistory-selected'";
898 $row .= "<td $selected style='white-space: nowrap;'>";
899 if( !$file->userCan(File
::DELETED_FILE
) ) {
900 # Don't link to unviewable files
901 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
902 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
903 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
904 # Make a link to review the image
905 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
906 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
907 $row .= '<span class="history-deleted">'.$url.'</span>';
909 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
910 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
914 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
919 $thumbnail = $file->transform( $params );
921 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
924 $row .= '</td><td>' . $thumbnail->toHtml( $options );
926 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
931 $row .= htmlspecialchars( $dims );
934 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
939 // Hide deleted usernames
940 if( $file->isDeleted(File
::DELETED_USER
) ) {
941 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
943 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
944 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
947 $row .= htmlspecialchars( $usertext );
951 // Don't show deleted descriptions
952 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
953 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
955 $row .= $this->skin
->commentBlock( $description, $this->title
);
959 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
960 $classAttr = $rowClass ?
" class='$rowClass'" : "";
962 return "<tr{$classAttr}>{$row}</tr>\n";
966 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
967 function __construct( $imagePage ) {
968 parent
::__construct();
969 $this->mImagePage
= $imagePage;
970 $this->mTitle
= clone( $imagePage->getTitle() );
971 $this->mTitle
->setFragment( '#filehistory' );
973 $this->mHist
= array();
974 $this->mRange
= array( 0, 0 ); // display range
977 function getTitle() {
978 return $this->mTitle
;
981 function getQueryInfo() {
985 function getIndexField() {
989 function formatRow( $row ) {
996 if( count($this->mHist
) ) {
997 $list = new ImageHistoryList( $this->mImagePage
);
998 # Generate prev/next links
999 $navLink = $this->getNavigationBar();
1000 $s = $list->beginImageHistoryList($navLink);
1001 // Skip rows there just for paging links
1002 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1003 $file = $this->mHist
[$i];
1004 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1006 $s .= $list->endImageHistoryList($navLink);
1011 function doQuery() {
1012 if( $this->mQueryDone
) return;
1013 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1014 if( !$this->mImg
->exists() ) {
1017 $queryLimit = $this->mLimit +
1; // limit plus extra row
1018 if( $this->mIsBackwards
) {
1019 // Fetch the file history
1020 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1021 // The current rev may not meet the offset/limit
1022 $numRows = count($this->mHist
);
1023 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1024 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1027 // The current rev may not meet the offset
1028 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1029 $this->mHist
[] = $this->mImg
;
1031 // Old image versions (fetch extra row for nav links)
1032 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1033 // Fetch the file history
1034 $this->mHist
= array_merge( $this->mHist
,
1035 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1037 $numRows = count($this->mHist
); // Total number of query results
1039 # Index value of top item in the list
1040 $firstIndex = $this->mIsBackwards ?
1041 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1042 # Discard the extra result row if there is one
1043 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1044 if( $this->mIsBackwards
) {
1045 # Index value of item past the index
1046 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1047 # Index value of bottom item in the list
1048 $lastIndex = $this->mHist
[1]->getTimestamp();
1050 $this->mRange
= array( 1, $numRows-1 );
1052 # Index value of item past the index
1053 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1054 # Index value of bottom item in the list
1055 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1057 $this->mRange
= array( 0, $numRows-2 );
1060 # Setting indexes to an empty string means that they will be
1061 # omitted if they would otherwise appear in URLs. It just so
1062 # happens that this is the right thing to do in the standard
1063 # UI, in all the relevant cases.
1064 $this->mPastTheEndIndex
= '';
1065 # Index value of bottom item in the list
1066 $lastIndex = $this->mIsBackwards ?
1067 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1069 $this->mRange
= array( 0, $numRows-1 );
1074 $this->mPastTheEndIndex
= '';
1076 if( $this->mIsBackwards
) {
1077 $this->mIsFirst
= ( $numRows < $queryLimit );
1078 $this->mIsLast
= ( $this->mOffset
== '' );
1079 $this->mLastShown
= $firstIndex;
1080 $this->mFirstShown
= $lastIndex;
1082 $this->mIsFirst
= ( $this->mOffset
== '' );
1083 $this->mIsLast
= ( $numRows < $queryLimit );
1084 $this->mLastShown
= $lastIndex;
1085 $this->mFirstShown
= $firstIndex;
1087 $this->mQueryDone
= true;