Пример #1
0
 /**
  * @deprecated since 1.16 Use link()
  *
  * Make a link for a title which definitely exists. This is faster than makeLinkObj because
  * it doesn't have to do a database query. It's also valid for interwiki titles and special
  * pages.
  *
  * @param $title  Title object of target page
  * @param $text   String: text to replace the title
  * @param $query  String: link target
  * @param $trail  String: text after link
  * @param $prefix String: text before link text
  * @param $aprops String: extra attributes to the a-element
  * @param $style  String: style to apply - if empty, use getInternalLinkAttributesObj instead
  * @return the a-element
  */
 static function makeKnownLinkObj($title, $text = '', $query = '', $trail = '', $prefix = '', $aprops = '', $style = '')
 {
     wfProfileIn(__METHOD__);
     if ($text == '') {
         $text = self::linkText($title);
     }
     $attribs = Sanitizer::mergeAttributes(Sanitizer::decodeTagAttributes($aprops), Sanitizer::decodeTagAttributes($style));
     $query = wfCgiToArray($query);
     list($inside, $trail) = self::splitTrail($trail);
     $ret = self::link($title, "{$prefix}{$text}{$inside}", $attribs, $query, array('known', 'noclasses')) . $trail;
     wfProfileOut(__METHOD__);
     return $ret;
 }
Пример #2
0
 /**
  * Return a HTML representation of the image gallery
  *
  * For each image in the gallery, display
  * - a thumbnail
  * - the image name
  * - the additional text provided when adding the image
  * - the size of the image
  *
  */
 function toHTML()
 {
     global $wgLang;
     $sk = $this->getSkin();
     $attribs = Sanitizer::mergeAttributes(array('class' => 'gallery', 'cellspacing' => '0', 'cellpadding' => '0'), $this->mAttribs);
     $s = Xml::openElement('table', $attribs);
     if ($this->mCaption) {
         $s .= "\n\t<caption>{$this->mCaption}</caption>";
     }
     $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
     $i = 0;
     foreach ($this->mImages as $pair) {
         $nt = $pair[0];
         $text = $pair[1];
         # Give extensions a chance to select the file revision for us
         $time = $descQuery = false;
         wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
         $img = wfFindFile($nt, $time);
         if ($nt->getNamespace() != NS_FILE || !$img) {
             # We're dealing with a non-image, spit out the name and be done with it.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($nt->getText()) . '</div>';
         } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
             # The image is blacklisted, just show it as a text link.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . $sk->makeKnownLinkObj($nt, htmlspecialchars($nt->getText())) . '</div>';
         } elseif (!($thumb = $img->transform($params))) {
             # Error generating thumbnail.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
         } else {
             $vpad = floor((1.25 * $this->mHeights - $thumb->height) / 2) - 2;
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="padding: ' . $vpad . 'px 0; width: ' . ($this->mWidths + 30) . 'px;">' . '<div style="margin-left: auto; margin-right: auto; width: ' . $this->mWidths . 'px;">' . $thumb->toHtml(array('desc-link' => true, 'desc-query' => $descQuery)) . '</div></div>';
             // Call parser transform hook
             if ($this->mParser && $img->getHandler()) {
                 $img->getHandler()->parserTransformHook($this->mParser, $img);
             }
         }
         //TODO
         //$ul = $sk->makeLink( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}", $ut );
         if ($this->mShowBytes) {
             if ($img) {
                 $nb = wfMsgExt('nbytes', array('parsemag', 'escape'), $wgLang->formatNum($img->getSize()));
             } else {
                 $nb = wfMsgHtml('filemissing');
             }
             $nb = "{$nb}<br />\n";
         } else {
             $nb = '';
         }
         $textlink = $this->mShowFilename ? $sk->makeKnownLinkObj($nt, htmlspecialchars($wgLang->truncate($nt->getText(), 20, '...'))) . "<br />\n" : '';
         # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
         # in version 4.8.6 generated crackpot html in its absence, see:
         # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
         if ($i % $this->mPerRow == 0) {
             $s .= "\n\t<tr>";
         }
         $s .= "\n\t\t" . '<td><div class="gallerybox" style="width: ' . ($this->mWidths + 35) . 'px;">' . $thumbhtml . "\n\t\t\t" . '<div class="gallerytext">' . "\n" . $textlink . $text . $nb . "\n\t\t\t</div>" . "\n\t\t</div></td>";
         if ($i % $this->mPerRow == $this->mPerRow - 1) {
             $s .= "\n\t</tr>";
         }
         ++$i;
     }
     if ($i % $this->mPerRow != 0) {
         $s .= "\n\t</tr>";
     }
     $s .= "\n</table>";
     return $s;
 }
 /**
  * Return a HTML representation of the image gallery
  *
  * For each image in the gallery, display
  * - a thumbnail
  * - the image name
  * - the additional text provided when adding the image
  * - the size of the image
  *
  * @return string
  */
 function toHTML()
 {
     if ($this->mPerRow > 0) {
         $maxwidth = $this->mPerRow * ($this->mWidths + $this->getAllPadding());
         $oldStyle = isset($this->mAttribs['style']) ? $this->mAttribs['style'] : '';
         # _width is ignored by any sane browser. IE6 doesn't know max-width
         # so it uses _width instead
         $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
     }
     $attribs = Sanitizer::mergeAttributes(['class' => 'gallery mw-gallery-' . $this->mMode], $this->mAttribs);
     $modules = $this->getModules();
     if ($this->mParser) {
         $this->mParser->getOutput()->addModules($modules);
         $this->mParser->getOutput()->addModuleStyles('mediawiki.page.gallery.styles');
     } else {
         $this->getOutput()->addModules($modules);
         $this->getOutput()->addModuleStyles('mediawiki.page.gallery.styles');
     }
     $output = Xml::openElement('ul', $attribs);
     if ($this->mCaption) {
         $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
     }
     if ($this->mShowFilename) {
         // Preload LinkCache info for when generating links
         // of the filename below
         $lb = new LinkBatch();
         foreach ($this->mImages as $img) {
             $lb->addObj($img[0]);
         }
         $lb->execute();
     }
     $lang = $this->getRenderLang();
     # Output each image...
     foreach ($this->mImages as $pair) {
         /** @var Title $nt */
         $nt = $pair[0];
         $text = $pair[1];
         # "text" means "caption" here
         $alt = $pair[2];
         $link = $pair[3];
         $descQuery = false;
         if ($nt->getNamespace() === NS_FILE) {
             # Get the file...
             if ($this->mParser instanceof Parser) {
                 # Give extensions a chance to select the file revision for us
                 $options = [];
                 Hooks::run('BeforeParserFetchFileAndTitle', [$this->mParser, $nt, &$options, &$descQuery]);
                 # Fetch and register the file (file title may be different via hooks)
                 list($img, $nt) = $this->mParser->fetchFileAndTitle($nt, $options);
             } else {
                 $img = wfFindFile($nt);
             }
         } else {
             $img = false;
         }
         $params = $this->getThumbParams($img);
         // $pair[4] is per image handler options
         $transformOptions = $params + $pair[4];
         $thumb = false;
         if (!$img) {
             # We're dealing with a non-image, spit out the name and be done with it.
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ($this->getThumbPadding() + $this->mHeights) . 'px;">' . htmlspecialchars($nt->getText()) . '</div>';
             if ($this->mParser instanceof Parser) {
                 $this->mParser->addTrackingCategory('broken-file-category');
             }
         } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
             # The image is blacklisted, just show it as a text link.
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ($this->getThumbPadding() + $this->mHeights) . 'px;">' . Linker::linkKnown($nt, htmlspecialchars($nt->getText())) . '</div>';
         } else {
             $thumb = $img->transform($transformOptions);
             if (!$thumb) {
                 # Error generating thumbnail.
                 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ($this->getThumbPadding() + $this->mHeights) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
             } else {
                 /** @var MediaTransformOutput $thumb */
                 $vpad = $this->getVPad($this->mHeights, $thumb->getHeight());
                 $imageParameters = ['desc-link' => true, 'desc-query' => $descQuery, 'alt' => $alt, 'custom-url-link' => $link];
                 // In the absence of both alt text and caption, fall back on
                 // providing screen readers with the filename as alt text
                 if ($alt == '' && $text == '') {
                     $imageParameters['alt'] = $nt->getText();
                 }
                 $this->adjustImageParameters($thumb, $imageParameters);
                 Linker::processResponsiveImages($img, $thumb, $transformOptions);
                 # Set both fixed width and min-height.
                 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="width: ' . $this->getThumbDivWidth($thumb->getWidth()) . 'px;">' . '<div style="margin:' . $vpad . 'px auto;">' . $thumb->toHtml($imageParameters) . '</div></div>';
                 // Call parser transform hook
                 /** @var MediaHandler $handler */
                 $handler = $img->getHandler();
                 if ($this->mParser && $handler) {
                     $handler->parserTransformHook($this->mParser, $img);
                 }
             }
         }
         // @todo Code is incomplete.
         // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) .
         // ":{$ut}" );
         // $ul = Linker::link( $linkTarget, $ut );
         if ($this->mShowBytes) {
             if ($img) {
                 $fileSize = htmlspecialchars($lang->formatSize($img->getSize()));
             } else {
                 $fileSize = $this->msg('filemissing')->escaped();
             }
             $fileSize = "{$fileSize}<br />\n";
         } else {
             $fileSize = '';
         }
         $textlink = $this->mShowFilename ? Linker::linkKnown($nt, htmlspecialchars($lang->truncate($nt->getText(), $this->mCaptionLength))) . "<br />\n" : '';
         $galleryText = $textlink . $text . $fileSize;
         $galleryText = $this->wrapGalleryText($galleryText, $thumb);
         # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
         # Can be safely removed if FF2 falls completely out of existence
         $output .= "\n\t\t" . '<li class="gallerybox" style="width: ' . $this->getGBWidth($thumb) . 'px">' . '<div style="width: ' . $this->getGBWidth($thumb) . 'px">' . $thumbhtml . $galleryText . "\n\t\t</div></li>";
     }
     $output .= "\n</ul>";
     return $output;
 }
