61 $this->mPage->setFile(
$file );
62 $this->displayImg =
$file;
63 $this->fileLoaded =
true;
67 if ( $this->fileLoaded ) {
70 $this->fileLoaded =
true;
72 $this->displayImg = $img =
false;
74 Hooks::run(
'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
76 $services = MediaWikiServices::getInstance();
77 $img = $services->getRepoGroup()->findFile( $this->
getTitle() );
79 $img = $services->getRepoGroup()->getLocalRepo()->newFile( $this->
getTitle() );
82 $this->mPage->setFile( $img );
83 if ( !$this->displayImg ) {
84 $this->displayImg = $img;
86 $this->repo = $img->getRepo();
93 if ( $this->viewIsRenderAction ) {
100 $diff = $request->getVal(
'diff' );
101 $diffOnly = $request->getBool(
106 if ( $this->
getTitle()->getNamespace() !=
NS_FILE || ( $diff !==
null && $diffOnly ) ) {
113 if ( $this->
getTitle()->getNamespace() ==
NS_FILE && $this->mPage->getFile()->getRedirected() ) {
114 if ( $this->
getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) {
115 $request->setVal(
'diffonly',
'true' );
122 if (
$wgShowEXIF && $this->displayImg->exists() ) {
124 $formattedMetadata = $this->displayImg->formatMetadata( $this->
getContext() );
125 $showmeta = $formattedMetadata !==
false;
130 if ( !$diff && $this->displayImg->exists() ) {
131 $out->addHTML( $this->
showTOC( $showmeta ) );
138 # No need to display noarticletext, we use our own message, output in openShowImage()
139 if ( $this->mPage->getId() ) {
140 # NS_FILE is in the user language, but this section (the actual wikitext)
141 # should be in page content language
142 $pageLang = $this->
getTitle()->getPageViewLanguage();
144 'lang' => $pageLang->getHtmlCode(),
'dir' => $pageLang->getDir(),
145 'class' =>
'mw-content-' . $pageLang->getDir() ] ) );
151 # Just need to set the right headers
152 $out->setArticleFlag(
true );
153 $out->setPageTitle( $this->
getTitle()->getPrefixedText() );
157 # Show shared description, if needed
158 if ( $this->mExtraDescription ) {
159 $fol = $this->
getContext()->msg(
'shareddescriptionfollows' );
160 if ( !$fol->isDisabled() ) {
161 $out->addWikiTextAsInterface( $fol->plain() );
163 $out->addHTML(
'<div id="shared-image-desc">' . $this->mExtraDescription .
"</div>\n" );
171 [
'id' =>
'filelinks' ],
172 $this->
getContext()->msg(
'imagelinks' )->text() ) .
"\n" );
174 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
175 # Yet we return metadata about the target. Definitely an issue in the FileRepo
178 # Allow extensions to add something after the image links
180 Hooks::run(
'ImagePageAfterImageLinks', [ $this, &$html ] );
182 $out->addHTML( $html );
188 [
'id' =>
'metadata' ],
189 $this->
getContext()->msg(
'metadata' )->text() ) .
"\n" );
190 $out->wrapWikiTextAsInterface(
191 'mw-imagepage-section-metadata',
194 $out->addModules( [
'mediawiki.action.view.metadata' ] );
198 if ( !$this->repo->isLocal() ) {
199 $css = $this->repo->getDescriptionStylesheetUrl();
201 $out->addStyle( $css );
205 $out->addModuleStyles( [
207 'mediawiki.action.view.filepage',
227 '<li><a href="#file">' . $this->
getContext()->msg(
'file-anchor-link' )->escaped() .
'</a></li>',
228 '<li><a href="#filehistory">' . $this->
getContext()->msg(
'filehist' )->escaped() .
'</a></li>',
229 '<li><a href="#filelinks">' . $this->
getContext()->msg(
'imagelinks' )->escaped() .
'</a></li>',
232 Hooks::run(
'ImagePageShowTOC', [ $this, &$r ] );
235 $r[] =
'<li><a href="#metadata">' .
236 $this->
getContext()->msg(
'metadata' )->escaped() .
240 return '<ul id="filetoc">' . implode(
"\n", $r ) .
'</ul>';
252 $r = $this->
getContext()->msg(
'metadata-help' )->plain();
255 $r .=
"<table id=\"mw_metadata\" class=\"mw_metadata collapsed\">\n";
256 foreach ( $metadata as
$type => $stuff ) {
257 foreach ( $stuff as $v ) {
258 $class = str_replace(
' ',
'_', $v[
'id'] );
259 if (
$type ==
'collapsed' ) {
260 $class .=
' mw-metadata-collapsible';
262 $r .= Html::rawElement(
'tr',
263 [
'class' => $class ],
264 Html::rawElement(
'th', [], $v[
'name'] )
265 . Html::rawElement(
'td', [], $v[
'value'] )
284 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && $this->
getId() == 0 ) {
287 return parent::getEmptyPageParserOutput( $options );
299 $handler =
$file->getHandler();
304 $config = MediaWikiServices::getInstance()->getMainConfig();
305 $requestLanguage = $request->
getVal(
'lang', $config->get(
'LanguageCode' ) );
306 if ( $handler->validateParam(
'lang', $requestLanguage ) ) {
307 return $file->getMatchedLanguage( $requestLanguage );
310 return $handler->getDefaultRenderLanguage(
$file );
320 $dirmark =
$lang->getDirMarkEntity();
325 if ( $this->displayImg->exists() ) {
327 $page = $request->getIntOrNull(
'page' );
328 if ( is_null( $page ) ) {
332 $params = [
'page' => $page ];
336 if ( !is_null( $renderLang ) ) {
337 $params[
'lang'] = $renderLang;
340 $width_orig = $this->displayImg->getWidth( $page );
341 $width = $width_orig;
342 $height_orig = $this->displayImg->getHeight( $page );
343 $height = $height_orig;
346 $linktext = $filename;
351 Hooks::run(
'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
353 if ( $this->displayImg->allowInlineDisplay() ) {
355 # "Download high res version" link below the image
356 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
357 # Language::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
358 # We'll show a thumbnail of this image
359 if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
361 $maxWidth, $maxHeight, $width, $height
363 $linktext = $this->
getContext()->msg(
'show-big-image' )->escaped();
365 $thumbSizes = $this->
getThumbSizes( $width_orig, $height_orig );
366 # Generate thumbnails or thumbnail links as needed...
368 foreach ( $thumbSizes as $size ) {
377 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
378 || ( $this->displayImg->isVectorized()
381 && $size[0] != $width && $size[1] != $height
383 $sizeLink = $this->
makeSizeLink( $params, $size[0], $size[1] );
385 $otherSizes[] = $sizeLink;
389 $otherSizes = array_unique( $otherSizes );
391 $sizeLinkBigImagePreview = $this->
makeSizeLink( $params, $width, $height );
393 if ( count( $otherSizes ) ) {
397 [
'class' =>
'mw-filepage-other-resolutions' ],
398 $this->
getContext()->msg(
'show-big-image-other' )
399 ->rawParams(
$lang->pipeList( $otherSizes ) )
400 ->params( count( $otherSizes ) )
404 } elseif ( $width == 0 && $height == 0 ) {
405 # Some sort of audio file that doesn't have dimensions
406 # Don't output a no hi res message for such a file
409 # Image is small enough to show full size on image page
410 $msgsmall = $this->
getContext()->msg(
'file-nohires' )->parse();
413 $params[
'width'] = $width;
414 $params[
'height'] = $height;
415 $thumbnail = $this->displayImg->transform( $params );
418 $anchorclose = Html::rawElement(
420 [
'class' =>
'mw-filepage-resolutioninfo' ],
424 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
426 $out->addModules(
'mediawiki.page.image.pagination' );
427 $out->addHTML(
'<table class="multipageimage"><tr><td>' );
432 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
435 $out->addHTML(
'<div class="fullImageLink" id="file">' .
436 $thumbnail->toHtml( $options ) .
437 $anchorclose .
"</div>\n" );
441 $count = $this->displayImg->pageCount();
444 $label = $this->
getContext()->msg(
'imgmultipageprev' )->text();
449 htmlspecialchars( $label ),
451 [
'page' => $page - 1 ]
459 [
'page' => $page - 1 ]
465 if ( $page < $count ) {
466 $label = $this->
getContext()->msg(
'imgmultipagenext' )->text();
469 htmlspecialchars( $label ),
471 [
'page' => $page + 1 ]
479 [
'page' => $page + 1 ]
488 'name' =>
'pageselector',
492 for ( $i = 1; $i <= $count; $i++ ) {
496 [
'id' =>
'pageselector',
'name' =>
'page' ],
497 implode(
"\n", $options ) );
500 '</td><td><div class="multipageimagenavbox">' .
502 Html::hidden(
'title', $this->
getTitle()->getPrefixedDBkey() ) .
503 $this->
getContext()->msg(
'imgmultigoto' )->rawParams( $select )->parse() .
504 $this->
getContext()->msg(
'word-separator' )->escaped() .
507 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
510 } elseif ( $this->displayImg->isSafeFile() ) {
511 # if direct link is allowed but it's not a renderable image, show an icon.
512 $icon = $this->displayImg->iconThumb();
514 $out->addHTML(
'<div class="fullImageLink" id="file">' .
515 $icon->toHtml( [
'file-link' =>
true ] ) .
519 $longDesc = $this->
getContext()->msg(
'parentheses', $this->displayImg->getLongDesc() )->text();
521 $handler = $this->displayImg->getHandler();
525 $warningConfig = $handler->getWarningConfig( $this->displayImg );
527 if ( $warningConfig !==
null ) {
531 $output->addJsConfigVars(
'wgFileWarning', $warningConfig );
532 $output->addModules( $warningConfig[
'module'] );
533 $output->addModules(
'mediawiki.filewarning' );
537 $medialink =
"[[Media:$filename|$linktext]]";
539 if ( !$this->displayImg->isSafeFile() ) {
540 $warning = $this->
getContext()->msg(
'mediawarning' )->plain();
549 $out->wrapWikiTextAsInterface(
'fullMedia', <<<EOT
550 <span
class=
"dangerousLink">{$medialink}</span> $dirmark<span
class=
"fileInfo">$longDesc</span>
554 $out->wrapWikiTextAsInterface(
'mediaWarning', $warning );
556 $out->wrapWikiTextAsInterface(
'fullMedia', <<<EOT
557 {$medialink} {$dirmark}<span
class=
"fileInfo">$longDesc</span>
562 $renderLangOptions = $this->displayImg->getAvailableLanguages();
563 if ( count( $renderLangOptions ) >= 1 ) {
564 $out->addHTML( $this->
doRenderLangOpt( $renderLangOptions, $renderLang ) );
568 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
574 $ext = $this->displayImg->getExtension();
576 'file-no-thumb-animation-' .
$ext,
577 'file-no-thumb-animation'
580 $out->wrapWikiTextAsInterface(
'mw-noanimatethumb', $noAnimMesg );
583 if ( !$this->displayImg->isLocal() ) {
587 # Image does not exist
588 if ( !$this->
getId() ) {
591 # No article exists either
592 # Show deletion log to be consistent with normal articles
595 [
'delete',
'move',
'protect' ],
596 $this->
getTitle()->getPrefixedText(),
599 'conds' => [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ],
600 'showIfEmpty' =>
false,
601 'msgKey' => [
'moveddeleted-notice' ]
607 ->getPermissionManager()
608 ->userHasRight( $user,
'upload' )
613 'filepage-nofile-link',
614 $uploadTitle->getFullURL( [
'wpDestFile' => $this->mPage->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 );
624 if ( !$this->
getId() && $wgSend404Code ) {
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() ) {
683 return Html::rawElement(
'a', [
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->mPage->getFile()->getDescriptionUrl();
702 $descText = $this->mPage->getFile()->getDescriptionText( $this->
getContext()->getLanguage() );
705 if ( $descUrl && $this->mPage->getId() == 0 ) {
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->mPage->getFile()->getName(),
743 if ( !$this->
getContext()->getConfig()->
get(
'EnableUploads' ) ) {
748 if ( !$this->mPage->getFile()->isLocal() ) {
752 $canUpload = MediaWikiServices::getInstance()->getPermissionManager()
754 if ( $canUpload && UploadBase::userCanReUpload(
756 $this->mPage->getFile() )
761 $this->
getContext()->msg(
'uploadnewversion-linktext' )->text()
763 $attrs = [
'class' =>
'plainlinks',
'id' =>
'mw-imagepage-reupload-link' ];
764 $linkPara = Html::rawElement(
'p', $attrs, $ulink );
767 $attrs = [
'id' =>
'mw-imagepage-upload-disallowed' ];
768 $msg = $this->
getContext()->msg(
'upload-disallowed-here' )->text();
769 $linkPara = Html::element(
'p', $attrs, $msg );
772 $uploadLinks = Html::rawElement(
'div', [
'class' =>
'mw-imagepage-upload-links' ], $linkPara );
773 $this->
getContext()->getOutput()->addHTML( $uploadLinks );
790 $out->addHTML( $pager->getBody() );
791 $out->preventClickjacking( $pager->getPreventClickjacking() );
793 $this->mPage->getFile()->resetHistory();
795 # Exist check because we don't want to show this on pages where an image
796 # doesn't exist along with the noimage message, that would suck. -ævar
797 if ( $this->mPage->getFile()->exists() ) {
811 [
'imagelinks',
'page' ],
812 [
'page_namespace',
'page_title',
'il_to' ],
813 [
'il_to' => $target,
'il_from = page_id' ],
815 [
'LIMIT' => $limit + 1,
'ORDER BY' =>
'il_from', ]
827 $redirects[$redir->getDBkey()] = [];
830 'page_title' => $redir->getDBkey(),
835 foreach (
$res as $row ) {
838 $count = count( $rows );
840 $hasMore = $count > $limit;
841 if ( !$hasMore && count( $redirects ) ) {
843 $limit - count( $rows ) + 1 );
844 foreach (
$res as $row ) {
845 $redirects[$row->il_to][] = $row;
848 $hasMore = (
$res->numRows() + count( $rows ) ) > $limit;
853 Html::rawElement(
'div',
854 [
'id' =>
'mw-imagepage-nolinkstoimage' ],
"\n$1\n" ),
860 $out->addHTML(
"<div id='mw-imagepage-section-linkstoimage'>\n" );
862 $out->addWikiMsg(
'linkstoimage', $count );
865 $out->addWikiMsg(
'linkstoimage-more',
866 $this->
getContext()->getLanguage()->formatNum( $limit ),
867 $this->
getTitle()->getPrefixedDBkey()
872 Html::openElement(
'ul',
873 [
'class' =>
'mw-imagepage-linkstoimage' ] ) .
"\n"
878 usort( $rows, [ $this,
'compare' ] );
882 foreach ( $rows as $element ) {
884 if ( $currentCount > $limit ) {
889 # Add a redirect=no to make redirect pages reachable
890 if ( isset( $redirects[$element->page_title] ) ) {
891 $query[
'redirect'] =
'no';
897 if ( !isset( $redirects[$element->page_title] ) ) {
900 } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
901 # Redirect without usages
902 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )
903 ->rawParams( $link,
'' )
906 # Redirect with usages
908 foreach ( $redirects[$element->page_title] as $row ) {
910 if ( $currentCount > $limit ) {
915 $li .= Html::rawElement(
917 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
922 $ul = Html::rawElement(
924 [
'class' =>
'mw-imagepage-redirectstofile' ],
927 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )->rawParams(
928 $link,
$ul )->parse();
930 $out->addHTML( Html::rawElement(
932 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
938 $out->addHTML( Html::closeElement(
'ul' ) .
"\n" );
942 if ( $count > $limit ) {
943 $out->addWikiMsg(
'morelinkstoimage', $this->
getTitle()->getPrefixedDBkey() );
945 $out->addHTML( Html::closeElement(
'div' ) .
"\n" );
952 $dupes = $this->mPage->getDuplicates();
953 if ( count( $dupes ) == 0 ) {
957 $out->addHTML(
"<div id='mw-imagepage-section-duplicates'>\n" );
958 $out->addWikiMsg(
'duplicatesoffile',
959 $this->
getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->
getTitle()->getDBkey()
961 $out->addHTML(
"<ul class='mw-imagepage-duplicates'>\n" );
966 foreach ( $dupes as
$file ) {
968 if (
$file->isLocal() ) {
972 $file->getTitle()->getPrefixedText() );
975 $file->getRepo()->getDisplayName()
978 $out->addHTML(
"<li>{$link} {$fromSrc}</li>\n" );
980 $out->addHTML(
"</ul></div>\n" );
986 public function delete() {
987 $file = $this->mPage->getFile();
988 if ( !
$file->exists() || !
$file->isLocal() ||
$file->getRedirected() ) {
993 '@phan-var LocalFile $file';
1006 $out->setPageTitle( $this->
getContext()->msg(
'internalerror' ) );
1007 $out->setRobotPolicy(
'noindex,nofollow' );
1008 $out->setArticleRelated(
false );
1009 $out->enableClientCache(
false );
1010 $out->addWikiTextAsInterface( $description );
1022 return $a->page_namespace <=> $b->page_namespace
1023 ?: strcmp( $a->page_title, $b->page_title );
1037 $option = $user->getIntOption( $optionName );
1064 $matchedRenderLang = $this->displayImg->getMatchedLanguage( $renderLang );
1066 foreach ( $langChoices as
$lang ) {
1069 $matchedRenderLang ===
$lang
1077 $this->
getContext()->msg(
'img-lang-default' )->text(),
1079 is_null( $matchedRenderLang )
1082 $select = Html::rawElement(
1084 [
'id' =>
'mw-imglangselector',
'name' =>
'lang' ],
1089 $formContents = $this->
getContext()->msg(
'img-lang-info' )
1090 ->rawParams( $select, $submit )
1092 $formContents .= Html::hidden(
'title', $this->
getTitle()->getPrefixedDBkey() );
1094 $langSelectLine = Html::rawElement(
'div', [
'id' =>
'mw-imglangselector-line' ],
1095 Html::rawElement(
'form', [
'action' =>
$wgScript ], $formContents )
1097 return $langSelectLine;
1108 if ( $name !==
'' ) {
1109 $display = $this->
getContext()->msg(
'img-lang-opt', $code, $name )->text();
1136 if ( !$maxWidth || !$maxHeight ) {
1138 throw new MWException(
'Using a choice from $wgImageLimits that is 0x0' );
1141 if ( !$width || !$height ) {
1145 # Calculate the thumbnail size.
1146 if ( $width <= $maxWidth && $height <= $maxHeight ) {
1148 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1149 # The limiting factor is the width, not the height.
1150 $height = round( $height * $maxWidth / $width );
1152 # Note that $height <= $maxHeight now.
1154 $newwidth = floor( $width * $maxHeight / $height );
1155 $height = round( $height * $newwidth / $width );
1157 # Note that $height <= $maxHeight now, but might not be identical
1158 # because of rounding.
1160 return [ $width, $height ];
1173 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1181 $thumbSizes[] = [ $origWidth, $origHeight ];
1183 # Creating thumb links triggers thumbnail generation.
1184 # Just generate the thumb for the current users prefs.
1188 if ( !$this->displayImg->mustRender() ) {
1191 $thumbSizes[] = [ $origWidth, $origHeight ];
1202 return $this->mPage->getFile();
1210 return $this->mPage->isLocal();
1218 return $this->mPage->getDuplicates();
1226 return $this->mPage->getForeignCategories();