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 ) {
120 $request->setVal(
'diffonly',
'true' );
126 $out->setPageTitle( $this->
getTitle()->getPrefixedText() );
137 if ( $wgShowEXIF && $this->displayImg->exists() ) {
139 $formattedMetadata = $this->displayImg->formatMetadata( $this->
getContext() );
140 $showmeta = $formattedMetadata !==
false;
145 if ( !$diff && $this->displayImg->exists() ) {
153 # No need to display noarticletext, we use our own message, output in openShowImage()
154 if ( $this->mPage->getId() ) {
155 # NS_FILE is in the user language, but this section (the actual wikitext)
156 # should be in page content language
157 $pageLang = $this->
getTitle()->getPageViewLanguage();
159 'lang' => $pageLang->getHtmlCode(),
'dir' => $pageLang->getDir(),
160 'class' =>
'mw-content-' . $pageLang->getDir() ] ) );
166 # Just need to set the right headers
167 $out->setArticleFlag(
true );
168 $out->setPageTitle( $this->
getTitle()->getPrefixedText() );
172 # Show shared description, if needed
173 if ( $this->mExtraDescription ) {
174 $fol = $this->
getContext()->msg(
'shareddescriptionfollows' );
175 if ( !$fol->isDisabled() ) {
176 $out->addWikiText( $fol->plain() );
178 $out->addHTML(
'<div id="shared-image-desc">' . $this->mExtraDescription .
"</div>\n" );
186 [
'id' =>
'filelinks' ],
189 # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
190 # Yet we return metadata about the target. Definitely an issue in the FileRepo
193 # Allow extensions to add something after the image links
203 [
'id' =>
'metadata' ],
206 $out->addModules( [
'mediawiki.action.view.metadata' ] );
210 if ( !$this->repo->isLocal() ) {
211 $css = $this->repo->getDescriptionStylesheetUrl();
217 $out->addModuleStyles( [
219 'mediawiki.action.view.filepage',
239 '<li><a href="#file">' . $this->
getContext()->msg(
'file-anchor-link' )->escaped() .
'</a></li>',
240 '<li><a href="#filehistory">' . $this->
getContext()->msg(
'filehist' )->escaped() .
'</a></li>',
241 '<li><a href="#filelinks">' . $this->
getContext()->msg(
'imagelinks' )->escaped() .
'</a></li>',
244 Hooks::run(
'ImagePageShowTOC', [ $this, &$r ] );
247 $r[] =
'<li><a href="#metadata">' .
248 $this->
getContext()->msg(
'metadata' )->escaped() .
252 return '<ul id="filetoc">' . implode(
"\n", $r ) .
'</ul>';
264 $r =
"<div class=\"mw-imagepage-section-metadata\">";
265 $r .= $this->
getContext()->msg(
'metadata-help' )->plain();
266 $r .=
"<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
267 foreach ( $metadata
as $type => $stuff ) {
268 foreach ( $stuff
as $v ) {
269 # @todo FIXME: Why is this using escapeId for a class?!
270 $class = Sanitizer::escapeId( $v[
'id'] );
271 if (
$type ==
'collapsed' ) {
273 $class .=
' collapsable';
275 $r .=
"<tr class=\"$class\">\n";
276 $r .=
"<th>{$v['name']}</th>\n";
277 $r .=
"<td>{$v['value']}</td>\n</tr>";
280 $r .=
"</table>\n</div>\n";
293 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->
getId() ) {
296 return parent::getContentObject();
306 $dirmark =
$lang->getDirMarkEntity();
311 $maxHeight = $max[1];
313 if ( $this->displayImg->exists() ) {
316 if ( is_null(
$page ) ) {
323 $renderLang =
$request->getVal(
'lang' );
324 if ( !is_null( $renderLang ) ) {
325 $handler = $this->displayImg->getHandler();
333 $width_orig = $this->displayImg->getWidth(
$page );
334 $width = $width_orig;
335 $height_orig = $this->displayImg->getHeight(
$page );
336 $height = $height_orig;
339 $linktext = $filename;
344 Hooks::run(
'ImageOpenShowImageInlineBefore', [ &$imagePage, &
$out ] );
346 if ( $this->displayImg->allowInlineDisplay() ) {
348 # "Download high res version" link below the image
349 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
350 # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
351 # We'll show a thumbnail of this image
352 if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
354 $maxWidth, $maxHeight, $width, $height
356 $linktext = $this->
getContext()->msg(
'show-big-image' )->escaped();
358 $thumbSizes = $this->
getThumbSizes( $width_orig, $height_orig );
359 # Generate thumbnails or thumbnail links as needed...
361 foreach ( $thumbSizes
as $size ) {
370 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
371 || ( $this->displayImg->isVectorized()
374 && $size[0] != $width && $size[1] != $height
378 $otherSizes[] = $sizeLink;
382 $otherSizes = array_unique( $otherSizes );
386 if (
count( $otherSizes ) ) {
390 [
'class' =>
'mw-filepage-other-resolutions' ],
391 $this->
getContext()->msg(
'show-big-image-other' )
392 ->rawParams(
$lang->pipeList( $otherSizes ) )
393 ->params(
count( $otherSizes ) )
397 } elseif ( $width == 0 && $height == 0 ) {
398 # Some sort of audio file that doesn't have dimensions
399 # Don't output a no hi res message for such a file
402 # Image is small enough to show full size on image page
403 $msgsmall = $this->
getContext()->msg(
'file-nohires' )->parse();
408 $thumbnail = $this->displayImg->transform(
$params );
413 [
'class' =>
'mw-filepage-resolutioninfo' ],
417 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
419 $out->addModules(
'mediawiki.page.image.pagination' );
420 $out->addHTML(
'<table class="multipageimage"><tr><td>' );
425 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
428 $out->addHTML(
'<div class="fullImageLink" id="file">' .
430 $anchorclose .
"</div>\n" );
434 $count = $this->displayImg->pageCount();
437 $label =
$out->parse( $this->
getContext()->msg(
'imgmultipageprev' )->
text(),
false );
444 [
'page' =>
$page - 1 ]
452 [
'page' =>
$page - 1 ]
458 if (
$page < $count ) {
459 $label = $this->
getContext()->msg(
'imgmultipagenext' )->text();
464 [
'page' =>
$page + 1 ]
472 [
'page' =>
$page + 1 ]
481 'name' =>
'pageselector',
485 for ( $i = 1; $i <= $count; $i++ ) {
489 [
'id' =>
'pageselector',
'name' =>
'page' ],
493 '</td><td><div class="multipageimagenavbox">' .
496 $this->
getContext()->msg(
'imgmultigoto' )->rawParams( $select )->parse() .
499 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
502 } elseif ( $this->displayImg->isSafeFile() ) {
503 # if direct link is allowed but it's not a renderable image, show an icon.
504 $icon = $this->displayImg->iconThumb();
506 $out->addHTML(
'<div class="fullImageLink" id="file">' .
507 $icon->toHtml( [
'file-link' =>
true ] ) .
511 $longDesc = $this->
getContext()->msg(
'parentheses', $this->displayImg->getLongDesc() )->
text();
513 $handler = $this->displayImg->getHandler();
517 $warningConfig =
$handler->getWarningConfig( $this->displayImg );
519 if ( $warningConfig !==
null ) {
523 $output->addJsConfigVars(
'wgFileWarning', $warningConfig );
524 $output->addModules( $warningConfig[
'module'] );
525 $output->addModules(
'mediawiki.filewarning' );
529 $medialink =
"[[Media:$filename|$linktext]]";
531 if ( !$this->displayImg->isSafeFile() ) {
532 $warning = $this->
getContext()->msg(
'mediawarning' )->plain();
541 $out->addWikiText( <<<EOT
542 <
div class=
"fullMedia"><span
class=
"dangerousLink">{$medialink}</span> $dirmark<span
class=
"fileInfo">$longDesc</span></
div>
543 <
div class=
"mediaWarning">$warning</
div>
548 $out->addWikiText( <<<EOT
549 <
div class=
"fullMedia">{$medialink} {$dirmark}<span
class=
"fileInfo">$longDesc</span>
555 $renderLangOptions = $this->displayImg->getAvailableLanguages();
556 if (
count( $renderLangOptions ) >= 1 ) {
557 $currentLanguage = $renderLang;
558 $defaultLang = $this->displayImg->getDefaultRenderLanguage();
559 if ( is_null( $currentLanguage ) ) {
560 $currentLanguage = $defaultLang;
562 $out->addHTML( $this->
doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
566 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
572 $ext = $this->displayImg->getExtension();
574 'file-no-thumb-animation-' .
$ext,
575 'file-no-thumb-animation'
578 $out->addWikiText( <<<EOT
579 <
div class=
"mw-noanimatethumb">{$noAnimMesg}</
div>
584 if ( !$this->displayImg->isLocal() ) {
588 # Image does not exist
589 if ( !$this->
getId() ) {
592 # No article exists either
593 # Show deletion log to be consistent with normal articles
596 [
'delete',
'move' ],
597 $this->
getTitle()->getPrefixedText(),
600 'conds' => [
'log_action != ' .
$dbr->addQuotes(
'revision' ) ],
601 'showIfEmpty' =>
false,
602 'msgKey' => [
'moveddeleted-notice' ]
611 'filepage-nofile-link',
612 $uploadTitle->getFullURL( [
'wpDestFile' => $this->mPage->getFile()->getName() ] )
615 $nofile =
'filepage-nofile';
620 $out->setRobotPolicy(
'noindex,nofollow' );
621 $out->wrapWikiMsg(
"<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
622 if ( !$this->
getId() && $wgSend404Code ) {
625 $request->response()->statusHeader( 404 );
628 $out->setFileVersion( $this->displayImg );
639 if ( $sizeLinkBigImagePreview ) {
641 $previewTypeDiffers =
false;
642 $origExt = $thumbExt = $this->displayImg->getExtension();
643 if ( $this->displayImg->getHandler() ) {
644 $origMime = $this->displayImg->getMimeType();
646 $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
647 list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
648 $origExt, $origMime, $typeParams );
649 if ( $thumbMime !== $origMime ) {
650 $previewTypeDiffers =
true;
653 if ( $previewTypeDiffers ) {
654 return $this->
getContext()->msg(
'show-big-image-preview-differ' )->
655 rawParams( $sizeLinkBigImagePreview )->
656 params( strtoupper( $origExt ) )->
657 params( strtoupper( $thumbExt ) )->
660 return $this->
getContext()->msg(
'show-big-image-preview' )->
661 rawParams( $sizeLinkBigImagePreview )->
679 $thumbnail = $this->displayImg->transform(
$params );
680 if ( $thumbnail && !$thumbnail->isError() ) {
682 'href' => $thumbnail->getUrl(),
683 'class' =>
'mw-thumbnail-link'
684 ], $this->
getContext()->msg(
'show-big-image-size' )->numParams(
685 $thumbnail->getWidth(), $thumbnail->getHeight()
699 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
700 $descText = $this->mPage->getFile()->getDescriptionText( $this->
getContext()->getLanguage() );
703 if ( $descUrl && $this->mPage->getId() == 0 ) {
704 $out->setCanonicalUrl( $descUrl );
707 $wrap =
"<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
714 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-here',
$repo, $descUrl ] );
715 } elseif ( $descUrl &&
718 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-there',
$repo, $descUrl ] );
720 $out->wrapWikiMsg( $wrap, [
'sharedupload',
$repo ],
'' );
724 $this->mExtraDescription = $descText;
731 return $uploadTitle->getFullURL( [
732 'wpDestFile' => $this->mPage->getFile()->getName(),
749 if ( !$this->mPage->getFile()->isLocal() ) {
754 $out->addHTML(
"<ul>\n" );
756 # "Upload a new version of this file" link
758 if ( $canUpload && UploadBase::userCanReUpload(
760 $this->mPage->getFile() )
766 $out->addHTML(
"<li id=\"mw-imagepage-reupload-link\">"
767 .
"<div class=\"plainlinks\">{$ulink}</div></li>\n" );
769 $out->addHTML(
"<li id=\"mw-imagepage-upload-disallowed\">"
770 . $this->
getContext()->msg(
'upload-disallowed-here' )->escaped() .
"</li>\n" );
773 $out->addHTML(
"</ul>\n" );
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 ) ) {
844 foreach (
$res as $row ) {
845 $redirects[$row->il_to][] = $row;
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',
867 $this->
getTitle()->getPrefixedDBkey()
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 ) {
917 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
924 [
'class' =>
'mw-imagepage-redirectstofile' ],
927 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )->rawParams(
932 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
943 $out->addWikiMsg(
'morelinkstoimage', $this->
getTitle()->getPrefixedDBkey() );
952 $dupes = $this->mPage->getDuplicates();
953 if (
count( $dupes ) == 0 ) {
957 $out->addHTML(
"<div id='mw-imagepage-section-duplicates'>\n" );
958 $out->addWikiMsg(
'duplicatesoffile',
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() ) {
1005 $out->setPageTitle( $this->
getContext()->msg(
'internalerror' ) );
1006 $out->setRobotPolicy(
'noindex,nofollow' );
1007 $out->setArticleRelated(
false );
1008 $out->enableClientCache(
false );
1009 $out->addWikiText( $description );
1021 if ( $a->page_namespace == $b->page_namespace ) {
1022 return strcmp( $a->page_title, $b->page_title );
1024 return $a->page_namespace - $b->page_namespace;
1039 $option =
$user->getIntOption( $optionName );
1066 sort( $langChoices );
1067 $curLang =
wfBCP47( $curLang );
1068 $defaultLang =
wfBCP47( $defaultLang );
1070 $haveCurrentLang =
false;
1071 $haveDefaultLang =
false;
1079 foreach ( $langChoices
as $lang ) {
1082 if (
$name !==
'' ) {
1088 if ( $curLang ===
$code ) {
1089 $haveCurrentLang =
true;
1091 if ( $defaultLang ===
$code ) {
1092 $haveDefaultLang =
true;
1095 if ( !$haveDefaultLang ) {
1101 $defaultLang === $curLang
1104 if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1106 if (
$name !==
'' ) {
1107 $display = $this->
getContext()->msg(
'img-lang-opt', $curLang,
$name )->text();
1109 $display = $curLang;
1111 $opts =
Xml::option( $display, $curLang,
true ) . $opts;
1116 [
'id' =>
'mw-imglangselector',
'name' =>
'lang' ],
1121 $formContents = $this->
getContext()->msg(
'img-lang-info' )
1122 ->rawParams( $select, $submit )
1126 $langSelectLine =
Html::rawElement(
'div', [
'id' =>
'mw-imglangselector-line' ],
1129 return $langSelectLine;
1147 if ( !$maxWidth || !$maxHeight ) {
1149 throw new MWException(
'Using a choice from $wgImageLimits that is 0x0' );
1152 if ( !$width || !$height ) {
1156 # Calculate the thumbnail size.
1157 if ( $width <= $maxWidth && $height <= $maxHeight ) {
1159 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1160 # The limiting factor is the width, not the height.
1161 $height = round( $height * $maxWidth / $width );
1163 # Note that $height <= $maxHeight now.
1165 $newwidth = floor( $width * $maxHeight / $height );
1166 $height = round( $height * $newwidth / $width );
1168 # Note that $height <= $maxHeight now, but might not be identical
1169 # because of rounding.
1171 return [ $width, $height ];
1184 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1192 $thumbSizes[] = [ $origWidth, $origHeight ];
1194 # Creating thumb links triggers thumbnail generation.
1195 # Just generate the thumb for the current users prefs.
1199 if ( !$this->displayImg->mustRender() ) {
1202 $thumbSizes[] = [ $origWidth, $origHeight ];
1213 return $this->mPage->getFile();
1221 return $this->mPage->isLocal();
1229 return $this->mPage->getDuplicates();
1237 $this->mPage->getForeignCategories();