Пример #4
0
 /**
  * Returns the array of attributes used when linking to the Title $target
  *
  * @param Title $target
  * @param array $attribs
  * @param array $options
  *
  * @return array
  */
 private static function linkAttribs($target, $attribs, $options)
 {
     global $wgUser;
     $defaults = array();
     if (!in_array('noclasses', $options)) {
         # Now build the classes.
         $classes = array();
         if (in_array('broken', $options)) {
             $classes[] = 'new';
         }
         if ($target->isExternal()) {
             $classes[] = 'extiw';
         }
         if (!in_array('broken', $options)) {
             # Avoid useless calls to LinkCache (see r50387)
             $colour = self::getLinkColour($target, $wgUser->getStubThreshold());
             if ($colour !== '') {
                 $classes[] = $colour;
                 # mw-redirect or stub
             }
         }
         if ($classes != array()) {
             $defaults['class'] = implode(' ', $classes);
         }
     }
     # Get a default title attribute.
     if ($target->getPrefixedText() == '') {
         # A link like [[#Foo]].  This used to mean an empty title
         # attribute, but that's silly.  Just don't output a title.
     } elseif (in_array('known', $options)) {
         $defaults['title'] = $target->getPrefixedText();
     } else {
         // This ends up in parser cache!
         $defaults['title'] = wfMessage('red-link-title', $target->getPrefixedText())->inContentLanguage()->text();
     }
     # Finally, merge the custom attribs with the default ones, and iterate
     # over that, deleting all "false" attributes.
     $ret = array();
     $merged = Sanitizer::mergeAttributes($defaults, $attribs);
     foreach ($merged as $key => $val) {
         # A false value suppresses the attribute, and we don't want the
         # href attribute to be overridden.
         if ($key != 'href' && $val !== false) {
             $ret[$key] = $val;
         }
     }
     return $ret;
 }
 function toHTML()
 {
     global $wgLang, $mvDefaultAspectRatio;
     $sk = $this->getSkin();
     $attribs = Sanitizer::mergeAttributes(array('class' => 'gallery', 'cellspacing' => '0', 'cellpadding' => '0'), $this->mAttribs);
     $s = Xml::openElement('table', $attribs);
     if ($this->mCaption) {
         $s .= "\n\t<caption>" . htmlspecialchars($this->mCaption) . "</caption>";
     }
     $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
     $i = 0;
     $this->already_named_resource = array();
     foreach ($this->mImages as $pair) {
         $nt = $pair[0];
         $text = $pair[1];
         # Give extensions a chance to select the file revision for us
         $time = false;
         wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time));
         $img = wfFindFile($nt, array('time' => $time));
         if ($nt->getNamespace() == MV_NS_MVD || $nt->getNamespace() == MV_NS_STREAM || $nt->getNamespace() == MV_NS_SEQUENCE) {
             // @@todo fix sequence embed
             // $vpad = floor( ( 1.25*$this->mHeights - $thumb->height ) /2 ) - 2;
             $mvTitle = new MV_Title($nt);
             // remap MVD namespace links into the Stream view (so contextual metadata is present)
             if ($nt->getNamespace() == MV_NS_MVD) {
                 $nt = Title::MakeTitle(MV_NS_STREAM, ucfirst($mvTitle->getStreamName()) . '/' . $mvTitle->getTimeRequest());
             }
             $vidH = round($this->mWidths * $mvDefaultAspectRatio);
             $vidRes = $this->mWidths . 'x' . $vidH;
             // print "img url: " . 	$mvTitle->getStreamImageURL();
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="padding: 4px 0; width: ' . htmlspecialchars($this->mWidths + 5) . 'px;">' . '<div style="margin-left: auto; margin-right: auto; width: ' . htmlspecialchars($this->mWidths) . 'px;">' . $sk->makeKnownLinkObj($nt, '<img title="' . htmlspecialchars($mvTitle->getStreamNameText()) . '"' . ' width="160" height="120" src="' . $mvTitle->getStreamImageURL('160x120') . '">') . '</div>' . '</div>' . '<span class="gallerytext" style="float:left">' . $sk->makeKnownLinkObj($nt, $mvTitle->getStreamNameText() . ' ' . $mvTitle->getTimeDesc()) . '</span>' . '</div>';
             $nb = '';
             $textlink = '';
         } else {
             if ($nt->getNamespace() != NS_IMAGE || !$img) {
                 # We're dealing with a non-image, spit out the name and be done with it.
                 $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($nt->getText()) . '</div>';
             } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
                 # The image is blacklisted, just show it as a text link.
                 $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . $sk->makeKnownLinkObj($nt, htmlspecialchars($nt->getText())) . '</div>';
             } elseif (!($thumb = $img->transform($params))) {
                 # Error generating thumbnail.
                 $thumbhtml = "\n\t\t\t" . '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
             } else {
                 $vpad = floor((1.25 * $this->mHeights - $thumb->height) / 2) - 2;
                 $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="padding: ' . htmlspecialchars($vpad) . 'px 0; width: ' . htmlspecialchars($this->mWidths + 30) . 'px;">' . '<div style="margin-left: auto; margin-right: auto; width: ' . htmlspecialchars($this->mWidths) . 'px;">' . $thumb->toHtml(array('desc-link' => true)) . '</div></div>';
                 // Call parser transform hook
                 if ($this->mParser && $img->getHandler()) {
                     $img->getHandler()->parserTransformHook($this->mParser, $img);
                 }
             }
             if ($this->mShowBytes) {
                 if ($img) {
                     $nb = wfMsgExt('nbytes', array('parsemag', 'escape'), $wgLang->formatNum($img->getSize()));
                 } else {
                     $nb = wfMsgHtml('filemissing');
                 }
                 $nb = "{$nb}<br />\n";
             } else {
                 $nb = '';
             }
             $textlink = $this->mShowFilename ? $sk->makeKnownLinkObj($nt, htmlspecialchars($wgLang->truncate($nt->getText(), 20))) . "<br />\n" : '';
         }
         # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
         # in version 4.8.6 generated crackpot html in its absence, see:
         # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
         if ($i % $this->mPerRow == 0) {
             $s .= "\n\t<tr>";
         }
         $s .= "\n\t\t" . '<td><div class="gallerybox" style="width: ' . ($this->mWidths + 10) . 'px;">' . $thumbhtml . "\n\t\t\t" . '<div class="gallerytext">' . "\n" . $textlink . htmlspecialchars($text) . $nb . "\n\t\t\t</div>" . "\n\t\t</div></td>";
         if ($i % $this->mPerRow == $this->mPerRow - 1) {
             $s .= "\n\t</tr>";
         }
         ++$i;
     }
     if ($i % $this->mPerRow != 0) {
         $s .= "\n\t</tr>";
     }
     $s .= "\n</table>";
     return $s;
 }
