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();
484 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
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 );
491 # Show message only if not voided by local sysops
496 $wgOut->addHTML( $s );
499 $this->mExtraDescription
= $descText;
503 public function getUploadUrl() {
505 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
506 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) . '&wpForReUpload=1' );
510 * Print out the various links at the bottom of the image page, e.g. reupload,
511 * external editing (and instructions link) etc.
513 protected function uploadLinksBox() {
514 global $wgUser, $wgOut;
517 if( !$this->img
->isLocal() )
520 $sk = $wgUser->getSkin();
522 $wgOut->addHTML( '<br /><ul>' );
524 # "Upload a new version of this file" link
525 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
526 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
527 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
530 # External editing link
531 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
532 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
534 $wgOut->addHTML( '</ul>' );
537 protected function closeShowImage() {} # For overloading
540 * If the page we've just displayed is in the "Image" namespace,
541 * we follow it with an upload history of the image and its usage.
543 protected function imageHistory() {
544 global $wgOut, $wgUseExternalEditor;
547 $pager = new ImageHistoryPseudoPager( $this );
548 $wgOut->addHTML( $pager->getBody() );
550 $this->img
->resetHistory(); // free db resources
552 # Exist check because we don't want to show this on pages where an image
553 # doesn't exist along with the noimage message, that would suck. -ævar
554 if( $wgUseExternalEditor && $this->img
->exists() ) {
555 $this->uploadLinksBox();
559 protected function imageLinks() {
560 global $wgUser, $wgOut, $wgLang;
564 $dbr = wfGetDB( DB_SLAVE
);
567 array( 'imagelinks', 'page' ),
568 array( 'page_namespace', 'page_title' ),
569 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
571 array( 'LIMIT' => $limit +
1)
573 $count = $dbr->numRows( $res );
575 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
576 $wgOut->addWikiMsg( 'nolinkstoimage' );
577 $wgOut->addHTML( "</div>\n" );
581 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
582 if( $count <= $limit - 1 ) {
583 $wgOut->addWikiMsg( 'linkstoimage', $count );
585 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
586 $wgOut->addWikiMsg( 'linkstoimage-more',
587 $wgLang->formatNum( $limit ),
588 $this->mTitle
->getPrefixedDBkey()
592 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
593 $sk = $wgUser->getSkin();
595 while ( $s = $res->fetchObject() ) {
597 if( $count <= $limit ) {
598 // We have not yet reached the extra one that tells us there is more to fetch
599 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
600 $link = $sk->makeKnownLinkObj( $name, "" );
601 $wgOut->addHTML( "<li>{$link}</li>\n" );
604 $wgOut->addHTML( "</ul></div>\n" );
607 // Add a links to [[Special:Whatlinkshere]]
608 if( $count > $limit )
609 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
612 protected function imageRedirects() {
613 global $wgUser, $wgOut, $wgLang;
615 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
616 if( count( $redirects ) == 0 ) return;
618 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
619 $wgOut->addWikiMsg( 'redirectstofile',
620 $wgLang->formatNum( count( $redirects ) )
622 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
624 $sk = $wgUser->getSkin();
625 foreach ( $redirects as $title ) {
626 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
627 $wgOut->addHTML( "<li>{$link}</li>\n" );
629 $wgOut->addHTML( "</ul></div>\n" );
633 protected function imageDupes() {
634 global $wgOut, $wgUser, $wgLang;
638 $dupes = $this->getDuplicates();
639 if( count( $dupes ) == 0 ) return;
641 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
642 $wgOut->addWikiMsg( 'duplicatesoffile',
643 $wgLang->formatNum( count( $dupes ) ), $this->mTitle
->getDBkey()
645 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
647 $sk = $wgUser->getSkin();
648 foreach ( $dupes as $file ) {
649 if( $file->isLocal() )
650 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
652 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
653 $file->getTitle()->getPrefixedText() );
655 $wgOut->addHTML( "<li>{$link}</li>\n" );
657 $wgOut->addHTML( "</ul></div>\n" );
661 * Delete the file, or an earlier version of it
663 public function delete() {
665 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
666 // Standard article deletion
670 $deleter = new FileDeleteForm( $this->img
);
675 * Revert the file to an earlier version
677 public function revert() {
679 $reverter = new FileRevertForm( $this->img
);
680 $reverter->execute();
684 * Override handling of action=purge
686 public function doPurge() {
688 if( $this->img
->exists() ) {
689 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
690 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
692 $this->img
->upgradeRow();
693 $this->img
->purgeCache();
695 wfDebug( "ImagePage::doPurge no image\n" );
701 * Display an error with a wikitext description
703 function showError( $description ) {
705 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
706 $wgOut->setRobotPolicy( "noindex,nofollow" );
707 $wgOut->setArticleRelated( false );
708 $wgOut->enableClientCache( false );
709 $wgOut->addWikiText( $description );
715 * Builds the image revision log shown on image pages
719 class ImageHistoryList
{
721 protected $imagePage, $img, $skin, $title, $repo;
723 public function __construct( $imagePage ) {
725 $this->skin
= $wgUser->getSkin();
726 $this->current
= $imagePage->getFile();
727 $this->img
= $imagePage->getDisplayedFile();
728 $this->title
= $imagePage->getTitle();
729 $this->imagePage
= $imagePage;
732 public function getImagePage() {
733 return $this->imagePage
;
736 public function getSkin() {
740 public function getFile() {
744 public function beginImageHistoryList( $navLinks = '' ) {
745 global $wgOut, $wgUser;
746 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
747 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
749 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
751 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
752 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
753 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
754 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
755 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
756 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
760 public function endImageHistoryList( $navLinks = '' ) {
761 return "</table>\n$navLinks\n";
764 public function imageHistoryLine( $iscur, $file ) {
765 global $wgUser, $wgLang, $wgContLang, $wgTitle;
767 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
768 $img = $iscur ?
$file->getName() : $file->getArchiveName();
769 $user = $file->getUser('id');
770 $usertext = $file->getUser('text');
771 $size = $file->getSize();
772 $description = $file->getDescription();
773 $dims = $file->getDimensionsString();
774 $sha1 = $file->getSha1();
776 $local = $this->current
->isLocal();
777 $row = $css = $selected = '';
780 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
782 # Link to remove from history
783 if( $wgUser->isAllowed( 'delete' ) ) {
785 $q[] = 'action=delete';
787 $q[] = 'oldimage=' . urlencode( $img );
788 $row .= $this->skin
->makeKnownLinkObj(
790 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
794 # Link to hide content
795 if( $wgUser->isAllowed( 'deleterevision' ) ) {
796 if( $wgUser->isAllowed('delete') ) {
799 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
800 // If file is top revision or locked from this user, don't link
801 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
802 $del = wfMsgHtml( 'rev-delundel' );
804 // If the file was hidden, link to sha-1
805 list($ts,$name) = explode('!',$img,2);
806 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
807 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
808 '&oldimage=' . urlencode( $ts ) );
809 // Bolden oversighted content
810 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
811 $del = "<strong>$del</strong>";
813 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
818 // Reversion link/current indicator
821 $row .= wfMsgHtml( 'filehist-current' );
822 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
823 if( $file->isDeleted(File
::DELETED_FILE
) ) {
824 $row .= wfMsgHtml('filehist-revert');
827 $q[] = 'action=revert';
828 $q[] = 'oldimage=' . urlencode( $img );
829 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
830 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
831 wfMsgHtml( 'filehist-revert' ),
832 implode( '&', $q ) );
837 // Date/time and image link
838 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
839 $selected = "class='filehistory-selected'";
841 $row .= "<td $selected style='white-space: nowrap;'>";
842 if( !$file->userCan(File
::DELETED_FILE
) ) {
843 # Don't link to unviewable files
844 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
845 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
846 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
847 # Make a link to review the image
848 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
849 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
850 $row .= '<span class="history-deleted">'.$url.'</span>';
852 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
853 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
857 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
862 $thumbnail = $file->transform( $params );
864 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
867 $row .= '</td><td>' . ( $thumbnail ?
$thumbnail->toHtml( $options ) :
868 wfMsgHtml( 'filehist-nothumb' ) );
870 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
875 $row .= htmlspecialchars( $dims );
878 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
883 // Hide deleted usernames
884 if( $file->isDeleted(File
::DELETED_USER
) ) {
885 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
887 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
888 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
891 $row .= htmlspecialchars( $usertext );
895 // Don't show deleted descriptions
896 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
897 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
899 $row .= $this->skin
->commentBlock( $description, $this->title
);
903 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
904 $classAttr = $rowClass ?
" class='$rowClass'" : "";
906 return "<tr{$classAttr}>{$row}</tr>\n";
910 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
911 function __construct( $imagePage ) {
912 parent
::__construct();
913 $this->mImagePage
= $imagePage;
914 $this->mTitle
= clone( $imagePage->getTitle() );
915 $this->mTitle
->setFragment( '#filehistory' );
917 $this->mHist
= array();
918 $this->mRange
= array( 0, 0 ); // display range
921 function getTitle() {
922 return $this->mTitle
;
925 function getQueryInfo() {
929 function getIndexField() {
933 function formatRow( $row ) {
940 if( count($this->mHist
) ) {
941 $list = new ImageHistoryList( $this->mImagePage
);
942 # Generate prev/next links
943 $navLink = $this->getNavigationBar();
944 $s = $list->beginImageHistoryList($navLink);
945 // Skip rows there just for paging links
946 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
947 $file = $this->mHist
[$i];
948 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
950 $s .= $list->endImageHistoryList($navLink);
956 if( $this->mQueryDone
) return;
957 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
958 if( !$this->mImg
->exists() ) {
961 $queryLimit = $this->mLimit +
1; // limit plus extra row
962 if( $this->mIsBackwards
) {
963 // Fetch the file history
964 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
965 // The current rev may not meet the offset/limit
966 $numRows = count($this->mHist
);
967 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
968 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
971 // The current rev may not meet the offset
972 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
973 $this->mHist
[] = $this->mImg
;
975 // Old image versions (fetch extra row for nav links)
976 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
977 // Fetch the file history
978 $this->mHist
= array_merge( $this->mHist
,
979 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
981 $numRows = count($this->mHist
); // Total number of query results
983 # Index value of top item in the list
984 $firstIndex = $this->mIsBackwards ?
985 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
986 # Discard the extra result row if there is one
987 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
988 if( $this->mIsBackwards
) {
989 # Index value of item past the index
990 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
991 # Index value of bottom item in the list
992 $lastIndex = $this->mHist
[1]->getTimestamp();
994 $this->mRange
= array( 1, $numRows-1 );
996 # Index value of item past the index
997 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
998 # Index value of bottom item in the list
999 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1001 $this->mRange
= array( 0, $numRows-2 );
1004 # Setting indexes to an empty string means that they will be
1005 # omitted if they would otherwise appear in URLs. It just so
1006 # happens that this is the right thing to do in the standard
1007 # UI, in all the relevant cases.
1008 $this->mPastTheEndIndex
= '';
1009 # Index value of bottom item in the list
1010 $lastIndex = $this->mIsBackwards ?
1011 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1013 $this->mRange
= array( 0, $numRows-1 );
1018 $this->mPastTheEndIndex
= '';
1020 if( $this->mIsBackwards
) {
1021 $this->mIsFirst
= ( $numRows < $queryLimit );
1022 $this->mIsLast
= ( $this->mOffset
== '' );
1023 $this->mLastShown
= $firstIndex;
1024 $this->mFirstShown
= $lastIndex;
1026 $this->mIsFirst
= ( $this->mOffset
== '' );
1027 $this->mIsLast
= ( $numRows < $queryLimit );
1028 $this->mLastShown
= $lastIndex;
1029 $this->mFirstShown
= $firstIndex;
1031 $this->mQueryDone
= true;