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( $this->displayImg
->exists() )
97 $wgOut->addHTML( $this->showTOC($showmeta) );
99 $this->openShowImage();
101 # No need to display noarticletext, we use our own message, output in openShowImage()
102 if( $this->getID() ) {
105 # Just need to set the right headers
106 $wgOut->setArticleFlag( true );
107 $wgOut->setRobotPolicy( 'noindex,nofollow' );
108 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
109 $this->viewUpdates();
111 # And also show "redirected from" message
112 $sk = $wgUser->getSkin();
113 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom
, '', 'redirect=no' );
114 $wgOut->setSubtitle( wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir ) );
117 # Show shared description, if needed
118 if( $this->mExtraDescription
) {
119 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
120 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
121 $wgOut->addWikiText( $fol );
123 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
125 $this->checkSharedConflict();
128 $this->closeShowImage();
129 $this->imageHistory();
130 // TODO: Cleanup the following
132 $wgOut->addHTML( Xml
::element( 'h2',
133 array( 'id' => 'filelinks' ),
134 wfMsg( 'imagelinks' ) ) . "\n" );
136 // TODO: We may want to find local images redirecting to a foreign
137 // file: "The following local files redirect to this file"
138 if( $this->img
->isLocal() ) {
139 $this->imageRedirects();
144 global $wgStylePath, $wgStyleVersion;
145 $expand = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-expand' ) ) );
146 $collapse = htmlspecialchars( Xml
::escapeJsString( wfMsg( 'metadata-collapse' ) ) );
147 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
148 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
149 $wgOut->addScriptFile( 'metadata.js' );
151 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
155 public function getRedirectTarget() {
157 if( $this->img
->isLocal() ) {
158 return parent
::getRedirectTarget();
160 // Foreign image page
161 $from = $this->img
->getRedirected();
162 $to = $this->img
->getName();
166 return $this->mRedirectTarget
= Title
::makeTitle( NS_FILE
, $to );
168 public function followRedirect() {
170 if( $this->img
->isLocal() ) {
171 return parent
::followRedirect();
173 $from = $this->img
->getRedirected();
174 $to = $this->img
->getName();
178 return Title
::makeTitle( NS_FILE
, $to );
180 public function isRedirect( $text = false ) {
182 if( $this->img
->isLocal() )
183 return parent
::isRedirect( $text );
185 return (bool)$this->img
->getRedirected();
188 public function isLocal() {
190 return $this->img
->isLocal();
193 public function getFile() {
198 public function getDisplayedFile() {
200 return $this->displayImg
;
203 public function getDuplicates() {
205 if( !is_null($this->dupes
) ) {
208 if( !( $hash = $this->img
->getSha1() ) ) {
209 return $this->dupes
= array();
211 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
212 // Remove duplicates with self and non matching file sizes
213 $self = $this->img
->getRepoName().':'.$this->img
->getName();
214 $size = $this->img
->getSize();
215 foreach ( $dupes as $index => $file ) {
216 $key = $file->getRepoName().':'.$file->getName();
218 unset( $dupes[$index] );
219 if( $file->getSize() != $size )
220 unset( $dupes[$index] );
222 return $this->dupes
= $dupes;
230 * @param bool $metadata Whether or not to show the metadata link
233 protected function showTOC( $metadata ) {
235 $r = '<ul id="filetoc">
236 <li><a href="#file">' . $wgLang->getNsText( NS_FILE
) . '</a></li>
237 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
238 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
239 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
245 * Make a table with metadata to be shown in the output page.
247 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
249 * @param array $exif The array containing the EXIF data
252 protected function makeMetadataTable( $metadata ) {
253 $r = wfMsg( 'metadata-help' ) . "\n\n";
254 $r .= "{| id=mw_metadata class=mw_metadata\n";
255 foreach ( $metadata as $type => $stuff ) {
256 foreach ( $stuff as $v ) {
257 # FIXME, why is this using escapeId for a class?!
258 $class = Sanitizer
::escapeId( $v['id'] );
259 if( $type == 'collapsed' ) {
260 $class .= ' collapsable';
262 $r .= "|- class=\"$class\"\n";
263 $r .= "!| {$v['name']}\n";
264 $r .= "|| {$v['value']}\n";
272 * Overloading Article's getContent method.
274 * Omit noarticletext if sharedupload; text will be fetched from the
275 * shared upload server if possible.
277 public function getContent() {
279 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
282 return Article
::getContent();
285 protected function openShowImage() {
286 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
290 $full_url = $this->displayImg
->getURL();
291 $linkAttribs = false;
292 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
293 if( !isset( $wgImageLimits[$sizeSel] ) ) {
294 $sizeSel = User
::getDefaultOption( 'imagesize' );
296 // The user offset might still be incorrect, specially if
297 // $wgImageLimits got changed (see bug #8858).
298 if( !isset( $wgImageLimits[$sizeSel] ) ) {
299 // Default to the first offset in $wgImageLimits
303 $max = $wgImageLimits[$sizeSel];
305 $maxHeight = $max[1];
306 $sk = $wgUser->getSkin();
307 $dirmark = $wgContLang->getDirMark();
309 if( $this->displayImg
->exists() ) {
311 $page = $wgRequest->getIntOrNull( 'page' );
312 if( is_null( $page ) ) {
316 $params = array( 'page' => $page );
318 $width_orig = $this->displayImg
->getWidth();
319 $width = $width_orig;
320 $height_orig = $this->displayImg
->getHeight();
321 $height = $height_orig;
322 $mime = $this->displayImg
->getMimeType();
324 $linkAttribs = array( 'href' => $full_url );
325 $longDesc = $this->displayImg
->getLongDesc();
327 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
329 if( $this->displayImg
->allowInlineDisplay() ) {
332 # "Download high res version" link below the image
333 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
334 # We'll show a thumbnail of this image
335 if( $width > $maxWidth ||
$height > $maxHeight ) {
336 # Calculate the thumbnail size.
337 # First case, the limiting factor is the width, not the height.
338 if( $width / $height >= $maxWidth / $maxHeight ) {
339 $height = round( $height * $maxWidth / $width);
341 # Note that $height <= $maxHeight now.
343 $newwidth = floor( $width * $maxHeight / $height);
344 $height = round( $height * $newwidth / $width );
346 # Note that $height <= $maxHeight now, but might not be identical
347 # because of rounding.
349 $msgbig = wfMsgHtml( 'show-big-image' );
350 $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline',
351 $wgLang->formatNum( $width ),
352 $wgLang->formatNum( $height )
355 # Image is small enough to show full size on image page
356 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
357 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
360 $params['width'] = $width;
361 $thumbnail = $this->displayImg
->transform( $params );
363 $anchorclose = "<br />";
364 if( $this->displayImg
->mustRender() ) {
369 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
372 if( $this->displayImg
->isMultipage() ) {
373 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
378 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
381 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
382 $thumbnail->toHtml( $options ) .
383 $anchorclose . '</div>' );
386 if( $this->displayImg
->isMultipage() ) {
387 $count = $this->displayImg
->pageCount();
390 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
391 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
392 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
393 array( 'page' => $page - 1 ) );
398 if( $page < $count ) {
399 $label = wfMsg( 'imgmultipagenext' );
400 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
401 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
402 array( 'page' => $page +
1 ) );
410 'name' => 'pageselector',
411 'action' => $wgScript,
412 'onchange' => 'document.pageselector.submit();',
416 for ( $i=1; $i <= $count; $i++
) {
417 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
419 $select = Xml
::tags( 'select',
420 array( 'id' => 'pageselector', 'name' => 'page' ),
421 implode( "\n", $options ) );
424 '</td><td><div class="multipageimagenavbox">' .
425 Xml
::openElement( 'form', $formParams ) .
426 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
427 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
428 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
429 Xml
::closeElement( 'form' ) .
430 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
434 #if direct link is allowed but it's not a renderable image, show an icon.
435 if( $this->displayImg
->isSafeFile() ) {
436 $icon= $this->displayImg
->iconThumb();
438 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
439 $icon->toHtml( array( 'desc-link' => true ) ) .
448 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
450 if( !$this->displayImg
->isSafeFile() ) {
451 $warning = wfMsgNoTrans( 'mediawarning' );
452 $wgOut->addWikiText( <<<EOT
453 <div class="fullMedia">
454 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
455 <span class="fileInfo"> $longDesc</span>
458 <div class="mediaWarning">$warning</div>
462 $wgOut->addWikiText( <<<EOT
463 <div class="fullMedia">
464 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
471 if( !$this->displayImg
->isLocal() ) {
472 $this->printSharedImageText();
475 # Image does not exist
477 $title = SpecialPage
::getTitleFor( 'Upload' );
478 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
479 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
480 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
485 * Show a notice that the file is from a shared repository
487 protected function printSharedImageText() {
488 global $wgOut, $wgUser;
492 $descUrl = $this->img
->getDescriptionUrl();
493 $descText = $this->img
->getDescriptionText();
494 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
496 $sk = $wgUser->getSkin();
497 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
498 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
499 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
501 # Show message only if not voided by local sysops
506 $wgOut->addHTML( $s );
509 $this->mExtraDescription
= $descText;
514 * Check for files with the same name on the foreign repos.
516 protected function checkSharedConflict() {
517 global $wgOut, $wgUser;
519 $repoGroup = RepoGroup
::singleton();
520 if( !$repoGroup->hasForeignRepos() ) {
525 if( !$this->img
->isLocal() ) {
529 $this->dupFile
= null;
530 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
532 if( !$this->dupFile
)
534 $dupfile = $this->dupFile
;
536 ($this->img
->getSha1() == $dupfile->getSha1()) &&
537 ($this->img
->getSize() == $dupfile->getSize())
540 $sk = $wgUser->getSkin();
541 $descUrl = $dupfile->getDescriptionUrl();
543 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
544 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
546 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
547 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
551 public function checkSharedConflictCallback( $repo ) {
553 $dupfile = $repo->newFile( $this->img
->getTitle() );
554 if( $dupfile && $dupfile->exists() ) {
555 $this->dupFile
= $dupfile;
556 return $dupfile->exists();
561 public function getUploadUrl() {
563 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
564 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
568 * Print out the various links at the bottom of the image page, e.g. reupload,
569 * external editing (and instructions link) etc.
571 protected function uploadLinksBox() {
572 global $wgUser, $wgOut;
575 if( !$this->img
->isLocal() )
578 $sk = $wgUser->getSkin();
580 $wgOut->addHTML( '<br /><ul>' );
582 # "Upload a new version of this file" link
583 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
584 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
585 $wgOut->addHTML( "<li><div class='plainlinks'>{$ulink}</div></li>" );
588 # Link to Special:FileDuplicateSearch
589 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
590 $wgOut->addHTML( "<li>{$dupeLink}</li>" );
592 # External editing link
593 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
594 $wgOut->addHTML( '<li>' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . '</small></li>' );
596 $wgOut->addHTML( '</ul>' );
599 protected function closeShowImage() {} # For overloading
602 * If the page we've just displayed is in the "Image" namespace,
603 * we follow it with an upload history of the image and its usage.
605 protected function imageHistory() {
606 global $wgOut, $wgUseExternalEditor;
609 $pager = new ImageHistoryPseudoPager( $this );
610 $wgOut->addHTML( $pager->getBody() );
612 $this->img
->resetHistory(); // free db resources
614 # Exist check because we don't want to show this on pages where an image
615 # doesn't exist along with the noimage message, that would suck. -ævar
616 if( $wgUseExternalEditor && $this->img
->exists() ) {
617 $this->uploadLinksBox();
621 protected function imageLinks() {
622 global $wgUser, $wgOut, $wgLang;
626 $dbr = wfGetDB( DB_SLAVE
);
629 array( 'imagelinks', 'page' ),
630 array( 'page_namespace', 'page_title' ),
631 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
633 array( 'LIMIT' => $limit +
1)
635 $count = $dbr->numRows( $res );
637 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
638 $wgOut->addWikiMsg( 'nolinkstoimage' );
639 $wgOut->addHTML( "</div>\n" );
643 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
644 if( $count <= $limit - 1 ) {
645 $wgOut->addWikiMsg( 'linkstoimage', $count );
647 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
648 $wgOut->addWikiMsg( 'linkstoimage-more',
649 $wgLang->formatNum( $limit ),
650 $this->mTitle
->getPrefixedDBkey()
654 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
655 $sk = $wgUser->getSkin();
657 while ( $s = $res->fetchObject() ) {
659 if( $count <= $limit ) {
660 // We have not yet reached the extra one that tells us there is more to fetch
661 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
662 $link = $sk->makeKnownLinkObj( $name, "" );
663 $wgOut->addHTML( "<li>{$link}</li>\n" );
666 $wgOut->addHTML( "</ul></div>\n" );
669 // Add a links to [[Special:Whatlinkshere]]
670 if( $count > $limit )
671 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
674 protected function imageRedirects() {
675 global $wgUser, $wgOut, $wgLang;
677 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE
);
678 if( count( $redirects ) == 0 ) return;
680 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
681 $wgOut->addWikiMsg( 'redirectstofile',
682 $wgLang->formatNum( count( $redirects ) )
684 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
686 $sk = $wgUser->getSkin();
687 foreach ( $redirects as $title ) {
688 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
689 $wgOut->addHTML( "<li>{$link}</li>\n" );
691 $wgOut->addHTML( "</ul></div>\n" );
695 protected function imageDupes() {
696 global $wgOut, $wgUser, $wgLang;
700 $dupes = $this->getDuplicates();
701 if( count( $dupes ) == 0 ) return;
703 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
704 $wgOut->addWikiMsg( 'duplicatesoffile',
705 $wgLang->formatNum( count( $dupes ) )
707 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
709 $sk = $wgUser->getSkin();
710 foreach ( $dupes as $file ) {
711 if( $file->isLocal() )
712 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
714 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
715 $file->getTitle()->getPrefixedText() );
717 $wgOut->addHTML( "<li>{$link}</li>\n" );
719 $wgOut->addHTML( "</ul></div>\n" );
723 * Delete the file, or an earlier version of it
725 public function delete() {
727 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
728 // Standard article deletion
732 $deleter = new FileDeleteForm( $this->img
);
737 * Revert the file to an earlier version
739 public function revert() {
741 $reverter = new FileRevertForm( $this->img
);
742 $reverter->execute();
746 * Override handling of action=purge
748 public function doPurge() {
750 if( $this->img
->exists() ) {
751 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
752 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
754 $this->img
->upgradeRow();
755 $this->img
->purgeCache();
757 wfDebug( "ImagePage::doPurge no image\n" );
763 * Display an error with a wikitext description
765 function showError( $description ) {
767 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
768 $wgOut->setRobotPolicy( "noindex,nofollow" );
769 $wgOut->setArticleRelated( false );
770 $wgOut->enableClientCache( false );
771 $wgOut->addWikiText( $description );
777 * Builds the image revision log shown on image pages
781 class ImageHistoryList
{
783 protected $imagePage, $img, $skin, $title, $repo;
785 public function __construct( $imagePage ) {
787 $this->skin
= $wgUser->getSkin();
788 $this->current
= $imagePage->getFile();
789 $this->img
= $imagePage->getDisplayedFile();
790 $this->title
= $imagePage->getTitle();
791 $this->imagePage
= $imagePage;
794 public function getImagePage() {
795 return $this->imagePage
;
798 public function getSkin() {
802 public function getFile() {
806 public function beginImageHistoryList( $navLinks = '' ) {
807 global $wgOut, $wgUser;
808 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
809 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
811 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
813 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
814 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
815 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
816 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
817 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
818 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
822 public function endImageHistoryList( $navLinks = '' ) {
823 return "</table>\n$navLinks\n";
826 public function imageHistoryLine( $iscur, $file ) {
827 global $wgUser, $wgLang, $wgContLang, $wgTitle;
829 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
830 $img = $iscur ?
$file->getName() : $file->getArchiveName();
831 $user = $file->getUser('id');
832 $usertext = $file->getUser('text');
833 $size = $file->getSize();
834 $description = $file->getDescription();
835 $dims = $file->getDimensionsString();
836 $sha1 = $file->getSha1();
838 $local = $this->current
->isLocal();
839 $row = $css = $selected = '';
842 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
844 # Link to remove from history
845 if( $wgUser->isAllowed( 'delete' ) ) {
847 $q[] = 'action=delete';
849 $q[] = 'oldimage=' . urlencode( $img );
850 $row .= $this->skin
->makeKnownLinkObj(
852 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
856 # Link to hide content
857 if( $wgUser->isAllowed( 'deleterevision' ) ) {
858 if( $wgUser->isAllowed('delete') ) {
861 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
862 // If file is top revision or locked from this user, don't link
863 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
864 $del = wfMsgHtml( 'rev-delundel' );
866 // If the file was hidden, link to sha-1
867 list($ts,$name) = explode('!',$img,2);
868 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
869 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
870 '&oldimage=' . urlencode( $ts ) );
871 // Bolden oversighted content
872 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
873 $del = "<strong>$del</strong>";
875 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
880 // Reversion link/current indicator
883 $row .= wfMsgHtml( 'filehist-current' );
884 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
885 if( $file->isDeleted(File
::DELETED_FILE
) ) {
886 $row .= wfMsgHtml('filehist-revert');
889 $q[] = 'action=revert';
890 $q[] = 'oldimage=' . urlencode( $img );
891 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
892 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
893 wfMsgHtml( 'filehist-revert' ),
894 implode( '&', $q ) );
899 // Date/time and image link
900 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
901 $selected = "class='filehistory-selected'";
903 $row .= "<td $selected style='white-space: nowrap;'>";
904 if( !$file->userCan(File
::DELETED_FILE
) ) {
905 # Don't link to unviewable files
906 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
907 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
908 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
909 # Make a link to review the image
910 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
911 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
912 $row .= '<span class="history-deleted">'.$url.'</span>';
914 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
915 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
919 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
924 $thumbnail = $file->transform( $params );
926 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
929 $row .= '</td><td>' . $thumbnail->toHtml( $options );
931 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
936 $row .= htmlspecialchars( $dims );
939 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
944 // Hide deleted usernames
945 if( $file->isDeleted(File
::DELETED_USER
) ) {
946 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
948 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
949 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
952 $row .= htmlspecialchars( $usertext );
956 // Don't show deleted descriptions
957 if( $file->isDeleted(File
::DELETED_COMMENT
) ) {
958 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
960 $row .= $this->skin
->commentBlock( $description, $this->title
);
964 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
965 $classAttr = $rowClass ?
" class='$rowClass'" : "";
967 return "<tr{$classAttr}>{$row}</tr>\n";
971 class ImageHistoryPseudoPager
extends ReverseChronologicalPager
{
972 function __construct( $imagePage ) {
973 parent
::__construct();
974 $this->mImagePage
= $imagePage;
975 $this->mTitle
= clone( $imagePage->getTitle() );
976 $this->mTitle
->setFragment( '#filehistory' );
978 $this->mHist
= array();
979 $this->mRange
= array( 0, 0 ); // display range
982 function getTitle() {
983 return $this->mTitle
;
986 function getQueryInfo() {
990 function getIndexField() {
994 function formatRow( $row ) {
1001 if( count($this->mHist
) ) {
1002 $list = new ImageHistoryList( $this->mImagePage
);
1003 # Generate prev/next links
1004 $navLink = $this->getNavigationBar();
1005 $s = $list->beginImageHistoryList($navLink);
1006 // Skip rows there just for paging links
1007 for( $i = $this->mRange
[0]; $i <= $this->mRange
[1]; $i++
) {
1008 $file = $this->mHist
[$i];
1009 $s .= $list->imageHistoryLine( !$file->isOld(), $file );
1011 $s .= $list->endImageHistoryList($navLink);
1016 function doQuery() {
1017 if( $this->mQueryDone
) return;
1018 $this->mImg
= $this->mImagePage
->getFile(); // ensure loading
1019 if( !$this->mImg
->exists() ) {
1022 $queryLimit = $this->mLimit +
1; // limit plus extra row
1023 if( $this->mIsBackwards
) {
1024 // Fetch the file history
1025 $this->mHist
= $this->mImg
->getHistory($queryLimit,null,$this->mOffset
,false);
1026 // The current rev may not meet the offset/limit
1027 $numRows = count($this->mHist
);
1028 if( $numRows <= $this->mLimit
&& $this->mImg
->getTimestamp() > $this->mOffset
) {
1029 $this->mHist
= array_merge( array($this->mImg
), $this->mHist
);
1032 // The current rev may not meet the offset
1033 if( !$this->mOffset ||
$this->mImg
->getTimestamp() < $this->mOffset
) {
1034 $this->mHist
[] = $this->mImg
;
1036 // Old image versions (fetch extra row for nav links)
1037 $oiLimit = count($this->mHist
) ?
$this->mLimit
: $this->mLimit+
1;
1038 // Fetch the file history
1039 $this->mHist
= array_merge( $this->mHist
,
1040 $this->mImg
->getHistory($oiLimit,$this->mOffset
,null,false) );
1042 $numRows = count($this->mHist
); // Total number of query results
1044 # Index value of top item in the list
1045 $firstIndex = $this->mIsBackwards ?
1046 $this->mHist
[$numRows-1]->getTimestamp() : $this->mHist
[0]->getTimestamp();
1047 # Discard the extra result row if there is one
1048 if( $numRows > $this->mLimit
&& $numRows > 1 ) {
1049 if( $this->mIsBackwards
) {
1050 # Index value of item past the index
1051 $this->mPastTheEndIndex
= $this->mHist
[0]->getTimestamp();
1052 # Index value of bottom item in the list
1053 $lastIndex = $this->mHist
[1]->getTimestamp();
1055 $this->mRange
= array( 1, $numRows-1 );
1057 # Index value of item past the index
1058 $this->mPastTheEndIndex
= $this->mHist
[$numRows-1]->getTimestamp();
1059 # Index value of bottom item in the list
1060 $lastIndex = $this->mHist
[$numRows-2]->getTimestamp();
1062 $this->mRange
= array( 0, $numRows-2 );
1065 # Setting indexes to an empty string means that they will be
1066 # omitted if they would otherwise appear in URLs. It just so
1067 # happens that this is the right thing to do in the standard
1068 # UI, in all the relevant cases.
1069 $this->mPastTheEndIndex
= '';
1070 # Index value of bottom item in the list
1071 $lastIndex = $this->mIsBackwards ?
1072 $this->mHist
[0]->getTimestamp() : $this->mHist
[$numRows-1]->getTimestamp();
1074 $this->mRange
= array( 0, $numRows-1 );
1079 $this->mPastTheEndIndex
= '';
1081 if( $this->mIsBackwards
) {
1082 $this->mIsFirst
= ( $numRows < $queryLimit );
1083 $this->mIsLast
= ( $this->mOffset
== '' );
1084 $this->mLastShown
= $firstIndex;
1085 $this->mFirstShown
= $lastIndex;
1087 $this->mIsFirst
= ( $this->mOffset
== '' );
1088 $this->mIsLast
= ( $numRows < $queryLimit );
1089 $this->mLastShown
= $lastIndex;
1090 $this->mFirstShown
= $firstIndex;
1092 $this->mQueryDone
= true;