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 // TODO: We may want to find local images redirecting to a foreign
133 // file: "The following local files redirect to this file"
134 if( $this->img
->isLocal() ) {
135 $this->imageRedirects();
140 global $wgStylePath, $wgStyleVersion;
141 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
142 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
143 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
144 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
145 $wgOut->addScriptFile( 'metadata.js' );
147 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
151 public function getRedirectTarget() {
153 if( $this->img
->isLocal() ) {
154 return parent
::getRedirectTarget();
156 // Foreign image page
157 $from = $this->img
->getRedirected();
158 $to = $this->img
->getName();
162 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
164 public function followRedirect() {
166 if( $this->img
->isLocal() ) {
167 return parent
::followRedirect();
169 $from = $this->img
->getRedirected();
170 $to = $this->img
->getName();
174 return Title
::makeTitle( NS_FILE
, $to );
176 public function isRedirect( $text = false ) {
178 if( $this->img
->isLocal() )
179 return parent
::isRedirect( $text );
181 return (bool)$this->img
->getRedirected();
184 public function isLocal() {
186 return $this->img
->isLocal();
189 public function getFile() {
194 public function getDisplayedFile() {
196 return $this->displayImg
;
199 public function getDuplicates() {
201 if( !is_null($this->dupes
) ) {
204 if( !( $hash = $this->img
->getSha1() ) ) {
205 return $this->dupes
= array();
207 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
208 // Remove duplicates with self and non matching file sizes
209 $self = $this->img
->getRepoName().':'.$this->img
->getName();
210 $size = $this->img
->getSize();
211 foreach ( $dupes as $index => $file ) {
212 $key = $file->getRepoName().':'.$file->getName();
214 unset( $dupes[$index] );
215 if( $file->getSize() != $size )
216 unset( $dupes[$index] );
218 return $this->dupes
= $dupes;
226 * @param bool $metadata Whether or not to show the metadata link
229 protected function showTOC( $metadata ) {
231 $r = '<ul id="filetoc">
232 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
233 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
234 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
235 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
241 * Make a table with metadata to be shown in the output page.
243 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
245 * @param array $exif The array containing the EXIF data
248 protected function makeMetadataTable( $metadata ) {
249 $r = wfMsg( 'metadata-help' ) . "\n\n";
250 $r .= "{| id=mw_metadata class=mw_metadata\n";
251 foreach ( $metadata as $type => $stuff ) {
252 foreach ( $stuff as $v ) {
253 # FIXME, why is this using escapeId for a class?!
254 $class = Sanitizer
::escapeId( $v['id'] );
255 if( $type == 'collapsed' ) {
256 $class .= ' collapsable';
258 $r .= "|- class=\"$class\"\n";
259 $r .= "!| {$v['name']}\n";
260 $r .= "|| {$v['value']}\n";
268 * Overloading Article's getContent method.
270 * Omit noarticletext if sharedupload; text will be fetched from the
271 * shared upload server if possible.
273 public function getContent() {
275 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
278 return Article
::getContent();
281 protected function openShowImage() {
282 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
286 $full_url = $this->displayImg
->getURL();
287 $linkAttribs = false;
288 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
289 if( !isset( $wgImageLimits[$sizeSel] ) ) {
290 $sizeSel = User
::getDefaultOption( 'imagesize' );
292 // The user offset might still be incorrect, specially if
293 // $wgImageLimits got changed (see bug #8858).
294 if( !isset( $wgImageLimits[$sizeSel] ) ) {
295 // Default to the first offset in $wgImageLimits
299 $max = $wgImageLimits[$sizeSel];
301 $maxHeight = $max[1];
302 $sk = $wgUser->getSkin();
303 $dirmark = $wgContLang->getDirMark();
305 if( $this->displayImg
->exists() ) {
307 $page = $wgRequest->getIntOrNull( 'page' );
308 if( is_null( $page ) ) {
312 $params = array( 'page' => $page );
314 $width_orig = $this->displayImg
->getWidth();
315 $width = $width_orig;
316 $height_orig = $this->displayImg
->getHeight();
317 $height = $height_orig;
318 $mime = $this->displayImg
->getMimeType();
320 $linkAttribs = array( 'href' => $full_url );
321 $longDesc = $this->displayImg
->getLongDesc();
323 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
325 if( $this->displayImg
->allowInlineDisplay() ) {
328 # "Download high res version" link below the image
329 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
330 # We'll show a thumbnail of this image
331 if( $width > $maxWidth ||
$height > $maxHeight ) {
332 # Calculate the thumbnail size.
333 # First case, the limiting factor is the width, not the height.
334 if( $width / $height >= $maxWidth / $maxHeight ) {
335 $height = round( $height * $maxWidth / $width);
337 # Note that $height <= $maxHeight now.
339 $newwidth = floor( $width * $maxHeight / $height);
340 $height = round( $height * $newwidth / $width );
342 # Note that $height <= $maxHeight now, but might not be identical
343 # because of rounding.
345 $msgbig = wfMsgHtml( 'show-big-image' );
346 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
347 $wgLang->formatNum( $width ),
348 $wgLang->formatNum( $height )
351 # Image is small enough to show full size on image page
352 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
353 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
356 $params['width'] = $width;
357 $thumbnail = $this->displayImg
->transform( $params );
359 $anchorclose = "<br />";
360 if( $this->displayImg
->mustRender() ) {
365 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
368 if( $this->displayImg
->isMultipage() ) {
369 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
374 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
377 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
378 $thumbnail->toHtml( $options ) .
379 $anchorclose . '</div>' );
382 if( $this->displayImg
->isMultipage() ) {
383 $count = $this->displayImg
->pageCount();
386 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
387 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
388 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
389 array( 'page' => $page - 1 ) );
394 if( $page < $count ) {
395 $label = wfMsg( 'imgmultipagenext' );
396 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
397 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
398 array( 'page' => $page +
1 ) );
406 'name' => 'pageselector',
407 'action' => $wgScript,
408 'onchange' => 'document.pageselector.submit();',
412 for ( $i=1; $i <= $count; $i++
) {
413 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
415 $select = Xml
::tags( 'select',
416 array( 'id' => 'pageselector', 'name' => 'page' ),
417 implode( "\n", $options ) );
420 '</td><td><div class="multipageimagenavbox">' .
421 Xml
::openElement( 'form', $formParams ) .
422 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
423 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
424 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
425 Xml
::closeElement( 'form' ) .
426 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
430 #if direct link is allowed but it's not a renderable image, show an icon.
431 if( $this->displayImg
->isSafeFile() ) {
432 $icon= $this->displayImg
->iconThumb();
434 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
435 $icon->toHtml( array( 'desc-link' => true ) ) .
444 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
446 if( !$this->displayImg
->isSafeFile() ) {
447 $warning = wfMsgNoTrans( 'mediawarning' );
448 $wgOut->addWikiText( <<<EOT
449 <div class="fullMedia">
450 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
451 <span class="fileInfo"> $longDesc</span>
454 <div class="mediaWarning">$warning</div>
458 $wgOut->addWikiText( <<<EOT
459 <div class="fullMedia">
460 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
467 if( !$this->displayImg
->isLocal() ) {
468 $this->printSharedImageText();
471 # Image does not exist
473 $title = SpecialPage
::getTitleFor( 'Upload' );
474 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
475 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
476 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
481 * Show a notice that the file is from a shared repository
483 protected function printSharedImageText() {
484 global $wgOut, $wgUser;
488 $descUrl = $this->img
->getDescriptionUrl();
489 $descText = $this->img
->getDescriptionText();
490 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
492 $sk = $wgUser->getSkin();
493 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
494 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
495 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
497 # Show message only if not voided by local sysops
502 $wgOut->addHTML( $s );
505 $this->mExtraDescription
= $descText;
510 * Check for files with the same name on the foreign repos.
512 protected function checkSharedConflict() {
513 global $wgOut, $wgUser;
515 $repoGroup = RepoGroup
::singleton();
516 if( !$repoGroup->hasForeignRepos() ) {
521 if( !$this->img
->isLocal() ) {
525 $this->dupFile
= null;
526 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
528 if( !$this->dupFile
)
530 $dupfile = $this->dupFile
;
532 ($this->img
->getSha1() == $dupfile->getSha1()) &&
533 ($this->img
->getSize() == $dupfile->getSize())
536 $sk = $wgUser->getSkin();
537 $descUrl = $dupfile->getDescriptionUrl();
539 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
540 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
542 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
543 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
547 public function checkSharedConflictCallback( $repo ) {
549 $dupfile = $repo->newFile( $this->img
->getTitle() );
550 if( $dupfile && $dupfile->exists() ) {
551 $this->dupFile
= $dupfile;
552 return $dupfile->exists();
557 public function getUploadUrl() {
559 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
560 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) . '&wpReUpload=1' );
564 * Print out the various links at the bottom of the image page, e.g. reupload,
565 * external editing (and instructions link) etc.
567 protected function uploadLinksBox() {
568 global $wgUser, $wgOut;
571 if( !$this->img
->isLocal() )
574 $sk = $wgUser->getSkin();
576 $wgOut->addHTML( '<br /><ul>' );
578 # "Upload a new version of this file" link
579 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
580 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
581 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
584 # Link to Special:FileDuplicateSearch
585 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
586 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
588 # External editing link
589 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
590 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
592 $wgOut->addHTML( '</ul>' );
595 protected function closeShowImage() {} # For overloading
598 * If the page we've just displayed is in the "Image" namespace,
599 * we follow it with an upload history of the image and its usage.
601 protected function imageHistory() {
602 global $wgOut, $wgUseExternalEditor;
605 $pager = new ImageHistoryPseudoPager( $this );
606 $wgOut->addHTML( $pager->getBody() );
608 $this->img
->resetHistory(); // free db resources
610 # Exist check because we don't want to show this on pages where an image
611 # doesn't exist along with the noimage message, that would suck. -ævar
612 if( $wgUseExternalEditor && $this->img
->exists() ) {
613 $this->uploadLinksBox();
617 protected function imageLinks() {
618 global $wgUser, $wgOut, $wgLang;
622 $dbr = wfGetDB( DB_SLAVE
);
625 array( 'imagelinks', 'page' ),
626 array( 'page_namespace', 'page_title' ),
627 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
629 array( 'LIMIT' => $limit +
1)
631 $count = $dbr->numRows( $res );
633 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
634 $wgOut->addWikiMsg( 'nolinkstoimage' );
635 $wgOut->addHTML( "</div>\n" );
639 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
640 if( $count <= $limit - 1 ) {
641 $wgOut->addWikiMsg( 'linkstoimage', $count );
643 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
644 $wgOut->addWikiMsg( 'linkstoimage-more',
645 $wgLang->formatNum( $limit ),
646 $this->mTitle
->getPrefixedDBkey()
650 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
651 $sk = $wgUser->getSkin();
653 while ( $s = $res->fetchObject() ) {
655 if( $count <= $limit ) {
656 // We have not yet reached the extra one that tells us there is more to fetch
657 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
658 $link = $sk->makeKnownLinkObj( $name, "" );
659 $wgOut->addHTML( "<li>{$link}</li>\n" );
662 $wgOut->addHTML( "</ul></div>\n" );
665 // Add a links to [[Special:Whatlinkshere]]
666 if( $count > $limit )
667 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
670 protected function imageRedirects() {
671 global $wgUser, $wgOut, $wgLang;
673 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
674 if( count( $redirects ) == 0 ) return;
676 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
677 $wgOut->addWikiMsg( 'redirectstofile',
678 $wgLang->formatNum( count( $redirects ) )
680 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
682 $sk = $wgUser->getSkin();
683 foreach ( $redirects as $title ) {
684 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
685 $wgOut->addHTML( "<li>{$link}</li>\n" );
687 $wgOut->addHTML( "</ul></div>\n" );
691 protected function imageDupes() {
692 global $wgOut, $wgUser, $wgLang;
696 $dupes = $this->getDuplicates();
697 if( count( $dupes ) == 0 ) return;
699 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
700 $wgOut->addWikiMsg( 'duplicatesoffile',
701 $wgLang->formatNum( count( $dupes ) )
703 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
705 $sk = $wgUser->getSkin();
706 foreach ( $dupes as $file ) {
707 if( $file->isLocal() )
708 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
710 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
711 $file->getTitle()->getPrefixedText() );
713 $wgOut->addHTML( "<li>{$link}</li>\n" );
715 $wgOut->addHTML( "</ul></div>\n" );
719 * Delete the file, or an earlier version of it
721 public function delete() {
723 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
724 // Standard article deletion
728 $deleter = new FileDeleteForm( $this->img
);
733 * Revert the file to an earlier version
735 public function revert() {
737 $reverter = new FileRevertForm( $this->img
);
738 $reverter->execute();
742 * Override handling of action=purge
744 public function doPurge() {
746 if( $this->img
->exists() ) {
747 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
748 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
750 $this->img
->upgradeRow();
751 $this->img
->purgeCache();
753 wfDebug( "ImagePage::doPurge no image\n" );
759 * Display an error with a wikitext description
761 function showError( $description ) {
763 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
764 $wgOut->setRobotPolicy( "noindex,nofollow" );
765 $wgOut->setArticleRelated( false );
766 $wgOut->enableClientCache( false );
767 $wgOut->addWikiText( $description );
773 * Builds the image revision log shown on image pages
777 class ImageHistoryList
{
779 protected $imagePage, $img, $skin, $title, $repo;
781 public function __construct( $imagePage ) {
783 $this->skin
= $wgUser->getSkin();
784 $this->current
= $imagePage->getFile();
785 $this->img
= $imagePage->getDisplayedFile();
786 $this->title
= $imagePage->getTitle();
787 $this->imagePage
= $imagePage;
790 public function getImagePage() {
791 return $this->imagePage
;
794 public function getSkin() {
798 public function getFile() {
802 public function beginImageHistoryList( $navLinks = '' ) {
803 global $wgOut, $wgUser;
804 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
805 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
807 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
809 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
810 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
811 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
812 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
813 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
814 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
818 public function endImageHistoryList( $navLinks = '' ) {
819 return "</table>\n$navLinks\n";
822 public function imageHistoryLine( $iscur, $file ) {
823 global $wgUser, $wgLang, $wgContLang, $wgTitle;
825 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
826 $img = $iscur ?
$file->getName() : $file->getArchiveName();
827 $user = $file->getUser('id');
828 $usertext = $file->getUser('text');
829 $size = $file->getSize();
830 $description = $file->getDescription();
831 $dims = $file->getDimensionsString();
832 $sha1 = $file->getSha1();
834 $local = $this->current
->isLocal();
835 $row = $css = $selected = '';
838 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
840 # Link to remove from history
841 if( $wgUser->isAllowed( 'delete' ) ) {
843 $q[] = 'action=delete';
845 $q[] = 'oldimage=' . urlencode( $img );
846 $row .= $this->skin
->makeKnownLinkObj(
848 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
852 # Link to hide content
853 if( $wgUser->isAllowed( 'deleterevision' ) ) {
854 if( $wgUser->isAllowed('delete') ) {
857 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
858 // If file is top revision or locked from this user, don't link
859 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
860 $del = wfMsgHtml( 'rev-delundel' );
862 // If the file was hidden, link to sha-1
863 list($ts,$name) = explode('!',$img,2);
864 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
865 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
866 '&oldimage=' . urlencode( $ts ) );
867 // Bolden oversighted content
868 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
869 $del = "<strong>$del</strong>";
871 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
876 // Reversion link/current indicator
879 $row .= wfMsgHtml( 'filehist-current' );
880 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
881 if( $file->isDeleted(File
::DELETED_FILE
) ) {
882 $row .= wfMsgHtml('filehist-revert');
885 $q[] = 'action=revert';
886 $q[] = 'oldimage=' . urlencode( $img );
887 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
888 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
889 wfMsgHtml( 'filehist-revert' ),
890 implode( '&', $q ) );
895 // Date/time and image link
896 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
897 $selected = "class='filehistory-selected'";
899 $row .= "<td $selected style='white-space: nowrap;'>";
900 if( !$file->userCan(File
::DELETED_FILE
) ) {
901 # Don't link to unviewable files
902 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
903 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
904 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
905 # Make a link to review the image
906 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
907 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
908 $row .= '<span class="history-deleted">'.$url.'</span>';
910 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
911 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
915 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
920 $thumbnail = $file->transform( $params );
922 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
925 $row .= '</td><td>' . $thumbnail->toHtml( $options );
927 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
932 $row .= htmlspecialchars( $dims );
935 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
940 // Hide deleted usernames
941 if( $file->isDeleted(File
::DELETED_USER
) ) {
942 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
944 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
945 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
948 $row .= htmlspecialchars( $usertext );
952 // Don't show deleted descriptions
953 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
954 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
956 $row .= $this->skin
->commentBlock( $description, $this->title
);
960 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
961 $classAttr = $rowClass ?
" class='$rowClass'" : "";
963 return "<tr{$classAttr}>{$row}</tr>\n";
967 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
968 function __construct( $imagePage ) {
969 parent
::__construct();
970 $this->mImagePage
= $imagePage;
971 $this->mTitle
= clone( $imagePage->getTitle() );
972 $this->mTitle
->setFragment( '#filehistory' );
974 $this->mHist
= array();
975 $this->mRange
= array( 0, 0 ); // display range
978 function getTitle() {
979 return $this->mTitle
;
982 function getQueryInfo() {
986 function getIndexField() {
990 function formatRow( $row ) {
997 if( count($this->mHist
) ) {
998 $list = new ImageHistoryList( $this->mImagePage
);
999 # Generate prev/next links
1000 $navLink = $this->getNavigationBar();
1001 $s = $list->beginImageHistoryList($navLink);
1002 // Skip rows there just for paging links
1003 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1004 $file = $this->mHist
[$i];
1005 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1007 $s .= $list->endImageHistoryList($navLink);
1012 function doQuery() {
1013 if( $this->mQueryDone
) return;
1014 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1015 if( !$this->mImg
->exists() ) {
1018 $queryLimit = $this->mLimit +
1; // limit plus extra row
1019 if( $this->mIsBackwards
) {
1020 // Fetch the file history
1021 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1022 // The current rev may not meet the offset/limit
1023 $numRows = count($this->mHist
);
1024 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1025 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1028 // The current rev may not meet the offset
1029 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1030 $this->mHist
[] = $this->mImg
;
1032 // Old image versions (fetch extra row for nav links)
1033 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1034 // Fetch the file history
1035 $this->mHist
= array_merge( $this->mHist
,
1036 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1038 $numRows = count($this->mHist
); // Total number of query results
1040 # Index value of top item in the list
1041 $firstIndex = $this->mIsBackwards ?
1042 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1043 # Discard the extra result row if there is one
1044 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1045 if( $this->mIsBackwards
) {
1046 # Index value of item past the index
1047 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1048 # Index value of bottom item in the list
1049 $lastIndex = $this->mHist
[1]->getTimestamp();
1051 $this->mRange
= array( 1, $numRows-1 );
1053 # Index value of item past the index
1054 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1055 # Index value of bottom item in the list
1056 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1058 $this->mRange
= array( 0, $numRows-2 );
1061 # Setting indexes to an empty string means that they will be
1062 # omitted if they would otherwise appear in URLs. It just so
1063 # happens that this is the right thing to do in the standard
1064 # UI, in all the relevant cases.
1065 $this->mPastTheEndIndex
= '';
1066 # Index value of bottom item in the list
1067 $lastIndex = $this->mIsBackwards ?
1068 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1070 $this->mRange
= array( 0, $numRows-1 );
1075 $this->mPastTheEndIndex
= '';
1077 if( $this->mIsBackwards
) {
1078 $this->mIsFirst
= ( $numRows < $queryLimit );
1079 $this->mIsLast
= ( $this->mOffset
== '' );
1080 $this->mLastShown
= $firstIndex;
1081 $this->mFirstShown
= $lastIndex;
1083 $this->mIsFirst
= ( $this->mOffset
== '' );
1084 $this->mIsLast
= ( $numRows < $queryLimit );
1085 $this->mLastShown
= $lastIndex;
1086 $this->mFirstShown
= $firstIndex;
1088 $this->mQueryDone
= true;