3 if( !defined( 'MEDIAWIKI' ) )
7 * Special handling for image description pages
11 class ImagePage
extends Article
{
13 /* private */ var $img; // Image object
14 /* private */ var $displayImg;
15 /* private */ var $repo;
16 /* private */ var $fileLoaded;
17 var $mExtraDescription = false;
20 function __construct( $title ) {
21 parent
::__construct( $title );
26 public function setFile( $file ) {
27 $this->displayImg
= $file;
29 $this->fileLoaded
= true;
32 protected function loadFile() {
33 if( $this->fileLoaded
) {
36 $this->fileLoaded
= true;
38 $this->displayImg
= $this->img
= false;
39 wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img
, &$this->displayImg
) );
41 $this->img
= wfFindFile( $this->mTitle
);
43 $this->img
= wfLocalFile( $this->mTitle
);
46 if( !$this->displayImg
) {
47 $this->displayImg
= $this->img
;
49 $this->repo
= $this->img
->getRepo();
53 * Handler for action=render
54 * Include body text only; none of the image extras
56 public function render() {
58 $wgOut->setArticleBodyOnly( true );
62 public function view() {
63 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
66 if( $this->mTitle
->getNamespace() == NS_FILE
&& $this->img
->getRedirected() ) {
67 if( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
68 // mTitle is the same as the redirect target so ask Article
69 // to perform the redirect for us.
70 return Article
::view();
72 // mTitle is not the same as the redirect target so it is
73 // probably the redirect page itself. Fake the redirect symbol
74 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
75 $wgOut->addHTML( $this->viewRedirect( Title
::makeTitle( NS_FILE
, $this->img
->getName() ),
76 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
82 $diff = $wgRequest->getVal( 'diff' );
83 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
85 if( $this->mTitle
->getNamespace() != NS_FILE ||
( isset( $diff ) && $diffOnly ) )
86 return Article
::view();
88 if( $wgShowEXIF && $this->displayImg
->exists() ) {
89 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
90 $formattedMetadata = $this->displayImg
->formatMetadata();
91 $showmeta = $formattedMetadata !== false;
96 if( !$diff && $this->displayImg
->exists() )
97 $wgOut->addHTML( $this->showTOC($showmeta) );
100 $this->openShowImage();
102 # No need to display noarticletext, we use our own message, output in openShowImage()
103 if( $this->getID() ) {
106 # Just need to set the right headers
107 $wgOut->setArticleFlag( true );
108 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
109 $this->viewUpdates();
112 # Show shared description, if needed
113 if( $this->mExtraDescription
) {
114 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
115 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
116 $wgOut->addWikiText( $fol );
118 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. "</div>\n" );
121 $this->closeShowImage();
122 $this->imageHistory();
123 // TODO: Cleanup the following
125 $wgOut->addHTML( Xml
::element( 'h2',
126 array( 'id' => 'filelinks' ),
127 wfMsg( 'imagelinks' ) ) . "\n" );
129 # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
130 # Yet we return metadata about the target. Definitely an issue in the FileRepo
131 $this->imageRedirects();
135 global $wgStylePath, $wgStyleVersion;
136 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
137 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
138 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
139 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
140 $wgOut->addScriptFile( 'metadata.js' );
142 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
146 public function getRedirectTarget() {
148 if( $this->img
->isLocal() ) {
149 return parent
::getRedirectTarget();
151 // Foreign image page
152 $from = $this->img
->getRedirected();
153 $to = $this->img
->getName();
157 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
159 public function followRedirect() {
161 if( $this->img
->isLocal() ) {
162 return parent
::followRedirect();
164 $from = $this->img
->getRedirected();
165 $to = $this->img
->getName();
169 return Title
::makeTitle( NS_FILE
, $to );
171 public function isRedirect( $text = false ) {
173 if( $this->img
->isLocal() )
174 return parent
::isRedirect( $text );
176 return (bool)$this->img
->getRedirected();
179 public function isLocal() {
181 return $this->img
->isLocal();
184 public function getFile() {
189 public function getDisplayedFile() {
191 return $this->displayImg
;
194 public function getDuplicates() {
196 if( !is_null($this->dupes
) ) {
199 if( !( $hash = $this->img
->getSha1() ) ) {
200 return $this->dupes
= array();
202 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
203 // Remove duplicates with self and non matching file sizes
204 $self = $this->img
->getRepoName().':'.$this->img
->getName();
205 $size = $this->img
->getSize();
206 foreach ( $dupes as $index => $file ) {
207 $key = $file->getRepoName().':'.$file->getName();
209 unset( $dupes[$index] );
210 if( $file->getSize() != $size )
211 unset( $dupes[$index] );
213 return $this->dupes
= $dupes;
221 * @param bool $metadata Whether or not to show the metadata link
224 protected function showTOC( $metadata ) {
226 $r = '<ul id="filetoc">
227 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
228 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
229 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . "</a></li>\n" .
230 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . "
236 * Make a table with metadata to be shown in the output page.
238 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
240 * @param array $exif The array containing the EXIF data
243 protected function makeMetadataTable( $metadata ) {
244 $r = "<div class=\"mw-imagepage-section-metadata\">\n";
245 $r .= wfMsg( 'metadata-help' );
246 $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
247 foreach ( $metadata as $type => $stuff ) {
248 foreach ( $stuff as $v ) {
249 # FIXME, why is this using escapeId for a class?!
250 $class = Sanitizer
::escapeId( $v['id'] );
251 if( $type == 'collapsed' ) {
252 $class .= ' collapsable';
254 $r .= "<tr class=\"$class\">\n";
255 $r .= "<th>{$v['name']}</th>\n";
256 $r .= "<td>{$v['value']}</td>\n</tr>";
259 $r .= "</table>\n</div>\n";
264 * Overloading Article's getContent method.
266 * Omit noarticletext if sharedupload; text will be fetched from the
267 * shared upload server if possible.
269 public function getContent() {
271 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
274 return Article
::getContent();
277 protected function openShowImage() {
278 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
282 $full_url = $this->displayImg
->getURL();
283 $linkAttribs = false;
284 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
285 if( !isset( $wgImageLimits[$sizeSel] ) ) {
286 $sizeSel = User
::getDefaultOption( 'imagesize' );
288 // The user offset might still be incorrect, specially if
289 // $wgImageLimits got changed (see bug #8858).
290 if( !isset( $wgImageLimits[$sizeSel] ) ) {
291 // Default to the first offset in $wgImageLimits
295 $max = $wgImageLimits[$sizeSel];
297 $maxHeight = $max[1];
298 $sk = $wgUser->getSkin();
299 $dirmark = $wgContLang->getDirMark();
301 if( $this->displayImg
->exists() ) {
303 $page = $wgRequest->getIntOrNull( 'page' );
304 if( is_null( $page ) ) {
308 $params = array( 'page' => $page );
310 $width_orig = $this->displayImg
->getWidth();
311 $width = $width_orig;
312 $height_orig = $this->displayImg
->getHeight();
313 $height = $height_orig;
314 $mime = $this->displayImg
->getMimeType();
316 $linkAttribs = array( 'href' => $full_url );
317 $longDesc = $this->displayImg
->getLongDesc();
319 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
321 if( $this->displayImg
->allowInlineDisplay() ) {
324 # "Download high res version" link below the image
325 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
326 # We'll show a thumbnail of this image
327 if( $width > $maxWidth ||
$height > $maxHeight ) {
328 # Calculate the thumbnail size.
329 # First case, the limiting factor is the width, not the height.
330 if( $width / $height >= $maxWidth / $maxHeight ) {
331 $height = round( $height * $maxWidth / $width);
333 # Note that $height <= $maxHeight now.
335 $newwidth = floor( $width * $maxHeight / $height);
336 $height = round( $height * $newwidth / $width );
338 # Note that $height <= $maxHeight now, but might not be identical
339 # because of rounding.
341 $msgbig = wfMsgHtml( 'show-big-image' );
342 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
343 $wgLang->formatNum( $width ),
344 $wgLang->formatNum( $height )
347 # Image is small enough to show full size on image page
348 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
349 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
352 $params['width'] = $width;
353 $thumbnail = $this->displayImg
->transform( $params );
355 $anchorclose = "<br />";
356 if( $this->displayImg
->mustRender() ) {
361 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
364 if( $this->displayImg
->isMultipage() ) {
365 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
370 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
373 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
374 $thumbnail->toHtml( $options ) .
375 $anchorclose . "</div>\n" );
378 if( $this->displayImg
->isMultipage() ) {
379 $count = $this->displayImg
->pageCount();
382 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
383 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
384 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
385 array( 'page' => $page - 1 ) );
390 if( $page < $count ) {
391 $label = wfMsg( 'imgmultipagenext' );
392 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
393 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
394 array( 'page' => $page +
1 ) );
402 'name' => 'pageselector',
403 'action' => $wgScript,
404 'onchange' => 'document.pageselector.submit();',
408 for ( $i=1; $i <= $count; $i++
) {
409 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
411 $select = Xml
::tags( 'select',
412 array( 'id' => 'pageselector', 'name' => 'page' ),
413 implode( "\n", $options ) );
416 '</td><td><div class="multipageimagenavbox">' .
417 Xml
::openElement( 'form', $formParams ) .
418 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
419 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
420 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
421 Xml
::closeElement( 'form' ) .
422 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
426 #if direct link is allowed but it's not a renderable image, show an icon.
427 if( $this->displayImg
->isSafeFile() ) {
428 $icon= $this->displayImg
->iconThumb();
430 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
431 $icon->toHtml( array( 'desc-link' => true ) ) .
440 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
442 if( !$this->displayImg
->isSafeFile() ) {
443 $warning = wfMsgNoTrans( 'mediawarning' );
444 $wgOut->addWikiText( <<<EOT
445 <div class="fullMedia">
446 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
447 <span class="fileInfo">$longDesc</span>
449 <div class="mediaWarning">$warning</div>
453 $wgOut->addWikiText( <<<EOT
454 <div class="fullMedia">
455 [[Media:$filename|$filename]]$dirmark
456 <span class="fileInfo">$longDesc</span>
463 if( !$this->displayImg
->isLocal() ) {
464 $this->printSharedImageText();
467 # Image does not exist
469 $title = SpecialPage
::getTitleFor( 'Upload' );
470 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
471 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
472 $wgOut->setRobotPolicy( 'noindex,nofollow' );
473 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
478 * Show a notice that the file is from a shared repository
480 protected function printSharedImageText() {
481 global $wgOut, $wgUser;
485 $descUrl = $this->img
->getDescriptionUrl();
486 $descText = $this->img
->getDescriptionText();
488 $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
489 $repo = $this->img
->getRepo()->getDisplayName();
492 if( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-' ) {
493 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) );
494 } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) {
495 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) );
497 $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ );
501 $this->mExtraDescription
= $descText;
505 public function getUploadUrl() {
507 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
508 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) . '&wpForReUpload=1' );
512 * Print out the various links at the bottom of the image page, e.g. reupload,
513 * external editing (and instructions link) etc.
515 protected function uploadLinksBox() {
516 global $wgUser, $wgOut;
519 if( !$this->img
->isLocal() )
522 $sk = $wgUser->getSkin();
524 $wgOut->addHTML( "<br /><ul>\n" );
526 # "Upload a new version of this file" link
527 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
528 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
529 $wgOut->addHTML( "<li id=\"mw-imagepage-reupload-link\"><div class=\"plainlinks\">{$ulink}</div></li>\n" );
532 # External editing link
533 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
534 $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
536 $wgOut->addHTML( "</ul>\n" );
539 protected function closeShowImage() {} # For overloading
542 * If the page we've just displayed is in the "Image" namespace,
543 * we follow it with an upload history of the image and its usage.
545 protected function imageHistory() {
546 global $wgOut, $wgUseExternalEditor;
549 $pager = new ImageHistoryPseudoPager( $this );
550 $wgOut->addHTML( $pager->getBody() );
552 $this->img
->resetHistory(); // free db resources
554 # Exist check because we don't want to show this on pages where an image
555 # doesn't exist along with the noimage message, that would suck. -ævar
556 if( $wgUseExternalEditor && $this->img
->exists() ) {
557 $this->uploadLinksBox();
561 protected function imageLinks() {
562 global $wgUser, $wgOut, $wgLang;
566 $dbr = wfGetDB( DB_SLAVE
);
569 array( 'imagelinks', 'page' ),
570 array( 'page_namespace', 'page_title' ),
571 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
573 array( 'LIMIT' => $limit +
1)
575 $count = $dbr->numRows( $res );
577 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
578 $wgOut->addWikiMsg( 'nolinkstoimage' );
579 $wgOut->addHTML( "</div>\n" );
583 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
584 if( $count <= $limit - 1 ) {
585 $wgOut->addWikiMsg( 'linkstoimage', $count );
587 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
588 $wgOut->addWikiMsg( 'linkstoimage-more',
589 $wgLang->formatNum( $limit ),
590 $this->mTitle
->getPrefixedDBkey()
594 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
595 $sk = $wgUser->getSkin();
597 while ( $s = $res->fetchObject() ) {
599 if( $count <= $limit ) {
600 // We have not yet reached the extra one that tells us there is more to fetch
601 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
602 $link = $sk->makeKnownLinkObj( $name, "" );
603 $wgOut->addHTML( "<li>{$link}</li>\n" );
606 $wgOut->addHTML( "</ul>\n" );
609 // Add a links to [[Special:Whatlinkshere]]
610 if( $count > $limit )
611 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
612 $wgOut->addHTML( "</div>\n" );
615 protected function imageRedirects() {
616 global $wgUser, $wgOut, $wgLang;
618 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
619 if( count( $redirects ) == 0 ) return;
621 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
622 $wgOut->addWikiMsg( 'redirectstofile',
623 $wgLang->formatNum( count( $redirects ) )
625 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
627 $sk = $wgUser->getSkin();
628 foreach ( $redirects as $title ) {
629 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
630 $wgOut->addHTML( "<li>{$link}</li>\n" );
632 $wgOut->addHTML( "</ul></div>\n" );
636 protected function imageDupes() {
637 global $wgOut, $wgUser, $wgLang;
641 $dupes = $this->getDuplicates();
642 if( count( $dupes ) == 0 ) return;
644 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
645 $wgOut->addWikiMsg( 'duplicatesoffile',
646 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
648 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
650 $sk = $wgUser->getSkin();
651 foreach ( $dupes as $file ) {
653 if( $file->isLocal() )
654 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
656 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
657 $file->getTitle()->getPrefixedText() );
658 $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() );
660 $wgOut->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
662 $wgOut->addHTML( "</ul></div>\n" );
666 * Delete the file, or an earlier version of it
668 public function delete() {
670 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
671 // Standard article deletion
675 $deleter = new FileDeleteForm( $this->img
);
680 * Revert the file to an earlier version
682 public function revert() {
684 $reverter = new FileRevertForm( $this->img
);
685 $reverter->execute();
689 * Override handling of action=purge
691 public function doPurge() {
693 if( $this->img
->exists() ) {
694 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
695 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
697 $this->img
->upgradeRow();
698 $this->img
->purgeCache();
700 wfDebug( "ImagePage::doPurge no image\n" );
706 * Display an error with a wikitext description
708 function showError( $description ) {
710 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
711 $wgOut->setRobotPolicy( "noindex,nofollow" );
712 $wgOut->setArticleRelated( false );
713 $wgOut->enableClientCache( false );
714 $wgOut->addWikiText( $description );
720 * Builds the image revision log shown on image pages
724 class ImageHistoryList
{
726 protected $imagePage, $img, $skin, $title, $repo;
728 public function __construct( $imagePage ) {
730 $this->skin
= $wgUser->getSkin();
731 $this->current
= $imagePage->getFile();
732 $this->img
= $imagePage->getDisplayedFile();
733 $this->title
= $imagePage->getTitle();
734 $this->imagePage
= $imagePage;
737 public function getImagePage() {
738 return $this->imagePage
;
741 public function getSkin() {
745 public function getFile() {
749 public function beginImageHistoryList( $navLinks = '' ) {
750 global $wgOut, $wgUser;
751 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) . "\n"
752 . "<div id=\"mw-imagepage-section-filehistory\">\n"
753 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
755 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
757 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
758 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
759 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
760 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
761 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
762 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
766 public function endImageHistoryList( $navLinks = '' ) {
767 return "</table>\n$navLinks\n</div>\n";
770 public function imageHistoryLine( $iscur, $file ) {
771 global $wgUser, $wgLang, $wgContLang, $wgTitle;
773 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
774 $img = $iscur ?
$file->getName() : $file->getArchiveName();
775 $user = $file->getUser('id');
776 $usertext = $file->getUser('text');
777 $size = $file->getSize();
778 $description = $file->getDescription();
779 $dims = $file->getDimensionsString();
780 $sha1 = $file->getSha1();
782 $local = $this->current
->isLocal();
783 $row = $css = $selected = '';
786 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
788 # Link to remove from history
789 if( $wgUser->isAllowed( 'delete' ) ) {
790 $q = array( 'action' => 'delete' );
792 $q['oldimage'] = $img;
793 $row .= $this->skin
->link(
795 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
796 array(), $q, array( 'known' )
799 # Link to hide content
800 if( $wgUser->isAllowed( 'deleterevision' ) ) {
801 if( $wgUser->isAllowed('delete') ) {
804 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
805 // If file is top revision or locked from this user, don't link
806 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
807 $del = wfMsgHtml( 'rev-delundel' );
809 // If the file was hidden, link to sha-1
810 list( $ts, $name ) = explode( '!', $img, 2 );
811 $del = $this->skin
->link( $revdel, wfMsgHtml( 'rev-delundel' ),
813 array( 'target' => $wgTitle->getPrefixedText(), 'oldimage' => $ts ),
816 // Bolden oversighted content
817 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
818 $del = "<strong>$del</strong>";
820 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
825 // Reversion link/current indicator
828 $row .= wfMsgHtml( 'filehist-current' );
829 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
830 if( $file->isDeleted(File
::DELETED_FILE
) ) {
831 $row .= wfMsgHtml('filehist-revert');
834 $q[] = 'action=revert';
835 $q[] = 'oldimage=' . urlencode( $img );
836 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
837 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
838 wfMsgHtml( 'filehist-revert' ),
839 implode( '&', $q ) );
844 // Date/time and image link
845 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
846 $selected = "class='filehistory-selected'";
848 $row .= "<td $selected style='white-space: nowrap;'>";
849 if( !$file->userCan(File
::DELETED_FILE
) ) {
850 # Don't link to unviewable files
851 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
852 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
853 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
854 # Make a link to review the image
855 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
856 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
857 $row .= '<span class="history-deleted">'.$url.'</span>';
859 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
860 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
864 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
869 $thumbnail = $file->transform( $params );
871 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
874 $row .= '</td><td>' . ( $thumbnail ?
$thumbnail->toHtml( $options ) :
875 wfMsgHtml( 'filehist-nothumb' ) );
877 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
882 $row .= htmlspecialchars( $dims );
885 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
890 // Hide deleted usernames
891 if( $file->isDeleted(File
::DELETED_USER
) ) {
892 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
894 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
895 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
898 $row .= htmlspecialchars( $usertext );
902 // Don't show deleted descriptions
903 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
904 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
906 $row .= $this->skin
->commentBlock( $description, $this->title
);
910 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
911 $classAttr = $rowClass ?
" class='$rowClass'" : "";
913 return "<tr{$classAttr}>{$row}</tr>\n";
917 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
918 function __construct( $imagePage ) {
919 parent
::__construct();
920 $this->mImagePage
= $imagePage;
921 $this->mTitle
= clone( $imagePage->getTitle() );
922 $this->mTitle
->setFragment( '#filehistory' );
924 $this->mHist
= array();
925 $this->mRange
= array( 0, 0 ); // display range
928 function getTitle() {
929 return $this->mTitle
;
932 function getQueryInfo() {
936 function getIndexField() {
940 function formatRow( $row ) {
947 if( count($this->mHist
) ) {
948 $list = new ImageHistoryList( $this->mImagePage
);
949 # Generate prev/next links
950 $navLink = $this->getNavigationBar();
951 $s = $list->beginImageHistoryList($navLink);
952 // Skip rows there just for paging links
953 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
954 $file = $this->mHist
[$i];
955 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
957 $s .= $list->endImageHistoryList($navLink);
963 if( $this->mQueryDone
) return;
964 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
965 if( !$this->mImg
->exists() ) {
968 $queryLimit = $this->mLimit +
1; // limit plus extra row
969 if( $this->mIsBackwards
) {
970 // Fetch the file history
971 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
972 // The current rev may not meet the offset/limit
973 $numRows = count($this->mHist
);
974 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
975 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
978 // The current rev may not meet the offset
979 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
980 $this->mHist
[] = $this->mImg
;
982 // Old image versions (fetch extra row for nav links)
983 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
984 // Fetch the file history
985 $this->mHist
= array_merge( $this->mHist
,
986 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
988 $numRows = count($this->mHist
); // Total number of query results
990 # Index value of top item in the list
991 $firstIndex = $this->mIsBackwards ?
992 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
993 # Discard the extra result row if there is one
994 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
995 if( $this->mIsBackwards
) {
996 # Index value of item past the index
997 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
998 # Index value of bottom item in the list
999 $lastIndex = $this->mHist
[1]->getTimestamp();
1001 $this->mRange
= array( 1, $numRows-1 );
1003 # Index value of item past the index
1004 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1005 # Index value of bottom item in the list
1006 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1008 $this->mRange
= array( 0, $numRows-2 );
1011 # Setting indexes to an empty string means that they will be
1012 # omitted if they would otherwise appear in URLs. It just so
1013 # happens that this is the right thing to do in the standard
1014 # UI, in all the relevant cases.
1015 $this->mPastTheEndIndex
= '';
1016 # Index value of bottom item in the list
1017 $lastIndex = $this->mIsBackwards ?
1018 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1020 $this->mRange
= array( 0, $numRows-1 );
1025 $this->mPastTheEndIndex
= '';
1027 if( $this->mIsBackwards
) {
1028 $this->mIsFirst
= ( $numRows < $queryLimit );
1029 $this->mIsLast
= ( $this->mOffset
== '' );
1030 $this->mLastShown
= $firstIndex;
1031 $this->mFirstShown
= $lastIndex;
1033 $this->mIsFirst
= ( $this->mOffset
== '' );
1034 $this->mIsLast
= ( $numRows < $queryLimit );
1035 $this->mLastShown
= $lastIndex;
1036 $this->mFirstShown
= $firstIndex;
1038 $this->mQueryDone
= true;