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 $time;
17 /* private */ var $fileLoaded;
18 var $mExtraDescription = false;
21 function __construct( $title, $time = null ) {
22 parent
::__construct( $title );
25 $time = is_null($time) ?
$wgRequest->getVal( 'filetimestamp' ) : $time;
26 $time = $time ?
$time : false; // be clear about type
32 protected function loadFile() {
33 if ( $this->fileLoaded
) {
36 $this->displayImg
= wfFindFile( $this->mTitle
, $this->time
);
37 # If none found, and no time given, use a valid local placeholder
38 if ( !$this->displayImg
&& !$this->time
) {
39 $this->displayImg
= wfLocalFile( $this->mTitle
);
40 $this->img
= $this->displayImg
;
41 # If none found, and time given, try current
42 } else if ( !$this->displayImg
&& $this->time
) {
43 $this->displayImg
= wfFindFile( $this->mTitle
);
44 # If none found, use a valid local placeholder
45 if( !$this->displayImg
) {
46 $this->displayImg
= wfLocalFile( $this->mTitle
); // fallback to current
48 $this->img
= $this->displayImg
;
49 # If found, set $this->img. This will be the same if no time given
51 $this->img
= $this->time ?
wfFindFile( $this->mTitle
) : $this->displayImg
;
53 $this->repo
= $this->img
->getRepo();
54 $this->fileLoaded
= true;
58 * Handler for action=render
59 * Include body text only; none of the image extras
63 $wgOut->setArticleBodyOnly( true );
68 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
71 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
72 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
73 // mTitle is the same as the redirect target so ask Article
74 // to perform the redirect for us.
75 return Article
::view();
77 // mTitle is not the same as the redirect target so it is
78 // probably the redirect page itself. Fake the redirect symbol
79 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
80 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
81 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
87 $diff = $wgRequest->getVal( 'diff' );
88 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
90 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
91 return Article
::view();
93 if ( $wgShowEXIF && $this->displayImg
->exists() ) {
94 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
95 $formattedMetadata = $this->displayImg
->formatMetadata();
96 $showmeta = $formattedMetadata !== false;
101 if ( $this->displayImg
->exists() )
102 $wgOut->addHTML( $this->showTOC($showmeta) );
104 $this->openShowImage();
106 # No need to display noarticletext, we use our own message, output in openShowImage()
107 if ( $this->getID() ) {
110 # Just need to set the right headers
111 $wgOut->setArticleFlag( true );
112 $wgOut->setRobotpolicy( 'noindex,nofollow' );
113 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
114 $this->viewUpdates();
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( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
146 $collapse = htmlspecialchars( wfEscapeJsString( 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();
163 if ( $from == $to ) {
166 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
168 public function followRedirect() {
170 if ( $this->img
->isLocal() ) {
171 return parent
::followRedirect();
173 $from = $this->img
->getRedirected();
174 $to = $this->img
->getName();
175 if ( $from == $to ) {
178 return Title
::makeTitle( NS_IMAGE
, $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;
232 * @param bool $metadata Whether or not to show the metadata link
235 function showTOC( $metadata ) {
237 $r = '<ul id="filetoc">
238 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
239 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
240 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
241 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
247 * Make a table with metadata to be shown in the output page.
249 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
253 * @param array $exif The array containing the EXIF data
256 function makeMetadataTable( $metadata ) {
257 $r = wfMsg( 'metadata-help' ) . "\n\n";
258 $r .= "{| id=mw_metadata class=mw_metadata\n";
259 foreach ( $metadata as $type => $stuff ) {
260 foreach ( $stuff as $v ) {
261 $class = Sanitizer
::escapeId( $v['id'] );
262 if( $type == 'collapsed' ) {
263 $class .= ' collapsable';
265 $r .= "|- class=\"$class\"\n";
266 $r .= "!| {$v['name']}\n";
267 $r .= "|| {$v['value']}\n";
275 * Overloading Article's getContent method.
277 * Omit noarticletext if sharedupload; text will be fetched from the
278 * shared upload server if possible.
280 function getContent() {
282 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
285 return Article
::getContent();
288 function openShowImage() {
289 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
293 $full_url = $this->displayImg
->getURL();
294 $linkAttribs = false;
295 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
296 if( !isset( $wgImageLimits[$sizeSel] ) ) {
297 $sizeSel = User
::getDefaultOption( 'imagesize' );
299 // The user offset might still be incorrect, specially if
300 // $wgImageLimits got changed (see bug #8858).
301 if( !isset( $wgImageLimits[$sizeSel] ) ) {
302 // Default to the first offset in $wgImageLimits
306 $max = $wgImageLimits[$sizeSel];
308 $maxHeight = $max[1];
309 $sk = $wgUser->getSkin();
310 $dirmark = $wgContLang->getDirMark();
312 if ( $this->displayImg
->exists() ) {
314 $page = $wgRequest->getIntOrNull( 'page' );
315 if ( is_null( $page ) ) {
319 $params = array( 'page' => $page );
321 $width_orig = $this->displayImg
->getWidth();
322 $width = $width_orig;
323 $height_orig = $this->displayImg
->getHeight();
324 $height = $height_orig;
325 $mime = $this->displayImg
->getMimeType();
327 $linkAttribs = array( 'href' => $full_url );
328 $longDesc = $this->displayImg
->getLongDesc();
330 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
332 if ( $this->displayImg
->allowInlineDisplay() ) {
335 # "Download high res version" link below the image
336 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
337 # We'll show a thumbnail of this image
338 if ( $width > $maxWidth ||
$height > $maxHeight ) {
339 # Calculate the thumbnail size.
340 # First case, the limiting factor is the width, not the height.
341 if ( $width / $height >= $maxWidth / $maxHeight ) {
342 $height = round( $height * $maxWidth / $width);
344 # Note that $height <= $maxHeight now.
346 $newwidth = floor( $width * $maxHeight / $height);
347 $height = round( $height * $newwidth / $width );
349 # Note that $height <= $maxHeight now, but might not be identical
350 # because of rounding.
352 $msgbig = wfMsgHtml( 'show-big-image' );
353 $msgsmall = wfMsgExt( 'show-big-image-thumb',
354 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
356 # Image is small enough to show full size on image page
357 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
358 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
361 $params['width'] = $width;
362 $thumbnail = $this->displayImg
->transform( $params );
364 $anchorclose = "<br />";
365 if( $this->displayImg
->mustRender() ) {
370 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
373 if ( $this->displayImg
->isMultipage() ) {
374 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
379 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
382 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
383 $thumbnail->toHtml( $options ) .
384 $anchorclose . '</div>' );
387 if ( $this->displayImg
->isMultipage() ) {
388 $count = $this->displayImg
->pageCount();
391 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
392 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
393 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
394 array( 'page' => $page - 1 ) );
399 if ( $page < $count ) {
400 $label = wfMsg( 'imgmultipagenext' );
401 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
402 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
403 array( 'page' => $page +
1 ) );
411 'name' => 'pageselector',
412 'action' => $wgScript,
413 'onchange' => 'document.pageselector.submit();',
417 for ( $i=1; $i <= $count; $i++
) {
418 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
420 $select = Xml
::tags( 'select',
421 array( 'id' => 'pageselector', 'name' => 'page' ),
422 implode( "\n", $options ) );
425 '</td><td><div class="multipageimagenavbox">' .
426 Xml
::openElement( 'form', $formParams ) .
427 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
428 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
429 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
430 Xml
::closeElement( 'form' ) .
431 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
435 #if direct link is allowed but it's not a renderable image, show an icon.
436 if ( $this->displayImg
->isSafeFile() ) {
437 $icon= $this->displayImg
->iconThumb();
439 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
440 $icon->toHtml( array( 'desc-link' => true ) ) .
449 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
451 if ( !$this->displayImg
->isSafeFile() ) {
452 $warning = wfMsgNoTrans( 'mediawarning' );
453 $wgOut->addWikiText( <<<EOT
454 <div class="fullMedia">
455 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
456 <span class="fileInfo"> $longDesc</span>
459 <div class="mediaWarning">$warning</div>
463 $wgOut->addWikiText( <<<EOT
464 <div class="fullMedia">
465 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
472 if( !$this->displayImg
->isLocal() ) {
473 $this->printSharedImageText();
476 # Image does not exist
478 $title = SpecialPage
::getTitleFor( 'Upload' );
479 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
480 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
481 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
486 * Show a notice that the file is from a shared repository
488 function printSharedImageText() {
489 global $wgOut, $wgUser;
493 $descUrl = $this->img
->getDescriptionUrl();
494 $descText = $this->img
->getDescriptionText();
495 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
497 $sk = $wgUser->getSkin();
498 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
499 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
500 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
502 # Show message only if not voided by local sysops
507 $wgOut->addHTML( $s );
510 $this->mExtraDescription
= $descText;
515 * Check for files with the same name on the foreign repos.
517 function checkSharedConflict() {
518 global $wgOut, $wgUser;
520 $repoGroup = RepoGroup
::singleton();
521 if( !$repoGroup->hasForeignRepos() ) {
526 if( !$this->img
->isLocal() ) {
530 $this->dupFile
= null;
531 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
533 if( !$this->dupFile
)
535 $dupfile = $this->dupFile
;
537 ($this->img
->getSha1() == $dupfile->getSha1()) &&
538 ($this->img
->getSize() == $dupfile->getSize())
541 $sk = $wgUser->getSkin();
542 $descUrl = $dupfile->getDescriptionUrl();
544 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
545 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
547 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
548 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
552 function checkSharedConflictCallback( $repo ) {
554 $dupfile = $repo->newFile( $this->img
->getTitle() );
555 if( $dupfile->exists() ) {
556 $this->dupFile
= $dupfile;
558 return $dupfile->exists();
561 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 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 . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
596 $wgOut->addHtml( '</ul>' );
599 function closeShowImage()
606 * If the page we've just displayed is in the "Image" namespace,
607 * we follow it with an upload history of the image and its usage.
609 function imageHistory()
611 global $wgUser, $wgOut, $wgUseExternalEditor;
613 $sk = $wgUser->getSkin();
616 if ( $this->img
->exists() ) {
617 $list = new ImageHistoryList( $sk, $this->img
, $this->displayImg
);
619 $dims = $file->getDimensionsString();
620 $s = $list->beginImageHistoryList();
621 $s .= $list->imageHistoryLine( true, $file );
622 // old image versions
623 $hist = $this->img
->getHistory();
624 foreach( $hist as $file ) {
625 $dims = $file->getDimensionsString();
626 $s .= $list->imageHistoryLine( false, $file );
628 $s .= $list->endImageHistoryList();
630 $wgOut->addHTML( $s );
632 $this->img
->resetHistory(); // free db resources
634 # Exist check because we don't want to show this on pages where an image
635 # doesn't exist along with the noimage message, that would suck. -ævar
636 if( $wgUseExternalEditor && $this->img
->exists() ) {
637 $this->uploadLinksBox();
642 function imageLinks()
644 global $wgUser, $wgOut;
648 $dbr = wfGetDB( DB_SLAVE
);
651 array( 'imagelinks', 'page' ),
652 array( 'page_namespace', 'page_title' ),
653 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
655 array( 'LIMIT' => $limit +
1)
658 if ( 0 == $dbr->numRows( $res ) ) {
659 $wgOut->addWikiMsg( 'nolinkstoimage' );
662 $wgOut->addWikiMsg( 'linkstoimage' );
663 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
665 $sk = $wgUser->getSkin();
667 while ( $s = $res->fetchObject() ) {
669 if ( $count <= $limit ) {
670 // We have not yet reached the extra one that tells us there is more to fetch
671 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
672 $link = $sk->makeKnownLinkObj( $name, "" );
673 $wgOut->addHTML( "<li>{$link}</li>\n" );
676 $wgOut->addHTML( "</ul>\n" );
679 // Add a links to [[Special:Whatlinkshere]]
680 if ( $count > $limit )
681 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
684 function imageRedirects()
686 global $wgUser, $wgOut;
688 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
689 if ( count( $redirects ) == 0 ) return;
692 $wgOut->addWikiMsg( 'redirectstofile' );
693 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
695 $sk = $wgUser->getSkin();
696 foreach ( $redirects as $title ) {
697 $link = $sk->makeKnownLinkObj( $title, "" );
698 $wgOut->addHTML( "<li>{$link}</li>\n" );
700 $wgOut->addHTML( "</ul>\n" );
704 function imageDupes() {
705 global $wgOut, $wgUser;
709 $dupes = $this->getDuplicates();
710 if ( count( $dupes ) == 0 ) return;
712 $wgOut->addWikiMsg( 'duplicatesoffile' );
713 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
715 $sk = $wgUser->getSkin();
716 foreach ( $dupes as $file ) {
717 if ( $file->isLocal() )
718 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
720 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
721 $file->getTitle()->getPrefixedText() );
722 $wgOut->addHTML( "<li>{$link}</li>\n" );
724 $wgOut->addHTML( "</ul>\n" );
728 * Delete the file, or an earlier version of it
730 public function delete() {
732 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
733 // Standard article deletion
737 $deleter = new FileDeleteForm( $this->img
);
742 * Revert the file to an earlier version
744 public function revert() {
746 $reverter = new FileRevertForm( $this->img
);
747 $reverter->execute();
751 * Override handling of action=purge
755 if( $this->img
->exists() ) {
756 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
757 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
759 $this->img
->upgradeRow();
760 $this->img
->purgeCache();
762 wfDebug( "ImagePage::doPurge no image\n" );
768 * Display an error with a wikitext description
770 function showError( $description ) {
772 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
773 $wgOut->setRobotpolicy( "noindex,nofollow" );
774 $wgOut->setArticleRelated( false );
775 $wgOut->enableClientCache( false );
776 $wgOut->addWikiText( $description );
782 * Builds the image revision log shown on image pages
786 class ImageHistoryList
{
788 protected $img, $skin, $title, $repo;
790 public function __construct( $skin, $curimg, $img ) {
792 $this->current
= $curimg;
794 $this->title
= $img->getTitle();
797 public function beginImageHistoryList() {
798 global $wgOut, $wgUser;
799 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
800 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
801 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
803 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
804 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
805 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
806 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
807 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
811 public function endImageHistoryList() {
815 public function imageHistoryLine( $iscur, $file ) {
816 global $wgUser, $wgLang, $wgContLang, $wgTitle;
818 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
819 $img = $iscur ?
$file->getName() : $file->getArchiveName();
820 $user = $file->getUser('id');
821 $usertext = $file->getUser('text');
822 $size = $file->getSize();
823 $description = $file->getDescription();
824 $dims = $file->getDimensionsString();
825 $sha1 = $file->getSha1();
827 $local = $this->current
->isLocal();
828 $row = $css = $selected = '';
831 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
833 # Link to remove from history
834 if( $wgUser->isAllowed( 'delete' ) ) {
836 $q[] = 'action=delete';
838 $q[] = 'oldimage=' . urlencode( $img );
839 $row .= $this->skin
->makeKnownLinkObj(
841 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
845 # Link to hide content
846 if( $wgUser->isAllowed( 'deleterevision' ) ) {
847 if( $wgUser->isAllowed('delete') ) {
850 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
851 // If file is top revision or locked from this user, don't link
852 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
853 $del = wfMsgHtml( 'rev-delundel' );
855 // If the file was hidden, link to sha-1
856 list($ts,$name) = explode('!',$img,2);
857 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
858 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
859 '&oldimage=' . urlencode( $ts ) );
860 // Bolden oversighted content
861 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
862 $del = "<strong>$del</strong>";
864 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
869 // Reversion link/current indicator
872 $row .= wfMsgHtml( 'filehist-current' );
873 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
874 if( $file->isDeleted(File
::DELETED_FILE
) ) {
875 $row .= wfMsgHtml('filehist-revert');
878 $q[] = 'action=revert';
879 $q[] = 'oldimage=' . urlencode( $img );
880 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
881 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
882 wfMsgHtml( 'filehist-revert' ),
883 implode( '&', $q ) );
888 // Date/time and image link
889 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
890 $selected = "class='filehistory-selected'";
892 $row .= "<td $selected style='white-space: nowrap;'>";
893 if( !$file->userCan(File
::DELETED_FILE
) ) {
894 # Don't link to unviewable files
895 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
896 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
897 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
898 # Make a link to review the image
899 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
900 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
901 $row .= '<span class="history-deleted">'.$url.'</span>';
903 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
904 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
910 $row .= htmlspecialchars( $dims );
913 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
918 // Hide deleted usernames
919 if( $file->isDeleted(File
::DELETED_USER
) ) {
920 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
922 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
923 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
926 $row .= htmlspecialchars( $usertext );
930 // Don't show deleted descriptions
931 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
932 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
934 $row .= $this->skin
->commentBlock( $description, $this->title
);
938 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
939 $trCSS = $css ?
" class='$css'" : "";
941 return "<tr{$trCSS}>{$row}</tr>\n";