/** * Obtain an HTML image gallery to output, or else an error message * * @return string */ public function render() { if( is_object( $this->user ) ) { $this->user->load(); if( $this->user->getId() > 0 ) { $images = $this->getImages(); if( count( $images ) > 0 ) { $gallery = new ImageGallery(); #$gallery->setParsing( true ); # Fixme (?) undefined method ImageGallery::setParsing $gallery->setCaption( $this->getCaption() ); foreach( $images as $image ) { $title = Title::makeTitleSafe( NS_IMAGE, $image->img_name ); $gallery->add( $title ); } return $gallery->toHtml(); } else { return '<p>' . wfMsgForContent( 'userimages-noimages', $this->user->getName() ) . '</p>'; } } else { return '<p>' . wfMsgForContent( 'nosuchusershort', $this->user->getName() ) . '</p>'; } } else { return '<p>' . wfMsgForContent( 'userimages-noname' ) . '</p>'; } }
public function actionAddToGallery($modelPk, $imageName) { $img = new ImageGallery('create'); $img->image_name = $imageName; $img->{Portfolio::getIdAttr()} = $modelPk; $img->makeThumb(); $img->save(); echo CJSON::encode(array('pk'=>$img->pk)); }
public function cmsDataTypeRelations($event) { $event->relations = CMap::mergeArray( $event->relations, array('gallery' => array(ImageGallery::HAS_MANY, 'ImageGallery', ImageGallery::getPkAttr())) ); }
/** * Format and output report results using the given information plus * OutputPage * * @param $out OutputPage to print to * @param $skin Skin: user skin to use [unused] * @param $dbr DatabaseBase (read) connection to use * @param $res Integer: result pointer * @param $num Integer: number of available result rows * @param $offset Integer: paging offset */ protected function outputResults($out, $skin, $dbr, $res, $num, $offset) { if ($num > 0) { $gallery = new ImageGallery(); # $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()); } }
/** * Format and output report results using the given information plus * OutputPage * * @param $out OutputPage to print to * @param $skin Skin: user skin to use * @param $dbr Database (read) connection to use * @param $res Integer: result pointer * @param $num Integer: number of available result rows * @param $offset Integer: paging offset */ protected function outputResults($out, $skin, $dbr, $res, $num, $offset) { if ($num > 0) { $gallery = new ImageGallery(); $gallery->useSkin($skin); # $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++) { $image = $this->prepareImage($row); if ($image) { $gallery->add($image->getTitle(), $this->getCellHtml($row)); } } $out->addHTML($gallery->toHtml()); } }
function formatRow($row) { $name = $row->img_name; $user = User::newFromId($row->img_user); $title = Title::makeTitle(NS_FILE, $name); $ul = Linker::link($user->getUserpage(), $user->getName()); $this->gallery->add($title, "{$ul}<br />\n<i>" . htmlspecialchars($this->getLanguage()->timeanddate($row->img_timestamp, true)) . "</i><br />\n"); }
function __construct() { parent::__construct(); $this->mData = array('externalImages' => array(), 'feedTitle' => '', 'hash' => false, 'id' => false, 'images' => array(), 'imagesShown' => array(), 'params' => array()); // allows galleries to take up the full width of a page $this->mPerRow = 0; // defaults $this->mCrop = false; $this->mShowRecentUploads = false; $this->mShowAddButton = true; // list of supported gallery parameters with list of valid values // default are the first values, false for params with no defined list of values (colors, etc) $this->mAvalaibleGalleryParams = array('bordercolor' => false, 'bordersize' => array('small', 'medium', 'large', 'none'), 'captionalign' => array('left', 'center', 'right'), 'captionposition' => array('below', 'within'), 'captionsize' => array('medium', 'small', 'large'), 'captiontextcolor' => false, 'rssfeed' => false, 'orientation' => array('none', 'square', 'portrait', 'landscape'), 'position' => array('left', 'center', 'right'), 'spacing' => array('medium', 'large', 'small'), 'buckets' => false, 'rowdivider' => false, 'hideoverflow' => false, 'sliderbar' => array('bottom', 'left')); }
/** * @return string */ function getImageSection() { $r = ''; $rescnt = $this->showGallery ? $this->gallery->count() : count($this->imgsNoGallery); if ($rescnt > 0) { $dbcnt = $this->cat->getFileCount(); $countmsg = $this->getCountMessage($rescnt, $dbcnt, 'file'); $r .= "<div id=\"mw-category-media\">\n"; $r .= '<h2>' . $this->msg('category-media-header', wfEscapeWikiText($this->title->getText()))->text() . "</h2>\n"; $r .= $countmsg; $r .= $this->getSectionPagingLinks('file'); if ($this->showGallery) { $r .= $this->gallery->toHTML(); } else { $r .= $this->formatList($this->imgsNoGallery, $this->imgsNoGallery_start_char); } $r .= $this->getSectionPagingLinks('file'); $r .= "\n</div>"; } return $r; }
/** * @return string */ function getImageSection() { $name = $this->getPrettyPageNameHtml(); $r = ''; $rescnt = $this->showGallery ? $this->gallery->count() : count($this->imgsNoGallery); $dbcnt = $this->cat->getFileCount(); // This function should be called even if the result isn't used, it has side-effects $countmsg = $this->getCountMessage($rescnt, $dbcnt, 'file'); if ($rescnt > 0) { $r .= "<div id=\"mw-category-media\">\n"; $r .= '<h2>' . $this->msg('category-media-header')->rawParams($name)->parse() . "</h2>\n"; $r .= $countmsg; $r .= $this->getSectionPagingLinks('file'); if ($this->showGallery) { $r .= $this->gallery->toHTML(); } else { $r .= $this->formatList($this->imgsNoGallery, $this->imgsNoGallery_start_char); } $r .= $this->getSectionPagingLinks('file'); $r .= "\n</div>"; } return $r; }
function ArrayDimension($array, $option = NULL) { $img = new ImageGallery(); if (!is_array($array)) { return 0; } elseif (!$array) { return 1; } else { switch (strtolower($option)) { case 'first': $keys = array_keys($array); return $img->ArrayDimension($array[$keys[0]], $option) + 1; case 'last': $keys = array_keys($array); return $img->ArrayDimension($array[$keys[count($keys) - 1]], $option) + 1; case 'min': foreach ($array as $key => $val) { $dems[$key] = $img->ArrayDimension($val, $option); } return min($dems) + 1; case 'max': default: foreach ($array as $key => $val) { $dems[$key] = $img->ArrayDimension($val, $option); } return max($dems) + 1; } } }
public function getResultText($results, $outputmode) { global $smwgIQRunningNumber, $wgUser, $wgParser; $skin = $wgUser->getSkin(); $ig = new ImageGallery(); $ig->setShowBytes(false); $ig->setShowFilename(false); $ig->setParser($wgParser); $ig->useSkin($skin); $ig->setCaption($this->mIntro); // set caption to IQ header if (isset($this->m_params['perrow'])) { $ig->setPerRow($this->m_params['perrow']); } if (isset($this->m_params['widths'])) { $ig->setWidths($this->m_params['widths']); } if (isset($this->m_params['heights'])) { $ig->setHeights($this->m_params['heights']); } while ($row = $results->getNext()) { $firstField = $row[0]; $imgTitle = $firstField->getNextObject()->getTitle(); $imgCaption = ''; // Is there a property queried for display with ?property if (isset($row[1])) { $imgCaption = $row[1]->getNextObject(); if (is_object($imgCaption)) { $imgCaption = $imgCaption->getShortText(SMW_OUTPUT_HTML, $this->getLinker(true)); $imgCaption = $wgParser->recursiveTagParse($imgCaption); } } if (empty($imgCaption)) { $imgCaption = $imgTitle->getBaseText(); $imgCaption = preg_replace('#\\.[^.]+$#', '', $imgCaption); // Remove image extension } $ig->add($imgTitle, $imgCaption); // Only add real images (bug #5586) if ($imgTitle->getNamespace() == NS_IMAGE) { $wgParser->mOutput->addImage($imgTitle->getDBkey()); } } return array($ig->toHTML(), 'nowiki' => true, 'isHTML' => true); }
/** * 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(); }
} function showImages() { if ($this->imgsGallery) { echo '<div class="gallery"><p class="title">' . $this->galleryName . '</p>'; foreach ($this->imgsGallery as $tImg) { $imgUrlName = urlencode($tImg); echo "<div class='image_gallery'><a href='" . $this->dirName . $tImg . "'><img src=" . $this->dirName . $tImg . "></a><br><a class='action_url' href=" . $_SERVER['PHP_SELF'] . "?action=delete&delimg=" . $imgUrlName . ">Delete</a></div>"; } echo '</div>'; } else { $this->msg = 'There are no images in this folder. It\'s time upload your first image!'; } } } $gallery = new ImageGallery('images/'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_FILES['userImage'] && !$_FILES['userImage']['error']) { $gallery->uploadImg('userImage'); } } if ($_SERVER['REQUEST_METHOD'] === 'GET' && $_GET['action'] === 'delete') { $gallery->deleteImg(strip_tags($_GET['delimg'])); } $gallery->prepareImages(); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title>
/** * Format the category data list. * * @param string $from -- return only sort keys from this item on * @param string $until -- don't return keys after this point. * @return string HTML output * @private */ function doCategoryMagic($from = '', $until = '') { global $wgOut; global $wgContLang, $wgUser, $wgCategoryMagicGallery, $wgCategoryPagingLimit; $fname = 'CategoryPage::doCategoryMagic'; wfProfileIn($fname); $articles = array(); $articles_start_char = array(); $children = array(); $children_start_char = array(); $showGallery = $wgCategoryMagicGallery && !$wgOut->mNoGallery; if ($showGallery) { $ig = new ImageGallery(); $ig->setParsing(); } $dbr =& wfGetDB(DB_SLAVE); if ($from != '') { $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes($from); $flip = false; } elseif ($until != '') { $pageCondition = 'cl_sortkey < ' . $dbr->addQuotes($until); $flip = true; } else { $pageCondition = '1 = 1'; $flip = false; } $limit = $wgCategoryPagingLimit; $res = $dbr->select(array('page', 'categorylinks'), array('page_title', 'page_namespace', 'page_len', 'cl_sortkey'), array($pageCondition, 'cl_from = page_id', 'cl_to' => $this->mTitle->getDBKey()), $fname, array('ORDER BY' => $flip ? 'cl_sortkey DESC' : 'cl_sortkey', 'LIMIT' => $limit + 1)); $sk =& $wgUser->getSkin(); $r = "<br style=\"clear:both;\"/>\n"; $count = 0; $nextPage = null; while ($x = $dbr->fetchObject($res)) { if (++$count > $limit) { // We've reached the one extra which shows that there are // additional pages to be had. Stop here... $nextPage = $x->cl_sortkey; break; } $title = Title::makeTitle($x->page_namespace, $x->page_title); if ($title->getNamespace() == NS_CATEGORY) { // Subcategory; strip the 'Category' namespace from the link text. array_push($children, $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText()))); // If there's a link from Category:A to Category:B, the sortkey of the resulting // entry in the categorylinks table is Category:A, not A, which it SHOULD be. // Workaround: If sortkey == "Category:".$title, than use $title for sorting, // else use sortkey... $sortkey = ''; if ($title->getPrefixedText() == $x->cl_sortkey) { $sortkey = $wgContLang->firstChar($x->page_title); } else { $sortkey = $wgContLang->firstChar($x->cl_sortkey); } array_push($children_start_char, $wgContLang->convert($sortkey)); } elseif ($showGallery && $title->getNamespace() == NS_IMAGE) { // Show thumbnails of categorized images, in a separate chunk if ($flip) { $ig->insert(Image::newFromTitle($title)); } else { $ig->add(Image::newFromTitle($title)); } } else { // Page in this category array_push($articles, $sk->makeSizeLinkObj($x->page_len, $title, $wgContLang->convert($title->getPrefixedText()))); array_push($articles_start_char, $wgContLang->convert($wgContLang->firstChar($x->cl_sortkey))); } } $dbr->freeResult($res); if ($flip) { $children = array_reverse($children); $children_start_char = array_reverse($children_start_char); $articles = array_reverse($articles); $articles_start_char = array_reverse($articles_start_char); } if ($until != '') { $r .= $this->pagingLinks($this->mTitle, $nextPage, $until, $limit); } elseif ($nextPage != '' || $from != '') { $r .= $this->pagingLinks($this->mTitle, $from, $nextPage, $limit); } # Don't show subcategories section if there are none. if (count($children) > 0) { # Showing subcategories $r .= '<h2>' . wfMsg('subcategories') . "</h2>\n"; $r .= wfMsgExt('subcategorycount', array('parse'), count($children)); $r .= $this->formatList($children, $children_start_char); } # Showing articles in this category $ti = htmlspecialchars($this->mTitle->getText()); $r .= '<h2>' . wfMsg('category_header', $ti) . "</h2>\n"; $r .= wfMsgExt('categoryarticlecount', array('parse'), count($articles)); $r .= $this->formatList($articles, $articles_start_char); if ($showGallery && !$ig->isEmpty()) { $r .= $ig->toHTML(); } if ($until != '') { $r .= $this->pagingLinks($this->mTitle, $nextPage, $until, $limit); } elseif ($nextPage != '' || $from != '') { $r .= $this->pagingLinks($this->mTitle, $from, $nextPage, $limit); } wfProfileOut($fname); return $r; }
/** * Adds a single image to the gallery. * Takes care of automatically adding a caption when none is provided and parsing it's wikitext. * * @since 1.5.3 * * @param ImageGallery $ig The gallery to add the image to * @param Title $imgTitle The title object of the page of the image * @param string $imgCaption An optional caption for the image */ protected function addImageToGallery( ImageGallery &$ig, Title $imgTitle, $imgCaption ) { global $wgParser; if ( empty( $imgCaption ) ) { if ( $this->m_params['autocaptions'] ) { $imgCaption = $imgTitle->getBaseText(); if ( !$this->m_params['fileextensions'] ) { $imgCaption = preg_replace( '#\.[^.]+$#', '', $imgCaption ); } } else { $imgCaption = ''; } } else { $imgCaption = $wgParser->recursiveTagParse( $imgCaption ); } $ig->add( $imgTitle, $imgCaption ); // Only add real images (bug #5586) if ( $imgTitle->getNamespace() == NS_IMAGE ) { $wgParser->mOutput->addImage( $imgTitle->getDBkey() ); } }
/** * Adds a single image to the gallery. * Takes care of automatically adding a caption when none is provided and parsing it's wikitext. * * @since 1.5.3 * * @param ImageGallery $ig The gallery to add the image to * @param Title $imgTitle The title object of the page of the image * @param string $imgCaption An optional caption for the image */ protected function addImageToGallery(ImageGallery &$ig, Title $imgTitle, $imgCaption) { global $wgParser; if (empty($imgCaption)) { if ($this->m_params['autocaptions']) { $imgCaption = $imgTitle->getBaseText(); if (!$this->m_params['fileextensions']) { $imgCaption = preg_replace('#\\.[^.]+$#', '', $imgCaption); } } else { $imgCaption = ''; } } else { $imgCaption = $wgParser->recursiveTagParse($imgCaption); // the above call creates getMaxIncludeSize() fatal error on Special Pages // below might fix this // $imgCaption = $wgParser->transformMsg( $imgCaption, ParserOptions::newFromUser( null ) ); } $ig->add($imgTitle, $imgCaption); // Only add real images (bug #5586) if ($imgTitle->getNamespace() == NS_IMAGE && !is_null($imgTitle->getDBkey())) { $wgParser->mOutput->addImage($imgTitle->getDBkey()); } }
/** * @file * @ingroup SpecialPage * FIXME: this code is crap, should use Pager and Database::select(). */ function wfSpecialNewimages($par, $specialPage) { global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMiserMode; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr = wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots', 1); $hidebotsql = ''; if ($hidebots) { # Make a list of group names which have the 'bot' flag set. $botconds = array(); foreach (User::getGroupsWithPermission('bot') as $groupname) { $botconds[] = 'ug_group = ' . $dbr->addQuotes($groupname); } # If not bot groups, do not set $hidebotsql if ($botconds) { $isbotmember = $dbr->makeList($botconds, LIST_OR); # This join, in conjunction with WHERE ug_group IS NULL, returns # only those rows from IMAGE where the uploading user is not a mem- # ber of a group which has the 'bot' permission set. $ug = $dbr->tableName('user_groups'); $hidebotsql = " LEFT JOIN {$ug} ON img_user=ug_user AND ({$isbotmember})"; } } $image = $dbr->tableName('image'); $sql = "SELECT img_timestamp from {$image}"; if ($hidebotsql) { $sql .= "{$hidebotsql} WHERE ug_group IS NULL"; } $sql .= ' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, __FUNCTION__); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $dbr->freeResult($res); $sql = ''; # If we were clever, we'd use this to cache. $latestTimestamp = wfTimestamp(TS_MW, $ts); # Hardcode this for now. $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = ''; if ($wpIlMatch != '' && !$wgMiserMode) { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->escapeLike(strtolower($nt->getDBkey())); $where[] = "LOWER(img_name) LIKE '%{$m}%'"; $searchpar = '&wpIlMatch=' . urlencode($wpIlMatch); } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = "img_timestamp < '" . $dbr->timestamp($until) . "'"; } if ($from = $wgRequest->getVal('from')) { $where[] = "img_timestamp >= '" . $dbr->timestamp($from) . "'"; $invertSort = true; } $sql = 'SELECT img_size, img_name, img_user, img_user_text,' . "img_description,img_timestamp FROM {$image}"; if ($hidebotsql) { $sql .= $hidebotsql; $where[] = 'ug_group IS NULL'; } if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY img_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, __FUNCTION__); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { $shownImages++; if ($shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_FILE); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($nt, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $titleObj = SpecialPage::getTitleFor('Newimages'); $action = $titleObj->getLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav && !$wgMiserMode) { $wgOut->addHTML(Xml::openElement('form', array('action' => $action, 'method' => 'post', 'id' => 'imagesearch')) . Xml::fieldset(wfMsg('newimages-legend')) . Xml::inputLabel(wfMsg('newimages-label'), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch) . ' ' . Xml::submitButton(wfMsg('ilsubmit'), array('name' => 'wpIlSubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form')); } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); if ($shownav) { $text = wfMsgExt('imagelisttext', array('parse'), $lt, $bydate); $wgOut->addHTML($text . "\n"); } /** * Paging controls... */ # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = '&hidebots=0'; } else { $botpar = ''; } $now = wfTimestampNow(); $d = $wgLang->date($now, true); $t = $wgLang->time($now, true); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('sp-newimages-showfrom', $d, $t), 'from=' . $now . $botpar . $searchpar); $botLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('showhidebots', $hidebots ? wfMsgHtml('show') : wfMsgHtml('hide')), 'hidebots=' . ($hidebots ? '0' : '1') . $searchpar); $opts = array('parsemag', 'escapenoentities'); $prevLink = wfMsgExt('pager-newer-n', $opts, $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar); } $nextLink = wfMsgExt('pager-older-n', $opts, $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp . $botpar . $searchpar); } $prevnext = '<p>' . $botLink . ' ' . wfMsgHtml('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if ($shownav) { $wgOut->addHTML($prevnext); } if (count($images)) { $wgOut->addHTML($gallery->toHTML()); if ($shownav) { $wgOut->addHTML($prevnext); } } else { $wgOut->addWikiMsg('noimages'); } }
function renderDynamicPageList($input, $args, $mwParser) { global $wgUser, $wgContLang; global $wgDisableCounters; // to determine if to allow sorting by #hits. global $wgDLPmaxCategories, $wgDLPMaxResultCount, $wgDLPMaxCacheTime; global $wgDLPAllowUnlimitedResults, $wgDLPAllowUnlimitedCategories; if ($wgDLPMaxCacheTime !== false) { $mwParser->getOutput()->updateCacheExpiry($wgDLPMaxCacheTime); } $countSet = false; $startList = '<ul>'; $endList = '</ul>'; $startItem = '<li>'; $endItem = '</li>'; $inlineMode = false; $useGallery = false; $galleryFileSize = false; $galleryFileName = true; $galleryImageHeight = 0; $galleryImageWidth = 0; $galleryNumbRows = 0; $galleryCaption = ''; $gallery = null; $orderMethod = 'categoryadd'; $order = 'descending'; $redirects = 'exclude'; $stable = $quality = 'include'; $flaggedRevs = false; $namespaceFiltering = false; $namespaceIndex = 0; $offset = 0; $googleHack = false; $suppressErrors = false; $showNamespace = true; $addFirstCategoryDate = false; $dateFormat = ''; $stripYear = false; $linkOptions = array(); $categories = array(); $excludeCategories = array(); $parameters = explode("\n", $input); $parser = new Parser(); $poptions = new ParserOptions(); foreach ($parameters as $parameter) { $paramField = explode('=', $parameter, 2); if (count($paramField) < 2) { continue; } $type = trim($paramField[0]); $arg = trim($paramField[1]); switch ($type) { case 'category': $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions)); if (is_null($title)) { continue; } $categories[] = $title; break; case 'notcategory': $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions)); if (is_null($title)) { continue; } $excludeCategories[] = $title; break; case 'namespace': $ns = $wgContLang->getNsIndex($arg); if ($ns != null) { $namespaceIndex = $ns; $namespaceFiltering = true; } else { // Note, since intval("some string") = 0 // this considers pretty much anything // invalid here as the main namespace. // This was probably originally a bug, // but is now depended upon by people // writing things like namespace=main // so be careful when changing this code. $namespaceIndex = intval($arg); if ($namespaceIndex >= 0) { $namespaceFiltering = true; } else { $namespaceFiltering = false; } } break; case 'count': // ensure that $count is a number; $count = intval($arg); $countSet = true; break; case 'offset': $offset = intval($arg); break; case 'imagewidth': $galleryImageWidth = intval($arg); break; case 'imageheight': $galleryImageHeight = intval($arg); break; case 'imagesperrow': $galleryNumbRows = intval($arg); break; case 'mode': switch ($arg) { case 'gallery': $useGallery = true; $gallery = new ImageGallery(); $startList = ''; $endList = ''; $startItem = ''; $endItem = ''; break; case 'none': $startList = ''; $endList = ''; $startItem = ''; $endItem = '<br />'; $inlineMode = false; break; case 'ordered': $startList = '<ol>'; $endList = '</ol>'; $startItem = '<li>'; $endItem = '</li>'; $inlineMode = false; break; case 'inline': // aka comma seperated list $startList = ''; $endList = ''; $startItem = ''; $endItem = ''; $inlineMode = true; break; case 'unordered': default: $startList = '<ul>'; $endList = '</ul>'; $startItem = '<li>'; $endItem = '</li>'; $inlineMode = false; break; } break; case 'gallerycaption': // Should perhaps actually parse caption instead // as links and what not in caption might be useful. $galleryCaption = $parser->transformMsg($arg, $poptions); break; case 'galleryshowfilesize': switch ($arg) { case 'no': case 'false': $galleryFileSize = false; break; case 'true': default: $galleryFileSize = true; } break; case 'galleryshowfilename': switch ($arg) { case 'no': case 'false': $galleryFileName = false; break; case 'true': default: $galleryFileName = true; break; } break; case 'order': switch ($arg) { case 'ascending': $order = 'ascending'; break; case 'descending': default: $order = 'descending'; break; } break; case 'ordermethod': switch ($arg) { case 'lastedit': $orderMethod = 'lastedit'; break; case 'length': $orderMethod = 'length'; break; case 'created': $orderMethod = 'created'; break; case 'sortkey': case 'categorysortkey': $orderMethod = 'categorysortkey'; break; case 'popularity': if (!$wgDisableCounters) { $orderMethod = 'popularity'; } else { $orderMethod = 'categoyadd'; // default if hitcounter disabled. } break; case 'categoryadd': default: $orderMethod = 'categoryadd'; break; } break; case 'redirects': switch ($arg) { case 'include': $redirects = 'include'; break; case 'only': $redirects = 'only'; break; case 'exclude': default: $redirects = 'exclude'; break; } break; case 'stablepages': switch ($arg) { case 'include': $stable = 'include'; break; case 'only': $flaggedRevs = true; $stable = 'only'; break; case 'exclude': default: $flaggedRevs = true; $stable = 'exclude'; break; } break; case 'qualitypages': switch ($arg) { case 'include': $quality = 'include'; break; case 'only': $flaggedRevs = true; $quality = 'only'; break; case 'exclude': default: $flaggedRevs = true; $quality = 'exclude'; break; } break; case 'suppresserrors': if ($arg == 'true') { $suppressErrors = true; } else { $suppressErrors = false; } break; case 'addfirstcategorydate': if ($arg == 'true') { $addFirstCategoryDate = true; } elseif (preg_match('/^(?:[ymd]{2,3}|ISO 8601)$/', $arg)) { // if it more or less is valid dateformat. $addFirstCategoryDate = true; $dateFormat = $arg; if (strlen($dateFormat) == 2) { $dateFormat = $dateFormat . 'y'; # DateFormatter does not support no year. work around $stripYear = true; } } else { $addFirstCategoryDate = false; } break; case 'shownamespace': if ('false' == $arg) { $showNamespace = false; } else { $showNamespace = true; } break; case 'googlehack': if ('false' == $arg) { $googleHack = false; } else { $googleHack = true; } break; case 'nofollow': # bug 6658 if ('false' != $arg) { $linkOptions['rel'] = 'nofollow'; } break; } // end main switch() } // end foreach() $catCount = count($categories); $excludeCatCount = count($excludeCategories); $totalCatCount = $catCount + $excludeCatCount; if ($catCount < 1 && false == $namespaceFiltering) { if ($suppressErrors == false) { return htmlspecialchars(wfMsgForContent('intersection_noincludecats')); // "!!no included categories!!"; } else { return ''; } } if ($totalCatCount > $wgDLPmaxCategories && !$wgDLPAllowUnlimitedCategories) { if ($suppressErrors == false) { return htmlspecialchars(wfMsgForContent('intersection_toomanycats')); // "!!too many categories!!"; } else { return ''; } } if ($countSet) { if ($count < 1) { $count = 1; } if ($count > $wgDLPMaxResultCount) { $count = $wgDLPMaxResultCount; } } elseif (!$wgDLPAllowUnlimitedResults) { $count = $wgDLPMaxResultCount; $countSet = true; } // disallow showing date if the query doesn't have an inclusion category parameter if ($catCount < 1) { $addFirstCategoryDate = false; // don't sort by fields relating to categories if there are no categories. if ($orderMethod == 'categoryadd' || $orderMethod == 'categorysortkey') { $orderMethod = 'created'; } } // build the SQL query $dbr = wfGetDB(DB_SLAVE); $tables = array('page'); $fields = array('page_namespace', 'page_title'); $where = array(); $join = array(); $options = array(); if ($googleHack) { $fields[] = 'page_id'; } if ($addFirstCategoryDate) { $fields[] = 'c1.cl_timestamp'; } if ($namespaceFiltering == true) { $where['page_namespace'] = $namespaceIndex; } // Bug 14943 - Allow filtering based on FlaggedRevs stability. // Check if the extension actually exists before changing the query... if ($flaggedRevs && defined('FLAGGED_REVISIONS')) { $tables[] = 'flaggedpages'; $join['flaggedpages'] = array('LEFT JOIN', 'page_id = fp_page_id'); switch ($stable) { case 'only': $where[] = 'fp_stable IS NOT NULL'; break; case 'exclude': $where['fp_stable'] = null; break; } switch ($quality) { case 'only': $where[] = 'fp_quality >= 1'; break; case 'exclude': $where[] = 'fp_quality = 0 OR fp_quality IS NULL'; break; } } switch ($redirects) { case 'only': $where['page_is_redirect'] = 1; break; case 'exclude': $where['page_is_redirect'] = 0; break; } $currentTableNumber = 1; $categorylinks = $dbr->tableName('categorylinks'); for ($i = 0; $i < $catCount; $i++) { $join["{$categorylinks} AS c{$currentTableNumber}"] = array('INNER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($categories[$i]->getDBKey())}")); $tables[] = "{$categorylinks} AS c{$currentTableNumber}"; $currentTableNumber++; } for ($i = 0; $i < $excludeCatCount; $i++) { $join["{$categorylinks} AS c{$currentTableNumber}"] = array('LEFT OUTER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($excludeCategories[$i]->getDBKey())}")); $tables[] = "{$categorylinks} AS c{$currentTableNumber}"; $where["c{$currentTableNumber}.cl_to"] = null; $currentTableNumber++; } if ('descending' == $order) { $sqlOrder = 'DESC'; } else { $sqlOrder = 'ASC'; } switch ($orderMethod) { case 'lastedit': $sqlSort = 'page_touched'; break; case 'length': $sqlSort = 'page_len'; break; case 'created': $sqlSort = 'page_id'; # Since they're never reused and increasing break; case 'categorysortkey': $sqlSort = "c1.cl_type {$sqlOrder}, c1.cl_sortkey"; break; case 'popularity': $sqlSort = 'page_counter'; break; case 'categoryadd': default: $sqlSort = 'c1.cl_timestamp'; break; } $options['ORDER BY'] = "{$sqlSort} {$sqlOrder}"; if ($countSet) { $options['LIMIT'] = $count; } if ($offset > 0) { $options['OFFSET'] = $offset; } // process the query $res = $dbr->select($tables, $fields, $where, __METHOD__, $options, $join); $sk = $wgUser->getSkin(); if ($dbr->numRows($res) == 0) { if ($suppressErrors == false) { return htmlspecialchars(wfMsgForContent('intersection_noresults')); } else { return ''; } } // start unordered list $output = $startList . "\n"; $categoryDate = ''; $df = null; if ($dateFormat != '' && $addFirstCategoryDate) { $df = DateFormatter::getInstance(); } // process results of query, outputing equivalent of <li>[[Article]]</li> // for each result, or something similar if the list uses other // startlist/endlist $articleList = array(); foreach ($res as $row) { $title = Title::makeTitle($row->page_namespace, $row->page_title); if (true == $addFirstCategoryDate) { if ($dateFormat != '') { # this is a tad ugly # use DateFormatter, and support disgarding year. $categoryDate = wfTimestamp(TS_ISO_8601, $row->cl_timestamp); if ($stripYear) { $categoryDate = $wgContLang->getMonthName(substr($categoryDate, 5, 2)) . ' ' . substr($categoryDate, 8, 2); } else { $categoryDate = substr($categoryDate, 0, 10); } $categoryDate = $df->reformat($dateFormat, $categoryDate, array('match-whole')); } else { $categoryDate = $wgContLang->date(wfTimestamp(TS_MW, $row->cl_timestamp)); } if (!$useGallery) { $categoryDate .= wfMsgForContent('colon-separator'); } else { $categoryDate .= ' '; } } $query = array(); if ($googleHack == true) { $query['dpl_id'] = intval($row->page_id); } if ($showNamespace == true) { $titleText = $title->getPrefixedText(); } else { $titleText = $title->getText(); } if ($useGallery) { # Note, $categoryDate is treated as raw html # this is safe since the only html present # would come from the dateformatter <span>. $gallery->add($title, $categoryDate); } else { $articleList[] = $categoryDate . $sk->link($title, htmlspecialchars($titleText), $linkOptions, $query, array('forcearticlepath', 'known')); } } // end unordered list if ($useGallery) { $gallery->setHideBadImages(); $gallery->setShowFilename($galleryFileName); $gallery->setShowBytes($galleryFileSize); if ($galleryImageHeight > 0) { $gallery->setHeights($galleryImageHeight); } if ($galleryImageWidth > 0) { $gallery->setWidths($galleryImageWidth); } if ($galleryNumbRows > 0) { $gallery->setPerRow($galleryNumbRows); } if ($galleryCaption != '') { $gallery->setCaption($galleryCaption); # gallery class escapes string } $output = $gallery->toHtml(); } else { $output .= $startItem; if ($inlineMode) { $output .= $wgContLang->commaList($articleList); } else { $output .= implode("{$endItem} \n{$startItem}", $articleList); } $output .= $endItem; $output .= $endList . "\n"; } return $output; }
/** * 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(); }
/** * */ function wfSpecialNewimages($par, $specialPage) { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgGroupPermissions; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); $shownav = !$specialPage->including(); $hidebots = $wgRequest->getBool('hidebots', 1); if ($hidebots) { /** Make a list of group names which have the 'bot' flag set. */ $botconds = array(); foreach ($wgGroupPermissions as $groupname => $perms) { if (array_key_exists('bot', $perms) && $perms['bot']) { $botconds[] = "ug_group='{$groupname}'"; } } $isbotmember = $dbr->makeList($botconds, LIST_OR); /** This join, in conjunction with WHERE ug_group IS NULL, returns only those rows from IMAGE where the uploading user is not a member of a group which has the 'bot' permission set. */ $ug = $dbr->tableName('user_groups'); $joinsql = " LEFT OUTER JOIN {$ug} ON img_user=ug_user AND (" . $isbotmember . ')'; } $image = $dbr->tableName('image'); $sql = "SELECT img_timestamp from {$image}"; if ($hidebots) { $sql .= $joinsql . ' WHERE ug_group IS NULL'; } $sql .= ' ORDER BY img_timestamp DESC LIMIT 1'; $res = $dbr->query($sql, 'wfSpecialNewImages'); $row = $dbr->fetchRow($res); if ($row !== false) { $ts = $row[0]; } else { $ts = false; } $dbr->freeResult($res); $sql = ''; /** If we were clever, we'd use this to cache. */ $latestTimestamp = wfTimestamp(TS_MW, $ts); /** Hardcode this for now. */ $limit = 48; if ($parval = intval($par)) { if ($parval <= $limit && $parval > 0) { $limit = $parval; } } $where = array(); $searchpar = ''; if ($wpIlMatch != '') { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace('%', "\\%", $m); $m = str_replace('_', "\\_", $m); $where[] = "LCASE(img_name) LIKE '%{$m}%'"; $searchpar = '&wpIlMatch=' . urlencode($wpIlMatch); } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = 'img_timestamp < ' . $dbr->timestamp($until); } if ($from = $wgRequest->getVal('from')) { $where[] = 'img_timestamp >= ' . $dbr->timestamp($from); $invertSort = true; } $sql = 'SELECT img_size, img_name, img_user, img_user_text,' . "img_description,img_timestamp FROM {$image}"; if ($hidebots) { $sql .= $joinsql; $where[] = 'ug_group IS NULL'; } if (count($where)) { $sql .= ' WHERE ' . $dbr->makeList($where, LIST_AND); } $sql .= ' ORDER BY img_timestamp ' . ($invertSort ? '' : ' DESC'); $sql .= ' LIMIT ' . ($limit + 1); $res = $dbr->query($sql, 'wfSpecialNewImages'); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { if (++$shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_IMAGE); $img = Image::newFromTitle($nt); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($img, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); if ($shownav) { $text = wfMsgExt('imagelisttext', array('parse'), $lt, $bydate); $wgOut->addHTML($text . "\n"); } $sub = wfMsg('ilsubmit'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Newimages'); $action = $titleObj->escapeLocalURL($hidebots ? '' : 'hidebots=0'); if ($shownav) { $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . "<input type='text' size='20' name=\"wpIlMatch\" value=\"" . htmlspecialchars($wpIlMatch) . "\" /> " . "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>"); } $here = $wgContLang->specialPage('Newimages'); /** * Paging controls... */ # If we change bot visibility, this needs to be carried along. if (!$hidebots) { $botpar = '&hidebots=0'; } else { $botpar = ''; } $now = wfTimestampNow(); $date = $wgLang->timeanddate($now, true); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsg('sp-newimages-showfrom', $date), 'from=' . $now . $botpar . $searchpar); $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg('showhidebots', $hidebots ? wfMsg('show') : wfMsg('hide')), 'hidebots=' . ($hidebots ? '0' : '1') . $searchpar); $prevLink = wfMsg('prevn', $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar); } $nextLink = wfMsg('nextn', $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp . $botpar . $searchpar); } $prevnext = '<p>' . $botLink . ' ' . wfMsg('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; if ($shownav) { $wgOut->addHTML($prevnext); } if (count($images)) { $wgOut->addHTML($gallery->toHTML()); if ($shownav) { $wgOut->addHTML($prevnext); } } else { $wgOut->addWikiText(wfMsg('noimages')); } }
/** * 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->setShowBytes(false); $ig->setShowFilename(false); $ig->setParsing(); $ig->useSkin($this->mOptions->getSkin()); if (isset($params['caption'])) { $ig->setCaption($params['caption']); } $lines = explode("\n", $text); foreach ($lines as $line) { # match lines like these: # Image:someimage.jpg|This is some image 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(); }
/** * Adds a single image to the gallery. * Takes care of automatically adding a caption when none is provided and parsing it's wikitext. * * @since 1.5.3 * * @param ImageGallery $ig The gallery to add the image to * @param Title $imgTitle The title object of the page of the image * @param string $imgCaption An optional caption for the image */ protected function addImageToGallery(ImageGallery &$ig, Title $imgTitle, $imgCaption, $imgRedirect = '') { if (empty($imgCaption)) { if ($this->m_params['autocaptions']) { $imgCaption = $imgTitle->getBaseText(); if (!$this->m_params['fileextensions']) { $imgCaption = preg_replace('#\\.[^.]+$#', '', $imgCaption); } } else { $imgCaption = ''; } } else { if ($imgTitle instanceof Title && $imgTitle->getNamespace() == NS_FILE && !$this->isSpecialPage()) { $imgCaption = $GLOBALS['wgParser']->recursiveTagParse($imgCaption); } } // Use image alt as helper for either text $imgAlt = $this->params['redirects'] === '' ? $imgCaption : $imgRedirect !== '' ? $imgRedirect : ''; $ig->add($imgTitle, $imgCaption, $imgAlt); }
public function displayFeatured() { $markup = "\n<ul id=\"featured-gallery\">"; // Select the featured gallery titles $sql = "SELECT id, page\n FROM `" . DB_NAME . "`.`" . DB_PREFIX . "entryMgr`\n WHERE data7='featured'"; $stmt = $this->mysqli->prepare($sql); $stmt->execute(); $stmt->bind_result($id, $page); // Create a new ImageGallery object $gal = new ImageGallery(); // Loop through the featured cars while ($stmt->fetch()) { $gal->dir = "img/gallery/{$page}{$id}/preview/"; $gal->getImages(); $img = $gal->getFirstImage(); $markup .= "\n\t<li><a href=\"/{$page}/{$id}\"><img src=\"/{$img}\" alt=\"Featured Customization\" /></a></li>"; } return $markup . "\n</ul>\n"; }
/** * Returns HTML for a gallery */ function makeGallery ( &$images , &$params ) { global $wgLang ; $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; $params['therearemore'] = false ; foreach( $images as $s ) { if( ++$shownImages > $params['limit'] ) { # One extra just to test for whether to show a page link; # don't actually show it, but remember there are more. $params['therearemore'] = true ; break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText( $name, NS_IMAGE ); $ul = $this->sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), htmlspecialchars( $ut ) ); $gallery->add( $nt, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" ); $timestamp = wfTimestamp( TS_MW, $s->img_timestamp ); if( empty( $firstTimestamp ) ) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $params['lasttimestamp'] = $lastTimestamp ; $params['firsttimestamp'] = $firstTimestamp ; return $gallery->toHTML() ; }
/** * 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(); }
/** * Example Image Gallery * @author KikApp * @version 1.0 */ $win = new SDPanel(); $win->setCaption("Image Gallery"); $mainTable = new Table(); //Create Inputs $id = new InputNumeric(); $title = new InputText(); $desc = new InputText(); $image = new InputImage(); //Create Image Gallery $grid = new ImageGallery(); $grid->setImage($image); $grid->setTitle($title); $grid->setSubtitle($desc); $grid->setEnableShare(true); $grid->addData(load_images()); $mainTable->addControl($grid, 1, 1); $win->addControl($mainTable); function load_images() { $url = "http://demo.kikapptools.com/magento/apiGecko/productos.php?cId=0"; $httpClient = new httpClient(); $result = $httpClient->Execute('GET', $url); $struct = array(array("id" => DataType::Numeric(6), "name" => DataType::Character(150), "description" => DataType::Character(300), "pirce" => DataType::Character(10), "thumb" => DataType::Character(200))); Data::FromJson($struct, $result); foreach ($struct as $product) {
/** * Construct a warning and a gallery from an array of duplicate files. * @param $dupes array * @return string */ public static function getDupeWarning($dupes) { if (!$dupes) { return ''; } $gallery = new ImageGallery(); $gallery->setShowBytes(false); foreach ($dupes as $file) { $gallery->add($file->getTitle()); } return '<li>' . wfMessage('file-exists-duplicate')->numParams(count($dupes))->parse() . $gallery->toHtml() . "</li>\n"; }
/** * */ function wfSpecialNewimages() { global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest; $wpIlMatch = $wgRequest->getText('wpIlMatch'); $dbr =& wfGetDB(DB_SLAVE); $sk = $wgUser->getSkin(); /** If we were clever, we'd use this to cache. */ $latestTimestamp = wfTimestamp(TS_MW, $dbr->selectField('image', 'img_timestamp', '', 'wfSpecialNewimages', array('ORDER BY' => 'img_timestamp DESC', 'LIMIT' => 1))); /** Hardcode this for now. */ $limit = 48; $where = array(); if ($wpIlMatch != '') { $nt = Title::newFromUrl($wpIlMatch); if ($nt) { $m = $dbr->strencode(strtolower($nt->getDBkey())); $m = str_replace('%', "\\%", $m); $m = str_replace('_', "\\_", $m); $where[] = "LCASE(img_name) LIKE '%{$m}%'"; } } $invertSort = false; if ($until = $wgRequest->getVal('until')) { $where[] = 'img_timestamp < ' . $dbr->timestamp($until); } if ($from = $wgRequest->getVal('from')) { $where[] = 'img_timestamp >= ' . $dbr->timestamp($from); $invertSort = true; } $res = $dbr->select('image', array('img_size', 'img_name', 'img_user', 'img_user_text', 'img_description', 'img_timestamp'), $where, 'wfSpecialNewimages', array('LIMIT' => $limit + 1, 'ORDER BY' => 'img_timestamp' . ($invertSort ? '' : ' DESC'))); /** * We have to flip things around to get the last N after a certain date */ $images = array(); while ($s = $dbr->fetchObject($res)) { if ($invertSort) { array_unshift($images, $s); } else { array_push($images, $s); } } $dbr->freeResult($res); $gallery = new ImageGallery(); $firstTimestamp = null; $lastTimestamp = null; $shownImages = 0; foreach ($images as $s) { if (++$shownImages > $limit) { # One extra just to test for whether to show a page link; # don't actually show it. break; } $name = $s->img_name; $ut = $s->img_user_text; $nt = Title::newFromText($name, NS_IMAGE); $img = Image::newFromTitle($nt); $ul = $sk->makeLinkObj(Title::makeTitle(NS_USER, $ut), $ut); $gallery->add($img, "{$ul}<br />\n<i>" . $wgLang->timeanddate($s->img_timestamp, true) . "</i><br />\n"); $timestamp = wfTimestamp(TS_MW, $s->img_timestamp); if (empty($firstTimestamp)) { $firstTimestamp = $timestamp; } $lastTimestamp = $timestamp; } $bydate = wfMsg('bydate'); $lt = $wgLang->formatNum(min($shownImages, $limit)); $text = wfMsg("imagelisttext", "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>"); $wgOut->addHTML("<p>{$text}\n</p>"); $sub = wfMsg('ilsubmit'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Newimages'); $action = $titleObj->escapeLocalURL("limit={$limit}"); $wgOut->addHTML("<form id=\"imagesearch\" method=\"post\" action=\"" . "{$action}\">" . "<input type='text' size='20' name=\"wpIlMatch\" value=\"" . htmlspecialchars($wpIlMatch) . "\" /> " . "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>"); $here = $wgContLang->specialPage('Newimages'); /** * Paging controls... */ $now = wfTimestampNow(); $date = $wgLang->timeanddate($now); $dateLink = $sk->makeKnownLinkObj($titleObj, wfMsg('rclistfrom', $date), 'from=' . $now); $prevLink = wfMsg('prevn', $wgLang->formatNum($limit)); if ($firstTimestamp && $firstTimestamp != $latestTimestamp) { $prevLink = $sk->makeKnownLinkObj($titleObj, $prevLink, 'from=' . $firstTimestamp); } $nextLink = wfMsg('nextn', $wgLang->formatNum($limit)); if ($shownImages > $limit && $lastTimestamp) { $nextLink = $sk->makeKnownLinkObj($titleObj, $nextLink, 'until=' . $lastTimestamp); } $prevnext = '<p>' . wfMsg('viewprevnext', $prevLink, $nextLink, $dateLink) . '</p>'; $wgOut->addHTML($prevnext); if (count($images)) { $wgOut->addHTML($gallery->toHTML()); $wgOut->addHTML($prevnext); } else { $wgOut->addWikiText(wfMsg('noimages')); } }
function generateList() { if ($this->pager->offset == -1) { return ''; // list has no entries } # {{{ gallery container template $gallery_html = ''; $gallery_tpl = array('__tag' => 'div', 'class' => 'cb_files_container', 0 => &$gallery_html); # }}} # create list of files (holder of prev/next AJAX links and generated image gallery) $filelist = array(); # create image gallery $gallery = new ImageGallery(); $gallery->setHideBadImages(); $gallery->setPerRow(CB_Setup::$imageGalleryPerRow); $this->addPrevPageLink($filelist); foreach ($this->pager->entries as &$file) { $file_title = Title::makeTitle($file->page_namespace, $file->page_title); # show the sortkey, when it does not match title name $gallery->add($file_title, $this->addSortKey($file_title, $file)); } if (!$gallery->isEmpty()) { $gallery_html = $gallery->toHTML(); $filelist[] = CB_XML::toText($gallery_tpl); } $this->addNextPageLink($filelist); return $filelist; }
function renderPlainGallery ( $galleryArray ) { if ( !isset( $galleryArray["images"] ) ) { return ''; } // Wrapper div for plain old gallery, to be shown per default, if JS is off. $output = '<div id="' . $galleryArray["gallery_name"] . '-fallback">'; $plain_gallery = new ImageGallery(); $i = 0; foreach ( $galleryArray["images"] as $image ) { if ( isset( $image["external"] ) && $image["external"] ) { continue; } $plain_gallery->add( $image["image_object"]->getTitle(), $image["description"] ); // TODO: use text $i++; } // Return an empty div if there are no usable images in the gallery. // This can happen if all images are external. if ( $i == 0 ) { return $output . '</div>'; } $output .= $plain_gallery->toHTML(); // Close the wrapper div for the plain old gallery $output .= '</div>'; return $output; }