/** * Small convenience function to display a (clickable) logo * @param $project Project name * @return String */ public function makeLogo( $project, $clickable = true, $width = 25, $height = '', $url = '', $args = array() ) { $projectForFile = preg_replace('/ /', '-', strtolower( $project ) ); $imageobj = wfFindFile( wfMsg( 'wminc-logo-' . $projectForFile ) ); $useUrl = $url ? $url : IncubatorTest::getSubdomain( 'www', IncubatorTest::getProject( $project, false, true ) ); if ( !$imageobj ) { # image not found if( !$clickable ) { return $logo; // FIXME: $logo is undefined } return Linker::makeExternalLink( $useUrl, $project, false ); } if( $clickable ) { $args['link-url'] = $useUrl; } else { $args['no-link'] = true; } $handlerParams['width'] = $width; if( $height ) { $handlerParams['height'] = $height; } return Linker::makeImageLink2( $this->mTitle, $imageobj, array( 'alt' => $project, 'caption' => $project ) + $args, $handlerParams ); }
/** * Parse image options text and use it to make an image * * @param $title Title * @param $options String * @param $holders LinkHolderArray * @return string HTML */ function makeImage($title, $options, $holders = false) { # Check if the options text is of the form "options|alt text" # Options are: # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang # * left no resizing, just left align. label is used for alt= only # * right same, but right aligned # * none same, but not aligned # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox # * center center the image # * frame Keep original image size, no magnify-button. # * framed Same as "frame" # * frameless like 'thumb' but without a frame. Keeps user preferences for width # * upright reduce width for upright images, rounded to full __0 px # * border draw a 1px border around the image # * alt Text for HTML alt attribute (defaults to empty) # * link Set the target of the image link. Can be external, interwiki, or local # vertical-align values (no % or length right now): # * baseline # * sub # * super # * top # * text-top # * middle # * bottom # * text-bottom $parts = StringUtils::explode("|", $options); # Give extensions a chance to select the file revision for us $time = $sha1 = $descQuery = false; wfRunHooks('BeforeParserFetchFileAndTitle', array($this, $title, &$time, &$sha1, &$descQuery)); # Fetch and register the file (file title may be different via hooks) list($file, $title) = $this->fetchFileAndTitle($title, $time, $sha1); # Get parameter map $handler = $file ? $file->getHandler() : false; list($paramMap, $mwArray) = $this->getImageParams($handler); if (!$file) { $this->addTrackingCategory('broken-file-category'); } # Process the input parameters $caption = ''; $params = array('frame' => array(), 'handler' => array(), 'horizAlign' => array(), 'vertAlign' => array()); foreach ($parts as $part) { $part = trim($part); list($magicName, $value) = $mwArray->matchVariableStartToEnd($part); $validated = false; if (isset($paramMap[$magicName])) { list($type, $paramName) = $paramMap[$magicName]; # Special case; width and height come in one variable together if ($type === 'handler' && $paramName === 'width') { $m = array(); # (bug 13500) In both cases (width/height and width only), # permit trailing "px" for backward compatibility. if (preg_match('/^([0-9]*)x([0-9]*)\\s*(?:px)?\\s*$/', $value, $m)) { $width = intval($m[1]); $height = intval($m[2]); if ($handler->validateParam('width', $width)) { $params[$type]['width'] = $width; $validated = true; } if ($handler->validateParam('height', $height)) { $params[$type]['height'] = $height; $validated = true; } } elseif (preg_match('/^[0-9]*\\s*(?:px)?\\s*$/', $value)) { $width = intval($value); if ($handler->validateParam('width', $width)) { $params[$type]['width'] = $width; $validated = true; } } # else no validation -- bug 13436 } else { if ($type === 'handler') { # Validate handler parameter $validated = $handler->validateParam($paramName, $value); } else { # Validate internal parameters switch ($paramName) { case 'manualthumb': case 'alt': # @todo FIXME: Possibly check validity here for # manualthumb? downstream behavior seems odd with # missing manual thumbs. $validated = true; $value = $this->stripAltText($value, $holders); break; case 'link': $chars = self::EXT_LINK_URL_CLASS; $prots = $this->mUrlProtocols; if ($value === '') { $paramName = 'no-link'; $value = true; $validated = true; } elseif (preg_match("/^{$prots}/", $value)) { if (preg_match("/^({$prots}){$chars}+\$/", $value, $m)) { $paramName = 'link-url'; $this->mOutput->addExternalLink($value); if ($this->mOptions->getExternalLinkTarget()) { $params[$type]['link-target'] = $this->mOptions->getExternalLinkTarget(); } $validated = true; } } else { $linkTitle = Title::newFromText($value); if ($linkTitle) { $paramName = 'link-title'; $value = $linkTitle; $this->mOutput->addLink($linkTitle); $validated = true; } } break; default: # Most other things appear to be empty or numeric... $validated = $value === false || is_numeric(trim($value)); } } if ($validated) { $params[$type][$paramName] = $value; } } } if (!$validated) { $caption = $part; } } # Process alignment parameters if ($params['horizAlign']) { $params['frame']['align'] = key($params['horizAlign']); } if ($params['vertAlign']) { $params['frame']['valign'] = key($params['vertAlign']); } $params['frame']['caption'] = $caption; # Will the image be presented in a frame, with the caption below? $imageIsFramed = isset($params['frame']['frame']) || isset($params['frame']['framed']) || isset($params['frame']['thumbnail']) || isset($params['frame']['manualthumb']); # In the old days, [[Image:Foo|text...]] would set alt text. Later it # came to also set the caption, ordinary text after the image -- which # makes no sense, because that just repeats the text multiple times in # screen readers. It *also* came to set the title attribute. # # Now that we have an alt attribute, we should not set the alt text to # equal the caption: that's worse than useless, it just repeats the # text. This is the framed/thumbnail case. If there's no caption, we # use the unnamed parameter for alt text as well, just for the time be- # ing, if the unnamed param is set and the alt param is not. # # For the future, we need to figure out if we want to tweak this more, # e.g., introducing a title= parameter for the title; ignoring the un- # named parameter entirely for images without a caption; adding an ex- # plicit caption= parameter and preserving the old magic unnamed para- # meter for BC; ... if ($imageIsFramed) { # Framed image if ($caption === '' && !isset($params['frame']['alt'])) { # No caption or alt text, add the filename as the alt text so # that screen readers at least get some description of the image $params['frame']['alt'] = $title->getText(); } # Do not set $params['frame']['title'] because tooltips don't make sense # for framed images } else { # Inline image if (!isset($params['frame']['alt'])) { # No alt text, use the "caption" for the alt text if ($caption !== '') { $params['frame']['alt'] = $this->stripAltText($caption, $holders); } else { # No caption, fall back to using the filename for the # alt text $params['frame']['alt'] = $title->getText(); } } # Use the "caption" for the tooltip text $params['frame']['title'] = $this->stripAltText($caption, $holders); } wfRunHooks('ParserMakeImageParams', array($title, $file, &$params)); # Linker does the rest $ret = Linker::makeImageLink2($title, $file, $params['frame'], $params['handler'], $time, $descQuery, $this->mOptions->getThumbSize()); # Give the handler a chance to modify the parser object if ($handler) { $handler->parserTransformHook($this, $file); } return $ret; }
/** * Create image link in MediaWiki 1.10 * * @param Title $nt * @param string $label label text * @param string $alt alt text * @param string $align horizontal alignment: none, left, center, right) * @param array $params Parameters to be passed to the media handler * @param boolean $framed shows image in original size in a frame * @param boolean $thumb shows image as thumbnail in a frame * @param string $manual_thumb image name for the manual thumbnail * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom * @return string * */ function makeImageLinkObj($nt, $label, $alt, $align = '', $params = array(), $framed = false, $thumb = false, $manual_thumb = '', $valign = '') { $orginal = $nt->getText(); $img = wfFindFile($nt); $found = $img->getURL(); if (!is_null($alt) && $alt == 'RTENOTITLE') { // 2223 $alt = ''; } if ($found) { // trick to get real URL for image: $frameParams = array('alt' => $alt, 'caption' => $label, 'align' => $align, 'framed' => $framed, 'thumbnail' => $thumb, 'manualthumb' => $manual_thumb, 'valign' => $valign); $originalLink = strip_tags(Linker::makeImageLink2($nt, $img, $frameParams, $params), '<img>'); $srcPart = substr($originalLink, strpos($originalLink, "src=") + 5); $url = strtok($srcPart, '"'); } $ret = '<img '; if ($found) { $ret .= "src=\"{$url}\" "; } else { $ret .= "_fck_mw_valid=\"false" . "\" "; } $ret .= "_fck_mw_filename=\"{$orginal}\" "; if ($align) { $ret .= "_fck_mw_location=\"" . strtolower($align) . "\" "; } if (!empty($params)) { if (isset($params['width'])) { $ret .= "_fck_mw_width=\"" . $params['width'] . "\" "; } if (isset($params['height'])) { $ret .= "_fck_mw_height=\"" . $params['height'] . "\" "; } } $class = ''; if ($thumb) { $ret .= "_fck_mw_type=\"thumb" . "\" "; $class .= "fck_mw_frame"; } elseif ($framed) { $ret .= "_fck_mw_type=\"frame" . "\" "; $class .= "fck_mw_frame"; } if ($align == 'right') { $class .= ($class ? ' ' : '') . 'fck_mw_right'; } elseif ($align == 'center') { $class .= ($class ? ' ' : '') . 'fck_mw_center'; } elseif ($align == 'left') { $class .= ($class ? ' ' : '') . 'fck_mw_left'; } elseif ($framed || $thumb) { $class .= ($class ? ' ' : '') . 'fck_mw_right'; } if (!$found) { $class .= ($class ? ' ' : '') . 'fck_mw_notfound'; } if (!is_null($alt) && !empty($alt) && false !== strpos(FCKeditorParser::$fkc_mw_makeImage_options, $alt) && $alt != 'Image:' . $orginal) { $ret .= "alt=\"" . htmlspecialchars($alt) . "\" "; } else { $ret .= "alt=\"\" "; } if ($class) { $ret .= "class=\"{$class}\" "; } $ret .= '/>'; return $ret; }
function makeImageLink2(Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "") { if (!$file || !$file->exists()) { return ""; } // remove none bitmap links if ($file->getMediaType() != "BITMAP" && $file->getMediaType() != "DRAWING" || preg_match('/\\.djvu$/', $title)) { return ""; } $html = Linker::makeImageLink2($title, $file, $frameParams, $handlerParams, $time, $query); // remove image links, the test is a trick to avoid doing that for imagemap pictures $trace = debug_backtrace(); $caller = $trace[2]; if ($caller['class'] == 'ParserOriginal' || $caller['class'] == 'Parser') { preg_match_all('/<a [^>]*>(.*?<img.*?)<\\/a>/s', $html, $matches); if (count($matches)) { $html = str_replace($matches[0], $matches[1], $html); } } return $html; }
/** * Make an image link in MediaWiki 1.11 * @param Title $title Title object * @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. * caption HTML for image caption. * * @param array $handlerParams Associative array of media handler parameters, to be passed * to transform(). Typical keys are "width" and "page". */ function makeImageLink2(Title $nt, $file, $frameParams = array(), $handlerParams = array()) { $orginal = $nt->getText(); $img = new Image($nt); $imgName = $img->getName(); $found = $img->getURL(); if (!empty($frameParams['alt']) && $frameParams['alt'] == 'RTENOTITLE') { // 2223 $frameParams['alt'] = ''; } if ($found) { $linker = new Linker(); $originalLink = $linker->makeImageLink2($nt, $file, $frameParams, $handlerParams); if (false !== strpos($originalLink, "src=\"")) { $srcPart = substr($originalLink, strpos($originalLink, "src=") + 5); $url = strtok($srcPart, '"'); } $srcPart = substr($originalLink, strpos($originalLink, "src=") + 5); $url = strtok($srcPart, '"'); } // Shortcuts $fp =& $frameParams; $hp =& $handlerParams; if (!isset($fp['align'])) { $fp['align'] = ''; } $ret = '<img '; if ($found) { $ret .= "src=\"{$url}\" "; } else { $ret .= "_fck_mw_valid=\"false" . "\" "; } $ret .= "_fck_mw_filename=\"{$orginal}\" "; if ($fp['align']) { $ret .= "_fck_mw_location=\"" . strtolower($fp['align']) . "\" "; } if (!empty($hp)) { if (isset($hp['width'])) { $ret .= "_fck_mw_width=\"" . $hp['width'] . "\" "; } if (isset($hp['height'])) { $ret .= "_fck_mw_height=\"" . $hp['height'] . "\" "; } } $class = ''; if (isset($fp['thumbnail'])) { $ret .= "_fck_mw_type=\"thumb" . "\" "; $class .= 'fck_mw_frame'; } else { if (isset($fp['border'])) { $ret .= "_fck_mw_type=\"border" . "\" "; $class .= 'fck_mw_border'; } else { if (isset($fp['framed'])) { $ret .= "_fck_mw_type=\"frame" . "\" "; $class .= 'fck_mw_frame'; } } } if ($fp['align'] == 'right') { $class .= ($class ? ' ' : '') . 'fck_mw_right'; } else { if ($fp['align'] == 'center') { $class .= ($class ? ' ' : '') . 'fck_mw_center'; } else { if ($fp['align'] == 'left') { $class .= ($class ? ' ' : '') . 'fck_mw_left'; } else { if (isset($fp['framed']) || isset($fp['thumbnail'])) { $class .= ($class ? ' ' : '') . 'fck_mw_right'; } } } } if (!$found) { $class .= ($class ? ' ' : '') . 'fck_mw_notfound'; } if (isset($fp['alt']) && !empty($fp['alt']) && $fp['alt'] != 'Image:' . $orginal) { $ret .= "alt=\"" . htmlspecialchars($fp['alt']) . "\" "; } else { $ret .= "alt=\"\" "; } if ($class) { $ret .= "class=\"{$class}\" "; } if (isset($fp['no-link'])) { $ret .= 'no-link="1" '; } if (isset($fp['link-title']) && is_object($fp['link-title'])) { $ret .= 'link="' . htmlentities($fp['link-title']->getFullText()) . '" '; } if (isset($fp['link-url'])) { $ret .= 'link="' . $fp['link-url'] . '" '; } $ret .= '/>'; return $ret; }