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>' );
121 $this->checkSharedConflict();
124 $this->closeShowImage();
125 $this->imageHistory();
126 // TODO: Cleanup the following
128 $wgOut->addHTML( Xml
::element( 'h2',
129 array( 'id' => 'filelinks' ),
130 wfMsg( 'imagelinks' ) ) . "\n" );
132 $this->imageRedirects();
136 global $wgStylePath, $wgStyleVersion;
137 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
138 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
139 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
140 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
141 $wgOut->addScriptFile( 'metadata.js' );
143 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
147 public function getRedirectTarget() {
149 if( $this->img
->isLocal() ) {
150 return parent
::getRedirectTarget();
152 // Foreign image page
153 $from = $this->img
->getRedirected();
154 $to = $this->img
->getName();
158 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
160 public function followRedirect() {
162 if( $this->img
->isLocal() ) {
163 return parent
::followRedirect();
165 $from = $this->img
->getRedirected();
166 $to = $this->img
->getName();
170 return Title
::makeTitle( NS_FILE
, $to );
172 public function isRedirect( $text = false ) {
174 if( $this->img
->isLocal() )
175 return parent
::isRedirect( $text );
177 return (bool)$this->img
->getRedirected();
180 public function isLocal() {
182 return $this->img
->isLocal();
185 public function getFile() {
190 public function getDisplayedFile() {
192 return $this->displayImg
;
195 public function getDuplicates() {
197 if( !is_null($this->dupes
) ) {
200 if( !( $hash = $this->img
->getSha1() ) ) {
201 return $this->dupes
= array();
203 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
204 // Remove duplicates with self and non matching file sizes
205 $self = $this->img
->getRepoName().':'.$this->img
->getName();
206 $size = $this->img
->getSize();
207 foreach ( $dupes as $index => $file ) {
208 $key = $file->getRepoName().':'.$file->getName();
210 unset( $dupes[$index] );
211 if( $file->getSize() != $size )
212 unset( $dupes[$index] );
214 return $this->dupes
= $dupes;
222 * @param bool $metadata Whether or not to show the metadata link
225 protected function showTOC( $metadata ) {
227 $r = '<ul id="filetoc">
228 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
229 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
230 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
231 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
237 * Make a table with metadata to be shown in the output page.
239 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
241 * @param array $exif The array containing the EXIF data
244 protected function makeMetadataTable( $metadata ) {
245 $r = wfMsg( 'metadata-help' ) . "\n\n";
246 $r .= "{| 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 .= "|- class=\"$class\"\n";
255 $r .= "!| {$v['name']}\n";
256 $r .= "|| {$v['value']}\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>' );
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>
450 <div class="mediaWarning">$warning</div>
454 $wgOut->addWikiText( <<<EOT
455 <div class="fullMedia">
456 [[Media:$filename|$filename]]$dirmark <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->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
477 * Show a notice that the file is from a shared repository
479 protected function printSharedImageText() {
480 global $wgOut, $wgUser;
484 $descUrl = $this->img
->getDescriptionUrl();
485 $descText = $this->img
->getDescriptionText();
486 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
488 $sk = $wgUser->getSkin();
489 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
490 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
491 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
493 # Show message only if not voided by local sysops
498 $wgOut->addHTML( $s );
501 $this->mExtraDescription
= $descText;
506 * Check for files with the same name on the foreign repos.
508 protected function checkSharedConflict() {
509 global $wgOut, $wgUser;
511 $repoGroup = RepoGroup
::singleton();
512 if( !$repoGroup->hasForeignRepos() ) {
517 if( !$this->img
->isLocal() ) {
521 $this->dupFile
= null;
522 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
524 if( !$this->dupFile
)
526 $dupfile = $this->dupFile
;
528 ($this->img
->getSha1() == $dupfile->getSha1()) &&
529 ($this->img
->getSize() == $dupfile->getSize())
532 $sk = $wgUser->getSkin();
533 $descUrl = $dupfile->getDescriptionUrl();
535 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
536 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
538 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
539 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
543 public function checkSharedConflictCallback( $repo ) {
545 $dupfile = $repo->newFile( $this->img
->getTitle() );
546 if( $dupfile && $dupfile->exists() ) {
547 $this->dupFile
= $dupfile;
548 return $dupfile->exists();
553 public function getUploadUrl() {
555 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
556 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) . '&wpForReUpload=1' );
560 * Print out the various links at the bottom of the image page, e.g. reupload,
561 * external editing (and instructions link) etc.
563 protected function uploadLinksBox() {
564 global $wgUser, $wgOut;
567 if( !$this->img
->isLocal() )
570 $sk = $wgUser->getSkin();
572 $wgOut->addHTML( '<br /><ul>' );
574 # "Upload a new version of this file" link
575 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
576 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
577 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
580 # Link to Special:FileDuplicateSearch
581 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
582 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
584 # External editing link
585 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
586 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
588 $wgOut->addHTML( '</ul>' );
591 protected function closeShowImage() {} # For overloading
594 * If the page we've just displayed is in the "Image" namespace,
595 * we follow it with an upload history of the image and its usage.
597 protected function imageHistory() {
598 global $wgOut, $wgUseExternalEditor;
601 $pager = new ImageHistoryPseudoPager( $this );
602 $wgOut->addHTML( $pager->getBody() );
604 $this->img
->resetHistory(); // free db resources
606 # Exist check because we don't want to show this on pages where an image
607 # doesn't exist along with the noimage message, that would suck. -ævar
608 if( $wgUseExternalEditor && $this->img
->exists() ) {
609 $this->uploadLinksBox();
613 protected function imageLinks() {
614 global $wgUser, $wgOut, $wgLang;
618 $dbr = wfGetDB( DB_SLAVE
);
621 array( 'imagelinks', 'page' ),
622 array( 'page_namespace', 'page_title' ),
623 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
625 array( 'LIMIT' => $limit +
1)
627 $count = $dbr->numRows( $res );
629 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
630 $wgOut->addWikiMsg( 'nolinkstoimage' );
631 $wgOut->addHTML( "</div>\n" );
635 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
636 if( $count <= $limit - 1 ) {
637 $wgOut->addWikiMsg( 'linkstoimage', $count );
639 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
640 $wgOut->addWikiMsg( 'linkstoimage-more',
641 $wgLang->formatNum( $limit ),
642 $this->mTitle
->getPrefixedDBkey()
646 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
647 $sk = $wgUser->getSkin();
649 while ( $s = $res->fetchObject() ) {
651 if( $count <= $limit ) {
652 // We have not yet reached the extra one that tells us there is more to fetch
653 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
654 $link = $sk->makeKnownLinkObj( $name, "" );
655 $wgOut->addHTML( "<li>{$link}</li>\n" );
658 $wgOut->addHTML( "</ul></div>\n" );
661 // Add a links to [[Special:Whatlinkshere]]
662 if( $count > $limit )
663 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
666 protected function imageRedirects() {
667 global $wgUser, $wgOut, $wgLang;
669 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
670 if( count( $redirects ) == 0 ) return;
672 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
673 $wgOut->addWikiMsg( 'redirectstofile',
674 $wgLang->formatNum( count( $redirects ) )
676 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
678 $sk = $wgUser->getSkin();
679 foreach ( $redirects as $title ) {
680 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
681 $wgOut->addHTML( "<li>{$link}</li>\n" );
683 $wgOut->addHTML( "</ul></div>\n" );
687 protected function imageDupes() {
688 global $wgOut, $wgUser, $wgLang;
692 $dupes = $this->getDuplicates();
693 if( count( $dupes ) == 0 ) return;
695 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
696 $wgOut->addWikiMsg( 'duplicatesoffile',
697 $wgLang->formatNum( count( $dupes ) )
699 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
701 $sk = $wgUser->getSkin();
702 foreach ( $dupes as $file ) {
703 if( $file->isLocal() )
704 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
706 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
707 $file->getTitle()->getPrefixedText() );
709 $wgOut->addHTML( "<li>{$link}</li>\n" );
711 $wgOut->addHTML( "</ul></div>\n" );
715 * Delete the file, or an earlier version of it
717 public function delete() {
719 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
720 // Standard article deletion
724 $deleter = new FileDeleteForm( $this->img
);
729 * Revert the file to an earlier version
731 public function revert() {
733 $reverter = new FileRevertForm( $this->img
);
734 $reverter->execute();
738 * Override handling of action=purge
740 public function doPurge() {
742 if( $this->img
->exists() ) {
743 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
744 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
746 $this->img
->upgradeRow();
747 $this->img
->purgeCache();
749 wfDebug( "ImagePage::doPurge no image\n" );
755 * Display an error with a wikitext description
757 function showError( $description ) {
759 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
760 $wgOut->setRobotPolicy( "noindex,nofollow" );
761 $wgOut->setArticleRelated( false );
762 $wgOut->enableClientCache( false );
763 $wgOut->addWikiText( $description );
769 * Builds the image revision log shown on image pages
773 class ImageHistoryList
{
775 protected $imagePage, $img, $skin, $title, $repo;
777 public function __construct( $imagePage ) {
779 $this->skin
= $wgUser->getSkin();
780 $this->current
= $imagePage->getFile();
781 $this->img
= $imagePage->getDisplayedFile();
782 $this->title
= $imagePage->getTitle();
783 $this->imagePage
= $imagePage;
786 public function getImagePage() {
787 return $this->imagePage
;
790 public function getSkin() {
794 public function getFile() {
798 public function beginImageHistoryList( $navLinks = '' ) {
799 global $wgOut, $wgUser;
800 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
801 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
803 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
805 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
806 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
807 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
808 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
809 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
810 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
814 public function endImageHistoryList( $navLinks = '' ) {
815 return "</table>\n$navLinks\n";
818 public function imageHistoryLine( $iscur, $file ) {
819 global $wgUser, $wgLang, $wgContLang, $wgTitle;
821 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
822 $img = $iscur ?
$file->getName() : $file->getArchiveName();
823 $user = $file->getUser('id');
824 $usertext = $file->getUser('text');
825 $size = $file->getSize();
826 $description = $file->getDescription();
827 $dims = $file->getDimensionsString();
828 $sha1 = $file->getSha1();
830 $local = $this->current
->isLocal();
831 $row = $css = $selected = '';
834 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
836 # Link to remove from history
837 if( $wgUser->isAllowed( 'delete' ) ) {
839 $q[] = 'action=delete';
841 $q[] = 'oldimage=' . urlencode( $img );
842 $row .= $this->skin
->makeKnownLinkObj(
844 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
848 # Link to hide content
849 if( $wgUser->isAllowed( 'deleterevision' ) ) {
850 if( $wgUser->isAllowed('delete') ) {
853 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
854 // If file is top revision or locked from this user, don't link
855 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
856 $del = wfMsgHtml( 'rev-delundel' );
858 // If the file was hidden, link to sha-1
859 list($ts,$name) = explode('!',$img,2);
860 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
861 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
862 '&oldimage=' . urlencode( $ts ) );
863 // Bolden oversighted content
864 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
865 $del = "<strong>$del</strong>";
867 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
872 // Reversion link/current indicator
875 $row .= wfMsgHtml( 'filehist-current' );
876 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
877 if( $file->isDeleted(File
::DELETED_FILE
) ) {
878 $row .= wfMsgHtml('filehist-revert');
881 $q[] = 'action=revert';
882 $q[] = 'oldimage=' . urlencode( $img );
883 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
884 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
885 wfMsgHtml( 'filehist-revert' ),
886 implode( '&', $q ) );
891 // Date/time and image link
892 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
893 $selected = "class='filehistory-selected'";
895 $row .= "<td $selected style='white-space: nowrap;'>";
896 if( !$file->userCan(File
::DELETED_FILE
) ) {
897 # Don't link to unviewable files
898 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
899 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
900 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
901 # Make a link to review the image
902 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
903 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
904 $row .= '<span class="history-deleted">'.$url.'</span>';
906 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
907 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
911 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
916 $thumbnail = $file->transform( $params );
918 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
921 $row .= '</td><td>' . ( $thumbnail ?
$thumbnail->toHtml( $options ) :
922 wfMsgHtml( 'filehist-nothumb' ) );
924 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
929 $row .= htmlspecialchars( $dims );
932 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
937 // Hide deleted usernames
938 if( $file->isDeleted(File
::DELETED_USER
) ) {
939 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
941 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
942 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
945 $row .= htmlspecialchars( $usertext );
949 // Don't show deleted descriptions
950 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
951 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
953 $row .= $this->skin
->commentBlock( $description, $this->title
);
957 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
958 $classAttr = $rowClass ?
" class='$rowClass'" : "";
960 return "<tr{$classAttr}>{$row}</tr>\n";
964 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
965 function __construct( $imagePage ) {
966 parent
::__construct();
967 $this->mImagePage
= $imagePage;
968 $this->mTitle
= clone( $imagePage->getTitle() );
969 $this->mTitle
->setFragment( '#filehistory' );
971 $this->mHist
= array();
972 $this->mRange
= array( 0, 0 ); // display range
975 function getTitle() {
976 return $this->mTitle
;
979 function getQueryInfo() {
983 function getIndexField() {
987 function formatRow( $row ) {
994 if( count($this->mHist
) ) {
995 $list = new ImageHistoryList( $this->mImagePage
);
996 # Generate prev/next links
997 $navLink = $this->getNavigationBar();
998 $s = $list->beginImageHistoryList($navLink);
999 // Skip rows there just for paging links
1000 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1001 $file = $this->mHist
[$i];
1002 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1004 $s .= $list->endImageHistoryList($navLink);
1009 function doQuery() {
1010 if( $this->mQueryDone
) return;
1011 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1012 if( !$this->mImg
->exists() ) {
1015 $queryLimit = $this->mLimit +
1; // limit plus extra row
1016 if( $this->mIsBackwards
) {
1017 // Fetch the file history
1018 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1019 // The current rev may not meet the offset/limit
1020 $numRows = count($this->mHist
);
1021 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1022 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1025 // The current rev may not meet the offset
1026 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1027 $this->mHist
[] = $this->mImg
;
1029 // Old image versions (fetch extra row for nav links)
1030 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1031 // Fetch the file history
1032 $this->mHist
= array_merge( $this->mHist
,
1033 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1035 $numRows = count($this->mHist
); // Total number of query results
1037 # Index value of top item in the list
1038 $firstIndex = $this->mIsBackwards ?
1039 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1040 # Discard the extra result row if there is one
1041 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1042 if( $this->mIsBackwards
) {
1043 # Index value of item past the index
1044 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1045 # Index value of bottom item in the list
1046 $lastIndex = $this->mHist
[1]->getTimestamp();
1048 $this->mRange
= array( 1, $numRows-1 );
1050 # Index value of item past the index
1051 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1052 # Index value of bottom item in the list
1053 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1055 $this->mRange
= array( 0, $numRows-2 );
1058 # Setting indexes to an empty string means that they will be
1059 # omitted if they would otherwise appear in URLs. It just so
1060 # happens that this is the right thing to do in the standard
1061 # UI, in all the relevant cases.
1062 $this->mPastTheEndIndex
= '';
1063 # Index value of bottom item in the list
1064 $lastIndex = $this->mIsBackwards ?
1065 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1067 $this->mRange
= array( 0, $numRows-1 );
1072 $this->mPastTheEndIndex
= '';
1074 if( $this->mIsBackwards
) {
1075 $this->mIsFirst
= ( $numRows < $queryLimit );
1076 $this->mIsLast
= ( $this->mOffset
== '' );
1077 $this->mLastShown
= $firstIndex;
1078 $this->mFirstShown
= $lastIndex;
1080 $this->mIsFirst
= ( $this->mOffset
== '' );
1081 $this->mIsLast
= ( $numRows < $queryLimit );
1082 $this->mLastShown
= $lastIndex;
1083 $this->mFirstShown
= $firstIndex;
1085 $this->mQueryDone
= true;