Пример #6
0
 /**
  * Return a HTML representation of the image Carrousel
  *
  * For each image in the gallery, display
  * - a thumbnail
  * - the image name
  * - the additional text provided when adding the image
  * - the size of the image
  *
  */
 public function toHTML()
 {
     $car_photos = '';
     $car_slider = '';
     # Output each image...
     foreach ($this->mImages as $pair) {
         $nt = $pair[0];
         $text = $pair[1];
         # "text" means "caption" here
         $alt = $pair[2];
         $titleLink = $pair[3];
         // Searching the image
         $descQuery = false;
         if ($nt->getNamespace() == NS_FILE) {
             # Get the file...
             if ($this->mParser instanceof Parser) {
                 # Give extensions a chance to select the file revision for us
                 $time = $sha1 = false;
                 wfRunHooks('BeforeParserFetchFileAndTitle', array($this->mParser, $nt, &$time, &$sha1, &$descQuery));
                 # Fetch and register the file (file title may be different via hooks)
                 list($img, $nt) = $this->mParser->fetchFileAndTitle($nt, $time, $sha1);
             } else {
                 $img = wfFindFile($nt);
             }
         } else {
             $img = false;
         }
         $car_photos .= Html::rawElement('li', array(), $this->photoToHTML($img, $nt, $text, $alt, $titleLink, $descQuery));
         $car_slider .= Html::rawElement('li', array(), $this->thumbToHTML($img, $nt, $text, $alt, $descQuery));
     }
     $car_photos = Html::rawElement('ul', array(), $car_photos);
     $photoHeight = $this->mPhotoHeight + self::CAPTIONHEIGHT;
     $car_photos = Html::rawElement('div', array('id' => 'car_photos', 'style' => 'height:' . $photoHeight . 'px'), $car_photos);
     $car_slider = Html::rawElement('ul', array(), $car_slider);
     $car_slider = Html::rawElement('div', array('class' => 'car_slider_window'), $car_slider);
     $car_slider = Html::rawElement('div', array('id' => 'car_slider'), $car_slider);
     $attribs = Sanitizer::mergeAttributes(array('id' => 'carrousel'), $this->mAttribs);
     $output = Html::rawElement('div', $attribs, $car_photos . $car_slider);
     return $output;
 }
Пример #7
0
 function _attribs($tag, $defaults = array(), $overrides = array())
 {
     $attribs = Sanitizer::validateTagAttributes($this->params, $tag);
     $attribs = Sanitizer::mergeAttributes($defaults, $attribs);
     $attribs = Sanitizer::mergeAttributes($attribs, $overrides);
     return $attribs;
 }
