62 $this->mPage->setFile( $file );
63 $this->displayImg = $file;
64 $this->fileLoaded =
true;
68 if ( $this->fileLoaded ) {
71 $this->fileLoaded =
true;
73 $this->displayImg = $img =
false;
75 Hooks::run(
'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
82 $this->mPage->setFile( $img );
83 if ( !$this->displayImg ) {
84 $this->displayImg = $img;
86 $this->repo = $img->getRepo();
94 $this->
getContext()->getOutput()->setArticleBodyOnly(
true );
109 if ( $this->
getTitle()->getNamespace() !=
NS_FILE || ( $diff !==
null && $diffOnly ) ) {
116 if ( $this->
getTitle()->getNamespace() ==
NS_FILE && $this->mPage->getFile()->getRedirected() ) {
117 if ( $this->
getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) {
118 $request->setVal(
'diffonly',
'true' );
125 if (
$wgShowEXIF && $this->displayImg->exists() ) {
127 $formattedMetadata = $this->displayImg->formatMetadata( $this->
getContext() );
128 $showmeta = $formattedMetadata !==
false;
133 if ( !$diff && $this->displayImg->exists() ) {
141 # No need to display noarticletext, we use our own message, output in openShowImage()
142 if ( $this->mPage->getId() ) {
143 # NS_FILE is in the user language, but this section (the actual wikitext)
144 # should be in page content language
145 $pageLang = $this->
getTitle()->getPageViewLanguage();
147 'lang' => $pageLang->getHtmlCode(),
'dir' => $pageLang->getDir(),
148 'class' =>
'mw-content-' . $pageLang->getDir() ] ) );
154 # Just need to set the right headers
155 $out->setArticleFlag(
true );
156 $out->setPageTitle( $this->
getTitle()->getPrefixedText() );
160 # Show shared description, if needed
161 if ( $this->mExtraDescription ) {
162 $fol = $this->
getContext()->msg(
'shareddescriptionfollows' );
163 if ( !$fol->isDisabled() ) {
164 $out->addWikiText( $fol->plain() );
166 $out->addHTML(
'<div id="shared-image-desc">' . $this->mExtraDescription .
"</div>\n" );
174 [
'id' =>
'filelinks' ],
177 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
178 # Yet we return metadata about the target. Definitely an issue in the FileRepo
181 # Allow extensions to add something after the image links
191 [
'id' =>
'metadata' ],
194 $out->addModules( [
'mediawiki.action.view.metadata' ] );
198 if ( !$this->repo->isLocal() ) {
199 $css = $this->repo->getDescriptionStylesheetUrl();
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 =
"<div class=\"mw-imagepage-section-metadata\">";
253 $r .= $this->
getContext()->msg(
'metadata-help' )->plain();
254 $r .=
"<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
255 foreach ( $metadata
as $type => $stuff ) {
256 foreach ( $stuff
as $v ) {
257 $class = str_replace(
' ',
'_', $v[
'id'] );
258 if (
$type ==
'collapsed' ) {
260 $class .=
' collapsable';
263 [
'class' => $class ],
269 $r .=
"</table>\n</div>\n";
282 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->
getId() ) {
285 return parent::getContentObject();
295 $dirmark =
$lang->getDirMarkEntity();
300 $maxHeight = $max[1];
302 if ( $this->displayImg->exists() ) {
304 $page =
$request->getIntOrNull(
'page' );
305 if ( is_null( $page ) ) {
312 $renderLang =
$request->getVal(
'lang' );
313 if ( !is_null( $renderLang ) ) {
314 $handler = $this->displayImg->getHandler();
322 $width_orig = $this->displayImg->getWidth( $page );
323 $width = $width_orig;
324 $height_orig = $this->displayImg->getHeight( $page );
325 $height = $height_orig;
328 $linktext = $filename;
333 Hooks::run(
'ImageOpenShowImageInlineBefore', [ &$imagePage, &
$out ] );
335 if ( $this->displayImg->allowInlineDisplay() ) {
337 # "Download high res version" link below the image
338 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
339 # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
340 # We'll show a thumbnail of this image
341 if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
343 $maxWidth, $maxHeight, $width, $height
345 $linktext = $this->
getContext()->msg(
'show-big-image' )->escaped();
347 $thumbSizes = $this->
getThumbSizes( $width_orig, $height_orig );
348 # Generate thumbnails or thumbnail links as needed...
350 foreach ( $thumbSizes
as $size ) {
359 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
360 || ( $this->displayImg->isVectorized()
363 && $size[0] != $width && $size[1] != $height
367 $otherSizes[] = $sizeLink;
371 $otherSizes = array_unique( $otherSizes );
375 if (
count( $otherSizes ) ) {
379 [
'class' =>
'mw-filepage-other-resolutions' ],
380 $this->
getContext()->msg(
'show-big-image-other' )
381 ->rawParams(
$lang->pipeList( $otherSizes ) )
382 ->params(
count( $otherSizes ) )
386 } elseif ( $width == 0 && $height == 0 ) {
387 # Some sort of audio file that doesn't have dimensions
388 # Don't output a no hi res message for such a file
391 # Image is small enough to show full size on image page
392 $msgsmall = $this->
getContext()->msg(
'file-nohires' )->parse();
397 $thumbnail = $this->displayImg->transform(
$params );
402 [
'class' =>
'mw-filepage-resolutioninfo' ],
406 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
408 $out->addModules(
'mediawiki.page.image.pagination' );
409 $out->addHTML(
'<table class="multipageimage"><tr><td>' );
414 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
417 $out->addHTML(
'<div class="fullImageLink" id="file">' .
419 $anchorclose .
"</div>\n" );
423 $count = $this->displayImg->pageCount();
426 $label = $this->
getContext()->msg(
'imgmultipageprev' )->text();
433 [
'page' => $page - 1 ]
441 [
'page' => $page - 1 ]
447 if ( $page < $count ) {
448 $label = $this->
getContext()->msg(
'imgmultipagenext' )->text();
453 [
'page' => $page + 1 ]
461 [
'page' => $page + 1 ]
470 'name' =>
'pageselector',
474 for ( $i = 1; $i <= $count; $i++ ) {
478 [
'id' =>
'pageselector',
'name' =>
'page' ],
482 '</td><td><div class="multipageimagenavbox">' .
485 $this->
getContext()->msg(
'imgmultigoto' )->rawParams( $select )->parse() .
486 $this->
getContext()->msg(
'word-separator' )->escaped() .
489 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
492 } elseif ( $this->displayImg->isSafeFile() ) {
493 # if direct link is allowed but it's not a renderable image, show an icon.
494 $icon = $this->displayImg->iconThumb();
496 $out->addHTML(
'<div class="fullImageLink" id="file">' .
497 $icon->toHtml( [
'file-link' =>
true ] ) .
501 $longDesc = $this->
getContext()->msg(
'parentheses', $this->displayImg->getLongDesc() )->
text();
503 $handler = $this->displayImg->getHandler();
507 $warningConfig =
$handler->getWarningConfig( $this->displayImg );
509 if ( $warningConfig !==
null ) {
513 $output->addJsConfigVars(
'wgFileWarning', $warningConfig );
514 $output->addModules( $warningConfig[
'module'] );
515 $output->addModules(
'mediawiki.filewarning' );
519 $medialink =
"[[Media:$filename|$linktext]]";
521 if ( !$this->displayImg->isSafeFile() ) {
522 $warning = $this->
getContext()->msg(
'mediawarning' )->plain();
531 $out->addWikiText( <<<EOT
532 <div
class=
"fullMedia"><span
class=
"dangerousLink">{$medialink}</span> $dirmark<span
class=
"fileInfo">$longDesc</span></div>
533 <div
class=
"mediaWarning">$warning</div>
538 $out->addWikiText( <<<EOT
539 <div
class=
"fullMedia">{$medialink} {$dirmark}<span
class=
"fileInfo">$longDesc</span>
545 $renderLangOptions = $this->displayImg->getAvailableLanguages();
546 if (
count( $renderLangOptions ) >= 1 ) {
547 $currentLanguage = $renderLang;
548 $defaultLang = $this->displayImg->getDefaultRenderLanguage();
549 if ( is_null( $currentLanguage ) ) {
550 $currentLanguage = $defaultLang;
552 $out->addHTML( $this->
doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
556 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
562 $ext = $this->displayImg->getExtension();
564 'file-no-thumb-animation-' .
$ext,
565 'file-no-thumb-animation'
568 $out->addWikiText( <<<EOT
569 <div
class=
"mw-noanimatethumb">{$noAnimMesg}</div>
574 if ( !$this->displayImg->isLocal() ) {
578 # Image does not exist
579 if ( !$this->
getId() ) {
582 # No article exists either
583 # Show deletion log to be consistent with normal articles
586 [
'delete',
'move' ],
587 $this->
getTitle()->getPrefixedText(),
590 'conds' => [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ],
591 'showIfEmpty' =>
false,
592 'msgKey' => [
'moveddeleted-notice' ]
601 'filepage-nofile-link',
602 $uploadTitle->getFullURL( [
'wpDestFile' => $this->mPage->getFile()->getName() ] )
605 $nofile =
'filepage-nofile';
610 $out->setRobotPolicy(
'noindex,nofollow' );
611 $out->wrapWikiMsg(
"<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
612 if ( !$this->
getId() && $wgSend404Code ) {
615 $request->response()->statusHeader( 404 );
618 $out->setFileVersion( $this->displayImg );
629 if ( $sizeLinkBigImagePreview ) {
631 $previewTypeDiffers =
false;
632 $origExt = $thumbExt = $this->displayImg->getExtension();
633 if ( $this->displayImg->getHandler() ) {
634 $origMime = $this->displayImg->getMimeType();
636 $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
637 list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
638 $origExt, $origMime, $typeParams );
639 if ( $thumbMime !== $origMime ) {
640 $previewTypeDiffers =
true;
643 if ( $previewTypeDiffers ) {
644 return $this->
getContext()->msg(
'show-big-image-preview-differ' )->
645 rawParams( $sizeLinkBigImagePreview )->
646 params( strtoupper( $origExt ) )->
647 params( strtoupper( $thumbExt ) )->
650 return $this->
getContext()->msg(
'show-big-image-preview' )->
651 rawParams( $sizeLinkBigImagePreview )->
669 $thumbnail = $this->displayImg->transform(
$params );
670 if ( $thumbnail && !$thumbnail->isError() ) {
672 'href' => $thumbnail->getUrl(),
673 'class' =>
'mw-thumbnail-link'
674 ], $this->
getContext()->msg(
'show-big-image-size' )->numParams(
675 $thumbnail->getWidth(), $thumbnail->getHeight()
689 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
690 $descText = $this->mPage->getFile()->getDescriptionText( $this->
getContext()->getLanguage() );
693 if ( $descUrl && $this->mPage->getId() == 0 ) {
694 $out->setCanonicalUrl( $descUrl );
697 $wrap =
"<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
704 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-here',
$repo, $descUrl ] );
705 } elseif ( $descUrl &&
708 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-there',
$repo, $descUrl ] );
710 $out->wrapWikiMsg( $wrap, [
'sharedupload',
$repo ],
'' );
714 $this->mExtraDescription = $descText;
721 return $uploadTitle->getFullURL( [
722 'wpDestFile' => $this->mPage->getFile()->getName(),
739 if ( !$this->mPage->getFile()->isLocal() ) {
744 $out->addHTML(
"<ul>\n" );
746 # "Upload a new version of this file" link
748 if ( $canUpload && UploadBase::userCanReUpload(
750 $this->mPage->getFile() )
756 $out->addHTML(
"<li id=\"mw-imagepage-reupload-link\">"
757 .
"<div class=\"plainlinks\">{$ulink}</div></li>\n" );
759 $out->addHTML(
"<li id=\"mw-imagepage-upload-disallowed\">"
760 . $this->
getContext()->msg(
'upload-disallowed-here' )->escaped() .
"</li>\n" );
763 $out->addHTML(
"</ul>\n" );
780 $out->addHTML( $pager->getBody() );
781 $out->preventClickjacking( $pager->getPreventClickjacking() );
783 $this->mPage->getFile()->resetHistory();
785 # Exist check because we don't want to show this on pages where an image
786 # doesn't exist along with the noimage message, that would suck. -ævar
787 if ( $this->mPage->getFile()->exists() ) {
801 [
'imagelinks',
'page' ],
802 [
'page_namespace',
'page_title',
'il_to' ],
803 [
'il_to' => $target,
'il_from = page_id' ],
805 [
'LIMIT' => $limit + 1,
'ORDER BY' =>
'il_from', ]
817 $redirects[$redir->getDBkey()] = [];
820 'page_title' => $redir->getDBkey(),
825 foreach (
$res as $row ) {
830 $hasMore = $count > $limit;
831 if ( !$hasMore &&
count( $redirects ) ) {
834 foreach (
$res as $row ) {
835 $redirects[$row->il_to][] = $row;
844 [
'id' =>
'mw-imagepage-nolinkstoimage' ],
"\n$1\n" ),
850 $out->addHTML(
"<div id='mw-imagepage-section-linkstoimage'>\n" );
852 $out->addWikiMsg(
'linkstoimage', $count );
855 $out->addWikiMsg(
'linkstoimage-more',
856 $this->
getContext()->getLanguage()->formatNum( $limit ),
857 $this->
getTitle()->getPrefixedDBkey()
863 [
'class' =>
'mw-imagepage-linkstoimage' ] ) .
"\n"
868 usort(
$rows, [ $this,
'compare' ] );
872 foreach (
$rows as $element ) {
874 if ( $currentCount > $limit ) {
879 # Add a redirect=no to make redirect pages reachable
880 if ( isset( $redirects[$element->page_title] ) ) {
881 $query[
'redirect'] =
'no';
887 if ( !isset( $redirects[$element->page_title] ) ) {
890 } elseif (
count( $redirects[$element->page_title] ) === 0 ) {
891 # Redirect without usages
892 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )
893 ->rawParams(
$link,
'' )
896 # Redirect with usages
898 foreach ( $redirects[$element->page_title]
as $row ) {
900 if ( $currentCount > $limit ) {
907 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
914 [
'class' =>
'mw-imagepage-redirectstofile' ],
917 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )->rawParams(
922 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
932 if ( $count > $limit ) {
933 $out->addWikiMsg(
'morelinkstoimage', $this->
getTitle()->getPrefixedDBkey() );
942 $dupes = $this->mPage->getDuplicates();
943 if (
count( $dupes ) == 0 ) {
947 $out->addHTML(
"<div id='mw-imagepage-section-duplicates'>\n" );
948 $out->addWikiMsg(
'duplicatesoffile',
951 $out->addHTML(
"<ul class='mw-imagepage-duplicates'>\n" );
956 foreach ( $dupes
as $file ) {
958 if ( $file->isLocal() ) {
962 $file->getTitle()->getPrefixedText() );
965 $file->getRepo()->getDisplayName()
968 $out->addHTML(
"<li>{$link} {$fromSrc}</li>\n" );
970 $out->addHTML(
"</ul></div>\n" );
976 public function delete() {
977 $file = $this->mPage->getFile();
978 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
995 $out->setPageTitle( $this->
getContext()->msg(
'internalerror' ) );
996 $out->setRobotPolicy(
'noindex,nofollow' );
997 $out->setArticleRelated(
false );
998 $out->enableClientCache(
false );
999 $out->addWikiText( $description );
1011 if ( $a->page_namespace == $b->page_namespace ) {
1012 return strcmp( $a->page_title, $b->page_title );
1014 return $a->page_namespace - $b->page_namespace;
1029 $option =
$user->getIntOption( $optionName );
1056 sort( $langChoices );
1057 $curLang =
wfBCP47( $curLang );
1058 $defaultLang =
wfBCP47( $defaultLang );
1060 $haveCurrentLang =
false;
1061 $haveDefaultLang =
false;
1069 foreach ( $langChoices
as $lang ) {
1072 if (
$name !==
'' ) {
1078 if ( $curLang ===
$code ) {
1079 $haveCurrentLang =
true;
1081 if ( $defaultLang ===
$code ) {
1082 $haveDefaultLang =
true;
1085 if ( !$haveDefaultLang ) {
1091 $defaultLang === $curLang
1094 if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1096 if (
$name !==
'' ) {
1097 $display = $this->
getContext()->msg(
'img-lang-opt', $curLang,
$name )->text();
1099 $display = $curLang;
1101 $opts =
Xml::option( $display, $curLang,
true ) . $opts;
1106 [
'id' =>
'mw-imglangselector',
'name' =>
'lang' ],
1111 $formContents = $this->
getContext()->msg(
'img-lang-info' )
1112 ->rawParams( $select, $submit )
1116 $langSelectLine =
Html::rawElement(
'div', [
'id' =>
'mw-imglangselector-line' ],
1119 return $langSelectLine;
1137 if ( !$maxWidth || !$maxHeight ) {
1139 throw new MWException(
'Using a choice from $wgImageLimits that is 0x0' );
1142 if ( !$width || !$height ) {
1146 # Calculate the thumbnail size.
1147 if ( $width <= $maxWidth && $height <= $maxHeight ) {
1149 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1150 # The limiting factor is the width, not the height.
1151 $height = round( $height * $maxWidth / $width );
1153 # Note that $height <= $maxHeight now.
1155 $newwidth = floor( $width * $maxHeight / $height );
1156 $height = round( $height * $newwidth / $width );
1158 # Note that $height <= $maxHeight now, but might not be identical
1159 # because of rounding.
1161 return [ $width, $height ];
1174 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1182 $thumbSizes[] = [ $origWidth, $origHeight ];
1184 # Creating thumb links triggers thumbnail generation.
1185 # Just generate the thumb for the current users prefs.
1189 if ( !$this->displayImg->mustRender() ) {
1192 $thumbSizes[] = [ $origWidth, $origHeight ];
1203 return $this->mPage->getFile();
1211 return $this->mPage->isLocal();
1219 return $this->mPage->getDuplicates();
1227 $this->mPage->getForeignCategories();