private static function loadModes() { if (self::$modeMapping === false) { self::$modeMapping = array('traditional' => 'TraditionalImageGallery', 'nolines' => 'NolinesImageGallery', 'packed' => 'PackedImageGallery', 'packed-hover' => 'PackedHoverImageGallery', 'packed-overlay' => 'PackedOverlayImageGallery'); // Allow extensions to make a new gallery format. wfRunHooks('GalleryGetModes', self::$modeMapping); } }
/** * Format and output report results using the given information plus * OutputPage * * @param OutputPage $out OutputPage to print to * @param Skin $skin User skin to use [unused] * @param DatabaseBase $dbr (read) connection to use * @param int $res Result pointer * @param int $num Number of available result rows * @param int $offset Paging offset */ protected function outputResults($out, $skin, $dbr, $res, $num, $offset) { if ($num > 0) { $gallery = ImageGalleryBase::factory(); $gallery->setContext($this->getContext()); # $res might contain the whole 1,000 rows, so we read up to # $num [should update this to use a Pager] for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) { $namespace = isset($row->namespace) ? $row->namespace : NS_FILE; $title = Title::makeTitleSafe($namespace, $row->title); if ($title instanceof Title && $title->getNamespace() == NS_FILE) { $gallery->add($title, $this->getCellHtml($row)); } } $out->addHTML($gallery->toHtml()); } }
public function generateReadHtml() { $config = $this->campaign->getParsedConfig(); $campaignTitle = array_key_exists('title', $config) ? $config['title'] : $this->campaign->getName(); $campaignDescription = array_key_exists('description', $config) ? $config['description'] : ''; $campaignViewMoreLink = $this->campaign->getTrackingCategory()->getFullURL(); $gallery = ImageGalleryBase::factory('packed-hover'); $gallery->setContext($this->context); $gallery->setWidths(180); $gallery->setHeights(180); $gallery->setShowBytes(false); $this->context->getOutput()->setSquidMaxage(UploadWizardConfig::getSetting('campaignSquidMaxAge')); $this->context->getOutput()->setHTMLTitle($this->context->msg('pagetitle', $campaignTitle)); $images = $this->campaign->getUploadedMedia(); if ($this->context->getUser()->isAnon()) { $urlParams = array('returnto' => $this->campaign->getTitle()->getPrefixedText()); if ($this->isCampaignExtensionEnabled()) { $campaignTemplate = UploadWizardConfig::getSetting('campaignCTACampaignTemplate'); $urlParams['campaign'] = str_replace('$1', $this->campaign->getName(), $campaignTemplate); } $createAccountUrl = Skin::makeSpecialUrlSubpage('UserLogin', 'signup', $urlParams); $uploadLink = Html::element('a', array('class' => 'mw-ui-big mw-ui-button mw-ui-primary', 'href' => $createAccountUrl), wfMessage('mwe-upwiz-campaign-create-account-button')->text()); } else { $uploadUrl = Skin::makeSpecialUrl('UploadWizard', array('campaign' => $this->campaign->getName())); $uploadLink = Html::element('a', array('class' => 'mw-ui-big mw-ui-button mw-ui-primary', 'href' => $uploadUrl), wfMessage('mwe-upwiz-campaign-upload-button')->text()); } if (count($images) === 0) { $body = Html::element('div', array('id' => 'mw-campaign-no-uploads-yet'), wfMessage('mwe-upwiz-campaign-no-uploads-yet')->plain()); } else { foreach ($images as $image) { $gallery->add($image); } $body = Html::rawElement('div', array('id' => 'mw-campaign-images'), $gallery->toHTML()) . Html::rawElement('a', array('id' => 'mw-campaign-view-all', 'href' => $campaignViewMoreLink), Html::rawElement('span', array('class' => 'mw-campaign-chevron mw-campaign-float-left'), ' ') . wfMessage('mwe-upwiz-campaign-view-all-media')->escaped() . Html::rawElement('span', array('class' => 'mw-campaign-chevron mw-campaign-float-right'), ' ')); } if (UploadWizardConfig::getSetting('campaignExpensiveStatsEnabled') === true) { $uploaderCount = $this->campaign->getTotalContributorsCount(); $campaignExpensiveStats = Html::rawElement('div', array('class' => 'mw-campaign-number-container'), Html::element('div', array('class' => 'mw-campaign-number'), $this->context->getLanguage()->formatNum($uploaderCount)) . Html::element('span', array('class' => 'mw-campaign-number-desc'), wfMessage('mwe-upwiz-campaign-contributors-count-desc')->numParams($uploaderCount)->text())); } else { $campaignExpensiveStats = ''; } $uploadCount = $this->campaign->getUploadedMediaCount(); $result = Html::rawElement('div', array('id' => 'mw-campaign-container'), Html::rawElement('div', array('id' => 'mw-campaign-header'), Html::rawElement('div', array('id' => 'mw-campaign-primary-info'), Html::rawElement('p', array('id' => 'mw-campaign-title'), $campaignTitle) . Html::rawElement('p', array('id' => 'mw-campaign-description'), $campaignDescription) . $uploadLink) . Html::rawElement('div', array('id' => 'mw-campaign-numbers'), $campaignExpensiveStats . Html::rawElement('div', array('class' => 'mw-campaign-number-container'), Html::element('div', array('class' => 'mw-campaign-number'), $this->context->getLanguage()->formatNum($uploadCount)) . Html::element('span', array('class' => 'mw-campaign-number-desc'), wfMessage('mwe-upwiz-campaign-media-count-desc')->numParams($uploadCount)->text())))) . $body); return $result; }
function clearCategoryState() { $this->articles = array(); $this->articles_start_char = array(); $this->children = array(); $this->children_start_char = array(); if ($this->showGallery) { // Note that null for mode is taken to mean use default. $mode = $this->getRequest()->getVal('gallerymode', null); try { $this->gallery = ImageGalleryBase::factory($mode); } catch (MWException $e) { // User specified something invalid, fallback to default. $this->gallery = ImageGalleryBase::factory(); } $this->gallery->setHideBadImages(); $this->gallery->setContext($this->getContext()); } else { $this->imgsNoGallery = array(); $this->imgsNoGallery_start_char = array(); } }
function getStartBody() { if (!$this->gallery) { // Note that null for mode is taken to mean use default. $mode = $this->getRequest()->getVal('gallerymode', null); try { $this->gallery = ImageGalleryBase::factory($mode, $this->getContext()); } catch (MWException $e) { // User specified something invalid, fallback to default. $this->gallery = ImageGalleryBase::factory(false, $this->getContext()); } } return ''; }
/** * Construct a warning and a gallery from an array of duplicate files. * @param array $dupes * @return string */ public function getDupeWarning($dupes) { if (!$dupes) { return ''; } $gallery = ImageGalleryBase::factory(false, $this->getContext()); $gallery->setShowBytes(false); foreach ($dupes as $file) { $gallery->add($file->getTitle()); } return '<li>' . $this->msg('file-exists-duplicate')->numParams(count($dupes))->parse() . $gallery->toHTML() . "</li>\n"; }
/** * 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) { wfProfileIn(__METHOD__); $mode = false; if (isset($params['mode'])) { $mode = $params['mode']; } try { $ig = ImageGalleryBase::factory($mode); } catch (MWException $e) { // If invalid type set, fallback to default. $ig = ImageGalleryBase::factory(false); } $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']); } $ig->setAdditionalOptions($params); 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; } # We need to get what handler the file uses, to figure out parameters. # Note, a hook can overide the file name, and chose an entirely different # file (which potentially could be of a different type and have different handler). $options = array(); $descQuery = false; wfRunHooks('BeforeParserFetchFileAndTitle', array($this, $title, &$options, &$descQuery)); # Don't register it now, as ImageGallery does that later. $file = $this->fetchFileNoRegister($title, $options); $handler = $file ? $file->getHandler() : false; wfProfileIn(__METHOD__ . '-getMagicWord'); $paramMap = array('img_alt' => 'gallery-internal-alt', 'img_link' => 'gallery-internal-link'); if ($handler) { $paramMap = $paramMap + $handler->getParamMap(); // We don't want people to specify per-image widths. // Additionally the width parameter would need special casing anyhow. unset($paramMap['img_width']); } $mwArray = new MagicWordArray(array_keys($paramMap)); wfProfileOut(__METHOD__ . '-getMagicWord'); $label = ''; $alt = ''; $link = ''; $handlerOptions = array(); 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 // FIXME: Doing recursiveTagParse at this stage, and the trim before // splitting on '|' is a bit odd, and different from makeImage. $matches[3] = $this->recursiveTagParse(trim($matches[3])); $parameterMatches = StringUtils::explode('|', $matches[3]); foreach ($parameterMatches as $parameterMatch) { list($magicName, $match) = $mwArray->matchVariableStartToEnd($parameterMatch); if ($magicName) { $paramName = $paramMap[$magicName]; switch ($paramName) { case 'gallery-internal-alt': $alt = $this->stripAltText($match, false); break; case 'gallery-internal-link': $linkValue = 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", $linkValue)) { $link = $linkValue; } else { $localLinkTitle = Title::newFromText($linkValue); if ($localLinkTitle !== null) { $link = $localLinkTitle->getLocalURL(); } } break; default: // Must be a handler specific parameter. if ($handler->validateParam($paramName, $match)) { $handlerOptions[$paramName] = $match; } else { // Guess not. Append it to the caption. wfDebug("{$parameterMatch} failed parameter validation\n"); $label .= '|' . $parameterMatch; } } } else { // concatenate all other pipes $label .= '|' . $parameterMatch; } } // remove the first pipe $label = substr($label, 1); } $ig->add($title, $label, $alt, $link, $handlerOptions); } $html = $ig->toHTML(); wfProfileOut(__METHOD__); return $html; }
private static function loadModes() { if (self::$modeMapping === false) { self::$modeMapping = ['traditional' => 'TraditionalImageGallery', 'nolines' => 'NolinesImageGallery', 'packed' => 'PackedImageGallery', 'packed-hover' => 'PackedHoverImageGallery', 'packed-overlay' => 'PackedOverlayImageGallery', 'slideshow' => 'SlideshowImageGallery']; // Allow extensions to make a new gallery format. Hooks::run('GalleryGetModes', [&self::$modeMapping]); } }