Пример #8
0
 /**
  * Return a HTML representation of the image slideshow
  */
 private function renderSlideshow()
 {
     global $wgStylePath;
     wfProfileIn(__METHOD__);
     // don't render empty slideshows
     if (empty($this->mFiles)) {
         wfProfileOut(__METHOD__);
         return '';
     }
     // If we can, render this as a media gallery
     if ($this->canRenderMediaGallery()) {
         $html = $this->renderMediaGallery();
         wfProfileOut(__METHOD__);
         return trim(preg_replace('/\\n+/', ' ', $html));
     }
     /** @var Skin|Linker $sk The Skin object falls back to Linker methods */
     $sk = RequestContext::getMain()->getSkin();
     // slideshow wrapper CSS class
     $class = 'wikia-slideshow clearfix';
     $id = "slideshow-{$this->mData['id']}";
     // do not add button for galleries from templates
     if (isset($this->mData['params']['source']) && $this->mData['params']['source'] == "template") {
         $class .= ' template';
     }
     // support "position" attribute (slideshow alignment)
     switch ($this->getParam('position')) {
         case 'left':
             $class .= ' floatleft';
             break;
         case 'center':
             $class .= ' slideshow-center';
             break;
         case 'right':
             $class .= ' floatright';
             break;
     }
     // wrap image slideshow inside div.slideshow
     $attribs = Sanitizer::mergeAttributes(array('class' => $class, 'data-hash' => $this->mData['hash'], 'data-crop' => $this->mCrop, 'id' => $id), $this->mAttribs);
     //renderSlideshow for WikiaMobile
     if (F::app()->checkSkin('wikiamobile')) {
         $slideshowHtml = $this->renderWikiaMobileMediaGroup();
     } else {
         $slideshowHtml = Xml::openElement('div', $attribs);
         // render slideshow caption
         if ($this->mCaption) {
             $slideshowHtml .= '<div class="wikia-slideshow-caption">' . $this->mCaption . '</div>';
         }
         // fit images inside width:height = 4:3 box
         $this->mHeights = round($this->mWidths * 3 / 4);
         $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
         wfDebug(__METHOD__ . ": slideshow {$params['width']}x{$params['height']}\n");
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-wrapper', 'style' => 'width: ' . ($this->mWidths + 10) . 'px'));
         // wrap images inside <div> and <ul>
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-images-wrapper accent'));
         $slideshowHtml .= Xml::openElement('ul', array('class' => 'wikia-slideshow-images neutral', 'style' => "height: {$params['height']}px; width: {$params['width']}px"));
         $index = 0;
         foreach ($this->mFiles as $p => $pair) {
             /**
              * @var $nt Title
              */
             $nt = $pair[0];
             $text = $pair[1];
             $link = $pair[2];
             # Give extensions a chance to select the file revision for us
             $time = $descQuery = false;
             wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
             $img = wfFindFile($nt, $time);
             if (WikiaFileHelper::isFileTypeVideo($img)) {
                 continue;
             }
             $thumb = null;
             // let's properly scale image (don't make it bigger than original size) and handle "crop" attribute
             if (is_object($img) && $nt->getNamespace() == NS_FILE) {
                 $thumbParams = WikiaPhotoGalleryHelper::getThumbnailDimensions($img, $params['width'], $params['height'], $this->mCrop);
             }
             $caption = $linkOverlay = '';
             // render caption overlay
             if ($text != '') {
                 $caption = Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption')) . Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption-inner')) . $text . Xml::closeElement('span') . Xml::closeElement('span');
             }
             // parse link
             $linkAttribs = $this->parseLink($nt->getLocalUrl(), $nt->getText(), $link);
             // extra link tag attributes
             $linkAttribs['id'] = "{$id}-{$index}";
             $linkAttribs['style'] = 'width: ' . ($params['width'] - 80) . 'px';
             if ($link == '') {
                 // tooltip to be used for not-linked images
                 $linkAttribs['title'] = wfMessage('wikiaPhotoGallery-slideshow-view-popout-tooltip')->text();
                 $linkAttribs['class'] = 'wikia-slideshow-image';
                 unset($linkAttribs['href']);
             } else {
                 // linked images
                 $linkAttribs['class'] .= ' wikia-slideshow-image';
                 // support |linktext= syntax
                 if ($this->mData['images'][$p]['linktext'] != '') {
                     $linkText = $this->mData['images'][$p]['linktext'];
                 } else {
                     $linkText = $link;
                 }
                 // add link overlay
                 $linkOverlay = Xml::openElement('span', array('class' => 'wikia-slideshow-link-overlay')) . wfMessage('wikiaPhotoGallery-slideshow-view-link-overlay', Sanitizer::removeHTMLtags($linkText))->text() . Xml::closeElement('span');
             }
             // generate HTML for a single slideshow image
             $thumbHtml = null;
             $liAttribs = array('title' => null);
             if ($nt->getNamespace() != NS_FILE || !$img) {
                 # We're dealing with a non-image, spit out the name and be done with it.
                 $thumbHtml = '<a class="image broken-image new" style="line-height: ' . $this->mHeights . 'px;">' . $nt->getText() . '</a>';
             } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
                 # The image is blacklisted, just show it as a text link.
                 $thumbHtml = '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . $sk->makeKnownLinkObj($nt, $nt->getText()) . '</div>';
             } elseif (!($thumb = $img->transform($thumbParams))) {
                 # Error generating thumbnail.
                 $thumbHtml = '<div style="height: ' . ($this->mHeights * 1.25 + 2) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
             } else {
                 $thumbAttribs = array('data-src' => $thumb->url, 'class' => 'thumbimage', 'width' => $thumb->width, 'height' => $thumb->height, 'style' => 'border: 0px;', 'data-image-name' => $img->getTitle()->getText(), 'data-image-key' => $img->getTitle()->getDBKey());
                 if (!empty($this->mData['images'][$p]['data-caption'])) {
                     $thumbAttribs['data-caption'] = $this->mData['images'][$p]['data-caption'];
                 }
                 $thumbHtml = Xml::element('img', $thumbAttribs);
             }
             // add CSS class so we can show first slideshow image before JS is loaded
             if ($index == 0) {
                 $liAttribs['class'] = 'wikia-slideshow-first-image';
             }
             $slideshowHtml .= Xml::openElement('li', $liAttribs) . $thumbHtml . Xml::element('a', $linkAttribs, ' ') . $caption . $linkOverlay . '</li>';
             $index++;
             // Call parser transform hook
             if ($this->mParser && is_object($img) && $img->getHandler()) {
                 $img->getHandler()->parserTransformHook($this->mParser, $img);
             }
             if (is_object($thumb)) {
                 wfDebug(__METHOD__ . ": image '" . $nt->getText() . "' {$thumb->width}x{$thumb->height}\n");
             }
         }
         $slideshowHtml .= Xml::closeElement('ul');
         $slideshowHtml .= Xml::closeElement('div');
         // render prev/next buttons
         global $wgBlankImgUrl;
         $top = ($params['height'] >> 1) - 30 + 5;
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-prev-next'));
         // prev
         $slideshowHtml .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-prev', 'style' => "top: {$top}px", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-prev-tooltip')->text()));
         $slideshowHtml .= Xml::openElement('span');
         $slideshowHtml .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
         $slideshowHtml .= Xml::closeElement('span');
         $slideshowHtml .= Xml::closeElement('a');
         // next
         $slideshowHtml .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-next', 'style' => "top: {$top}px", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-next-tooltip')->text()));
         $slideshowHtml .= Xml::openElement('span');
         $slideshowHtml .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
         $slideshowHtml .= Xml::closeElement('span');
         $slideshowHtml .= Xml::closeElement('a');
         $slideshowHtml .= Xml::closeElement('div');
         // render slideshow toolbar
         $slideshowHtml .= Xml::openElement('div', array('class' => 'wikia-slideshow-toolbar clearfix', 'style' => 'display: none'));
         // Pop-out icon, "X of X" counter
         $counterValue = wfMessage('wikiaPhotoGallery-slideshow-view-number', '$1', $index)->text();
         $slideshowHtml .= Xml::openElement('div', array('style' => 'float: left'));
         $slideshowHtml .= Xml::element('img', array('class' => 'wikia-slideshow-popout lightbox', 'height' => 11, 'src' => "{$wgStylePath}/common/images/magnify-clip.png", 'title' => wfMessage('wikiaPhotoGallery-slideshow-view-popout-tooltip')->text(), 'width' => 15));
         $slideshowHtml .= Xml::element('span', array('class' => 'wikia-slideshow-toolbar-counter', 'data-counter' => $counterValue), str_replace('$1', '1', $counterValue));
         $slideshowHtml .= Xml::closeElement('div');
         // "Add Image"
         if (!empty($this->mShowAddButton)) {
             $slideshowHtml .= Xml::element('a', array('class' => 'wikia-slideshow-addimage wikia-button secondary', 'style' => 'float: right'), wfMessage('wikiaPhotoGallery-slideshow-view-addphoto')->inContentLanguage()->text());
         }
         $slideshowHtml .= Xml::closeElement('div');
         // close slideshow wrapper
         $slideshowHtml .= Xml::closeElement('div');
         $slideshowHtml .= Xml::closeElement('div');
         // output JS to init slideshow
         $width = "{$params['width']}px";
         $height = "{$params['height']}px";
         $slideshowHtml .= JSSnippets::addToStack(array('wikia_photo_gallery_slideshow_js', 'wikia_photo_gallery_slideshow_scss'), array(), 'WikiaPhotoGallerySlideshow.init', array('id' => $id, 'width' => $width, 'height' => $height));
     }
     wfProfileOut(__METHOD__);
     return $slideshowHtml;
 }
 /**
  * Return a HTML representation of the image gallery
  *
  * For each image in the gallery, display
  * - a thumbnail
  * - the image name
  * - the additional text provided when adding the image
  * - the size of the image
  *
  * @return string
  */
 function toHTML()
 {
     if ($this->mPerRow > 0) {
         $maxwidth = $this->mPerRow * ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS);
         $oldStyle = isset($this->mAttribs['style']) ? $this->mAttribs['style'] : '';
         # _width is ignored by any sane browser. IE6 doesn't know max-width so it uses _width instead
         $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
     }
     $attribs = Sanitizer::mergeAttributes(array('class' => 'gallery'), $this->mAttribs);
     $output = Xml::openElement('ul', $attribs);
     if ($this->mCaption) {
         $output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
     }
     $lang = $this->getLang();
     $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
     # Output each image...
     foreach ($this->mImages as $pair) {
         $nt = $pair[0];
         $text = $pair[1];
         # "text" means "caption" here
         $alt = $pair[2];
         $link = $pair[3];
         $descQuery = false;
         if ($nt->getNamespace() == NS_FILE) {
             # Get the file...
             if ($this->mParser instanceof Parser) {
                 # Give extensions a chance to select the file revision for us
                 $options = array();
                 wfRunHooks('BeforeParserFetchFileAndTitle', array($this->mParser, $nt, &$options, &$descQuery));
                 # Fetch and register the file (file title may be different via hooks)
                 list($img, $nt) = $this->mParser->fetchFileAndTitle($nt, $options);
             } else {
                 $img = wfFindFile($nt);
             }
         } else {
             $img = false;
         }
         if (!$img) {
             # We're dealing with a non-image, spit out the name and be done with it.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . htmlspecialchars($nt->getText()) . '</div>';
         } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
             # The image is blacklisted, just show it as a text link.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . Linker::link($nt, htmlspecialchars($nt->getText()), array(), array(), array('known', 'noclasses')) . '</div>';
         } elseif (!($thumb = $img->transform($params))) {
             # Error generating thumbnail.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
         } else {
             $vpad = (self::THUMB_PADDING + $this->mHeights - $thumb->height) / 2;
             $imageParameters = array('desc-link' => true, 'desc-query' => $descQuery, 'alt' => $alt, 'custom-url-link' => $link);
             # In the absence of both alt text and caption, fall back on providing screen readers with the filename as alt text
             if ($alt == '' && $text == '') {
                 $imageParameters['alt'] = $nt->getText();
             }
             # Set both fixed width and min-height.
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="width: ' . ($this->mWidths + self::THUMB_PADDING) . 'px;">' . '<div style="margin:' . $vpad . 'px auto;">' . $thumb->toHtml($imageParameters) . '</div></div>';
             // Call parser transform hook
             if ($this->mParser && $img->getHandler()) {
                 $img->getHandler()->parserTransformHook($this->mParser, $img);
             }
         }
         //TODO
         // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}" );
         // $ul = Linker::link( $linkTarget, $ut );
         if ($this->mShowBytes) {
             if ($img) {
                 $fileSize = htmlspecialchars($lang->formatSize($img->getSize()));
             } else {
                 $fileSize = wfMessage('filemissing')->escaped();
             }
             $fileSize = "{$fileSize}<br />\n";
         } else {
             $fileSize = '';
         }
         $textlink = $this->mShowFilename ? Linker::link($nt, htmlspecialchars($lang->truncate($nt->getText(), $this->mCaptionLength)), array(), array(), array('known', 'noclasses')) . "<br />\n" : '';
         # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
         # in version 4.8.6 generated crackpot html in its absence, see:
         # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
         # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
         # Can be safely removed if FF2 falls completely out of existence
         $output .= "\n\t\t" . '<li class="gallerybox" style="width: ' . ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING) . 'px">' . '<div style="width: ' . ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING) . 'px">' . $thumbhtml . "\n\t\t\t" . '<div class="gallerytext">' . "\n" . $textlink . $text . $fileSize . "\n\t\t\t</div>" . "\n\t\t</div></li>";
     }
     $output .= "\n</ul>";
     return $output;
 }
