Пример #1
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;
 }
Пример #2
0
 /**
  * Renders an image gallery from a text with one line per image.
  * text labels may be given by using |-style alternative text. E.g.
  *   Image:one.jpg|The number "1"
  *   Image:tree.jpg|A tree
  * given as text will return the HTML of a gallery with two images,
  * labeled 'The number "1"' and
  * 'A tree'.
  */
 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();
 }