63 $this->displayImg =
$file;
64 $this->fileLoaded =
true;
68 if ( $this->fileLoaded ) {
71 $this->fileLoaded =
true;
73 $this->displayImg = $img =
false;
75 $this->getHookRunner()->onImagePageFindFile( $this, $img, $this->displayImg );
77 $services = MediaWikiServices::getInstance();
78 $img = $services->getRepoGroup()->findFile( $this->
getTitle() );
80 $img = $services->getRepoGroup()->getLocalRepo()->newFile( $this->
getTitle() );
83 $this->
getPage()->setFile( $img );
84 if ( !$this->displayImg ) {
85 $this->displayImg = $img;
87 $this->repo = $img->getRepo();
94 if ( $this->viewIsRenderAction ) {
101 $diff = $request->getVal(
'diff' );
102 $diffOnly = $request->getBool(
107 if ( $this->
getTitle()->getNamespace() !==
NS_FILE || ( $diff !==
null && $diffOnly ) ) {
116 && $this->
getFile()->getRedirected()
122 $request->setVal(
'diffonly',
'true' );
129 if (
$wgShowEXIF && $this->displayImg->exists() ) {
131 $formattedMetadata = $this->displayImg->formatMetadata( $this->
getContext() );
133 $formattedMetadata =
false;
136 if ( !$diff && $this->displayImg->exists() ) {
137 $out->addHTML( $this->
showTOC( (
bool)$formattedMetadata ) );
144 # No need to display noarticletext, we use our own message, output in openShowImage()
146 # NS_FILE is in the user language, but this section (the actual wikitext)
147 # should be in page content language
148 $pageLang = $this->
getTitle()->getPageViewLanguage();
150 'lang' => $pageLang->getHtmlCode(),
'dir' => $pageLang->getDir(),
151 'class' =>
'mw-content-' . $pageLang->getDir() ] ) );
157 # Just need to set the right headers
158 $out->setArticleFlag(
true );
159 $out->setPageTitle( $this->
getTitle()->getPrefixedText() );
160 $this->
getPage()->doViewUpdates(
166 # Show shared description, if needed
167 if ( $this->mExtraDescription ) {
168 $fol = $this->
getContext()->msg(
'shareddescriptionfollows' );
169 if ( !$fol->isDisabled() ) {
170 $out->addWikiTextAsInterface( $fol->plain() );
172 $out->addHTML(
'<div id="shared-image-desc">' . $this->mExtraDescription .
"</div>\n" );
180 [
'id' =>
'filelinks' ],
181 $this->
getContext()->msg(
'imagelinks' )->text() ) .
"\n" );
183 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
184 # Yet we return metadata about the target. Definitely an issue in the FileRepo
187 # Allow extensions to add something after the image links
189 $this->getHookRunner()->onImagePageAfterImageLinks( $this, $html );
191 $out->addHTML( $html );
194 if ( $formattedMetadata ) {
197 [
'id' =>
'metadata' ],
198 $this->
getContext()->msg(
'metadata' )->text() ) .
"\n" );
199 $out->wrapWikiTextAsInterface(
200 'mw-imagepage-section-metadata',
203 $out->addModules( [
'mediawiki.action.view.metadata' ] );
207 if ( !$this->repo->isLocal() ) {
208 $css = $this->repo->getDescriptionStylesheetUrl();
210 $out->addStyle( $css );
214 $out->addModuleStyles( [
216 'mediawiki.action.view.filepage',
236 '<li><a href="#file">' . $this->
getContext()->msg(
'file-anchor-link' )->escaped() .
'</a></li>',
237 '<li><a href="#filehistory">' . $this->
getContext()->msg(
'filehist' )->escaped() .
'</a></li>',
238 '<li><a href="#filelinks">' . $this->
getContext()->msg(
'imagelinks' )->escaped() .
'</a></li>',
241 $this->getHookRunner()->onImagePageShowTOC( $this, $r );
244 $r[] =
'<li><a href="#metadata">' .
245 $this->
getContext()->msg(
'metadata' )->escaped() .
249 return '<ul id="filetoc">' . implode(
"\n", $r ) .
'</ul>';
261 $r = $this->
getContext()->msg(
'metadata-help' )->plain();
264 $r .=
"<table id=\"mw_metadata\" class=\"mw_metadata collapsed\">\n";
265 foreach ( $metadata as
$type => $stuff ) {
266 foreach ( $stuff as $v ) {
267 $class = str_replace(
' ',
'_', $v[
'id'] );
268 if (
$type ==
'collapsed' ) {
269 $class .=
' mw-metadata-collapsible';
272 [
'class' => $class ],
291 $handler =
$file->getHandler();
296 $config = MediaWikiServices::getInstance()->getMainConfig();
297 $requestLanguage = $request->
getVal(
'lang', $config->get(
'LanguageCode' ) );
298 if ( $handler->validateParam(
'lang', $requestLanguage ) ) {
299 return $file->getMatchedLanguage( $requestLanguage );
302 return $handler->getDefaultRenderLanguage(
$file );
312 $dirmark =
$lang->getDirMarkEntity();
315 if ( $this->displayImg->exists() ) {
319 $page = $request->getIntOrNull(
'page' );
320 if ( $page ===
null ) {
324 $params = [
'page' => $page ];
328 if ( $renderLang !==
null ) {
329 $params[
'lang'] = $renderLang;
332 $width_orig = $this->displayImg->getWidth( $page );
333 $width = $width_orig;
334 $height_orig = $this->displayImg->getHeight( $page );
335 $height = $height_orig;
338 $linktext = $filename;
340 $this->getHookRunner()->onImageOpenShowImageInlineBefore( $this, $out );
342 if ( $this->displayImg->allowInlineDisplay() ) {
344 # "Download high res version" link below the image
345 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
346 # Language::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
347 # We'll show a thumbnail of this image
348 if ( $width > $maxWidth ||
349 $height > $maxHeight ||
350 $this->displayImg->isVectorized()
352 list( $width, $height ) = $this->displayImg->getDisplayWidthHeight(
353 $maxWidth, $maxHeight, $page
355 $linktext = $this->
getContext()->msg(
'show-big-image' )->escaped();
357 $thumbSizes = $this->
getThumbSizes( $width_orig, $height_orig );
358 # Generate thumbnails or thumbnail links as needed...
360 foreach ( $thumbSizes as $size ) {
369 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
370 || ( $this->displayImg->isVectorized()
373 && $size[0] != $width && $size[1] != $height
375 $sizeLink = $this->
makeSizeLink( $params, $size[0], $size[1] );
377 $otherSizes[] = $sizeLink;
381 $otherSizes = array_unique( $otherSizes );
383 $sizeLinkBigImagePreview = $this->
makeSizeLink( $params, $width, $height );
385 if ( count( $otherSizes ) ) {
389 [
'class' =>
'mw-filepage-other-resolutions' ],
390 $this->
getContext()->msg(
'show-big-image-other' )
391 ->rawParams(
$lang->pipeList( $otherSizes ) )
392 ->params( count( $otherSizes ) )
396 } elseif ( $width == 0 && $height == 0 ) {
397 # Some sort of audio file that doesn't have dimensions
398 # Don't output a no hi res message for such a file
401 # Image is small enough to show full size on image page
402 $msgsmall = $this->
getContext()->msg(
'file-nohires' )->parse();
405 $params[
'width'] = $width;
406 $params[
'height'] = $height;
409 $params[
'imagePageParams'] = $request->getQueryValuesOnly();
410 $thumbnail = $this->displayImg->transform( $params );
415 [
'class' =>
'mw-filepage-resolutioninfo' ],
419 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
421 $out->addModules(
'mediawiki.page.image.pagination' );
422 $out->addHTML(
'<table class="multipageimage"><tr><td>' );
427 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
430 $out->addHTML(
'<div class="fullImageLink" id="file">' .
431 $thumbnail->toHtml( $options ) .
432 $anchorclose .
"</div>\n" );
436 $count = $this->displayImg->pageCount();
437 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
440 $label = $this->
getContext()->msg(
'imgmultipageprev' )->text();
447 [
'page' => $page - 1 ]
456 [
'page' => $page - 1 ]
462 if ( $page < $count ) {
463 $label = $this->
getContext()->msg(
'imgmultipagenext' )->text();
468 [
'page' => $page + 1 ]
477 [
'page' => $page + 1 ]
486 'name' =>
'pageselector',
490 for ( $i = 1; $i <= $count; $i++ ) {
494 [
'id' =>
'pageselector',
'name' =>
'page' ],
495 implode(
"\n", $options ) );
498 '</td><td><div class="multipageimagenavbox">' .
501 $this->
getContext()->msg(
'imgmultigoto' )->rawParams( $select )->parse() .
502 $this->
getContext()->msg(
'word-separator' )->escaped() .
505 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
508 } elseif ( $this->displayImg->isSafeFile() ) {
509 # if direct link is allowed but it's not a renderable image, show an icon.
510 $icon = $this->displayImg->iconThumb();
512 $out->addHTML(
'<div class="fullImageLink" id="file">' .
513 $icon->toHtml( [
'file-link' =>
true ] ) .
517 $longDesc = $this->
getContext()->msg(
'parentheses', $this->displayImg->getLongDesc() )->text();
519 $handler = $this->displayImg->getHandler();
523 $warningConfig = $handler->getWarningConfig( $this->displayImg );
525 if ( $warningConfig !==
null ) {
529 $output->addJsConfigVars(
'wgFileWarning', $warningConfig );
530 $output->addModules( $warningConfig[
'module'] );
531 $output->addModules(
'mediawiki.filewarning' );
535 $medialink =
"[[Media:$filename|$linktext]]";
537 if ( !$this->displayImg->isSafeFile() ) {
538 $warning = $this->
getContext()->msg(
'mediawarning' )->plain();
547 $out->wrapWikiTextAsInterface(
'fullMedia', <<<EOT
548 <span
class=
"dangerousLink">{$medialink}</span> $dirmark<span
class=
"fileInfo">$longDesc</span>
552 $out->wrapWikiTextAsInterface(
'mediaWarning', $warning );
554 $out->wrapWikiTextAsInterface(
'fullMedia', <<<EOT
555 {$medialink} {$dirmark}<span
class=
"fileInfo">$longDesc</span>
560 $renderLangOptions = $this->displayImg->getAvailableLanguages();
561 if ( count( $renderLangOptions ) >= 1 ) {
562 $out->addHTML( $this->
doRenderLangOpt( $renderLangOptions, $renderLang ) );
566 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
572 $ext = $this->displayImg->getExtension();
574 'file-no-thumb-animation-' .
$ext,
575 'file-no-thumb-animation'
578 $out->wrapWikiTextAsInterface(
'mw-noanimatethumb', $noAnimMesg );
581 if ( !$this->displayImg->isLocal() ) {
585 # Image does not exist
589 # No article exists either
590 # Show deletion log to be consistent with normal articles
593 [
'delete',
'move',
'protect' ],
594 $this->
getTitle()->getPrefixedText(),
597 'conds' => [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ],
598 'showIfEmpty' =>
false,
599 'msgKey' => [
'moveddeleted-notice' ]
606 ->userHasRight( $user,
'upload' )
611 'filepage-nofile-link',
612 $uploadTitle->getFullURL( [
613 'wpDestFile' => $this->
getFile()->getName()
617 $nofile =
'filepage-nofile';
622 $out->setRobotPolicy(
'noindex,nofollow' );
623 $out->wrapWikiMsg(
"<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
627 $request->response()->statusHeader( 404 );
630 $out->setFileVersion( $this->displayImg );
641 if ( $sizeLinkBigImagePreview ) {
643 $previewTypeDiffers =
false;
644 $origExt = $thumbExt = $this->displayImg->getExtension();
645 if ( $this->displayImg->getHandler() ) {
646 $origMime = $this->displayImg->getMimeType();
647 $typeParams = $params;
648 $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
649 list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
650 $origExt, $origMime, $typeParams );
651 if ( $thumbMime !== $origMime ) {
652 $previewTypeDiffers =
true;
655 if ( $previewTypeDiffers ) {
656 return $this->
getContext()->msg(
'show-big-image-preview-differ' )->
657 rawParams( $sizeLinkBigImagePreview )->
658 params( strtoupper( $origExt ) )->
659 params( strtoupper( $thumbExt ) )->
662 return $this->
getContext()->msg(
'show-big-image-preview' )->
663 rawParams( $sizeLinkBigImagePreview )->
679 $params[
'width'] = $width;
680 $params[
'height'] = $height;
681 $thumbnail = $this->displayImg->transform( $params );
682 if ( $thumbnail && !$thumbnail->isError() ) {
684 'href' => $thumbnail->getUrl(),
685 'class' =>
'mw-thumbnail-link'
686 ], $this->getContext()->msg(
'show-big-image-size' )->numParams(
687 $thumbnail->getWidth(), $thumbnail->getHeight()
701 $descUrl = $this->
getFile()->getDescriptionUrl();
702 $descText = $this->
getFile()->getDescriptionText( $this->
getContext()->getLanguage() );
706 $out->setCanonicalUrl( $descUrl );
709 $wrap =
"<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
714 $this->
getContext()->msg(
'sharedupload-desc-here' )->plain() !==
'-'
716 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-here',
$repo, $descUrl ] );
717 } elseif ( $descUrl &&
718 $this->
getContext()->msg(
'sharedupload-desc-there' )->plain() !==
'-'
720 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-there',
$repo, $descUrl ] );
722 $out->wrapWikiMsg( $wrap, [
'sharedupload',
$repo ],
'' );
726 $this->mExtraDescription = $descText;
733 return $uploadTitle->getFullURL( [
734 'wpDestFile' => $this->
getFile()->getName(),
743 if ( !$this->
getContext()->getConfig()->
get(
'EnableUploads' ) ) {
752 $canUpload = MediaWikiServices::getInstance()->getPermissionManager()
761 $this->
getContext()->msg(
'uploadnewversion-linktext' )->text()
763 $attrs = [
'class' =>
'plainlinks',
'id' =>
'mw-imagepage-reupload-link' ];
767 $attrs = [
'id' =>
'mw-imagepage-upload-disallowed' ];
768 $msg = $this->
getContext()->msg(
'upload-disallowed-here' )->text();
772 $uploadLinks =
Html::rawElement(
'div', [
'class' =>
'mw-imagepage-upload-links' ], $linkPara );
773 $this->
getContext()->getOutput()->addHTML( $uploadLinks );
791 MediaWikiServices::getInstance()->getLinkBatchFactory()
793 $out->addHTML( $pager->getBody() );
794 $out->preventClickjacking( $pager->getPreventClickjacking() );
796 $this->
getFile()->resetHistory();
798 # Exist check because we don't want to show this on pages where an image
799 # doesn't exist along with the noimage message, that would suck. -ævar
814 [
'imagelinks',
'page' ],
815 [
'page_namespace',
'page_title',
'il_to' ],
816 [
'il_to' => $target,
'il_from = page_id' ],
818 [
'LIMIT' => $limit + 1,
'ORDER BY' =>
'il_from', ]
830 $redirects[$redir->getDBkey()] = [];
833 'page_title' => $redir->getDBkey(),
838 foreach (
$res as $row ) {
841 $count = count( $rows );
843 $hasMore = $count > $limit;
844 if ( !$hasMore && count( $redirects ) ) {
846 $limit - count( $rows ) + 1 );
847 foreach (
$res as $row ) {
848 $redirects[$row->il_to][] = $row;
851 $hasMore = (
$res->numRows() + count( $rows ) ) > $limit;
857 [
'id' =>
'mw-imagepage-nolinkstoimage' ],
"\n$1\n" ),
863 $out->addHTML(
"<div id='mw-imagepage-section-linkstoimage'>\n" );
865 $out->addWikiMsg(
'linkstoimage', $count );
868 $out->addWikiMsg(
'linkstoimage-more',
869 $this->
getContext()->getLanguage()->formatNum( $limit ),
870 $this->
getTitle()->getPrefixedDBkey()
876 [
'class' =>
'mw-imagepage-linkstoimage' ] ) .
"\n"
879 usort( $rows, [ $this,
'compare' ] );
881 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
885 foreach ( $rows as $element ) {
887 if ( $currentCount > $limit ) {
892 # Add a redirect=no to make redirect pages reachable
893 if ( isset( $redirects[$element->page_title] ) ) {
894 $query[
'redirect'] =
'no';
900 if ( !isset( $redirects[$element->page_title] ) ) {
903 } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
904 # Redirect without usages
905 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )
906 ->rawParams( $link,
'' )
909 # Redirect with usages
911 foreach ( $redirects[$element->page_title] as $row ) {
913 if ( $currentCount > $limit ) {
921 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
928 [
'class' =>
'mw-imagepage-redirectstofile' ],
931 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )->rawParams(
932 $link,
$ul )->parse();
936 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
946 if ( $currentCount > $limit ) {
947 $out->addWikiMsg(
'morelinkstoimage', $this->
getTitle()->getPrefixedDBkey() );
956 $dupes = $this->
getPage()->getDuplicates();
957 if ( count( $dupes ) == 0 ) {
961 $out->addHTML(
"<div id='mw-imagepage-section-duplicates'>\n" );
962 $out->addWikiMsg(
'duplicatesoffile',
963 $this->
getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->
getTitle()->getDBkey()
965 $out->addHTML(
"<ul class='mw-imagepage-duplicates'>\n" );
967 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
972 foreach ( $dupes as
$file ) {
974 if (
$file->isLocal() ) {
978 $file->getTitle()->getPrefixedText() );
981 $file->getRepo()->getDisplayName()
984 $out->addHTML(
"<li>{$link} {$fromSrc}</li>\n" );
986 $out->addHTML(
"</ul></div>\n" );
992 public function delete() {
994 if ( !
$file->exists() || !
$file->isLocal() ||
$file->getRedirected() ) {
999 '@phan-var LocalFile $file';
1004 $context->getUser(),
1005 $context->getOutput()
1007 $deleter->execute();
1017 $out->setPageTitle( $this->
getContext()->msg(
'internalerror' ) );
1018 $out->setRobotPolicy(
'noindex,nofollow' );
1019 $out->setArticleRelated(
false );
1020 $out->enableClientCache(
false );
1021 $out->addWikiTextAsInterface( $description );
1033 return $a->page_namespace <=> $b->page_namespace
1034 ?: strcmp( $a->page_title, $b->page_title );
1047 return MediaFileTrait::getImageLimitsFromOption( $user, $optionName );
1061 $matchedRenderLang = $this->displayImg->getMatchedLanguage( $renderLang );
1063 foreach ( $langChoices as
$lang ) {
1066 $matchedRenderLang ===
$lang
1074 $this->
getContext()->msg(
'img-lang-default' )->text(),
1076 $matchedRenderLang ===
null
1081 [
'id' =>
'mw-imglangselector',
'name' =>
'lang' ],
1086 $formContents = $this->
getContext()->msg(
'img-lang-info' )
1087 ->rawParams( $select, $submit )
1091 $langSelectLine =
Html::rawElement(
'div', [
'id' =>
'mw-imglangselector-line' ],
1094 return $langSelectLine;
1104 $name = MediaWikiServices::getInstance()
1105 ->getLanguageNameUtils()
1106 ->getLanguageName( $code, $this->
getContext()->getLanguage()->getCode() );
1107 if ( $name !==
'' ) {
1108 $display = $this->
getContext()->msg(
'img-lang-opt', $code, $name )->text();
1131 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1139 $thumbSizes[] = [ $origWidth, $origHeight ];
1141 # Creating thumb links triggers thumbnail generation.
1142 # Just generate the thumb for the current users prefs.
1146 if ( !$this->displayImg->mustRender() ) {
1149 $thumbSizes[] = [ $origWidth, $origHeight ];
1160 return $this->
getPage()->getFile();
1168 return $this->
getPage()->isLocal();
1176 return $this->
getPage()->getDuplicates();
1184 return $this->
getPage()->getForeignCategories();