Пример #10
0
 /**
  * @param Skin $sk The given Skin
  * @param bool $includeStyle Unused
  * @return string The doctype, opening "<html>", and head element.
  */
 public function headElement(Skin $sk, $includeStyle = true)
 {
     global $wgContLang;
     $userdir = $this->getLanguage()->getDir();
     $sitedir = $wgContLang->getDir();
     $pieces = [];
     $pieces[] = Html::htmlHeader(Sanitizer::mergeAttributes($this->getRlClient()->getDocumentAttributes(), $sk->getHtmlElementAttributes()));
     $pieces[] = Html::openElement('head');
     if ($this->getHTMLTitle() == '') {
         $this->setHTMLTitle($this->msg('pagetitle', $this->getPageTitle())->inContentLanguage());
     }
     if (!Html::isXmlMimeType($this->getConfig()->get('MimeType'))) {
         // Add <meta charset="UTF-8">
         // This should be before <title> since it defines the charset used by
         // text including the text inside <title>.
         // The spec recommends defining XHTML5's charset using the XML declaration
         // instead of meta.
         // Our XML declaration is output by Html::htmlHeader.
         // http://www.whatwg.org/html/semantics.html#attr-meta-http-equiv-content-type
         // http://www.whatwg.org/html/semantics.html#charset
         $pieces[] = Html::element('meta', ['charset' => 'UTF-8']);
     }
     $pieces[] = Html::element('title', null, $this->getHTMLTitle());
     $pieces[] = $this->getRlClient()->getHeadHtml();
     $pieces[] = $this->buildExemptModules();
     $pieces = array_merge($pieces, array_values($this->getHeadLinksArray()));
     $pieces = array_merge($pieces, array_values($this->mHeadItems));
     $pieces[] = Html::closeElement('head');
     $bodyClasses = [];
     $bodyClasses[] = 'mediawiki';
     # Classes for LTR/RTL directionality support
     $bodyClasses[] = $userdir;
     $bodyClasses[] = "sitedir-{$sitedir}";
     if ($this->getLanguage()->capitalizeAllNouns()) {
         # A <body> class is probably not the best way to do this . . .
         $bodyClasses[] = 'capitalize-all-nouns';
     }
     // Parser feature migration class
     // The idea is that this will eventually be removed, after the wikitext
     // which requires it is cleaned up.
     $bodyClasses[] = 'mw-hide-empty-elt';
     $bodyClasses[] = $sk->getPageClasses($this->getTitle());
     $bodyClasses[] = 'skin-' . Sanitizer::escapeClass($sk->getSkinName());
     $bodyClasses[] = 'action-' . Sanitizer::escapeClass(Action::getActionName($this->getContext()));
     $bodyAttrs = [];
     // While the implode() is not strictly needed, it's used for backwards compatibility
     // (this used to be built as a string and hooks likely still expect that).
     $bodyAttrs['class'] = implode(' ', $bodyClasses);
     // Allow skins and extensions to add body attributes they need
     $sk->addToBodyAttributes($this, $bodyAttrs);
     Hooks::run('OutputPageBodyAttributes', [$this, $sk, &$bodyAttrs]);
     $pieces[] = Html::openElement('body', $bodyAttrs);
     return self::combineWrappedStrings($pieces);
 }
