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 protected function loadFile() {
27 if ( $this->fileLoaded
) {
30 $this->fileLoaded
= true;
32 $this->displayImg
= $this->img
= false;
33 wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img
, &$this->displayImg
) );
35 $this->img
= wfFindFile( $this->mTitle
);
37 $this->img
= wfLocalFile( $this->mTitle
);
40 if ( !$this->displayImg
) {
41 $this->displayImg
= $this->img
;
43 $this->repo
= $this->img
->getRepo();
47 * Handler for action=render
48 * Include body text only; none of the image extras
52 $wgOut->setArticleBodyOnly( true );
57 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
60 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
61 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
62 // mTitle is the same as the redirect target so ask Article
63 // to perform the redirect for us.
64 return Article
::view();
66 // mTitle is not the same as the redirect target so it is
67 // probably the redirect page itself. Fake the redirect symbol
68 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
69 $wgOut->addHTML( $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
70 /* $appendSubtitle */ true, /* $forceKnown */ true ) );
76 $diff = $wgRequest->getVal( 'diff' );
77 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
79 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
80 return Article
::view();
82 if ( $wgShowEXIF && $this->displayImg
->exists() ) {
83 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
84 $formattedMetadata = $this->displayImg
->formatMetadata();
85 $showmeta = $formattedMetadata !== false;
90 if ( $this->displayImg
->exists() )
91 $wgOut->addHTML( $this->showTOC($showmeta) );
93 $this->openShowImage();
95 # No need to display noarticletext, we use our own message, output in openShowImage()
96 if ( $this->getID() ) {
99 # Just need to set the right headers
100 $wgOut->setArticleFlag( true );
101 $wgOut->setRobotPolicy( 'noindex,nofollow' );
102 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
103 $this->viewUpdates();
106 # Show shared description, if needed
107 if ( $this->mExtraDescription
) {
108 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
109 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
110 $wgOut->addWikiText( $fol );
112 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
114 $this->checkSharedConflict();
117 $this->closeShowImage();
118 $this->imageHistory();
119 // TODO: Cleanup the following
121 $wgOut->addHTML( Xml
::element( 'h2',
122 array( 'id' => 'filelinks' ),
123 wfMsg( 'imagelinks' ) ) . "\n" );
125 // TODO: We may want to find local images redirecting to a foreign
126 // file: "The following local files redirect to this file"
127 if ( $this->img
->isLocal() ) {
128 $this->imageRedirects();
133 global $wgStylePath, $wgStyleVersion;
134 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
135 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
136 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
137 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
138 $wgOut->addScriptFile( 'metadata.js' );
140 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
144 public function getRedirectTarget() {
146 if ( $this->img
->isLocal() ) {
147 return parent
::getRedirectTarget();
149 // Foreign image page
150 $from = $this->img
->getRedirected();
151 $to = $this->img
->getName();
152 if ( $from == $to ) {
155 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
157 public function followRedirect() {
159 if ( $this->img
->isLocal() ) {
160 return parent
::followRedirect();
162 $from = $this->img
->getRedirected();
163 $to = $this->img
->getName();
164 if ( $from == $to ) {
167 return Title
::makeTitle( NS_IMAGE
, $to );
169 public function isRedirect( $text = false ) {
171 if ( $this->img
->isLocal() )
172 return parent
::isRedirect( $text );
174 return (bool)$this->img
->getRedirected();
177 public function isLocal() {
179 return $this->img
->isLocal();
182 public function getFile() {
187 public function getDisplayedFile() {
189 return $this->displayImg
;
192 public function getDuplicates() {
194 if ( !is_null($this->dupes
) ) {
197 if ( !( $hash = $this->img
->getSha1() ) ) {
198 return $this->dupes
= array();
200 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
201 // Remove duplicates with self and non matching file sizes
202 $self = $this->img
->getRepoName().':'.$this->img
->getName();
203 $size = $this->img
->getSize();
204 foreach ( $dupes as $index => $file ) {
205 $key = $file->getRepoName().':'.$file->getName();
207 unset( $dupes[$index] );
208 if ( $file->getSize() != $size )
209 unset( $dupes[$index] );
211 return $this->dupes
= $dupes;
221 * @param bool $metadata Whether or not to show the metadata link
224 function showTOC( $metadata ) {
226 $r = '<ul id="filetoc">
227 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
228 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
229 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
230 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
236 * Make a table with metadata to be shown in the output page.
238 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
242 * @param array $exif The array containing the EXIF data
245 function makeMetadataTable( $metadata ) {
246 $r = wfMsg( 'metadata-help' ) . "\n\n";
247 $r .= "{| id=mw_metadata class=mw_metadata\n";
248 foreach ( $metadata as $type => $stuff ) {
249 foreach ( $stuff as $v ) {
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 function getContent() {
271 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
274 return Article
::getContent();
277 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 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 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 function checkSharedConflictCallback( $repo ) {
545 $dupfile = $repo->newFile( $this->img
->getTitle() );
546 if( $dupfile && $dupfile->exists() ) {
547 $this->dupFile
= $dupfile;
548 return $dupfile->exists();
553 function getUploadUrl() {
555 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
556 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
560 * Print out the various links at the bottom of the image page, e.g. reupload,
561 * external editing (and instructions link) etc.
563 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 . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
588 $wgOut->addHtml( '</ul>' );
591 function closeShowImage()
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 function imageHistory() {
602 global $wgOut, $wgUseExternalEditor;
605 if ( $this->img
->exists() ) {
606 $list = new ImageHistoryList( $this );
608 $s = $list->beginImageHistoryList();
609 $s .= $list->imageHistoryLine( true, $file );
610 // old image versions
611 $hist = $this->img
->getHistory();
612 foreach( $hist as $file ) {
613 $s .= $list->imageHistoryLine( false, $file );
615 $s .= $list->endImageHistoryList();
617 $wgOut->addHTML( $s );
619 $this->img
->resetHistory(); // free db resources
621 # Exist check because we don't want to show this on pages where an image
622 # doesn't exist along with the noimage message, that would suck. -ævar
623 if( $wgUseExternalEditor && $this->img
->exists() ) {
624 $this->uploadLinksBox();
629 function imageLinks() {
630 global $wgUser, $wgOut, $wgLang;
634 $dbr = wfGetDB( DB_SLAVE
);
637 array( 'imagelinks', 'page' ),
638 array( 'page_namespace', 'page_title' ),
639 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
641 array( 'LIMIT' => $limit +
1)
643 $count = $dbr->numRows( $res );
645 $wgOut->addHTML( "<div id='mw-imagepage-nolinkstoimage'>\n" );
646 $wgOut->addWikiMsg( 'nolinkstoimage' );
647 $wgOut->addHTML( "</div>\n" );
651 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
652 if ( $count <= $limit - 1 ) {
653 $wgOut->addWikiMsg( 'linkstoimage', $count );
655 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
656 $wgOut->addWikiMsg( 'linkstoimage-more',
657 $wgLang->formatNum( $limit ),
658 $this->mTitle
->getPrefixedDBkey()
662 $wgOut->addHTML( "<ul class='mw-imagepage-linkstoimage'>\n" );
663 $sk = $wgUser->getSkin();
665 while ( $s = $res->fetchObject() ) {
667 if ( $count <= $limit ) {
668 // We have not yet reached the extra one that tells us there is more to fetch
669 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
670 $link = $sk->makeKnownLinkObj( $name, "" );
671 $wgOut->addHTML( "<li>{$link}</li>\n" );
674 $wgOut->addHTML( "</ul></div>\n" );
677 // Add a links to [[Special:Whatlinkshere]]
678 if ( $count > $limit )
679 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
682 function imageRedirects() {
683 global $wgUser, $wgOut, $wgLang;
685 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
686 if ( count( $redirects ) == 0 ) return;
688 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
689 $wgOut->addWikiMsg( 'redirectstofile',
690 $wgLang->formatNum( count( $redirects ) )
692 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
694 $sk = $wgUser->getSkin();
695 foreach ( $redirects as $title ) {
696 $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" );
697 $wgOut->addHTML( "<li>{$link}</li>\n" );
699 $wgOut->addHTML( "</ul></div>\n" );
703 function imageDupes() {
704 global $wgOut, $wgUser, $wgLang;
708 $dupes = $this->getDuplicates();
709 if ( count( $dupes ) == 0 ) return;
711 $wgOut->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
712 $wgOut->addWikiMsg( 'duplicatesoffile',
713 $wgLang->formatNum( count( $dupes ) )
715 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
717 $sk = $wgUser->getSkin();
718 foreach ( $dupes as $file ) {
719 if ( $file->isLocal() )
720 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
722 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
723 $file->getTitle()->getPrefixedText() );
725 $wgOut->addHTML( "<li>{$link}</li>\n" );
727 $wgOut->addHTML( "</ul></div>\n" );
731 * Delete the file, or an earlier version of it
733 public function delete() {
735 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
736 // Standard article deletion
740 $deleter = new FileDeleteForm( $this->img
);
745 * Revert the file to an earlier version
747 public function revert() {
749 $reverter = new FileRevertForm( $this->img
);
750 $reverter->execute();
754 * Override handling of action=purge
758 if( $this->img
->exists() ) {
759 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
760 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
762 $this->img
->upgradeRow();
763 $this->img
->purgeCache();
765 wfDebug( "ImagePage::doPurge no image\n" );
771 * Display an error with a wikitext description
773 function showError( $description ) {
775 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
776 $wgOut->setRobotPolicy( "noindex,nofollow" );
777 $wgOut->setArticleRelated( false );
778 $wgOut->enableClientCache( false );
779 $wgOut->addWikiText( $description );
785 * Builds the image revision log shown on image pages
789 class ImageHistoryList
{
791 protected $imagePage, $img, $skin, $title, $repo;
793 public function __construct( $imagePage ) {
795 $this->skin
= $wgUser->getSkin();
796 $this->current
= $imagePage->getFile();
797 $this->img
= $imagePage->getDisplayedFile();
798 $this->title
= $imagePage->getTitle();
799 $this->imagePage
= $imagePage;
802 function getImagePage() {
803 return $this->imagePage
;
814 public function beginImageHistoryList() {
815 global $wgOut, $wgUser;
816 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
817 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
818 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
820 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
821 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
822 . '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>'
823 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
824 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
825 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
829 public function endImageHistoryList() {
833 public function imageHistoryLine( $iscur, $file ) {
834 global $wgUser, $wgLang, $wgContLang, $wgTitle;
836 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
837 $img = $iscur ?
$file->getName() : $file->getArchiveName();
838 $user = $file->getUser('id');
839 $usertext = $file->getUser('text');
840 $size = $file->getSize();
841 $description = $file->getDescription();
842 $dims = $file->getDimensionsString();
843 $sha1 = $file->getSha1();
845 $local = $this->current
->isLocal();
846 $row = $css = $selected = '';
849 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
851 # Link to remove from history
852 if( $wgUser->isAllowed( 'delete' ) ) {
854 $q[] = 'action=delete';
856 $q[] = 'oldimage=' . urlencode( $img );
857 $row .= $this->skin
->makeKnownLinkObj(
859 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
863 # Link to hide content
864 if( $wgUser->isAllowed( 'deleterevision' ) ) {
865 if( $wgUser->isAllowed('delete') ) {
868 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
869 // If file is top revision or locked from this user, don't link
870 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
871 $del = wfMsgHtml( 'rev-delundel' );
873 // If the file was hidden, link to sha-1
874 list($ts,$name) = explode('!',$img,2);
875 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
876 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
877 '&oldimage=' . urlencode( $ts ) );
878 // Bolden oversighted content
879 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
880 $del = "<strong>$del</strong>";
882 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
887 // Reversion link/current indicator
890 $row .= wfMsgHtml( 'filehist-current' );
891 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
892 if( $file->isDeleted(File
::DELETED_FILE
) ) {
893 $row .= wfMsgHtml('filehist-revert');
896 $q[] = 'action=revert';
897 $q[] = 'oldimage=' . urlencode( $img );
898 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
899 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
900 wfMsgHtml( 'filehist-revert' ),
901 implode( '&', $q ) );
906 // Date/time and image link
907 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
908 $selected = "class='filehistory-selected'";
910 $row .= "<td $selected style='white-space: nowrap;'>";
911 if( !$file->userCan(File
::DELETED_FILE
) ) {
912 # Don't link to unviewable files
913 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
914 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
915 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
916 # Make a link to review the image
917 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
918 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
919 $row .= '<span class="history-deleted">'.$url.'</span>';
921 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
922 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
926 if( $file->allowInlineDisplay() && $file->userCan( File
::DELETED_FILE
) && !$file->isDeleted( File
::DELETED_FILE
) ) {
931 $thumbnail = $file->transform( $params );
933 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ),
936 $row .= '</td><td>' . $thumbnail->toHtml( $options );
938 $row .= '</td><td>' . wfMsgHtml( 'filehist-nothumb' );
943 $row .= htmlspecialchars( $dims );
946 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
951 // Hide deleted usernames
952 if( $file->isDeleted(File
::DELETED_USER
) ) {
953 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
955 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
956 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
959 $row .= htmlspecialchars( $usertext );
963 // Don't show deleted descriptions
964 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
965 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
967 $row .= $this->skin
->commentBlock( $description, $this->title
);
971 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
972 $classAttr = $rowClass ?
" class='$rowClass'" : "";
974 return "<tr{$classAttr}>{$row}</tr>\n";