protected function openShowImage() { global $wgImageLimits, $wgEnableUploads, $wgSend404Code; $this->loadFile(); $out = $this->getContext()->getOutput(); $user = $this->getContext()->getUser(); $lang = $this->getContext()->getLanguage(); $dirmark = $lang->getDirMarkEntity(); $request = $this->getContext()->getRequest(); $max = $this->getImageLimitsFromOption($user, 'imagesize'); $maxWidth = $max[0]; $maxHeight = $max[1]; if ($this->displayImg->exists()) { # image $page = $request->getIntOrNull('page'); if (is_null($page)) { $params = array(); $page = 1; } else { $params = array('page' => $page); } $renderLang = $request->getVal('lang'); if (!is_null($renderLang)) { $handler = $this->displayImg->getHandler(); if ($handler && $handler->validateParam('lang', $renderLang)) { $params['lang'] = $renderLang; } else { $renderLang = null; } } $width_orig = $this->displayImg->getWidth($page); $width = $width_orig; $height_orig = $this->displayImg->getHeight($page); $height = $height_orig; $filename = wfEscapeWikiText($this->displayImg->getName()); $linktext = $filename; wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$out)); if ($this->displayImg->allowInlineDisplay()) { # image # "Download high res version" link below the image # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped(); # We'll show a thumbnail of this image if ($width > $maxWidth || $height > $maxHeight) { # Calculate the thumbnail size. # First case, the limiting factor is the width, not the height. if ($width / $height >= $maxWidth / $maxHeight) { // FIXME: Possible division by 0. bug 36911 $height = round($height * $maxWidth / $width); // FIXME: Possible division by 0. bug 36911 $width = $maxWidth; # Note that $height <= $maxHeight now. } else { $newwidth = floor($width * $maxHeight / $height); // FIXME: Possible division by 0. bug 36911 $height = round($height * $newwidth / $width); // FIXME: Possible division by 0. bug 36911 $width = $newwidth; # Note that $height <= $maxHeight now, but might not be identical # because of rounding. } $linktext = wfMessage('show-big-image')->escaped(); if ($this->displayImg->getRepo()->canTransformVia404()) { $thumbSizes = $wgImageLimits; // Also include the full sized resolution in the list, so // that users know they can get it. This will link to the // original file asset if mustRender() === false. In the case // that we mustRender, some users have indicated that they would // find it useful to have the full size image in the rendered // image format. $thumbSizes[] = array($width_orig, $height_orig); } else { # Creating thumb links triggers thumbnail generation. # Just generate the thumb for the current users prefs. $thumbSizes = array($this->getImageLimitsFromOption($user, 'thumbsize')); if (!$this->displayImg->mustRender()) { // We can safely include a link to the "full-size" preview, // without actually rendering. $thumbSizes[] = array($width_orig, $height_orig); } } # Generate thumbnails or thumbnail links as needed... $otherSizes = array(); foreach ($thumbSizes as $size) { // We include a thumbnail size in the list, if it is // less than or equal to the original size of the image // asset ($width_orig/$height_orig). We also exclude // the current thumbnail's size ($width/$height) // since that is added to the message separately, so // it can be denoted as the current size being shown. if ($size[0] <= $width_orig && $size[1] <= $height_orig && $size[0] != $width && $size[1] != $height) { $sizeLink = $this->makeSizeLink($params, $size[0], $size[1]); if ($sizeLink) { $otherSizes[] = $sizeLink; } } } $otherSizes = array_unique($otherSizes); $msgsmall = ''; $sizeLinkBigImagePreview = $this->makeSizeLink($params, $width, $height); if ($sizeLinkBigImagePreview) { $msgsmall .= wfMessage('show-big-image-preview')->rawParams($sizeLinkBigImagePreview)->parse(); } if (count($otherSizes)) { $msgsmall .= ' ' . Html::rawElement('span', array('class' => 'mw-filepage-other-resolutions'), wfMessage('show-big-image-other')->rawParams($lang->pipeList($otherSizes))->params(count($otherSizes))->parse()); } } elseif ($width == 0 && $height == 0) { # Some sort of audio file that doesn't have dimensions # Don't output a no hi res message for such a file $msgsmall = ''; } elseif ($this->displayImg->isVectorized()) { # For vectorized images, full size is just the frame size $msgsmall = ''; } else { # Image is small enough to show full size on image page $msgsmall = wfMessage('file-nohires')->parse(); } $params['width'] = $width; $params['height'] = $height; $thumbnail = $this->displayImg->transform($params); Linker::processResponsiveImages($this->displayImg, $thumbnail, $params); $anchorclose = Html::rawElement('div', array('class' => 'mw-filepage-resolutioninfo'), $msgsmall); $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1; if ($isMulti) { $out->addModules('mediawiki.page.image.pagination'); $out->addHTML('<table class="multipageimage"><tr><td>'); } if ($thumbnail) { $options = array('alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true); $out->addHTML('<div class="fullImageLink" id="file">' . $thumbnail->toHtml($options) . $anchorclose . "</div>\n"); } if ($isMulti) { $count = $this->displayImg->pageCount(); if ($page > 1) { $label = $out->parse(wfMessage('imgmultipageprev')->text(), false); // on the client side, this link is generated in ajaxifyPageNavigation() // in the mediawiki.page.image.pagination module $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page - 1)); $thumb1 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page - 1)); } else { $thumb1 = ''; } if ($page < $count) { $label = wfMessage('imgmultipagenext')->text(); $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page + 1)); $thumb2 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page + 1)); } else { $thumb2 = ''; } global $wgScript; $formParams = array('name' => 'pageselector', 'action' => $wgScript); $options = array(); for ($i = 1; $i <= $count; $i++) { $options[] = Xml::option($lang->formatNum($i), $i, $i == $page); } $select = Xml::tags('select', array('id' => 'pageselector', 'name' => 'page'), implode("\n", $options)); $out->addHTML('</td><td><div class="multipageimagenavbox">' . Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . wfMessage('imgmultigoto')->rawParams($select)->parse() . Xml::submitButton(wfMessage('imgmultigo')->text()) . Xml::closeElement('form') . "<hr />{$thumb1}\n{$thumb2}<br style=\"clear: both\" /></div></td></tr></table>"); } } elseif ($this->displayImg->isSafeFile()) { # if direct link is allowed but it's not a renderable image, show an icon. $icon = $this->displayImg->iconThumb(); $out->addHTML('<div class="fullImageLink" id="file">' . $icon->toHtml(array('file-link' => true)) . "</div>\n"); } $longDesc = wfMessage('parentheses', $this->displayImg->getLongDesc())->text(); $medialink = "[[Media:{$filename}|{$linktext}]]"; if (!$this->displayImg->isSafeFile()) { $warning = wfMessage('mediawarning')->plain(); // dirmark is needed here to separate the file name, which // most likely ends in Latin characters, from the description, // which may begin with the file type. In RTL environment // this will get messy. // The dirmark, however, must not be immediately adjacent // to the filename, because it can get copied with it. // See bug 25277. $out->addWikiText(<<<EOT <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> {$dirmark}<span class="fileInfo">{$longDesc}</span></div> <div class="mediaWarning">{$warning}</div> EOT ); } else { $out->addWikiText(<<<EOT <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">{$longDesc}</span> </div> EOT ); } $renderLangOptions = $this->displayImg->getAvailableLanguages(); if (count($renderLangOptions) >= 1) { $currentLanguage = $renderLang; $defaultLang = $this->displayImg->getDefaultRenderLanguage(); if (is_null($currentLanguage)) { $currentLanguage = $defaultLang; } $out->addHtml($this->doRenderLangOpt($renderLangOptions, $currentLanguage, $defaultLang)); } // Add cannot animate thumbnail warning if (!$this->displayImg->canAnimateThumbIfAppropriate()) { // Include the extension so wiki admins can // customize it on a per file-type basis // (aka say things like use format X instead). // additionally have a specific message for // file-no-thumb-animation-gif $ext = $this->displayImg->getExtension(); $noAnimMesg = wfMessageFallback('file-no-thumb-animation-' . $ext, 'file-no-thumb-animation')->plain(); $out->addWikiText(<<<EOT <div class="mw-noanimatethumb">{$noAnimMesg}</div> EOT ); } if (!$this->displayImg->isLocal()) { $this->printSharedImageText(); } } else { # Image does not exist if (!$this->getID()) { # No article exists either # Show deletion log to be consistent with normal articles LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle()->getPrefixedText(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice'))); } if ($wgEnableUploads && $user->isAllowed('upload')) { // Only show an upload link if the user can upload $uploadTitle = SpecialPage::getTitleFor('Upload'); $nofile = array('filepage-nofile-link', $uploadTitle->getFullURL(array('wpDestFile' => $this->mPage->getFile()->getName()))); } else { $nofile = 'filepage-nofile'; } // Note, if there is an image description page, but // no image, then this setRobotPolicy is overridden // by Article::View(). $out->setRobotPolicy('noindex,nofollow'); $out->wrapWikiMsg("<div id='mw-imagepage-nofile' class='plainlinks'>\n\$1\n</div>", $nofile); if (!$this->getID() && $wgSend404Code) { // If there is no image, no shared image, and no description page, // output a 404, to be consistent with articles. $request->response()->header('HTTP/1.1 404 Not Found'); } } $out->setFileVersion($this->displayImg); }
/** * Given parameters derived from [[Image:Foo|options...]], generate the * HTML that that syntax inserts in the page. * * @param Parser $parser * @param Title $title Title object of the file (not the currently viewed page) * @param File $file File object, or false if it doesn't exist * @param array $frameParams Associative array of parameters external to the media handler. * Boolean parameters are indicated by presence or absence, the value is arbitrary and * will often be false. * thumbnail If present, downscale and frame * manualthumb Image name to use as a thumbnail, instead of automatic scaling * framed Shows image in original size in a frame * frameless Downscale but don't frame * upright If present, tweak default sizes for portrait orientation * upright_factor Fudge factor for "upright" tweak (default 0.75) * border If present, show a border around the image * align Horizontal alignment (left, right, center, none) * valign Vertical alignment (baseline, sub, super, top, text-top, middle, * bottom, text-bottom) * alt Alternate text for image (i.e. alt attribute). Plain text. * class HTML for image classes. Plain text. * caption HTML for image caption. * link-url URL to link to * link-title Title object to link to * link-target Value for the target attribute, only with link-url * no-link Boolean, suppress description link * * @param array $handlerParams Associative array of media handler parameters, to be passed * to transform(). Typical keys are "width" and "page". * @param string|bool $time Timestamp of the file, set as false for current * @param string $query Query params for desc url * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize * @since 1.20 * @return string HTML for an image, with links, wrappers, etc. */ public static function makeImageLink(Parser $parser, Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null) { $res = null; $dummy = new DummyLinker(); if (!Hooks::run('ImageBeforeProduceHTML', array(&$dummy, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res))) { return $res; } if ($file && !$file->allowInlineDisplay()) { wfDebug(__METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n"); return self::link($title); } // Shortcuts $fp =& $frameParams; $hp =& $handlerParams; // Clean up parameters $page = isset($hp['page']) ? $hp['page'] : false; if (!isset($fp['align'])) { $fp['align'] = ''; } if (!isset($fp['alt'])) { $fp['alt'] = ''; } if (!isset($fp['title'])) { $fp['title'] = ''; } if (!isset($fp['class'])) { $fp['class'] = ''; } $prefix = $postfix = ''; if ('center' == $fp['align']) { $prefix = '<div class="center">'; $postfix = '</div>'; $fp['align'] = 'none'; } if ($file && !isset($hp['width'])) { if (isset($hp['height']) && $file->isVectorized()) { // If its a vector image, and user only specifies height // we don't want it to be limited by its "normal" width. global $wgSVGMaxSize; $hp['width'] = $wgSVGMaxSize; } else { $hp['width'] = $file->getWidth($page); } if (isset($fp['thumbnail']) || isset($fp['manualthumb']) || isset($fp['framed']) || isset($fp['frameless']) || !$hp['width']) { global $wgThumbLimits, $wgThumbUpright; if ($widthOption === null || !isset($wgThumbLimits[$widthOption])) { $widthOption = User::getDefaultOption('thumbsize'); } // Reduce width for upright images when parameter 'upright' is used if (isset($fp['upright']) && $fp['upright'] == 0) { $fp['upright'] = $wgThumbUpright; } // For caching health: If width scaled down due to upright // parameter, round to full __0 pixel to avoid the creation of a // lot of odd thumbs. $prefWidth = isset($fp['upright']) ? round($wgThumbLimits[$widthOption] * $fp['upright'], -1) : $wgThumbLimits[$widthOption]; // Use width which is smaller: real image width or user preference width // Unless image is scalable vector. if (!isset($hp['height']) && ($hp['width'] <= 0 || $prefWidth < $hp['width'] || $file->isVectorized())) { $hp['width'] = $prefWidth; } } } if (isset($fp['thumbnail']) || isset($fp['manualthumb']) || isset($fp['framed'])) { # Create a thumbnail. Alignment depends on the writing direction of # the page content language (right-aligned for LTR languages, # left-aligned for RTL languages) # If a thumbnail width has not been provided, it is set # to the default user option as specified in Language*.php if ($fp['align'] == '') { $fp['align'] = $parser->getTargetLanguage()->alignEnd(); } return $prefix . self::makeThumbLink2($title, $file, $fp, $hp, $time, $query) . $postfix; } if ($file && isset($fp['frameless'])) { $srcWidth = $file->getWidth($page); # For "frameless" option: do not present an image bigger than the # source (for bitmap-style images). This is the same behavior as the # "thumb" option does it already. if ($srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth) { $hp['width'] = $srcWidth; } } if ($file && isset($hp['width'])) { # Create a resized image, without the additional thumbnail features $thumb = $file->transform($hp); } else { $thumb = false; } if (!$thumb) { $s = self::makeBrokenImageLinkObj($title, $fp['title'], '', '', '', $time == true); } else { self::processResponsiveImages($file, $thumb, $hp); $params = array('alt' => $fp['alt'], 'title' => $fp['title'], 'valign' => isset($fp['valign']) ? $fp['valign'] : false, 'img-class' => $fp['class']); if (isset($fp['border'])) { $params['img-class'] .= ($params['img-class'] !== '' ? ' ' : '') . 'thumbborder'; } $params = self::getImageLinkMTOParams($fp, $query, $parser) + $params; $s = $thumb->toHtml($params); } if ($fp['align'] != '') { $s = "<div class=\"float{$fp['align']}\">{$s}</div>"; } return str_replace("\n", ' ', $prefix . $s . $postfix); }