Пример #11
0
 /**
  * Returns the array of attributes used when linking to the Title $target
  */
 private function linkAttribs($target, $attribs, $options)
 {
     wfProfileIn(__METHOD__);
     global $wgUser;
     $defaults = array();
     if (!in_array('noclasses', $options)) {
         wfProfileIn(__METHOD__ . '-getClasses');
         # Now build the classes.
         $classes = array();
         if (in_array('broken', $options)) {
             $classes[] = 'new';
         }
         if ($target->isExternal()) {
             $classes[] = 'extiw';
         }
         # Note that redirects never count as stubs here.
         if (!in_array('broken', $options) && $target->isRedirect()) {
             $classes[] = 'mw-redirect';
         } elseif ($target->isContentPage()) {
             # Check for stub.
             $threshold = $wgUser->getOption('stubthreshold');
             if ($threshold > 0 and $target->exists() and $target->getLength() < $threshold) {
                 $classes[] = 'stub';
             }
         }
         if ($classes != array()) {
             $defaults['class'] = implode(' ', $classes);
         }
         wfProfileOut(__METHOD__ . '-getClasses');
     }
     # Get a default title attribute.
     if ($target->getPrefixedText() == '') {
         # A link like [[#Foo]].  This used to mean an empty title
         # attribute, but that's silly.  Just don't output a title.
     } elseif (in_array('known', $options)) {
         $defaults['title'] = $target->getPrefixedText();
     } else {
         $defaults['title'] = wfMsg('red-link-title', $target->getPrefixedText());
     }
     # Finally, merge the custom attribs with the default ones, and iterate
     # over that, deleting all "false" attributes.
     $ret = array();
     $merged = Sanitizer::mergeAttributes($defaults, $attribs);
     foreach ($merged as $key => $val) {
         # A false value suppresses the attribute, and we don't want the
         # href attribute to be overridden.
         if ($key != 'href' and $val !== false) {
             $ret[$key] = $val;
         }
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }
	/**
	 * Return a HTML representation of the image gallery
	 *
	 * For each image in the gallery, display
	 * - a thumbnail
	 * - the image name
	 * - the additional text provided when adding the image
	 * - the size of the image
	 *
	 * @return string
	 */
	function toHTML() {
		if ( $this->mPerRow > 0 ) {
			$maxwidth = $this->mPerRow * ( $this->mWidths + $this->getAllPadding() );
			$oldStyle = isset( $this->mAttribs['style'] ) ? $this->mAttribs['style'] : '';
			# _width is ignored by any sane browser. IE6 doesn't know max-width so it uses _width instead
			$this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
		}

		$attribs = Sanitizer::mergeAttributes(
			array( 'class' => 'gallery mw-gallery-' . $this->mMode ), $this->mAttribs );

		$modules = $this->getModules();

		if ( $this->mParser ) {
			$this->mParser->getOutput()->addModules( $modules );
		} else {
			$this->getOutput()->addModules( $modules );
		}
		$output = Xml::openElement( 'ul', $attribs );
		if ( $this->mCaption ) {
			$output .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
		}

		$lang = $this->getRenderLang();
		# Output each image...
		foreach ( $this->mImages as $pair ) {
			$nt = $pair[0];
			$text = $pair[1]; # "text" means "caption" here
			$alt = $pair[2];
			$link = $pair[3];

			$descQuery = false;
			if ( $nt->getNamespace() === NS_FILE ) {
				# Get the file...
				if ( $this->mParser instanceof Parser ) {
					# Give extensions a chance to select the file revision for us
					$options = array();
					wfRunHooks( 'BeforeParserFetchFileAndTitle',
						array( $this->mParser, $nt, &$options, &$descQuery ) );
					# Fetch and register the file (file title may be different via hooks)
					list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
				} else {
					$img = wfFindFile( $nt );
				}
			} else {
				$img = false;
			}

			$params = $this->getThumbParams( $img );
			// $pair[4] is per image handler options
			$transformOptions = $params + $pair[4];

			$thumb = false;

			if ( !$img ) {
				# We're dealing with a non-image, spit out the name and be done with it.
				$thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
					. htmlspecialchars( $nt->getText() ) . '</div>';

				if ( $this->mParser instanceof Parser ) {
					$this->mParser->addTrackingCategory( 'broken-file-category' );
				}
			} elseif ( $this->mHideBadImages && wfIsBadImage( $nt->getDBkey(), $this->getContextTitle() ) ) {
				# The image is blacklisted, just show it as a text link.
				$thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">' .
					Linker::link(
						$nt,
						htmlspecialchars( $nt->getText() ),
						array(),
						array(),
						array( 'known', 'noclasses' )
					) .
					'</div>';
			} elseif ( !( $thumb = $img->transform( $transformOptions ) ) ) {
				# Error generating thumbnail.
				$thumbhtml = "\n\t\t\t" . '<div class="thumb" style="height: ' . ( $this->getThumbPadding() + $this->mHeights ) . 'px;">'
					. htmlspecialchars( $img->getLastError() ) . '</div>';
			} else {
				$vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() );

				$imageParameters = array(
					'desc-link' => true,
					'desc-query' => $descQuery,
					'alt' => $alt,
					'custom-url-link' => $link
				);
				# In the absence of both alt text and caption, fall back on providing screen readers with the filename as alt text
				if ( $alt == '' && $text == '' ) {
					$imageParameters['alt'] = $nt->getText();
				}

				$this->adjustImageParameters( $thumb, $imageParameters );

				# Set both fixed width and min-height.
				$thumbhtml = "\n\t\t\t" .
					'<div class="thumb" style="width: ' . $this->getThumbDivWidth( $thumb->getWidth() ) . 'px;">'
					# Auto-margin centering for block-level elements. Needed now that we have video
					# handlers since they may emit block-level elements as opposed to simple <img> tags.
					# ref http://css-discuss.incutio.com/?page=CenteringBlockElement
					. '<div style="margin:' . $vpad . 'px auto;">'
					. $thumb->toHtml( $imageParameters ) . '</div></div>';

				// Call parser transform hook
				if ( $this->mParser && $img->getHandler() ) {
					$img->getHandler()->parserTransformHook( $this->mParser, $img );
				}
			}

			//TODO
			// $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}" );
			// $ul = Linker::link( $linkTarget, $ut );

			if ( $this->mShowBytes ) {
				if ( $img ) {
					$fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
				} else {
					$fileSize = $this->msg( 'filemissing' )->escaped();
				}
				$fileSize = "$fileSize<br />\n";
			} else {
				$fileSize = '';
			}

			$textlink = $this->mShowFilename ?
				Linker::link(
					$nt,
					htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) ),
					array(),
					array(),
					array( 'known', 'noclasses' )
				) . "<br />\n" :
				'';


			$galleryText = $textlink . $text . $fileSize;
			$galleryText = $this->wrapGalleryText( $galleryText, $thumb );

			# Weird double wrapping (the extra div inside the li) needed due to FF2 bug
			# Can be safely removed if FF2 falls completely out of existence
			$output .=
				"\n\t\t" . '<li class="gallerybox" style="width: ' . $this->getGBWidth( $thumb ) . 'px">'
					. '<div style="width: ' . $this->getGBWidth( $thumb ) . 'px">'
					. $thumbhtml
					. $galleryText
					. "\n\t\t</div></li>";
		}
		$output .= "\n</ul>";

		return $output;
	}
