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 $this->time
= is_null($time) ?
$wgRequest->getVal( 'filetimestamp' ) : $time;
30 protected function loadFile() {
31 if( $this->fileLoaded
) {
34 $this->displayImg
= wfFindFile( $this->mTitle
, $this->time
);
35 if ( !$this->displayImg
) {
36 $this->displayImg
= wfLocalFile( $this->mTitle
);
37 $this->img
= $this->displayImg
;
39 $this->img
= $this->time ?
wfLocalFile( $this->mTitle
) : $this->displayImg
;
41 $this->repo
= $this->img
->getRepo();
42 $this->fileLoaded
= true;
46 * Handler for action=render
47 * Include body text only; none of the image extras
51 $wgOut->setArticleBodyOnly( true );
56 global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
59 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&& $this->img
->getRedirected() ) {
60 if ( $this->mTitle
->getDBkey() == $this->img
->getName() ) {
61 // mTitle is the same as the redirect target so ask Article
62 // to perform the redirect for us.
63 return Article
::view();
65 // mTitle is not the same as the redirect target so it is
66 // probably the redirect page itself. Fake the redirect symbol
67 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
68 $this->viewRedirect( Title
::makeTitle( NS_IMAGE
, $this->img
->getName() ),
69 /* $overwriteSubtitle */ true, /* $forceKnown */ true );
75 $diff = $wgRequest->getVal( 'diff' );
76 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
78 if ( $this->mTitle
->getNamespace() != NS_IMAGE ||
( isset( $diff ) && $diffOnly ) )
79 return Article
::view();
81 if ( $wgShowEXIF && $this->displayImg
->exists() ) {
82 // FIXME: bad interface, see note on MediaHandler::formatMetadata().
83 $formattedMetadata = $this->displayImg
->formatMetadata();
84 $showmeta = $formattedMetadata !== false;
89 if ( $this->displayImg
->exists() )
90 $wgOut->addHTML( $this->showTOC($showmeta) );
92 $this->openShowImage();
94 # No need to display noarticletext, we use our own message, output in openShowImage()
95 if ( $this->getID() ) {
98 # Just need to set the right headers
99 $wgOut->setArticleFlag( true );
100 $wgOut->setRobotpolicy( 'noindex,nofollow' );
101 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
102 $this->viewUpdates();
105 # Show shared description, if needed
106 if ( $this->mExtraDescription
) {
107 $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
108 if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
109 $wgOut->addWikiText( $fol );
111 $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription
. '</div>' );
113 $this->checkSharedConflict();
116 $this->closeShowImage();
117 $this->imageHistory();
118 // TODO: Cleanup the following
120 $wgOut->addHTML( Xml
::element( 'h2',
121 array( 'id' => 'filelinks' ),
122 wfMsg( 'imagelinks' ) ) . "\n" );
124 // TODO: We may want to find local images redirecting to a foreign
125 // file: "The following local files redirect to this file"
126 if ( $this->img
->isLocal() ) {
127 $this->imageRedirects();
132 global $wgStylePath, $wgStyleVersion;
133 $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
134 $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
135 $wgOut->addHTML( Xml
::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
136 $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
137 $wgOut->addScriptFile( 'metadata.js' );
139 "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
143 public function getRedirectTarget() {
145 if ( $this->img
->isLocal() ) {
146 return parent
::getRedirectTarget();
148 // Foreign image page
149 $from = $this->img
->getRedirected();
150 $to = $this->img
->getName();
151 if ( $from == $to ) {
154 return $this->mRedirectTarget
= Title
::makeTitle( NS_IMAGE
, $to );
156 public function followRedirect() {
158 if ( $this->img
->isLocal() ) {
159 return parent
::followRedirect();
161 $from = $this->img
->getRedirected();
162 $to = $this->img
->getName();
163 if ( $from == $to ) {
166 return Title
::makeTitle( NS_IMAGE
, $to );
168 public function isRedirect( $text = false ) {
170 if ( $this->img
->isLocal() )
171 return parent
::isRedirect( $text );
173 return (bool)$this->img
->getRedirected();
176 public function isLocal() {
178 return $this->img
->isLocal();
181 public function getFile() {
186 public function getDisplayedFile() {
188 return $this->displayImg
;
191 public function getDuplicates() {
193 if ( !is_null($this->dupes
) ) {
196 if ( !( $hash = $this->img
->getSha1() ) ) {
197 return $this->dupes
= array();
199 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
200 // Remove duplicates with self and non matching file sizes
201 $self = $this->img
->getRepoName().':'.$this->img
->getName();
202 $size = $this->img
->getSize();
203 foreach ( $dupes as $index => $file ) {
204 $key = $file->getRepoName().':'.$file->getName();
206 unset( $dupes[$index] );
207 if ( $file->getSize() != $size )
208 unset( $dupes[$index] );
210 return $this->dupes
= $dupes;
220 * @param bool $metadata Whether or not to show the metadata link
223 function showTOC( $metadata ) {
225 $r = '<ul id="filetoc">
226 <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE
) . '</a></li>
227 <li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>
228 <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
229 ($metadata ?
' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
235 * Make a table with metadata to be shown in the output page.
237 * FIXME: bad interface, see note on MediaHandler::formatMetadata().
241 * @param array $exif The array containing the EXIF data
244 function makeMetadataTable( $metadata ) {
245 $r = wfMsg( 'metadata-help' ) . "\n\n";
246 $r .= "{| id=mw_metadata class=mw_metadata\n";
247 foreach ( $metadata as $type => $stuff ) {
248 foreach ( $stuff as $v ) {
249 $class = Sanitizer
::escapeId( $v['id'] );
250 if( $type == 'collapsed' ) {
251 $class .= ' collapsable';
253 $r .= "|- class=\"$class\"\n";
254 $r .= "!| {$v['name']}\n";
255 $r .= "|| {$v['value']}\n";
263 * Overloading Article's getContent method.
265 * Omit noarticletext if sharedupload; text will be fetched from the
266 * shared upload server if possible.
268 function getContent() {
270 if( $this->img
&& !$this->img
->isLocal() && 0 == $this->getID() ) {
273 return Article
::getContent();
276 function openShowImage() {
277 global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
281 $full_url = $this->displayImg
->getURL();
282 $linkAttribs = false;
283 $sizeSel = intval( $wgUser->getOption( 'imagesize') );
284 if( !isset( $wgImageLimits[$sizeSel] ) ) {
285 $sizeSel = User
::getDefaultOption( 'imagesize' );
287 // The user offset might still be incorrect, specially if
288 // $wgImageLimits got changed (see bug #8858).
289 if( !isset( $wgImageLimits[$sizeSel] ) ) {
290 // Default to the first offset in $wgImageLimits
294 $max = $wgImageLimits[$sizeSel];
296 $maxHeight = $max[1];
297 $sk = $wgUser->getSkin();
298 $dirmark = $wgContLang->getDirMark();
300 if ( $this->displayImg
->exists() ) {
302 $page = $wgRequest->getIntOrNull( 'page' );
303 if ( is_null( $page ) ) {
307 $params = array( 'page' => $page );
309 $width_orig = $this->displayImg
->getWidth();
310 $width = $width_orig;
311 $height_orig = $this->displayImg
->getHeight();
312 $height = $height_orig;
313 $mime = $this->displayImg
->getMimeType();
315 $linkAttribs = array( 'href' => $full_url );
316 $longDesc = $this->displayImg
->getLongDesc();
318 wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
320 if ( $this->displayImg
->allowInlineDisplay() ) {
323 # "Download high res version" link below the image
324 #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
325 # We'll show a thumbnail of this image
326 if ( $width > $maxWidth ||
$height > $maxHeight ) {
327 # Calculate the thumbnail size.
328 # First case, the limiting factor is the width, not the height.
329 if ( $width / $height >= $maxWidth / $maxHeight ) {
330 $height = round( $height * $maxWidth / $width);
332 # Note that $height <= $maxHeight now.
334 $newwidth = floor( $width * $maxHeight / $height);
335 $height = round( $height * $newwidth / $width );
337 # Note that $height <= $maxHeight now, but might not be identical
338 # because of rounding.
340 $msgbig = wfMsgHtml( 'show-big-image' );
341 $msgsmall = wfMsgExt( 'show-big-image-thumb',
342 array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
344 # Image is small enough to show full size on image page
345 $msgbig = htmlspecialchars( $this->displayImg
->getName() );
346 $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) );
349 $params['width'] = $width;
350 $thumbnail = $this->displayImg
->transform( $params );
352 $anchorclose = "<br />";
353 if( $this->displayImg
->mustRender() ) {
358 '<br />' . Xml
::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc;
361 if ( $this->displayImg
->isMultipage() ) {
362 $wgOut->addHTML( '<table class="multipageimage"><tr><td>' );
367 'alt' => $this->displayImg
->getTitle()->getPrefixedText(),
370 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
371 $thumbnail->toHtml( $options ) .
372 $anchorclose . '</div>' );
375 if ( $this->displayImg
->isMultipage() ) {
376 $count = $this->displayImg
->pageCount();
379 $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false );
380 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page-1) );
381 $thumb1 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
382 array( 'page' => $page - 1 ) );
387 if ( $page < $count ) {
388 $label = wfMsg( 'imgmultipagenext' );
389 $link = $sk->makeKnownLinkObj( $this->mTitle
, $label, 'page='. ($page+
1) );
390 $thumb2 = $sk->makeThumbLinkObj( $this->mTitle
, $this->displayImg
, $link, $label, 'none',
391 array( 'page' => $page +
1 ) );
399 'name' => 'pageselector',
400 'action' => $wgScript,
401 'onchange' => 'document.pageselector.submit();',
405 for ( $i=1; $i <= $count; $i++
) {
406 $options[] = Xml
::option( $wgLang->formatNum($i), $i, $i == $page );
408 $select = Xml
::tags( 'select',
409 array( 'id' => 'pageselector', 'name' => 'page' ),
410 implode( "\n", $options ) );
413 '</td><td><div class="multipageimagenavbox">' .
414 Xml
::openElement( 'form', $formParams ) .
415 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
416 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
417 Xml
::submitButton( wfMsg( 'imgmultigo' ) ) .
418 Xml
::closeElement( 'form' ) .
419 "<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>"
423 #if direct link is allowed but it's not a renderable image, show an icon.
424 if ( $this->displayImg
->isSafeFile() ) {
425 $icon= $this->displayImg
->iconThumb();
427 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
428 $icon->toHtml( array( 'desc-link' => true ) ) .
437 $filename = wfEscapeWikiText( $this->displayImg
->getName() );
439 if ( !$this->displayImg
->isSafeFile() ) {
440 $warning = wfMsgNoTrans( 'mediawarning' );
441 $wgOut->addWikiText( <<<EOT
442 <div class="fullMedia">
443 <span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
444 <span class="fileInfo"> $longDesc</span>
447 <div class="mediaWarning">$warning</div>
451 $wgOut->addWikiText( <<<EOT
452 <div class="fullMedia">
453 [[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $longDesc</span>
460 if( !$this->displayImg
->isLocal() ) {
461 $this->printSharedImageText();
464 # Image does not exist
466 $title = SpecialPage
::getTitleFor( 'Upload' );
467 $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
468 'wpDestFile=' . urlencode( $this->displayImg
->getName() ) );
469 $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
474 * Show a notice that the file is from a shared repository
476 function printSharedImageText() {
477 global $wgOut, $wgUser;
481 $descUrl = $this->img
->getDescriptionUrl();
482 $descText = $this->img
->getDescriptionText();
483 $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
485 $sk = $wgUser->getSkin();
486 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
487 $msg = ( $descText ) ?
'shareduploadwiki-desc' : 'shareduploadwiki';
488 $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
490 # Show message only if not voided by local sysops
495 $wgOut->addHTML( $s );
498 $this->mExtraDescription
= $descText;
503 * Check for files with the same name on the foreign repos.
505 function checkSharedConflict() {
506 global $wgOut, $wgUser;
508 $repoGroup = RepoGroup
::singleton();
509 if( !$repoGroup->hasForeignRepos() ) {
514 if( !$this->img
->isLocal() ) {
518 $this->dupFile
= null;
519 $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) );
521 if( !$this->dupFile
)
523 $dupfile = $this->dupFile
;
525 ($this->img
->getSha1() == $dupfile->getSha1()) &&
526 ($this->img
->getSize() == $dupfile->getSize())
529 $sk = $wgUser->getSkin();
530 $descUrl = $dupfile->getDescriptionUrl();
532 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) );
533 $wgOut->addHTML( '<div id="shared-image-dup">' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '</div>' );
535 $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) );
536 $wgOut->addHTML( '<div id="shared-image-conflict">' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '</div>' );
540 function checkSharedConflictCallback( $repo ) {
542 $dupfile = $repo->newFile( $this->img
->getTitle() );
543 if( $dupfile->exists() ) {
544 $this->dupFile
= $dupfile;
546 return $dupfile->exists();
549 function getUploadUrl() {
551 $uploadTitle = SpecialPage
::getTitleFor( 'Upload' );
552 return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img
->getName() ) );
556 * Print out the various links at the bottom of the image page, e.g. reupload,
557 * external editing (and instructions link) etc.
559 function uploadLinksBox() {
560 global $wgUser, $wgOut;
563 if( !$this->img
->isLocal() )
566 $sk = $wgUser->getSkin();
568 $wgOut->addHtml( '<br /><ul>' );
570 # "Upload a new version of this file" link
571 if( UploadForm
::userCanReUpload($wgUser,$this->img
->name
) ) {
572 $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
573 $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
576 # Link to Special:FileDuplicateSearch
577 $dupeLink = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'FileDuplicateSearch', $this->mTitle
->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
578 $wgOut->addHtml( "<li>{$dupeLink}</li>" );
580 # External editing link
581 $elink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
582 $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
584 $wgOut->addHtml( '</ul>' );
587 function closeShowImage()
594 * If the page we've just displayed is in the "Image" namespace,
595 * we follow it with an upload history of the image and its usage.
597 function imageHistory()
599 global $wgUser, $wgOut, $wgUseExternalEditor;
601 $sk = $wgUser->getSkin();
604 if ( $this->img
->exists() ) {
605 $list = new ImageHistoryList( $sk, $this->img
, $this->displayImg
);
607 $dims = $file->getDimensionsString();
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 $dims = $file->getDimensionsString();
614 $s .= $list->imageHistoryLine( false, $file );
616 $s .= $list->endImageHistoryList();
618 $wgOut->addHTML( $s );
620 $this->img
->resetHistory(); // free db resources
622 # Exist check because we don't want to show this on pages where an image
623 # doesn't exist along with the noimage message, that would suck. -ævar
624 if( $wgUseExternalEditor && $this->img
->exists() ) {
625 $this->uploadLinksBox();
630 function imageLinks()
632 global $wgUser, $wgOut;
636 $dbr = wfGetDB( DB_SLAVE
);
639 array( 'imagelinks', 'page' ),
640 array( 'page_namespace', 'page_title' ),
641 array( 'il_to' => $this->mTitle
->getDBkey(), 'il_from = page_id' ),
643 array( 'LIMIT' => $limit +
1)
646 if ( 0 == $dbr->numRows( $res ) ) {
647 $wgOut->addWikiMsg( 'nolinkstoimage' );
650 $wgOut->addWikiMsg( 'linkstoimage' );
651 $wgOut->addHTML( "<ul class='mw-imagepage-linktoimage'>\n" );
653 $sk = $wgUser->getSkin();
655 while ( $s = $res->fetchObject() ) {
657 if ( $count <= $limit ) {
658 // We have not yet reached the extra one that tells us there is more to fetch
659 $name = Title
::makeTitle( $s->page_namespace
, $s->page_title
);
660 $link = $sk->makeKnownLinkObj( $name, "" );
661 $wgOut->addHTML( "<li>{$link}</li>\n" );
664 $wgOut->addHTML( "</ul>\n" );
667 // Add a links to [[Special:Whatlinkshere]]
668 if ( $count > $limit )
669 $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle
->getPrefixedDBkey() );
672 function imageRedirects()
674 global $wgUser, $wgOut;
676 $redirects = $this->getTitle()->getRedirectsHere( NS_IMAGE
);
677 if ( count( $redirects ) == 0 ) return;
680 $wgOut->addWikiMsg( 'redirectstofile' );
681 $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
683 $sk = $wgUser->getSkin();
684 foreach ( $redirects as $title ) {
685 $link = $sk->makeKnownLinkObj( $title, "" );
686 $wgOut->addHTML( "<li>{$link}</li>\n" );
688 $wgOut->addHTML( "</ul>\n" );
692 function imageDupes() {
693 global $wgOut, $wgUser;
697 $dupes = $this->getDuplicates();
698 if ( count( $dupes ) == 0 ) return;
700 $wgOut->addWikiMsg( 'duplicatesoffile' );
701 $wgOut->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
703 $sk = $wgUser->getSkin();
704 foreach ( $dupes as $file ) {
705 if ( $file->isLocal() )
706 $link = $sk->makeKnownLinkObj( $file->getTitle(), "" );
708 $link = $sk->makeExternalLink( $file->getDescriptionUrl(),
709 $file->getTitle()->getPrefixedText() );
710 $wgOut->addHTML( "<li>{$link}</li>\n" );
712 $wgOut->addHTML( "</ul>\n" );
716 * Delete the file, or an earlier version of it
718 public function delete() {
720 if( !$this->img
->exists() ||
!$this->img
->isLocal() ||
$this->img
->getRedirected() ) {
721 // Standard article deletion
725 $deleter = new FileDeleteForm( $this->img
);
730 * Revert the file to an earlier version
732 public function revert() {
734 $reverter = new FileRevertForm( $this->img
);
735 $reverter->execute();
739 * Override handling of action=purge
743 if( $this->img
->exists() ) {
744 wfDebug( "ImagePage::doPurge purging " . $this->img
->getName() . "\n" );
745 $update = new HTMLCacheUpdate( $this->mTitle
, 'imagelinks' );
747 $this->img
->upgradeRow();
748 $this->img
->purgeCache();
750 wfDebug( "ImagePage::doPurge no image\n" );
756 * Display an error with a wikitext description
758 function showError( $description ) {
760 $wgOut->setPageTitle( wfMsg( "internalerror" ) );
761 $wgOut->setRobotpolicy( "noindex,nofollow" );
762 $wgOut->setArticleRelated( false );
763 $wgOut->enableClientCache( false );
764 $wgOut->addWikiText( $description );
770 * Builds the image revision log shown on image pages
774 class ImageHistoryList
{
776 protected $img, $skin, $title, $repo;
778 public function __construct( $skin, $curimg, $img ) {
780 $this->current
= $curimg;
782 $this->title
= $img->getTitle();
785 public function beginImageHistoryList() {
786 global $wgOut, $wgUser;
787 return Xml
::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
788 . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
789 . Xml
::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
791 . ( $this->current
->isLocal() && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ?
'<td></td>' : '' )
792 . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
793 . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
794 . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
795 . '<th>' . wfMsgHtml( 'filehist-comment' ) . '</th>'
799 public function endImageHistoryList() {
803 public function imageHistoryLine( $iscur, $file ) {
804 global $wgUser, $wgLang, $wgContLang, $wgTitle;
806 $timestamp = wfTimestamp(TS_MW
, $file->getTimestamp());
807 $img = $iscur ?
$file->getName() : $file->getArchiveName();
808 $user = $file->getUser('id');
809 $usertext = $file->getUser('text');
810 $size = $file->getSize();
811 $description = $file->getDescription();
812 $dims = $file->getDimensionsString();
813 $sha1 = $file->getSha1();
815 $local = $this->current
->isLocal();
816 $row = $css = $selected = '';
819 if( $local && ($wgUser->isAllowed('delete') ||
$wgUser->isAllowed('deleterevision') ) ) {
821 # Link to remove from history
822 if( $wgUser->isAllowed( 'delete' ) ) {
824 $q[] = 'action=delete';
826 $q[] = 'oldimage=' . urlencode( $img );
827 $row .= $this->skin
->makeKnownLinkObj(
829 wfMsgHtml( $iscur ?
'filehist-deleteall' : 'filehist-deleteone' ),
833 # Link to hide content
834 if( $wgUser->isAllowed( 'deleterevision' ) ) {
835 if( $wgUser->isAllowed('delete') ) {
838 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
839 // If file is top revision or locked from this user, don't link
840 if( $iscur ||
!$file->userCan(File
::DELETED_RESTRICTED
) ) {
841 $del = wfMsgHtml( 'rev-delundel' );
843 // If the file was hidden, link to sha-1
844 list($ts,$name) = explode('!',$img,2);
845 $del = $this->skin
->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ),
846 'target=' . urlencode( $wgTitle->getPrefixedText() ) .
847 '&oldimage=' . urlencode( $ts ) );
848 // Bolden oversighted content
849 if( $file->isDeleted(File
::DELETED_RESTRICTED
) )
850 $del = "<strong>$del</strong>";
852 $row .= "<tt style='white-space: nowrap;'><small>$del</small></tt>";
857 // Reversion link/current indicator
860 $row .= wfMsgHtml( 'filehist-current' );
861 } elseif( $local && $wgUser->isLoggedIn() && $this->title
->userCan( 'edit' ) ) {
862 if( $file->isDeleted(File
::DELETED_FILE
) ) {
863 $row .= wfMsgHtml('filehist-revert');
866 $q[] = 'action=revert';
867 $q[] = 'oldimage=' . urlencode( $img );
868 $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
869 $row .= $this->skin
->makeKnownLinkObj( $this->title
,
870 wfMsgHtml( 'filehist-revert' ),
871 implode( '&', $q ) );
876 // Date/time and image link
877 if( $file->getTimestamp() === $this->img
->getTimestamp() ) {
878 $selected = "class='filehistory-selected'";
880 $row .= "<td $selected style='white-space: nowrap;'>";
881 if( !$file->userCan(File
::DELETED_FILE
) ) {
882 # Don't link to unviewable files
883 $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
884 } else if( $file->isDeleted(File
::DELETED_FILE
) ) {
885 $revdel = SpecialPage
::getTitleFor( 'Revisiondelete' );
886 # Make a link to review the image
887 $url = $this->skin
->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ),
888 "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current
->getExtension() );
889 $row .= '<span class="history-deleted">'.$url.'</span>';
891 $url = $iscur ?
$this->current
->getUrl() : $this->current
->getArchiveUrl( $img );
892 $row .= Xml
::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
898 $row .= htmlspecialchars( $dims );
901 $row .= " <span style='white-space: nowrap;'>(" . $this->skin
->formatSize( $size ) . ')</span>';
906 // Hide deleted usernames
907 if( $file->isDeleted(File
::DELETED_USER
) ) {
908 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
910 $row .= $this->skin
->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
911 $this->skin
->userToolLinks( $user, $usertext ) . "</span>";
914 $row .= htmlspecialchars( $usertext );
918 // Don't show deleted descriptions
919 if ( $file->isDeleted(File
::DELETED_COMMENT
) ) {
920 $row .= '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
922 $row .= $this->skin
->commentBlock( $description, $this->title
);
926 wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
927 $trCSS = $css ?
" class='$css'" : "";
929 return "<tr{$trCSS}>{$row}</tr>\n";