/**
  * Determines the correct language to be used for this image gallery
  * @return Language object
  */
 private function getLang()
 {
     global $wgLang;
     return $this->mParser ? $this->mParser->getTargetLanguage() : $wgLang;
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
	/**
	 * Determines the correct language to be used for this image gallery
	 * @return Language object
	 */
	protected function getRenderLang() {
		return $this->mParser
			? $this->mParser->getTargetLanguage()
			: $this->getLanguage();
	}