Пример #13
0
 /**
  * Return a HTML representation of the image gallery
  *
  * For each image in the gallery, display
  * - a thumbnail
  * - the image name
  * - the additional text provided when adding the image
  * - the size of the image
  *
  */
 function toHTML()
 {
     global $wgLang;
     $sk = $this->getSkin();
     if ($this->mPerRow > 0) {
         $maxwidth = $this->mPerRow * ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING + self::GB_BORDERS);
         $oldStyle = isset($this->mAttribs['style']) ? $this->mAttribs['style'] : "";
         $this->mAttribs['style'] = "max-width: {$maxwidth}px;_width: {$maxwidth}px;" . $oldStyle;
     }
     $attribs = Sanitizer::mergeAttributes(array('class' => 'gallery'), $this->mAttribs);
     $s = Xml::openElement('ul', $attribs);
     if ($this->mCaption) {
         $s .= "\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
     }
     $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
     $i = 0;
     foreach ($this->mImages as $pair) {
         $nt = $pair[0];
         $text = $pair[1];
         # "text" means "caption" here
         # Give extensions a chance to select the file revision for us
         $time = $descQuery = false;
         wfRunHooks('BeforeGalleryFindFile', array(&$this, &$nt, &$time, &$descQuery));
         if ($nt->getNamespace() == NS_FILE) {
             $img = wfFindFile($nt, array('time' => $time));
         } else {
             $img = false;
         }
         if (!$img) {
             # We're dealing with a non-image, spit out the name and be done with it.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . htmlspecialchars($nt->getText()) . '</div>';
         } elseif ($this->mHideBadImages && wfIsBadImage($nt->getDBkey(), $this->getContextTitle())) {
             # The image is blacklisted, just show it as a text link.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . $sk->link($nt, htmlspecialchars($nt->getText()), array(), array(), array('known', 'noclasses')) . '</div>';
         } elseif (!($thumb = $img->transform($params))) {
             # Error generating thumbnail.
             $thumbhtml = "\n\t\t\t" . '<div style="height: ' . (self::THUMB_PADDING + $this->mHeights) . 'px;">' . htmlspecialchars($img->getLastError()) . '</div>';
         } else {
             //We get layout problems with the margin, if the image is smaller
             //than the line-height, so we less margin in these cases.
             $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17;
             $vpad = floor((self::THUMB_PADDING + $this->mHeights - $minThumbHeight) / 2);
             $imageParameters = array('desc-link' => true, 'desc-query' => $descQuery);
             # In the absence of a caption, fall back on providing screen readers with the filename as alt text
             if ($text == '') {
                 $imageParameters['alt'] = $nt->getText();
             }
             # Set both fixed width and min-height.
             $thumbhtml = "\n\t\t\t" . '<div class="thumb" style="width: ' . ($this->mWidths + self::THUMB_PADDING) . 'px;">' . '<div style="margin:' . $vpad . 'px auto;">' . $thumb->toHtml($imageParameters) . '</div></div>';
             // Call parser transform hook
             if ($this->mParser && $img->getHandler()) {
                 $img->getHandler()->parserTransformHook($this->mParser, $img);
             }
         }
         //TODO
         // $linkTarget = Title::newFromText( $wgContLang->getNsText( MWNamespace::getUser() ) . ":{$ut}" );
         // $ul = $sk->link( $linkTarget, $ut );
         if ($this->mShowBytes) {
             if ($img) {
                 $nb = wfMsgExt('nbytes', array('parsemag', 'escape'), $wgLang->formatNum($img->getSize()));
             } else {
                 $nb = wfMsgHtml('filemissing');
             }
             $nb = "{$nb}<br />\n";
         } else {
             $nb = '';
         }
         $textlink = $this->mShowFilename ? $sk->link($nt, htmlspecialchars($wgLang->truncate($nt->getText(), $this->mCaptionLength)), array(), array(), array('known', 'noclasses')) . "<br />\n" : '';
         # ATTENTION: The newline after <div class="gallerytext"> is needed to accommodate htmltidy which
         # in version 4.8.6 generated crackpot html in its absence, see:
         # http://bugzilla.wikimedia.org/show_bug.cgi?id=1765 -Ævar
         # Weird double wrapping in div needed due to FF2 bug
         # Can be safely removed if FF2 falls completely out of existance
         $s .= "\n\t\t" . '<li class="gallerybox" style="width: ' . ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING) . 'px">' . '<div style="width: ' . ($this->mWidths + self::THUMB_PADDING + self::GB_PADDING) . 'px">' . $thumbhtml . "\n\t\t\t" . '<div class="gallerytext">' . "\n" . $textlink . $text . $nb . "\n\t\t\t</div>" . "\n\t\t</div></li>";
         ++$i;
     }
     $s .= "\n</ul>";
     return $s;
 }
