Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * @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;
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
/**
 * @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');
    }
}
Exemplo n.º 5
0
 function getEndBody()
 {
     return $this->gallery->toHTML();
 }
Exemplo n.º 6
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();
 }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
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();
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
 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;
 }
Exemplo n.º 11
0
/**
 *
 */
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'));
    }
}
Exemplo n.º 12
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->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();
 }
	/**
	 * 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() ;
	}
	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;
	}
/**
 *
 */
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'));
    }
}