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->setRobotPolicy( 'noindex,nofollow' );
109 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
110 $this->viewUpdates();
113 # Show shared description, if needed
114 if( $this->mExtraDescription
) {
115 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
116 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
117 $wgOut->addWikiText( $fol );
119 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
122 $this->closeShowImage();
123 $this->imageHistory();
124 // TODO: Cleanup the following
126 $wgOut->addHTML( Xml
::element( 'h2',
127 array( 'id' => 'filelinks' ),
128 wfMsg( 'imagelinks' ) ) . "\n" );
130 $this->imageRedirects();
134 global $wgStylePath, $wgStyleVersion;
135 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
136 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
137 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
138 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
139 $wgOut->addScriptFile( 'metadata.js' );
141 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
145 public function getRedirectTarget() {
147 if( $this->img
->isLocal() ) {
148 return parent
::getRedirectTarget();
150 // Foreign image page
151 $from = $this->img
->getRedirected();
152 $to = $this->img
->getName();
156 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
158 public function followRedirect() {
160 if( $this->img
->isLocal() ) {
161 return parent
::followRedirect();
163 $from = $this->img
->getRedirected();
164 $to = $this->img
->getName();
168 return Title
::makeTitle( NS_FILE
, $to );
170 public function isRedirect( $text = false ) {
172 if( $this->img
->isLocal() )
173 return parent
::isRedirect( $text );
175 return (bool)$this->img
->getRedirected();
178 public function isLocal() {
180 return $this->img
->isLocal();
183 public function getFile() {
188 public function getDisplayedFile() {
190 return $this->displayImg
;
193 public function getDuplicates() {
195 if( !is_null($this->dupes
) ) {
198 if( !( $hash = $this->img
->getSha1() ) ) {
199 return $this->dupes
= array();
201 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
202 // Remove duplicates with self and non matching file sizes
203 $self = $this->img
->getRepoName().':'.$this->img
->getName();
204 $size = $this->img
->getSize();
205 foreach ( $dupes as $index => $file ) {
206 $key = $file->getRepoName().':'.$file->getName();
208 unset( $dupes[$index] );
209 if( $file->getSize() != $size )
210 unset( $dupes[$index] );
212 return $this->dupes
= $dupes;
220 * @param bool $metadata Whether or not to show the metadata link
223 protected function showTOC( $metadata ) {
225 $r = '<ul id="filetoc">
226 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
227 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
228 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
229 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
235 * Make a table with metadata to be shown in the output page.
237 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
239 * @param array $exif The array containing the EXIF data
242 protected function makeMetadataTable( $metadata ) {
243 $r = wfMsg( 'metadata-help' ) . "\n\n";
244 $r .= "{| id=mw_metadata class=mw_metadata\n";
245 foreach ( $metadata as $type => $stuff ) {
246 foreach ( $stuff as $v ) {
247 # FIXME, why is this using escapeId for a class?!
248 $class = Sanitizer
::escapeId( $v['id'] );
249 if( $type == 'collapsed' ) {
250 $class .= ' collapsable';
252 $r .= "|- class=\"$class\"\n";
253 $r .= "!| {$v['name']}\n";
254 $r .= "|| {$v['value']}\n";
262 * Overloading Article's getContent method.
264 * Omit noarticletext if sharedupload; text will be fetched from the
265 * shared upload server if possible.
267 public function getContent() {
269 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
272 return Article
::getContent();
275 protected function openShowImage() {
276 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
280 $full_url = $this->displayImg
->getURL();
281 $linkAttribs = false;
282 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
283 if( !isset( $wgImageLimits[$sizeSel] ) ) {
284 $sizeSel = User
::getDefaultOption( 'imagesize' );
286 // The user offset might still be incorrect, specially if
287 // $wgImageLimits got changed (see bug #8858).
288 if( !isset( $wgImageLimits[$sizeSel] ) ) {
289 // Default to the first offset in $wgImageLimits
293 $max = $wgImageLimits[$sizeSel];
295 $maxHeight = $max[1];
296 $sk = $wgUser->getSkin();
297 $dirmark = $wgContLang->getDirMark();
299 if( $this->displayImg
->exists() ) {
301 $page = $wgRequest->getIntOrNull( 'page' );
302 if( is_null( $page ) ) {
306 $params = array( 'page' => $page );
308 $width_orig = $this->displayImg
->getWidth();
309 $width = $width_orig;
310 $height_orig = $this->displayImg
->getHeight();
311 $height = $height_orig;
312 $mime = $this->displayImg
->getMimeType();
314 $linkAttribs = array( 'href' => $full_url );
315 $longDesc = $this->displayImg
->getLongDesc();
317 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
319 if( $this->displayImg
->allowInlineDisplay() ) {
322 # "Download high res version" link below the image
323 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
324 # We'll show a thumbnail of this image
325 if( $width > $maxWidth ||
$height > $maxHeight ) {
326 # Calculate the thumbnail size.
327 # First case, the limiting factor is the width, not the height.
328 if( $width / $height >= $maxWidth / $maxHeight ) {
329 $height = round( $height * $maxWidth / $width);
331 # Note that $height <= $maxHeight now.
333 $newwidth = floor( $width * $maxHeight / $height);
334 $height = round( $height * $newwidth / $width );
336 # Note that $height <= $maxHeight now, but might not be identical
337 # because of rounding.
339 $msgbig = wfMsgHtml( 'show-big-image' );
340 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
341 $wgLang->formatNum( $width ),
342 $wgLang->formatNum( $height )
345 # Image is small enough to show full size on image page
346 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
347 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
350 $params['width'] = $width;
351 $thumbnail = $this->displayImg
->transform( $params );
353 $anchorclose = "<br />";
354 if( $this->displayImg
->mustRender() ) {
359 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
362 if( $this->displayImg
->isMultipage() ) {
363 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
368 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
371 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
372 $thumbnail->toHtml( $options ) .
373 $anchorclose . '</div>' );
376 if( $this->displayImg
->isMultipage() ) {
377 $count = $this->displayImg
->pageCount();
380 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
381 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
382 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
383 array( 'page' => $page - 1 ) );
388 if( $page < $count ) {
389 $label = wfMsg( 'imgmultipagenext' );
390 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
391 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
392 array( 'page' => $page +
1 ) );
400 'name' => 'pageselector',
401 'action' => $wgScript,
402 'onchange' => 'document.pageselector.submit();',
406 for ( $i=1; $i <= $count; $i++
) {
407 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
409 $select = Xml
::tags( 'select',
410 array( 'id' => 'pageselector', 'name' => 'page' ),
411 implode( "\n", $options ) );
414 '</td><td><div class="multipageimagenavbox">' .
415 Xml
::openElement( 'form', $formParams ) .
416 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
417 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
418 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
419 Xml
::closeElement( 'form' ) .
420 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
424 #if direct link is allowed but it's not a renderable image, show an icon.
425 if( $this->displayImg
->isSafeFile() ) {
426 $icon= $this->displayImg
->iconThumb();
428 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
429 $icon->toHtml( array( 'desc-link' => true ) ) .
438 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
440 if( !$this->displayImg
->isSafeFile() ) {
441 $warning = wfMsgNoTrans( 'mediawarning' );
442 $wgOut->addWikiText( <<<EOT
443 <div class="fullMedia">
444 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
445 <span class="fileInfo"> $longDesc</span>
448 <div class="mediaWarning">$warning</div>
452 $wgOut->addWikiText( <<<EOT
453 <div class="fullMedia">
454 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
461 if( !$this->displayImg
->isLocal() ) {
462 $this->printSharedImageText();
465 # Image does not exist
467 $title = SpecialPage
::getTitleFor( 'Upload' );
468 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
469 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
470 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
475 * Show a notice that the file is from a shared repository
477 protected function printSharedImageText() {
478 global $wgOut, $wgUser;
482 $descUrl = $this->img
->getDescriptionUrl();
483 $descText = $this->img
->getDescriptionText();
486 $sk = $wgUser->getSkin();
487 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
488 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
489 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
494 $s = "<div class='sharedUploadNotice'>";
495 $s .= wfMsgWikiHtml( 'sharedupload', $this->img
->getRepo()->getDisplayName(), $msg );
497 $wgOut->addHTML( $s );
500 $this->mExtraDescription
= $descText;
504 public function getUploadUrl() {
506 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
507 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) . '&wpForReUpload=1' );
511 * Print out the various links at the bottom of the image page, e.g. reupload,
512 * external editing (and instructions link) etc.
514 protected function uploadLinksBox() {
515 global $wgUser, $wgOut;
518 if( !$this->img
->isLocal() )
521 $sk = $wgUser->getSkin();
523 $wgOut->addHTML( '<br /><ul>' );
525 # "Upload a new version of this file" link
526 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
527 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
528 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
531 # External editing link
532 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
533 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
535 $wgOut->addHTML( '</ul>' );
538 protected function closeShowImage() {} # For overloading
541 * If the page we've just displayed is in the "Image" namespace,
542 * we follow it with an upload history of the image and its usage.
544 protected function imageHistory() {
545 global $wgOut, $wgUseExternalEditor;
548 $pager = new ImageHistoryPseudoPager( $this );
549 $wgOut->addHTML( $pager->getBody() );
551 $this->img
->resetHistory(); // free db resources
553 # Exist check because we don't want to show this on pages where an image
554 # doesn't exist along with the noimage message, that would suck. -ævar
555 if( $wgUseExternalEditor && $this->img
->exists() ) {
556 $this->uploadLinksBox();
560 protected function imageLinks() {
561 global $wgUser, $wgOut, $wgLang;
565 $dbr = wfGetDB( DB_SLAVE
);
568 array( 'imagelinks', 'page' ),
569 array( 'page_namespace', 'page_title' ),
570 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
572 array( 'LIMIT' => $limit +
1)
574 $count = $dbr->numRows( $res );
576 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
577 $wgOut->addWikiMsg( 'nolinkstoimage' );
578 $wgOut->addHTML( "</div>\n" );
582 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
583 if( $count <= $limit - 1 ) {
584 $wgOut->addWikiMsg( 'linkstoimage', $count );
586 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
587 $wgOut->addWikiMsg( 'linkstoimage-more',
588 $wgLang->formatNum( $limit ),
589 $this->mTitle
->getPrefixedDBkey()
593 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
594 $sk = $wgUser->getSkin();
596 while ( $s = $res->fetchObject() ) {
598 if( $count <= $limit ) {
599 // We have not yet reached the extra one that tells us there is more to fetch
600 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
601 $link = $sk->makeKnownLinkObj( $name, "" );
602 $wgOut->addHTML( "<li>{$link}</li>\n" );
605 $wgOut->addHTML( "</ul></div>\n" );
608 // Add a links to [[Special:Whatlinkshere]]
609 if( $count > $limit )
610 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
613 protected function imageRedirects() {
614 global $wgUser, $wgOut, $wgLang;
616 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
617 if( count( $redirects ) == 0 ) return;
619 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
620 $wgOut->addWikiMsg( 'redirectstofile',
621 $wgLang->formatNum( count( $redirects ) )
623 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
625 $sk = $wgUser->getSkin();
626 foreach ( $redirects as $title ) {
627 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
628 $wgOut->addHTML( "<li>{$link}</li>\n" );
630 $wgOut->addHTML( "</ul></div>\n" );
634 protected function imageDupes() {
635 global $wgOut, $wgUser, $wgLang;
639 $dupes = $this->getDuplicates();
640 if( count( $dupes ) == 0 ) return;
642 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
643 $wgOut->addWikiMsg( 'duplicatesoffile',
644 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
646 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
648 $sk = $wgUser->getSkin();
649 foreach ( $dupes as $file ) {
651 if( $file->isLocal() )
652 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
654 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
655 $file->getTitle()->getPrefixedText() );
656 $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
658 $wgOut->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
660 $wgOut->addHTML( "</ul></div>\n" );
664 * Delete the file, or an earlier version of it
666 public function delete() {
668 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
669 // Standard article deletion
673 $deleter = new FileDeleteForm( $this->img
);
678 * Revert the file to an earlier version
680 public function revert() {
682 $reverter = new FileRevertForm( $this->img
);
683 $reverter->execute();
687 * Override handling of action=purge
689 public function doPurge() {
691 if( $this->img
->exists() ) {
692 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
693 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
695 $this->img
->upgradeRow();
696 $this->img
->purgeCache();
698 wfDebug( "ImagePage::doPurge no image\n" );
704 * Display an error with a wikitext description
706 function showError( $description ) {
708 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
709 $wgOut->setRobotPolicy( "noindex,nofollow" );
710 $wgOut->setArticleRelated( false );
711 $wgOut->enableClientCache( false );
712 $wgOut->addWikiText( $description );
718 * Builds the image revision log shown on image pages
722 class ImageHistoryList
{
724 protected $imagePage, $img, $skin, $title, $repo;
726 public function __construct( $imagePage ) {
728 $this->skin
= $wgUser->getSkin();
729 $this->current
= $imagePage->getFile();
730 $this->img
= $imagePage->getDisplayedFile();
731 $this->title
= $imagePage->getTitle();
732 $this->imagePage
= $imagePage;
735 public function getImagePage() {
736 return $this->imagePage
;
739 public function getSkin() {
743 public function getFile() {
747 public function beginImageHistoryList( $navLinks = '' ) {
748 global $wgOut, $wgUser;
749 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
750 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
752 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
754 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
755 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
756 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
757 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
758 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
759 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
763 public function endImageHistoryList( $navLinks = '' ) {
764 return "</table>\n$navLinks\n";
767 public function imageHistoryLine( $iscur, $file ) {
768 global $wgUser, $wgLang, $wgContLang, $wgTitle;
770 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
771 $img = $iscur ?
$file->getName() : $file->getArchiveName();
772 $user = $file->getUser('id');
773 $usertext = $file->getUser('text');
774 $size = $file->getSize();
775 $description = $file->getDescription();
776 $dims = $file->getDimensionsString();
777 $sha1 = $file->getSha1();
779 $local = $this->current
->isLocal();
780 $row = $css = $selected = '';
783 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
785 # Link to remove from history
786 if( $wgUser->isAllowed( 'delete' ) ) {
788 $q[] = 'action=delete';
790 $q[] = 'oldimage=' . urlencode( $img );
791 $row .= $this->skin
->makeKnownLinkObj(
793 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
797 # Link to hide content
798 if( $wgUser->isAllowed( 'deleterevision' ) ) {
799 if( $wgUser->isAllowed('delete') ) {
802 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
803 // If file is top revision or locked from this user, don't link
804 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
805 $del = wfMsgHtml( 'rev-delundel' );
807 // If the file was hidden, link to sha-1
808 list($ts,$name) = explode('!',$img,2);
809 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
810 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
811 '&oldimage=' . urlencode( $ts ) );
812 // Bolden oversighted content
813 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
814 $del = "<strong>$del</strong>";
816 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
821 // Reversion link/current indicator
824 $row .= wfMsgHtml( 'filehist-current' );
825 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
826 if( $file->isDeleted(File
::DELETED_FILE
) ) {
827 $row .= wfMsgHtml('filehist-revert');
830 $q[] = 'action=revert';
831 $q[] = 'oldimage=' . urlencode( $img );
832 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
833 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
834 wfMsgHtml( 'filehist-revert' ),
835 implode( '&', $q ) );
840 // Date/time and image link
841 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
842 $selected = "class='filehistory-selected'";
844 $row .= "<td $selected style='white-space: nowrap;'>";
845 if( !$file->userCan(File
::DELETED_FILE
) ) {
846 # Don't link to unviewable files
847 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
848 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
849 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
850 # Make a link to review the image
851 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
852 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
853 $row .= '<span class="history-deleted">'.$url.'</span>';
855 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
856 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
860 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
865 $thumbnail = $file->transform( $params );
867 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
870 $row .= '</td><td>' . ( $thumbnail ?
$thumbnail->toHtml( $options ) :
871 wfMsgHtml( 'filehist-nothumb' ) );
873 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
878 $row .= htmlspecialchars( $dims );
881 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
886 // Hide deleted usernames
887 if( $file->isDeleted(File
::DELETED_USER
) ) {
888 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
890 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
891 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
894 $row .= htmlspecialchars( $usertext );
898 // Don't show deleted descriptions
899 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
900 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
902 $row .= $this->skin
->commentBlock( $description, $this->title
);
906 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
907 $classAttr = $rowClass ?
" class='$rowClass'" : "";
909 return "<tr{$classAttr}>{$row}</tr>\n";
913 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
914 function __construct( $imagePage ) {
915 parent
::__construct();
916 $this->mImagePage
= $imagePage;
917 $this->mTitle
= clone( $imagePage->getTitle() );
918 $this->mTitle
->setFragment( '#filehistory' );
920 $this->mHist
= array();
921 $this->mRange
= array( 0, 0 ); // display range
924 function getTitle() {
925 return $this->mTitle
;
928 function getQueryInfo() {
932 function getIndexField() {
936 function formatRow( $row ) {
943 if( count($this->mHist
) ) {
944 $list = new ImageHistoryList( $this->mImagePage
);
945 # Generate prev/next links
946 $navLink = $this->getNavigationBar();
947 $s = $list->beginImageHistoryList($navLink);
948 // Skip rows there just for paging links
949 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
950 $file = $this->mHist
[$i];
951 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
953 $s .= $list->endImageHistoryList($navLink);
959 if( $this->mQueryDone
) return;
960 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
961 if( !$this->mImg
->exists() ) {
964 $queryLimit = $this->mLimit +
1; // limit plus extra row
965 if( $this->mIsBackwards
) {
966 // Fetch the file history
967 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
968 // The current rev may not meet the offset/limit
969 $numRows = count($this->mHist
);
970 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
971 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
974 // The current rev may not meet the offset
975 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
976 $this->mHist
[] = $this->mImg
;
978 // Old image versions (fetch extra row for nav links)
979 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
980 // Fetch the file history
981 $this->mHist
= array_merge( $this->mHist
,
982 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
984 $numRows = count($this->mHist
); // Total number of query results
986 # Index value of top item in the list
987 $firstIndex = $this->mIsBackwards ?
988 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
989 # Discard the extra result row if there is one
990 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
991 if( $this->mIsBackwards
) {
992 # Index value of item past the index
993 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
994 # Index value of bottom item in the list
995 $lastIndex = $this->mHist
[1]->getTimestamp();
997 $this->mRange
= array( 1, $numRows-1 );
999 # Index value of item past the index
1000 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1001 # Index value of bottom item in the list
1002 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1004 $this->mRange
= array( 0, $numRows-2 );
1007 # Setting indexes to an empty string means that they will be
1008 # omitted if they would otherwise appear in URLs. It just so
1009 # happens that this is the right thing to do in the standard
1010 # UI, in all the relevant cases.
1011 $this->mPastTheEndIndex
= '';
1012 # Index value of bottom item in the list
1013 $lastIndex = $this->mIsBackwards ?
1014 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1016 $this->mRange
= array( 0, $numRows-1 );
1021 $this->mPastTheEndIndex
= '';
1023 if( $this->mIsBackwards
) {
1024 $this->mIsFirst
= ( $numRows < $queryLimit );
1025 $this->mIsLast
= ( $this->mOffset
== '' );
1026 $this->mLastShown
= $firstIndex;
1027 $this->mFirstShown
= $lastIndex;
1029 $this->mIsFirst
= ( $this->mOffset
== '' );
1030 $this->mIsLast
= ( $numRows < $queryLimit );
1031 $this->mLastShown
= $lastIndex;
1032 $this->mFirstShown
= $firstIndex;
1034 $this->mQueryDone
= true;