Beispiel #1
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     $ig->useSkin($this->mOptions->getSkin());
     $ig->mRevisionId = $this->mRevisionId;
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig));
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = urldecode($matches[1]);
         }
         $tp = Title::newFromText($matches[1]);
         $nt =& $tp;
         if (is_null($nt)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         if (isset($matches[3])) {
             $label = $matches[3];
         } else {
             $label = '';
         }
         $html = $this->recursiveTagParse(trim($label));
         $ig->add($nt, $html);
         # Only add real images (bug #5586)
         if ($nt->getNamespace() == NS_FILE) {
             $this->mOutput->addImage($nt->getDBkey());
         }
     }
     return $ig->toHTML();
 }
Beispiel #2
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  *
  * @param string $text
  * @param array $params
  * @return string HTML
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     /* Wikia change begin - @author: Macbre */
     /* Allow extensions to use different class to render image gallery */
     wfRunHooks('renderImageGallerySetup', array(&$ig, &$text, &$params));
     /* Wikia change end */
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     if (isset($params['showfilename'])) {
         $ig->setShowFilename(true);
     } else {
         $ig->setShowFilename(false);
     }
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     /* Wikia change begin */
     /* Allow extensions to use their own "parser" for <gallery> tag content */
     if (!wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig))) {
         return $ig->toHTML();
     }
     /* Wikia change end */
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = rawurldecode($matches[1]);
         }
         $title = Title::newFromText($matches[1], NS_FILE);
         if (is_null($title)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         $label = '';
         $alt = '';
         if (isset($matches[3])) {
             // look for an |alt= definition while trying not to break existing
             // captions with multiple pipes (|) in it, until a more sensible grammar
             // is defined for images in galleries
             $matches[3] = $this->recursiveTagParse(trim($matches[3]));
             $altmatches = StringUtils::explode('|', $matches[3]);
             $magicWordAlt = MagicWord::get('img_alt');
             foreach ($altmatches as $altmatch) {
                 $match = $magicWordAlt->matchVariableStartToEnd($altmatch);
                 if ($match) {
                     $alt = $this->stripAltText($match, false);
                 } else {
                     // concatenate all other pipes
                     $label .= '|' . $altmatch;
                 }
             }
             // remove the first pipe
             $label = substr($label, 1);
         }
         $ig->add($title, $label, $alt);
     }
     return $ig->toHTML();
 }
Beispiel #3
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  *
  * @param string $text
  * @param array $params
  * @return string HTML
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParser($this);
     $ig->setHideBadImages();
     $ig->setAttributes(Sanitizer::validateTagAttributes($params, 'table'));
     if (isset($params['showfilename'])) {
         $ig->setShowFilename(true);
     } else {
         $ig->setShowFilename(false);
     }
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     wfRunHooks('BeforeParserrenderImageGallery', array(&$this, &$ig));
     $lines = StringUtils::explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         if (strpos($matches[0], '%') !== false) {
             $matches[1] = rawurldecode($matches[1]);
         }
         $title = Title::newFromText($matches[1], NS_FILE);
         if (is_null($title)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         $label = '';
         $alt = '';
         $link = '';
         if (isset($matches[3])) {
             // look for an |alt= definition while trying not to break existing
             // captions with multiple pipes (|) in it, until a more sensible grammar
             // is defined for images in galleries
             $matches[3] = $this->recursiveTagParse(trim($matches[3]));
             $parameterMatches = StringUtils::explode('|', $matches[3]);
             $magicWordAlt = MagicWord::get('img_alt');
             $magicWordLink = MagicWord::get('img_link');
             foreach ($parameterMatches as $parameterMatch) {
                 if ($match = $magicWordAlt->matchVariableStartToEnd($parameterMatch)) {
                     $alt = $this->stripAltText($match, false);
                 } elseif ($match = $magicWordLink->matchVariableStartToEnd($parameterMatch)) {
                     $link = strip_tags($this->replaceLinkHoldersText($match));
                     $chars = self::EXT_LINK_URL_CLASS;
                     $prots = $this->mUrlProtocols;
                     //check to see if link matches an absolute url, if not then it must be a wiki link.
                     if (!preg_match("/^({$prots}){$chars}+\$/u", $link)) {
                         $localLinkTitle = Title::newFromText($link);
                         $link = $localLinkTitle->getLocalURL();
                     }
                 } else {
                     // concatenate all other pipes
                     $label .= '|' . $parameterMatch;
                 }
             }
             // remove the first pipe
             $label = substr($label, 1);
         }
         $ig->add($title, $label, $alt, $link);
     }
     return $ig->toHTML();
 }
Beispiel #4
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  */
 function renderImageGallery($text, $params)
 {
     $ig = new ImageGallery();
     $ig->setContextTitle($this->mTitle);
     $ig->setShowBytes(false);
     $ig->setShowFilename(false);
     $ig->setParsing();
     $ig->useSkin($this->mOptions->getSkin());
     if (isset($params['caption'])) {
         $caption = $params['caption'];
         $caption = htmlspecialchars($caption);
         $caption = $this->replaceInternalLinks($caption);
         $ig->setCaptionHtml($caption);
     }
     if (isset($params['perrow'])) {
         $ig->setPerRow($params['perrow']);
     }
     if (isset($params['widths'])) {
         $ig->setWidths($params['widths']);
     }
     if (isset($params['heights'])) {
         $ig->setHeights($params['heights']);
     }
     $lines = explode("\n", $text);
     foreach ($lines as $line) {
         # match lines like these:
         # Image:someimage.jpg|This is some image
         $matches = array();
         preg_match("/^([^|]+)(\\|(.*))?\$/", $line, $matches);
         # Skip empty lines
         if (count($matches) == 0) {
             continue;
         }
         $tp = Title::newFromText($matches[1]);
         $nt =& $tp;
         if (is_null($nt)) {
             # Bogus title. Ignore these so we don't bomb out later.
             continue;
         }
         if (isset($matches[3])) {
             $label = $matches[3];
         } else {
             $label = '';
         }
         $pout = $this->parse($label, $this->mTitle, $this->mOptions, false, false);
         $html = $pout->getText();
         $ig->add(new Image($nt), $html);
         # Only add real images (bug #5586)
         if ($nt->getNamespace() == NS_IMAGE) {
             $this->mOutput->addImage($nt->getDBkey());
         }
     }
     return $ig->toHTML();
 }