Пример #14
0
 /**
  * Return a HTML representation of the image slideshow for external images taken from feed
  * @author Marooned
  */
 private function renderFeedSlideshow()
 {
     global $wgStylePath, $wgBlankImgUrl;
     wfProfileIn(__METHOD__);
     // don't render empty slideshows
     if (empty($this->mExternalImages)) {
         wfProfileOut(__METHOD__);
         return '';
     }
     // slideshow wrapper CSS class
     $class = 'wikia-slideshow clearfix';
     $id = "slideshow-{$this->mData['id']}";
     // do not add button for galleries from templates
     if (isset($this->mData['params']['source']) && $this->mData['params']['source'] == "template") {
         $class .= ' template';
     }
     // support "position" attribute (slideshow alignment)
     switch ($this->getParam('position')) {
         case 'left':
             $class .= ' floatleft';
             break;
         case 'center':
             $class .= ' slideshow-center';
             break;
         case 'right':
             $class .= ' floatright';
             break;
     }
     // wrap image slideshow inside div.slideshow
     $attribs = Sanitizer::mergeAttributes(array('class' => $class, 'hash' => $this->mData['hash'], 'id' => $id), $this->mAttribs);
     $html = Xml::openElement('div', $attribs);
     // render slideshow caption
     if ($this->mCaption) {
         $html .= '<div class="wikia-slideshow-caption">' . $this->mCaption . '</div>';
     }
     // fit images inside width:height = 4:3 box
     $this->mHeights = round($this->mWidths * 3 / 4);
     $params = array('width' => $this->mWidths, 'height' => $this->mHeights);
     wfDebug(__METHOD__ . ": slideshow {$params['width']}x{$params['height']}\n");
     $html .= Xml::openElement('div', array('class' => 'wikia-slideshow-wrapper', 'style' => 'width: ' . ($this->mWidths + 10) . 'px'));
     // wrap images inside <div> and <ul>
     $html .= Xml::openElement('div', array('class' => 'wikia-slideshow-images-wrapper accent'));
     $html .= Xml::openElement('ul', array('class' => 'wikia-slideshow-images neutral', 'style' => "height: {$params['height']}px; width: {$params['width']}px;"));
     foreach ($this->mExternalImages as $index => $imageData) {
         // Give extensions a chance to select the file revision for us
         $caption = $linkOverlay = '';
         // render caption overlay
         if ($imageData['caption'] != '') {
             $caption = Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption')) . Xml::openElement('span', array('class' => 'wikia-slideshow-image-caption-inner')) . $imageData['caption'] . Xml::closeElement('span') . Xml::closeElement('span');
         }
         // parse link
         $linkAttribs = $this->parseLink($imageData['src'], $imageData['caption'], $imageData['link']);
         // extra link tag attributes
         $linkAttribs['id'] = "{$id}-{$index}";
         $linkAttribs['style'] = 'width: ' . ($params['width'] - 80) . 'px';
         $linkAttribs['class'] = 'wikia-slideshow-image';
         $linkAttribs['target'] = "_blank";
         if ($imageData['link'] == '') {
             // tooltip to be used for not-linked images
             $linkAttribs['title'] = wfMsg('wikiaPhotoGallery-slideshow-view-popout-tooltip');
             unset($linkAttribs['href']);
         } else {
             $linkText = $imageData['link'];
             // add link overlay
             $linkOverlay = Xml::openElement('span', array('class' => 'wikia-slideshow-link-overlay')) . wfMsg('wikiaPhotoGallery-slideshow-view-link-overlay', $linkText) . Xml::closeElement('span');
         }
         // add CSS class so we can show first slideshow image before JS is loaded
         $liAttribs = array('class' => 'wikia-slideshow-from-feed');
         if ($index == 0) {
             $liAttribs['class'] .= ' wikia-slideshow-first-image';
         }
         $html .= Xml::openElement('li', $liAttribs) . Xml::openElement('img', array('data-src' => $imageData['src'])) . Xml::element('a', $linkAttribs, ' ') . $caption . $linkOverlay . '</li>';
     }
     $html .= Xml::closeElement('ul');
     $html .= Xml::closeElement('div');
     // render prev/next buttons
     $top = ($params['height'] >> 1) - 30 + 5;
     $html .= Xml::openElement('div', array('class' => 'wikia-slideshow-prev-next'));
     // prev
     $html .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-prev', 'style' => "top: {$top}px", 'title' => wfMsg('wikiaPhotoGallery-slideshow-view-prev-tooltip')));
     $html .= Xml::openElement('span');
     $html .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
     $html .= Xml::closeElement('span');
     $html .= Xml::closeElement('a');
     // next
     $html .= Xml::openElement('a', array('class' => 'wikia-slideshow-sprite wikia-slideshow-next', 'style' => "top: {$top}px", 'title' => wfMsg('wikiaPhotoGallery-slideshow-view-next-tooltip')));
     $html .= Xml::openElement('span');
     $html .= Xml::element('img', array('class' => 'chevron', 'src' => $wgBlankImgUrl));
     $html .= Xml::closeElement('span');
     $html .= Xml::closeElement('a');
     $html .= Xml::closeElement('div');
     // render slideshow toolbar
     $html .= Xml::openElement('div', array('class' => 'wikia-slideshow-toolbar clearfix', 'style' => 'display: none'));
     // Pop-out icon, "X of X" counter
     $counterValue = wfMsg('wikiaPhotoGallery-slideshow-view-number', '$1', $index);
     $html .= Xml::openElement('div', array('style' => 'float: left'));
     $html .= Xml::element('img', array('class' => 'wikia-slideshow-popout', 'height' => 11, 'src' => "{$wgStylePath}/common/images/magnify-clip.png", 'title' => wfMsg('wikiaPhotoGallery-slideshow-view-popout-tooltip'), 'width' => 15));
     $html .= Xml::element('span', array('class' => 'wikia-slideshow-toolbar-counter', 'data-counter' => $counterValue), str_replace('$1', '1', $counterValue));
     $html .= Xml::closeElement('div');
     $html .= Xml::closeElement('div');
     // close slideshow wrapper
     $html .= Xml::closeElement('div');
     $html .= Xml::closeElement('div');
     // output JS to init slideshow
     $height = $params['height'];
     $width = $params['width'];
     $html .= F::build('JSSnippets')->addToStack(array('/resources/wikia/libraries/jquery/slideshow/jquery-slideshow-0.4.js', '/extensions/wikia/WikiaPhotoGallery/js/WikiaPhotoGallery.slideshow.js'), array(), 'WikiaPhotoGallerySlideshow.init', array('id' => $id, 'width' => $width, 'height' => $height));
     wfProfileOut(__METHOD__);
     return $html;
 }