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();
256 $r .=
"<table id=\"mw_metadata\" class=\"mw_metadata collapsed\">\n";
257 foreach ( $metadata
as $type => $stuff ) {
258 foreach ( $stuff
as $v ) {
259 $class = str_replace(
' ',
'_', $v[
'id'] );
260 if (
$type ==
'collapsed' ) {
261 $class .=
' mw-metadata-collapsible';
264 [
'class' => $class ],
270 $r .=
"</table>\n</div>\n";
285 if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->
getId() ) {
288 return parent::getEmptyPageParserOutput(
$options );
292 $handler = $this->displayImg->getHandler();
297 $requestLanguage =
$request->getVal(
'lang' );
298 if ( !is_null( $requestLanguage ) ) {
299 if (
$handler->validateParam(
'lang', $requestLanguage ) ) {
300 return $requestLanguage;
304 return $handler->getDefaultRenderLanguage( $this->displayImg );
314 $dirmark =
$lang->getDirMarkEntity();
319 $maxHeight = $max[1];
321 if ( $this->displayImg->exists() ) {
323 $page =
$request->getIntOrNull(
'page' );
324 if ( is_null( $page ) ) {
332 if ( !is_null( $renderLang ) ) {
336 $width_orig = $this->displayImg->getWidth( $page );
337 $width = $width_orig;
338 $height_orig = $this->displayImg->getHeight( $page );
339 $height = $height_orig;
342 $linktext = $filename;
347 Hooks::run(
'ImageOpenShowImageInlineBefore', [ &$imagePage, &
$out ] );
349 if ( $this->displayImg->allowInlineDisplay() ) {
351 # "Download high res version" link below the image
352 # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
353 # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
354 # We'll show a thumbnail of this image
355 if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
357 $maxWidth, $maxHeight, $width, $height
359 $linktext = $this->
getContext()->msg(
'show-big-image' )->escaped();
361 $thumbSizes = $this->
getThumbSizes( $width_orig, $height_orig );
362 # Generate thumbnails or thumbnail links as needed...
364 foreach ( $thumbSizes
as $size ) {
373 if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
374 || ( $this->displayImg->isVectorized()
377 && $size[0] != $width && $size[1] != $height
381 $otherSizes[] = $sizeLink;
385 $otherSizes = array_unique( $otherSizes );
389 if (
count( $otherSizes ) ) {
393 [
'class' =>
'mw-filepage-other-resolutions' ],
394 $this->
getContext()->msg(
'show-big-image-other' )
395 ->rawParams(
$lang->pipeList( $otherSizes ) )
396 ->params(
count( $otherSizes ) )
400 } elseif ( $width == 0 && $height == 0 ) {
401 # Some sort of audio file that doesn't have dimensions
402 # Don't output a no hi res message for such a file
405 # Image is small enough to show full size on image page
406 $msgsmall = $this->
getContext()->msg(
'file-nohires' )->parse();
411 $thumbnail = $this->displayImg->transform(
$params );
416 [
'class' =>
'mw-filepage-resolutioninfo' ],
420 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
422 $out->addModules(
'mediawiki.page.image.pagination' );
423 $out->addHTML(
'<table class="multipageimage"><tr><td>' );
428 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
431 $out->addHTML(
'<div class="fullImageLink" id="file">' .
433 $anchorclose .
"</div>\n" );
437 $count = $this->displayImg->pageCount();
440 $label = $this->
getContext()->msg(
'imgmultipageprev' )->text();
445 htmlspecialchars( $label ),
447 [
'page' => $page - 1 ]
455 [
'page' => $page - 1 ]
461 if ( $page < $count ) {
462 $label = $this->
getContext()->msg(
'imgmultipagenext' )->text();
465 htmlspecialchars( $label ),
467 [
'page' => $page + 1 ]
475 [
'page' => $page + 1 ]
484 'name' =>
'pageselector',
488 for ( $i = 1; $i <= $count; $i++ ) {
492 [
'id' =>
'pageselector',
'name' =>
'page' ],
496 '</td><td><div class="multipageimagenavbox">' .
499 $this->
getContext()->msg(
'imgmultigoto' )->rawParams( $select )->parse() .
500 $this->
getContext()->msg(
'word-separator' )->escaped() .
503 "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
506 } elseif ( $this->displayImg->isSafeFile() ) {
507 # if direct link is allowed but it's not a renderable image, show an icon.
508 $icon = $this->displayImg->iconThumb();
510 $out->addHTML(
'<div class="fullImageLink" id="file">' .
511 $icon->toHtml( [
'file-link' =>
true ] ) .
515 $longDesc = $this->
getContext()->msg(
'parentheses', $this->displayImg->getLongDesc() )->
text();
517 $handler = $this->displayImg->getHandler();
521 $warningConfig =
$handler->getWarningConfig( $this->displayImg );
523 if ( $warningConfig !==
null ) {
527 $output->addJsConfigVars(
'wgFileWarning', $warningConfig );
528 $output->addModules( $warningConfig[
'module'] );
529 $output->addModules(
'mediawiki.filewarning' );
533 $medialink =
"[[Media:$filename|$linktext]]";
535 if ( !$this->displayImg->isSafeFile() ) {
536 $warning = $this->
getContext()->msg(
'mediawarning' )->plain();
545 $out->addWikiText( <<<EOT
546 <
div class=
"fullMedia"><span
class=
"dangerousLink">{$medialink}</span> $dirmark<span
class=
"fileInfo">$longDesc</span></
div>
547 <
div class=
"mediaWarning">$warning</
div>
552 $out->addWikiText( <<<EOT
553 <
div class=
"fullMedia">{$medialink} {$dirmark}<span
class=
"fileInfo">$longDesc</span>
559 $renderLangOptions = $this->displayImg->getAvailableLanguages();
560 if (
count( $renderLangOptions ) >= 1 ) {
565 if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
571 $ext = $this->displayImg->getExtension();
573 'file-no-thumb-animation-' .
$ext,
574 'file-no-thumb-animation'
577 $out->addWikiText( <<<EOT
578 <
div class=
"mw-noanimatethumb">{$noAnimMesg}</
div>
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' ]
610 'filepage-nofile-link',
611 $uploadTitle->getFullURL( [
'wpDestFile' => $this->mPage->getFile()->getName() ] )
614 $nofile =
'filepage-nofile';
619 $out->setRobotPolicy(
'noindex,nofollow' );
620 $out->wrapWikiMsg(
"<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
621 if ( !$this->
getId() && $wgSend404Code ) {
624 $request->response()->statusHeader( 404 );
627 $out->setFileVersion( $this->displayImg );
638 if ( $sizeLinkBigImagePreview ) {
640 $previewTypeDiffers =
false;
641 $origExt = $thumbExt = $this->displayImg->getExtension();
642 if ( $this->displayImg->getHandler() ) {
643 $origMime = $this->displayImg->getMimeType();
645 $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
646 list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
647 $origExt, $origMime, $typeParams );
648 if ( $thumbMime !== $origMime ) {
649 $previewTypeDiffers =
true;
652 if ( $previewTypeDiffers ) {
653 return $this->
getContext()->msg(
'show-big-image-preview-differ' )->
654 rawParams( $sizeLinkBigImagePreview )->
655 params( strtoupper( $origExt ) )->
656 params( strtoupper( $thumbExt ) )->
659 return $this->
getContext()->msg(
'show-big-image-preview' )->
660 rawParams( $sizeLinkBigImagePreview )->
678 $thumbnail = $this->displayImg->transform(
$params );
679 if ( $thumbnail && !$thumbnail->isError() ) {
681 'href' => $thumbnail->getUrl(),
682 'class' =>
'mw-thumbnail-link'
683 ], $this->
getContext()->msg(
'show-big-image-size' )->numParams(
684 $thumbnail->getWidth(), $thumbnail->getHeight()
698 $descUrl = $this->mPage->getFile()->getDescriptionUrl();
699 $descText = $this->mPage->getFile()->getDescriptionText( $this->
getContext()->getLanguage() );
702 if ( $descUrl && $this->mPage->getId() == 0 ) {
703 $out->setCanonicalUrl( $descUrl );
706 $wrap =
"<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
713 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-here',
$repo, $descUrl ] );
714 } elseif ( $descUrl &&
717 $out->wrapWikiMsg( $wrap, [
'sharedupload-desc-there',
$repo, $descUrl ] );
719 $out->wrapWikiMsg( $wrap, [
'sharedupload',
$repo ],
'' );
723 $this->mExtraDescription = $descText;
730 return $uploadTitle->getFullURL( [
731 'wpDestFile' => $this->mPage->getFile()->getName(),
748 if ( !$this->mPage->getFile()->isLocal() ) {
753 $out->addHTML(
"<ul>\n" );
755 # "Upload a new version of this file" link
757 if ( $canUpload && UploadBase::userCanReUpload(
759 $this->mPage->getFile() )
765 $out->addHTML(
"<li id=\"mw-imagepage-reupload-link\">"
766 .
"<div class=\"plainlinks\">{$ulink}</div></li>\n" );
768 $out->addHTML(
"<li id=\"mw-imagepage-upload-disallowed\">"
769 . $this->
getContext()->msg(
'upload-disallowed-here' )->escaped() .
"</li>\n" );
772 $out->addHTML(
"</ul>\n" );
789 $out->addHTML( $pager->getBody() );
790 $out->preventClickjacking( $pager->getPreventClickjacking() );
792 $this->mPage->getFile()->resetHistory();
794 # Exist check because we don't want to show this on pages where an image
795 # doesn't exist along with the noimage message, that would suck. -ævar
796 if ( $this->mPage->getFile()->exists() ) {
810 [
'imagelinks',
'page' ],
811 [
'page_namespace',
'page_title',
'il_to' ],
812 [
'il_to' => $target,
'il_from = page_id' ],
814 [
'LIMIT' => $limit + 1,
'ORDER BY' =>
'il_from', ]
826 $redirects[$redir->getDBkey()] = [];
829 'page_title' => $redir->getDBkey(),
834 foreach (
$res as $row ) {
839 $hasMore = $count > $limit;
840 if ( !$hasMore &&
count( $redirects ) ) {
843 foreach (
$res as $row ) {
844 $redirects[$row->il_to][] = $row;
853 [
'id' =>
'mw-imagepage-nolinkstoimage' ],
"\n$1\n" ),
859 $out->addHTML(
"<div id='mw-imagepage-section-linkstoimage'>\n" );
861 $out->addWikiMsg(
'linkstoimage', $count );
864 $out->addWikiMsg(
'linkstoimage-more',
865 $this->
getContext()->getLanguage()->formatNum( $limit ),
866 $this->
getTitle()->getPrefixedDBkey()
872 [
'class' =>
'mw-imagepage-linkstoimage' ] ) .
"\n"
877 usort(
$rows, [ $this,
'compare' ] );
881 foreach (
$rows as $element ) {
883 if ( $currentCount > $limit ) {
888 # Add a redirect=no to make redirect pages reachable
889 if ( isset( $redirects[$element->page_title] ) ) {
890 $query[
'redirect'] =
'no';
896 if ( !isset( $redirects[$element->page_title] ) ) {
899 } elseif (
count( $redirects[$element->page_title] ) === 0 ) {
900 # Redirect without usages
901 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )
902 ->rawParams(
$link,
'' )
905 # Redirect with usages
907 foreach ( $redirects[$element->page_title]
as $row ) {
909 if ( $currentCount > $limit ) {
916 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
923 [
'class' =>
'mw-imagepage-redirectstofile' ],
926 $liContents = $this->
getContext()->msg(
'linkstoimage-redirect' )->rawParams(
931 [
'class' =>
'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
941 if ( $count > $limit ) {
942 $out->addWikiMsg(
'morelinkstoimage', $this->
getTitle()->getPrefixedDBkey() );
951 $dupes = $this->mPage->getDuplicates();
952 if (
count( $dupes ) == 0 ) {
956 $out->addHTML(
"<div id='mw-imagepage-section-duplicates'>\n" );
957 $out->addWikiMsg(
'duplicatesoffile',
960 $out->addHTML(
"<ul class='mw-imagepage-duplicates'>\n" );
965 foreach ( $dupes
as $file ) {
967 if ( $file->isLocal() ) {
971 $file->getTitle()->getPrefixedText() );
974 $file->getRepo()->getDisplayName()
977 $out->addHTML(
"<li>{$link} {$fromSrc}</li>\n" );
979 $out->addHTML(
"</ul></div>\n" );
985 public function delete() {
986 $file = $this->mPage->getFile();
987 if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
1004 $out->setPageTitle( $this->
getContext()->msg(
'internalerror' ) );
1005 $out->setRobotPolicy(
'noindex,nofollow' );
1006 $out->setArticleRelated(
false );
1007 $out->enableClientCache(
false );
1008 $out->addWikiText( $description );
1020 return $a->page_namespace <=> $b->page_namespace
1021 ?: strcmp( $a->page_title, $b->page_title );
1035 $option =
$user->getIntOption( $optionName );
1062 $matchedRenderLang = $this->displayImg->getMatchedLanguage( $renderLang );
1064 foreach ( $langChoices
as $lang ) {
1067 $matchedRenderLang ===
$lang
1077 is_null( $matchedRenderLang )
1082 [
'id' =>
'mw-imglangselector',
'name' =>
'lang' ],
1087 $formContents = $this->
getContext()->msg(
'img-lang-info' )
1088 ->rawParams( $select, $submit )
1092 $langSelectLine =
Html::rawElement(
'div', [
'id' =>
'mw-imglangselector-line' ],
1095 return $langSelectLine;
1106 if (
$name !==
'' ) {
1134 if ( !$maxWidth || !$maxHeight ) {
1136 throw new MWException(
'Using a choice from $wgImageLimits that is 0x0' );
1139 if ( !$width || !$height ) {
1143 # Calculate the thumbnail size.
1144 if ( $width <= $maxWidth && $height <= $maxHeight ) {
1146 } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1147 # The limiting factor is the width, not the height.
1148 $height = round( $height * $maxWidth / $width );
1150 # Note that $height <= $maxHeight now.
1152 $newwidth = floor( $width * $maxHeight / $height );
1153 $height = round( $height * $newwidth / $width );
1155 # Note that $height <= $maxHeight now, but might not be identical
1156 # because of rounding.
1158 return [ $width, $height ];
1171 if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1179 $thumbSizes[] = [ $origWidth, $origHeight ];
1181 # Creating thumb links triggers thumbnail generation.
1182 # Just generate the thumb for the current users prefs.
1186 if ( !$this->displayImg->mustRender() ) {
1189 $thumbSizes[] = [ $origWidth, $origHeight ];
1200 return $this->mPage->getFile();
1208 return $this->mPage->isLocal();
1216 return $this->mPage->getDuplicates();
1224 $this->mPage->getForeignCategories();